deslop-js 0.0.24 → 0.0.25-dev.aeeb44a

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
@@ -268,6 +268,13 @@ const PLATFORM_SUFFIXES = [
268
268
  ".server",
269
269
  ".client"
270
270
  ];
271
+ const REACT_NATIVE_PLATFORM_SUFFIXES = [
272
+ ".web",
273
+ ".react-native",
274
+ ".native",
275
+ ".ios",
276
+ ".android"
277
+ ];
271
278
  const REACT_NATIVE_PLATFORM_EXTENSIONS = [
272
279
  ".web.ts",
273
280
  ".web.tsx",
@@ -7771,10 +7778,21 @@ const hasReachableDirectImporter = (targetModuleIndex, graph) => {
7771
7778
  return false;
7772
7779
  };
7773
7780
 
7781
+ //#endregion
7782
+ //#region src/utils/platform-stripped-base-path.ts
7783
+ const platformStrippedBasePath = (modulePath, suffixes = PLATFORM_SUFFIXES) => {
7784
+ const extensionIndex = modulePath.lastIndexOf(".");
7785
+ if (extensionIndex === -1) return modulePath;
7786
+ const withoutExtension = modulePath.slice(0, extensionIndex);
7787
+ for (const suffix of suffixes) if (withoutExtension.endsWith(suffix)) return withoutExtension.slice(0, -suffix.length) + modulePath.slice(extensionIndex);
7788
+ return modulePath;
7789
+ };
7790
+
7774
7791
  //#endregion
7775
7792
  //#region src/report/exports.ts
7776
7793
  const detectDeadExports = (graph, config) => {
7777
7794
  const usageMap = buildUsageMap(graph);
7795
+ const platformSiblingUsageKeys = graph.hasReactNative ? buildPlatformSiblingUsageKeys(usageMap) : void 0;
7778
7796
  const unusedExports = [];
7779
7797
  for (const module of graph.modules) {
7780
7798
  if (!module.isReachable) continue;
@@ -7789,6 +7807,7 @@ const detectDeadExports = (graph, config) => {
7789
7807
  if (!config.reportTypes && exportInfo.isTypeOnly) continue;
7790
7808
  const usageKey = `${module.fileId.path}::${exportInfo.name}`;
7791
7809
  if (usageMap.has(usageKey)) continue;
7810
+ if (platformSiblingUsageKeys?.has(`${platformStrippedBasePath(module.fileId.path, REACT_NATIVE_PLATFORM_SUFFIXES)}::${exportInfo.name}`)) continue;
7792
7811
  if (module.localIdentifierReferences.includes(exportInfo.name)) continue;
7793
7812
  if (!exportInfo.isDefault && defaultExportLinkedNames.has(exportInfo.name)) continue;
7794
7813
  unusedExports.push({
@@ -7802,6 +7821,18 @@ const detectDeadExports = (graph, config) => {
7802
7821
  }
7803
7822
  return unusedExports;
7804
7823
  };
7824
+ const buildPlatformSiblingUsageKeys = (usageMap) => {
7825
+ const baseKeys = /* @__PURE__ */ new Set();
7826
+ for (const usageKey of usageMap) {
7827
+ const separatorIndex = usageKey.lastIndexOf("::");
7828
+ if (separatorIndex === -1) continue;
7829
+ const filePath = usageKey.slice(0, separatorIndex);
7830
+ const exportName = usageKey.slice(separatorIndex + 2);
7831
+ const basePath = platformStrippedBasePath(filePath, REACT_NATIVE_PLATFORM_SUFFIXES);
7832
+ baseKeys.add(`${basePath}::${exportName}`);
7833
+ }
7834
+ return baseKeys;
7835
+ };
7805
7836
  const buildUsageMap = (graph) => {
7806
7837
  const usedExportKeys = /* @__PURE__ */ new Set();
7807
7838
  const sourceToTargetMap = buildSourceToTargetsMap(graph);
@@ -8878,19 +8909,7 @@ const detectCycles = (graph) => {
8878
8909
 
8879
8910
  //#endregion
8880
8911
  //#region src/report/redundancy.ts
8881
- const isPlatformSpecificModulePath = (modulePath) => {
8882
- const extensionIndex = modulePath.lastIndexOf(".");
8883
- if (extensionIndex === -1) return false;
8884
- const withoutExtension = modulePath.slice(0, extensionIndex);
8885
- return PLATFORM_SUFFIXES.some((suffix) => withoutExtension.endsWith(suffix));
8886
- };
8887
- const platformStrippedBasePath = (modulePath) => {
8888
- const extensionIndex = modulePath.lastIndexOf(".");
8889
- if (extensionIndex === -1) return modulePath;
8890
- const withoutExtension = modulePath.slice(0, extensionIndex);
8891
- for (const suffix of PLATFORM_SUFFIXES) if (withoutExtension.endsWith(suffix)) return withoutExtension.slice(0, -suffix.length) + modulePath.slice(extensionIndex);
8892
- return modulePath;
8893
- };
8912
+ const isPlatformSpecificModulePath = (modulePath) => platformStrippedBasePath(modulePath) !== modulePath;
8894
8913
  const buildPlatformSiblingGroupSizes = (graph) => {
8895
8914
  const baseToCount = /* @__PURE__ */ new Map();
8896
8915
  for (const module of graph.modules) {
@@ -13224,6 +13243,7 @@ const analyze = async (config) => {
13224
13243
  }));
13225
13244
  return buildEmptyScanResult(setupErrors, performance.now() - pipelineStartTime);
13226
13245
  }
13246
+ moduleGraph.hasReactNative = hasReactNative;
13227
13247
  try {
13228
13248
  resolveReExportChains(moduleGraph);
13229
13249
  } catch (reExportError) {
package/dist/index.mjs CHANGED
@@ -236,6 +236,13 @@ const PLATFORM_SUFFIXES = [
236
236
  ".server",
237
237
  ".client"
238
238
  ];
239
+ const REACT_NATIVE_PLATFORM_SUFFIXES = [
240
+ ".web",
241
+ ".react-native",
242
+ ".native",
243
+ ".ios",
244
+ ".android"
245
+ ];
239
246
  const REACT_NATIVE_PLATFORM_EXTENSIONS = [
240
247
  ".web.ts",
241
248
  ".web.tsx",
@@ -7739,10 +7746,21 @@ const hasReachableDirectImporter = (targetModuleIndex, graph) => {
7739
7746
  return false;
7740
7747
  };
7741
7748
 
7749
+ //#endregion
7750
+ //#region src/utils/platform-stripped-base-path.ts
7751
+ const platformStrippedBasePath = (modulePath, suffixes = PLATFORM_SUFFIXES) => {
7752
+ const extensionIndex = modulePath.lastIndexOf(".");
7753
+ if (extensionIndex === -1) return modulePath;
7754
+ const withoutExtension = modulePath.slice(0, extensionIndex);
7755
+ for (const suffix of suffixes) if (withoutExtension.endsWith(suffix)) return withoutExtension.slice(0, -suffix.length) + modulePath.slice(extensionIndex);
7756
+ return modulePath;
7757
+ };
7758
+
7742
7759
  //#endregion
7743
7760
  //#region src/report/exports.ts
7744
7761
  const detectDeadExports = (graph, config) => {
7745
7762
  const usageMap = buildUsageMap(graph);
7763
+ const platformSiblingUsageKeys = graph.hasReactNative ? buildPlatformSiblingUsageKeys(usageMap) : void 0;
7746
7764
  const unusedExports = [];
7747
7765
  for (const module of graph.modules) {
7748
7766
  if (!module.isReachable) continue;
@@ -7757,6 +7775,7 @@ const detectDeadExports = (graph, config) => {
7757
7775
  if (!config.reportTypes && exportInfo.isTypeOnly) continue;
7758
7776
  const usageKey = `${module.fileId.path}::${exportInfo.name}`;
7759
7777
  if (usageMap.has(usageKey)) continue;
7778
+ if (platformSiblingUsageKeys?.has(`${platformStrippedBasePath(module.fileId.path, REACT_NATIVE_PLATFORM_SUFFIXES)}::${exportInfo.name}`)) continue;
7760
7779
  if (module.localIdentifierReferences.includes(exportInfo.name)) continue;
7761
7780
  if (!exportInfo.isDefault && defaultExportLinkedNames.has(exportInfo.name)) continue;
7762
7781
  unusedExports.push({
@@ -7770,6 +7789,18 @@ const detectDeadExports = (graph, config) => {
7770
7789
  }
7771
7790
  return unusedExports;
7772
7791
  };
7792
+ const buildPlatformSiblingUsageKeys = (usageMap) => {
7793
+ const baseKeys = /* @__PURE__ */ new Set();
7794
+ for (const usageKey of usageMap) {
7795
+ const separatorIndex = usageKey.lastIndexOf("::");
7796
+ if (separatorIndex === -1) continue;
7797
+ const filePath = usageKey.slice(0, separatorIndex);
7798
+ const exportName = usageKey.slice(separatorIndex + 2);
7799
+ const basePath = platformStrippedBasePath(filePath, REACT_NATIVE_PLATFORM_SUFFIXES);
7800
+ baseKeys.add(`${basePath}::${exportName}`);
7801
+ }
7802
+ return baseKeys;
7803
+ };
7773
7804
  const buildUsageMap = (graph) => {
7774
7805
  const usedExportKeys = /* @__PURE__ */ new Set();
7775
7806
  const sourceToTargetMap = buildSourceToTargetsMap(graph);
@@ -8846,19 +8877,7 @@ const detectCycles = (graph) => {
8846
8877
 
8847
8878
  //#endregion
8848
8879
  //#region src/report/redundancy.ts
8849
- const isPlatformSpecificModulePath = (modulePath) => {
8850
- const extensionIndex = modulePath.lastIndexOf(".");
8851
- if (extensionIndex === -1) return false;
8852
- const withoutExtension = modulePath.slice(0, extensionIndex);
8853
- return PLATFORM_SUFFIXES.some((suffix) => withoutExtension.endsWith(suffix));
8854
- };
8855
- const platformStrippedBasePath = (modulePath) => {
8856
- const extensionIndex = modulePath.lastIndexOf(".");
8857
- if (extensionIndex === -1) return modulePath;
8858
- const withoutExtension = modulePath.slice(0, extensionIndex);
8859
- for (const suffix of PLATFORM_SUFFIXES) if (withoutExtension.endsWith(suffix)) return withoutExtension.slice(0, -suffix.length) + modulePath.slice(extensionIndex);
8860
- return modulePath;
8861
- };
8880
+ const isPlatformSpecificModulePath = (modulePath) => platformStrippedBasePath(modulePath) !== modulePath;
8862
8881
  const buildPlatformSiblingGroupSizes = (graph) => {
8863
8882
  const baseToCount = /* @__PURE__ */ new Map();
8864
8883
  for (const module of graph.modules) {
@@ -13192,6 +13211,7 @@ const analyze = async (config) => {
13192
13211
  }));
13193
13212
  return buildEmptyScanResult(setupErrors, performance.now() - pipelineStartTime);
13194
13213
  }
13214
+ moduleGraph.hasReactNative = hasReactNative;
13195
13215
  try {
13196
13216
  resolveReExportChains(moduleGraph);
13197
13217
  } catch (reExportError) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deslop-js",
3
- "version": "0.0.24",
3
+ "version": "0.0.25-dev.aeeb44a",
4
4
  "description": "Deslop JavaScript code",
5
5
  "keywords": [
6
6
  "dead-code",