knip 5.73.0 → 5.73.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/ProjectPrincipal.d.ts +2 -2
- package/dist/ProjectPrincipal.js +4 -4
- package/dist/constants.d.ts +1 -0
- package/dist/constants.js +4 -3
- package/dist/graph/build.js +7 -2
- package/dist/plugins/astro/index.js +1 -1
- package/dist/types/module-graph.d.ts +2 -1
- package/dist/typescript/get-imports-and-exports.js +9 -6
- package/dist/typescript/visitors/dynamic-imports/requireCall.js +1 -1
- package/dist/util/map-workspaces.js +6 -6
- package/dist/util/module-graph.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ import type { ToSourceFilePath } from './util/to-source-path.js';
|
|
|
11
11
|
export declare class ProjectPrincipal {
|
|
12
12
|
entryPaths: Set<string>;
|
|
13
13
|
projectPaths: Set<string>;
|
|
14
|
-
|
|
14
|
+
programPaths: Set<string>;
|
|
15
15
|
skipExportsAnalysis: Set<string>;
|
|
16
16
|
cwd: string;
|
|
17
17
|
compilerOptions: ts.CompilerOptions;
|
|
@@ -44,7 +44,7 @@ export declare class ProjectPrincipal {
|
|
|
44
44
|
addEntryPaths(filePaths: Set<string> | string[], options?: {
|
|
45
45
|
skipExportsAnalysis: boolean;
|
|
46
46
|
}): void;
|
|
47
|
-
|
|
47
|
+
addProgramPath(filePath: string): void;
|
|
48
48
|
addProjectPath(filePath: string): void;
|
|
49
49
|
deletedFiles: Set<unknown>;
|
|
50
50
|
removeProjectPath(filePath: string): void;
|
package/dist/ProjectPrincipal.js
CHANGED
|
@@ -29,7 +29,7 @@ const tsCreateProgram = timerify(ts.createProgram);
|
|
|
29
29
|
export class ProjectPrincipal {
|
|
30
30
|
entryPaths = new Set();
|
|
31
31
|
projectPaths = new Set();
|
|
32
|
-
|
|
32
|
+
programPaths = new Set();
|
|
33
33
|
skipExportsAnalysis = new Set();
|
|
34
34
|
cwd;
|
|
35
35
|
compilerOptions;
|
|
@@ -98,7 +98,7 @@ export class ProjectPrincipal {
|
|
|
98
98
|
this.extensions = new Set([...this.extensions, ...getCompilerExtensions(compilers)]);
|
|
99
99
|
}
|
|
100
100
|
createProgram() {
|
|
101
|
-
this.backend.program = tsCreateProgram([...this.entryPaths, ...this.
|
|
101
|
+
this.backend.program = tsCreateProgram([...this.entryPaths, ...this.programPaths], this.compilerOptions, this.backend.compilerHost, this.backend.program);
|
|
102
102
|
const typeChecker = timerify(this.backend.program.getTypeChecker);
|
|
103
103
|
this.backend.typeChecker = typeChecker();
|
|
104
104
|
}
|
|
@@ -117,9 +117,9 @@ export class ProjectPrincipal {
|
|
|
117
117
|
for (const filePath of filePaths)
|
|
118
118
|
this.addEntryPath(filePath, options);
|
|
119
119
|
}
|
|
120
|
-
|
|
120
|
+
addProgramPath(filePath) {
|
|
121
121
|
if (!isInNodeModules(filePath) && this.hasAcceptedExtension(filePath)) {
|
|
122
|
-
this.
|
|
122
|
+
this.programPaths.add(filePath);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
addProjectPath(filePath) {
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -217,7 +217,8 @@ export const IMPORT_MODIFIERS = {
|
|
|
217
217
|
RE_EXPORT: 1 << 0,
|
|
218
218
|
TYPE_ONLY: 1 << 1,
|
|
219
219
|
ENTRY: 1 << 2,
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
BRIDGE: 1 << 3,
|
|
221
|
+
OPTIONAL: 1 << 4,
|
|
222
|
+
SIDE_EFFECTS: 1 << 5,
|
|
223
|
+
OPAQUE: 1 << 6,
|
|
223
224
|
};
|
package/dist/graph/build.js
CHANGED
|
@@ -271,7 +271,12 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
|
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
}
|
|
274
|
-
for (const filePath of file.imports.
|
|
274
|
+
for (const filePath of file.imports.programFiles) {
|
|
275
|
+
const isIgnored = isGitIgnored(filePath);
|
|
276
|
+
if (!isIgnored)
|
|
277
|
+
principal.addProgramPath(filePath);
|
|
278
|
+
}
|
|
279
|
+
for (const filePath of file.imports.entryFiles) {
|
|
275
280
|
const isIgnored = isGitIgnored(filePath);
|
|
276
281
|
if (!isIgnored)
|
|
277
282
|
principal.addEntryPath(filePath, { skipExportsAnalysis: true });
|
|
@@ -283,7 +288,7 @@ export async function build({ chief, collector, counselor, deputy, factory, isGi
|
|
|
283
288
|
file.imports.external.add({ ..._import, specifier: packageName });
|
|
284
289
|
const principal = getPrincipalByFilePath(_import.filePath);
|
|
285
290
|
if (principal && !isGitIgnored(_import.filePath)) {
|
|
286
|
-
principal.
|
|
291
|
+
principal.addProgramPath(_import.filePath);
|
|
287
292
|
}
|
|
288
293
|
}
|
|
289
294
|
}
|
|
@@ -16,7 +16,7 @@ const production = [
|
|
|
16
16
|
];
|
|
17
17
|
const resolveFromAST = sourceFile => {
|
|
18
18
|
const srcDir = getSrcDir(sourceFile);
|
|
19
|
-
const setSrcDir = (entry) => entry.replace(
|
|
19
|
+
const setSrcDir = (entry) => entry.replace(/^src\//, `${srcDir}/`);
|
|
20
20
|
return [
|
|
21
21
|
...entry.map(setSrcDir).map(path => toEntry(path)),
|
|
22
22
|
...production.map(setSrcDir).map(path => toProductionEntry(path)),
|
|
@@ -37,7 +37,8 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
37
37
|
const internal = new Map();
|
|
38
38
|
const external = new Set();
|
|
39
39
|
const unresolved = new Set();
|
|
40
|
-
const
|
|
40
|
+
const programFiles = new Set();
|
|
41
|
+
const entryFiles = new Set();
|
|
41
42
|
const imports = new Set();
|
|
42
43
|
const exports = new Map();
|
|
43
44
|
const aliasedExports = new Map();
|
|
@@ -132,9 +133,11 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
132
133
|
if (module) {
|
|
133
134
|
const filePath = module.resolvedFileName;
|
|
134
135
|
if (filePath) {
|
|
135
|
-
if (
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
if (!isInNodeModules(filePath)) {
|
|
137
|
+
if (opts.modifiers & IMPORT_MODIFIERS.ENTRY)
|
|
138
|
+
entryFiles.add(filePath);
|
|
139
|
+
if (opts.modifiers & IMPORT_MODIFIERS.BRIDGE)
|
|
140
|
+
programFiles.add(filePath);
|
|
138
141
|
}
|
|
139
142
|
if (!module.isExternalLibraryImport || !isInNodeModules(filePath)) {
|
|
140
143
|
const { line, character } = node.getSourceFile().getLineAndCharacterOfPosition(opts.pos);
|
|
@@ -176,7 +179,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
176
179
|
if (opts.specifier.startsWith(PROTOCOL_VIRTUAL))
|
|
177
180
|
return;
|
|
178
181
|
if (opts.modifiers && opts.modifiers & IMPORT_MODIFIERS.OPTIONAL) {
|
|
179
|
-
|
|
182
|
+
programFiles.add(resolve(dirname(sourceFile.fileName), opts.specifier));
|
|
180
183
|
return;
|
|
181
184
|
}
|
|
182
185
|
const pos = 'moduleSpecifier' in node ? node.moduleSpecifier.pos : node.pos;
|
|
@@ -441,7 +444,7 @@ const getImportsAndExports = (sourceFile, resolveModule, typeChecker, options, i
|
|
|
441
444
|
item.symbol = undefined;
|
|
442
445
|
}
|
|
443
446
|
return {
|
|
444
|
-
imports: { internal, external,
|
|
447
|
+
imports: { internal, external, programFiles, entryFiles, imports, unresolved },
|
|
445
448
|
exports,
|
|
446
449
|
duplicates: [...aliasedExports.values()],
|
|
447
450
|
scripts,
|
|
@@ -7,7 +7,7 @@ export default visit(() => true, node => {
|
|
|
7
7
|
if (isRequireCall(node)) {
|
|
8
8
|
if (ts.isStringLiteralLike(node.arguments[0])) {
|
|
9
9
|
const specifier = node.arguments[0].text;
|
|
10
|
-
const modifiers = isNotJS(node.getSourceFile()) ? IMPORT_MODIFIERS.
|
|
10
|
+
const modifiers = isNotJS(node.getSourceFile()) ? IMPORT_MODIFIERS.BRIDGE : IMPORT_MODIFIERS.NONE;
|
|
11
11
|
if (specifier) {
|
|
12
12
|
const propertyAccessExpression = findAncestor(node, _node => {
|
|
13
13
|
if (ts.isExpressionStatement(_node) || ts.isCallExpression(_node))
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import fg from 'fast-glob';
|
|
3
3
|
import { partition } from './array.js';
|
|
4
|
-
import { debugLog } from './debug.js';
|
|
5
4
|
import { ConfigurationError } from './errors.js';
|
|
6
5
|
import { getPackageName } from './package-name.js';
|
|
7
6
|
import { join } from './path.js';
|
|
@@ -11,14 +10,15 @@ export default async function mapWorkspaces(cwd, workspaces) {
|
|
|
11
10
|
const wsPkgNames = new Set();
|
|
12
11
|
if (patterns.length === 0 && negatedPatterns.length === 0)
|
|
13
12
|
return [packages, wsPkgNames];
|
|
14
|
-
const
|
|
13
|
+
const manifestPatterns = patterns.map(p => join(p, 'package.json'));
|
|
14
|
+
const matches = await fg.glob(manifestPatterns, {
|
|
15
15
|
cwd,
|
|
16
|
-
|
|
17
|
-
ignore: ['**/node_modules/**', ...negatedPatterns],
|
|
16
|
+
ignore: ['**/node_modules/**', ...negatedPatterns.map(p => p.slice(1))],
|
|
18
17
|
});
|
|
19
|
-
for (const
|
|
18
|
+
for (const match of matches) {
|
|
19
|
+
const name = match === 'package.json' ? '.' : match.replace(/\/package\.json$/, '');
|
|
20
20
|
const dir = join(cwd, name);
|
|
21
|
-
const manifestPath = join(
|
|
21
|
+
const manifestPath = join(cwd, match);
|
|
22
22
|
try {
|
|
23
23
|
const manifestStr = await readFile(manifestPath, 'utf8');
|
|
24
24
|
const manifest = JSON.parse(manifestStr);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.73.
|
|
1
|
+
export declare const version = "5.73.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.73.
|
|
1
|
+
export const version = '5.73.1';
|