@anthonyalayo/drizzle-kit 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api.d.mts +2891 -0
- package/api.d.ts +2891 -0
- package/api.js +47534 -0
- package/api.mjs +47521 -0
- package/bin.cjs +80043 -0
- package/{src/index.ts → index-Z-1TKnbX.d.mts} +123 -141
- package/index-Z-1TKnbX.d.ts +308 -0
- package/index.d.mts +2 -0
- package/index.d.ts +2 -0
- package/index.js +32 -0
- package/index.mjs +7 -0
- package/package.json +1 -1
- package/utils.js +6056 -0
- package/utils.mjs +6032 -0
- package/.gitignore +0 -25
- package/build.dev.ts +0 -51
- package/build.ts +0 -112
- package/imports-checker/analyze.ts +0 -78
- package/imports-checker/checker.ts +0 -296
- package/imports-checker/grammar/grammar.ohm +0 -121
- package/imports-checker/grammar/grammar.ohm-bundle.d.ts +0 -164
- package/imports-checker/grammar/grammar.ohm-bundle.js +0 -753
- package/imports-checker/index.ts +0 -48
- package/patches/difflib@0.2.4.patch +0 -31
- package/src/@types/utils.ts +0 -58
- package/src/api.ts +0 -504
- package/src/cli/commands/_es5.ts +0 -2
- package/src/cli/commands/check.ts +0 -52
- package/src/cli/commands/drop.ts +0 -60
- package/src/cli/commands/introspect.ts +0 -772
- package/src/cli/commands/libSqlPushUtils.ts +0 -355
- package/src/cli/commands/migrate.ts +0 -1526
- package/src/cli/commands/mysqlIntrospect.ts +0 -53
- package/src/cli/commands/mysqlPushUtils.ts +0 -352
- package/src/cli/commands/mysqlUp.ts +0 -102
- package/src/cli/commands/pgIntrospect.ts +0 -55
- package/src/cli/commands/pgPushUtils.ts +0 -269
- package/src/cli/commands/pgUp.ts +0 -217
- package/src/cli/commands/push.ts +0 -637
- package/src/cli/commands/singlestoreIntrospect.ts +0 -53
- package/src/cli/commands/singlestorePushUtils.ts +0 -456
- package/src/cli/commands/singlestoreUp.ts +0 -1
- package/src/cli/commands/sqliteIntrospect.ts +0 -96
- package/src/cli/commands/sqlitePushUtils.ts +0 -322
- package/src/cli/commands/sqliteUp.ts +0 -52
- package/src/cli/commands/utils.ts +0 -858
- package/src/cli/connections.ts +0 -914
- package/src/cli/index.ts +0 -48
- package/src/cli/schema.ts +0 -794
- package/src/cli/selector-ui.ts +0 -38
- package/src/cli/utils.ts +0 -112
- package/src/cli/validations/cli.ts +0 -79
- package/src/cli/validations/common.ts +0 -193
- package/src/cli/validations/libsql.ts +0 -27
- package/src/cli/validations/mysql.ts +0 -61
- package/src/cli/validations/outputs.ts +0 -91
- package/src/cli/validations/postgres.ts +0 -83
- package/src/cli/validations/singlestore.ts +0 -61
- package/src/cli/validations/sqlite.ts +0 -104
- package/src/cli/validations/studio.ts +0 -24
- package/src/cli/views.ts +0 -658
- package/src/extensions/getTablesFilterByExtensions.ts +0 -16
- package/src/extensions/vector.ts +0 -10
- package/src/global.ts +0 -61
- package/src/introspect-mysql.ts +0 -1030
- package/src/introspect-pg.ts +0 -1435
- package/src/introspect-singlestore.ts +0 -913
- package/src/introspect-sqlite.ts +0 -533
- package/src/jsonDiffer.js +0 -882
- package/src/jsonStatements.ts +0 -3590
- package/src/loader.mjs +0 -57
- package/src/migrationPreparator.ts +0 -217
- package/src/schemaValidator.ts +0 -23
- package/src/serializer/index.ts +0 -142
- package/src/serializer/mysqlImports.ts +0 -38
- package/src/serializer/mysqlSchema.ts +0 -423
- package/src/serializer/mysqlSerializer.ts +0 -999
- package/src/serializer/pgImports.ts +0 -106
- package/src/serializer/pgSchema.ts +0 -937
- package/src/serializer/pgSerializer.ts +0 -2223
- package/src/serializer/singlestoreImports.ts +0 -38
- package/src/serializer/singlestoreSchema.ts +0 -257
- package/src/serializer/singlestoreSerializer.ts +0 -767
- package/src/serializer/sqliteImports.ts +0 -41
- package/src/serializer/sqliteSchema.ts +0 -352
- package/src/serializer/sqliteSerializer.ts +0 -931
- package/src/serializer/studio.ts +0 -694
- package/src/serializer/utils.ts +0 -45
- package/src/simulator.ts +0 -157
- package/src/snapshotsDiffer.ts +0 -4398
- package/src/sqlgenerator.ts +0 -4212
- package/src/statementCombiner.ts +0 -597
- package/src/utils/certs.ts +0 -44
- package/src/utils/words.ts +0 -1333
- package/src/utils.ts +0 -370
- package/tests/bin.test.ts +0 -58
- package/tests/cli/d1http.config.ts +0 -12
- package/tests/cli/drizzle.config.ts +0 -9
- package/tests/cli/durable-sqlite.config.ts +0 -7
- package/tests/cli/expo.config.ts +0 -7
- package/tests/cli/postgres.config.ts +0 -13
- package/tests/cli/postgres2.config.ts +0 -17
- package/tests/cli/schema.ts +0 -1
- package/tests/cli/turso.config.ts +0 -10
- package/tests/cli-export.test.ts +0 -79
- package/tests/cli-generate.test.ts +0 -259
- package/tests/cli-migrate.test.ts +0 -103
- package/tests/cli-push.test.ts +0 -126
- package/tests/common.ts +0 -15
- package/tests/indexes/common.ts +0 -21
- package/tests/indexes/pg.test.ts +0 -245
- package/tests/introspect/libsql.test.ts +0 -35
- package/tests/introspect/mysql.test.ts +0 -319
- package/tests/introspect/pg.test.ts +0 -894
- package/tests/introspect/singlestore.test.ts +0 -275
- package/tests/introspect/sqlite.test.ts +0 -122
- package/tests/libsql-checks.test.ts +0 -308
- package/tests/libsql-statements.test.ts +0 -989
- package/tests/libsql-views.test.ts +0 -218
- package/tests/migrate/libsq-schema.ts +0 -6
- package/tests/migrate/libsql-migrate.test.ts +0 -58
- package/tests/migrate/migrations/0000_little_blizzard.sql +0 -4
- package/tests/migrate/migrations/0001_nebulous_storm.sql +0 -10
- package/tests/migrate/migrations/meta/0000_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/0001_snapshot.json +0 -40
- package/tests/migrate/migrations/meta/_journal.json +0 -20
- package/tests/mysql-checks.test.ts +0 -291
- package/tests/mysql-generated.test.ts +0 -1290
- package/tests/mysql-schemas.test.ts +0 -156
- package/tests/mysql-views.test.ts +0 -553
- package/tests/mysql.test.ts +0 -863
- package/tests/pg-array.test.ts +0 -368
- package/tests/pg-checks.test.ts +0 -329
- package/tests/pg-columns.test.ts +0 -484
- package/tests/pg-domains.test.ts +0 -306
- package/tests/pg-enums.test.ts +0 -751
- package/tests/pg-generated.test.ts +0 -529
- package/tests/pg-identity.test.ts +0 -447
- package/tests/pg-schemas.test.ts +0 -105
- package/tests/pg-sequences.test.ts +0 -298
- package/tests/pg-tables.test.ts +0 -1021
- package/tests/pg-views.test.ts +0 -1929
- package/tests/push/common.ts +0 -58
- package/tests/push/libsql.test.ts +0 -1400
- package/tests/push/mysql-push.test.ts +0 -345
- package/tests/push/mysql.test.ts +0 -788
- package/tests/push/pg.test.ts +0 -4341
- package/tests/push/singlestore-push.test.ts +0 -894
- package/tests/push/singlestore.test.ts +0 -444
- package/tests/push/sqlite.test.ts +0 -1613
- package/tests/rls/pg-policy.test.ts +0 -1656
- package/tests/rls/pg-role.test.ts +0 -234
- package/tests/schemaDiffer.ts +0 -2852
- package/tests/singlestore-generated.test.ts +0 -1290
- package/tests/singlestore-schemas.test.ts +0 -155
- package/tests/singlestore.test.ts +0 -978
- package/tests/sqlite-checks.test.ts +0 -308
- package/tests/sqlite-columns.test.ts +0 -1049
- package/tests/sqlite-generated.test.ts +0 -1726
- package/tests/sqlite-tables.test.ts +0 -637
- package/tests/sqlite-views.test.ts +0 -218
- package/tests/statements-combiner/libsql-statements-combiner.test.ts +0 -1812
- package/tests/statements-combiner/singlestore-statements-combiner.test.ts +0 -882
- package/tests/statements-combiner/sqlite-statements-combiner.test.ts +0 -1211
- package/tests/test/sqlite.test.ts +0 -39
- package/tests/testsinglestore.ts +0 -29
- package/tests/validations.test.ts +0 -869
- package/tests/wrap-param.test.ts +0 -16
- package/tsconfig.build.json +0 -4
- package/tsconfig.cli-types.json +0 -9
- package/tsconfig.json +0 -28
- package/vitest.config.ts +0 -34
package/.gitignore
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
**/.DS_Store
|
|
3
|
-
|
|
4
|
-
!src
|
|
5
|
-
!imports-checker
|
|
6
|
-
!tests
|
|
7
|
-
!vitest.config.ts
|
|
8
|
-
!README.md
|
|
9
|
-
!CONTRIBUTING.md
|
|
10
|
-
!schema.ts
|
|
11
|
-
|
|
12
|
-
!.eslint
|
|
13
|
-
!.gitignore
|
|
14
|
-
!package.json
|
|
15
|
-
!tsconfig.json
|
|
16
|
-
!tsconfig.cli-types.json
|
|
17
|
-
!tsconfig.build.json
|
|
18
|
-
!pnpm-lock.yaml
|
|
19
|
-
!.github
|
|
20
|
-
!build.ts
|
|
21
|
-
!build.dev.ts
|
|
22
|
-
|
|
23
|
-
tests/test.ts
|
|
24
|
-
|
|
25
|
-
!patches
|
package/build.dev.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as esbuild from 'esbuild';
|
|
2
|
-
import { cpSync } from 'node:fs';
|
|
3
|
-
|
|
4
|
-
const driversPackages = [
|
|
5
|
-
// postgres drivers
|
|
6
|
-
'pg',
|
|
7
|
-
'postgres',
|
|
8
|
-
'@vercel/postgres',
|
|
9
|
-
'@neondatabase/serverless',
|
|
10
|
-
// mysql drivers
|
|
11
|
-
'mysql2',
|
|
12
|
-
'@planetscale/database',
|
|
13
|
-
// sqlite drivers
|
|
14
|
-
'@libsql/client',
|
|
15
|
-
'better-sqlite3',
|
|
16
|
-
];
|
|
17
|
-
|
|
18
|
-
esbuild.buildSync({
|
|
19
|
-
entryPoints: ['./src/utils.ts'],
|
|
20
|
-
bundle: true,
|
|
21
|
-
outfile: 'dist/utils.js',
|
|
22
|
-
format: 'cjs',
|
|
23
|
-
target: 'node16',
|
|
24
|
-
platform: 'node',
|
|
25
|
-
external: ['drizzle-orm', 'esbuild', ...driversPackages],
|
|
26
|
-
banner: {
|
|
27
|
-
js: `#!/usr/bin/env -S node --loader @esbuild-kit/esm-loader --no-warnings`,
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
esbuild.buildSync({
|
|
32
|
-
entryPoints: ['./src/cli/index.ts'],
|
|
33
|
-
bundle: true,
|
|
34
|
-
outfile: 'dist/index.cjs',
|
|
35
|
-
format: 'cjs',
|
|
36
|
-
target: 'node16',
|
|
37
|
-
platform: 'node',
|
|
38
|
-
external: [
|
|
39
|
-
'commander',
|
|
40
|
-
'json-diff',
|
|
41
|
-
'glob',
|
|
42
|
-
'esbuild',
|
|
43
|
-
'drizzle-orm',
|
|
44
|
-
...driversPackages,
|
|
45
|
-
],
|
|
46
|
-
banner: {
|
|
47
|
-
js: `#!/usr/bin/env -S node --loader ./dist/loader.mjs --no-warnings`,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
cpSync('./src/loader.mjs', 'dist/loader.mjs');
|
package/build.ts
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
/// <reference types="bun-types" />
|
|
2
|
-
import * as esbuild from 'esbuild';
|
|
3
|
-
import { readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import * as tsup from 'tsup';
|
|
5
|
-
import pkg from './package.json';
|
|
6
|
-
|
|
7
|
-
const driversPackages = [
|
|
8
|
-
// postgres drivers
|
|
9
|
-
'pg',
|
|
10
|
-
'postgres',
|
|
11
|
-
'@vercel/postgres',
|
|
12
|
-
'@neondatabase/serverless',
|
|
13
|
-
'@electric-sql/pglite',
|
|
14
|
-
// mysql drivers
|
|
15
|
-
'mysql2',
|
|
16
|
-
'@planetscale/database',
|
|
17
|
-
// sqlite drivers
|
|
18
|
-
'@libsql/client',
|
|
19
|
-
'better-sqlite3',
|
|
20
|
-
'bun:sqlite',
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
esbuild.buildSync({
|
|
24
|
-
entryPoints: ['./src/utils.ts'],
|
|
25
|
-
bundle: true,
|
|
26
|
-
outfile: 'dist/utils.js',
|
|
27
|
-
format: 'cjs',
|
|
28
|
-
target: 'node16',
|
|
29
|
-
platform: 'node',
|
|
30
|
-
external: [
|
|
31
|
-
'commander',
|
|
32
|
-
'json-diff',
|
|
33
|
-
'glob',
|
|
34
|
-
'esbuild',
|
|
35
|
-
'drizzle-orm',
|
|
36
|
-
...driversPackages,
|
|
37
|
-
],
|
|
38
|
-
banner: {
|
|
39
|
-
js: `#!/usr/bin/env node`,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
esbuild.buildSync({
|
|
44
|
-
entryPoints: ['./src/utils.ts'],
|
|
45
|
-
bundle: true,
|
|
46
|
-
outfile: 'dist/utils.mjs',
|
|
47
|
-
format: 'esm',
|
|
48
|
-
target: 'node16',
|
|
49
|
-
platform: 'node',
|
|
50
|
-
external: [
|
|
51
|
-
'commander',
|
|
52
|
-
'json-diff',
|
|
53
|
-
'glob',
|
|
54
|
-
'esbuild',
|
|
55
|
-
'drizzle-orm',
|
|
56
|
-
...driversPackages,
|
|
57
|
-
],
|
|
58
|
-
banner: {
|
|
59
|
-
js: `#!/usr/bin/env node`,
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
esbuild.buildSync({
|
|
64
|
-
entryPoints: ['./src/cli/index.ts'],
|
|
65
|
-
bundle: true,
|
|
66
|
-
outfile: 'dist/bin.cjs',
|
|
67
|
-
format: 'cjs',
|
|
68
|
-
target: 'node16',
|
|
69
|
-
platform: 'node',
|
|
70
|
-
define: {
|
|
71
|
-
'process.env.DRIZZLE_KIT_VERSION': `"${pkg.version}"`,
|
|
72
|
-
},
|
|
73
|
-
external: [
|
|
74
|
-
'esbuild',
|
|
75
|
-
'drizzle-orm',
|
|
76
|
-
...driversPackages,
|
|
77
|
-
],
|
|
78
|
-
banner: {
|
|
79
|
-
js: `#!/usr/bin/env node`,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const main = async () => {
|
|
84
|
-
await tsup.build({
|
|
85
|
-
entryPoints: ['./src/index.ts', './src/api.ts'],
|
|
86
|
-
outDir: './dist',
|
|
87
|
-
external: ['bun:sqlite'],
|
|
88
|
-
splitting: false,
|
|
89
|
-
dts: true,
|
|
90
|
-
format: ['cjs', 'esm'],
|
|
91
|
-
outExtension: (ctx) => {
|
|
92
|
-
if (ctx.format === 'cjs') {
|
|
93
|
-
return {
|
|
94
|
-
dts: '.d.ts',
|
|
95
|
-
js: '.js',
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
dts: '.d.mts',
|
|
100
|
-
js: '.mjs',
|
|
101
|
-
};
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const apiCjs = readFileSync('./dist/api.js', 'utf8').replace(/await import\(/g, 'require(');
|
|
106
|
-
writeFileSync('./dist/api.js', apiCjs);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
main().catch((e) => {
|
|
110
|
-
console.error(e);
|
|
111
|
-
process.exit(1);
|
|
112
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import type { Node } from 'ohm-js';
|
|
3
|
-
import JSImports from './grammar/grammar.ohm-bundle';
|
|
4
|
-
|
|
5
|
-
export type CollectionItem = {
|
|
6
|
-
type: 'data' | 'types';
|
|
7
|
-
source: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
function recursiveRun(...args: Node[]): boolean {
|
|
11
|
-
for (const arg of args) {
|
|
12
|
-
if (
|
|
13
|
-
arg.ctorName === 'Rest'
|
|
14
|
-
|| arg.ctorName === 'comment'
|
|
15
|
-
|| arg.ctorName === 'stringLiteral'
|
|
16
|
-
) {
|
|
17
|
-
continue;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (
|
|
21
|
-
arg.ctorName === 'ImportExpr_From'
|
|
22
|
-
|| arg.ctorName === 'ImportExpr_NoFrom'
|
|
23
|
-
) {
|
|
24
|
-
arg['analyze']();
|
|
25
|
-
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (arg.isTerminal()) continue;
|
|
30
|
-
|
|
31
|
-
for (const c of arg.children) {
|
|
32
|
-
if (!recursiveRun(c)) return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
function init(collection: CollectionItem[]) {
|
|
39
|
-
const semantics = JSImports.createSemantics();
|
|
40
|
-
|
|
41
|
-
semantics.addOperation('analyze', {
|
|
42
|
-
JSImports(arg0, arg1) {
|
|
43
|
-
recursiveRun(arg0, arg1);
|
|
44
|
-
},
|
|
45
|
-
|
|
46
|
-
ImportExpr_From(kImport, importInner, kFrom, importSource) {
|
|
47
|
-
const ruleName = importInner.children[0]!.ctorName;
|
|
48
|
-
const importType = ruleName === 'ImportInner_Type' || ruleName === 'ImportInner_Types'
|
|
49
|
-
? 'types'
|
|
50
|
-
: 'data';
|
|
51
|
-
|
|
52
|
-
collection.push({
|
|
53
|
-
source: importSource.children[1]!.sourceString!,
|
|
54
|
-
type: importType,
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
ImportExpr_NoFrom(kImport, importSource) {
|
|
59
|
-
collection.push({
|
|
60
|
-
source: importSource.children[1]!.sourceString!,
|
|
61
|
-
type: 'data',
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return semantics;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function analyze(path: string) {
|
|
70
|
-
const file = readFileSync(path).toString();
|
|
71
|
-
const match = JSImports.match(file, 'JSImports');
|
|
72
|
-
|
|
73
|
-
if (match.failed()) throw new Error(`Failed to parse file: ${path}`);
|
|
74
|
-
const collection: CollectionItem[] = [];
|
|
75
|
-
|
|
76
|
-
init(collection)(match)['analyze']();
|
|
77
|
-
return collection;
|
|
78
|
-
}
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import m from 'micromatch';
|
|
3
|
-
import { dirname, join as joinPath, relative, resolve as resolvePath } from 'path';
|
|
4
|
-
import { analyze } from './analyze';
|
|
5
|
-
|
|
6
|
-
type External = {
|
|
7
|
-
file: string;
|
|
8
|
-
import: string;
|
|
9
|
-
type: 'data' | 'types';
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export type Issue = {
|
|
13
|
-
file: string;
|
|
14
|
-
imports: IssueImport[];
|
|
15
|
-
accessChains: ChainLink[][];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type IssueImport = {
|
|
19
|
-
name: string;
|
|
20
|
-
type: 'data' | 'types';
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export type ChainLink = {
|
|
24
|
-
file: string;
|
|
25
|
-
import: string;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type ListMode = 'whitelist' | 'blacklist';
|
|
29
|
-
|
|
30
|
-
class ImportAnalyzer {
|
|
31
|
-
private localImportRegex = /^(\.?\.?\/|\.\.?$)/;
|
|
32
|
-
private importedFileFormatRegex = /^.*\.(ts|tsx|mts|cts|js|jsx|mjs|cjs|json)$/i;
|
|
33
|
-
|
|
34
|
-
private visited: Set<string> = new Set<string>();
|
|
35
|
-
|
|
36
|
-
private externals: External[] = [];
|
|
37
|
-
private accessChains: Record<string, ChainLink[][]> = {};
|
|
38
|
-
|
|
39
|
-
constructor(
|
|
40
|
-
private basePath: string,
|
|
41
|
-
private entry: string,
|
|
42
|
-
private listMode: ListMode,
|
|
43
|
-
private readonly wantedList: string[],
|
|
44
|
-
private localPaths: string[],
|
|
45
|
-
private logger?: boolean,
|
|
46
|
-
private ignoreTypes?: boolean,
|
|
47
|
-
) {}
|
|
48
|
-
|
|
49
|
-
private isDirectory = (path: string) => {
|
|
50
|
-
try {
|
|
51
|
-
return fs.lstatSync(path).isDirectory();
|
|
52
|
-
} catch (e) {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
private isFile = (path: string) => {
|
|
58
|
-
try {
|
|
59
|
-
return fs.lstatSync(path).isFile();
|
|
60
|
-
} catch (e) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
private localizePath = (path: string) => relative(resolvePath(this.basePath), resolvePath(path));
|
|
66
|
-
|
|
67
|
-
private isCustomLocal = (importTarget: string) =>
|
|
68
|
-
!!this.localPaths.find(
|
|
69
|
-
(l) =>
|
|
70
|
-
importTarget === l
|
|
71
|
-
|| importTarget.startsWith(l.endsWith('/') ? l : `${l}/`),
|
|
72
|
-
);
|
|
73
|
-
private isLocal = (importTarget: string) =>
|
|
74
|
-
this.localImportRegex.test(importTarget)
|
|
75
|
-
|| this.isCustomLocal(importTarget);
|
|
76
|
-
private isTsFormat = (path: string) => this.importedFileFormatRegex.test(path);
|
|
77
|
-
|
|
78
|
-
private resolveCustomLocalPath = (
|
|
79
|
-
absoluteBase: string,
|
|
80
|
-
base: string,
|
|
81
|
-
target: string,
|
|
82
|
-
): string => {
|
|
83
|
-
return joinPath(absoluteBase, target);
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
private resolveTargetFile = (path: string): string => {
|
|
87
|
-
if (this.isFile(path)) return path;
|
|
88
|
-
|
|
89
|
-
const formats = [
|
|
90
|
-
'.ts',
|
|
91
|
-
'.mts',
|
|
92
|
-
'.cts',
|
|
93
|
-
'.tsx',
|
|
94
|
-
'.js',
|
|
95
|
-
'.mjs',
|
|
96
|
-
'.cjs',
|
|
97
|
-
'.jsx',
|
|
98
|
-
];
|
|
99
|
-
|
|
100
|
-
for (const format of formats) {
|
|
101
|
-
const indexPath = joinPath(path, `/index${format}`);
|
|
102
|
-
if (this.isFile(indexPath)) return indexPath;
|
|
103
|
-
|
|
104
|
-
const formatFilePath = `${path}${format}`;
|
|
105
|
-
if (this.isFile(formatFilePath)) return formatFilePath;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return path;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
private resolveTargetPath = (
|
|
112
|
-
absoluteBase: string,
|
|
113
|
-
base: string,
|
|
114
|
-
target: string,
|
|
115
|
-
): string => {
|
|
116
|
-
if (this.isCustomLocal(target)) {
|
|
117
|
-
return this.resolveTargetFile(
|
|
118
|
-
this.resolveCustomLocalPath(absoluteBase, base, target),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const dir = this.isDirectory(base) ? base : dirname(base);
|
|
123
|
-
const joined = joinPath(dir, target);
|
|
124
|
-
|
|
125
|
-
return this.resolveTargetFile(joined);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
private _analyzeImports = (
|
|
129
|
-
target: string = this.entry,
|
|
130
|
-
basePath: string = this.basePath,
|
|
131
|
-
accessChain: ChainLink[] = [],
|
|
132
|
-
) => {
|
|
133
|
-
if (this.visited.has(target)) return;
|
|
134
|
-
|
|
135
|
-
const locals: string[] = [];
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
if (this.logger) console.log(`${this.localizePath(target)}`);
|
|
139
|
-
|
|
140
|
-
const imports = analyze(target);
|
|
141
|
-
|
|
142
|
-
for (const { source: i, type } of imports) {
|
|
143
|
-
if (this.ignoreTypes && type === 'types') continue;
|
|
144
|
-
|
|
145
|
-
if (this.isLocal(i)) {
|
|
146
|
-
locals.push(i);
|
|
147
|
-
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
this.externals.push({
|
|
152
|
-
file: this.localizePath(target),
|
|
153
|
-
import: i,
|
|
154
|
-
type: type,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
} catch (e) {
|
|
158
|
-
throw e;
|
|
159
|
-
} finally {
|
|
160
|
-
this.visited.add(target);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
for (const local of locals) {
|
|
164
|
-
const transformedTarget = this.resolveTargetPath(basePath, target, local);
|
|
165
|
-
|
|
166
|
-
const localChain = [
|
|
167
|
-
...accessChain,
|
|
168
|
-
{
|
|
169
|
-
file: this.localizePath(target),
|
|
170
|
-
import: local,
|
|
171
|
-
},
|
|
172
|
-
];
|
|
173
|
-
|
|
174
|
-
const localized = this.localizePath(transformedTarget);
|
|
175
|
-
|
|
176
|
-
if (this.accessChains[localized]) {
|
|
177
|
-
this.accessChains[localized].push(localChain);
|
|
178
|
-
} else this.accessChains[localized] = [localChain];
|
|
179
|
-
|
|
180
|
-
if (this.isTsFormat(transformedTarget)) {
|
|
181
|
-
this._analyzeImports(transformedTarget, basePath, localChain);
|
|
182
|
-
} else {
|
|
183
|
-
throw new Error(`unrecognized: ${localized}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
public analyzeImports = () => {
|
|
189
|
-
const entryLocalized = this.localizePath(this.entry);
|
|
190
|
-
if (!this.accessChains[entryLocalized]) {
|
|
191
|
-
this.accessChains[entryLocalized] = [[]];
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
this._analyzeImports();
|
|
195
|
-
|
|
196
|
-
const rawIssues = this.listMode === 'whitelist'
|
|
197
|
-
? this.externals.filter((e) => !m([e.import], this.wantedList).length)
|
|
198
|
-
: this.externals.filter((e) => m([e.import], this.wantedList).length);
|
|
199
|
-
|
|
200
|
-
const issueMap: Record<string, Issue> = {};
|
|
201
|
-
for (const { file, import: i, type } of rawIssues) {
|
|
202
|
-
if (issueMap[file]) {
|
|
203
|
-
issueMap[file].imports.push({
|
|
204
|
-
name: i,
|
|
205
|
-
type,
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
continue;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
issueMap[file] = {
|
|
212
|
-
file,
|
|
213
|
-
imports: [
|
|
214
|
-
{
|
|
215
|
-
name: i,
|
|
216
|
-
type,
|
|
217
|
-
},
|
|
218
|
-
],
|
|
219
|
-
accessChains: this.accessChains[file]!,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
issues: Object.entries(issueMap).map(([file, data]) => {
|
|
225
|
-
for (const chain of data.accessChains) {
|
|
226
|
-
chain.push({
|
|
227
|
-
file,
|
|
228
|
-
import: '',
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
return data;
|
|
233
|
-
}),
|
|
234
|
-
accessChains: this.accessChains,
|
|
235
|
-
};
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
export type CustomLocalPathResolver = (
|
|
240
|
-
basePath: string,
|
|
241
|
-
path: string,
|
|
242
|
-
target: string,
|
|
243
|
-
) => string;
|
|
244
|
-
|
|
245
|
-
export type AnalyzeImportsConfig =
|
|
246
|
-
& {
|
|
247
|
-
basePath: string;
|
|
248
|
-
entry: string;
|
|
249
|
-
logger?: boolean;
|
|
250
|
-
ignoreTypes?: boolean;
|
|
251
|
-
localPaths?: string[];
|
|
252
|
-
}
|
|
253
|
-
& (
|
|
254
|
-
| {
|
|
255
|
-
blackList: string[];
|
|
256
|
-
}
|
|
257
|
-
| {
|
|
258
|
-
whiteList: string[];
|
|
259
|
-
}
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
type AnyAnalyzeImportsConfig = {
|
|
263
|
-
basePath: string;
|
|
264
|
-
entry: string;
|
|
265
|
-
blackList?: string[];
|
|
266
|
-
whiteList?: string[];
|
|
267
|
-
logger?: boolean;
|
|
268
|
-
ignoreTypes?: boolean;
|
|
269
|
-
localPaths?: string[];
|
|
270
|
-
};
|
|
271
|
-
|
|
272
|
-
export function analyzeImports(cfg: AnalyzeImportsConfig) {
|
|
273
|
-
const {
|
|
274
|
-
basePath,
|
|
275
|
-
blackList,
|
|
276
|
-
whiteList,
|
|
277
|
-
entry,
|
|
278
|
-
localPaths: localImports,
|
|
279
|
-
ignoreTypes,
|
|
280
|
-
logger,
|
|
281
|
-
} = cfg as AnyAnalyzeImportsConfig;
|
|
282
|
-
const mode = whiteList ? 'whitelist' : 'blacklist';
|
|
283
|
-
const wantedList = blackList ?? whiteList!;
|
|
284
|
-
|
|
285
|
-
const analyzer = new ImportAnalyzer(
|
|
286
|
-
joinPath(basePath),
|
|
287
|
-
joinPath(entry),
|
|
288
|
-
mode,
|
|
289
|
-
wantedList,
|
|
290
|
-
localImports ?? [],
|
|
291
|
-
logger,
|
|
292
|
-
ignoreTypes,
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
return analyzer.analyzeImports();
|
|
296
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
JSImports {
|
|
2
|
-
JSImports = (Expr ";"?)*
|
|
3
|
-
|
|
4
|
-
Expr =
|
|
5
|
-
| comment
|
|
6
|
-
| stringLiteral
|
|
7
|
-
| ImportExpr
|
|
8
|
-
| Rest
|
|
9
|
-
|
|
10
|
-
ImportExpr =
|
|
11
|
-
| "import" ImportInner "from" importSource -- From
|
|
12
|
-
| "import" importSource -- NoFrom
|
|
13
|
-
|
|
14
|
-
Rest = (~(ImportExpr | comment | stringLiteral) any)+
|
|
15
|
-
|
|
16
|
-
ImportInner =
|
|
17
|
-
| ("type" "{" NonemptyListOf<ImportExtendedSelectionTypeless, ","> ","? "}") -- Type
|
|
18
|
-
| ("{" NonemptyListOf<ImportExtendedSelectionTypes, ","> ","? "}") -- Types
|
|
19
|
-
| ("{" NonemptyListOf<ImportExtendedSelection, ","> ","? "}") -- Extended
|
|
20
|
-
| (identifier ("," "type"? "{" NonemptyListOf<ImportExtendedSelection, ","> ","? "}")?) -- Mixed
|
|
21
|
-
| ("*" ("as" identifier)?) -- All
|
|
22
|
-
| (identifier ("as" identifier)?) -- Default
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
ImportExtendedSelection = TypeImport | Import
|
|
26
|
-
ImportExtendedSelectionTypes = TypeImport
|
|
27
|
-
ImportExtendedSelectionTypeless = Import
|
|
28
|
-
|
|
29
|
-
Import = identifier ("as" identifier)?
|
|
30
|
-
TypeImport = "type" Import ("as" identifier)?
|
|
31
|
-
|
|
32
|
-
identifier = letter alnum*
|
|
33
|
-
quote = "\"" | "'" | "`"
|
|
34
|
-
notQuote = ~quote any
|
|
35
|
-
importSource =
|
|
36
|
-
| "\"" notQuote+ "\""
|
|
37
|
-
| "'" notQuote+ "'"
|
|
38
|
-
| "`" notQuote+ "`"
|
|
39
|
-
|
|
40
|
-
lineTerminator = "\n" | "\r" | "\u2028" | "\u2029"
|
|
41
|
-
lineTerminatorSequence = "\n" | "\r" ~"\n" | "\u2028" | "\u2029" | "\r\n"
|
|
42
|
-
|
|
43
|
-
comment = multiLineComment | singleLineComment
|
|
44
|
-
|
|
45
|
-
multiLineComment = "/*" (~"*/" any)* "*/"
|
|
46
|
-
singleLineComment = "//" (~lineTerminator any)*
|
|
47
|
-
|
|
48
|
-
stringLiteral =
|
|
49
|
-
| "\"" doubleStringCharacter* "\""
|
|
50
|
-
| "'" singleStringCharacter* "'"
|
|
51
|
-
| "`" templateStringCharacter* "`"
|
|
52
|
-
doubleStringCharacter =
|
|
53
|
-
| ~("\"" | "\\" | lineTerminator) any -- NonEscaped
|
|
54
|
-
| "\\" escapeSequence -- Escaped
|
|
55
|
-
| lineContinuation -- LineContinuation
|
|
56
|
-
singleStringCharacter =
|
|
57
|
-
| ~("'" | "\\" | lineTerminator) any -- NonEscaped
|
|
58
|
-
| "\\" escapeSequence -- Escaped
|
|
59
|
-
| lineContinuation -- LineContinuation
|
|
60
|
-
templateStringCharacter =
|
|
61
|
-
| ~ ("`" | "\\") any -- NonEscaped
|
|
62
|
-
| "\\" escapeSequence -- Escaped
|
|
63
|
-
lineContinuation = "\\" lineTerminatorSequence
|
|
64
|
-
escapeSequence = unicodeEscapeSequence | hexEscapeSequence | octalEscapeSequence | characterEscapeSequence
|
|
65
|
-
characterEscapeSequence = singleEscapeCharacter | nonEscapeCharacter
|
|
66
|
-
singleEscapeCharacter = "'" | "\"" | "\\" | "b" | "f" | "n" | "r" | "t" | "v"
|
|
67
|
-
nonEscapeCharacter = ~(escapeCharacter | lineTerminator) any
|
|
68
|
-
escapeCharacter = singleEscapeCharacter | decimalDigit | "x" | "u"
|
|
69
|
-
octalEscapeSequence =
|
|
70
|
-
| zeroToThree octalDigit octalDigit -- Whole
|
|
71
|
-
| fourToSeven octalDigit -- EightTimesfourToSeven
|
|
72
|
-
| zeroToThree octalDigit ~decimalDigit -- EightTimesZeroToThree
|
|
73
|
-
| octalDigit ~decimalDigit -- Octal
|
|
74
|
-
hexEscapeSequence = "x" hexDigit hexDigit
|
|
75
|
-
unicodeEscapeSequence = "u" hexDigit hexDigit hexDigit hexDigit
|
|
76
|
-
|
|
77
|
-
zeroToThree = "0".."3"
|
|
78
|
-
fourToSeven = "4".."7"
|
|
79
|
-
decimalDigit = "0".."9"
|
|
80
|
-
nonZeroDigit = "1".."9"
|
|
81
|
-
octalDigit = "0".."7"
|
|
82
|
-
|
|
83
|
-
regularExpressionLiteral = "/" regularExpressionBody "/" regularExpressionFlags
|
|
84
|
-
regularExpressionBody = regularExpressionFirstChar regularExpressionChar*
|
|
85
|
-
regularExpressionFirstChar =
|
|
86
|
-
| ~("*" | "\\" | "/" | "[") regularExpressionNonTerminator
|
|
87
|
-
| regularExpressionBackslashSequence
|
|
88
|
-
| regularExpressionClass
|
|
89
|
-
regularExpressionChar = ~("\\" | "/" | "[") regularExpressionNonTerminator
|
|
90
|
-
| regularExpressionBackslashSequence
|
|
91
|
-
| regularExpressionClass
|
|
92
|
-
regularExpressionBackslashSequence = "\\" regularExpressionNonTerminator
|
|
93
|
-
regularExpressionNonTerminator = ~(lineTerminator) any
|
|
94
|
-
regularExpressionClass = "[" regularExpressionClassChar* "]"
|
|
95
|
-
regularExpressionClassChar =
|
|
96
|
-
| ~("]" | "\\") regularExpressionNonTerminator
|
|
97
|
-
| regularExpressionBackslashSequence
|
|
98
|
-
regularExpressionFlags = identifierPart*
|
|
99
|
-
|
|
100
|
-
multiLineCommentNoNL = "/*" (~("*/" | lineTerminator) any)* "*/"
|
|
101
|
-
|
|
102
|
-
identifierStart =
|
|
103
|
-
| letter | "$" | "_"
|
|
104
|
-
| "\\" unicodeEscapeSequence -- escaped
|
|
105
|
-
identifierPart =
|
|
106
|
-
| identifierStart | unicodeCombiningMark
|
|
107
|
-
| unicodeDigit | unicodeConnectorPunctuation
|
|
108
|
-
| "\u200C" | "\u200D"
|
|
109
|
-
letter += unicodeCategoryNl
|
|
110
|
-
unicodeCategoryNl
|
|
111
|
-
= "\u2160".."\u2182" | "\u3007" | "\u3021".."\u3029"
|
|
112
|
-
unicodeDigit (a digit)
|
|
113
|
-
= "\u0030".."\u0039" | "\u0660".."\u0669" | "\u06F0".."\u06F9" | "\u0966".."\u096F" | "\u09E6".."\u09EF" | "\u0A66".."\u0A6F" | "\u0AE6".."\u0AEF" | "\u0B66".."\u0B6F" | "\u0BE7".."\u0BEF" | "\u0C66".."\u0C6F" | "\u0CE6".."\u0CEF" | "\u0D66".."\u0D6F" | "\u0E50".."\u0E59" | "\u0ED0".."\u0ED9" | "\u0F20".."\u0F29" | "\uFF10".."\uFF19"
|
|
114
|
-
|
|
115
|
-
unicodeCombiningMark (a Unicode combining mark)
|
|
116
|
-
= "\u0300".."\u0345" | "\u0360".."\u0361" | "\u0483".."\u0486" | "\u0591".."\u05A1" | "\u05A3".."\u05B9" | "\u05BB".."\u05BD" | "\u05BF".."\u05BF" | "\u05C1".."\u05C2" | "\u05C4".."\u05C4" | "\u064B".."\u0652" | "\u0670".."\u0670" | "\u06D6".."\u06DC" | "\u06DF".."\u06E4" | "\u06E7".."\u06E8" | "\u06EA".."\u06ED" | "\u0901".."\u0902" | "\u093C".."\u093C" | "\u0941".."\u0948" | "\u094D".."\u094D" | "\u0951".."\u0954" | "\u0962".."\u0963" | "\u0981".."\u0981" | "\u09BC".."\u09BC" | "\u09C1".."\u09C4" | "\u09CD".."\u09CD" | "\u09E2".."\u09E3" | "\u0A02".."\u0A02" | "\u0A3C".."\u0A3C" | "\u0A41".."\u0A42" | "\u0A47".."\u0A48" | "\u0A4B".."\u0A4D" | "\u0A70".."\u0A71" | "\u0A81".."\u0A82" | "\u0ABC".."\u0ABC" | "\u0AC1".."\u0AC5" | "\u0AC7".."\u0AC8" | "\u0ACD".."\u0ACD" | "\u0B01".."\u0B01" | "\u0B3C".."\u0B3C" | "\u0B3F".."\u0B3F" | "\u0B41".."\u0B43" | "\u0B4D".."\u0B4D" | "\u0B56".."\u0B56" | "\u0B82".."\u0B82" | "\u0BC0".."\u0BC0" | "\u0BCD".."\u0BCD" | "\u0C3E".."\u0C40" | "\u0C46".."\u0C48" | "\u0C4A".."\u0C4D" | "\u0C55".."\u0C56" | "\u0CBF".."\u0CBF" | "\u0CC6".."\u0CC6" | "\u0CCC".."\u0CCD" | "\u0D41".."\u0D43" | "\u0D4D".."\u0D4D" | "\u0E31".."\u0E31" | "\u0E34".."\u0E3A" | "\u0E47".."\u0E4E" | "\u0EB1".."\u0EB1" | "\u0EB4".."\u0EB9" | "\u0EBB".."\u0EBC" | "\u0EC8".."\u0ECD" | "\u0F18".."\u0F19" | "\u0F35".."\u0F35" | "\u0F37".."\u0F37" | "\u0F39".."\u0F39" | "\u0F71".."\u0F7E" | "\u0F80".."\u0F84" | "\u0F86".."\u0F87" | "\u0F90".."\u0F95" | "\u0F97".."\u0F97" | "\u0F99".."\u0FAD" | "\u0FB1".."\u0FB7" | "\u0FB9".."\u0FB9" | "\u20D0".."\u20DC" | "\u20E1".."\u20E1" | "\u302A".."\u302F" | "\u3099".."\u309A" | "\uFB1E".."\uFB1E" | "\uFE20".."\uFE23"
|
|
117
|
-
|
|
118
|
-
unicodeConnectorPunctuation = "\u005F" | "\u203F".."\u2040" | "\u30FB" | "\uFE33".."\uFE34" | "\uFE4D".."\uFE4F" | "\uFF3F" | "\uFF65"
|
|
119
|
-
unicodeSpaceSeparator = "\u2000".."\u200B" | "\u3000"
|
|
120
|
-
|
|
121
|
-
}
|