deslop-js 0.9.3 → 0.9.5
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/analyzed-inputs.cjs +1 -1
- package/dist/analyzed-inputs.mjs +1 -1
- package/dist/{constants-oYYofMhb.mjs → constants-DBVadY0c.mjs} +1 -2
- package/dist/{constants-CD9NXHxi.cjs → constants-DL5OyI3b.cjs} +0 -7
- package/dist/entries-worker.mjs +1 -8
- package/dist/index.cjs +58 -32
- package/dist/index.mjs +58 -32
- package/dist/{parse-CDdo_Ppt.mjs → parse-C6-m3QMJ.mjs} +25 -4
- package/dist/parse-worker.mjs +1 -1
- package/package.json +1 -1
package/dist/analyzed-inputs.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_constants = require('./constants-
|
|
2
|
+
const require_constants = require('./constants-DL5OyI3b.cjs');
|
|
3
3
|
|
|
4
4
|
exports.ANALYZED_MANIFEST_FILENAMES = require_constants.ANALYZED_MANIFEST_FILENAMES;
|
|
5
5
|
exports.DEFAULT_EXTENSIONS = require_constants.DEFAULT_EXTENSIONS;
|
package/dist/analyzed-inputs.mjs
CHANGED
|
@@ -86,7 +86,6 @@ const DEFAULT_EXCLUSIONS = [
|
|
|
86
86
|
const SCRIPT_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|tsc|npx|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:\s|$)/;
|
|
87
87
|
const SCRIPT_EXTENSIONLESS_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?((?:[./]|[\w@][\w@-]*\/)[\w./@-]+)(?:\s|$)/;
|
|
88
88
|
const SCRIPT_CONFIG_FILE_PATTERN = /--config\s+([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))/;
|
|
89
|
-
const SCRIPT_ENTRY_PATTERNS = [];
|
|
90
89
|
const DEFAULT_ENTRY_GLOBS = [
|
|
91
90
|
"src/index.{ts,tsx,js,jsx}",
|
|
92
91
|
"src/main.{ts,tsx,js,jsx}",
|
|
@@ -341,4 +340,4 @@ const DEFAULT_SEMANTIC_TSCONFIG_NAMES = [
|
|
|
341
340
|
const GIT_CHECK_IGNORE_MAX_BUFFER_BYTES = 10 * 1024 * 1024;
|
|
342
341
|
|
|
343
342
|
//#endregion
|
|
344
|
-
export {
|
|
343
|
+
export { SUMMARY_CACHE_MAX_BYTES as A, RESOLVER_EXTENSIONS as C, SEMANTIC_MAX_PROGRAM_FILES as D, SCRIPT_FILE_PATTERN as E, SOURCE_EXTENSIONS as O, REACT_NATIVE_PLATFORM_EXTENSIONS as S, SCRIPT_EXTENSIONLESS_FILE_PATTERN as T, MINIFIED_DETECTION_MIN_BYTES as _, DEFAULT_EXCLUSIONS as a, OUTPUT_DIRECTORIES as b, DEFAULT_SEMANTIC_TSCONFIG_NAMES as c, IMPLICIT_DEPENDENCIES as d, KNOWN_CONFIG_PREFIXES as f, MAX_PARSE_FILE_SIZE_BYTES as g, MAX_ERROR_DETAIL_LENGTH as h, DEFAULT_ENTRY_GLOBS as i, STANDALONE_PROJECT_LOCKFILES as k, GIT_CHECK_IGNORE_MAX_BUFFER_BYTES as l, MAX_ANALYSIS_ERRORS as m, BINARY_DETECTION_SAMPLE_BYTES as n, DEFAULT_EXTENSIONS as o, LOCKFILE_MARKERS as p, BUILTIN_MODULES as r, DEFAULT_SEMANTIC_DECORATOR_ALLOWLIST as s, ANALYZED_MANIFEST_FILENAMES as t, HIDDEN_DIRECTORY_ALLOWLIST as u, MIN_NUMERIC_LITERAL_MAGNITUDE_FOR_DUPLICATE as v, SCRIPT_CONFIG_FILE_PATTERN as w, PLATFORM_SUFFIXES as x, MONOREPO_ROOT_MARKERS as y };
|
|
@@ -87,7 +87,6 @@ const DEFAULT_EXCLUSIONS = [
|
|
|
87
87
|
const SCRIPT_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|tsc|npx|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:\s|$)/;
|
|
88
88
|
const SCRIPT_EXTENSIONLESS_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?((?:[./]|[\w@][\w@-]*\/)[\w./@-]+)(?:\s|$)/;
|
|
89
89
|
const SCRIPT_CONFIG_FILE_PATTERN = /--config\s+([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))/;
|
|
90
|
-
const SCRIPT_ENTRY_PATTERNS = [];
|
|
91
90
|
const DEFAULT_ENTRY_GLOBS = [
|
|
92
91
|
"src/index.{ts,tsx,js,jsx}",
|
|
93
92
|
"src/main.{ts,tsx,js,jsx}",
|
|
@@ -486,12 +485,6 @@ Object.defineProperty(exports, 'SCRIPT_CONFIG_FILE_PATTERN', {
|
|
|
486
485
|
return SCRIPT_CONFIG_FILE_PATTERN;
|
|
487
486
|
}
|
|
488
487
|
});
|
|
489
|
-
Object.defineProperty(exports, 'SCRIPT_ENTRY_PATTERNS', {
|
|
490
|
-
enumerable: true,
|
|
491
|
-
get: function () {
|
|
492
|
-
return SCRIPT_ENTRY_PATTERNS;
|
|
493
|
-
}
|
|
494
|
-
});
|
|
495
488
|
Object.defineProperty(exports, 'SCRIPT_EXTENSIONLESS_FILE_PATTERN', {
|
|
496
489
|
enumerable: true,
|
|
497
490
|
get: function () {
|
package/dist/entries-worker.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as OUTPUT_DIRECTORIES, c as
|
|
1
|
+
import { a as OUTPUT_DIRECTORIES, c as SCRIPT_EXTENSIONLESS_FILE_PATTERN, d as STANDALONE_PROJECT_LOCKFILES, i as MONOREPO_ROOT_MARKERS, l as SCRIPT_FILE_PATTERN, o as RESOLVER_EXTENSIONS, r as LOCKFILE_MARKERS, s as SCRIPT_CONFIG_FILE_PATTERN, t as extractReactRouterRouteModuleEntries, u as SOURCE_EXTENSIONS$3 } from "./parse-C6-m3QMJ.mjs";
|
|
2
2
|
import { parentPort } from "node:worker_threads";
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import fg from "fast-glob";
|
|
@@ -1868,13 +1868,6 @@ const extractScriptEntries = (directory) => {
|
|
|
1868
1868
|
entries.push(...extractScriptFileArguments(scriptCommand, directory));
|
|
1869
1869
|
}
|
|
1870
1870
|
} catch {}
|
|
1871
|
-
const scriptDirectoryFiles = fg.sync(SCRIPT_ENTRY_PATTERNS, {
|
|
1872
|
-
cwd: directory,
|
|
1873
|
-
absolute: true,
|
|
1874
|
-
onlyFiles: true,
|
|
1875
|
-
ignore: ["**/node_modules/**"]
|
|
1876
|
-
});
|
|
1877
|
-
entries.push(...scriptDirectoryFiles);
|
|
1878
1871
|
return entries;
|
|
1879
1872
|
};
|
|
1880
1873
|
const isYamlMapping = (line) => {
|
package/dist/index.cjs
CHANGED
|
@@ -26,7 +26,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
}) : target, mod));
|
|
27
27
|
|
|
28
28
|
//#endregion
|
|
29
|
-
const require_constants = require('./constants-
|
|
29
|
+
const require_constants = require('./constants-DL5OyI3b.cjs');
|
|
30
30
|
let node_path = require("node:path");
|
|
31
31
|
node_path = __toESM(node_path, 1);
|
|
32
32
|
let node_fs = require("node:fs");
|
|
@@ -1777,7 +1777,7 @@ const parseSourceFile = (filePath) => {
|
|
|
1777
1777
|
wholeObjectUses,
|
|
1778
1778
|
localIdentifierReferences,
|
|
1779
1779
|
topLevelImportReferences,
|
|
1780
|
-
referencedFilenames: extractReferencedFilenames(sourceText),
|
|
1780
|
+
referencedFilenames: extractReferencedFilenames(sourceText, program.body),
|
|
1781
1781
|
redundantTypePatterns,
|
|
1782
1782
|
identityWrappers,
|
|
1783
1783
|
typeDefinitionHashes,
|
|
@@ -1789,11 +1789,33 @@ const parseSourceFile = (filePath) => {
|
|
|
1789
1789
|
};
|
|
1790
1790
|
};
|
|
1791
1791
|
const REFERENCED_FILENAME_LITERAL_PATTERN = /(?<![./@\w-])(?:["'`])([a-z][\w-]*\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:["'`])/g;
|
|
1792
|
-
const
|
|
1792
|
+
const REFERENCED_MODULE_PATH_PATTERN = /^[a-zA-Z0-9_@-][a-zA-Z0-9_@.-]*(?:\/[a-zA-Z0-9_@.-]+)+$/;
|
|
1793
|
+
const extractReferencedFilenames = (sourceText, bodyNodes = []) => {
|
|
1793
1794
|
const captured = /* @__PURE__ */ new Set();
|
|
1794
1795
|
REFERENCED_FILENAME_LITERAL_PATTERN.lastIndex = 0;
|
|
1795
1796
|
let match;
|
|
1796
1797
|
while ((match = REFERENCED_FILENAME_LITERAL_PATTERN.exec(sourceText)) !== null) captured.add(match[1]);
|
|
1798
|
+
const visitNode = (node) => {
|
|
1799
|
+
if (node.type === "ImportExpression") {
|
|
1800
|
+
const sourceExpression = node.source;
|
|
1801
|
+
if (isWalkableNode(sourceExpression) && sourceExpression.type === "Literal") {
|
|
1802
|
+
const literalValue = sourceExpression.value;
|
|
1803
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
if (node.type === "CallExpression" || node.type === "NewExpression") {
|
|
1807
|
+
const callArguments = node.arguments;
|
|
1808
|
+
for (const callArgument of Array.isArray(callArguments) ? callArguments : []) {
|
|
1809
|
+
if (!isWalkableNode(callArgument) || callArgument.type !== "Literal") continue;
|
|
1810
|
+
const literalValue = callArgument.value;
|
|
1811
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1812
|
+
}
|
|
1813
|
+
}
|
|
1814
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) {
|
|
1815
|
+
for (const element of value) if (isWalkableNode(element)) visitNode(element);
|
|
1816
|
+
} else if (isWalkableNode(value)) visitNode(value);
|
|
1817
|
+
};
|
|
1818
|
+
for (const bodyNode of bodyNodes) if (isWalkableNode(bodyNode)) visitNode(bodyNode);
|
|
1797
1819
|
return [...captured];
|
|
1798
1820
|
};
|
|
1799
1821
|
const collectDryPatterns = (bodyNodes, sourceText, redundantTypePatterns, identityWrappers, typeDefinitionHashes) => {
|
|
@@ -5225,13 +5247,6 @@ const extractScriptEntries = (directory) => {
|
|
|
5225
5247
|
entries.push(...extractScriptFileArguments(scriptCommand, directory));
|
|
5226
5248
|
}
|
|
5227
5249
|
} catch {}
|
|
5228
|
-
const scriptDirectoryFiles = fast_glob.default.sync(require_constants.SCRIPT_ENTRY_PATTERNS, {
|
|
5229
|
-
cwd: directory,
|
|
5230
|
-
absolute: true,
|
|
5231
|
-
onlyFiles: true,
|
|
5232
|
-
ignore: ["**/node_modules/**"]
|
|
5233
|
-
});
|
|
5234
|
-
entries.push(...scriptDirectoryFiles);
|
|
5235
5250
|
return entries;
|
|
5236
5251
|
};
|
|
5237
5252
|
const isYamlMapping = (line) => {
|
|
@@ -12371,8 +12386,7 @@ const createDisabledSemanticResult = () => ({
|
|
|
12371
12386
|
unusedClassMembers: [],
|
|
12372
12387
|
misclassifiedDependencies: [],
|
|
12373
12388
|
redundantAliases: [],
|
|
12374
|
-
errors: []
|
|
12375
|
-
contextStatus: "disabled"
|
|
12389
|
+
errors: []
|
|
12376
12390
|
});
|
|
12377
12391
|
const runSemanticAnalysis = (graph, config) => {
|
|
12378
12392
|
const semanticConfig = config.semantic;
|
|
@@ -12393,8 +12407,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12393
12407
|
unusedClassMembers: [],
|
|
12394
12408
|
misclassifiedDependencies,
|
|
12395
12409
|
redundantAliases: [],
|
|
12396
|
-
errors
|
|
12397
|
-
contextStatus: "no-context-required"
|
|
12410
|
+
errors
|
|
12398
12411
|
};
|
|
12399
12412
|
let contextResult;
|
|
12400
12413
|
try {
|
|
@@ -12410,8 +12423,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12410
12423
|
code: "ts-not-loadable",
|
|
12411
12424
|
message: "createSemanticContext threw before returning a result",
|
|
12412
12425
|
detail: describeUnknownError(contextError)
|
|
12413
|
-
})]
|
|
12414
|
-
contextStatus: "typescript-load-failed"
|
|
12426
|
+
})]
|
|
12415
12427
|
};
|
|
12416
12428
|
}
|
|
12417
12429
|
if (!contextResult.ok) return {
|
|
@@ -12420,9 +12432,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12420
12432
|
unusedClassMembers: [],
|
|
12421
12433
|
misclassifiedDependencies,
|
|
12422
12434
|
redundantAliases: [],
|
|
12423
|
-
errors: [...errors, contextResult.failure.error]
|
|
12424
|
-
contextStatus: contextResult.failure.reason,
|
|
12425
|
-
contextMessage: contextResult.failure.message
|
|
12435
|
+
errors: [...errors, contextResult.failure.error]
|
|
12426
12436
|
};
|
|
12427
12437
|
const { context } = contextResult;
|
|
12428
12438
|
let referenceIndex;
|
|
@@ -12441,8 +12451,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12441
12451
|
unusedClassMembers,
|
|
12442
12452
|
misclassifiedDependencies,
|
|
12443
12453
|
redundantAliases: [...variableAliases, ...roundTripAliases],
|
|
12444
|
-
errors
|
|
12445
|
-
contextStatus: "ready"
|
|
12454
|
+
errors
|
|
12446
12455
|
};
|
|
12447
12456
|
};
|
|
12448
12457
|
|
|
@@ -12513,8 +12522,7 @@ const generateReport = (graph, config, summaryCache) => {
|
|
|
12513
12522
|
unusedClassMembers: [],
|
|
12514
12523
|
misclassifiedDependencies: [],
|
|
12515
12524
|
redundantAliases: [],
|
|
12516
|
-
errors: []
|
|
12517
|
-
contextStatus: "typescript-load-failed"
|
|
12525
|
+
errors: []
|
|
12518
12526
|
};
|
|
12519
12527
|
}
|
|
12520
12528
|
for (const semanticError of semanticResult.errors) {
|
|
@@ -12725,7 +12733,7 @@ const isRecordValue = (value) => typeof value === "object" && value !== null &&
|
|
|
12725
12733
|
const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
12726
12734
|
const isOptionalArray = (value) => value === void 0 || Array.isArray(value);
|
|
12727
12735
|
const emptyStore = (scopeHash) => ({
|
|
12728
|
-
version:
|
|
12736
|
+
version: 4,
|
|
12729
12737
|
scopeHash,
|
|
12730
12738
|
fileList: null,
|
|
12731
12739
|
resolutions: null,
|
|
@@ -12735,10 +12743,10 @@ const emptyStore = (scopeHash) => ({
|
|
|
12735
12743
|
const readPersistedStore = (cachePath, scopeHash) => {
|
|
12736
12744
|
try {
|
|
12737
12745
|
const parsed = JSON.parse((0, node_fs.readFileSync)(cachePath, "utf-8"));
|
|
12738
|
-
if (isRecordValue(parsed) && parsed.version ===
|
|
12746
|
+
if (isRecordValue(parsed) && parsed.version === 4 && parsed.scopeHash === scopeHash && isRecordValue(parsed.summaries) && isRecordValue(parsed.packageFacts)) {
|
|
12739
12747
|
const persisted = parsed;
|
|
12740
12748
|
return {
|
|
12741
|
-
version:
|
|
12749
|
+
version: 4,
|
|
12742
12750
|
scopeHash,
|
|
12743
12751
|
fileList: isRecordValue(persisted.fileList) ? persisted.fileList : null,
|
|
12744
12752
|
resolutions: isRecordValue(persisted.resolutions) && typeof persisted.resolutions.hash === "string" && isRecordValue(persisted.resolutions.entries) ? persisted.resolutions : null,
|
|
@@ -13008,7 +13016,7 @@ const createSummaryCache = (cachePath, config) => {
|
|
|
13008
13016
|
if (resolutionEntry !== void 0) compactedResolutions[resolutionKey] = resolutionEntry;
|
|
13009
13017
|
}
|
|
13010
13018
|
const serialized = JSON.stringify({
|
|
13011
|
-
version:
|
|
13019
|
+
version: 4,
|
|
13012
13020
|
scopeHash,
|
|
13013
13021
|
fileList: store.fileList,
|
|
13014
13022
|
resolutions: {
|
|
@@ -13095,6 +13103,10 @@ const collectGitIgnoredPaths = (rootDirectory, candidatePaths) => {
|
|
|
13095
13103
|
};
|
|
13096
13104
|
};
|
|
13097
13105
|
|
|
13106
|
+
//#endregion
|
|
13107
|
+
//#region src/utils/normalize-registry-module-path.ts
|
|
13108
|
+
const normalizeRegistryModulePath = (modulePath) => modulePath.replace(/^\.\//, "").replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
13109
|
+
|
|
13098
13110
|
//#endregion
|
|
13099
13111
|
//#region src/index.ts
|
|
13100
13112
|
const STYLE_EXTENSIONS = [".css", ".scss"];
|
|
@@ -13110,21 +13122,35 @@ const basenameFromPath = (filePath) => {
|
|
|
13110
13122
|
* analysis can't follow the indirection, so those targets get falsely
|
|
13111
13123
|
* flagged as unused.
|
|
13112
13124
|
*
|
|
13113
|
-
* Heuristic: if a parsed string literal exactly matches the basename
|
|
13114
|
-
* exactly one file in the project, treat that
|
|
13115
|
-
* Uniqueness guards against false-positives from
|
|
13116
|
-
* `index.ts` matching dozens of unrelated files.
|
|
13125
|
+
* Heuristic: if a parsed string literal exactly matches the basename or
|
|
13126
|
+
* extensionless path suffix of exactly one file in the project, treat that
|
|
13127
|
+
* file as an entry point. Uniqueness guards against false-positives from
|
|
13128
|
+
* common names like `index.ts` matching dozens of unrelated files.
|
|
13117
13129
|
*/
|
|
13118
13130
|
const markFilenameRegistryEntries = (moduleGraph) => {
|
|
13119
13131
|
const basenameToModuleIndex = /* @__PURE__ */ new Map();
|
|
13132
|
+
const pathSuffixToModuleIndex = /* @__PURE__ */ new Map();
|
|
13133
|
+
const referencedPathSet = /* @__PURE__ */ new Set();
|
|
13134
|
+
for (const module of moduleGraph.modules) for (const referencedFilename of module.referencedFilenames) if (referencedFilename.includes("/")) referencedPathSet.add(normalizeRegistryModulePath(referencedFilename));
|
|
13120
13135
|
for (const module of moduleGraph.modules) {
|
|
13121
13136
|
const basename = basenameFromPath(module.fileId.path);
|
|
13122
13137
|
const existing = basenameToModuleIndex.get(basename);
|
|
13123
13138
|
if (existing === void 0) basenameToModuleIndex.set(basename, module.fileId.index);
|
|
13124
13139
|
else if (existing !== "ambiguous") basenameToModuleIndex.set(basename, "ambiguous");
|
|
13140
|
+
const extensionlessPath = normalizeRegistryModulePath(module.fileId.path);
|
|
13141
|
+
let slashIndex = extensionlessPath.indexOf("/");
|
|
13142
|
+
while (slashIndex !== -1) {
|
|
13143
|
+
const pathSuffix = extensionlessPath.slice(slashIndex + 1);
|
|
13144
|
+
slashIndex = extensionlessPath.indexOf("/", slashIndex + 1);
|
|
13145
|
+
if (!referencedPathSet.has(pathSuffix)) continue;
|
|
13146
|
+
const existingPathIndex = pathSuffixToModuleIndex.get(pathSuffix);
|
|
13147
|
+
if (existingPathIndex === void 0) pathSuffixToModuleIndex.set(pathSuffix, module.fileId.index);
|
|
13148
|
+
else if (existingPathIndex !== "ambiguous") pathSuffixToModuleIndex.set(pathSuffix, "ambiguous");
|
|
13149
|
+
}
|
|
13125
13150
|
}
|
|
13126
13151
|
for (const module of moduleGraph.modules) for (const referencedFilename of module.referencedFilenames) {
|
|
13127
|
-
const
|
|
13152
|
+
const normalizedReference = normalizeRegistryModulePath(referencedFilename);
|
|
13153
|
+
const targetIndex = referencedFilename.includes("/") ? pathSuffixToModuleIndex.get(normalizedReference) : basenameToModuleIndex.get(referencedFilename);
|
|
13128
13154
|
if (typeof targetIndex !== "number") continue;
|
|
13129
13155
|
const targetModule = moduleGraph.modules[targetIndex];
|
|
13130
13156
|
if (!targetModule || targetModule.isEntryPoint) continue;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as SUMMARY_CACHE_MAX_BYTES, C as RESOLVER_EXTENSIONS, D as SEMANTIC_MAX_PROGRAM_FILES, E as SCRIPT_FILE_PATTERN, O as SOURCE_EXTENSIONS$3, S as REACT_NATIVE_PLATFORM_EXTENSIONS, T as SCRIPT_EXTENSIONLESS_FILE_PATTERN, _ as MINIFIED_DETECTION_MIN_BYTES, a as DEFAULT_EXCLUSIONS, b as OUTPUT_DIRECTORIES, c as DEFAULT_SEMANTIC_TSCONFIG_NAMES, d as IMPLICIT_DEPENDENCIES, f as KNOWN_CONFIG_PREFIXES, g as MAX_PARSE_FILE_SIZE_BYTES, h as MAX_ERROR_DETAIL_LENGTH, i as DEFAULT_ENTRY_GLOBS, k as STANDALONE_PROJECT_LOCKFILES, l as GIT_CHECK_IGNORE_MAX_BUFFER_BYTES, m as MAX_ANALYSIS_ERRORS, n as BINARY_DETECTION_SAMPLE_BYTES, o as DEFAULT_EXTENSIONS, p as LOCKFILE_MARKERS, r as BUILTIN_MODULES, s as DEFAULT_SEMANTIC_DECORATOR_ALLOWLIST, t as ANALYZED_MANIFEST_FILENAMES, u as HIDDEN_DIRECTORY_ALLOWLIST, v as MIN_NUMERIC_LITERAL_MAGNITUDE_FOR_DUPLICATE, w as SCRIPT_CONFIG_FILE_PATTERN, x as PLATFORM_SUFFIXES, y as MONOREPO_ROOT_MARKERS } from "./constants-DBVadY0c.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import path, { basename, dirname, extname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, statSync, writeFileSync } from "node:fs";
|
|
@@ -1744,7 +1744,7 @@ const parseSourceFile = (filePath) => {
|
|
|
1744
1744
|
wholeObjectUses,
|
|
1745
1745
|
localIdentifierReferences,
|
|
1746
1746
|
topLevelImportReferences,
|
|
1747
|
-
referencedFilenames: extractReferencedFilenames(sourceText),
|
|
1747
|
+
referencedFilenames: extractReferencedFilenames(sourceText, program.body),
|
|
1748
1748
|
redundantTypePatterns,
|
|
1749
1749
|
identityWrappers,
|
|
1750
1750
|
typeDefinitionHashes,
|
|
@@ -1756,11 +1756,33 @@ const parseSourceFile = (filePath) => {
|
|
|
1756
1756
|
};
|
|
1757
1757
|
};
|
|
1758
1758
|
const REFERENCED_FILENAME_LITERAL_PATTERN = /(?<![./@\w-])(?:["'`])([a-z][\w-]*\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:["'`])/g;
|
|
1759
|
-
const
|
|
1759
|
+
const REFERENCED_MODULE_PATH_PATTERN = /^[a-zA-Z0-9_@-][a-zA-Z0-9_@.-]*(?:\/[a-zA-Z0-9_@.-]+)+$/;
|
|
1760
|
+
const extractReferencedFilenames = (sourceText, bodyNodes = []) => {
|
|
1760
1761
|
const captured = /* @__PURE__ */ new Set();
|
|
1761
1762
|
REFERENCED_FILENAME_LITERAL_PATTERN.lastIndex = 0;
|
|
1762
1763
|
let match;
|
|
1763
1764
|
while ((match = REFERENCED_FILENAME_LITERAL_PATTERN.exec(sourceText)) !== null) captured.add(match[1]);
|
|
1765
|
+
const visitNode = (node) => {
|
|
1766
|
+
if (node.type === "ImportExpression") {
|
|
1767
|
+
const sourceExpression = node.source;
|
|
1768
|
+
if (isWalkableNode(sourceExpression) && sourceExpression.type === "Literal") {
|
|
1769
|
+
const literalValue = sourceExpression.value;
|
|
1770
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
if (node.type === "CallExpression" || node.type === "NewExpression") {
|
|
1774
|
+
const callArguments = node.arguments;
|
|
1775
|
+
for (const callArgument of Array.isArray(callArguments) ? callArguments : []) {
|
|
1776
|
+
if (!isWalkableNode(callArgument) || callArgument.type !== "Literal") continue;
|
|
1777
|
+
const literalValue = callArgument.value;
|
|
1778
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) {
|
|
1782
|
+
for (const element of value) if (isWalkableNode(element)) visitNode(element);
|
|
1783
|
+
} else if (isWalkableNode(value)) visitNode(value);
|
|
1784
|
+
};
|
|
1785
|
+
for (const bodyNode of bodyNodes) if (isWalkableNode(bodyNode)) visitNode(bodyNode);
|
|
1764
1786
|
return [...captured];
|
|
1765
1787
|
};
|
|
1766
1788
|
const collectDryPatterns = (bodyNodes, sourceText, redundantTypePatterns, identityWrappers, typeDefinitionHashes) => {
|
|
@@ -5192,13 +5214,6 @@ const extractScriptEntries = (directory) => {
|
|
|
5192
5214
|
entries.push(...extractScriptFileArguments(scriptCommand, directory));
|
|
5193
5215
|
}
|
|
5194
5216
|
} catch {}
|
|
5195
|
-
const scriptDirectoryFiles = fg.sync(SCRIPT_ENTRY_PATTERNS, {
|
|
5196
|
-
cwd: directory,
|
|
5197
|
-
absolute: true,
|
|
5198
|
-
onlyFiles: true,
|
|
5199
|
-
ignore: ["**/node_modules/**"]
|
|
5200
|
-
});
|
|
5201
|
-
entries.push(...scriptDirectoryFiles);
|
|
5202
5217
|
return entries;
|
|
5203
5218
|
};
|
|
5204
5219
|
const isYamlMapping = (line) => {
|
|
@@ -12338,8 +12353,7 @@ const createDisabledSemanticResult = () => ({
|
|
|
12338
12353
|
unusedClassMembers: [],
|
|
12339
12354
|
misclassifiedDependencies: [],
|
|
12340
12355
|
redundantAliases: [],
|
|
12341
|
-
errors: []
|
|
12342
|
-
contextStatus: "disabled"
|
|
12356
|
+
errors: []
|
|
12343
12357
|
});
|
|
12344
12358
|
const runSemanticAnalysis = (graph, config) => {
|
|
12345
12359
|
const semanticConfig = config.semantic;
|
|
@@ -12360,8 +12374,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12360
12374
|
unusedClassMembers: [],
|
|
12361
12375
|
misclassifiedDependencies,
|
|
12362
12376
|
redundantAliases: [],
|
|
12363
|
-
errors
|
|
12364
|
-
contextStatus: "no-context-required"
|
|
12377
|
+
errors
|
|
12365
12378
|
};
|
|
12366
12379
|
let contextResult;
|
|
12367
12380
|
try {
|
|
@@ -12377,8 +12390,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12377
12390
|
code: "ts-not-loadable",
|
|
12378
12391
|
message: "createSemanticContext threw before returning a result",
|
|
12379
12392
|
detail: describeUnknownError(contextError)
|
|
12380
|
-
})]
|
|
12381
|
-
contextStatus: "typescript-load-failed"
|
|
12393
|
+
})]
|
|
12382
12394
|
};
|
|
12383
12395
|
}
|
|
12384
12396
|
if (!contextResult.ok) return {
|
|
@@ -12387,9 +12399,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12387
12399
|
unusedClassMembers: [],
|
|
12388
12400
|
misclassifiedDependencies,
|
|
12389
12401
|
redundantAliases: [],
|
|
12390
|
-
errors: [...errors, contextResult.failure.error]
|
|
12391
|
-
contextStatus: contextResult.failure.reason,
|
|
12392
|
-
contextMessage: contextResult.failure.message
|
|
12402
|
+
errors: [...errors, contextResult.failure.error]
|
|
12393
12403
|
};
|
|
12394
12404
|
const { context } = contextResult;
|
|
12395
12405
|
let referenceIndex;
|
|
@@ -12408,8 +12418,7 @@ const runSemanticAnalysis = (graph, config) => {
|
|
|
12408
12418
|
unusedClassMembers,
|
|
12409
12419
|
misclassifiedDependencies,
|
|
12410
12420
|
redundantAliases: [...variableAliases, ...roundTripAliases],
|
|
12411
|
-
errors
|
|
12412
|
-
contextStatus: "ready"
|
|
12421
|
+
errors
|
|
12413
12422
|
};
|
|
12414
12423
|
};
|
|
12415
12424
|
|
|
@@ -12480,8 +12489,7 @@ const generateReport = (graph, config, summaryCache) => {
|
|
|
12480
12489
|
unusedClassMembers: [],
|
|
12481
12490
|
misclassifiedDependencies: [],
|
|
12482
12491
|
redundantAliases: [],
|
|
12483
|
-
errors: []
|
|
12484
|
-
contextStatus: "typescript-load-failed"
|
|
12492
|
+
errors: []
|
|
12485
12493
|
};
|
|
12486
12494
|
}
|
|
12487
12495
|
for (const semanticError of semanticResult.errors) {
|
|
@@ -12692,7 +12700,7 @@ const isRecordValue = (value) => typeof value === "object" && value !== null &&
|
|
|
12692
12700
|
const isStringArray = (value) => Array.isArray(value) && value.every((entry) => typeof entry === "string");
|
|
12693
12701
|
const isOptionalArray = (value) => value === void 0 || Array.isArray(value);
|
|
12694
12702
|
const emptyStore = (scopeHash) => ({
|
|
12695
|
-
version:
|
|
12703
|
+
version: 4,
|
|
12696
12704
|
scopeHash,
|
|
12697
12705
|
fileList: null,
|
|
12698
12706
|
resolutions: null,
|
|
@@ -12702,10 +12710,10 @@ const emptyStore = (scopeHash) => ({
|
|
|
12702
12710
|
const readPersistedStore = (cachePath, scopeHash) => {
|
|
12703
12711
|
try {
|
|
12704
12712
|
const parsed = JSON.parse(readFileSync(cachePath, "utf-8"));
|
|
12705
|
-
if (isRecordValue(parsed) && parsed.version ===
|
|
12713
|
+
if (isRecordValue(parsed) && parsed.version === 4 && parsed.scopeHash === scopeHash && isRecordValue(parsed.summaries) && isRecordValue(parsed.packageFacts)) {
|
|
12706
12714
|
const persisted = parsed;
|
|
12707
12715
|
return {
|
|
12708
|
-
version:
|
|
12716
|
+
version: 4,
|
|
12709
12717
|
scopeHash,
|
|
12710
12718
|
fileList: isRecordValue(persisted.fileList) ? persisted.fileList : null,
|
|
12711
12719
|
resolutions: isRecordValue(persisted.resolutions) && typeof persisted.resolutions.hash === "string" && isRecordValue(persisted.resolutions.entries) ? persisted.resolutions : null,
|
|
@@ -12975,7 +12983,7 @@ const createSummaryCache = (cachePath, config) => {
|
|
|
12975
12983
|
if (resolutionEntry !== void 0) compactedResolutions[resolutionKey] = resolutionEntry;
|
|
12976
12984
|
}
|
|
12977
12985
|
const serialized = JSON.stringify({
|
|
12978
|
-
version:
|
|
12986
|
+
version: 4,
|
|
12979
12987
|
scopeHash,
|
|
12980
12988
|
fileList: store.fileList,
|
|
12981
12989
|
resolutions: {
|
|
@@ -13062,6 +13070,10 @@ const collectGitIgnoredPaths = (rootDirectory, candidatePaths) => {
|
|
|
13062
13070
|
};
|
|
13063
13071
|
};
|
|
13064
13072
|
|
|
13073
|
+
//#endregion
|
|
13074
|
+
//#region src/utils/normalize-registry-module-path.ts
|
|
13075
|
+
const normalizeRegistryModulePath = (modulePath) => modulePath.replace(/^\.\//, "").replace(/\.(?:[cm]?[jt]sx?)$/, "");
|
|
13076
|
+
|
|
13065
13077
|
//#endregion
|
|
13066
13078
|
//#region src/index.ts
|
|
13067
13079
|
const STYLE_EXTENSIONS = [".css", ".scss"];
|
|
@@ -13077,21 +13089,35 @@ const basenameFromPath = (filePath) => {
|
|
|
13077
13089
|
* analysis can't follow the indirection, so those targets get falsely
|
|
13078
13090
|
* flagged as unused.
|
|
13079
13091
|
*
|
|
13080
|
-
* Heuristic: if a parsed string literal exactly matches the basename
|
|
13081
|
-
* exactly one file in the project, treat that
|
|
13082
|
-
* Uniqueness guards against false-positives from
|
|
13083
|
-
* `index.ts` matching dozens of unrelated files.
|
|
13092
|
+
* Heuristic: if a parsed string literal exactly matches the basename or
|
|
13093
|
+
* extensionless path suffix of exactly one file in the project, treat that
|
|
13094
|
+
* file as an entry point. Uniqueness guards against false-positives from
|
|
13095
|
+
* common names like `index.ts` matching dozens of unrelated files.
|
|
13084
13096
|
*/
|
|
13085
13097
|
const markFilenameRegistryEntries = (moduleGraph) => {
|
|
13086
13098
|
const basenameToModuleIndex = /* @__PURE__ */ new Map();
|
|
13099
|
+
const pathSuffixToModuleIndex = /* @__PURE__ */ new Map();
|
|
13100
|
+
const referencedPathSet = /* @__PURE__ */ new Set();
|
|
13101
|
+
for (const module of moduleGraph.modules) for (const referencedFilename of module.referencedFilenames) if (referencedFilename.includes("/")) referencedPathSet.add(normalizeRegistryModulePath(referencedFilename));
|
|
13087
13102
|
for (const module of moduleGraph.modules) {
|
|
13088
13103
|
const basename = basenameFromPath(module.fileId.path);
|
|
13089
13104
|
const existing = basenameToModuleIndex.get(basename);
|
|
13090
13105
|
if (existing === void 0) basenameToModuleIndex.set(basename, module.fileId.index);
|
|
13091
13106
|
else if (existing !== "ambiguous") basenameToModuleIndex.set(basename, "ambiguous");
|
|
13107
|
+
const extensionlessPath = normalizeRegistryModulePath(module.fileId.path);
|
|
13108
|
+
let slashIndex = extensionlessPath.indexOf("/");
|
|
13109
|
+
while (slashIndex !== -1) {
|
|
13110
|
+
const pathSuffix = extensionlessPath.slice(slashIndex + 1);
|
|
13111
|
+
slashIndex = extensionlessPath.indexOf("/", slashIndex + 1);
|
|
13112
|
+
if (!referencedPathSet.has(pathSuffix)) continue;
|
|
13113
|
+
const existingPathIndex = pathSuffixToModuleIndex.get(pathSuffix);
|
|
13114
|
+
if (existingPathIndex === void 0) pathSuffixToModuleIndex.set(pathSuffix, module.fileId.index);
|
|
13115
|
+
else if (existingPathIndex !== "ambiguous") pathSuffixToModuleIndex.set(pathSuffix, "ambiguous");
|
|
13116
|
+
}
|
|
13092
13117
|
}
|
|
13093
13118
|
for (const module of moduleGraph.modules) for (const referencedFilename of module.referencedFilenames) {
|
|
13094
|
-
const
|
|
13119
|
+
const normalizedReference = normalizeRegistryModulePath(referencedFilename);
|
|
13120
|
+
const targetIndex = referencedFilename.includes("/") ? pathSuffixToModuleIndex.get(normalizedReference) : basenameToModuleIndex.get(referencedFilename);
|
|
13095
13121
|
if (typeof targetIndex !== "number") continue;
|
|
13096
13122
|
const targetModule = moduleGraph.modules[targetIndex];
|
|
13097
13123
|
if (!targetModule || targetModule.isEntryPoint) continue;
|
|
@@ -72,7 +72,6 @@ const SOURCE_EXTENSIONS = [
|
|
|
72
72
|
const SCRIPT_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|tsc|npx|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:\s|$)/;
|
|
73
73
|
const SCRIPT_EXTENSIONLESS_FILE_PATTERN = /(?:^|\s)(?:node|tsx|ts-node|bun|esr|esno|jiti|babel-node|zx)\s+(?:\S+\s+)*?((?:[./]|[\w@][\w@-]*\/)[\w./@-]+)(?:\s|$)/;
|
|
74
74
|
const SCRIPT_CONFIG_FILE_PATTERN = /--config\s+([\w./@-]+\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))/;
|
|
75
|
-
const SCRIPT_ENTRY_PATTERNS = [];
|
|
76
75
|
const RESOLVER_EXTENSIONS = [
|
|
77
76
|
...DEFAULT_EXTENSIONS,
|
|
78
77
|
".d.ts",
|
|
@@ -1787,7 +1786,7 @@ const parseSourceFile = (filePath) => {
|
|
|
1787
1786
|
wholeObjectUses,
|
|
1788
1787
|
localIdentifierReferences,
|
|
1789
1788
|
topLevelImportReferences,
|
|
1790
|
-
referencedFilenames: extractReferencedFilenames(sourceText),
|
|
1789
|
+
referencedFilenames: extractReferencedFilenames(sourceText, program.body),
|
|
1791
1790
|
redundantTypePatterns,
|
|
1792
1791
|
identityWrappers,
|
|
1793
1792
|
typeDefinitionHashes,
|
|
@@ -1799,11 +1798,33 @@ const parseSourceFile = (filePath) => {
|
|
|
1799
1798
|
};
|
|
1800
1799
|
};
|
|
1801
1800
|
const REFERENCED_FILENAME_LITERAL_PATTERN = /(?<![./@\w-])(?:["'`])([a-z][\w-]*\.(?:ts|tsx|js|jsx|mts|mjs|cts|cjs))(?:["'`])/g;
|
|
1802
|
-
const
|
|
1801
|
+
const REFERENCED_MODULE_PATH_PATTERN = /^[a-zA-Z0-9_@-][a-zA-Z0-9_@.-]*(?:\/[a-zA-Z0-9_@.-]+)+$/;
|
|
1802
|
+
const extractReferencedFilenames = (sourceText, bodyNodes = []) => {
|
|
1803
1803
|
const captured = /* @__PURE__ */ new Set();
|
|
1804
1804
|
REFERENCED_FILENAME_LITERAL_PATTERN.lastIndex = 0;
|
|
1805
1805
|
let match;
|
|
1806
1806
|
while ((match = REFERENCED_FILENAME_LITERAL_PATTERN.exec(sourceText)) !== null) captured.add(match[1]);
|
|
1807
|
+
const visitNode = (node) => {
|
|
1808
|
+
if (node.type === "ImportExpression") {
|
|
1809
|
+
const sourceExpression = node.source;
|
|
1810
|
+
if (isWalkableNode(sourceExpression) && sourceExpression.type === "Literal") {
|
|
1811
|
+
const literalValue = sourceExpression.value;
|
|
1812
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
if (node.type === "CallExpression" || node.type === "NewExpression") {
|
|
1816
|
+
const callArguments = node.arguments;
|
|
1817
|
+
for (const callArgument of Array.isArray(callArguments) ? callArguments : []) {
|
|
1818
|
+
if (!isWalkableNode(callArgument) || callArgument.type !== "Literal") continue;
|
|
1819
|
+
const literalValue = callArgument.value;
|
|
1820
|
+
if (typeof literalValue === "string" && REFERENCED_MODULE_PATH_PATTERN.test(literalValue)) captured.add(literalValue);
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
for (const value of Object.values(node)) if (Array.isArray(value)) {
|
|
1824
|
+
for (const element of value) if (isWalkableNode(element)) visitNode(element);
|
|
1825
|
+
} else if (isWalkableNode(value)) visitNode(value);
|
|
1826
|
+
};
|
|
1827
|
+
for (const bodyNode of bodyNodes) if (isWalkableNode(bodyNode)) visitNode(bodyNode);
|
|
1807
1828
|
return [...captured];
|
|
1808
1829
|
};
|
|
1809
1830
|
const collectDryPatterns = (bodyNodes, sourceText, redundantTypePatterns, identityWrappers, typeDefinitionHashes) => {
|
|
@@ -2455,4 +2476,4 @@ const extractReactRouterRouteModuleEntries = (routesFilePath) => {
|
|
|
2455
2476
|
};
|
|
2456
2477
|
|
|
2457
2478
|
//#endregion
|
|
2458
|
-
export { OUTPUT_DIRECTORIES as a,
|
|
2479
|
+
export { OUTPUT_DIRECTORIES as a, SCRIPT_EXTENSIONLESS_FILE_PATTERN as c, STANDALONE_PROJECT_LOCKFILES as d, MONOREPO_ROOT_MARKERS as i, SCRIPT_FILE_PATTERN as l, parseSourceFile as n, RESOLVER_EXTENSIONS as o, LOCKFILE_MARKERS as r, SCRIPT_CONFIG_FILE_PATTERN as s, extractReactRouterRouteModuleEntries as t, SOURCE_EXTENSIONS as u };
|
package/dist/parse-worker.mjs
CHANGED