@xylabs/ts-scripts-yarn3 7.4.2 → 7.4.3

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 (35) hide show
  1. package/dist/actions/deplint/checkPackage/checkPackage.mjs +82 -89
  2. package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
  3. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +5 -5
  4. package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -1
  5. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +2 -2
  6. package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -1
  7. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +7 -10
  8. package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -1
  9. package/dist/actions/deplint/checkPackage/index.mjs +82 -89
  10. package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
  11. package/dist/actions/deplint/deplint.mjs +82 -89
  12. package/dist/actions/deplint/deplint.mjs.map +1 -1
  13. package/dist/actions/deplint/findFiles.mjs +29 -14
  14. package/dist/actions/deplint/findFiles.mjs.map +1 -1
  15. package/dist/actions/deplint/findFilesByGlob.mjs +7 -2
  16. package/dist/actions/deplint/findFilesByGlob.mjs.map +1 -1
  17. package/dist/actions/deplint/getExternalImportsFromFiles.mjs +16 -23
  18. package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -1
  19. package/dist/actions/deplint/implicitDevDependencies.mjs +2 -2
  20. package/dist/actions/deplint/implicitDevDependencies.mjs.map +1 -1
  21. package/dist/actions/deplint/index.mjs +82 -89
  22. package/dist/actions/deplint/index.mjs.map +1 -1
  23. package/dist/actions/index.mjs +86 -93
  24. package/dist/actions/index.mjs.map +1 -1
  25. package/dist/bin/xy.mjs +82 -89
  26. package/dist/bin/xy.mjs.map +1 -1
  27. package/dist/index.mjs +86 -93
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/xy/index.mjs +82 -89
  30. package/dist/xy/index.mjs.map +1 -1
  31. package/dist/xy/xy.mjs +82 -89
  32. package/dist/xy/xy.mjs.map +1 -1
  33. package/dist/xy/xyLintCommands.mjs +82 -89
  34. package/dist/xy/xyLintCommands.mjs.map +1 -1
  35. package/package.json +4 -3
