deslop-js 0.0.9 → 0.0.10
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.cjs +169 -3
- package/dist/index.mjs +169 -3
- package/package.json +1 -1
- package/dist/cli.cjs +0 -141
- package/dist/cli.d.cts +0 -1
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs +0 -142
- package/dist/src-BIp8ek0h.mjs +0 -4922
- package/dist/src-BuniDJsj.cjs +0 -4970
- package/dist/src-OVMbJnkL.mjs +0 -4924
- package/dist/src-wbNpmldQ.cjs +0 -4968
package/dist/index.cjs
CHANGED
|
@@ -5321,6 +5321,126 @@ const extractPackageName = (specifier) => {
|
|
|
5321
5321
|
return normalizedSpecifier.split("/")[0];
|
|
5322
5322
|
};
|
|
5323
5323
|
|
|
5324
|
+
//#endregion
|
|
5325
|
+
//#region src/utils/extract-override-target.ts
|
|
5326
|
+
const extractOverrideTargetPackage = (overrideValue) => {
|
|
5327
|
+
let normalizedValue = overrideValue.trim().replace(/^["']|["']$/g, "");
|
|
5328
|
+
if (normalizedValue.startsWith("npm:")) normalizedValue = normalizedValue.slice(4);
|
|
5329
|
+
if (normalizedValue.startsWith("@")) {
|
|
5330
|
+
const slashIndex = normalizedValue.indexOf("/");
|
|
5331
|
+
if (slashIndex === -1) return void 0;
|
|
5332
|
+
const scope = normalizedValue.slice(0, slashIndex);
|
|
5333
|
+
const remainder = normalizedValue.slice(slashIndex + 1);
|
|
5334
|
+
const versionSeparatorIndex = remainder.indexOf("@");
|
|
5335
|
+
const packageName = versionSeparatorIndex === -1 ? remainder : remainder.slice(0, versionSeparatorIndex);
|
|
5336
|
+
if (!packageName) return void 0;
|
|
5337
|
+
return `${scope}/${packageName}`;
|
|
5338
|
+
}
|
|
5339
|
+
const versionSeparatorIndex = normalizedValue.indexOf("@");
|
|
5340
|
+
return (versionSeparatorIndex === -1 ? normalizedValue : normalizedValue.slice(0, versionSeparatorIndex)) || void 0;
|
|
5341
|
+
};
|
|
5342
|
+
|
|
5343
|
+
//#endregion
|
|
5344
|
+
//#region src/utils/collect-override-mappings-from-record.ts
|
|
5345
|
+
const collectOverrideMappingsFromUnknown = (fromPackage, overrideValue, mappings) => {
|
|
5346
|
+
if (typeof overrideValue === "string") {
|
|
5347
|
+
const toPackage = extractOverrideTargetPackage(overrideValue);
|
|
5348
|
+
if (!toPackage) return;
|
|
5349
|
+
mappings.push({
|
|
5350
|
+
fromPackage,
|
|
5351
|
+
toPackage
|
|
5352
|
+
});
|
|
5353
|
+
return;
|
|
5354
|
+
}
|
|
5355
|
+
if (!overrideValue || typeof overrideValue !== "object" || Array.isArray(overrideValue)) return;
|
|
5356
|
+
for (const [nestedFromPackage, nestedValue] of Object.entries(overrideValue)) collectOverrideMappingsFromUnknown(nestedFromPackage, nestedValue, mappings);
|
|
5357
|
+
};
|
|
5358
|
+
const collectOverrideMappingsFromRecord = (overrideRecord) => {
|
|
5359
|
+
const mappings = [];
|
|
5360
|
+
for (const [fromPackage, overrideValue] of Object.entries(overrideRecord)) collectOverrideMappingsFromUnknown(fromPackage, overrideValue, mappings);
|
|
5361
|
+
return mappings;
|
|
5362
|
+
};
|
|
5363
|
+
|
|
5364
|
+
//#endregion
|
|
5365
|
+
//#region src/utils/parse-pnpm-workspace-overrides.ts
|
|
5366
|
+
const PNPM_WORKSPACE_FILENAMES = ["pnpm-workspace.yaml", "pnpm-workspace.yml"];
|
|
5367
|
+
const parseIndentedYamlMapping = (lines, startLineIndex, sectionIndent) => {
|
|
5368
|
+
const entries = {};
|
|
5369
|
+
let lineIndex = startLineIndex;
|
|
5370
|
+
while (lineIndex < lines.length) {
|
|
5371
|
+
const line = lines[lineIndex];
|
|
5372
|
+
const trimmedLine = line.trim();
|
|
5373
|
+
if (trimmedLine.length === 0 || trimmedLine.startsWith("#")) {
|
|
5374
|
+
lineIndex++;
|
|
5375
|
+
continue;
|
|
5376
|
+
}
|
|
5377
|
+
const indent = line.length - line.trimStart().length;
|
|
5378
|
+
if (indent <= sectionIndent) break;
|
|
5379
|
+
const colonIndex = trimmedLine.indexOf(":");
|
|
5380
|
+
if (colonIndex === -1) {
|
|
5381
|
+
lineIndex++;
|
|
5382
|
+
continue;
|
|
5383
|
+
}
|
|
5384
|
+
const key = trimmedLine.slice(0, colonIndex).trim().replace(/^["']|["']$/g, "");
|
|
5385
|
+
const rawValue = trimmedLine.slice(colonIndex + 1).trim();
|
|
5386
|
+
if (!key) {
|
|
5387
|
+
lineIndex++;
|
|
5388
|
+
continue;
|
|
5389
|
+
}
|
|
5390
|
+
if (rawValue.length === 0) {
|
|
5391
|
+
const nestedMapping = parseIndentedYamlMapping(lines, lineIndex + 1, indent);
|
|
5392
|
+
entries[key] = nestedMapping.entries;
|
|
5393
|
+
lineIndex = nestedMapping.endLineIndex;
|
|
5394
|
+
continue;
|
|
5395
|
+
}
|
|
5396
|
+
entries[key] = rawValue.replace(/^["']|["']$/g, "");
|
|
5397
|
+
lineIndex++;
|
|
5398
|
+
}
|
|
5399
|
+
return {
|
|
5400
|
+
entries,
|
|
5401
|
+
endLineIndex: lineIndex
|
|
5402
|
+
};
|
|
5403
|
+
};
|
|
5404
|
+
const parsePnpmWorkspaceOverrideRecords = (yamlContent) => {
|
|
5405
|
+
const lines = yamlContent.split("\n");
|
|
5406
|
+
const overrideRecords = [];
|
|
5407
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
5408
|
+
if (lines[lineIndex].trim() !== "overrides:") continue;
|
|
5409
|
+
const sectionIndent = lines[lineIndex].length - lines[lineIndex].trimStart().length;
|
|
5410
|
+
const parsedMapping = parseIndentedYamlMapping(lines, lineIndex + 1, sectionIndent);
|
|
5411
|
+
if (Object.keys(parsedMapping.entries).length > 0) overrideRecords.push(parsedMapping.entries);
|
|
5412
|
+
}
|
|
5413
|
+
return overrideRecords;
|
|
5414
|
+
};
|
|
5415
|
+
const collectPnpmWorkspaceOverrideMappings = (rootDir) => {
|
|
5416
|
+
const mappings = [];
|
|
5417
|
+
for (const workspaceFilename of PNPM_WORKSPACE_FILENAMES) {
|
|
5418
|
+
const workspacePath = (0, node_path.join)(rootDir, workspaceFilename);
|
|
5419
|
+
if (!(0, node_fs.existsSync)(workspacePath)) continue;
|
|
5420
|
+
try {
|
|
5421
|
+
const overrideRecords = parsePnpmWorkspaceOverrideRecords((0, node_fs.readFileSync)(workspacePath, "utf-8"));
|
|
5422
|
+
for (const overrideRecord of overrideRecords) mappings.push(...collectOverrideMappingsFromRecord(overrideRecord));
|
|
5423
|
+
} catch {
|
|
5424
|
+
continue;
|
|
5425
|
+
}
|
|
5426
|
+
}
|
|
5427
|
+
return mappings;
|
|
5428
|
+
};
|
|
5429
|
+
|
|
5430
|
+
//#endregion
|
|
5431
|
+
//#region src/utils/matches-package-import-reference.ts
|
|
5432
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5433
|
+
const matchesPackageImportReference = (content, packageName) => {
|
|
5434
|
+
const escapedPackageName = escapeRegExp(packageName);
|
|
5435
|
+
const subpathPattern = `(?:/[^'"]*)?`;
|
|
5436
|
+
return [
|
|
5437
|
+
new RegExp(`\\bfrom\\s+['"]${escapedPackageName}${subpathPattern}['"]`),
|
|
5438
|
+
new RegExp(`\\bimport\\s+(?:[^'";\\n]*?\\sfrom\\s+)?['"]${escapedPackageName}${subpathPattern}['"]`),
|
|
5439
|
+
new RegExp(`\\brequire\\s*\\(\\s*['"]${escapedPackageName}${subpathPattern}['"]\\s*\\)`),
|
|
5440
|
+
new RegExp(`\\bimport\\s*\\(\\s*['"]${escapedPackageName}${subpathPattern}['"]`)
|
|
5441
|
+
].some((pattern) => pattern.test(content));
|
|
5442
|
+
};
|
|
5443
|
+
|
|
5324
5444
|
//#endregion
|
|
5325
5445
|
//#region src/report/packages.ts
|
|
5326
5446
|
const discoverAllPackageJsonPaths = (rootDir) => {
|
|
@@ -5415,6 +5535,11 @@ const detectStalePackages = (graph, config) => {
|
|
|
5415
5535
|
for (const packageName of staticPeerSatisfied) usedPackageNames.add(packageName);
|
|
5416
5536
|
const implicitCompanionPackages = collectImplicitCompanionPackages(declaredNames, usedPackageNames);
|
|
5417
5537
|
for (const packageName of implicitCompanionPackages) usedPackageNames.add(packageName);
|
|
5538
|
+
const overrideMappings = collectOverrideMappings(configSearchRoots, allPackageJsonPaths, monorepoRoot);
|
|
5539
|
+
for (const { fromPackage, toPackage } of overrideMappings) {
|
|
5540
|
+
if (declaredNames.has(toPackage)) usedPackageNames.add(toPackage);
|
|
5541
|
+
if (usedPackageNames.has(fromPackage) && declaredNames.has(toPackage)) usedPackageNames.add(toPackage);
|
|
5542
|
+
}
|
|
5418
5543
|
const candidateUnused = /* @__PURE__ */ new Set();
|
|
5419
5544
|
for (const [dependencyName] of declaredDependencies) {
|
|
5420
5545
|
if (isAlwaysConsideredUsed(dependencyName)) continue;
|
|
@@ -5511,7 +5636,8 @@ const collectStaticPeerSatisfiedPackages = (declaredNames, confirmedUsedNames) =
|
|
|
5511
5636
|
};
|
|
5512
5637
|
const IMPLICIT_COMPANION_DEPENDENCY_MAP = {
|
|
5513
5638
|
jest: ["jest-config"],
|
|
5514
|
-
"jest-cli": ["jest-config"]
|
|
5639
|
+
"jest-cli": ["jest-config"],
|
|
5640
|
+
"vite-plus": ["@voidzero-dev/vite-plus-core"]
|
|
5515
5641
|
};
|
|
5516
5642
|
const collectImplicitCompanionPackages = (declaredNames, confirmedUsedNames) => {
|
|
5517
5643
|
const companions = /* @__PURE__ */ new Set();
|
|
@@ -5552,7 +5678,11 @@ const CLI_BINARY_TO_PACKAGE = {
|
|
|
5552
5678
|
"rndebugger-open": "react-native-debugger-open",
|
|
5553
5679
|
"simple-git-hooks": "simple-git-hooks",
|
|
5554
5680
|
"generate-arg-types": "@webstudio-is/generate-arg-types",
|
|
5555
|
-
email: "@react-email/preview-server"
|
|
5681
|
+
email: "@react-email/preview-server",
|
|
5682
|
+
vp: "vite-plus",
|
|
5683
|
+
turbo: "turbo",
|
|
5684
|
+
changeset: "@changesets/cli",
|
|
5685
|
+
tsx: "tsx"
|
|
5556
5686
|
};
|
|
5557
5687
|
const CLI_BINARY_FALLBACK_PACKAGES = {
|
|
5558
5688
|
babel: ["babel-cli"],
|
|
@@ -5706,6 +5836,42 @@ const PACKAGE_JSON_CONFIG_SECTIONS = [
|
|
|
5706
5836
|
"resolutions",
|
|
5707
5837
|
"overrides"
|
|
5708
5838
|
];
|
|
5839
|
+
const collectOverrideMappingsFromPackageJson = (packageJsonPath) => {
|
|
5840
|
+
const mappings = [];
|
|
5841
|
+
try {
|
|
5842
|
+
const content = (0, node_fs.readFileSync)(packageJsonPath, "utf-8");
|
|
5843
|
+
const packageJson = JSON.parse(content);
|
|
5844
|
+
const overrideSections = [
|
|
5845
|
+
packageJson.overrides,
|
|
5846
|
+
packageJson.resolutions,
|
|
5847
|
+
packageJson.pnpm?.overrides
|
|
5848
|
+
];
|
|
5849
|
+
for (const overrideSection of overrideSections) {
|
|
5850
|
+
if (!overrideSection || typeof overrideSection !== "object") continue;
|
|
5851
|
+
mappings.push(...collectOverrideMappingsFromRecord(overrideSection));
|
|
5852
|
+
}
|
|
5853
|
+
} catch {
|
|
5854
|
+
return mappings;
|
|
5855
|
+
}
|
|
5856
|
+
return mappings;
|
|
5857
|
+
};
|
|
5858
|
+
const collectOverrideMappings = (configSearchRoots, packageJsonPaths, monorepoRoot) => {
|
|
5859
|
+
const mappings = [];
|
|
5860
|
+
const seenMappings = /* @__PURE__ */ new Set();
|
|
5861
|
+
const addMappings = (nextMappings) => {
|
|
5862
|
+
for (const mapping of nextMappings) {
|
|
5863
|
+
const mappingKey = `${mapping.fromPackage}->${mapping.toPackage}`;
|
|
5864
|
+
if (seenMappings.has(mappingKey)) continue;
|
|
5865
|
+
seenMappings.add(mappingKey);
|
|
5866
|
+
mappings.push(mapping);
|
|
5867
|
+
}
|
|
5868
|
+
};
|
|
5869
|
+
for (const packageJsonPath of packageJsonPaths) addMappings(collectOverrideMappingsFromPackageJson(packageJsonPath));
|
|
5870
|
+
const workspaceRoots = new Set(configSearchRoots);
|
|
5871
|
+
if (monorepoRoot) workspaceRoots.add(monorepoRoot);
|
|
5872
|
+
for (const workspaceRoot of workspaceRoots) addMappings(collectPnpmWorkspaceOverrideMappings(workspaceRoot));
|
|
5873
|
+
return mappings;
|
|
5874
|
+
};
|
|
5709
5875
|
const collectPackageJsonConfigReferences = (packageJsonPath, declaredNames) => {
|
|
5710
5876
|
const referenced = /* @__PURE__ */ new Set();
|
|
5711
5877
|
try {
|
|
@@ -5831,7 +5997,7 @@ const scanSourceFilesForPackageImports = (rootDir, candidatePackages) => {
|
|
|
5831
5997
|
if (candidatePackages.size === 0) break;
|
|
5832
5998
|
try {
|
|
5833
5999
|
const content = (0, node_fs.readFileSync)(filePath, "utf-8");
|
|
5834
|
-
for (const packageName of candidatePackages) if (
|
|
6000
|
+
for (const packageName of candidatePackages) if (matchesPackageImportReference(content, packageName)) {
|
|
5835
6001
|
found.add(packageName);
|
|
5836
6002
|
candidatePackages.delete(packageName);
|
|
5837
6003
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5291,6 +5291,126 @@ const extractPackageName = (specifier) => {
|
|
|
5291
5291
|
return normalizedSpecifier.split("/")[0];
|
|
5292
5292
|
};
|
|
5293
5293
|
|
|
5294
|
+
//#endregion
|
|
5295
|
+
//#region src/utils/extract-override-target.ts
|
|
5296
|
+
const extractOverrideTargetPackage = (overrideValue) => {
|
|
5297
|
+
let normalizedValue = overrideValue.trim().replace(/^["']|["']$/g, "");
|
|
5298
|
+
if (normalizedValue.startsWith("npm:")) normalizedValue = normalizedValue.slice(4);
|
|
5299
|
+
if (normalizedValue.startsWith("@")) {
|
|
5300
|
+
const slashIndex = normalizedValue.indexOf("/");
|
|
5301
|
+
if (slashIndex === -1) return void 0;
|
|
5302
|
+
const scope = normalizedValue.slice(0, slashIndex);
|
|
5303
|
+
const remainder = normalizedValue.slice(slashIndex + 1);
|
|
5304
|
+
const versionSeparatorIndex = remainder.indexOf("@");
|
|
5305
|
+
const packageName = versionSeparatorIndex === -1 ? remainder : remainder.slice(0, versionSeparatorIndex);
|
|
5306
|
+
if (!packageName) return void 0;
|
|
5307
|
+
return `${scope}/${packageName}`;
|
|
5308
|
+
}
|
|
5309
|
+
const versionSeparatorIndex = normalizedValue.indexOf("@");
|
|
5310
|
+
return (versionSeparatorIndex === -1 ? normalizedValue : normalizedValue.slice(0, versionSeparatorIndex)) || void 0;
|
|
5311
|
+
};
|
|
5312
|
+
|
|
5313
|
+
//#endregion
|
|
5314
|
+
//#region src/utils/collect-override-mappings-from-record.ts
|
|
5315
|
+
const collectOverrideMappingsFromUnknown = (fromPackage, overrideValue, mappings) => {
|
|
5316
|
+
if (typeof overrideValue === "string") {
|
|
5317
|
+
const toPackage = extractOverrideTargetPackage(overrideValue);
|
|
5318
|
+
if (!toPackage) return;
|
|
5319
|
+
mappings.push({
|
|
5320
|
+
fromPackage,
|
|
5321
|
+
toPackage
|
|
5322
|
+
});
|
|
5323
|
+
return;
|
|
5324
|
+
}
|
|
5325
|
+
if (!overrideValue || typeof overrideValue !== "object" || Array.isArray(overrideValue)) return;
|
|
5326
|
+
for (const [nestedFromPackage, nestedValue] of Object.entries(overrideValue)) collectOverrideMappingsFromUnknown(nestedFromPackage, nestedValue, mappings);
|
|
5327
|
+
};
|
|
5328
|
+
const collectOverrideMappingsFromRecord = (overrideRecord) => {
|
|
5329
|
+
const mappings = [];
|
|
5330
|
+
for (const [fromPackage, overrideValue] of Object.entries(overrideRecord)) collectOverrideMappingsFromUnknown(fromPackage, overrideValue, mappings);
|
|
5331
|
+
return mappings;
|
|
5332
|
+
};
|
|
5333
|
+
|
|
5334
|
+
//#endregion
|
|
5335
|
+
//#region src/utils/parse-pnpm-workspace-overrides.ts
|
|
5336
|
+
const PNPM_WORKSPACE_FILENAMES = ["pnpm-workspace.yaml", "pnpm-workspace.yml"];
|
|
5337
|
+
const parseIndentedYamlMapping = (lines, startLineIndex, sectionIndent) => {
|
|
5338
|
+
const entries = {};
|
|
5339
|
+
let lineIndex = startLineIndex;
|
|
5340
|
+
while (lineIndex < lines.length) {
|
|
5341
|
+
const line = lines[lineIndex];
|
|
5342
|
+
const trimmedLine = line.trim();
|
|
5343
|
+
if (trimmedLine.length === 0 || trimmedLine.startsWith("#")) {
|
|
5344
|
+
lineIndex++;
|
|
5345
|
+
continue;
|
|
5346
|
+
}
|
|
5347
|
+
const indent = line.length - line.trimStart().length;
|
|
5348
|
+
if (indent <= sectionIndent) break;
|
|
5349
|
+
const colonIndex = trimmedLine.indexOf(":");
|
|
5350
|
+
if (colonIndex === -1) {
|
|
5351
|
+
lineIndex++;
|
|
5352
|
+
continue;
|
|
5353
|
+
}
|
|
5354
|
+
const key = trimmedLine.slice(0, colonIndex).trim().replace(/^["']|["']$/g, "");
|
|
5355
|
+
const rawValue = trimmedLine.slice(colonIndex + 1).trim();
|
|
5356
|
+
if (!key) {
|
|
5357
|
+
lineIndex++;
|
|
5358
|
+
continue;
|
|
5359
|
+
}
|
|
5360
|
+
if (rawValue.length === 0) {
|
|
5361
|
+
const nestedMapping = parseIndentedYamlMapping(lines, lineIndex + 1, indent);
|
|
5362
|
+
entries[key] = nestedMapping.entries;
|
|
5363
|
+
lineIndex = nestedMapping.endLineIndex;
|
|
5364
|
+
continue;
|
|
5365
|
+
}
|
|
5366
|
+
entries[key] = rawValue.replace(/^["']|["']$/g, "");
|
|
5367
|
+
lineIndex++;
|
|
5368
|
+
}
|
|
5369
|
+
return {
|
|
5370
|
+
entries,
|
|
5371
|
+
endLineIndex: lineIndex
|
|
5372
|
+
};
|
|
5373
|
+
};
|
|
5374
|
+
const parsePnpmWorkspaceOverrideRecords = (yamlContent) => {
|
|
5375
|
+
const lines = yamlContent.split("\n");
|
|
5376
|
+
const overrideRecords = [];
|
|
5377
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
5378
|
+
if (lines[lineIndex].trim() !== "overrides:") continue;
|
|
5379
|
+
const sectionIndent = lines[lineIndex].length - lines[lineIndex].trimStart().length;
|
|
5380
|
+
const parsedMapping = parseIndentedYamlMapping(lines, lineIndex + 1, sectionIndent);
|
|
5381
|
+
if (Object.keys(parsedMapping.entries).length > 0) overrideRecords.push(parsedMapping.entries);
|
|
5382
|
+
}
|
|
5383
|
+
return overrideRecords;
|
|
5384
|
+
};
|
|
5385
|
+
const collectPnpmWorkspaceOverrideMappings = (rootDir) => {
|
|
5386
|
+
const mappings = [];
|
|
5387
|
+
for (const workspaceFilename of PNPM_WORKSPACE_FILENAMES) {
|
|
5388
|
+
const workspacePath = join(rootDir, workspaceFilename);
|
|
5389
|
+
if (!existsSync(workspacePath)) continue;
|
|
5390
|
+
try {
|
|
5391
|
+
const overrideRecords = parsePnpmWorkspaceOverrideRecords(readFileSync(workspacePath, "utf-8"));
|
|
5392
|
+
for (const overrideRecord of overrideRecords) mappings.push(...collectOverrideMappingsFromRecord(overrideRecord));
|
|
5393
|
+
} catch {
|
|
5394
|
+
continue;
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5397
|
+
return mappings;
|
|
5398
|
+
};
|
|
5399
|
+
|
|
5400
|
+
//#endregion
|
|
5401
|
+
//#region src/utils/matches-package-import-reference.ts
|
|
5402
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5403
|
+
const matchesPackageImportReference = (content, packageName) => {
|
|
5404
|
+
const escapedPackageName = escapeRegExp(packageName);
|
|
5405
|
+
const subpathPattern = `(?:/[^'"]*)?`;
|
|
5406
|
+
return [
|
|
5407
|
+
new RegExp(`\\bfrom\\s+['"]${escapedPackageName}${subpathPattern}['"]`),
|
|
5408
|
+
new RegExp(`\\bimport\\s+(?:[^'";\\n]*?\\sfrom\\s+)?['"]${escapedPackageName}${subpathPattern}['"]`),
|
|
5409
|
+
new RegExp(`\\brequire\\s*\\(\\s*['"]${escapedPackageName}${subpathPattern}['"]\\s*\\)`),
|
|
5410
|
+
new RegExp(`\\bimport\\s*\\(\\s*['"]${escapedPackageName}${subpathPattern}['"]`)
|
|
5411
|
+
].some((pattern) => pattern.test(content));
|
|
5412
|
+
};
|
|
5413
|
+
|
|
5294
5414
|
//#endregion
|
|
5295
5415
|
//#region src/report/packages.ts
|
|
5296
5416
|
const discoverAllPackageJsonPaths = (rootDir) => {
|
|
@@ -5385,6 +5505,11 @@ const detectStalePackages = (graph, config) => {
|
|
|
5385
5505
|
for (const packageName of staticPeerSatisfied) usedPackageNames.add(packageName);
|
|
5386
5506
|
const implicitCompanionPackages = collectImplicitCompanionPackages(declaredNames, usedPackageNames);
|
|
5387
5507
|
for (const packageName of implicitCompanionPackages) usedPackageNames.add(packageName);
|
|
5508
|
+
const overrideMappings = collectOverrideMappings(configSearchRoots, allPackageJsonPaths, monorepoRoot);
|
|
5509
|
+
for (const { fromPackage, toPackage } of overrideMappings) {
|
|
5510
|
+
if (declaredNames.has(toPackage)) usedPackageNames.add(toPackage);
|
|
5511
|
+
if (usedPackageNames.has(fromPackage) && declaredNames.has(toPackage)) usedPackageNames.add(toPackage);
|
|
5512
|
+
}
|
|
5388
5513
|
const candidateUnused = /* @__PURE__ */ new Set();
|
|
5389
5514
|
for (const [dependencyName] of declaredDependencies) {
|
|
5390
5515
|
if (isAlwaysConsideredUsed(dependencyName)) continue;
|
|
@@ -5481,7 +5606,8 @@ const collectStaticPeerSatisfiedPackages = (declaredNames, confirmedUsedNames) =
|
|
|
5481
5606
|
};
|
|
5482
5607
|
const IMPLICIT_COMPANION_DEPENDENCY_MAP = {
|
|
5483
5608
|
jest: ["jest-config"],
|
|
5484
|
-
"jest-cli": ["jest-config"]
|
|
5609
|
+
"jest-cli": ["jest-config"],
|
|
5610
|
+
"vite-plus": ["@voidzero-dev/vite-plus-core"]
|
|
5485
5611
|
};
|
|
5486
5612
|
const collectImplicitCompanionPackages = (declaredNames, confirmedUsedNames) => {
|
|
5487
5613
|
const companions = /* @__PURE__ */ new Set();
|
|
@@ -5522,7 +5648,11 @@ const CLI_BINARY_TO_PACKAGE = {
|
|
|
5522
5648
|
"rndebugger-open": "react-native-debugger-open",
|
|
5523
5649
|
"simple-git-hooks": "simple-git-hooks",
|
|
5524
5650
|
"generate-arg-types": "@webstudio-is/generate-arg-types",
|
|
5525
|
-
email: "@react-email/preview-server"
|
|
5651
|
+
email: "@react-email/preview-server",
|
|
5652
|
+
vp: "vite-plus",
|
|
5653
|
+
turbo: "turbo",
|
|
5654
|
+
changeset: "@changesets/cli",
|
|
5655
|
+
tsx: "tsx"
|
|
5526
5656
|
};
|
|
5527
5657
|
const CLI_BINARY_FALLBACK_PACKAGES = {
|
|
5528
5658
|
babel: ["babel-cli"],
|
|
@@ -5676,6 +5806,42 @@ const PACKAGE_JSON_CONFIG_SECTIONS = [
|
|
|
5676
5806
|
"resolutions",
|
|
5677
5807
|
"overrides"
|
|
5678
5808
|
];
|
|
5809
|
+
const collectOverrideMappingsFromPackageJson = (packageJsonPath) => {
|
|
5810
|
+
const mappings = [];
|
|
5811
|
+
try {
|
|
5812
|
+
const content = readFileSync(packageJsonPath, "utf-8");
|
|
5813
|
+
const packageJson = JSON.parse(content);
|
|
5814
|
+
const overrideSections = [
|
|
5815
|
+
packageJson.overrides,
|
|
5816
|
+
packageJson.resolutions,
|
|
5817
|
+
packageJson.pnpm?.overrides
|
|
5818
|
+
];
|
|
5819
|
+
for (const overrideSection of overrideSections) {
|
|
5820
|
+
if (!overrideSection || typeof overrideSection !== "object") continue;
|
|
5821
|
+
mappings.push(...collectOverrideMappingsFromRecord(overrideSection));
|
|
5822
|
+
}
|
|
5823
|
+
} catch {
|
|
5824
|
+
return mappings;
|
|
5825
|
+
}
|
|
5826
|
+
return mappings;
|
|
5827
|
+
};
|
|
5828
|
+
const collectOverrideMappings = (configSearchRoots, packageJsonPaths, monorepoRoot) => {
|
|
5829
|
+
const mappings = [];
|
|
5830
|
+
const seenMappings = /* @__PURE__ */ new Set();
|
|
5831
|
+
const addMappings = (nextMappings) => {
|
|
5832
|
+
for (const mapping of nextMappings) {
|
|
5833
|
+
const mappingKey = `${mapping.fromPackage}->${mapping.toPackage}`;
|
|
5834
|
+
if (seenMappings.has(mappingKey)) continue;
|
|
5835
|
+
seenMappings.add(mappingKey);
|
|
5836
|
+
mappings.push(mapping);
|
|
5837
|
+
}
|
|
5838
|
+
};
|
|
5839
|
+
for (const packageJsonPath of packageJsonPaths) addMappings(collectOverrideMappingsFromPackageJson(packageJsonPath));
|
|
5840
|
+
const workspaceRoots = new Set(configSearchRoots);
|
|
5841
|
+
if (monorepoRoot) workspaceRoots.add(monorepoRoot);
|
|
5842
|
+
for (const workspaceRoot of workspaceRoots) addMappings(collectPnpmWorkspaceOverrideMappings(workspaceRoot));
|
|
5843
|
+
return mappings;
|
|
5844
|
+
};
|
|
5679
5845
|
const collectPackageJsonConfigReferences = (packageJsonPath, declaredNames) => {
|
|
5680
5846
|
const referenced = /* @__PURE__ */ new Set();
|
|
5681
5847
|
try {
|
|
@@ -5801,7 +5967,7 @@ const scanSourceFilesForPackageImports = (rootDir, candidatePackages) => {
|
|
|
5801
5967
|
if (candidatePackages.size === 0) break;
|
|
5802
5968
|
try {
|
|
5803
5969
|
const content = readFileSync(filePath, "utf-8");
|
|
5804
|
-
for (const packageName of candidatePackages) if (
|
|
5970
|
+
for (const packageName of candidatePackages) if (matchesPackageImportReference(content, packageName)) {
|
|
5805
5971
|
found.add(packageName);
|
|
5806
5972
|
candidatePackages.delete(packageName);
|
|
5807
5973
|
}
|
package/package.json
CHANGED
package/dist/cli.cjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const require_src = require('./src-wbNpmldQ.cjs');
|
|
3
|
-
let node_path = require("node:path");
|
|
4
|
-
|
|
5
|
-
//#region src/cli.ts
|
|
6
|
-
const HELP_TEXT = `
|
|
7
|
-
deslop - Dead code detector for TypeScript/JavaScript
|
|
8
|
-
|
|
9
|
-
Usage:
|
|
10
|
-
deslop [options] [rootDir]
|
|
11
|
-
|
|
12
|
-
Options:
|
|
13
|
-
--entry <pattern> Entry point glob pattern (can be repeated)
|
|
14
|
-
--ignore <pattern> Ignore glob pattern (can be repeated)
|
|
15
|
-
--tsconfig <path> Path to tsconfig.json
|
|
16
|
-
--include-types Include type-only exports in results
|
|
17
|
-
--include-entry-exports Include entry file exports in results
|
|
18
|
-
--json Output as JSON
|
|
19
|
-
--help Show this help message
|
|
20
|
-
--version Show version
|
|
21
|
-
|
|
22
|
-
Examples:
|
|
23
|
-
deslop
|
|
24
|
-
deslop ./my-project
|
|
25
|
-
deslop --entry "src/main.ts" --ignore "**/*.test.ts"
|
|
26
|
-
deslop --json > results.json
|
|
27
|
-
`;
|
|
28
|
-
const parseArguments = (argv) => {
|
|
29
|
-
const entries = [];
|
|
30
|
-
const ignores = [];
|
|
31
|
-
let rootDir = ".";
|
|
32
|
-
let tsconfig;
|
|
33
|
-
let includeTypes = false;
|
|
34
|
-
let includeEntryExports = false;
|
|
35
|
-
let outputJson = false;
|
|
36
|
-
let showHelp = false;
|
|
37
|
-
let showVersion = false;
|
|
38
|
-
let argumentIndex = 0;
|
|
39
|
-
while (argumentIndex < argv.length) {
|
|
40
|
-
const argument = argv[argumentIndex];
|
|
41
|
-
if (argument === "--help" || argument === "-h") showHelp = true;
|
|
42
|
-
else if (argument === "--version" || argument === "-v") showVersion = true;
|
|
43
|
-
else if (argument === "--entry" || argument === "-e") {
|
|
44
|
-
argumentIndex++;
|
|
45
|
-
if (argumentIndex < argv.length) entries.push(argv[argumentIndex]);
|
|
46
|
-
} else if (argument === "--ignore" || argument === "-i") {
|
|
47
|
-
argumentIndex++;
|
|
48
|
-
if (argumentIndex < argv.length) ignores.push(argv[argumentIndex]);
|
|
49
|
-
} else if (argument === "--tsconfig") {
|
|
50
|
-
argumentIndex++;
|
|
51
|
-
if (argumentIndex < argv.length) tsconfig = argv[argumentIndex];
|
|
52
|
-
} else if (argument === "--include-types") includeTypes = true;
|
|
53
|
-
else if (argument === "--include-entry-exports") includeEntryExports = true;
|
|
54
|
-
else if (argument === "--json") outputJson = true;
|
|
55
|
-
else if (!argument.startsWith("-")) rootDir = argument;
|
|
56
|
-
argumentIndex++;
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
rootDir,
|
|
60
|
-
entries,
|
|
61
|
-
ignores,
|
|
62
|
-
tsconfig,
|
|
63
|
-
includeTypes,
|
|
64
|
-
includeEntryExports,
|
|
65
|
-
outputJson,
|
|
66
|
-
showHelp,
|
|
67
|
-
showVersion
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
const formatResults = (analysisResult, rootDir) => {
|
|
71
|
-
const outputLines = [];
|
|
72
|
-
outputLines.push(`\n deslop analysis complete\n`);
|
|
73
|
-
outputLines.push(` Scanned ${analysisResult.totalFiles} files with ${analysisResult.totalExports} exports in ${analysisResult.analysisTimeMs.toFixed(0)}ms\n`);
|
|
74
|
-
if (analysisResult.unusedFiles.length > 0) {
|
|
75
|
-
outputLines.push(` Unused files (${analysisResult.unusedFiles.length}):`);
|
|
76
|
-
for (const unusedFile of analysisResult.unusedFiles) outputLines.push(` ${(0, node_path.relative)(rootDir, unusedFile.path)}`);
|
|
77
|
-
outputLines.push("");
|
|
78
|
-
}
|
|
79
|
-
if (analysisResult.unusedExports.length > 0) {
|
|
80
|
-
outputLines.push(` Unused exports (${analysisResult.unusedExports.length}):`);
|
|
81
|
-
for (const unusedExport of analysisResult.unusedExports) {
|
|
82
|
-
const relativePath = (0, node_path.relative)(rootDir, unusedExport.path);
|
|
83
|
-
const typeLabel = unusedExport.isTypeOnly ? " (type)" : "";
|
|
84
|
-
outputLines.push(` ${relativePath}:${unusedExport.line} ${unusedExport.name}${typeLabel}`);
|
|
85
|
-
}
|
|
86
|
-
outputLines.push("");
|
|
87
|
-
}
|
|
88
|
-
if (analysisResult.unusedDependencies.length > 0) {
|
|
89
|
-
outputLines.push(` Unused dependencies (${analysisResult.unusedDependencies.length}):`);
|
|
90
|
-
for (const unusedDependency of analysisResult.unusedDependencies) {
|
|
91
|
-
const devLabel = unusedDependency.isDevDependency ? " (dev)" : "";
|
|
92
|
-
outputLines.push(` ${unusedDependency.name}${devLabel}`);
|
|
93
|
-
}
|
|
94
|
-
outputLines.push("");
|
|
95
|
-
}
|
|
96
|
-
if (analysisResult.circularDependencies.length > 0) {
|
|
97
|
-
outputLines.push(` Circular dependencies (${analysisResult.circularDependencies.length}):`);
|
|
98
|
-
for (const cycle of analysisResult.circularDependencies) {
|
|
99
|
-
const relativePaths = cycle.files.map((filePath) => (0, node_path.relative)(rootDir, filePath));
|
|
100
|
-
outputLines.push(` ${relativePaths.join(" → ")} → ${relativePaths[0]}`);
|
|
101
|
-
}
|
|
102
|
-
outputLines.push("");
|
|
103
|
-
}
|
|
104
|
-
const totalIssueCount = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length;
|
|
105
|
-
if (totalIssueCount === 0) outputLines.push(" No dead code found!\n");
|
|
106
|
-
else outputLines.push(` Total issues: ${totalIssueCount}\n`);
|
|
107
|
-
return outputLines.join("\n");
|
|
108
|
-
};
|
|
109
|
-
const main = async () => {
|
|
110
|
-
const cliArguments = parseArguments(process.argv.slice(2));
|
|
111
|
-
if (cliArguments.showHelp) {
|
|
112
|
-
process.stdout.write(HELP_TEXT);
|
|
113
|
-
process.exit(0);
|
|
114
|
-
}
|
|
115
|
-
if (cliArguments.showVersion) {
|
|
116
|
-
process.stdout.write("deslop 0.1.0\n");
|
|
117
|
-
process.exit(0);
|
|
118
|
-
}
|
|
119
|
-
const rootDir = (0, node_path.resolve)(cliArguments.rootDir);
|
|
120
|
-
const config = require_src.createConfig({
|
|
121
|
-
rootDir,
|
|
122
|
-
entryPatterns: cliArguments.entries.length > 0 ? cliArguments.entries : void 0,
|
|
123
|
-
ignorePatterns: cliArguments.ignores.length > 0 ? cliArguments.ignores : void 0,
|
|
124
|
-
tsConfigPath: cliArguments.tsconfig,
|
|
125
|
-
reportTypes: cliArguments.includeTypes,
|
|
126
|
-
includeEntryExports: cliArguments.includeEntryExports
|
|
127
|
-
});
|
|
128
|
-
try {
|
|
129
|
-
const analysisResult = await require_src.analyze(config);
|
|
130
|
-
const outputContent = cliArguments.outputJson ? JSON.stringify(analysisResult, null, 2) + "\n" : formatResults(analysisResult, rootDir);
|
|
131
|
-
const exitCode = analysisResult.unusedFiles.length + analysisResult.unusedExports.length + analysisResult.unusedDependencies.length + analysisResult.circularDependencies.length > 0 ? 1 : 0;
|
|
132
|
-
if (process.stdout.write(outputContent)) process.exit(exitCode);
|
|
133
|
-
else process.stdout.once("drain", () => process.exit(exitCode));
|
|
134
|
-
} catch (error) {
|
|
135
|
-
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
136
|
-
process.exit(2);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
main();
|
|
140
|
-
|
|
141
|
-
//#endregion
|
package/dist/cli.d.cts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/dist/cli.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|