knip 6.24.0 → 6.26.0
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 +115 -1
- package/dist/ConfigurationChief.js +3 -0
- package/dist/ProjectPrincipal.d.ts +2 -0
- package/dist/ProjectPrincipal.js +4 -1
- package/dist/binaries/bash-parser.js +55 -83
- package/dist/binaries/index.js +3 -0
- package/dist/compilers/index.d.ts +199 -5
- package/dist/constants.d.ts +5 -1
- package/dist/constants.js +18 -0
- package/dist/graph/analyze.js +37 -2
- package/dist/graph/build.js +17 -3
- package/dist/graph-explorer/explorer.d.ts +1 -0
- package/dist/graph-explorer/explorer.js +2 -0
- package/dist/graph-explorer/operations/find-all-cycles.d.ts +3 -0
- package/dist/graph-explorer/operations/find-all-cycles.js +43 -0
- package/dist/graph-explorer/operations/find-cycles.js +3 -9
- package/dist/graph-explorer/utils.d.ts +10 -1
- package/dist/graph-explorer/utils.js +53 -0
- package/dist/plugins/_vue/auto-import.d.ts +12 -0
- package/dist/plugins/_vue/auto-import.js +272 -0
- package/dist/plugins/_vue/types.d.ts +38 -0
- package/dist/plugins/_vue/types.js +1 -0
- package/dist/plugins/astro/index.js +2 -37
- package/dist/plugins/astro/resolveFromAST.d.ts +4 -4
- package/dist/plugins/astro/resolveFromAST.js +34 -7
- package/dist/plugins/bun/index.js +28 -14
- package/dist/plugins/electron-vite/index.d.ts +3 -0
- package/dist/plugins/electron-vite/index.js +51 -0
- package/dist/plugins/electron-vite/types.d.ts +23 -0
- package/dist/plugins/electron-vite/types.js +1 -0
- package/dist/plugins/esbuild/index.d.ts +3 -0
- package/dist/plugins/esbuild/index.js +17 -0
- package/dist/plugins/eslint/resolveFromAST.js +18 -21
- package/dist/plugins/eve/index.d.ts +3 -0
- package/dist/plugins/eve/index.js +22 -0
- package/dist/plugins/execa/visitors/execa.js +10 -18
- package/dist/plugins/fumadocs/index.d.ts +3 -0
- package/dist/plugins/fumadocs/index.js +18 -0
- package/dist/plugins/graphql-codegen/index.js +9 -7
- package/dist/plugins/index.d.ts +19 -0
- package/dist/plugins/index.js +38 -0
- package/dist/plugins/jest/index.js +13 -3
- package/dist/plugins/laravel-vite-plugin/index.d.ts +3 -0
- package/dist/plugins/laravel-vite-plugin/index.js +14 -0
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.d.ts +2 -0
- package/dist/plugins/laravel-vite-plugin/resolveFromAST.js +27 -0
- package/dist/plugins/next/index.js +25 -12
- package/dist/plugins/next-mdx/index.js +2 -8
- package/dist/plugins/next-mdx/resolveFromAST.d.ts +3 -2
- package/dist/plugins/next-mdx/resolveFromAST.js +17 -21
- package/dist/plugins/node/index.js +4 -1
- package/dist/plugins/nuxt/index.js +5 -68
- package/dist/plugins/nuxt/types.d.ts +0 -34
- package/dist/plugins/nuxtjs-i18n/index.d.ts +3 -0
- package/dist/plugins/nuxtjs-i18n/index.js +12 -0
- package/dist/plugins/oclif/index.js +10 -5
- package/dist/plugins/orval/index.js +1 -3
- package/dist/plugins/orval/resolveFromAST.d.ts +2 -2
- package/dist/plugins/orval/resolveFromAST.js +4 -7
- package/dist/plugins/oxlint/index.js +23 -2
- package/dist/plugins/pnpm/index.js +22 -1
- package/dist/plugins/pnpm/types.d.ts +4 -0
- package/dist/plugins/pnpm/types.js +1 -0
- package/dist/plugins/prettier/index.js +19 -3
- package/dist/plugins/prettier/types.d.ts +6 -1
- package/dist/plugins/quasar/index.d.ts +3 -0
- package/dist/plugins/quasar/index.js +15 -0
- package/dist/plugins/quasar/resolveFromAST.d.ts +3 -0
- package/dist/plugins/quasar/resolveFromAST.js +63 -0
- package/dist/plugins/qwik/index.js +1 -25
- package/dist/plugins/qwik/resolveFromAST.d.ts +5 -3
- package/dist/plugins/qwik/resolveFromAST.js +28 -9
- package/dist/plugins/rolldown/index.js +2 -5
- package/dist/plugins/rollup/index.js +2 -5
- package/dist/plugins/rslib/index.js +2 -5
- package/dist/plugins/rspack/index.js +5 -0
- package/dist/plugins/serverless-framework/index.js +12 -1
- package/dist/plugins/serverless-framework/types.d.ts +5 -2
- package/dist/plugins/sst/index.js +1 -5
- package/dist/plugins/sst/resolveFromAST.d.ts +1 -1
- package/dist/plugins/sst/resolveFromAST.js +1 -1
- package/dist/plugins/starlight/index.js +1 -19
- package/dist/plugins/starlight/resolveFromAST.d.ts +2 -2
- package/dist/plugins/starlight/resolveFromAST.js +12 -8
- package/dist/plugins/stencil/index.js +2 -37
- package/dist/plugins/stencil/resolveFromAST.d.ts +3 -0
- package/dist/plugins/stencil/resolveFromAST.js +36 -0
- package/dist/plugins/storybook/index.js +10 -0
- package/dist/plugins/sveltekit/index.js +1 -48
- package/dist/plugins/sveltekit/resolveFromAST.d.ts +2 -0
- package/dist/plugins/sveltekit/resolveFromAST.js +45 -0
- package/dist/plugins/tauri/index.d.ts +3 -0
- package/dist/plugins/tauri/index.js +42 -0
- package/dist/plugins/tauri/types.d.ts +16 -0
- package/dist/plugins/tauri/types.js +1 -0
- package/dist/plugins/tsdown/index.js +2 -5
- package/dist/plugins/tsup/index.js +2 -5
- package/dist/plugins/typedoc/index.js +9 -3
- package/dist/plugins/typedoc/types.d.ts +2 -0
- package/dist/plugins/unplugin-auto-import/index.d.ts +3 -0
- package/dist/plugins/unplugin-auto-import/index.js +18 -0
- package/dist/plugins/unplugin-icons/index.d.ts +3 -0
- package/dist/plugins/unplugin-icons/index.js +17 -0
- package/dist/plugins/unplugin-vue-components/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-components/index.js +16 -0
- package/dist/plugins/unplugin-vue-i18n/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-i18n/index.js +10 -0
- package/dist/plugins/unplugin-vue-markdown/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-markdown/index.js +16 -0
- package/dist/plugins/unplugin-vue-router/index.d.ts +3 -0
- package/dist/plugins/unplugin-vue-router/index.js +14 -0
- package/dist/plugins/vite/helpers.d.ts +2 -0
- package/dist/plugins/vite/helpers.js +46 -31
- package/dist/plugins/vite/index.js +1 -1
- package/dist/plugins/vite/visitors/importMetaGlob.js +1 -8
- package/dist/plugins/vite-plugin-pages/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-pages/index.js +26 -0
- package/dist/plugins/vite-plugin-pwa/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-pwa/index.js +17 -0
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.d.ts +4 -0
- package/dist/plugins/vite-plugin-pwa/resolveFromAST.js +37 -0
- package/dist/plugins/vite-plugin-vue-layouts-next/index.d.ts +3 -0
- package/dist/plugins/vite-plugin-vue-layouts-next/index.js +23 -0
- package/dist/plugins/vite-plus/index.d.ts +3 -0
- package/dist/plugins/vite-plus/index.js +14 -0
- package/dist/plugins/vite-plus/resolveFromAST.d.ts +2 -0
- package/dist/plugins/vite-plus/resolveFromAST.js +37 -0
- package/dist/plugins/vite-pwa-assets-generator/index.d.ts +3 -0
- package/dist/plugins/vite-pwa-assets-generator/index.js +12 -0
- package/dist/plugins/vitepress/index.js +5 -1
- package/dist/plugins/vitest/index.js +4 -0
- package/dist/plugins/vitest/types.d.ts +3 -0
- package/dist/plugins/vue/index.js +5 -3
- package/dist/plugins/webpack/visitors/requireContext.js +2 -13
- package/dist/plugins/yarn/index.js +14 -4
- package/dist/plugins/yarn/types.d.ts +8 -0
- package/dist/plugins/yarn/types.js +1 -0
- package/dist/plugins/zx/visitors/zx.js +4 -4
- package/dist/reporters/cycles.d.ts +3 -0
- package/dist/reporters/cycles.js +79 -0
- package/dist/reporters/index.d.ts +1 -0
- package/dist/reporters/index.js +2 -0
- package/dist/reporters/json.d.ts +3 -0
- package/dist/reporters/json.js +2 -1
- package/dist/reporters/util/util.d.ts +3 -1
- package/dist/reporters/util/util.js +5 -1
- package/dist/schema/configuration.d.ts +295 -6
- package/dist/schema/configuration.js +6 -0
- package/dist/schema/plugins.d.ts +95 -0
- package/dist/schema/plugins.js +19 -0
- package/dist/types/PluginNames.d.ts +2 -2
- package/dist/types/PluginNames.js +19 -0
- package/dist/types/config.d.ts +9 -0
- package/dist/types/issues.d.ts +3 -0
- package/dist/types/module-graph.d.ts +7 -0
- package/dist/types/package-json.d.ts +8 -1
- package/dist/typescript/ast-helpers.d.ts +7 -2
- package/dist/typescript/ast-helpers.js +36 -8
- package/dist/typescript/ast-nodes.d.ts +4 -1
- package/dist/typescript/ast-nodes.js +17 -1
- package/dist/typescript/get-imports-and-exports.js +10 -0
- package/dist/typescript/glob-imports.d.ts +3 -0
- package/dist/typescript/glob-imports.js +49 -0
- package/dist/typescript/resolve-module-names.d.ts +2 -0
- package/dist/typescript/resolve-module-names.js +35 -1
- package/dist/typescript/visitors/calls.js +4 -6
- package/dist/typescript/visitors/imports.js +8 -8
- package/dist/typescript/visitors/script-visitors.js +4 -4
- package/dist/typescript/visitors/walk.js +2 -3
- package/dist/util/cli-arguments.d.ts +2 -1
- package/dist/util/cli-arguments.js +5 -3
- package/dist/util/create-options.d.ts +202 -5
- package/dist/util/create-options.js +4 -1
- package/dist/util/get-included-issue-types.d.ts +1 -0
- package/dist/util/get-included-issue-types.js +4 -2
- package/dist/util/issue-initializers.js +1 -1
- package/dist/util/load-tsconfig.js +17 -4
- package/dist/util/module-graph.js +1 -0
- package/dist/util/modules.js +25 -4
- package/dist/util/resolve.js +4 -1
- package/dist/util/scripts.d.ts +7 -0
- package/dist/util/scripts.js +75 -0
- package/dist/util/to-source-path.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +108 -1
- package/dist/plugins/next/resolveFromAST.d.ts +0 -2
- package/dist/plugins/next/resolveFromAST.js +0 -2
- package/dist/plugins/nuxt/helpers.d.ts +0 -15
- package/dist/plugins/nuxt/helpers.js +0 -133
- package/dist/plugins/rolldown/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rolldown/resolveFromAST.js +0 -4
- package/dist/plugins/rollup/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rollup/resolveFromAST.js +0 -4
- package/dist/plugins/rslib/resolveFromAST.d.ts +0 -2
- package/dist/plugins/rslib/resolveFromAST.js +0 -4
- package/dist/plugins/tsdown/resolveFromAST.d.ts +0 -2
- package/dist/plugins/tsdown/resolveFromAST.js +0 -4
- package/dist/plugins/tsup/resolveFromAST.d.ts +0 -2
- package/dist/plugins/tsup/resolveFromAST.js +0 -4
- package/dist/plugins/vue/compiler.d.ts +0 -3
- package/dist/plugins/vue/compiler.js +0 -10
|
@@ -24,6 +24,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
24
24
|
const aliasedExports = new Map();
|
|
25
25
|
const specifierExportNames = new Set();
|
|
26
26
|
const scripts = new Set();
|
|
27
|
+
const importGlobs = [];
|
|
27
28
|
const importAliases = new Map();
|
|
28
29
|
const addImportAlias = (aliasName, id, importFilePath) => {
|
|
29
30
|
const aliases = importAliases.get(aliasName);
|
|
@@ -58,6 +59,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
58
59
|
line: opts.line,
|
|
59
60
|
col: opts.col,
|
|
60
61
|
isTypeOnly: isDts || !!(modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
62
|
+
modifiers,
|
|
61
63
|
});
|
|
62
64
|
const file = internal.get(importFilePath);
|
|
63
65
|
const importMaps = file ?? createImports();
|
|
@@ -93,6 +95,10 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
93
95
|
if (!specifier || isBuiltin(specifier))
|
|
94
96
|
return;
|
|
95
97
|
const module = preResolvedModule ?? resolveModule(specifier, filePath);
|
|
98
|
+
if (modifiers & IMPORT_FLAGS.AUGMENT &&
|
|
99
|
+
(!module || module.isExternalLibraryImport || isInNodeModules(module.resolvedFileName))) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
96
102
|
if (module) {
|
|
97
103
|
const resolvedFileName = module.resolvedFileName;
|
|
98
104
|
if (resolvedFileName) {
|
|
@@ -134,6 +140,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
134
140
|
line,
|
|
135
141
|
col,
|
|
136
142
|
isTypeOnly: isDts || !!(modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
143
|
+
modifiers,
|
|
137
144
|
});
|
|
138
145
|
}
|
|
139
146
|
}
|
|
@@ -158,6 +165,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
158
165
|
line,
|
|
159
166
|
col,
|
|
160
167
|
isTypeOnly: isDts || !!(modifiers & IMPORT_FLAGS.TYPE_ONLY),
|
|
168
|
+
modifiers,
|
|
161
169
|
});
|
|
162
170
|
}
|
|
163
171
|
}
|
|
@@ -266,6 +274,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
266
274
|
pluginCtx.sourceText = sourceText;
|
|
267
275
|
pluginCtx.addScript = (s) => scripts.add(s);
|
|
268
276
|
pluginCtx.addImport = (spec, pos, mod) => addImport(spec, undefined, undefined, undefined, pos, mod);
|
|
277
|
+
pluginCtx.addImportGlob = (patterns, opts) => importGlobs.push({ patterns, base: opts?.base, filter: opts?.filter });
|
|
269
278
|
pluginCtx.markExportRegistered = (name) => registeredCustomElements.add(name);
|
|
270
279
|
}
|
|
271
280
|
const localRefs = _walkAST(result.program, sourceText, filePath, {
|
|
@@ -314,6 +323,7 @@ const getImportsAndExports = (filePath, sourceText, resolveModule, options, igno
|
|
|
314
323
|
exports,
|
|
315
324
|
duplicates: [...aliasedExports.values()],
|
|
316
325
|
scripts,
|
|
326
|
+
importGlobs,
|
|
317
327
|
importedBy: undefined,
|
|
318
328
|
internalImportCache: undefined,
|
|
319
329
|
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ImportGlob } from '../types/module-graph.ts';
|
|
2
|
+
import type { ResolveGlobPattern } from './resolve-module-names.ts';
|
|
3
|
+
export declare function resolveImportGlobs(items: ImportGlob[], containingFile: string, resolveGlobPattern: ResolveGlobPattern, workspaceRoot: string): string[];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { _syncGlob } from '../util/glob.js';
|
|
3
|
+
import { dirname, isAbsolute, join, toRelative } from '../util/path.js';
|
|
4
|
+
function resolveBaseDir(base, dir, resolveGlobPattern) {
|
|
5
|
+
if (base.startsWith('.'))
|
|
6
|
+
return join(dir, base);
|
|
7
|
+
if (isAbsolute(base))
|
|
8
|
+
return base;
|
|
9
|
+
for (const resolved of resolveGlobPattern(base, dir)) {
|
|
10
|
+
if (resolved !== base && existsSync(resolved))
|
|
11
|
+
return resolved;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
export function resolveImportGlobs(items, containingFile, resolveGlobPattern, workspaceRoot) {
|
|
16
|
+
const filePaths = [];
|
|
17
|
+
const dir = dirname(containingFile);
|
|
18
|
+
for (const { patterns, base, filter } of items) {
|
|
19
|
+
if (base !== undefined) {
|
|
20
|
+
const cwd = resolveBaseDir(base, dir, resolveGlobPattern);
|
|
21
|
+
if (!cwd)
|
|
22
|
+
continue;
|
|
23
|
+
for (const filePath of _syncGlob({ patterns, cwd })) {
|
|
24
|
+
if (!filter || filter.test(`./${toRelative(filePath, cwd)}`))
|
|
25
|
+
filePaths.push(filePath);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const resolved = [];
|
|
30
|
+
for (const pattern of patterns) {
|
|
31
|
+
const isNegated = pattern[0] === '!';
|
|
32
|
+
const specifier = isNegated ? pattern.slice(1) : pattern;
|
|
33
|
+
if (specifier[0] === '/') {
|
|
34
|
+
const rooted = join(workspaceRoot, specifier);
|
|
35
|
+
resolved.push(isNegated ? `!${rooted}` : rooted);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const p of resolveGlobPattern(pattern, dir))
|
|
39
|
+
resolved.push(p);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (resolved.length === 0)
|
|
43
|
+
continue;
|
|
44
|
+
for (const filePath of _syncGlob({ patterns: resolved, cwd: dir }))
|
|
45
|
+
filePaths.push(filePath);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return filePaths;
|
|
49
|
+
}
|
|
@@ -9,6 +9,8 @@ type ScopedRootDirs = Array<{
|
|
|
9
9
|
rootDirs: string[];
|
|
10
10
|
}>;
|
|
11
11
|
export declare function clearModuleResolutionCaches(): void;
|
|
12
|
+
export type ResolveGlobPattern = (pattern: string, dir: string) => string[];
|
|
13
|
+
export declare function createGlobAliasResolver(scopedPaths: ScopedPaths | undefined): ResolveGlobPattern;
|
|
12
14
|
export declare function createCustomModuleResolver(compilerOptions: {
|
|
13
15
|
scopedPaths?: ScopedPaths;
|
|
14
16
|
scopedRootDirs?: ScopedRootDirs;
|
|
@@ -3,7 +3,7 @@ import { isBuiltin } from 'node:module';
|
|
|
3
3
|
import { DEFAULT_EXTENSIONS, DTS_EXTENSIONS } from '../constants.js';
|
|
4
4
|
import { sanitizeSpecifier } from '../util/modules.js';
|
|
5
5
|
import { timerify } from '../util/Performance.js';
|
|
6
|
-
import { dirname, extname, isAbsolute, isInNodeModules, join } from '../util/path.js';
|
|
6
|
+
import { dirname, extname, isAbsolute, isInNodeModules, join, toPosix } from '../util/path.js';
|
|
7
7
|
import { _createSyncModuleResolver, _resolveModuleSync } from '../util/resolve.js';
|
|
8
8
|
function pickStringTarget(value) {
|
|
9
9
|
if (typeof value === 'string')
|
|
@@ -56,6 +56,40 @@ function compileRootDirs(scopedRootDirs) {
|
|
|
56
56
|
scoped.sort((a, b) => b.scope.length - a.scope.length);
|
|
57
57
|
return scoped;
|
|
58
58
|
}
|
|
59
|
+
export function createGlobAliasResolver(scopedPaths) {
|
|
60
|
+
const mappings = compilePathMappings(scopedPaths);
|
|
61
|
+
return (pattern, dir) => {
|
|
62
|
+
if (!mappings)
|
|
63
|
+
return [pattern];
|
|
64
|
+
const isNegated = pattern[0] === '!';
|
|
65
|
+
const specifier = isNegated ? pattern.slice(1) : pattern;
|
|
66
|
+
let best;
|
|
67
|
+
for (const mapping of mappings) {
|
|
68
|
+
const { prefix, wildcard, scope } = mapping;
|
|
69
|
+
if (dir !== scope && !dir.startsWith(`${scope}/`))
|
|
70
|
+
continue;
|
|
71
|
+
const matches = wildcard
|
|
72
|
+
? specifier.startsWith(prefix)
|
|
73
|
+
: specifier === prefix || specifier.startsWith(`${prefix}/`);
|
|
74
|
+
if (!matches)
|
|
75
|
+
continue;
|
|
76
|
+
if (!best ||
|
|
77
|
+
scope.length > best.scope.length ||
|
|
78
|
+
(scope.length === best.scope.length && prefix.length > best.prefix.length))
|
|
79
|
+
best = mapping;
|
|
80
|
+
}
|
|
81
|
+
if (!best)
|
|
82
|
+
return [pattern];
|
|
83
|
+
const captured = specifier.slice(best.prefix.length);
|
|
84
|
+
const resolved = [];
|
|
85
|
+
for (const value of best.values) {
|
|
86
|
+
const starIdx = value.indexOf('*');
|
|
87
|
+
const mapped = toPosix(starIdx >= 0 ? value.slice(0, starIdx) + captured + value.slice(starIdx + 1) : value + captured);
|
|
88
|
+
resolved.push(isNegated ? `!${mapped}` : mapped);
|
|
89
|
+
}
|
|
90
|
+
return resolved;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
59
93
|
export function createCustomModuleResolver(compilerOptions, customCompilerExtensions, toSourceFilePath, findWorkspaceManifestImports, tsConfigFile) {
|
|
60
94
|
const customCompilerExtensionsSet = new Set(customCompilerExtensions);
|
|
61
95
|
const hasCustomExts = customCompilerExtensionsSet.size > 0;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IMPORT_FLAGS, OPAQUE } from '../../constants.js';
|
|
2
2
|
import { addValue } from '../../util/module-graph.js';
|
|
3
|
-
import { getSafeScriptFromArgs, getStringValue, isStringLiteral } from '../ast-nodes.js';
|
|
3
|
+
import { getSafeScriptFromArgs, getScriptFromArg, getStringValue, isStringLiteral } from '../ast-nodes.js';
|
|
4
4
|
import { isShadowed } from './walk.js';
|
|
5
5
|
function getRegisteredCustomElement(node, s) {
|
|
6
6
|
const callee = node.callee;
|
|
@@ -162,11 +162,9 @@ export function handleCallExpression(node, s) {
|
|
|
162
162
|
if (method) {
|
|
163
163
|
const arg = node.arguments[0];
|
|
164
164
|
if (CHILD_PROCESS_COMMAND_METHODS.has(method)) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
s.scripts.add(command);
|
|
169
|
-
}
|
|
165
|
+
const command = getScriptFromArg(arg);
|
|
166
|
+
if (command)
|
|
167
|
+
s.scripts.add(command);
|
|
170
168
|
return;
|
|
171
169
|
}
|
|
172
170
|
if (CHILD_PROCESS_FILE_METHODS.has(method)) {
|
|
@@ -26,16 +26,16 @@ export function handleVariableDeclarator(node, s) {
|
|
|
26
26
|
: undefined;
|
|
27
27
|
const localName = prop.value?.type === 'Identifier' ? prop.value.name : importedName;
|
|
28
28
|
const alias = localName !== importedName ? localName : undefined;
|
|
29
|
-
s.addImport(specifier, importedName, alias, undefined, prop.key?.start ?? prop.start, IMPORT_FLAGS.
|
|
29
|
+
s.addImport(specifier, importedName, alias, undefined, prop.key?.start ?? prop.start, IMPORT_FLAGS.DYNAMIC);
|
|
30
30
|
}
|
|
31
31
|
else if (prop.type === 'RestElement' && prop.argument?.type === 'Identifier') {
|
|
32
|
-
s.addImport(specifier, IMPORT_STAR, prop.argument.name, undefined, prop.start, IMPORT_FLAGS.
|
|
32
|
+
s.addImport(specifier, IMPORT_STAR, prop.argument.name, undefined, prop.start, IMPORT_FLAGS.DYNAMIC);
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
else if (node.id.type === 'Identifier') {
|
|
37
37
|
if (init.type === 'AwaitExpression') {
|
|
38
|
-
s.addImport(specifier, 'default', node.id.name, undefined, importExpr.source.start, IMPORT_FLAGS.
|
|
38
|
+
s.addImport(specifier, 'default', node.id.name, undefined, importExpr.source.start, IMPORT_FLAGS.DYNAMIC);
|
|
39
39
|
const resolved = s.resolveModule(specifier, s.filePath);
|
|
40
40
|
if (resolved && !resolved.isExternalLibraryImport && !isInNodeModules(resolved.resolvedFileName)) {
|
|
41
41
|
s.localImportMap.set(node.id.name, {
|
|
@@ -47,11 +47,11 @@ export function handleVariableDeclarator(node, s) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
s.addImport(specifier, undefined, undefined, undefined, importExpr.source.start, IMPORT_FLAGS.OPAQUE);
|
|
50
|
+
s.addImport(specifier, undefined, undefined, undefined, importExpr.source.start, IMPORT_FLAGS.DYNAMIC | IMPORT_FLAGS.OPAQUE);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
s.addImport(specifier, undefined, undefined, undefined, importExpr.source.start, IMPORT_FLAGS.OPAQUE);
|
|
54
|
+
s.addImport(specifier, undefined, undefined, undefined, importExpr.source.start, IMPORT_FLAGS.DYNAMIC | IMPORT_FLAGS.OPAQUE);
|
|
55
55
|
}
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
@@ -117,10 +117,10 @@ export function handleVariableDeclarator(node, s) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
else if (binding?.type === 'Identifier') {
|
|
120
|
-
s.addImport(specifier, 'default', binding.name, undefined, imp.source.start, IMPORT_FLAGS.
|
|
120
|
+
s.addImport(specifier, 'default', binding.name, undefined, imp.source.start, IMPORT_FLAGS.DYNAMIC);
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
-
s.addImport(specifier, undefined, undefined, undefined, imp.source.start, IMPORT_FLAGS.SIDE_EFFECTS);
|
|
123
|
+
s.addImport(specifier, undefined, undefined, undefined, imp.source.start, IMPORT_FLAGS.DYNAMIC | IMPORT_FLAGS.SIDE_EFFECTS);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
}
|
|
@@ -257,6 +257,6 @@ export function handleImportExpression(node, s) {
|
|
|
257
257
|
return;
|
|
258
258
|
const specifier = getStringValue(node.source);
|
|
259
259
|
if (specifier) {
|
|
260
|
-
s.addImport(specifier, undefined, undefined, undefined, node.source.start, IMPORT_FLAGS.OPAQUE);
|
|
260
|
+
s.addImport(specifier, undefined, undefined, undefined, node.source.start, IMPORT_FLAGS.DYNAMIC | IMPORT_FLAGS.OPAQUE);
|
|
261
261
|
}
|
|
262
262
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { getScriptFromTemplate } from '../ast-nodes.js';
|
|
1
2
|
export function createBunShellVisitor(ctx) {
|
|
2
3
|
return {
|
|
3
4
|
TaggedTemplateExpression(node) {
|
|
4
5
|
const tag = node.tag;
|
|
5
6
|
if (tag.type === 'Identifier' && tag.name === '$') {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
7
|
+
const script = getScriptFromTemplate(node.quasi);
|
|
8
|
+
if (script)
|
|
9
|
+
ctx.addScript(script);
|
|
10
10
|
}
|
|
11
11
|
},
|
|
12
12
|
};
|
|
@@ -213,9 +213,8 @@ const coreVisitorObject = {
|
|
|
213
213
|
state.nsRanges.push([node.start, node.end]);
|
|
214
214
|
if (node.kind !== 'global' && isStringLiteral(node.id)) {
|
|
215
215
|
const specifier = getStringValue(node.id);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
state.addImport(specifier, name, undefined, undefined, node.id.start, IMPORT_FLAGS.TYPE_ONLY);
|
|
216
|
+
for (const name of collectAugmentationRefs(node))
|
|
217
|
+
state.addImport(specifier, name, undefined, undefined, node.id.start, IMPORT_FLAGS.TYPE_ONLY | IMPORT_FLAGS.AUGMENT);
|
|
219
218
|
}
|
|
220
219
|
},
|
|
221
220
|
ClassDeclaration(node) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include
|
|
1
|
+
export declare const helpText = "\u2702\uFE0F Find unused dependencies, exports and files in your JavaScript and TypeScript projects\n\nUsage: knip [options]\n\nOptions:\n -h, --help Print this help text\n -V, --version Print version\n -n, --no-progress Don't show dynamic progress updates (automatically enabled in CI environments)\n -c, --config [file] Configuration file path\n (default: [.]knip.json[c], knip.(js|ts), knip.config.(js|ts) or package.json#knip)\n --use-tsconfig-files Use tsconfig.json to define project files (override `project` patterns)\n -t, --tsConfig [file] TypeScript configuration path (default: tsconfig.json)\n\nMode\n --cache Enable caching\n --cache-location Change cache location (default: node_modules/.cache/knip)\n --include-entry-exports Include entry files when reporting unused exports\n --no-gitignore Don't respect .gitignore\n -p, --production Analyze only production source files (e.g. no test files, devDependencies)\n -s, --strict Consider only direct dependencies of workspace (not devDependencies, not other workspaces)\n -w, --watch Watch mode\n\nScope\n -W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)\n -D, --directory [dir] Run process from a different directory (default: cwd)\n --include Include provided issue type(s), can be comma-separated or repeated (1)\n --exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)\n --dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog\n --exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates\n --files Shortcut for --include files\n --cycles Shortcut for --include cycles (circular dependencies)\n --tags Include or exclude tagged exports\n\nFix\n -f, --fix Fix issues (modifies files in your repo)\n --fix-type Fix only issues of type, can be comma-separated or repeated (2)\n --allow-remove-files Allow Knip to remove files (with --fix)\n -F, --format Format modified files after --fix using the local formatter\n\nOutput\n --preprocessor Preprocess the results before providing it to the reporter(s), can be repeated\n --preprocessor-options Pass extra options to the preprocessor (as JSON string, see --reporter-options example)\n --reporter Select reporter (default: symbols), can be repeated (3)\n --reporter-options Pass extra options to the reporter (as JSON string, see example)\n --no-config-hints Suppress configuration hints\n --no-tag-hints Suppress tag hints\n --treat-config-hints-as-errors Exit with non-zero code (1) if there are any configuration hints\n --treat-tag-hints-as-errors Exit with non-zero code (1) if there are any tag hints\n --max-issues Maximum number of total issues before non-zero exit code (default: 0)\n --max-show-issues Maximum number of issues to display per type\n --no-exit-code Always exit with code zero (0)\n\nTroubleshooting\n -d, --debug Show debug output\n --memory Measure memory usage and display data table\n --memory-realtime Log memory usage in realtime\n --performance Measure count and running time of key functions and display stats table\n --performance-fn [name] Measure only function [name]\n -u, --duration Print total running time (zero overhead, no instrumentation)\n --trace Show trace output\n --trace-dependency [name] Show files that import the named dependency\n --trace-export [name] Show trace output for named export(s)\n --trace-file [file] Show trace output for exports in file\n\n(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog, cycles\n(2) Fixable issue types: dependencies, exports, types, files, catalog\n(3) Built-in reporters: symbols (default), compact, codeowners, cycles, json, codeclimate, markdown, disclosure, github-actions\n\nExamples:\n\n$ knip\n$ knip --production\n$ knip --workspace packages/client --include files,dependencies\n$ knip --workspace @myorg/* --workspace '!@myorg/legacy'\n$ knip --workspace './apps/*' --workspace '@shared/utils'\n$ knip -c ./config/knip.json --reporter compact\n$ knip --reporter codeowners --reporter-options '{\"path\":\".github/CODEOWNERS\"}'\n$ knip --tags=-lintignore\n\nWebsite: https://knip.dev";
|
|
2
2
|
export type ParsedCLIArgs = ReturnType<typeof parseCLIArgs>;
|
|
3
3
|
export default function parseCLIArgs(): {
|
|
4
4
|
cache?: boolean | undefined;
|
|
5
5
|
'cache-location'?: string | undefined;
|
|
6
6
|
config?: string | undefined;
|
|
7
|
+
cycles?: boolean | undefined;
|
|
7
8
|
debug?: boolean | undefined;
|
|
8
9
|
dependencies?: boolean | undefined;
|
|
9
10
|
directory?: string | undefined;
|
|
@@ -24,11 +24,12 @@ Mode
|
|
|
24
24
|
Scope
|
|
25
25
|
-W, --workspace [filter] Filter workspaces by name, directory, or glob (can be repeated)
|
|
26
26
|
-D, --directory [dir] Run process from a different directory (default: cwd)
|
|
27
|
-
--include
|
|
27
|
+
--include Include provided issue type(s), can be comma-separated or repeated (1)
|
|
28
28
|
--exclude Exclude provided issue type(s) from report, can be comma-separated or repeated (1)
|
|
29
29
|
--dependencies Shortcut for --include dependencies,unlisted,binaries,unresolved,catalog
|
|
30
30
|
--exports Shortcut for --include exports,nsExports,types,nsTypes,enumMembers,namespaceMembers,duplicates
|
|
31
31
|
--files Shortcut for --include files
|
|
32
|
+
--cycles Shortcut for --include cycles (circular dependencies)
|
|
32
33
|
--tags Include or exclude tagged exports
|
|
33
34
|
|
|
34
35
|
Fix
|
|
@@ -62,9 +63,9 @@ Troubleshooting
|
|
|
62
63
|
--trace-export [name] Show trace output for named export(s)
|
|
63
64
|
--trace-file [file] Show trace output for exports in file
|
|
64
65
|
|
|
65
|
-
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog
|
|
66
|
+
(1) Issue types: files, dependencies, unlisted, unresolved, exports, nsExports, types, nsTypes, enumMembers, namespaceMembers, duplicates, catalog, cycles
|
|
66
67
|
(2) Fixable issue types: dependencies, exports, types, files, catalog
|
|
67
|
-
(3) Built-in reporters: symbols (default), compact, codeowners, json, codeclimate, markdown, disclosure, github-actions
|
|
68
|
+
(3) Built-in reporters: symbols (default), compact, codeowners, cycles, json, codeclimate, markdown, disclosure, github-actions
|
|
68
69
|
|
|
69
70
|
Examples:
|
|
70
71
|
|
|
@@ -84,6 +85,7 @@ export default function parseCLIArgs() {
|
|
|
84
85
|
cache: { type: 'boolean' },
|
|
85
86
|
'cache-location': { type: 'string' },
|
|
86
87
|
config: { type: 'string', short: 'c' },
|
|
88
|
+
cycles: { type: 'boolean' },
|
|
87
89
|
debug: { type: 'boolean', short: 'd' },
|
|
88
90
|
dependencies: { type: 'boolean' },
|
|
89
91
|
directory: { type: 'string', short: 'D' },
|