knip 6.15.0 → 6.16.1
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/dist/ConfigurationChief.d.ts +20 -0
- package/dist/ConfigurationChief.js +2 -1
- package/dist/ProjectPrincipal.d.ts +4 -1
- package/dist/ProjectPrincipal.js +21 -13
- package/dist/binaries/fallback.js +1 -1
- package/dist/binaries/plugins.js +1 -1
- package/dist/binaries/resolvers/bun.js +1 -1
- package/dist/binaries/resolvers/bunx.js +1 -1
- package/dist/binaries/resolvers/npm.js +1 -1
- package/dist/binaries/resolvers/npx.js +1 -1
- package/dist/binaries/resolvers/pnpm.js +1 -1
- package/dist/binaries/resolvers/pnpx.js +1 -1
- package/dist/binaries/resolvers/yarn.js +1 -1
- package/dist/binaries/util.d.ts +1 -2
- package/dist/binaries/util.js +1 -1
- package/dist/compilers/index.d.ts +31 -0
- package/dist/graph/analyze.js +8 -7
- package/dist/graph/build.js +4 -3
- package/dist/plugins/_custom-elements/custom-element-visitor.d.ts +7 -0
- package/dist/plugins/_custom-elements/custom-element-visitor.js +106 -0
- package/dist/plugins/bun/index.js +1 -1
- package/dist/plugins/catalyst/index.d.ts +3 -0
- package/dist/plugins/catalyst/index.js +16 -0
- package/dist/plugins/execa/visitors/execa.js +4 -17
- package/dist/plugins/fast/index.d.ts +3 -0
- package/dist/plugins/fast/index.js +16 -0
- package/dist/plugins/index.d.ts +3 -0
- package/dist/plugins/index.js +6 -0
- package/dist/plugins/lit/index.d.ts +3 -0
- package/dist/plugins/lit/index.js +25 -0
- package/dist/plugins/nano-spawn/visitors/nano-spawn.js +4 -17
- package/dist/plugins/relay/index.js +1 -1
- package/dist/plugins/stencil/index.js +17 -1
- package/dist/plugins/sveltejs-package/helpers.js +1 -1
- package/dist/schema/configuration.d.ts +51 -0
- package/dist/schema/configuration.js +1 -0
- package/dist/schema/plugins.d.ts +15 -0
- package/dist/schema/plugins.js +3 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +3 -0
- package/dist/types/args.d.ts +1 -1
- package/dist/types/config.d.ts +2 -0
- package/dist/types/module-graph.d.ts +1 -0
- package/dist/types/project.d.ts +1 -0
- package/dist/typescript/ast-helpers.js +21 -20
- package/dist/typescript/ast-nodes.d.ts +1 -0
- package/dist/typescript/ast-nodes.js +19 -0
- package/dist/typescript/get-imports-and-exports.js +18 -2
- package/dist/typescript/resolve-module-names.d.ts +11 -1
- package/dist/typescript/resolve-module-names.js +49 -12
- package/dist/typescript/visitors/calls.d.ts +3 -2
- package/dist/typescript/visitors/calls.js +88 -16
- package/dist/typescript/visitors/exports.js +12 -0
- package/dist/typescript/visitors/walk.d.ts +7 -0
- package/dist/typescript/visitors/walk.js +36 -1
- package/dist/util/create-options.d.ts +31 -0
- package/dist/util/load-tsconfig.js +2 -0
- package/dist/util/parse-args.d.ts +14 -0
- package/dist/util/parse-args.js +112 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -3
- package/schema.json +61 -43
|
@@ -9,6 +9,8 @@ import { extractImportsFromComments } from './comments.js';
|
|
|
9
9
|
import { _parseFile, buildLineStarts, getLineAndCol, shouldCountRefs, } from './ast-nodes.js';
|
|
10
10
|
import { buildJSDocTagLookup } from './visitors/jsdoc.js';
|
|
11
11
|
import { _walkAST } from './visitors/walk.js';
|
|
12
|
+
const EMPTY_CHILD_PROCESS_NAMES = new Set();
|
|
13
|
+
const EMPTY_CHILD_PROCESS_METHODS = new Map();
|
|
12
14
|
const getImportsAndExports = (filePath, sourceText, resolveModule, options, ignoreExportsUsedInFile, skipExportsForFile, visitor, pluginCtx, cachedParseResult) => {
|
|
13
15
|
const skipExports = skipExportsForFile || !options.isReportExports;
|
|
14
16
|
const isDts = filePath.endsWith('.d.ts') || filePath.endsWith('.d.cts') || filePath.endsWith('.d.mts');
|
|
@@ -34,6 +36,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
34
36
|
const localDeclarationTypes = new Map();
|
|
35
37
|
const referencedInExport = new Map();
|
|
36
38
|
const destructuredExports = new Set();
|
|
39
|
+
const registeredCustomElements = new Set();
|
|
37
40
|
const addNsMemberRefs = (internalImport, namespace, member) => {
|
|
38
41
|
if (typeof member === 'string') {
|
|
39
42
|
internalImport.refs.add(`${namespace}.${member}`);
|
|
@@ -167,15 +170,18 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
167
170
|
let hasChildProcessImport = false;
|
|
168
171
|
let hasPathJoinImport = false;
|
|
169
172
|
let hasPathResolveImport = false;
|
|
173
|
+
let childProcessNamespaces;
|
|
174
|
+
let childProcessMethods;
|
|
170
175
|
for (const _imports of result.module.staticImports) {
|
|
171
176
|
const specifier = _imports.moduleRequest.value;
|
|
177
|
+
const isPathImport = specifier === 'node:path' || specifier === 'path';
|
|
178
|
+
const isChildProcessImport = specifier === 'node:child_process' || specifier === 'child_process';
|
|
172
179
|
if (specifier === 'node:module' || specifier === 'module')
|
|
173
180
|
hasNodeModuleImport = true;
|
|
174
181
|
else if (specifier === 'node:worker_threads' || specifier === 'worker_threads')
|
|
175
182
|
hasWorkerThreadsImport = true;
|
|
176
|
-
else if (
|
|
183
|
+
else if (isChildProcessImport)
|
|
177
184
|
hasChildProcessImport = true;
|
|
178
|
-
const isPathImport = specifier === 'node:path' || specifier === 'path';
|
|
179
185
|
const pos = _imports.moduleRequest.start;
|
|
180
186
|
const jsdocTags = getJSDocTags(_imports.start);
|
|
181
187
|
if (_imports.entries.length === 0) {
|
|
@@ -190,12 +196,16 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
190
196
|
const modifiers = entry.isType ? IMPORT_FLAGS.TYPE_ONLY : IMPORT_FLAGS.NONE;
|
|
191
197
|
if (entry.importName.kind === 'NamespaceObject') {
|
|
192
198
|
const localName = entry.localName.value;
|
|
199
|
+
if (isChildProcessImport)
|
|
200
|
+
(childProcessNamespaces ??= new Set()).add(localName);
|
|
193
201
|
addImport(specifier, IMPORT_STAR, localName, undefined, entry.localName.start, modifiers, pos, jsdocTags, resolved);
|
|
194
202
|
if (internalPath)
|
|
195
203
|
localImportMap.set(localName, { importedName: IMPORT_STAR, filePath: internalPath, isNamespace: true });
|
|
196
204
|
}
|
|
197
205
|
else if (entry.importName.kind === 'Default') {
|
|
198
206
|
const localName = entry.localName.value;
|
|
207
|
+
if (isChildProcessImport)
|
|
208
|
+
(childProcessNamespaces ??= new Set()).add(localName);
|
|
199
209
|
const alias = localName !== 'default' ? localName : undefined;
|
|
200
210
|
addImport(specifier, 'default', alias, undefined, entry.localName.start, modifiers, pos, jsdocTags, resolved);
|
|
201
211
|
if (internalPath)
|
|
@@ -205,6 +215,8 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
205
215
|
const importedName = entry.importName.name;
|
|
206
216
|
const localName = entry.localName.value;
|
|
207
217
|
const alias = localName !== importedName ? localName : undefined;
|
|
218
|
+
if (isChildProcessImport)
|
|
219
|
+
(childProcessMethods ??= new Map()).set(localName, importedName);
|
|
208
220
|
if (isPathImport && !alias) {
|
|
209
221
|
if (importedName === 'join')
|
|
210
222
|
hasPathJoinImport = true;
|
|
@@ -254,6 +266,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
254
266
|
pluginCtx.sourceText = sourceText;
|
|
255
267
|
pluginCtx.addScript = (s) => scripts.add(s);
|
|
256
268
|
pluginCtx.addImport = (spec, pos, mod) => addImport(spec, undefined, undefined, undefined, pos, mod);
|
|
269
|
+
pluginCtx.markExportRegistered = (name) => registeredCustomElements.add(name);
|
|
257
270
|
}
|
|
258
271
|
const localRefs = _walkAST(result.program, sourceText, filePath, {
|
|
259
272
|
lineStarts,
|
|
@@ -277,6 +290,9 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
277
290
|
hasNodeModuleImport,
|
|
278
291
|
hasWorkerThreadsImport,
|
|
279
292
|
hasChildProcessImport,
|
|
293
|
+
childProcessNamespaces: childProcessNamespaces ?? EMPTY_CHILD_PROCESS_NAMES,
|
|
294
|
+
childProcessMethods: childProcessMethods ?? EMPTY_CHILD_PROCESS_METHODS,
|
|
295
|
+
registeredCustomElements,
|
|
280
296
|
hasPathJoinImport,
|
|
281
297
|
hasPathResolveImport,
|
|
282
298
|
resolveModule,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import type { ToSourceFilePath, WorkspaceManifestHandler } from '../util/to-source-path.ts';
|
|
2
2
|
import type { ResolveModule } from './ast-nodes.ts';
|
|
3
|
+
type ScopedPaths = Array<{
|
|
4
|
+
scope: string;
|
|
5
|
+
paths: Record<string, string[]>;
|
|
6
|
+
}>;
|
|
7
|
+
type ScopedRootDirs = Array<{
|
|
8
|
+
scope: string;
|
|
9
|
+
rootDirs: string[];
|
|
10
|
+
}>;
|
|
3
11
|
export declare function clearModuleResolutionCaches(): void;
|
|
4
12
|
export declare function createCustomModuleResolver(compilerOptions: {
|
|
5
|
-
|
|
13
|
+
scopedPaths?: ScopedPaths;
|
|
14
|
+
scopedRootDirs?: ScopedRootDirs;
|
|
6
15
|
}, customCompilerExtensions: string[], toSourceFilePath: ToSourceFilePath, findWorkspaceManifestImports?: WorkspaceManifestHandler): ResolveModule;
|
|
16
|
+
export {};
|
|
@@ -27,27 +27,42 @@ export function clearModuleResolutionCaches() {
|
|
|
27
27
|
for (const cache of moduleResolutionCaches)
|
|
28
28
|
cache.clear();
|
|
29
29
|
}
|
|
30
|
-
function compilePathMappings(
|
|
31
|
-
if (!
|
|
30
|
+
function compilePathMappings(scopedPaths) {
|
|
31
|
+
if (!scopedPaths)
|
|
32
32
|
return undefined;
|
|
33
33
|
const mappings = [];
|
|
34
|
-
for (const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
for (const { scope, paths } of scopedPaths) {
|
|
35
|
+
for (const key in paths) {
|
|
36
|
+
const starIndex = key.indexOf('*');
|
|
37
|
+
if (starIndex >= 0) {
|
|
38
|
+
mappings.push({ prefix: key.slice(0, starIndex), wildcard: true, values: paths[key], scope });
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
mappings.push({ prefix: key, wildcard: false, values: paths[key], scope });
|
|
42
|
+
}
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
if (mappings.length === 0)
|
|
46
|
+
return undefined;
|
|
47
|
+
mappings.sort((a, b) => b.scope.length - a.scope.length);
|
|
48
|
+
return mappings;
|
|
49
|
+
}
|
|
50
|
+
function compileRootDirs(scopedRootDirs) {
|
|
51
|
+
if (!scopedRootDirs)
|
|
52
|
+
return undefined;
|
|
53
|
+
const scoped = scopedRootDirs.filter(({ rootDirs }) => rootDirs.length > 1);
|
|
54
|
+
if (scoped.length === 0)
|
|
55
|
+
return undefined;
|
|
56
|
+
scoped.sort((a, b) => b.scope.length - a.scope.length);
|
|
57
|
+
return scoped;
|
|
44
58
|
}
|
|
45
59
|
export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspaceManifestImports) {
|
|
46
60
|
const customCompilerExtensionsSet = new Set(customCompilerExtensions);
|
|
47
61
|
const hasCustomExts = customCompilerExtensionsSet.size > 0;
|
|
48
62
|
const extensions = [...DEFAULT_EXTENSIONS, ...customCompilerExtensions, ...DTS_EXTENSIONS];
|
|
49
63
|
const resolveSync = hasCustomExts ? _createSyncModuleResolver(extensions) : _resolveModuleSync;
|
|
50
|
-
const pathMappings = compilePathMappings(compilerOptions.
|
|
64
|
+
const pathMappings = compilePathMappings(compilerOptions.scopedPaths);
|
|
65
|
+
const rootDirMappings = compileRootDirs(compilerOptions.scopedRootDirs);
|
|
51
66
|
function toSourcePath(resolvedFileName) {
|
|
52
67
|
if (!hasCustomExts || !customCompilerExtensionsSet.has(extname(resolvedFileName))) {
|
|
53
68
|
return toSourceFilePath(resolvedFileName) || resolvedFileName;
|
|
@@ -86,7 +101,10 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
86
101
|
if (resolvedFileName)
|
|
87
102
|
return toResult(resolvedFileName);
|
|
88
103
|
if (pathMappings) {
|
|
89
|
-
|
|
104
|
+
const dir = dirname(containingFile);
|
|
105
|
+
for (const { prefix, wildcard, values, scope } of pathMappings) {
|
|
106
|
+
if (dir !== scope && !dir.startsWith(`${scope}/`))
|
|
107
|
+
continue;
|
|
90
108
|
if (wildcard ? specifier.startsWith(prefix) : specifier === prefix) {
|
|
91
109
|
const captured = wildcard ? specifier.slice(prefix.length) : '';
|
|
92
110
|
for (const value of values) {
|
|
@@ -99,6 +117,25 @@ export function createCustomModuleResolver(compilerOptions, customCompilerExtens
|
|
|
99
117
|
}
|
|
100
118
|
}
|
|
101
119
|
}
|
|
120
|
+
if (rootDirMappings && !isAbsolute(specifier)) {
|
|
121
|
+
const dir = dirname(containingFile);
|
|
122
|
+
for (const { scope, rootDirs } of rootDirMappings) {
|
|
123
|
+
if (dir !== scope && !dir.startsWith(`${scope}/`))
|
|
124
|
+
continue;
|
|
125
|
+
for (const rootDir of rootDirs) {
|
|
126
|
+
if (dir !== rootDir && !dir.startsWith(`${rootDir}/`))
|
|
127
|
+
continue;
|
|
128
|
+
const relPath = dir === rootDir ? '' : dir.slice(rootDir.length + 1);
|
|
129
|
+
for (const targetRoot of rootDirs) {
|
|
130
|
+
if (targetRoot === rootDir)
|
|
131
|
+
continue;
|
|
132
|
+
const resolved = resolveSync(join(targetRoot, relPath, specifier), containingFile);
|
|
133
|
+
if (resolved)
|
|
134
|
+
return toResult(resolved);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
102
139
|
if (specifier.startsWith('#') && findWorkspaceManifestImports) {
|
|
103
140
|
const ws = findWorkspaceManifestImports(containingFile);
|
|
104
141
|
if (ws) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { CallExpression, NewExpression } from 'oxc-parser';
|
|
2
|
-
import type
|
|
1
|
+
import type { CallExpression, NewExpression, VariableDeclarator } from 'oxc-parser';
|
|
2
|
+
import { type WalkState } from './walk.ts';
|
|
3
|
+
export declare function trackCustomElementRegistry(node: VariableDeclarator, s: WalkState): void;
|
|
3
4
|
export declare function handleCallExpression(node: CallExpression, s: WalkState): void;
|
|
4
5
|
export declare function handleNewExpression(node: NewExpression, s: WalkState): void;
|
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
|
|
2
2
|
import { addValue } from '../../util/module-graph.js';
|
|
3
|
-
import { getStringValue, isStringLiteral } from '../ast-nodes.js';
|
|
3
|
+
import { getSafeScriptFromArgs, getStringValue, isStringLiteral } from '../ast-nodes.js';
|
|
4
|
+
import { isShadowed } from './walk.js';
|
|
5
|
+
function getRegisteredCustomElement(node, s) {
|
|
6
|
+
const callee = node.callee;
|
|
7
|
+
if (callee.type !== 'MemberExpression' || callee.computed)
|
|
8
|
+
return undefined;
|
|
9
|
+
if (callee.property.type !== 'Identifier' || callee.property.name !== 'define')
|
|
10
|
+
return undefined;
|
|
11
|
+
const object = callee.object;
|
|
12
|
+
let isRegistry;
|
|
13
|
+
if (object.type === 'Identifier') {
|
|
14
|
+
isRegistry =
|
|
15
|
+
(object.name === 'customElements' || s.customElementRegistries.has(object.name)) &&
|
|
16
|
+
!isShadowed(object.name, object.start);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
isRegistry =
|
|
20
|
+
object.type === 'MemberExpression' &&
|
|
21
|
+
!object.computed &&
|
|
22
|
+
object.property.type === 'Identifier' &&
|
|
23
|
+
object.property.name === 'customElements';
|
|
24
|
+
}
|
|
25
|
+
if (!isRegistry)
|
|
26
|
+
return undefined;
|
|
27
|
+
const arg = node.arguments[1];
|
|
28
|
+
if (arg?.type === 'Identifier')
|
|
29
|
+
return isShadowed(arg.name, arg.start) ? undefined : arg.name;
|
|
30
|
+
if (arg?.type === 'ThisExpression' && s.staticBlockDepth > 0)
|
|
31
|
+
return s.classNameStack[s.classNameStack.length - 1] || undefined;
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
export function trackCustomElementRegistry(node, s) {
|
|
35
|
+
if (node.id.type !== 'Identifier' || !node.init)
|
|
36
|
+
return;
|
|
37
|
+
const init = node.init;
|
|
38
|
+
if ((init.type === 'Identifier' && init.name === 'customElements' && !isShadowed('customElements', init.start)) ||
|
|
39
|
+
(init.type === 'MemberExpression' &&
|
|
40
|
+
!init.computed &&
|
|
41
|
+
init.property.type === 'Identifier' &&
|
|
42
|
+
init.property.name === 'customElements') ||
|
|
43
|
+
(init.type === 'NewExpression' && init.callee.type === 'Identifier' && init.callee.name === 'CustomElementRegistry')) {
|
|
44
|
+
s.customElementRegistries.add(node.id.name);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
4
47
|
function extractInlineDirnamePath(node, s) {
|
|
5
48
|
if (node?.type !== 'CallExpression')
|
|
6
49
|
return undefined;
|
|
@@ -41,8 +84,28 @@ function extractInlineDirnamePath(node, s) {
|
|
|
41
84
|
const joined = parts.join('/').replace(/\/+/g, '/');
|
|
42
85
|
return joined.startsWith('.') || joined.startsWith('/') ? joined : `./${joined}`;
|
|
43
86
|
}
|
|
44
|
-
const
|
|
87
|
+
const CHILD_PROCESS_FILE_METHODS = new Set(['fork', 'spawn', 'spawnSync', 'execFile', 'execFileSync']);
|
|
88
|
+
const CHILD_PROCESS_COMMAND_METHODS = new Set(['exec', 'execSync']);
|
|
89
|
+
function getChildProcessMethod(node, s) {
|
|
90
|
+
const callee = node.callee;
|
|
91
|
+
if (callee.type === 'Identifier')
|
|
92
|
+
return s.childProcessMethods.get(callee.name);
|
|
93
|
+
if (callee.type === 'MemberExpression' &&
|
|
94
|
+
!callee.computed &&
|
|
95
|
+
callee.object.type === 'Identifier' &&
|
|
96
|
+
callee.property.type === 'Identifier' &&
|
|
97
|
+
s.childProcessNamespaces.has(callee.object.name))
|
|
98
|
+
return callee.property.name;
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
45
101
|
export function handleCallExpression(node, s) {
|
|
102
|
+
if (node.arguments.length >= 2) {
|
|
103
|
+
const registered = getRegisteredCustomElement(node, s);
|
|
104
|
+
if (registered) {
|
|
105
|
+
s.registeredCustomElements.add(registered);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
46
109
|
if (node.callee.type === 'Identifier' &&
|
|
47
110
|
node.callee.name === 'require' &&
|
|
48
111
|
node.arguments.length === 1 &&
|
|
@@ -95,22 +158,31 @@ export function handleCallExpression(node, s) {
|
|
|
95
158
|
}
|
|
96
159
|
}
|
|
97
160
|
if (s.hasChildProcessImport && node.arguments.length >= 1) {
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
if (isChildProcessEntry) {
|
|
109
|
-
const specifier = extractInlineDirnamePath(node.arguments[0], s);
|
|
110
|
-
if (specifier) {
|
|
111
|
-
s.addImport(specifier, undefined, undefined, undefined, node.arguments[0].start, IMPORT_FLAGS.ENTRY);
|
|
161
|
+
const method = getChildProcessMethod(node, s);
|
|
162
|
+
if (method) {
|
|
163
|
+
const arg = node.arguments[0];
|
|
164
|
+
if (CHILD_PROCESS_COMMAND_METHODS.has(method)) {
|
|
165
|
+
if (isStringLiteral(arg)) {
|
|
166
|
+
const command = getStringValue(arg);
|
|
167
|
+
if (command)
|
|
168
|
+
s.scripts.add(command);
|
|
169
|
+
}
|
|
112
170
|
return;
|
|
113
171
|
}
|
|
172
|
+
if (CHILD_PROCESS_FILE_METHODS.has(method)) {
|
|
173
|
+
const specifier = extractInlineDirnamePath(arg, s);
|
|
174
|
+
if (specifier) {
|
|
175
|
+
s.addImport(specifier, undefined, undefined, undefined, arg.start, IMPORT_FLAGS.ENTRY);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (method !== 'fork') {
|
|
179
|
+
const script = getSafeScriptFromArgs(arg, node.arguments[1]);
|
|
180
|
+
if (script) {
|
|
181
|
+
s.scripts.add(script);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
114
186
|
}
|
|
115
187
|
}
|
|
116
188
|
if (node.callee.type === 'MemberExpression' &&
|
|
@@ -3,6 +3,13 @@ import { addNsValue, addValue } from '../../util/module-graph.js';
|
|
|
3
3
|
import { extractEnumMembers, extractNamespaceMembers, getLineAndCol, getStringValue, isStringLiteral, } from '../ast-nodes.js';
|
|
4
4
|
import { EMPTY_TAGS } from './jsdoc.js';
|
|
5
5
|
const getName = (n) => (n?.type === 'Identifier' ? n.name : undefined);
|
|
6
|
+
const addLocalToExport = (s, local, exported) => {
|
|
7
|
+
const set = s.localToExports.get(local);
|
|
8
|
+
if (set)
|
|
9
|
+
set.add(exported);
|
|
10
|
+
else
|
|
11
|
+
s.localToExports.set(local, new Set([exported]));
|
|
12
|
+
};
|
|
6
13
|
const hasExplicitFunctionReturnType = (node) => !!node &&
|
|
7
14
|
(node.type === 'ArrowFunctionExpression' ||
|
|
8
15
|
node.type === 'FunctionExpression' ||
|
|
@@ -214,6 +221,8 @@ export function handleExportNamed(node, s) {
|
|
|
214
221
|
s.addExport(exportedName, type, spec.exported?.start ?? spec.start, [], fix, isReExport, s.getJSDocTags(node.start));
|
|
215
222
|
if (exportedName)
|
|
216
223
|
s.specifierExportNames.add(exportedName);
|
|
224
|
+
if (localName && exportedName)
|
|
225
|
+
addLocalToExport(s, localName, exportedName);
|
|
217
226
|
}
|
|
218
227
|
}
|
|
219
228
|
}
|
|
@@ -240,6 +249,8 @@ export function handleExportDefault(node, s) {
|
|
|
240
249
|
pos = decl.id?.start ?? decl.start;
|
|
241
250
|
members = [];
|
|
242
251
|
s.collectRefsInType(decl, 'default', true);
|
|
252
|
+
if (decl.id)
|
|
253
|
+
addLocalToExport(s, decl.id.name, 'default');
|
|
243
254
|
}
|
|
244
255
|
else if (decl.type === 'TSInterfaceDeclaration') {
|
|
245
256
|
type = SYMBOL_TYPE.INTERFACE;
|
|
@@ -249,6 +260,7 @@ export function handleExportDefault(node, s) {
|
|
|
249
260
|
else if (decl.type === 'Identifier') {
|
|
250
261
|
type = s.localDeclarationTypes.get(decl.name) ?? SYMBOL_TYPE.UNKNOWN;
|
|
251
262
|
pos = decl.start;
|
|
263
|
+
addLocalToExport(s, decl.name, 'default');
|
|
252
264
|
const _import = s.localImportMap.get(decl.name);
|
|
253
265
|
if (_import) {
|
|
254
266
|
const internalImport = s.internal.get(_import.filePath);
|
|
@@ -35,6 +35,9 @@ interface WalkContext {
|
|
|
35
35
|
hasNodeModuleImport: boolean;
|
|
36
36
|
hasWorkerThreadsImport: boolean;
|
|
37
37
|
hasChildProcessImport: boolean;
|
|
38
|
+
childProcessNamespaces: ReadonlySet<string>;
|
|
39
|
+
childProcessMethods: ReadonlyMap<string, string>;
|
|
40
|
+
registeredCustomElements: Set<string>;
|
|
38
41
|
hasPathJoinImport: boolean;
|
|
39
42
|
hasPathResolveImport: boolean;
|
|
40
43
|
resolveModule: ResolveModule;
|
|
@@ -72,6 +75,10 @@ export interface WalkState extends WalkContext {
|
|
|
72
75
|
exportName: string;
|
|
73
76
|
seen: Set<string>;
|
|
74
77
|
}>;
|
|
78
|
+
localToExports: Map<string, Set<string>>;
|
|
79
|
+
customElementRegistries: Set<string>;
|
|
80
|
+
classNameStack: string[];
|
|
81
|
+
staticBlockDepth: number;
|
|
75
82
|
addExport: (identifier: string, type: SymbolType, pos: number, members: ExportMember[], fix: Fix, isReExport: boolean, jsDocTags: Set<string>) => void;
|
|
76
83
|
getFix: (start: number, end: number, flags?: number) => Fix;
|
|
77
84
|
getTypeFix: (start: number, end: number) => Fix;
|
|
@@ -5,7 +5,7 @@ import { isInNodeModules } from '../../util/path.js';
|
|
|
5
5
|
import { timerify } from '../../util/Performance.js';
|
|
6
6
|
import { getLineAndCol, getStringValue, isStringLiteral } from '../ast-nodes.js';
|
|
7
7
|
import { EMPTY_TAGS } from './jsdoc.js';
|
|
8
|
-
import { handleCallExpression, handleNewExpression } from './calls.js';
|
|
8
|
+
import { handleCallExpression, handleNewExpression, trackCustomElementRegistry } from './calls.js';
|
|
9
9
|
import { handleExportAssignment, handleExportDefault, handleExportNamed, handleExpressionStatement, } from './exports.js';
|
|
10
10
|
import { handleImportExpression, handleVariableDeclarator } from './imports.js';
|
|
11
11
|
import { handleJSXMemberExpression, handleMemberExpression } from './members.js';
|
|
@@ -42,6 +42,7 @@ const _addExport = (identifier, type, pos, members, fix, isReExport, jsDocTags)
|
|
|
42
42
|
line,
|
|
43
43
|
col,
|
|
44
44
|
hasRefsInFile: false,
|
|
45
|
+
isRegistered: false,
|
|
45
46
|
referencedIn: undefined,
|
|
46
47
|
fixes: fix ? [fix] : [],
|
|
47
48
|
isReExport,
|
|
@@ -212,11 +213,27 @@ const coreVisitorObject = {
|
|
|
212
213
|
state.nsRanges.push([node.start, node.end]);
|
|
213
214
|
},
|
|
214
215
|
ClassDeclaration(node) {
|
|
216
|
+
state.classNameStack.push(node.id?.name ?? '');
|
|
215
217
|
if (node.id?.name) {
|
|
216
218
|
state.localDeclarationTypes.set(node.id.name, SYMBOL_TYPE.CLASS);
|
|
217
219
|
state.localDeclarations.set(node.id.name, node);
|
|
218
220
|
}
|
|
219
221
|
},
|
|
222
|
+
'ClassDeclaration:exit'() {
|
|
223
|
+
state.classNameStack.pop();
|
|
224
|
+
},
|
|
225
|
+
ClassExpression(node) {
|
|
226
|
+
state.classNameStack.push(node.id?.name ?? '');
|
|
227
|
+
},
|
|
228
|
+
'ClassExpression:exit'() {
|
|
229
|
+
state.classNameStack.pop();
|
|
230
|
+
},
|
|
231
|
+
StaticBlock() {
|
|
232
|
+
state.staticBlockDepth++;
|
|
233
|
+
},
|
|
234
|
+
'StaticBlock:exit'() {
|
|
235
|
+
state.staticBlockDepth--;
|
|
236
|
+
},
|
|
220
237
|
FunctionDeclaration(node) {
|
|
221
238
|
if (node.id?.name) {
|
|
222
239
|
state.localDeclarationTypes.set(node.id.name, SYMBOL_TYPE.FUNCTION);
|
|
@@ -274,6 +291,7 @@ const coreVisitorObject = {
|
|
|
274
291
|
},
|
|
275
292
|
VariableDeclarator(node) {
|
|
276
293
|
handleVariableDeclarator(node, state);
|
|
294
|
+
trackCustomElementRegistry(node, state);
|
|
277
295
|
},
|
|
278
296
|
ImportExpression(node) {
|
|
279
297
|
handleImportExpression(node, state);
|
|
@@ -704,6 +722,10 @@ function walkAST(program, sourceText, filePath, ctx) {
|
|
|
704
722
|
localDeclarations: new Map(),
|
|
705
723
|
pendingCallRefs: [],
|
|
706
724
|
pendingMemberCallRefs: [],
|
|
725
|
+
localToExports: new Map(),
|
|
726
|
+
customElementRegistries: new Set(),
|
|
727
|
+
classNameStack: [],
|
|
728
|
+
staticBlockDepth: 0,
|
|
707
729
|
addExport: _addExport,
|
|
708
730
|
getFix: _getFix,
|
|
709
731
|
getTypeFix: _getTypeFix,
|
|
@@ -784,6 +806,19 @@ function walkAST(program, sourceText, filePath, ctx) {
|
|
|
784
806
|
item.hasRefsInFile = true;
|
|
785
807
|
}
|
|
786
808
|
}
|
|
809
|
+
for (const name of state.registeredCustomElements) {
|
|
810
|
+
const item = state.exports.get(name);
|
|
811
|
+
if (item)
|
|
812
|
+
item.isRegistered = true;
|
|
813
|
+
const aliases = state.localToExports.get(name);
|
|
814
|
+
if (aliases) {
|
|
815
|
+
for (const exportName of aliases) {
|
|
816
|
+
const aliased = state.exports.get(exportName);
|
|
817
|
+
if (aliased)
|
|
818
|
+
aliased.isRegistered = true;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
787
822
|
const localRefs = state.localRefs;
|
|
788
823
|
state = undefined;
|
|
789
824
|
return localRefs;
|
|
@@ -98,6 +98,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
98
98
|
entry?: string | string[] | undefined;
|
|
99
99
|
project?: string | string[] | undefined;
|
|
100
100
|
} | undefined;
|
|
101
|
+
catalyst?: string | boolean | string[] | {
|
|
102
|
+
config?: string | string[] | undefined;
|
|
103
|
+
entry?: string | string[] | undefined;
|
|
104
|
+
project?: string | string[] | undefined;
|
|
105
|
+
} | undefined;
|
|
101
106
|
changelogen?: string | boolean | string[] | {
|
|
102
107
|
config?: string | string[] | undefined;
|
|
103
108
|
entry?: string | string[] | undefined;
|
|
@@ -198,6 +203,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
198
203
|
entry?: string | string[] | undefined;
|
|
199
204
|
project?: string | string[] | undefined;
|
|
200
205
|
} | undefined;
|
|
206
|
+
fast?: string | boolean | string[] | {
|
|
207
|
+
config?: string | string[] | undefined;
|
|
208
|
+
entry?: string | string[] | undefined;
|
|
209
|
+
project?: string | string[] | undefined;
|
|
210
|
+
} | undefined;
|
|
201
211
|
gatsby?: string | boolean | string[] | {
|
|
202
212
|
config?: string | string[] | undefined;
|
|
203
213
|
entry?: string | string[] | undefined;
|
|
@@ -273,6 +283,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
273
283
|
entry?: string | string[] | undefined;
|
|
274
284
|
project?: string | string[] | undefined;
|
|
275
285
|
} | undefined;
|
|
286
|
+
lit?: string | boolean | string[] | {
|
|
287
|
+
config?: string | string[] | undefined;
|
|
288
|
+
entry?: string | string[] | undefined;
|
|
289
|
+
project?: string | string[] | undefined;
|
|
290
|
+
} | undefined;
|
|
276
291
|
'lockfile-lint'?: string | boolean | string[] | {
|
|
277
292
|
config?: string | string[] | undefined;
|
|
278
293
|
entry?: string | string[] | undefined;
|
|
@@ -882,6 +897,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
882
897
|
entry?: string | string[] | undefined;
|
|
883
898
|
project?: string | string[] | undefined;
|
|
884
899
|
} | undefined;
|
|
900
|
+
catalyst?: string | boolean | string[] | {
|
|
901
|
+
config?: string | string[] | undefined;
|
|
902
|
+
entry?: string | string[] | undefined;
|
|
903
|
+
project?: string | string[] | undefined;
|
|
904
|
+
} | undefined;
|
|
885
905
|
changelogen?: string | boolean | string[] | {
|
|
886
906
|
config?: string | string[] | undefined;
|
|
887
907
|
entry?: string | string[] | undefined;
|
|
@@ -982,6 +1002,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
982
1002
|
entry?: string | string[] | undefined;
|
|
983
1003
|
project?: string | string[] | undefined;
|
|
984
1004
|
} | undefined;
|
|
1005
|
+
fast?: string | boolean | string[] | {
|
|
1006
|
+
config?: string | string[] | undefined;
|
|
1007
|
+
entry?: string | string[] | undefined;
|
|
1008
|
+
project?: string | string[] | undefined;
|
|
1009
|
+
} | undefined;
|
|
985
1010
|
gatsby?: string | boolean | string[] | {
|
|
986
1011
|
config?: string | string[] | undefined;
|
|
987
1012
|
entry?: string | string[] | undefined;
|
|
@@ -1057,6 +1082,11 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1057
1082
|
entry?: string | string[] | undefined;
|
|
1058
1083
|
project?: string | string[] | undefined;
|
|
1059
1084
|
} | undefined;
|
|
1085
|
+
lit?: string | boolean | string[] | {
|
|
1086
|
+
config?: string | string[] | undefined;
|
|
1087
|
+
entry?: string | string[] | undefined;
|
|
1088
|
+
project?: string | string[] | undefined;
|
|
1089
|
+
} | undefined;
|
|
1060
1090
|
'lockfile-lint'?: string | boolean | string[] | {
|
|
1061
1091
|
config?: string | string[] | undefined;
|
|
1062
1092
|
entry?: string | string[] | undefined;
|
|
@@ -1596,6 +1626,7 @@ export declare const createOptions: (options: CreateOptions) => Promise<{
|
|
|
1596
1626
|
ignoreDependencies?: (string | RegExp)[] | undefined;
|
|
1597
1627
|
ignoreMembers?: (string | RegExp)[] | undefined;
|
|
1598
1628
|
ignoreUnresolved?: (string | RegExp)[] | undefined;
|
|
1629
|
+
ignoreExportsUsedInFile?: boolean | Record<string, boolean | undefined> | undefined;
|
|
1599
1630
|
includeEntryExports?: boolean | undefined;
|
|
1600
1631
|
}> | undefined;
|
|
1601
1632
|
};
|
|
@@ -94,6 +94,8 @@ export const loadTSConfig = async (tsConfigFilePath) => {
|
|
|
94
94
|
compilerOptions.outDir = absDir(compilerOptions.outDir, dir);
|
|
95
95
|
if (compilerOptions.rootDir)
|
|
96
96
|
compilerOptions.rootDir = absDir(compilerOptions.rootDir, dir);
|
|
97
|
+
if (compilerOptions.rootDirs)
|
|
98
|
+
compilerOptions.rootDirs = compilerOptions.rootDirs.map(d => absDir(d, dir));
|
|
97
99
|
if (compilerOptions.paths) {
|
|
98
100
|
compilerOptions.pathsBasePath ??= dir;
|
|
99
101
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type ParsedValue = any;
|
|
2
|
+
export interface ParsedArgs {
|
|
3
|
+
_: string[];
|
|
4
|
+
'--'?: string[];
|
|
5
|
+
[key: string]: ParsedValue;
|
|
6
|
+
}
|
|
7
|
+
interface Opts {
|
|
8
|
+
string?: string[];
|
|
9
|
+
boolean?: string[];
|
|
10
|
+
alias?: Record<string, string | string[]>;
|
|
11
|
+
'--'?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const parseArgs: (argv: string[], opts?: Opts) => ParsedArgs;
|
|
14
|
+
export default parseArgs;
|