deslop-js 0.0.3 → 0.0.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.
Files changed (3) hide show
  1. package/dist/index.cjs +117 -12
  2. package/dist/index.mjs +117 -12
  3. package/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -167,6 +167,10 @@ const IMPLICIT_DEPENDENCIES = new Set([
167
167
  "lint-staged",
168
168
  "tslib",
169
169
  "@babel/core",
170
+ "@babel/runtime",
171
+ "babel-core",
172
+ "babel-jest",
173
+ "babel-loader",
170
174
  "postcss",
171
175
  "cross-env",
172
176
  "sass",
@@ -177,7 +181,19 @@ const IMPLICIT_DEPENDENCIES = new Set([
177
181
  "@biomejs/biome",
178
182
  "patch-package",
179
183
  "simple-git-hooks",
180
- "lefthook"
184
+ "lefthook",
185
+ "ts-node",
186
+ "ts-jest",
187
+ "tsx",
188
+ "jsdom",
189
+ "rimraf",
190
+ "concurrently",
191
+ "npm-run-all",
192
+ "npm-run-all2",
193
+ "dotenv-cli",
194
+ "webpack",
195
+ "rollup",
196
+ "terser"
181
197
  ]);
182
198
  const BUILTIN_MODULES = new Set([
183
199
  "assert",
@@ -4479,8 +4495,15 @@ const buildSourceTargetMap = (graph) => {
4479
4495
 
4480
4496
  //#endregion
4481
4497
  //#region src/report/files.ts
4482
- const isHtmlFile = (filePath) => {
4483
- return filePath.endsWith(".html");
4498
+ const EXCLUDED_EXTENSIONS = new Set([
4499
+ ".html",
4500
+ ".mdx",
4501
+ ".md"
4502
+ ]);
4503
+ const hasExcludedExtension = (filePath) => {
4504
+ const lastDot = filePath.lastIndexOf(".");
4505
+ if (lastDot === -1) return false;
4506
+ return EXCLUDED_EXTENSIONS.has(filePath.slice(lastDot));
4484
4507
  };
4485
4508
  const detectOrphanFiles = (graph) => {
4486
4509
  const unusedFiles = [];
@@ -4489,7 +4512,7 @@ const detectOrphanFiles = (graph) => {
4489
4512
  if (module.isEntryPoint) continue;
4490
4513
  if (module.isDeclarationFile) continue;
4491
4514
  if (module.isConfigFile) continue;
4492
- if (isHtmlFile(module.fileId.path)) continue;
4515
+ if (hasExcludedExtension(module.fileId.path)) continue;
4493
4516
  if (isBarrelWithReachableSources(module, graph)) continue;
4494
4517
  if (hasReachableDirectImporter(module.fileId.index, graph)) continue;
4495
4518
  unusedFiles.push({ path: module.fileId.path });
@@ -4654,6 +4677,38 @@ const extractPackageName = (specifier) => {
4654
4677
 
4655
4678
  //#endregion
4656
4679
  //#region src/report/packages.ts
4680
+ const MONOREPO_ROOT_MARKERS = [
4681
+ "pnpm-workspace.yaml",
4682
+ "pnpm-workspace.yml",
4683
+ "lerna.json",
4684
+ "nx.json",
4685
+ "turbo.json",
4686
+ "rush.json"
4687
+ ];
4688
+ const LOCKFILE_MARKERS = [
4689
+ "pnpm-lock.yaml",
4690
+ "yarn.lock",
4691
+ "package-lock.json",
4692
+ "bun.lockb",
4693
+ "bun.lock"
4694
+ ];
4695
+ const findMonorepoRoot = (rootDir) => {
4696
+ let currentDirectory = (0, node_path.resolve)(rootDir);
4697
+ while (true) {
4698
+ const parentDirectory = (0, node_path.dirname)(currentDirectory);
4699
+ if (parentDirectory === currentDirectory) break;
4700
+ currentDirectory = parentDirectory;
4701
+ for (const marker of MONOREPO_ROOT_MARKERS) if ((0, node_fs.existsSync)((0, node_path.join)(currentDirectory, marker))) return currentDirectory;
4702
+ const packageJsonPath = (0, node_path.join)(currentDirectory, "package.json");
4703
+ if ((0, node_fs.existsSync)(packageJsonPath)) try {
4704
+ const content = (0, node_fs.readFileSync)(packageJsonPath, "utf-8");
4705
+ if (JSON.parse(content).workspaces) return currentDirectory;
4706
+ } catch {
4707
+ continue;
4708
+ }
4709
+ for (const lockfile of LOCKFILE_MARKERS) if ((0, node_fs.existsSync)((0, node_path.join)(currentDirectory, lockfile))) return currentDirectory;
4710
+ }
4711
+ };
4657
4712
  const discoverAllPackageJsonPaths = (rootDir) => {
4658
4713
  const paths = [(0, node_path.join)(rootDir, "package.json")];
4659
4714
  const workspacePackageJsons = fast_glob.default.sync("**/package.json", {
@@ -4687,25 +4742,34 @@ const detectStalePackages = (graph, config) => {
4687
4742
  for (const dependencyName of Object.keys(devDependencies)) declaredDependencies.set(dependencyName, true);
4688
4743
  const declaredNames = new Set(declaredDependencies.keys());
4689
4744
  const usedPackageNames = collectUsedPackages(graph);
4745
+ const monorepoRoot = findMonorepoRoot(config.rootDir);
4746
+ const nodeModulesRoot = monorepoRoot ?? config.rootDir;
4690
4747
  const allPackageJsonPaths = discoverAllPackageJsonPaths(config.rootDir);
4691
- const binToPackage = buildBinToPackageMap(config.rootDir, declaredNames);
4748
+ if (monorepoRoot) {
4749
+ const monorepoPackageJson = (0, node_path.join)(monorepoRoot, "package.json");
4750
+ if (!allPackageJsonPaths.includes(monorepoPackageJson) && (0, node_fs.existsSync)(monorepoPackageJson)) allPackageJsonPaths.push(monorepoPackageJson);
4751
+ }
4752
+ const binToPackage = buildBinToPackageMap(nodeModulesRoot, declaredNames);
4692
4753
  for (const workspacePackageJsonPath of allPackageJsonPaths) {
4693
4754
  const scriptReferenced = collectScriptReferencedPackages(workspacePackageJsonPath, declaredNames, binToPackage);
4694
4755
  for (const packageName of scriptReferenced) usedPackageNames.add(packageName);
4695
4756
  const packageJsonConfigReferenced = collectPackageJsonConfigReferences(workspacePackageJsonPath, declaredNames);
4696
4757
  for (const packageName of packageJsonConfigReferenced) usedPackageNames.add(packageName);
4697
4758
  }
4698
- const configReferenced = collectConfigReferencedPackages(config.rootDir, graph, declaredNames);
4699
- for (const packageName of configReferenced) usedPackageNames.add(packageName);
4700
- const tsconfigReferenced = collectTsconfigReferencedPackages(config.rootDir);
4701
- for (const packageName of tsconfigReferenced) usedPackageNames.add(packageName);
4759
+ const configSearchRoots = monorepoRoot && monorepoRoot !== config.rootDir ? [config.rootDir, monorepoRoot] : [config.rootDir];
4760
+ for (const configSearchRoot of configSearchRoots) {
4761
+ const configReferenced = collectConfigReferencedPackages(configSearchRoot, graph, declaredNames);
4762
+ for (const packageName of configReferenced) usedPackageNames.add(packageName);
4763
+ const tsconfigReferenced = collectTsconfigReferencedPackages(configSearchRoot);
4764
+ for (const packageName of tsconfigReferenced) usedPackageNames.add(packageName);
4765
+ }
4702
4766
  if (hasJsxFiles(graph)) {
4703
4767
  if (declaredNames.has("react")) usedPackageNames.add("react");
4704
4768
  if (declaredNames.has("react-dom")) usedPackageNames.add("react-dom");
4705
4769
  if (declaredNames.has("react-native")) usedPackageNames.add("react-native");
4706
4770
  if (declaredNames.has("react-native-web")) usedPackageNames.add("react-native-web");
4707
4771
  }
4708
- const peerSatisfied = collectPeerSatisfiedPackages(config.rootDir, declaredNames, usedPackageNames);
4772
+ const peerSatisfied = collectPeerSatisfiedPackages(nodeModulesRoot, declaredNames, usedPackageNames);
4709
4773
  for (const packageName of peerSatisfied) usedPackageNames.add(packageName);
4710
4774
  const unusedDependencies = [];
4711
4775
  for (const [dependencyName, isDevDependency] of declaredDependencies) {
@@ -4840,9 +4904,12 @@ const CONFIG_FILE_GLOBS = [
4840
4904
  "eslint.config.{js,cjs,mjs,ts,mts,cts}",
4841
4905
  "webpack.config.{js,ts,mjs,cjs}",
4842
4906
  "**/webpack*.config.{js,ts,mjs,cjs}",
4907
+ "**/webpack*.config*.{js,ts,mjs,cjs}",
4908
+ "**/webpack*.babel.{js,ts}",
4843
4909
  "vite.config.{js,ts,mjs,mts}",
4844
4910
  "rollup.config.{js,ts,mjs,cjs}",
4845
4911
  ".storybook/main.{js,ts,mjs,cjs}",
4912
+ ".storybook/preview.{js,ts,mjs,cjs,tsx,jsx}",
4846
4913
  "docusaurus.config.{js,ts,mjs}",
4847
4914
  "next.config.{js,ts,mjs,mts}",
4848
4915
  "tailwind.config.{js,ts,cjs,mjs}",
@@ -4855,7 +4922,14 @@ const CONFIG_FILE_GLOBS = [
4855
4922
  "wrangler.jsonc",
4856
4923
  "metro.config.{js,ts}",
4857
4924
  "electron.vite.config.{js,ts,mjs}",
4858
- "api-extractor.json"
4925
+ "api-extractor.json",
4926
+ "codegen.{ts,js,yml,yaml}",
4927
+ ".graphqlrc.{ts,js,json,yml,yaml}",
4928
+ "graphql.config.{ts,js,json,yml,yaml}",
4929
+ ".lintstagedrc.{js,cjs,mjs,json}",
4930
+ "commitlint.config.{js,cjs,mjs,ts}",
4931
+ ".commitlintrc.{js,cjs,mjs,json,yaml,yml}",
4932
+ "tslint.json"
4859
4933
  ];
4860
4934
  const collectConfigReferencedPackages = (rootDir, graph, declaredNames) => {
4861
4935
  const referenced = /* @__PURE__ */ new Set();
@@ -4979,7 +5053,38 @@ const ALWAYS_USED_PREFIXES = [
4979
5053
  "@svgr/",
4980
5054
  "@docusaurus/",
4981
5055
  "stylelint-config-",
4982
- "stylelint-plugin-"
5056
+ "stylelint-plugin-",
5057
+ "@testing-library/",
5058
+ "@vitest/",
5059
+ "@playwright/",
5060
+ "@storybook/",
5061
+ "jest-environment-",
5062
+ "@graphql-codegen/",
5063
+ "@size-limit/",
5064
+ "@nestjs/",
5065
+ "@swc/",
5066
+ "@electron-forge/",
5067
+ "@parcel/",
5068
+ "@wyw-in-js/",
5069
+ "@typescript-eslint/",
5070
+ "@react-native/",
5071
+ "@react-native-community/",
5072
+ "postcss-",
5073
+ "@tailwindcss/",
5074
+ "rollup-plugin-",
5075
+ "vite-plugin-",
5076
+ "@vitejs/",
5077
+ "webpack-",
5078
+ "esbuild-",
5079
+ "@esbuild-plugins/",
5080
+ "@lingui/",
5081
+ "@emotion/",
5082
+ "tslint-config-",
5083
+ "@changesets/",
5084
+ "@vercel/",
5085
+ "@expo/",
5086
+ "expo-",
5087
+ "react-native-"
4983
5088
  ];
4984
5089
  const isAlwaysConsideredUsed = (dependencyName) => {
4985
5090
  if (IMPLICIT_DEPENDENCIES.has(dependencyName)) return true;
package/dist/index.mjs CHANGED
@@ -137,6 +137,10 @@ const IMPLICIT_DEPENDENCIES = new Set([
137
137
  "lint-staged",
138
138
  "tslib",
139
139
  "@babel/core",
140
+ "@babel/runtime",
141
+ "babel-core",
142
+ "babel-jest",
143
+ "babel-loader",
140
144
  "postcss",
141
145
  "cross-env",
142
146
  "sass",
@@ -147,7 +151,19 @@ const IMPLICIT_DEPENDENCIES = new Set([
147
151
  "@biomejs/biome",
148
152
  "patch-package",
149
153
  "simple-git-hooks",
150
- "lefthook"
154
+ "lefthook",
155
+ "ts-node",
156
+ "ts-jest",
157
+ "tsx",
158
+ "jsdom",
159
+ "rimraf",
160
+ "concurrently",
161
+ "npm-run-all",
162
+ "npm-run-all2",
163
+ "dotenv-cli",
164
+ "webpack",
165
+ "rollup",
166
+ "terser"
151
167
  ]);
152
168
  const BUILTIN_MODULES = new Set([
153
169
  "assert",
@@ -4449,8 +4465,15 @@ const buildSourceTargetMap = (graph) => {
4449
4465
 
4450
4466
  //#endregion
4451
4467
  //#region src/report/files.ts
4452
- const isHtmlFile = (filePath) => {
4453
- return filePath.endsWith(".html");
4468
+ const EXCLUDED_EXTENSIONS = new Set([
4469
+ ".html",
4470
+ ".mdx",
4471
+ ".md"
4472
+ ]);
4473
+ const hasExcludedExtension = (filePath) => {
4474
+ const lastDot = filePath.lastIndexOf(".");
4475
+ if (lastDot === -1) return false;
4476
+ return EXCLUDED_EXTENSIONS.has(filePath.slice(lastDot));
4454
4477
  };
4455
4478
  const detectOrphanFiles = (graph) => {
4456
4479
  const unusedFiles = [];
@@ -4459,7 +4482,7 @@ const detectOrphanFiles = (graph) => {
4459
4482
  if (module.isEntryPoint) continue;
4460
4483
  if (module.isDeclarationFile) continue;
4461
4484
  if (module.isConfigFile) continue;
4462
- if (isHtmlFile(module.fileId.path)) continue;
4485
+ if (hasExcludedExtension(module.fileId.path)) continue;
4463
4486
  if (isBarrelWithReachableSources(module, graph)) continue;
4464
4487
  if (hasReachableDirectImporter(module.fileId.index, graph)) continue;
4465
4488
  unusedFiles.push({ path: module.fileId.path });
@@ -4624,6 +4647,38 @@ const extractPackageName = (specifier) => {
4624
4647
 
4625
4648
  //#endregion
4626
4649
  //#region src/report/packages.ts
4650
+ const MONOREPO_ROOT_MARKERS = [
4651
+ "pnpm-workspace.yaml",
4652
+ "pnpm-workspace.yml",
4653
+ "lerna.json",
4654
+ "nx.json",
4655
+ "turbo.json",
4656
+ "rush.json"
4657
+ ];
4658
+ const LOCKFILE_MARKERS = [
4659
+ "pnpm-lock.yaml",
4660
+ "yarn.lock",
4661
+ "package-lock.json",
4662
+ "bun.lockb",
4663
+ "bun.lock"
4664
+ ];
4665
+ const findMonorepoRoot = (rootDir) => {
4666
+ let currentDirectory = resolve(rootDir);
4667
+ while (true) {
4668
+ const parentDirectory = dirname(currentDirectory);
4669
+ if (parentDirectory === currentDirectory) break;
4670
+ currentDirectory = parentDirectory;
4671
+ for (const marker of MONOREPO_ROOT_MARKERS) if (existsSync(join(currentDirectory, marker))) return currentDirectory;
4672
+ const packageJsonPath = join(currentDirectory, "package.json");
4673
+ if (existsSync(packageJsonPath)) try {
4674
+ const content = readFileSync(packageJsonPath, "utf-8");
4675
+ if (JSON.parse(content).workspaces) return currentDirectory;
4676
+ } catch {
4677
+ continue;
4678
+ }
4679
+ for (const lockfile of LOCKFILE_MARKERS) if (existsSync(join(currentDirectory, lockfile))) return currentDirectory;
4680
+ }
4681
+ };
4627
4682
  const discoverAllPackageJsonPaths = (rootDir) => {
4628
4683
  const paths = [join(rootDir, "package.json")];
4629
4684
  const workspacePackageJsons = fg.sync("**/package.json", {
@@ -4657,25 +4712,34 @@ const detectStalePackages = (graph, config) => {
4657
4712
  for (const dependencyName of Object.keys(devDependencies)) declaredDependencies.set(dependencyName, true);
4658
4713
  const declaredNames = new Set(declaredDependencies.keys());
4659
4714
  const usedPackageNames = collectUsedPackages(graph);
4715
+ const monorepoRoot = findMonorepoRoot(config.rootDir);
4716
+ const nodeModulesRoot = monorepoRoot ?? config.rootDir;
4660
4717
  const allPackageJsonPaths = discoverAllPackageJsonPaths(config.rootDir);
4661
- const binToPackage = buildBinToPackageMap(config.rootDir, declaredNames);
4718
+ if (monorepoRoot) {
4719
+ const monorepoPackageJson = join(monorepoRoot, "package.json");
4720
+ if (!allPackageJsonPaths.includes(monorepoPackageJson) && existsSync(monorepoPackageJson)) allPackageJsonPaths.push(monorepoPackageJson);
4721
+ }
4722
+ const binToPackage = buildBinToPackageMap(nodeModulesRoot, declaredNames);
4662
4723
  for (const workspacePackageJsonPath of allPackageJsonPaths) {
4663
4724
  const scriptReferenced = collectScriptReferencedPackages(workspacePackageJsonPath, declaredNames, binToPackage);
4664
4725
  for (const packageName of scriptReferenced) usedPackageNames.add(packageName);
4665
4726
  const packageJsonConfigReferenced = collectPackageJsonConfigReferences(workspacePackageJsonPath, declaredNames);
4666
4727
  for (const packageName of packageJsonConfigReferenced) usedPackageNames.add(packageName);
4667
4728
  }
4668
- const configReferenced = collectConfigReferencedPackages(config.rootDir, graph, declaredNames);
4669
- for (const packageName of configReferenced) usedPackageNames.add(packageName);
4670
- const tsconfigReferenced = collectTsconfigReferencedPackages(config.rootDir);
4671
- for (const packageName of tsconfigReferenced) usedPackageNames.add(packageName);
4729
+ const configSearchRoots = monorepoRoot && monorepoRoot !== config.rootDir ? [config.rootDir, monorepoRoot] : [config.rootDir];
4730
+ for (const configSearchRoot of configSearchRoots) {
4731
+ const configReferenced = collectConfigReferencedPackages(configSearchRoot, graph, declaredNames);
4732
+ for (const packageName of configReferenced) usedPackageNames.add(packageName);
4733
+ const tsconfigReferenced = collectTsconfigReferencedPackages(configSearchRoot);
4734
+ for (const packageName of tsconfigReferenced) usedPackageNames.add(packageName);
4735
+ }
4672
4736
  if (hasJsxFiles(graph)) {
4673
4737
  if (declaredNames.has("react")) usedPackageNames.add("react");
4674
4738
  if (declaredNames.has("react-dom")) usedPackageNames.add("react-dom");
4675
4739
  if (declaredNames.has("react-native")) usedPackageNames.add("react-native");
4676
4740
  if (declaredNames.has("react-native-web")) usedPackageNames.add("react-native-web");
4677
4741
  }
4678
- const peerSatisfied = collectPeerSatisfiedPackages(config.rootDir, declaredNames, usedPackageNames);
4742
+ const peerSatisfied = collectPeerSatisfiedPackages(nodeModulesRoot, declaredNames, usedPackageNames);
4679
4743
  for (const packageName of peerSatisfied) usedPackageNames.add(packageName);
4680
4744
  const unusedDependencies = [];
4681
4745
  for (const [dependencyName, isDevDependency] of declaredDependencies) {
@@ -4810,9 +4874,12 @@ const CONFIG_FILE_GLOBS = [
4810
4874
  "eslint.config.{js,cjs,mjs,ts,mts,cts}",
4811
4875
  "webpack.config.{js,ts,mjs,cjs}",
4812
4876
  "**/webpack*.config.{js,ts,mjs,cjs}",
4877
+ "**/webpack*.config*.{js,ts,mjs,cjs}",
4878
+ "**/webpack*.babel.{js,ts}",
4813
4879
  "vite.config.{js,ts,mjs,mts}",
4814
4880
  "rollup.config.{js,ts,mjs,cjs}",
4815
4881
  ".storybook/main.{js,ts,mjs,cjs}",
4882
+ ".storybook/preview.{js,ts,mjs,cjs,tsx,jsx}",
4816
4883
  "docusaurus.config.{js,ts,mjs}",
4817
4884
  "next.config.{js,ts,mjs,mts}",
4818
4885
  "tailwind.config.{js,ts,cjs,mjs}",
@@ -4825,7 +4892,14 @@ const CONFIG_FILE_GLOBS = [
4825
4892
  "wrangler.jsonc",
4826
4893
  "metro.config.{js,ts}",
4827
4894
  "electron.vite.config.{js,ts,mjs}",
4828
- "api-extractor.json"
4895
+ "api-extractor.json",
4896
+ "codegen.{ts,js,yml,yaml}",
4897
+ ".graphqlrc.{ts,js,json,yml,yaml}",
4898
+ "graphql.config.{ts,js,json,yml,yaml}",
4899
+ ".lintstagedrc.{js,cjs,mjs,json}",
4900
+ "commitlint.config.{js,cjs,mjs,ts}",
4901
+ ".commitlintrc.{js,cjs,mjs,json,yaml,yml}",
4902
+ "tslint.json"
4829
4903
  ];
4830
4904
  const collectConfigReferencedPackages = (rootDir, graph, declaredNames) => {
4831
4905
  const referenced = /* @__PURE__ */ new Set();
@@ -4949,7 +5023,38 @@ const ALWAYS_USED_PREFIXES = [
4949
5023
  "@svgr/",
4950
5024
  "@docusaurus/",
4951
5025
  "stylelint-config-",
4952
- "stylelint-plugin-"
5026
+ "stylelint-plugin-",
5027
+ "@testing-library/",
5028
+ "@vitest/",
5029
+ "@playwright/",
5030
+ "@storybook/",
5031
+ "jest-environment-",
5032
+ "@graphql-codegen/",
5033
+ "@size-limit/",
5034
+ "@nestjs/",
5035
+ "@swc/",
5036
+ "@electron-forge/",
5037
+ "@parcel/",
5038
+ "@wyw-in-js/",
5039
+ "@typescript-eslint/",
5040
+ "@react-native/",
5041
+ "@react-native-community/",
5042
+ "postcss-",
5043
+ "@tailwindcss/",
5044
+ "rollup-plugin-",
5045
+ "vite-plugin-",
5046
+ "@vitejs/",
5047
+ "webpack-",
5048
+ "esbuild-",
5049
+ "@esbuild-plugins/",
5050
+ "@lingui/",
5051
+ "@emotion/",
5052
+ "tslint-config-",
5053
+ "@changesets/",
5054
+ "@vercel/",
5055
+ "@expo/",
5056
+ "expo-",
5057
+ "react-native-"
4953
5058
  ];
4954
5059
  const isAlwaysConsideredUsed = (dependencyName) => {
4955
5060
  if (IMPLICIT_DEPENDENCIES.has(dependencyName)) return true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deslop-js",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Deslop JavaScript code",
5
5
  "keywords": [
6
6
  "dead-code",