@@ -219,33 +219,48 @@ var cycleAll = async ({ verbose = false }) => {
219
219
  // src/actions/deplint/deplint.ts
220
220
  import chalk10 from "chalk";
221
221
 
222
+ // src/actions/deplint/findFiles.ts
223
+ import fs from "fs";
224
+
222
225
  // src/actions/deplint/findFilesByGlob.ts
223
226
  import { globSync } from "glob";
224
- function findFilesByGlob(cwd, pattern) {
225
- return globSync(pattern, { cwd, absolute: true });
227
+ function findFilesByGlob(cwd, pattern, ignore) {
228
+ return globSync(pattern, {
229
+ cwd,
230
+ absolute: true,
231
+ ignore,
232
+ nodir: true
233
+ });
226
234
  }
227
235
 
228
236
  // src/actions/deplint/findFiles.ts
229
- function findFiles(path5) {
230
- const allSourceInclude = ["./src/**/*.{ts,tsx,mts,cts,js,mjs,cjs}"];
231
- const allDistInclude = ["./dist/**/*.d.ts", "./dist/**/*.{mjs,js,cjs}"];
232
- const allConfigInclude = ["./*.config.{ts,mts,mjs,js}"];
233
- const srcFiles = allSourceInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
234
- const distFiles = allDistInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
235
- const configFiles = allConfigInclude.flatMap((pattern) => findFilesByGlob(path5, pattern));
236
- return {
237
- srcFiles,
238
- distFiles,
239
- configFiles
240
- };
237
+ var codeExtensions = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
238
+ function getWorkspaceIgnores(location) {
239
+ try {
240
+ const raw = fs.readFileSync(`${location}/package.json`, "utf8");
241
+ const pkg = JSON.parse(raw);
242
+ return pkg.workspaces ?? [];
243
+ } catch {
244
+ return [];
245
+ }
246
+ }
247
+ function findFiles(location) {
248
+ const workspaceIgnores = getWorkspaceIgnores(location).map((w) => `${w}/**`);
249
+ const ignore = ["**/node_modules/**", "dist/**", ...workspaceIgnores];
250
+ const allFiles = findFilesByGlob(location, `./**/${codeExtensions}`, ignore);
251
+ const distFiles = [
252
+ ...findFilesByGlob(location, "./dist/**/*.d.ts"),
253
+ ...findFilesByGlob(location, `./dist/**/${codeExtensions}`)
254
+ ];
255
+ return { allFiles, distFiles };
241
256
  }
242
257
 
243
258
  // src/actions/deplint/getDependenciesFromPackageJson.ts
244
- import fs from "fs";
259
+ import fs2 from "fs";
245
260
  import path from "path";
246
261
  function getDependenciesFromPackageJson(packageJsonPath) {
247
262
  const packageJsonFullPath = path.resolve(packageJsonPath);
248
- const rawContent = fs.readFileSync(packageJsonFullPath, "utf8");
263
+ const rawContent = fs2.readFileSync(packageJsonFullPath, "utf8");
249
264
  const packageJson = JSON.parse(rawContent);
250
265
  const dependencies = packageJson.dependencies ? Object.keys(packageJson.dependencies) : [];
251
266
  const devDependencies = packageJson.devDependencies ? Object.keys(packageJson.devDependencies) : [];
@@ -258,7 +273,7 @@ function getDependenciesFromPackageJson(packageJsonPath) {
258
273
  }
259
274
 
260
275
  // src/actions/deplint/getExtendsFromTsconfigs.ts
261
- import fs2 from "fs";
276
+ import fs3 from "fs";
262
277
  import { globSync as globSync2 } from "glob";
263
278
 
264
279
  // src/actions/deplint/getBasePackageName.ts
@@ -283,7 +298,7 @@ function getExtendsFromTsconfigs(location) {
283
298
  const packages = /* @__PURE__ */ new Set();
284
299
  for (const file of tsconfigFiles) {
285
300
  try {
286
- const content = fs2.readFileSync(file, "utf8");
301
+ const content = fs3.readFileSync(file, "utf8");
287
302
  const cleaned = content.replaceAll(/\/\/.*/g, "").replaceAll(/,\s*([}\]])/g, "$1");
288
303
  const parsed = JSON.parse(cleaned);
289
304
  const refs = parseExtendsField(parsed.extends);
@@ -299,7 +314,7 @@ function getExtendsFromTsconfigs(location) {
299
314
  }
300
315
 
301
316
  // src/actions/deplint/getImportsFromFile.ts
302
- import fs3 from "fs";
317
+ import fs4 from "fs";
303
318
  import path2 from "path";
304
319
  import ts from "typescript";
305
320
  function isTypeOnlyImportClause(clause) {
@@ -314,7 +329,7 @@ function isTypeOnlyImportClause(clause) {
314
329
  return clause.isTypeOnly;
315
330
  }
316
331
  function getImportsFromFile(filePath, importPaths, typeImportPaths) {
317
- const sourceCode = fs3.readFileSync(filePath, "utf8");
332
+ const sourceCode = fs4.readFileSync(filePath, "utf8");
318
333
  const isMjsFile = filePath.endsWith(".mjs");
319
334
  const sourceFile = ts.createSourceFile(
320
335
  path2.basename(filePath),
@@ -325,14 +340,14 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
325
340
  );
326
341
  const imports = [];
327
342
  const typeImports = [];
328
- const isDeclarationFile = filePath.endsWith(".d.ts");
343
+ const isDeclarationFile2 = filePath.endsWith(".d.ts");
329
344
  function visit(node) {
330
345
  if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
331
346
  const moduleSpecifier = node.moduleSpecifier?.getFullText();
332
347
  const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
333
348
  if (typeof moduleSpecifier === "string") {
334
349
  const trimmed = moduleSpecifier.replaceAll("'", "").replaceAll('"', "").trim();
335
- if (isTypeImport || isDeclarationFile) {
350
+ if (isTypeImport || isDeclarationFile2) {
336
351
  typeImports.push(trimmed);
337
352
  } else {
338
353
  imports.push(trimmed);
@@ -367,41 +382,34 @@ var internalImportPrefixes = [".", "#", "node:"];
367
382
  var removeInternalImports = (imports) => {
368
383
  return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
369
384
  };
385
+ var isDeclarationFile = (file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts");
370
386
  function getExternalImportsFromFiles({
371
- srcFiles,
387
+ allFiles,
372
388
  distFiles,
373
- configFiles = [],
374
389
  tsconfigExtends = []
375
390
  }) {
376
- const srcImportPaths = {};
391
+ const allImportPaths = {};
377
392
  const distImportPaths = {};
378
393
  const distTypeImportPaths = {};
379
- const configImportPaths = {};
380
- for (const path5 of srcFiles) getImportsFromFile(path5, srcImportPaths, srcImportPaths).flat();
381
- for (const path5 of configFiles) getImportsFromFile(path5, configImportPaths, configImportPaths).flat();
382
- const distTypeFiles = distFiles.filter((file) => file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts"));
383
- const distCodeFiles = distFiles.filter((file) => !(file.endsWith(".d.ts") || file.endsWith(".d.cts") || file.endsWith(".d.mts")));
394
+ for (const path5 of allFiles) getImportsFromFile(path5, allImportPaths, allImportPaths).flat();
395
+ const distTypeFiles = distFiles.filter(isDeclarationFile);
396
+ const distCodeFiles = distFiles.filter((file) => !isDeclarationFile(file));
384
397
  for (const path5 of distCodeFiles) getImportsFromFile(path5, distImportPaths, distImportPaths).flat();
385
398
  for (const path5 of distTypeFiles) getImportsFromFile(path5, distTypeImportPaths, distTypeImportPaths).flat();
386
- const srcImports = Object.keys(srcImportPaths);
399
+ const allImports = Object.keys(allImportPaths);
387
400
  const distImports = Object.keys(distImportPaths);
388
- const distTypeImports = Object.keys(distTypeImportPaths);
389
- const externalSrcImports = removeInternalImports(srcImports);
401
+ const externalAllImports = removeInternalImports(allImports);
390
402
  const externalDistImports = removeInternalImports(distImports);
391
- const externalDistTypeImports = removeInternalImports(distTypeImports);
392
- const externalConfigImports = removeInternalImports(Object.keys(configImportPaths));
403
+ const externalDistTypeImports = removeInternalImports(Object.keys(distTypeImportPaths));
393
404
  for (const ext of tsconfigExtends) {
394
- if (!externalSrcImports.includes(ext)) externalSrcImports.push(ext);
395
- if (!externalConfigImports.includes(ext)) externalConfigImports.push(ext);
405
+ if (!externalAllImports.includes(ext)) externalAllImports.push(ext);
396
406
  }
397
407
  return {
398
- configImportPaths,
399
- srcImports,
400
- srcImportPaths,
401
- externalConfigImports,
402
- externalSrcImports,
403
- distImports,
408
+ allImportPaths,
409
+ allImports,
404
410
  distImportPaths,
411
+ distImports,
412
+ externalAllImports,
405
413
  externalDistImports,
406
414
  externalDistTypeImports
407
415
  };
@@ -453,17 +461,17 @@ function getUnlistedDevDependencies({ name, location }, {
453
461
  dependencies,
454
462
  peerDependencies
455
463
  }, {
456
- srcImportPaths,
457
- externalSrcImports,
464
+ allImportPaths,
465
+ externalAllImports,
458
466
  distImports
459
467
  }) {
460
468
  let unlistedDevDependencies = 0;
461
- for (const imp of externalSrcImports) {
469
+ for (const imp of externalAllImports) {
462
470
  if (!distImports.includes(imp) && imp !== name && !dependencies.includes(imp) && !dependencies.includes(`@types/${imp}`) && !peerDependencies.includes(imp) && !peerDependencies.includes(`@types/${imp}`) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`) && !builtinModules2.includes(imp)) {
463
471
  unlistedDevDependencies++;
464
472
  console.log(`[${chalk6.blue(name)}] Missing devDependency in package.json: ${chalk6.red(imp)}`);
465
- if (srcImportPaths[imp]) {
466
- console.log(` ${srcImportPaths[imp].join("\n ")}`);
473
+ if (allImportPaths[imp]) {
474
+ console.log(` ${allImportPaths[imp].join("\n ")}`);
467
475
  }
468
476
  }
469
477
  }
@@ -480,13 +488,13 @@ import chalk7 from "chalk";
480
488
  function getUnusedDependencies({ name, location }, { dependencies }, {
481
489
  externalDistImports,
482
490
  externalDistTypeImports,
483
- externalSrcImports
491
+ externalAllImports
484
492
  }) {
485
493
  let unusedDependencies = 0;
486
494
  for (const dep of dependencies) {
487
495
  if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
488
496
  unusedDependencies++;
489
- if (externalSrcImports.includes(dep)) {
497
+ if (externalAllImports.includes(dep)) {
490
498
  console.log(`[${chalk7.blue(name)}] dependency should be devDependency in package.json: ${chalk7.red(dep)}`);
491
499
  } else {
492
500
  console.log(`[${chalk7.blue(name)}] Unused dependency in package.json: ${chalk7.red(dep)}`);
@@ -505,13 +513,13 @@ function getUnusedDependencies({ name, location }, { dependencies }, {
505
513
  import chalk8 from "chalk";
506
514
 
507
515
  // src/actions/deplint/getRequiredPeerDependencies.ts
508
- import fs4 from "fs";
516
+ import fs5 from "fs";
509
517
  import path3 from "path";
510
518
  function findDepPackageJson(location, dep) {
511
519
  let dir = location;
512
520
  while (true) {
513
521
  const candidate = path3.join(dir, "node_modules", dep, "package.json");
514
- if (fs4.existsSync(candidate)) return candidate;
522
+ if (fs5.existsSync(candidate)) return candidate;
515
523
  const parent = path3.dirname(dir);
516
524
  if (parent === dir) return void 0;
517
525
  dir = parent;
@@ -523,7 +531,7 @@ function getRequiredPeerDependencies(location, allDeps) {
523
531
  const depPkgPath = findDepPackageJson(location, dep);
524
532
  if (!depPkgPath) continue;
525
533
  try {
526
- const raw = fs4.readFileSync(depPkgPath, "utf8");
534
+ const raw = fs5.readFileSync(depPkgPath, "utf8");
527
535
  const pkg = JSON.parse(raw);
528
536
  if (pkg.peerDependencies) {
529
537
  for (const peer of Object.keys(pkg.peerDependencies)) {
@@ -537,13 +545,13 @@ function getRequiredPeerDependencies(location, allDeps) {
537
545
  }
538
546
 
539
547
  // src/actions/deplint/getScriptReferencedPackages.ts
540
- import fs5 from "fs";
548
+ import fs6 from "fs";
541
549
  import path4 from "path";
542
550
  function getBinNames(location, dep) {
543
551
  const depPkgPath = findDepPackageJson(location, dep);
544
552
  if (!depPkgPath) return [];
545
553
  try {
546
- const raw = fs5.readFileSync(depPkgPath, "utf8");
554
+ const raw = fs6.readFileSync(depPkgPath, "utf8");
547
555
  const pkg = JSON.parse(raw);
548
556
  if (!pkg.bin) return [];
549
557
  if (typeof pkg.bin === "string") return [pkg.name?.split("/").pop() ?? dep];
@@ -559,7 +567,7 @@ function getScriptReferencedPackages(location, allDeps) {
559
567
  const pkgPath = path4.join(location, "package.json");
560
568
  let scripts = {};
561
569
  try {
562
- const raw = fs5.readFileSync(pkgPath, "utf8");
570
+ const raw = fs6.readFileSync(pkgPath, "utf8");
563
571
  const pkg = JSON.parse(raw);
564
572
  scripts = pkg.scripts ?? {};
565
573
  } catch {
@@ -589,14 +597,14 @@ function getScriptReferencedPackages(location, allDeps) {
589
597
  }
590
598
 
591
599
  // src/actions/deplint/implicitDevDependencies.ts
592
- import fs6 from "fs";
600
+ import fs7 from "fs";
593
601
  var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
594
602
  var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
595
- var hasTypescriptFiles = ({ srcFiles, configFiles }) => hasFileWithExtension([...srcFiles, ...configFiles], tsExtensions);
603
+ var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
596
604
  var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
597
- var hasDecorators = ({ srcFiles }) => srcFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
605
+ var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
598
606
  try {
599
- const content = fs6.readFileSync(file, "utf8");
607
+ const content = fs7.readFileSync(file, "utf8");
600
608
  return decoratorPattern.test(content);
601
609
  } catch {
602
610
  return false;
@@ -609,7 +617,7 @@ function hasImportPlugin({ location, allDependencies }) {
609
617
  const pkgPath = findDepPackageJson(location, dep);
610
618
  if (!pkgPath) continue;
611
619
  try {
612
- const pkg = JSON.parse(fs6.readFileSync(pkgPath, "utf8"));
620
+ const pkg = JSON.parse(fs7.readFileSync(pkgPath, "utf8"));
613
621
  const transitiveDeps = [
614
622
  ...Object.keys(pkg.dependencies ?? {}),
615
623
  ...Object.keys(pkg.peerDependencies ?? {})
@@ -646,18 +654,15 @@ function getImplicitDevDependencies(context) {
646
654
 
647
655
  // src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
648
656
  var allExternalImports = ({
649
- externalSrcImports,
657
+ externalAllImports,
650
658
  externalDistImports,
651
- externalDistTypeImports,
652
- externalConfigImports
659
+ externalDistTypeImports
653
660
  }) => {
654
- const all = /* @__PURE__ */ new Set([
655
- ...externalSrcImports,
661
+ return /* @__PURE__ */ new Set([
662
+ ...externalAllImports,
656
663
  ...externalDistImports,
657
- ...externalDistTypeImports,
658
- ...externalConfigImports
664
+ ...externalDistTypeImports
659
665
  ]);
660
- return all;
661
666
  };
662
667
  function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs) {
663
668
  if (implicitDeps.has(dep)) return true;
@@ -722,18 +727,15 @@ function getUnusedPeerDependencies({ name, location }, { peerDependencies, depen
722
727
  }
723
728
 
724
729
  // src/actions/deplint/checkPackage/checkPackage.ts
725
- function logVerbose(name, location, srcFiles, distFiles, configFiles, tsconfigExtends) {
730
+ function logVerbose(name, location, allFiles, distFiles, tsconfigExtends) {
726
731
  console.info(`Checking package: ${name} at ${location}`);
727
- console.info(`Source files: ${srcFiles.length}, Distribution files: ${distFiles.length}, Config files: ${configFiles.length}`);
728
- for (const file of srcFiles) {
729
- console.info(`Source file: ${file}`);
732
+ console.info(`All files: ${allFiles.length}, Distribution files: ${distFiles.length}`);
733
+ for (const file of allFiles) {
734
+ console.info(`File: ${file}`);
730
735
  }
731
736
  for (const file of distFiles) {
732
737
  console.info(`Distribution file: ${file}`);
733
738
  }
734
- for (const file of configFiles) {
735
- console.info(`Config file: ${file}`);
736
- }
737
739
  for (const ext of tsconfigExtends) {
738
740
  console.info(`Tsconfig extends: ${ext}`);
739
741
  }
@@ -746,33 +748,24 @@ function checkPackage({
746
748
  peerDeps = false,
747
749
  verbose = false
748
750
  }) {
749
- const {
750
- srcFiles,
751
- distFiles,
752
- configFiles
753
- } = findFiles(location);
751
+ const { allFiles, distFiles } = findFiles(location);
754
752
  const tsconfigExtends = getExtendsFromTsconfigs(location);
755
753
  if (verbose) {
756
- logVerbose(name, location, srcFiles, distFiles, configFiles, tsconfigExtends);
754
+ logVerbose(name, location, allFiles, distFiles, tsconfigExtends);
757
755
  }
758
756
  const checkDeps = deps || !(deps || devDeps || peerDeps);
759
757
  const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
760
758
  const checkPeerDeps = peerDeps;
761
759
  const sourceParams = getExternalImportsFromFiles({
762
- srcFiles,
760
+ allFiles,
763
761
  distFiles,
764
- configFiles,
765
762
  tsconfigExtends
766
763
  });
767
764
  const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
768
765
  const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
769
766
  const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0;
770
767
  const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
771
- const fileContext = {
772
- configFiles,
773
- distFiles,
774
- srcFiles
775
- };
768
+ const fileContext = { allFiles, distFiles };
776
769
  const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext) : 0;
777
770
  const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0;
778
771
  const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedDevDependencies + unusedPeerDependencies;