deslop-js 0.0.15 → 0.0.16-dev.e558efe

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 CHANGED
@@ -3694,7 +3694,7 @@ const toPosixPath = (filePath) => filePath.replace(/\\/g, "/");
3694
3694
  const collectSourceFiles = async (config) => {
3695
3695
  const extensions = config.includeExtensions.length > 0 ? config.includeExtensions : DEFAULT_EXTENSIONS;
3696
3696
  const extensionGlob = extensions.length === 1 ? `**/*${extensions[0]}` : `**/*{${extensions.join(",")}}`;
3697
- const ignorePatterns = [...DEFAULT_EXCLUSIONS, ...config.ignorePatterns];
3697
+ const ignorePatterns = [...DEFAULT_EXCLUSIONS, ...config.ignorePatterns].map(toPosixPath);
3698
3698
  const absoluteRoot = (0, node_path.resolve)(config.rootDir);
3699
3699
  const mainFiles = await (0, fast_glob.default)(extensionGlob, {
3700
3700
  cwd: absoluteRoot,
@@ -3711,7 +3711,7 @@ const collectSourceFiles = async (config) => {
3711
3711
  dot: true,
3712
3712
  onlyFiles: true
3713
3713
  }) : [];
3714
- return [...mainFiles, ...hiddenFiles].sort().map((filePath, fileIndex) => ({
3714
+ return [...new Set([...mainFiles, ...hiddenFiles].map(toPosixPath))].sort().map((filePath, fileIndex) => ({
3715
3715
  index: fileIndex,
3716
3716
  path: filePath
3717
3717
  }));
@@ -7001,9 +7001,16 @@ const isConfigFile = (filePath) => {
7001
7001
  //#endregion
7002
7002
  //#region src/linker/build.ts
7003
7003
  const buildDependencyGraph = (inputs) => {
7004
+ const normalizedInputs = inputs.map((input) => ({
7005
+ ...input,
7006
+ fileId: {
7007
+ ...input.fileId,
7008
+ path: toPosixPath(input.fileId.path)
7009
+ }
7010
+ }));
7004
7011
  const fileIdMap = /* @__PURE__ */ new Map();
7005
- for (const input of inputs) fileIdMap.set(toPosixPath(input.fileId.path), input.fileId.index);
7006
- const modules = inputs.map((input) => ({
7012
+ for (const input of normalizedInputs) fileIdMap.set(input.fileId.path, input.fileId.index);
7013
+ const modules = normalizedInputs.map((input) => ({
7007
7014
  fileId: input.fileId,
7008
7015
  imports: input.parsed.imports,
7009
7016
  exports: input.parsed.exports,
@@ -7041,7 +7048,7 @@ const buildDependencyGraph = (inputs) => {
7041
7048
  if (!existingReverseEdges.includes(sourceIndex)) existingReverseEdges.push(sourceIndex);
7042
7049
  } else reverseEdges.set(targetIndex, [sourceIndex]);
7043
7050
  };
7044
- for (const input of inputs) {
7051
+ for (const input of normalizedInputs) {
7045
7052
  const sourceIndex = input.fileId.index;
7046
7053
  for (const importInfo of input.parsed.imports) {
7047
7054
  if (importInfo.isGlob) {
@@ -7643,8 +7650,11 @@ const collectPnpmWorkspaceOverrideMappings = (rootDir) => {
7643
7650
  };
7644
7651
 
7645
7652
  //#endregion
7646
- //#region src/utils/matches-package-import-reference.ts
7653
+ //#region src/utils/escape-reg-exp.ts
7647
7654
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7655
+
7656
+ //#endregion
7657
+ //#region src/utils/matches-package-import-reference.ts
7648
7658
  const matchesPackageImportReference = (content, packageName) => {
7649
7659
  const escapedPackageName = escapeRegExp(packageName);
7650
7660
  const subpathPattern = `(?:/[^'"]*)?`;
@@ -7657,6 +7667,13 @@ const matchesPackageImportReference = (content, packageName) => {
7657
7667
  ].some((pattern) => pattern.test(content));
7658
7668
  };
7659
7669
 
7670
+ //#endregion
7671
+ //#region src/utils/matches-package-token-reference.ts
7672
+ const matchesPackageTokenReference = (command, packageName) => {
7673
+ const escapedPackageName = escapeRegExp(packageName);
7674
+ return new RegExp(`(?:^|[\\s='"\`(,;:|&])${escapedPackageName}(?:/[^\\s'"\`]*)?(?=$|[\\s='"\`),;:|&])`).test(command);
7675
+ };
7676
+
7660
7677
  //#endregion
7661
7678
  //#region src/report/packages.ts
7662
7679
  const discoverAllPackageJsonPaths = (rootDir) => {
@@ -7946,6 +7963,10 @@ const collectScriptReferencedPackages = (packageJsonPath, declaredNames, binToPa
7946
7963
  if (typeof scriptCommand !== "string") continue;
7947
7964
  const commandReferenced = collectCommandReferencedPackages(scriptCommand, declaredNames, binToPackage);
7948
7965
  for (const packageName of commandReferenced) referenced.add(packageName);
7966
+ for (const declaredName of declaredNames) {
7967
+ if (referenced.has(declaredName)) continue;
7968
+ if (matchesPackageTokenReference(scriptCommand, declaredName)) referenced.add(declaredName);
7969
+ }
7949
7970
  }
7950
7971
  } catch {
7951
7972
  return referenced;
package/dist/index.mjs CHANGED
@@ -3663,7 +3663,7 @@ const toPosixPath = (filePath) => filePath.replace(/\\/g, "/");
3663
3663
  const collectSourceFiles = async (config) => {
3664
3664
  const extensions = config.includeExtensions.length > 0 ? config.includeExtensions : DEFAULT_EXTENSIONS;
3665
3665
  const extensionGlob = extensions.length === 1 ? `**/*${extensions[0]}` : `**/*{${extensions.join(",")}}`;
3666
- const ignorePatterns = [...DEFAULT_EXCLUSIONS, ...config.ignorePatterns];
3666
+ const ignorePatterns = [...DEFAULT_EXCLUSIONS, ...config.ignorePatterns].map(toPosixPath);
3667
3667
  const absoluteRoot = resolve(config.rootDir);
3668
3668
  const mainFiles = await fg(extensionGlob, {
3669
3669
  cwd: absoluteRoot,
@@ -3680,7 +3680,7 @@ const collectSourceFiles = async (config) => {
3680
3680
  dot: true,
3681
3681
  onlyFiles: true
3682
3682
  }) : [];
3683
- return [...mainFiles, ...hiddenFiles].sort().map((filePath, fileIndex) => ({
3683
+ return [...new Set([...mainFiles, ...hiddenFiles].map(toPosixPath))].sort().map((filePath, fileIndex) => ({
3684
3684
  index: fileIndex,
3685
3685
  path: filePath
3686
3686
  }));
@@ -6970,9 +6970,16 @@ const isConfigFile = (filePath) => {
6970
6970
  //#endregion
6971
6971
  //#region src/linker/build.ts
6972
6972
  const buildDependencyGraph = (inputs) => {
6973
+ const normalizedInputs = inputs.map((input) => ({
6974
+ ...input,
6975
+ fileId: {
6976
+ ...input.fileId,
6977
+ path: toPosixPath(input.fileId.path)
6978
+ }
6979
+ }));
6973
6980
  const fileIdMap = /* @__PURE__ */ new Map();
6974
- for (const input of inputs) fileIdMap.set(toPosixPath(input.fileId.path), input.fileId.index);
6975
- const modules = inputs.map((input) => ({
6981
+ for (const input of normalizedInputs) fileIdMap.set(input.fileId.path, input.fileId.index);
6982
+ const modules = normalizedInputs.map((input) => ({
6976
6983
  fileId: input.fileId,
6977
6984
  imports: input.parsed.imports,
6978
6985
  exports: input.parsed.exports,
@@ -7010,7 +7017,7 @@ const buildDependencyGraph = (inputs) => {
7010
7017
  if (!existingReverseEdges.includes(sourceIndex)) existingReverseEdges.push(sourceIndex);
7011
7018
  } else reverseEdges.set(targetIndex, [sourceIndex]);
7012
7019
  };
7013
- for (const input of inputs) {
7020
+ for (const input of normalizedInputs) {
7014
7021
  const sourceIndex = input.fileId.index;
7015
7022
  for (const importInfo of input.parsed.imports) {
7016
7023
  if (importInfo.isGlob) {
@@ -7612,8 +7619,11 @@ const collectPnpmWorkspaceOverrideMappings = (rootDir) => {
7612
7619
  };
7613
7620
 
7614
7621
  //#endregion
7615
- //#region src/utils/matches-package-import-reference.ts
7622
+ //#region src/utils/escape-reg-exp.ts
7616
7623
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
7624
+
7625
+ //#endregion
7626
+ //#region src/utils/matches-package-import-reference.ts
7617
7627
  const matchesPackageImportReference = (content, packageName) => {
7618
7628
  const escapedPackageName = escapeRegExp(packageName);
7619
7629
  const subpathPattern = `(?:/[^'"]*)?`;
@@ -7626,6 +7636,13 @@ const matchesPackageImportReference = (content, packageName) => {
7626
7636
  ].some((pattern) => pattern.test(content));
7627
7637
  };
7628
7638
 
7639
+ //#endregion
7640
+ //#region src/utils/matches-package-token-reference.ts
7641
+ const matchesPackageTokenReference = (command, packageName) => {
7642
+ const escapedPackageName = escapeRegExp(packageName);
7643
+ return new RegExp(`(?:^|[\\s='"\`(,;:|&])${escapedPackageName}(?:/[^\\s'"\`]*)?(?=$|[\\s='"\`),;:|&])`).test(command);
7644
+ };
7645
+
7629
7646
  //#endregion
7630
7647
  //#region src/report/packages.ts
7631
7648
  const discoverAllPackageJsonPaths = (rootDir) => {
@@ -7915,6 +7932,10 @@ const collectScriptReferencedPackages = (packageJsonPath, declaredNames, binToPa
7915
7932
  if (typeof scriptCommand !== "string") continue;
7916
7933
  const commandReferenced = collectCommandReferencedPackages(scriptCommand, declaredNames, binToPackage);
7917
7934
  for (const packageName of commandReferenced) referenced.add(packageName);
7935
+ for (const declaredName of declaredNames) {
7936
+ if (referenced.has(declaredName)) continue;
7937
+ if (matchesPackageTokenReference(scriptCommand, declaredName)) referenced.add(declaredName);
7938
+ }
7918
7939
  }
7919
7940
  } catch {
7920
7941
  return referenced;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deslop-js",
3
- "version": "0.0.15",
3
+ "version": "0.0.16-dev.e558efe",
4
4
  "description": "Deslop JavaScript code",
5
5
  "keywords": [
6
6
  "dead-code",