-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Issue
Version 0.2.0
added support for migrations! In that update, a new index-imported top-level file, src/fs-migration-source.ts
, was added, which imports the following from knex
:
import {FsMigrations} from 'knex/lib/migrations/migrate/sources/fs-migrations.js'
Unfortunately the knex
package does not declare itself as "sideEffects": false
the way kysely-knex
does. As such, this import is not treeshaken away when not needed - even when KyselyFsMigrationSource
is treeshaken away.
This issue manifests itself further downstream: Packages that import kysely-knex
will end up bundling that particular knex file, which itself includes various imports from path
, os
etc. (potentially problematic in certain runtimes) and further bloats bundle outputs.
Repro
I can spin up a proper repro if requested, but basic, minimal example looks like this:
// src/my-file.ts
import {KyselyKnexDialect} from 'kysely-knex'
export function foo() {
new KyselyKnexDialect({} as any)
}
Worst case this file, when bundled, will already include the entire fs-migrations.js
file knex.
Best case, when declaring knex as external dependency, the dist output may look something like this (exact output depends on the bundler, target, etc.):
// dist/my-file.js
import { FsMigrations } from "knex/lib/migrations/migrate/sources/fs-migrations.js";
var KyselyKnexConnection = class {
#connection;
#knex;
// ...
};
function foo() {
new KyselyKnexDialect({});
}
export {
foo
};
However, the next package that utilizes this, without declaring knex
(or specifically knex/lib/migrations/migrate/sources/fs-migrations.js
) as external, will in turn bundle said knex file into its dist output.