@xylabs/ts-scripts-yarn3 7.4.10 → 7.4.11
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/actions/deplint/checkPackage/checkPackage.mjs +115 -16
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +2 -1
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs +114 -20
- package/dist/actions/deplint/checkPackage/getUnusedDevDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +2 -1
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -1
- package/dist/actions/deplint/checkPackage/index.mjs +115 -16
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -1
- package/dist/actions/deplint/deplint.mjs +166 -38
- package/dist/actions/deplint/deplint.mjs.map +1 -1
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs +140 -0
- package/dist/actions/deplint/getCliReferencedPackagesFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getScriptReferencedPackages.mjs +3 -1
- package/dist/actions/deplint/getScriptReferencedPackages.mjs.map +1 -1
- package/dist/actions/deplint/index.mjs +166 -38
- package/dist/actions/deplint/index.mjs.map +1 -1
- package/dist/actions/index.mjs +147 -40
- package/dist/actions/index.mjs.map +1 -1
- package/dist/bin/xy.mjs +251 -117
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +23 -2
- package/dist/index.mjs +155 -42
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +251 -117
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/xy.mjs +251 -117
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +205 -71
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/xy/xyLintCommands.ts
|
|
2
|
-
import
|
|
2
|
+
import chalk14 from "chalk";
|
|
3
3
|
|
|
4
4
|
// src/lib/checkResult.ts
|
|
5
5
|
import chalk from "chalk";
|
|
@@ -90,25 +90,46 @@ var yarnWorkspace = (pkg) => {
|
|
|
90
90
|
return workspace;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
+
// src/lib/loadConfig.ts
|
|
94
|
+
import chalk3 from "chalk";
|
|
95
|
+
import { cosmiconfig } from "cosmiconfig";
|
|
96
|
+
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
97
|
+
import deepmerge from "deepmerge";
|
|
98
|
+
var config;
|
|
99
|
+
var loadConfig = async (params) => {
|
|
100
|
+
if (config === void 0) {
|
|
101
|
+
const cosmicConfigResult = await cosmiconfig("xy", { cache: true, loaders: { ".ts": TypeScriptLoader() } }).search();
|
|
102
|
+
config = cosmicConfigResult?.config;
|
|
103
|
+
const configFilePath = cosmicConfigResult?.filepath;
|
|
104
|
+
if (configFilePath !== void 0) {
|
|
105
|
+
console.log(chalk3.green(`Loaded config from ${configFilePath}`));
|
|
106
|
+
if (config.verbose) {
|
|
107
|
+
console.log(chalk3.gray(`${JSON.stringify(config, null, 2)}`));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return deepmerge(config, params ?? {});
|
|
112
|
+
};
|
|
113
|
+
|
|
93
114
|
// src/lib/runSteps.ts
|
|
94
115
|
import { spawnSync as spawnSync2 } from "child_process";
|
|
95
116
|
import { existsSync } from "fs";
|
|
96
|
-
import
|
|
117
|
+
import chalk4 from "chalk";
|
|
97
118
|
var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
98
119
|
return safeExit(() => {
|
|
99
120
|
const pkgName = process.env.npm_package_name;
|
|
100
|
-
console.log(
|
|
121
|
+
console.log(chalk4.green(`${name} [${pkgName}]`));
|
|
101
122
|
let totalStatus = 0;
|
|
102
|
-
for (const [i, [command, args,
|
|
123
|
+
for (const [i, [command, args, config2]] of steps.entries()) {
|
|
103
124
|
if (messages?.[i]) {
|
|
104
|
-
console.log(
|
|
125
|
+
console.log(chalk4.gray(messages?.[i]));
|
|
105
126
|
}
|
|
106
127
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
107
128
|
if (command === "node" && !existsSync(argList[0])) {
|
|
108
129
|
throw new Error(`File not found [${argList[0]}]`);
|
|
109
130
|
}
|
|
110
131
|
const status = spawnSync2(command, Array.isArray(args) ? args : args.split(" "), {
|
|
111
|
-
...
|
|
132
|
+
...config2,
|
|
112
133
|
encoding: "utf8",
|
|
113
134
|
env: { FORCE_COLOR: "3", ...process.env },
|
|
114
135
|
shell: true,
|
|
@@ -124,27 +145,27 @@ var runSteps = (name, steps, exitOnFail = true, messages) => {
|
|
|
124
145
|
// src/lib/runStepsAsync.ts
|
|
125
146
|
import { spawn } from "child_process";
|
|
126
147
|
import { existsSync as existsSync2 } from "fs";
|
|
127
|
-
import
|
|
148
|
+
import chalk5 from "chalk";
|
|
128
149
|
var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
129
150
|
return new Promise((resolve) => {
|
|
130
|
-
const [command, args,
|
|
151
|
+
const [command, args, config2] = step;
|
|
131
152
|
if (message) {
|
|
132
|
-
console.log(
|
|
153
|
+
console.log(chalk5.gray(message));
|
|
133
154
|
}
|
|
134
155
|
const argList = Array.isArray(args) ? args : args.split(" ");
|
|
135
156
|
if (command === "node" && !existsSync2(argList[0])) {
|
|
136
157
|
throw new Error(`File not found [${argList[0]}]`);
|
|
137
158
|
}
|
|
138
159
|
spawn(command, Array.isArray(args) ? args : args.split(" "), {
|
|
139
|
-
...
|
|
160
|
+
...config2,
|
|
140
161
|
env: { FORCE_COLOR: "3", ...process.env },
|
|
141
162
|
shell: true,
|
|
142
163
|
stdio: "inherit"
|
|
143
164
|
}).on("close", (code) => {
|
|
144
165
|
if (code) {
|
|
145
166
|
console.error(
|
|
146
|
-
|
|
147
|
-
`Command Exited With Non-Zero Result [${
|
|
167
|
+
chalk5.red(
|
|
168
|
+
`Command Exited With Non-Zero Result [${chalk5.gray(code)}] | ${chalk5.yellow(command)} ${chalk5.white(
|
|
148
169
|
Array.isArray(args) ? args.join(" ") : args
|
|
149
170
|
)}`
|
|
150
171
|
)
|
|
@@ -160,7 +181,7 @@ var runStepAsync = (name, step, exitOnFail = true, message) => {
|
|
|
160
181
|
var runStepsAsync = async (name, steps, exitOnFail = true, messages) => {
|
|
161
182
|
return await safeExitAsync(async () => {
|
|
162
183
|
const pkgName = process.env.npm_package_name;
|
|
163
|
-
console.log(
|
|
184
|
+
console.log(chalk5.green(`${name} [${pkgName}]`));
|
|
164
185
|
let result = 0;
|
|
165
186
|
for (const [i, step] of steps.entries()) {
|
|
166
187
|
result += await runStepAsync(name, step, exitOnFail, messages?.[i]);
|
|
@@ -217,7 +238,7 @@ var cycleAll = async ({ verbose = false }) => {
|
|
|
217
238
|
};
|
|
218
239
|
|
|
219
240
|
// src/actions/deplint/deplint.ts
|
|
220
|
-
import
|
|
241
|
+
import chalk11 from "chalk";
|
|
221
242
|
|
|
222
243
|
// src/actions/deplint/findFiles.ts
|
|
223
244
|
import fs from "fs";
|
|
@@ -393,11 +414,11 @@ function getExternalImportsFromFiles({
|
|
|
393
414
|
const allImportPaths = {};
|
|
394
415
|
const distImportPaths = {};
|
|
395
416
|
const distTypeImportPaths = {};
|
|
396
|
-
for (const
|
|
417
|
+
for (const path6 of allFiles) getImportsFromFile(path6, allImportPaths, allImportPaths).flat();
|
|
397
418
|
const distTypeFiles = distFiles.filter(isDeclarationFile);
|
|
398
419
|
const distCodeFiles = distFiles.filter((file) => !isDeclarationFile(file));
|
|
399
|
-
for (const
|
|
400
|
-
for (const
|
|
420
|
+
for (const path6 of distCodeFiles) getImportsFromFile(path6, distImportPaths, distImportPaths).flat();
|
|
421
|
+
for (const path6 of distTypeFiles) getImportsFromFile(path6, distTypeImportPaths, distTypeImportPaths).flat();
|
|
401
422
|
const allImports = Object.keys(allImportPaths);
|
|
402
423
|
const distImports = Object.keys(distImportPaths);
|
|
403
424
|
const externalAllImports = removeInternalImports(allImports);
|
|
@@ -419,12 +440,12 @@ function getExternalImportsFromFiles({
|
|
|
419
440
|
|
|
420
441
|
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
421
442
|
import { builtinModules } from "module";
|
|
422
|
-
import
|
|
443
|
+
import chalk6 from "chalk";
|
|
423
444
|
function isListedOrBuiltin(imp, name, dependencies, peerDependencies) {
|
|
424
445
|
return dependencies.includes(imp) || imp === name || dependencies.includes(`@types/${imp}`) || peerDependencies.includes(imp) || peerDependencies.includes(`@types/${imp}`) || builtinModules.includes(imp) || builtinModules.includes(`@types/${imp}`);
|
|
425
446
|
}
|
|
426
447
|
function logMissing(name, imp, importPaths) {
|
|
427
|
-
console.log(`[${
|
|
448
|
+
console.log(`[${chalk6.blue(name)}] Missing dependency in package.json: ${chalk6.red(imp)}`);
|
|
428
449
|
if (importPaths[imp]) {
|
|
429
450
|
console.log(` ${importPaths[imp].join("\n ")}`);
|
|
430
451
|
}
|
|
@@ -449,7 +470,7 @@ function getUnlistedDependencies({ name, location }, { dependencies, peerDepende
|
|
|
449
470
|
}
|
|
450
471
|
if (unlistedDependencies > 0) {
|
|
451
472
|
const packageLocation = `${location}/package.json`;
|
|
452
|
-
console.log(` ${
|
|
473
|
+
console.log(` ${chalk6.yellow(packageLocation)}
|
|
453
474
|
`);
|
|
454
475
|
}
|
|
455
476
|
return unlistedDependencies;
|
|
@@ -457,7 +478,7 @@ function getUnlistedDependencies({ name, location }, { dependencies, peerDepende
|
|
|
457
478
|
|
|
458
479
|
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
459
480
|
import { builtinModules as builtinModules2 } from "module";
|
|
460
|
-
import
|
|
481
|
+
import chalk7 from "chalk";
|
|
461
482
|
function getUnlistedDevDependencies({ name, location }, {
|
|
462
483
|
devDependencies,
|
|
463
484
|
dependencies,
|
|
@@ -471,7 +492,7 @@ function getUnlistedDevDependencies({ name, location }, {
|
|
|
471
492
|
for (const imp of externalAllImports) {
|
|
472
493
|
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)) {
|
|
473
494
|
unlistedDevDependencies++;
|
|
474
|
-
console.log(`[${
|
|
495
|
+
console.log(`[${chalk7.blue(name)}] Missing devDependency in package.json: ${chalk7.red(imp)}`);
|
|
475
496
|
if (allImportPaths[imp]) {
|
|
476
497
|
console.log(` ${allImportPaths[imp].join("\n ")}`);
|
|
477
498
|
}
|
|
@@ -479,40 +500,50 @@ function getUnlistedDevDependencies({ name, location }, {
|
|
|
479
500
|
}
|
|
480
501
|
if (unlistedDevDependencies > 0) {
|
|
481
502
|
const packageLocation = `${location}/package.json`;
|
|
482
|
-
console.log(` ${
|
|
503
|
+
console.log(` ${chalk7.yellow(packageLocation)}
|
|
483
504
|
`);
|
|
484
505
|
}
|
|
485
506
|
return unlistedDevDependencies;
|
|
486
507
|
}
|
|
487
508
|
|
|
488
509
|
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
489
|
-
import
|
|
510
|
+
import chalk8 from "chalk";
|
|
490
511
|
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
491
512
|
externalDistImports,
|
|
492
513
|
externalDistTypeImports,
|
|
493
514
|
externalAllImports
|
|
494
|
-
}) {
|
|
515
|
+
}, exclude) {
|
|
495
516
|
let unusedDependencies = 0;
|
|
496
517
|
for (const dep of dependencies) {
|
|
518
|
+
if (exclude?.has(dep)) continue;
|
|
497
519
|
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
498
520
|
unusedDependencies++;
|
|
499
521
|
if (externalAllImports.includes(dep)) {
|
|
500
|
-
console.log(`[${
|
|
522
|
+
console.log(`[${chalk8.blue(name)}] dependency should be devDependency in package.json: ${chalk8.red(dep)}`);
|
|
501
523
|
} else {
|
|
502
|
-
console.log(`[${
|
|
524
|
+
console.log(`[${chalk8.blue(name)}] Unused dependency in package.json: ${chalk8.red(dep)}`);
|
|
503
525
|
}
|
|
504
526
|
}
|
|
505
527
|
}
|
|
506
528
|
if (unusedDependencies > 0) {
|
|
507
529
|
const packageLocation = `${location}/package.json`;
|
|
508
|
-
console.log(` ${
|
|
530
|
+
console.log(` ${chalk8.yellow(packageLocation)}
|
|
509
531
|
`);
|
|
510
532
|
}
|
|
511
533
|
return unusedDependencies;
|
|
512
534
|
}
|
|
513
535
|
|
|
514
536
|
// src/actions/deplint/checkPackage/getUnusedDevDependencies.ts
|
|
515
|
-
import
|
|
537
|
+
import chalk9 from "chalk";
|
|
538
|
+
|
|
539
|
+
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
540
|
+
import fs7 from "fs";
|
|
541
|
+
import path5 from "path";
|
|
542
|
+
import ts2 from "typescript";
|
|
543
|
+
|
|
544
|
+
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
545
|
+
import fs6 from "fs";
|
|
546
|
+
import path4 from "path";
|
|
516
547
|
|
|
517
548
|
// src/actions/deplint/getRequiredPeerDependencies.ts
|
|
518
549
|
import fs5 from "fs";
|
|
@@ -547,8 +578,6 @@ function getRequiredPeerDependencies(location, allDeps) {
|
|
|
547
578
|
}
|
|
548
579
|
|
|
549
580
|
// src/actions/deplint/getScriptReferencedPackages.ts
|
|
550
|
-
import fs6 from "fs";
|
|
551
|
-
import path4 from "path";
|
|
552
581
|
function getBinNames(location, dep) {
|
|
553
582
|
const depPkgPath = findDepPackageJson(location, dep);
|
|
554
583
|
if (!depPkgPath) return [];
|
|
@@ -598,15 +627,101 @@ function getScriptReferencedPackages(location, allDeps) {
|
|
|
598
627
|
return referenced;
|
|
599
628
|
}
|
|
600
629
|
|
|
630
|
+
// src/actions/deplint/getCliReferencedPackagesFromFiles.ts
|
|
631
|
+
var shellCommandFunctions = /* @__PURE__ */ new Set(["execSync", "exec"]);
|
|
632
|
+
var directExecFunctions = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
633
|
+
var allExecFunctions = /* @__PURE__ */ new Set([...shellCommandFunctions, ...directExecFunctions]);
|
|
634
|
+
function getCommandTokensFromFile(filePath) {
|
|
635
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
636
|
+
let sourceCode;
|
|
637
|
+
try {
|
|
638
|
+
sourceCode = fs7.readFileSync(filePath, "utf8");
|
|
639
|
+
} catch {
|
|
640
|
+
return tokens;
|
|
641
|
+
}
|
|
642
|
+
const isMjsFile = filePath.endsWith(".mjs");
|
|
643
|
+
const sourceFile = ts2.createSourceFile(
|
|
644
|
+
path5.basename(filePath),
|
|
645
|
+
sourceCode,
|
|
646
|
+
ts2.ScriptTarget.Latest,
|
|
647
|
+
true,
|
|
648
|
+
isMjsFile ? ts2.ScriptKind.JS : void 0
|
|
649
|
+
);
|
|
650
|
+
function visit(node) {
|
|
651
|
+
if (ts2.isCallExpression(node) && node.arguments.length > 0) {
|
|
652
|
+
const fnName = getFunctionName(node.expression);
|
|
653
|
+
if (fnName && allExecFunctions.has(fnName)) {
|
|
654
|
+
const firstArg = node.arguments[0];
|
|
655
|
+
if (ts2.isStringLiteral(firstArg) || ts2.isNoSubstitutionTemplateLiteral(firstArg)) {
|
|
656
|
+
const value = firstArg.text;
|
|
657
|
+
if (shellCommandFunctions.has(fnName)) {
|
|
658
|
+
for (const token of tokenizeScript(value)) {
|
|
659
|
+
tokens.add(token);
|
|
660
|
+
}
|
|
661
|
+
} else {
|
|
662
|
+
tokens.add(value);
|
|
663
|
+
}
|
|
664
|
+
} else if (ts2.isTemplateExpression(firstArg)) {
|
|
665
|
+
const head = firstArg.head.text;
|
|
666
|
+
if (head) {
|
|
667
|
+
for (const token of tokenizeScript(head)) {
|
|
668
|
+
tokens.add(token);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
ts2.forEachChild(node, visit);
|
|
675
|
+
}
|
|
676
|
+
visit(sourceFile);
|
|
677
|
+
return tokens;
|
|
678
|
+
}
|
|
679
|
+
function getFunctionName(expr) {
|
|
680
|
+
if (ts2.isIdentifier(expr)) {
|
|
681
|
+
return expr.text;
|
|
682
|
+
}
|
|
683
|
+
if (ts2.isPropertyAccessExpression(expr) && ts2.isIdentifier(expr.name)) {
|
|
684
|
+
return expr.name.text;
|
|
685
|
+
}
|
|
686
|
+
return void 0;
|
|
687
|
+
}
|
|
688
|
+
function getCliReferencedPackagesFromFiles(allFiles, location, allDeps) {
|
|
689
|
+
const allTokens = /* @__PURE__ */ new Set();
|
|
690
|
+
for (const file of allFiles) {
|
|
691
|
+
for (const token of getCommandTokensFromFile(file)) {
|
|
692
|
+
allTokens.add(token);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
if (allTokens.size === 0) return /* @__PURE__ */ new Set();
|
|
696
|
+
const binToPackage = /* @__PURE__ */ new Map();
|
|
697
|
+
for (const dep of allDeps) {
|
|
698
|
+
for (const bin of getBinNames(location, dep)) {
|
|
699
|
+
binToPackage.set(bin, dep);
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
const referenced = /* @__PURE__ */ new Set();
|
|
703
|
+
for (const token of allTokens) {
|
|
704
|
+
const baseName = getBasePackageName(token);
|
|
705
|
+
if (allDeps.includes(baseName)) {
|
|
706
|
+
referenced.add(baseName);
|
|
707
|
+
}
|
|
708
|
+
const pkg = binToPackage.get(token);
|
|
709
|
+
if (pkg) {
|
|
710
|
+
referenced.add(pkg);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return referenced;
|
|
714
|
+
}
|
|
715
|
+
|
|
601
716
|
// src/actions/deplint/implicitDevDependencies.ts
|
|
602
|
-
import
|
|
717
|
+
import fs8 from "fs";
|
|
603
718
|
var hasFileWithExtension = (files, extensions) => files.some((f) => extensions.some((ext) => f.endsWith(ext)));
|
|
604
719
|
var tsExtensions = [".ts", ".tsx", ".mts", ".cts"];
|
|
605
720
|
var hasTypescriptFiles = ({ allFiles }) => hasFileWithExtension(allFiles, tsExtensions);
|
|
606
721
|
var decoratorPattern = /^\s*@[a-zA-Z]\w*/m;
|
|
607
722
|
var hasDecorators = ({ allFiles }) => allFiles.filter((f) => tsExtensions.some((ext) => f.endsWith(ext))).some((file) => {
|
|
608
723
|
try {
|
|
609
|
-
const content =
|
|
724
|
+
const content = fs8.readFileSync(file, "utf8");
|
|
610
725
|
return decoratorPattern.test(content);
|
|
611
726
|
} catch {
|
|
612
727
|
return false;
|
|
@@ -619,7 +734,7 @@ function hasImportPlugin({ location, allDependencies }) {
|
|
|
619
734
|
const pkgPath = findDepPackageJson(location, dep);
|
|
620
735
|
if (!pkgPath) continue;
|
|
621
736
|
try {
|
|
622
|
-
const pkg = JSON.parse(
|
|
737
|
+
const pkg = JSON.parse(fs8.readFileSync(pkgPath, "utf8"));
|
|
623
738
|
const transitiveDeps = [
|
|
624
739
|
...Object.keys(pkg.dependencies ?? {}),
|
|
625
740
|
...Object.keys(pkg.peerDependencies ?? {})
|
|
@@ -671,10 +786,11 @@ var allExternalImports = ({
|
|
|
671
786
|
...externalDistTypeImports
|
|
672
787
|
]);
|
|
673
788
|
};
|
|
674
|
-
function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs) {
|
|
789
|
+
function isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs) {
|
|
675
790
|
if (implicitDeps.has(dep)) return true;
|
|
676
791
|
if (requiredPeers.has(dep)) return true;
|
|
677
792
|
if (scriptRefs.has(dep)) return true;
|
|
793
|
+
if (cliRefs.has(dep)) return true;
|
|
678
794
|
if (dep.startsWith("@types/")) {
|
|
679
795
|
const baseName = dep.replace(/^@types\//, "");
|
|
680
796
|
return allImports.has(baseName) || allImports.has(dep) || implicitDeps.has(baseName);
|
|
@@ -685,7 +801,7 @@ function getUnusedDevDependencies({ name, location }, {
|
|
|
685
801
|
devDependencies,
|
|
686
802
|
dependencies,
|
|
687
803
|
peerDependencies
|
|
688
|
-
}, sourceParams, fileContext) {
|
|
804
|
+
}, sourceParams, fileContext, exclude) {
|
|
689
805
|
const allImports = allExternalImports(sourceParams);
|
|
690
806
|
const allDeps = [...dependencies, ...devDependencies, ...peerDependencies];
|
|
691
807
|
const implicitDeps = getImplicitDevDependencies({
|
|
@@ -695,39 +811,42 @@ function getUnusedDevDependencies({ name, location }, {
|
|
|
695
811
|
});
|
|
696
812
|
const requiredPeers = getRequiredPeerDependencies(location, allDeps);
|
|
697
813
|
const scriptRefs = getScriptReferencedPackages(location, allDeps);
|
|
814
|
+
const cliRefs = getCliReferencedPackagesFromFiles(fileContext.allFiles, location, allDeps);
|
|
698
815
|
let unusedDevDependencies = 0;
|
|
699
816
|
for (const dep of devDependencies) {
|
|
817
|
+
if (exclude?.has(dep)) continue;
|
|
700
818
|
if (dependencies.includes(dep) || peerDependencies.includes(dep)) continue;
|
|
701
|
-
if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs)) {
|
|
819
|
+
if (!isDevDepUsed(dep, allImports, implicitDeps, requiredPeers, scriptRefs, cliRefs)) {
|
|
702
820
|
unusedDevDependencies++;
|
|
703
|
-
console.log(`[${
|
|
821
|
+
console.log(`[${chalk9.blue(name)}] Unused devDependency in package.json: ${chalk9.red(dep)}`);
|
|
704
822
|
}
|
|
705
823
|
}
|
|
706
824
|
if (unusedDevDependencies > 0) {
|
|
707
825
|
const packageLocation = `${location}/package.json`;
|
|
708
|
-
console.log(` ${
|
|
826
|
+
console.log(` ${chalk9.yellow(packageLocation)}
|
|
709
827
|
`);
|
|
710
828
|
}
|
|
711
829
|
return unusedDevDependencies;
|
|
712
830
|
}
|
|
713
831
|
|
|
714
832
|
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
715
|
-
import
|
|
716
|
-
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports, externalDistTypeImports }) {
|
|
833
|
+
import chalk10 from "chalk";
|
|
834
|
+
function getUnusedPeerDependencies({ name, location }, { peerDependencies, dependencies }, { externalDistImports, externalDistTypeImports }, exclude) {
|
|
717
835
|
let unusedDependencies = 0;
|
|
718
836
|
for (const dep of peerDependencies) {
|
|
837
|
+
if (exclude?.has(dep)) continue;
|
|
719
838
|
if (!externalDistImports.includes(dep) && !externalDistImports.includes(dep.replace(/^@types\//, "")) && !externalDistTypeImports.includes(dep) && !externalDistTypeImports.includes(dep.replace(/^@types\//, ""))) {
|
|
720
839
|
unusedDependencies++;
|
|
721
840
|
if (dependencies.includes(dep)) {
|
|
722
|
-
console.log(`[${
|
|
841
|
+
console.log(`[${chalk10.blue(name)}] Unused peerDependency [already a dependency] in package.json: ${chalk10.red(dep)}`);
|
|
723
842
|
} else {
|
|
724
|
-
console.log(`[${
|
|
843
|
+
console.log(`[${chalk10.blue(name)}] Unused peerDependency in package.json: ${chalk10.red(dep)}`);
|
|
725
844
|
}
|
|
726
845
|
}
|
|
727
846
|
}
|
|
728
847
|
if (unusedDependencies > 0) {
|
|
729
848
|
const packageLocation = `${location}/package.json`;
|
|
730
|
-
console.log(` ${
|
|
849
|
+
console.log(` ${chalk10.yellow(packageLocation)}
|
|
731
850
|
`);
|
|
732
851
|
}
|
|
733
852
|
return unusedDependencies;
|
|
@@ -752,6 +871,7 @@ function checkPackage({
|
|
|
752
871
|
location,
|
|
753
872
|
deps = false,
|
|
754
873
|
devDeps = false,
|
|
874
|
+
exclude,
|
|
755
875
|
peerDeps = false,
|
|
756
876
|
verbose = false
|
|
757
877
|
}) {
|
|
@@ -770,23 +890,29 @@ function checkPackage({
|
|
|
770
890
|
});
|
|
771
891
|
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
772
892
|
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
773
|
-
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
893
|
+
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
774
894
|
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
775
895
|
const fileContext = { allFiles, distFiles };
|
|
776
|
-
const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext) : 0;
|
|
777
|
-
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
896
|
+
const unusedDevDependencies = checkDevDeps ? getUnusedDevDependencies({ name, location }, packageParams, sourceParams, fileContext, exclude) : 0;
|
|
897
|
+
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams, exclude) : 0;
|
|
778
898
|
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + unusedDevDependencies + unusedPeerDependencies;
|
|
779
899
|
return totalErrors;
|
|
780
900
|
}
|
|
781
901
|
|
|
782
902
|
// src/actions/deplint/deplint.ts
|
|
783
|
-
var deplint = ({
|
|
903
|
+
var deplint = async ({
|
|
784
904
|
pkg,
|
|
785
905
|
deps,
|
|
786
906
|
devDeps,
|
|
787
907
|
peerDeps,
|
|
788
|
-
verbose
|
|
908
|
+
verbose,
|
|
909
|
+
cliExclude
|
|
789
910
|
}) => {
|
|
911
|
+
const config2 = await loadConfig();
|
|
912
|
+
const exclude = /* @__PURE__ */ new Set([
|
|
913
|
+
...config2.deplint?.exclude ?? [],
|
|
914
|
+
...cliExclude ?? []
|
|
915
|
+
]);
|
|
790
916
|
let totalErrors = 0;
|
|
791
917
|
if (pkg === void 0) {
|
|
792
918
|
const workspaces = yarnWorkspaces();
|
|
@@ -796,6 +922,7 @@ var deplint = ({
|
|
|
796
922
|
...workspace,
|
|
797
923
|
deps,
|
|
798
924
|
devDeps,
|
|
925
|
+
exclude,
|
|
799
926
|
peerDeps,
|
|
800
927
|
verbose
|
|
801
928
|
});
|
|
@@ -808,26 +935,27 @@ var deplint = ({
|
|
|
808
935
|
location,
|
|
809
936
|
devDeps,
|
|
810
937
|
deps,
|
|
938
|
+
exclude,
|
|
811
939
|
peerDeps,
|
|
812
940
|
verbose
|
|
813
941
|
});
|
|
814
942
|
}
|
|
815
943
|
if (totalErrors > 0) {
|
|
816
|
-
console.warn(`Deplint: Found ${
|
|
944
|
+
console.warn(`Deplint: Found ${chalk11.red(totalErrors)} dependency problems. ${chalk11.red("\u2716")}`);
|
|
817
945
|
} else {
|
|
818
|
-
console.info(`Deplint: Found no dependency problems. ${
|
|
946
|
+
console.info(`Deplint: Found no dependency problems. ${chalk11.green("\u2714")}`);
|
|
819
947
|
}
|
|
820
948
|
return 0;
|
|
821
949
|
};
|
|
822
950
|
|
|
823
951
|
// src/actions/lint.ts
|
|
824
|
-
import
|
|
952
|
+
import chalk12 from "chalk";
|
|
825
953
|
var lintPackage = ({
|
|
826
954
|
pkg,
|
|
827
955
|
fix: fix2,
|
|
828
956
|
verbose
|
|
829
957
|
}) => {
|
|
830
|
-
console.log(
|
|
958
|
+
console.log(chalk12.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
831
959
|
const start = Date.now();
|
|
832
960
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
833
961
|
["yarn", [
|
|
@@ -837,7 +965,7 @@ var lintPackage = ({
|
|
|
837
965
|
fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
|
|
838
966
|
]]
|
|
839
967
|
]);
|
|
840
|
-
console.log(
|
|
968
|
+
console.log(chalk12.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk12.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk12.gray("seconds")}`));
|
|
841
969
|
return result;
|
|
842
970
|
};
|
|
843
971
|
var lint = ({
|
|
@@ -857,13 +985,13 @@ var lint = ({
|
|
|
857
985
|
});
|
|
858
986
|
};
|
|
859
987
|
var lintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
860
|
-
console.log(
|
|
988
|
+
console.log(chalk12.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
861
989
|
const start = Date.now();
|
|
862
990
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
863
991
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
864
992
|
["yarn", ["eslint", "--cache", "--cache-location", ".eslintcache", "--cache-strategy", "content", ...fixOptions]]
|
|
865
993
|
]);
|
|
866
|
-
console.log(
|
|
994
|
+
console.log(chalk12.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk12.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk12.gray("seconds")}`));
|
|
867
995
|
return result;
|
|
868
996
|
};
|
|
869
997
|
|
|
@@ -890,13 +1018,13 @@ var publintAll = ({ verbose }) => {
|
|
|
890
1018
|
};
|
|
891
1019
|
|
|
892
1020
|
// src/actions/relint.ts
|
|
893
|
-
import
|
|
1021
|
+
import chalk13 from "chalk";
|
|
894
1022
|
var relintPackage = ({
|
|
895
1023
|
pkg,
|
|
896
1024
|
fix: fix2,
|
|
897
1025
|
verbose
|
|
898
1026
|
}) => {
|
|
899
|
-
console.log(
|
|
1027
|
+
console.log(chalk13.gray(`${fix2 ? "Fix" : "Lint"} [${pkg}]`));
|
|
900
1028
|
const start = Date.now();
|
|
901
1029
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [${pkg}]`, [
|
|
902
1030
|
["yarn", [
|
|
@@ -906,7 +1034,7 @@ var relintPackage = ({
|
|
|
906
1034
|
fix2 ? "package-fix" : verbose ? "package-lint-verbose" : "package-lint"
|
|
907
1035
|
]]
|
|
908
1036
|
]);
|
|
909
|
-
console.log(
|
|
1037
|
+
console.log(chalk13.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk13.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk13.gray("seconds")}`));
|
|
910
1038
|
return result;
|
|
911
1039
|
};
|
|
912
1040
|
var relint = ({
|
|
@@ -926,13 +1054,13 @@ var relint = ({
|
|
|
926
1054
|
});
|
|
927
1055
|
};
|
|
928
1056
|
var relintAllPackages = ({ fix: fix2 = false } = {}) => {
|
|
929
|
-
console.log(
|
|
1057
|
+
console.log(chalk13.gray(`${fix2 ? "Fix" : "Lint"} [All-Packages]`));
|
|
930
1058
|
const start = Date.now();
|
|
931
1059
|
const fixOptions = fix2 ? ["--fix"] : [];
|
|
932
1060
|
const result = runSteps(`${fix2 ? "Fix" : "Lint"} [All-Packages]`, [
|
|
933
1061
|
["yarn", ["eslint", ...fixOptions]]
|
|
934
1062
|
]);
|
|
935
|
-
console.log(
|
|
1063
|
+
console.log(chalk13.gray(`${fix2 ? "Fixed in" : "Linted in"} [${chalk13.magenta(((Date.now() - start) / 1e3).toFixed(2))}] ${chalk13.gray("seconds")}`));
|
|
936
1064
|
return result;
|
|
937
1065
|
};
|
|
938
1066
|
|
|
@@ -958,7 +1086,7 @@ var xyLintCommands = (args) => {
|
|
|
958
1086
|
const start = Date.now();
|
|
959
1087
|
if (argv.verbose) console.log("Cycle");
|
|
960
1088
|
process.exitCode = await cycle({ pkg: argv.package });
|
|
961
|
-
console.log(
|
|
1089
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
962
1090
|
}
|
|
963
1091
|
).command(
|
|
964
1092
|
"lint [package]",
|
|
@@ -988,7 +1116,7 @@ var xyLintCommands = (args) => {
|
|
|
988
1116
|
cache: argv.cache,
|
|
989
1117
|
verbose: !!argv.verbose
|
|
990
1118
|
});
|
|
991
|
-
console.log(
|
|
1119
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
992
1120
|
}
|
|
993
1121
|
).command(
|
|
994
1122
|
"deplint [package]",
|
|
@@ -1009,19 +1137,25 @@ var xyLintCommands = (args) => {
|
|
|
1009
1137
|
default: false,
|
|
1010
1138
|
description: "Check peerDependencies",
|
|
1011
1139
|
type: "boolean"
|
|
1140
|
+
}).option("exclude", {
|
|
1141
|
+
alias: "e",
|
|
1142
|
+
description: "Package names to exclude from unused checks (comma-separated or repeated)",
|
|
1143
|
+
type: "array"
|
|
1012
1144
|
});
|
|
1013
1145
|
},
|
|
1014
|
-
(argv) => {
|
|
1146
|
+
async (argv) => {
|
|
1015
1147
|
if (argv.verbose) console.log("Deplint");
|
|
1016
1148
|
const start = Date.now();
|
|
1017
|
-
|
|
1149
|
+
const cliExclude = argv.exclude?.flatMap((v) => String(v).split(",")).map((v) => v.trim()).filter(Boolean);
|
|
1150
|
+
process.exitCode = await deplint({
|
|
1151
|
+
cliExclude,
|
|
1018
1152
|
pkg: argv.package,
|
|
1019
1153
|
deps: !!argv.deps,
|
|
1020
1154
|
devDeps: !!argv.devDeps,
|
|
1021
1155
|
peerDeps: !!argv.peerDeps,
|
|
1022
1156
|
verbose: !!argv.verbose
|
|
1023
1157
|
});
|
|
1024
|
-
console.log(
|
|
1158
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
1025
1159
|
}
|
|
1026
1160
|
).command(
|
|
1027
1161
|
"fix [package]",
|
|
@@ -1033,7 +1167,7 @@ var xyLintCommands = (args) => {
|
|
|
1033
1167
|
const start = Date.now();
|
|
1034
1168
|
if (argv.verbose) console.log("Fix");
|
|
1035
1169
|
process.exitCode = fix();
|
|
1036
|
-
console.log(
|
|
1170
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
1037
1171
|
}
|
|
1038
1172
|
).command(
|
|
1039
1173
|
"relint [package]",
|
|
@@ -1045,7 +1179,7 @@ var xyLintCommands = (args) => {
|
|
|
1045
1179
|
if (argv.verbose) console.log("Relinting");
|
|
1046
1180
|
const start = Date.now();
|
|
1047
1181
|
process.exitCode = relint();
|
|
1048
|
-
console.log(
|
|
1182
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
1049
1183
|
}
|
|
1050
1184
|
).command(
|
|
1051
1185
|
"publint [package]",
|
|
@@ -1057,7 +1191,7 @@ var xyLintCommands = (args) => {
|
|
|
1057
1191
|
if (argv.verbose) console.log("Publint");
|
|
1058
1192
|
const start = Date.now();
|
|
1059
1193
|
process.exitCode = await publint({ pkg: argv.package, verbose: !!argv.verbose });
|
|
1060
|
-
console.log(
|
|
1194
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
1061
1195
|
}
|
|
1062
1196
|
).command(
|
|
1063
1197
|
"knip",
|
|
@@ -1069,7 +1203,7 @@ var xyLintCommands = (args) => {
|
|
|
1069
1203
|
if (argv.verbose) console.log("Knip");
|
|
1070
1204
|
const start = Date.now();
|
|
1071
1205
|
process.exitCode = knip();
|
|
1072
|
-
console.log(
|
|
1206
|
+
console.log(chalk14.blue(`Knip finished in ${Date.now() - start}ms`));
|
|
1073
1207
|
}
|
|
1074
1208
|
).command(
|
|
1075
1209
|
"sonar",
|
|
@@ -1081,7 +1215,7 @@ var xyLintCommands = (args) => {
|
|
|
1081
1215
|
const start = Date.now();
|
|
1082
1216
|
if (argv.verbose) console.log("Sonar Check");
|
|
1083
1217
|
process.exitCode = sonar();
|
|
1084
|
-
console.log(
|
|
1218
|
+
console.log(chalk14.blue(`Finished in ${Date.now() - start}ms`));
|
|
1085
1219
|
}
|
|
1086
1220
|
);
|
|
1087
1221
|
};
|