knip 5.4.0 → 5.5.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/index.js +23 -122
- package/dist/manifest/index.js +2 -2
- package/dist/typescript/SourceFile.d.ts +9 -1
- package/dist/typescript/getImportsAndExports.js +4 -4
- package/dist/typescript/resolveModuleNames.js +1 -1
- package/dist/typescript/visitors/dynamic-imports/importType.js +2 -2
- package/dist/typescript/visitors/helpers.d.ts +2 -1
- package/dist/typescript/visitors/helpers.js +25 -6
- package/dist/util/get-reexporting-entry-file.d.ts +3 -0
- package/dist/util/get-reexporting-entry-file.js +55 -0
- package/dist/util/globby.js +2 -2
- package/dist/util/is-identifier-referenced.d.ts +2 -0
- package/dist/util/is-identifier-referenced.js +44 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/schema.json +1 -1
- /package/dist/util/{handleReferencedDependency.d.ts → handle-dependency.d.ts} +0 -0
- /package/dist/util/{handleReferencedDependency.js → handle-dependency.js} +0 -0
package/dist/index.js
CHANGED
|
@@ -8,10 +8,12 @@ import { IssueFixer } from './IssueFixer.js';
|
|
|
8
8
|
import { getFilteredScripts } from './manifest/helpers.js';
|
|
9
9
|
import { PrincipalFactory } from './PrincipalFactory.js';
|
|
10
10
|
import { ProjectPrincipal } from './ProjectPrincipal.js';
|
|
11
|
-
import { debugLogObject, debugLogArray, debugLog
|
|
11
|
+
import { debugLogObject, debugLogArray, debugLog } from './util/debug.js';
|
|
12
|
+
import { getReExportingEntryFileHandler } from './util/get-reexporting-entry-file.js';
|
|
12
13
|
import { _glob, negate } from './util/glob.js';
|
|
13
14
|
import { getGitIgnoredFn } from './util/globby.js';
|
|
14
|
-
import { getHandler } from './util/
|
|
15
|
+
import { getHandler } from './util/handle-dependency.js';
|
|
16
|
+
import { getIsIdentifierReferencedHandler } from './util/is-identifier-referenced.js';
|
|
15
17
|
import { getEntryPathFromManifest, getPackageNameFromModuleSpecifier } from './util/modules.js';
|
|
16
18
|
import { dirname, join } from './util/path.js';
|
|
17
19
|
import { hasMatch } from './util/regex.js';
|
|
@@ -168,7 +170,6 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
168
170
|
const importedSymbols = {};
|
|
169
171
|
const unreferencedFiles = new Set();
|
|
170
172
|
const entryPaths = new Set();
|
|
171
|
-
const exportedClasses = new Set();
|
|
172
173
|
for (const principal of principals) {
|
|
173
174
|
principal.init();
|
|
174
175
|
const handleReferencedDependency = getHandler(collector, deputy, chief);
|
|
@@ -277,93 +278,8 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
277
278
|
if (isSkipLibs)
|
|
278
279
|
factory.deletePrincipal(principal);
|
|
279
280
|
}
|
|
280
|
-
const isIdentifierReferenced = (
|
|
281
|
-
|
|
282
|
-
exportLookupLog(depth, `no imports found from`, filePath);
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
if (importsForExport.identifiers.has(id)) {
|
|
286
|
-
exportLookupLog(depth, `imported from`, filePath);
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
for (const ns of importsForExport.importedNs) {
|
|
290
|
-
if (importsForExport.identifiers.has(`${ns}.${id}`)) {
|
|
291
|
-
exportLookupLog(depth, `imported on ${ns} from`, filePath);
|
|
292
|
-
return true;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
if (importsForExport.isReExport) {
|
|
296
|
-
for (const filePath of importsForExport.isReExportedBy) {
|
|
297
|
-
if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
|
|
298
|
-
exportLookupLog(depth, `re-exported by`, filePath);
|
|
299
|
-
return true;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
for (const [filePath, alias] of importsForExport.isReExportedAs) {
|
|
303
|
-
if (isIdentifierReferenced(filePath, alias, importedSymbols[filePath], depth + 1)) {
|
|
304
|
-
exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
for (const [filePath, ns] of importsForExport.isReExportedNs) {
|
|
309
|
-
if (isIdentifierReferenced(filePath, `${ns}.${id}`, importedSymbols[filePath], depth + 1)) {
|
|
310
|
-
exportLookupLog(depth, `re-exported on ${ns} by`, filePath);
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
exportLookupLog(depth, `not imported from`, filePath);
|
|
316
|
-
return false;
|
|
317
|
-
};
|
|
318
|
-
const getReExportingEntryFile = (importedModule, id, depth = 0) => {
|
|
319
|
-
if (!importedModule)
|
|
320
|
-
return undefined;
|
|
321
|
-
if (importedModule.isReExport) {
|
|
322
|
-
for (const filePath of importedModule.isReExportedBy) {
|
|
323
|
-
if (entryPaths.has(filePath)) {
|
|
324
|
-
if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
|
|
325
|
-
exportLookupLog(depth, `re-exported by entry`, filePath);
|
|
326
|
-
return filePath;
|
|
327
|
-
}
|
|
328
|
-
else if (importedModule.hasStar) {
|
|
329
|
-
exportLookupLog(depth, `re-exported (*) by entry`, filePath);
|
|
330
|
-
return filePath;
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
exportLookupLog(depth, `re-exported by`, filePath);
|
|
335
|
-
const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
|
|
336
|
-
if (file)
|
|
337
|
-
return file;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
for (const [filePath, namespace] of importedModule.isReExportedNs) {
|
|
341
|
-
if (entryPaths.has(filePath)) {
|
|
342
|
-
exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
|
|
343
|
-
return filePath;
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
|
|
347
|
-
const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
|
|
348
|
-
if (file)
|
|
349
|
-
return file;
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
for (const [filePath, alias] of importedModule.isReExportedAs) {
|
|
353
|
-
if (entryPaths.has(filePath)) {
|
|
354
|
-
exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
|
|
355
|
-
return filePath;
|
|
356
|
-
}
|
|
357
|
-
else {
|
|
358
|
-
exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
|
|
359
|
-
const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
|
|
360
|
-
if (file)
|
|
361
|
-
return file;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
|
|
366
|
-
};
|
|
281
|
+
const isIdentifierReferenced = getIsIdentifierReferencedHandler(importedSymbols);
|
|
282
|
+
const getReExportingEntryFile = getReExportingEntryFileHandler(entryPaths, exportedSymbols, importedSymbols);
|
|
367
283
|
const isExportedItemReferenced = (exportedItem) => {
|
|
368
284
|
return (exportedItem.refs > 0 &&
|
|
369
285
|
(typeof chief.config.ignoreExportsUsedInFile === 'object'
|
|
@@ -374,6 +290,7 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
374
290
|
streamer.cast('Analyzing source files...');
|
|
375
291
|
for (const [filePath, exportItems] of Object.entries(exportedSymbols)) {
|
|
376
292
|
const workspace = chief.findWorkspaceByFilePath(filePath);
|
|
293
|
+
const principal = workspace && factory.getPrincipalByPackageName(workspace.pkgName);
|
|
377
294
|
if (workspace) {
|
|
378
295
|
const { isIncludeEntryExports } = workspace.config;
|
|
379
296
|
if (!isIncludeEntryExports && entryPaths.has(filePath))
|
|
@@ -390,20 +307,17 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
390
307
|
continue;
|
|
391
308
|
if (importsForExport) {
|
|
392
309
|
if (!isIncludeEntryExports) {
|
|
393
|
-
|
|
394
|
-
if (getReExportingEntryFile(importsForExport, identifier))
|
|
310
|
+
if (getReExportingEntryFile(importsForExport, identifier, 0, filePath))
|
|
395
311
|
continue;
|
|
396
312
|
}
|
|
397
|
-
exportLookupLog(-1, `Looking up ${identifier} export from`, filePath);
|
|
398
313
|
if (isIdentifierReferenced(filePath, identifier, importsForExport)) {
|
|
399
|
-
if (exportedItem.type === 'enum') {
|
|
314
|
+
if (report.enumMembers && exportedItem.type === 'enum') {
|
|
400
315
|
exportedItem.members?.forEach(member => {
|
|
401
316
|
if (hasMatch(workspace.ignoreMembers, member.identifier))
|
|
402
317
|
return;
|
|
403
318
|
if (shouldIgnore(member.jsDocTags, tags))
|
|
404
319
|
return;
|
|
405
320
|
if (member.refs === 0) {
|
|
406
|
-
exportLookupLog(-1, `Looking up export member ${identifier}.${member.identifier} from`, filePath);
|
|
407
321
|
if (!isIdentifierReferenced(filePath, `${identifier}.${member.identifier}`, importsForExport)) {
|
|
408
322
|
collector.addIssue({
|
|
409
323
|
type: 'enumMembers',
|
|
@@ -419,7 +333,18 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
419
333
|
});
|
|
420
334
|
}
|
|
421
335
|
if (isReportClassMembers && exportedItem.type === 'class') {
|
|
422
|
-
|
|
336
|
+
const members = exportedItem.members.filter(member => !hasMatch(workspace.ignoreMembers, member.identifier) && !shouldIgnore(member.jsDocTags, tags));
|
|
337
|
+
principal?.findUnusedMembers(filePath, members).forEach(member => {
|
|
338
|
+
collector.addIssue({
|
|
339
|
+
type: 'classMembers',
|
|
340
|
+
filePath,
|
|
341
|
+
symbol: member.identifier,
|
|
342
|
+
parentSymbol: exportedItem.identifier,
|
|
343
|
+
pos: member.pos,
|
|
344
|
+
line: member.line,
|
|
345
|
+
col: member.col,
|
|
346
|
+
});
|
|
347
|
+
});
|
|
423
348
|
}
|
|
424
349
|
continue;
|
|
425
350
|
}
|
|
@@ -429,11 +354,8 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
429
354
|
if (hasStrictlyNsReferences && ((!report.nsTypes && isType) || (!report.nsExports && !isType)))
|
|
430
355
|
continue;
|
|
431
356
|
if (!isExportedItemReferenced(exportedItem)) {
|
|
432
|
-
if (!isSkipLibs)
|
|
433
|
-
|
|
434
|
-
if (principal?.hasReferences(filePath, exportedItem))
|
|
435
|
-
continue;
|
|
436
|
-
}
|
|
357
|
+
if (!isSkipLibs && principal?.hasReferences(filePath, exportedItem))
|
|
358
|
+
continue;
|
|
437
359
|
const type = getType(hasStrictlyNsReferences, isType);
|
|
438
360
|
collector.addIssue({
|
|
439
361
|
type,
|
|
@@ -469,27 +391,6 @@ export const main = async (unresolvedConfiguration) => {
|
|
|
469
391
|
const unusedIgnoredWorkspaces = chief.getUnusedIgnoredWorkspaces();
|
|
470
392
|
unusedIgnoredWorkspaces.forEach(identifier => collector.addConfigurationHint({ type: 'ignoreWorkspaces', identifier }));
|
|
471
393
|
const { issues, counters, configurationHints } = collector.getIssues();
|
|
472
|
-
if (isReportClassMembers) {
|
|
473
|
-
streamer.cast('Validating expensive classy memberships...');
|
|
474
|
-
for (const [filePath, exportedItem] of exportedClasses) {
|
|
475
|
-
const workspace = chief.findWorkspaceByFilePath(filePath);
|
|
476
|
-
const principal = workspace && factory.getPrincipalByPackageName(workspace.pkgName);
|
|
477
|
-
if (principal) {
|
|
478
|
-
const members = exportedItem.members.filter(member => !hasMatch(workspace.ignoreMembers, member.identifier) && !shouldIgnore(member.jsDocTags, tags));
|
|
479
|
-
principal.findUnusedMembers(filePath, members).forEach(member => {
|
|
480
|
-
collector.addIssue({
|
|
481
|
-
type: 'classMembers',
|
|
482
|
-
filePath,
|
|
483
|
-
symbol: member.identifier,
|
|
484
|
-
parentSymbol: exportedItem.identifier,
|
|
485
|
-
pos: member.pos,
|
|
486
|
-
line: member.line,
|
|
487
|
-
col: member.col,
|
|
488
|
-
});
|
|
489
|
-
});
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
394
|
if (isFix) {
|
|
494
395
|
await fixer.fixIssues(issues);
|
|
495
396
|
}
|
package/dist/manifest/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { isDefinitelyTyped } from '../util/modules.js';
|
|
2
2
|
import { timerify } from '../util/Performance.js';
|
|
3
3
|
import { loadPackageManifest } from './helpers.js';
|
|
4
|
-
const
|
|
4
|
+
const getMetaDataFromPackageJson = ({ cwd, dir, packageNames }) => {
|
|
5
5
|
const hostDependencies = new Map();
|
|
6
6
|
const installedBinaries = new Map();
|
|
7
7
|
const hasTypesIncluded = new Set();
|
|
@@ -47,4 +47,4 @@ const _getDependencyMetaData = ({ cwd, dir, packageNames }) => {
|
|
|
47
47
|
hasTypesIncluded,
|
|
48
48
|
};
|
|
49
49
|
};
|
|
50
|
-
export const getDependencyMetaData = timerify(
|
|
50
|
+
export const getDependencyMetaData = timerify(getMetaDataFromPackageJson);
|
|
@@ -5,7 +5,15 @@ type SymbolWithExports = ts.Symbol & {
|
|
|
5
5
|
};
|
|
6
6
|
type PragmaMap = {
|
|
7
7
|
arguments: {
|
|
8
|
-
factory
|
|
8
|
+
factory?: string;
|
|
9
|
+
path?: {
|
|
10
|
+
value?: string;
|
|
11
|
+
pos?: number;
|
|
12
|
+
};
|
|
13
|
+
types?: {
|
|
14
|
+
value?: string;
|
|
15
|
+
pos?: number;
|
|
16
|
+
};
|
|
9
17
|
};
|
|
10
18
|
};
|
|
11
19
|
export interface BoundSourceFile extends ts.SourceFile {
|
|
@@ -7,7 +7,7 @@ import { shouldIgnore } from '../util/tag.js';
|
|
|
7
7
|
import { isAccessExpression, getJSDocTags, getLineAndCharacterOfPosition, getMemberStringLiterals, } from './ast-helpers.js';
|
|
8
8
|
import getDynamicImportVisitors from './visitors/dynamic-imports/index.js';
|
|
9
9
|
import getExportVisitors from './visitors/exports/index.js';
|
|
10
|
-
import {
|
|
10
|
+
import { getImportsFromPragmas } from './visitors/helpers.js';
|
|
11
11
|
import getImportVisitors from './visitors/imports/index.js';
|
|
12
12
|
import getScriptVisitors from './visitors/scripts/index.js';
|
|
13
13
|
const getVisitors = (sourceFile) => ({
|
|
@@ -39,9 +39,6 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
39
39
|
const aliasedExports = new Map();
|
|
40
40
|
const scripts = new Set();
|
|
41
41
|
const importedInternalSymbols = new Map();
|
|
42
|
-
const jsxImport = getJSXImplicitImportBase(sourceFile);
|
|
43
|
-
if (jsxImport)
|
|
44
|
-
externalImports.add(jsxImport);
|
|
45
42
|
const visitors = getVisitors(sourceFile);
|
|
46
43
|
const addInternalImport = (options) => {
|
|
47
44
|
const { identifier, specifier, symbol, filePath, namespace, isReExport } = options;
|
|
@@ -288,6 +285,9 @@ const getImportsAndExports = (sourceFile, getResolvedModule, typeChecker, option
|
|
|
288
285
|
ts.forEachChild(node, visit);
|
|
289
286
|
};
|
|
290
287
|
visit(sourceFile);
|
|
288
|
+
const pragmaImports = getImportsFromPragmas(sourceFile);
|
|
289
|
+
if (pragmaImports)
|
|
290
|
+
pragmaImports.forEach(node => addImport(node, sourceFile));
|
|
291
291
|
const setRefs = (item) => {
|
|
292
292
|
if (!item.symbol)
|
|
293
293
|
return;
|
|
@@ -42,7 +42,7 @@ export function createCustomModuleResolver(customSys, compilerOptions, virtualFi
|
|
|
42
42
|
const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.mts$/, '.mjs');
|
|
43
43
|
return { resolvedFileName, extension: '.mjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
|
|
44
44
|
}
|
|
45
|
-
if (tsResolvedModule.extension === '.d.cts') {
|
|
45
|
+
else if (tsResolvedModule.extension === '.d.cts') {
|
|
46
46
|
const resolvedFileName = tsResolvedModule.resolvedFileName.replace(/\.d\.cts$/, '.cjs');
|
|
47
47
|
return { resolvedFileName, extension: '.cjs', isExternalLibraryImport: false, resolvedUsingTsExtension: false };
|
|
48
48
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
import { importVisitor as visit } from '../index.js';
|
|
3
3
|
export default visit(() => true, node => {
|
|
4
|
-
if (ts.isImportTypeNode(node)
|
|
4
|
+
if (ts.isImportTypeNode(node)) {
|
|
5
5
|
if (ts.isLiteralTypeNode(node.argument) && ts.isStringLiteral(node.argument.literal)) {
|
|
6
|
-
return { specifier: node.argument.literal.text, identifier: undefined, pos: 0 };
|
|
6
|
+
return { specifier: node.argument.literal.text, identifier: undefined, pos: 0, isTypeOnly: true };
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import type { ImportNode } from '../../types/imports.js';
|
|
2
3
|
import type { BoundSourceFile } from '../SourceFile.js';
|
|
3
4
|
export declare const isNotJS: (sourceFile: BoundSourceFile) => boolean;
|
|
4
5
|
export declare const isJS: (sourceFile: BoundSourceFile) => boolean;
|
|
5
|
-
export declare function
|
|
6
|
+
export declare function getImportsFromPragmas(sourceFile: BoundSourceFile): ImportNode[];
|
|
6
7
|
export declare function hasImportSpecifier(node: ts.Statement, name: string): boolean;
|
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
export const isNotJS = (sourceFile) => sourceFile.scriptKind !== ts.ScriptKind.JS && sourceFile.scriptKind !== ts.ScriptKind.JSX;
|
|
3
3
|
export const isJS = (sourceFile) => sourceFile.scriptKind === ts.ScriptKind.JS || sourceFile.scriptKind === ts.ScriptKind.JSX;
|
|
4
|
-
export function
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export function getImportsFromPragmas(sourceFile) {
|
|
5
|
+
const importNodes = [];
|
|
6
|
+
if (sourceFile.pragmas) {
|
|
7
|
+
const jsxImportSourcePragmas = sourceFile.pragmas.get('jsximportsource');
|
|
8
|
+
if (jsxImportSourcePragmas) {
|
|
9
|
+
const jsxImportSourcePragma = Array.isArray(jsxImportSourcePragmas)
|
|
10
|
+
? jsxImportSourcePragmas[jsxImportSourcePragmas.length - 1]
|
|
11
|
+
: jsxImportSourcePragmas;
|
|
12
|
+
const { factory: specifier } = jsxImportSourcePragma?.arguments ?? {};
|
|
13
|
+
if (specifier)
|
|
14
|
+
importNodes.push({ specifier, isTypeOnly: true, identifier: '__jsx', pos: 0 });
|
|
15
|
+
}
|
|
16
|
+
const referencePragma = sourceFile.pragmas.get('reference');
|
|
17
|
+
if (referencePragma) {
|
|
18
|
+
const refs = [referencePragma].flat();
|
|
19
|
+
for (const ref of refs) {
|
|
20
|
+
if (ref.arguments?.types) {
|
|
21
|
+
const { value: specifier, pos } = ref.arguments.types;
|
|
22
|
+
if (specifier)
|
|
23
|
+
importNodes.push({ specifier, isTypeOnly: true, identifier: undefined, pos });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return importNodes;
|
|
10
29
|
}
|
|
11
30
|
export function hasImportSpecifier(node, name) {
|
|
12
31
|
return (ts.isImportDeclaration(node) &&
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { SerializableExportMap } from '../types/exports.js';
|
|
2
|
+
import type { SerializableImportMap, SerializableImports } from '../types/imports.js';
|
|
3
|
+
export declare const getReExportingEntryFileHandler: (entryPaths: Set<string>, exportedSymbols: SerializableExportMap, importedSymbols: SerializableImportMap) => (importedModule: SerializableImports | undefined, id: string, depth?: number, filePath?: string) => string | undefined;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { exportLookupLog } from './debug.js';
|
|
2
|
+
export const getReExportingEntryFileHandler = (entryPaths, exportedSymbols, importedSymbols) => {
|
|
3
|
+
const getReExportingEntryFile = (importedModule, id, depth = 0, filePath) => {
|
|
4
|
+
if (depth === 0 && filePath)
|
|
5
|
+
exportLookupLog(-1, `Looking up re-exporting file for ${id} from`, filePath);
|
|
6
|
+
if (!importedModule)
|
|
7
|
+
return undefined;
|
|
8
|
+
if (importedModule.isReExport) {
|
|
9
|
+
for (const filePath of importedModule.isReExportedBy) {
|
|
10
|
+
if (entryPaths.has(filePath)) {
|
|
11
|
+
if (filePath in exportedSymbols && id in exportedSymbols[filePath]) {
|
|
12
|
+
exportLookupLog(depth, `re-exported by entry`, filePath);
|
|
13
|
+
return filePath;
|
|
14
|
+
}
|
|
15
|
+
else if (importedModule.hasStar) {
|
|
16
|
+
exportLookupLog(depth, `re-exported (*) by entry`, filePath);
|
|
17
|
+
return filePath;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
exportLookupLog(depth, `re-exported by`, filePath);
|
|
22
|
+
const file = getReExportingEntryFile(importedSymbols[filePath], id, depth + 1);
|
|
23
|
+
if (file)
|
|
24
|
+
return file;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const [filePath, namespace] of importedModule.isReExportedNs) {
|
|
28
|
+
if (entryPaths.has(filePath)) {
|
|
29
|
+
exportLookupLog(depth, `re-exported on ${namespace} by entry`, filePath);
|
|
30
|
+
return filePath;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
exportLookupLog(depth, `re-exported on ${namespace} by`, filePath);
|
|
34
|
+
const file = getReExportingEntryFile(importedSymbols[filePath], namespace, depth + 1);
|
|
35
|
+
if (file)
|
|
36
|
+
return file;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
for (const [filePath, alias] of importedModule.isReExportedAs) {
|
|
40
|
+
if (entryPaths.has(filePath)) {
|
|
41
|
+
exportLookupLog(depth, `re-exported as ${alias} by entry`, filePath);
|
|
42
|
+
return filePath;
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
|
|
46
|
+
const file = getReExportingEntryFile(importedSymbols[filePath], alias, depth + 1);
|
|
47
|
+
if (file)
|
|
48
|
+
return file;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exportLookupLog(depth, `${id} is not re-exported by entry file`, '');
|
|
53
|
+
};
|
|
54
|
+
return getReExportingEntryFile;
|
|
55
|
+
};
|
package/dist/util/globby.js
CHANGED
|
@@ -21,7 +21,7 @@ function convertGitignoreToMicromatch(pattern) {
|
|
|
21
21
|
pattern = pattern.slice(5);
|
|
22
22
|
if (pattern.startsWith('/'))
|
|
23
23
|
pattern = pattern.slice(1);
|
|
24
|
-
else
|
|
24
|
+
else if (!pattern.startsWith('**/'))
|
|
25
25
|
pattern = '**/' + pattern;
|
|
26
26
|
if (pattern.endsWith('/*'))
|
|
27
27
|
extPattern = pattern;
|
|
@@ -36,7 +36,7 @@ function parseGitignoreFile(filePath) {
|
|
|
36
36
|
return file
|
|
37
37
|
.split(/\r?\n/)
|
|
38
38
|
.filter(line => line && !line.startsWith('#'))
|
|
39
|
-
.map(pattern => convertGitignoreToMicromatch(pattern));
|
|
39
|
+
.map(pattern => convertGitignoreToMicromatch(pattern.replace(/#.*/, '').trim()));
|
|
40
40
|
}
|
|
41
41
|
async function parseFindGitignores(options) {
|
|
42
42
|
const ignores = ['.git', ...GLOBAL_IGNORE_PATTERNS];
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { SerializableImportMap, SerializableImports } from '../types/imports.js';
|
|
2
|
+
export declare const getIsIdentifierReferencedHandler: (importedSymbols: SerializableImportMap) => (filePath: string, id: string, importsForExport?: SerializableImports, depth?: number) => boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { exportLookupLog } from './debug.js';
|
|
2
|
+
export const getIsIdentifierReferencedHandler = (importedSymbols) => {
|
|
3
|
+
const isIdentifierReferenced = (filePath, id, importsForExport, depth = 0) => {
|
|
4
|
+
if (depth === 0)
|
|
5
|
+
exportLookupLog(-1, `Looking up export "${id}" from`, filePath);
|
|
6
|
+
if (!importsForExport) {
|
|
7
|
+
exportLookupLog(depth, `no imports found from`, filePath);
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
if (importsForExport.identifiers.has(id)) {
|
|
11
|
+
exportLookupLog(depth, `imported from`, filePath);
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
for (const ns of importsForExport.importedNs) {
|
|
15
|
+
if (importsForExport.identifiers.has(`${ns}.${id}`)) {
|
|
16
|
+
exportLookupLog(depth, `imported on ${ns} from`, filePath);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (importsForExport.isReExport) {
|
|
21
|
+
for (const filePath of importsForExport.isReExportedBy) {
|
|
22
|
+
if (isIdentifierReferenced(filePath, id, importedSymbols[filePath], depth + 1)) {
|
|
23
|
+
exportLookupLog(depth, `re-exported by`, filePath);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
for (const [filePath, alias] of importsForExport.isReExportedAs) {
|
|
28
|
+
if (isIdentifierReferenced(filePath, alias, importedSymbols[filePath], depth + 1)) {
|
|
29
|
+
exportLookupLog(depth, `re-exported as ${alias} by`, filePath);
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const [filePath, ns] of importsForExport.isReExportedNs) {
|
|
34
|
+
if (isIdentifierReferenced(filePath, `${ns}.${id}`, importedSymbols[filePath], depth + 1)) {
|
|
35
|
+
exportLookupLog(depth, `re-exported on ${ns} by`, filePath);
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exportLookupLog(depth, `not imported from`, filePath);
|
|
41
|
+
return false;
|
|
42
|
+
};
|
|
43
|
+
return isIdentifierReferenced;
|
|
44
|
+
};
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "5.
|
|
1
|
+
export declare const version = "5.5.0";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '5.
|
|
1
|
+
export const version = '5.5.0';
|
package/package.json
CHANGED
package/schema.json
CHANGED
|
File without changes
|
|
File without changes
|