0

In a typescript project, I use knex for querying a sqlite database (in development mode)

in short

how do I tell typescript to ignore a file (plain js config file must stay at root) while adapting the import path of this file ?

in details:

My knexfile (connection configuration) lives at the root of the project, and is imported by ./src/connect.ts.

// ./src/connect.ts
import knex from "knex"
import knexfile from "../knexfile"

export default function connect () {
    const config = process.env.NODE_ENV === "production" 
    ? knexfile.production
    : knexfile.development

    console.log("> connection to " + config.client)

    return knex(config)
}

Inside the knexfile the configuration specifies the path for the sqlite database using __dirname so that the db exists at the root dev.sqlite3

// ./knexfile.js

// ...
module.exports = {
  development: {
    client: 'sqlite3',
    connection: {
      filename: resolve(__dirname, './dev.sqlite3')
    },
// ...

(I need the knexfile to be plain javascript for migrations)

The problem is: when I transpile, the output lives in the ./build directory, and the knexfile gets moved there too, resulting in the creation of a second database ./build/dev.sqlite3

here is the folder view:

knexfile.js
dev.sqlite3        #the database i want to use
src/
    connect.ts
build/
    knexfile.js    # X a copy of knexfile, I don't want this
    dev.sqlite3    # X a new database I don't want either
    src/
        connect.js # this file should import "../../knexfile" and not "../knexfile"
gui3
  • 1,711
  • 14
  • 30
  • Do you mean you want [to ignore the files](https://stackoverflow.com/q/43538650/215552) during transpilation? – Heretic Monkey Nov 07 '22 at 14:21
  • yes, and to have the correct import path in the final output... your link says it is not possible, I'm looking for a workaround – gui3 Nov 07 '22 at 14:43

0 Answers0