@xylabs/ts-scripts-yarn3 6.5.0 → 6.5.1
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 +256 -0
- package/dist/actions/deplint/checkPackage/checkPackage.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs +1 -0
- package/dist/actions/deplint/checkPackage/checkPackageTypes.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getTypesInDependencies.mjs +19 -0
- package/dist/actions/deplint/checkPackage/getTypesInDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs +35 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs +17 -0
- package/dist/actions/deplint/checkPackage/getUnlistedDevDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs +22 -0
- package/dist/actions/deplint/checkPackage/getUnusedDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs +19 -0
- package/dist/actions/deplint/checkPackage/getUnusedPeerDependencies.mjs.map +1 -0
- package/dist/actions/deplint/checkPackage/index.mjs +256 -0
- package/dist/actions/deplint/checkPackage/index.mjs.map +1 -0
- package/dist/actions/deplint/deplint.mjs +316 -0
- package/dist/actions/deplint/deplint.mjs.map +1 -0
- package/dist/actions/deplint/findFiles.mjs +24 -0
- package/dist/actions/deplint/findFiles.mjs.map +1 -0
- package/dist/actions/deplint/findFilesByGlob.mjs +9 -0
- package/dist/actions/deplint/findFilesByGlob.mjs.map +1 -0
- package/dist/actions/deplint/getBasePackageName.mjs +12 -0
- package/dist/actions/deplint/getBasePackageName.mjs.map +1 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs +20 -0
- package/dist/actions/deplint/getDependenciesFromPackageJson.mjs.map +1 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs +98 -0
- package/dist/actions/deplint/getExternalImportsFromFiles.mjs.map +1 -0
- package/dist/actions/deplint/getImportsFromFile.mjs +65 -0
- package/dist/actions/deplint/getImportsFromFile.mjs.map +1 -0
- package/dist/actions/{deplint.mjs → deplint/index.mjs} +160 -87
- package/dist/actions/deplint/index.mjs.map +1 -0
- package/dist/actions/fix.mjs.map +1 -1
- package/dist/actions/index.mjs +235 -160
- package/dist/actions/index.mjs.map +1 -1
- package/dist/actions/lint.mjs.map +1 -1
- package/dist/bin/xy.mjs +239 -155
- package/dist/bin/xy.mjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +282 -198
- package/dist/index.mjs.map +1 -1
- package/dist/xy/index.mjs +239 -155
- package/dist/xy/index.mjs.map +1 -1
- package/dist/xy/param.mjs +1 -1
- package/dist/xy/param.mjs.map +1 -1
- package/dist/xy/xy.mjs +239 -155
- package/dist/xy/xy.mjs.map +1 -1
- package/dist/xy/xyCommonCommands.mjs +1 -1
- package/dist/xy/xyCommonCommands.mjs.map +1 -1
- package/dist/xy/xyLintCommands.mjs +212 -107
- package/dist/xy/xyLintCommands.mjs.map +1 -1
- package/dist/xy/xyParseOptions.mjs +0 -21
- package/dist/xy/xyParseOptions.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/actions/deplint.mjs.map +0 -1
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
// src/actions/deplint.ts
|
|
2
|
-
import
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import { globSync } from "glob";
|
|
6
|
-
import ts from "typescript";
|
|
1
|
+
// src/actions/deplint/deplint.ts
|
|
2
|
+
import chalk6 from "chalk";
|
|
7
3
|
|
|
8
4
|
// src/lib/yarn/workspace/yarnWorkspaces.ts
|
|
9
5
|
import { spawnSync } from "node:child_process";
|
|
@@ -24,7 +20,30 @@ var yarnWorkspace = (pkg) => {
|
|
|
24
20
|
return workspace;
|
|
25
21
|
};
|
|
26
22
|
|
|
27
|
-
// src/actions/deplint.ts
|
|
23
|
+
// src/actions/deplint/findFilesByGlob.ts
|
|
24
|
+
import { globSync } from "glob";
|
|
25
|
+
function findFilesByGlob(cwd, pattern) {
|
|
26
|
+
return globSync(pattern, { cwd, absolute: true });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// src/actions/deplint/findFiles.ts
|
|
30
|
+
function findFiles(path3) {
|
|
31
|
+
const allSourceInclude = ["./src/**/*.{ts,tsx}", "./dist/**/*.d.ts"];
|
|
32
|
+
const prodExcludeEndswith = [".spec.ts", ".stories.tsx"];
|
|
33
|
+
const prodExcludeIncludes = ["/spec/", "/stories/", "/scripts/"];
|
|
34
|
+
const allSourceFiles = allSourceInclude.flatMap((pattern) => findFilesByGlob(path3, pattern));
|
|
35
|
+
const prodSourceFiles = allSourceFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
36
|
+
const devSourceFiles = allSourceFiles.filter((file) => !prodSourceFiles.includes(file));
|
|
37
|
+
return {
|
|
38
|
+
allSourceFiles,
|
|
39
|
+
prodSourceFiles,
|
|
40
|
+
devSourceFiles
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/actions/deplint/getDependenciesFromPackageJson.ts
|
|
45
|
+
import fs from "node:fs";
|
|
46
|
+
import path from "node:path";
|
|
28
47
|
function getDependenciesFromPackageJson(packageJsonPath) {
|
|
29
48
|
const packageJsonFullPath = path.resolve(packageJsonPath);
|
|
30
49
|
const rawContent = fs.readFileSync(packageJsonFullPath, "utf8");
|
|
@@ -38,6 +57,13 @@ function getDependenciesFromPackageJson(packageJsonPath) {
|
|
|
38
57
|
peerDependencies
|
|
39
58
|
};
|
|
40
59
|
}
|
|
60
|
+
|
|
61
|
+
// src/actions/deplint/getImportsFromFile.ts
|
|
62
|
+
import fs2 from "node:fs";
|
|
63
|
+
import path2 from "node:path";
|
|
64
|
+
import ts from "typescript";
|
|
65
|
+
|
|
66
|
+
// src/actions/deplint/getBasePackageName.ts
|
|
41
67
|
function getBasePackageName(importName) {
|
|
42
68
|
if (importName.startsWith("@")) {
|
|
43
69
|
const parts = importName.split("/");
|
|
@@ -45,10 +71,12 @@ function getBasePackageName(importName) {
|
|
|
45
71
|
}
|
|
46
72
|
return importName.split("/")[0];
|
|
47
73
|
}
|
|
74
|
+
|
|
75
|
+
// src/actions/deplint/getImportsFromFile.ts
|
|
48
76
|
function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
49
|
-
const sourceCode =
|
|
77
|
+
const sourceCode = fs2.readFileSync(filePath, "utf8");
|
|
50
78
|
const sourceFile = ts.createSourceFile(
|
|
51
|
-
|
|
79
|
+
path2.basename(filePath),
|
|
52
80
|
sourceCode,
|
|
53
81
|
ts.ScriptTarget.Latest,
|
|
54
82
|
true
|
|
@@ -91,36 +119,26 @@ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
|
|
|
91
119
|
}
|
|
92
120
|
return [cleanedImports, cleanedTypeImports];
|
|
93
121
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const prodExcludeIncludes = ["/spec/", "/stories/", "/scripts/"];
|
|
101
|
-
const allSourceFiles = allSourceInclude.flatMap((pattern) => findFilesByGlob(path2, pattern));
|
|
102
|
-
const prodSourceFiles = allSourceFiles.filter((file) => !prodExcludeEndswith.some((ext) => file.endsWith(ext)) && !prodExcludeIncludes.some((excl) => file.includes(excl)));
|
|
103
|
-
const devSourceFiles = allSourceFiles.filter((file) => !prodSourceFiles.includes(file));
|
|
104
|
-
return {
|
|
105
|
-
allSourceFiles,
|
|
106
|
-
prodSourceFiles,
|
|
107
|
-
devSourceFiles
|
|
108
|
-
};
|
|
109
|
-
}
|
|
122
|
+
|
|
123
|
+
// src/actions/deplint/getExternalImportsFromFiles.ts
|
|
124
|
+
var internalImportPrefixes = [".", "#", "node:"];
|
|
125
|
+
var removeInternalImports = (imports) => {
|
|
126
|
+
return imports.filter((imp) => !internalImportPrefixes.some((prefix) => imp.startsWith(prefix)));
|
|
127
|
+
};
|
|
110
128
|
function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
111
129
|
const prodImportPaths = {};
|
|
112
130
|
const prodTypeImportPaths = {};
|
|
113
|
-
const prodImportPairs = prodSourceFiles.map((
|
|
131
|
+
const prodImportPairs = prodSourceFiles.map((path3) => getImportsFromFile(path3, prodImportPaths, prodTypeImportPaths));
|
|
114
132
|
const prodImports = prodImportPairs.flatMap((pair) => pair[0]);
|
|
115
133
|
const prodTypeImports = prodImportPairs.flatMap((pair) => pair[1]);
|
|
116
134
|
const devImportPaths = {};
|
|
117
135
|
const devTypeImportPaths = {};
|
|
118
|
-
const devImportPairs = devSourceFiles.map((
|
|
136
|
+
const devImportPairs = devSourceFiles.map((path3) => getImportsFromFile(path3, devImportPaths, devTypeImportPaths));
|
|
119
137
|
const devImports = devImportPairs.flatMap((pair) => pair[0]);
|
|
120
138
|
const devTypeImports = devImportPairs.flatMap((pair) => pair[1]);
|
|
121
|
-
const externalProdImports = prodImports
|
|
122
|
-
const externalProdTypeImports = prodTypeImports
|
|
123
|
-
const externalDevImports = devImports
|
|
139
|
+
const externalProdImports = removeInternalImports(prodImports);
|
|
140
|
+
const externalProdTypeImports = removeInternalImports(prodTypeImports);
|
|
141
|
+
const externalDevImports = removeInternalImports(devImports);
|
|
124
142
|
return {
|
|
125
143
|
prodImports,
|
|
126
144
|
devImports,
|
|
@@ -134,34 +152,40 @@ function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }) {
|
|
|
134
152
|
externalProdTypeImports
|
|
135
153
|
};
|
|
136
154
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
155
|
+
|
|
156
|
+
// src/actions/deplint/checkPackage/getTypesInDependencies.ts
|
|
157
|
+
import chalk from "chalk";
|
|
158
|
+
function getTypesInDependencies({ name, location }, { dependencies }, {}) {
|
|
159
|
+
let typesInDependencies = 0;
|
|
160
|
+
for (const dep of dependencies) {
|
|
161
|
+
if (dep.startsWith("@types/")) {
|
|
162
|
+
typesInDependencies++;
|
|
163
|
+
console.log(`[${chalk.blue(name)}] @types in dependencies in package.json: ${chalk.red(dep)}`);
|
|
164
|
+
console.log(` ${location}/package.json
|
|
165
|
+
`);
|
|
166
|
+
console.log("");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return typesInDependencies;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/actions/deplint/checkPackage/getUnlistedDependencies.ts
|
|
173
|
+
import chalk2 from "chalk";
|
|
174
|
+
function getUnlistedDependencies({ name }, {
|
|
175
|
+
dependencies,
|
|
176
|
+
devDependencies,
|
|
177
|
+
peerDependencies
|
|
178
|
+
}, {
|
|
179
|
+
externalProdTypeImports,
|
|
180
|
+
prodTypeImportPaths,
|
|
181
|
+
externalProdImports,
|
|
182
|
+
prodImportPaths
|
|
142
183
|
}) {
|
|
143
|
-
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
144
|
-
const {
|
|
145
|
-
prodTypeImportPaths,
|
|
146
|
-
prodImportPaths,
|
|
147
|
-
externalProdTypeImports,
|
|
148
|
-
devImportPaths,
|
|
149
|
-
externalProdImports,
|
|
150
|
-
externalDevImports
|
|
151
|
-
} = getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles });
|
|
152
|
-
const {
|
|
153
|
-
dependencies,
|
|
154
|
-
devDependencies,
|
|
155
|
-
peerDependencies
|
|
156
|
-
} = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
157
184
|
let unlistedDependencies = 0;
|
|
158
|
-
let unlistedDevDependencies = 0;
|
|
159
|
-
let unusedDependencies = 0;
|
|
160
|
-
let typesInDependencies = 0;
|
|
161
185
|
for (const imp of externalProdTypeImports) {
|
|
162
186
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`)) {
|
|
163
187
|
unlistedDependencies++;
|
|
164
|
-
console.log(`[${
|
|
188
|
+
console.log(`[${chalk2.blue(name)}] Missing dependency in package.json: ${chalk2.red(imp)}`);
|
|
165
189
|
console.log(` ${prodTypeImportPaths[imp].join("\n")}`);
|
|
166
190
|
console.log("");
|
|
167
191
|
}
|
|
@@ -169,70 +193,119 @@ function check({
|
|
|
169
193
|
for (const imp of externalProdImports) {
|
|
170
194
|
if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {
|
|
171
195
|
unlistedDependencies++;
|
|
172
|
-
console.log(`[${
|
|
196
|
+
console.log(`[${chalk2.blue(name)}] Missing dependency in package.json: ${chalk2.red(imp)}`);
|
|
173
197
|
console.log(` ${prodImportPaths[imp].join("\n")}`);
|
|
174
198
|
console.log("");
|
|
175
199
|
}
|
|
176
200
|
}
|
|
201
|
+
return unlistedDependencies;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts
|
|
205
|
+
import chalk3 from "chalk";
|
|
206
|
+
function getUnlistedDevDependencies({ name }, { devDependencies }, { devImportPaths, externalDevImports }) {
|
|
207
|
+
let unlistedDevDependencies = 0;
|
|
208
|
+
for (const imp of externalDevImports) {
|
|
209
|
+
if (!devDependencies.includes(imp)) {
|
|
210
|
+
unlistedDevDependencies++;
|
|
211
|
+
console.log(`[${chalk3.blue(name)}] Missing devDependency in package.json: ${chalk3.red(imp)}`);
|
|
212
|
+
console.log(` Found in: ${devImportPaths[imp].join(", ")}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return unlistedDevDependencies;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/actions/deplint/checkPackage/getUnusedDependencies.ts
|
|
219
|
+
import chalk4 from "chalk";
|
|
220
|
+
function getUnusedDependencies({ name, location }, { dependencies }, {
|
|
221
|
+
externalProdImports,
|
|
222
|
+
externalProdTypeImports
|
|
223
|
+
}) {
|
|
224
|
+
let unusedDependencies = 0;
|
|
177
225
|
for (const dep of dependencies) {
|
|
178
|
-
if (dep.
|
|
179
|
-
|
|
180
|
-
console.log(`[${
|
|
226
|
+
if (!externalProdImports.includes(dep) && !externalProdTypeImports.includes(dep)) {
|
|
227
|
+
unusedDependencies++;
|
|
228
|
+
console.log(`[${chalk4.blue(name)}] Unused dependency in package.json: ${chalk4.red(dep)}`);
|
|
181
229
|
console.log(` ${location}/package.json
|
|
182
230
|
`);
|
|
183
231
|
console.log("");
|
|
184
232
|
}
|
|
185
|
-
|
|
233
|
+
}
|
|
234
|
+
return unusedDependencies;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts
|
|
238
|
+
import chalk5 from "chalk";
|
|
239
|
+
function getUnusedPeerDependencies({ name, location }, { peerDependencies }, { externalProdImports, externalProdTypeImports }) {
|
|
240
|
+
let unusedDependencies = 0;
|
|
241
|
+
for (const dep of peerDependencies) {
|
|
242
|
+
if (!externalProdImports.includes(dep) && !externalProdTypeImports.includes(dep)) {
|
|
186
243
|
unusedDependencies++;
|
|
187
|
-
console.log(`[${
|
|
244
|
+
console.log(`[${chalk5.blue(name)}] Unused peerDependency in package.json: ${chalk5.red(dep)}`);
|
|
188
245
|
console.log(` ${location}/package.json
|
|
189
246
|
`);
|
|
190
247
|
console.log("");
|
|
191
248
|
}
|
|
192
249
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
const
|
|
250
|
+
return unusedDependencies;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// src/actions/deplint/checkPackage/checkPackage.ts
|
|
254
|
+
function checkPackage({
|
|
255
|
+
name,
|
|
256
|
+
location,
|
|
257
|
+
deps = false,
|
|
258
|
+
devDeps = false,
|
|
259
|
+
peerDeps = false
|
|
260
|
+
}) {
|
|
261
|
+
const { prodSourceFiles, devSourceFiles } = findFiles(location);
|
|
262
|
+
const checkDeps = deps || !(deps || devDeps || peerDeps);
|
|
263
|
+
const checkDevDeps = devDeps || !(deps || devDeps || peerDeps);
|
|
264
|
+
const checkPeerDeps = peerDeps || !(deps || devDeps || peerDeps);
|
|
265
|
+
const sourceParams = getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles });
|
|
266
|
+
const packageParams = getDependenciesFromPackageJson(`${location}/package.json`);
|
|
267
|
+
const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
268
|
+
const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
269
|
+
const typesInDependencies = checkDeps ? getTypesInDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
270
|
+
const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
271
|
+
const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0;
|
|
272
|
+
const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies + unusedPeerDependencies;
|
|
214
273
|
return totalErrors;
|
|
215
274
|
}
|
|
216
|
-
|
|
275
|
+
|
|
276
|
+
// src/actions/deplint/deplint.ts
|
|
277
|
+
var deplint = ({
|
|
278
|
+
pkg,
|
|
279
|
+
deps,
|
|
280
|
+
devDeps,
|
|
281
|
+
peerDeps
|
|
282
|
+
}) => {
|
|
217
283
|
if (pkg) {
|
|
218
284
|
const { location, name } = yarnWorkspace(pkg);
|
|
219
285
|
console.log(`Running Deplint for ${name}`);
|
|
220
|
-
|
|
286
|
+
checkPackage({
|
|
221
287
|
name,
|
|
222
288
|
location,
|
|
223
|
-
devDeps
|
|
289
|
+
devDeps,
|
|
290
|
+
deps,
|
|
291
|
+
peerDeps
|
|
224
292
|
});
|
|
225
293
|
} else {
|
|
226
294
|
const workspaces = yarnWorkspaces();
|
|
227
295
|
console.log("Deplint Started...");
|
|
228
296
|
let totalErrors = 0;
|
|
229
297
|
for (const workspace of workspaces) {
|
|
230
|
-
totalErrors +=
|
|
298
|
+
totalErrors += checkPackage({
|
|
299
|
+
...workspace,
|
|
300
|
+
deps,
|
|
301
|
+
devDeps,
|
|
302
|
+
peerDeps
|
|
303
|
+
});
|
|
231
304
|
}
|
|
232
305
|
if (totalErrors > 0) {
|
|
233
|
-
console.log(`Found ${
|
|
306
|
+
console.log(`Deplint: Found ${chalk6.red(totalErrors)} dependency problems. ${chalk6.red("\u2716")}`);
|
|
234
307
|
} else {
|
|
235
|
-
console.log(`
|
|
308
|
+
console.log(`Deplint: Found no dependency problems. ${chalk6.green("\u2714")}`);
|
|
236
309
|
}
|
|
237
310
|
}
|
|
238
311
|
return 0;
|
|
@@ -240,4 +313,4 @@ var deplint = ({ pkg }) => {
|
|
|
240
313
|
export {
|
|
241
314
|
deplint
|
|
242
315
|
};
|
|
243
|
-
//# sourceMappingURL=
|
|
316
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/actions/deplint/deplint.ts","../../../src/lib/yarn/workspace/yarnWorkspaces.ts","../../../src/lib/yarn/workspace/yarnWorkspace.ts","../../../src/actions/deplint/findFilesByGlob.ts","../../../src/actions/deplint/findFiles.ts","../../../src/actions/deplint/getDependenciesFromPackageJson.ts","../../../src/actions/deplint/getImportsFromFile.ts","../../../src/actions/deplint/getBasePackageName.ts","../../../src/actions/deplint/getExternalImportsFromFiles.ts","../../../src/actions/deplint/checkPackage/getTypesInDependencies.ts","../../../src/actions/deplint/checkPackage/getUnlistedDependencies.ts","../../../src/actions/deplint/checkPackage/getUnlistedDevDependencies.ts","../../../src/actions/deplint/checkPackage/getUnusedDependencies.ts","../../../src/actions/deplint/checkPackage/getUnusedPeerDependencies.ts","../../../src/actions/deplint/checkPackage/checkPackage.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { yarnWorkspace, yarnWorkspaces } from '../../lib/index.ts'\nimport { checkPackage } from './checkPackage/index.ts'\n\nexport const deplint = ({\n pkg, deps, devDeps, peerDeps,\n}: { deps: boolean; devDeps: boolean; peerDeps: boolean; pkg: string }) => {\n if (pkg) {\n const { location, name } = yarnWorkspace(pkg)\n\n console.log(`Running Deplint for ${name}`)\n checkPackage({\n name, location, devDeps, deps, peerDeps,\n })\n } else {\n const workspaces = yarnWorkspaces()\n\n console.log('Deplint Started...')\n\n let totalErrors = 0\n\n for (const workspace of workspaces) {\n totalErrors += checkPackage({\n ...workspace, deps, devDeps, peerDeps,\n })\n }\n\n if (totalErrors > 0) {\n console.log(`Deplint: Found ${chalk.red(totalErrors)} dependency problems. ${chalk.red('✖')}`)\n } else {\n console.log(`Deplint: Found no dependency problems. ${chalk.green('✔')}`)\n }\n }\n return 0\n}\n","import { spawnSync } from 'node:child_process'\n\nimport type { Workspace } from './Workspace.ts'\n\nexport const yarnWorkspaces = (): Workspace[] => {\n const result = spawnSync('yarn', ['workspaces', 'list', '--json', '--recursive'], { encoding: 'utf8', shell: true })\n if (result.error) {\n throw result.error\n }\n return (\n result.stdout\n .toString()\n // NOTE: This probably doesn't work on Windows\n // TODO: Replace /r/n with /n first\n .split('\\n')\n .slice(0, -1)\n .map((item) => {\n return JSON.parse(item)\n })\n )\n}\n","import type { Workspace } from './Workspace.ts'\nimport { yarnWorkspaces } from './yarnWorkspaces.ts'\n\nexport const yarnWorkspace = (pkg: string): Workspace => {\n const workspace = yarnWorkspaces().find(({ name }) => name === pkg)\n if (!workspace) throw new Error(`Workspace ${pkg} not found`)\n return workspace\n}\n","import { globSync } from 'glob'\n\nexport function findFilesByGlob(cwd: string, pattern: string) {\n return globSync(pattern, { cwd, absolute: true })\n}\n","import { findFilesByGlob } from './findFilesByGlob.ts'\n\nexport function findFiles(path: string) {\n const allSourceInclude = ['./src/**/*.{ts,tsx}', './dist/**/*.d.ts']\n const prodExcludeEndswith = ['.spec.ts', '.stories.tsx']\n const prodExcludeIncludes = ['/spec/', '/stories/', '/scripts/']\n const allSourceFiles = allSourceInclude.flatMap(pattern => findFilesByGlob(path, pattern))\n\n const prodSourceFiles = allSourceFiles.filter(file => !prodExcludeEndswith.some(ext => file.endsWith(ext))\n && !prodExcludeIncludes.some(excl => file.includes(excl)))\n\n const devSourceFiles = allSourceFiles.filter(file => !prodSourceFiles.includes(file))\n return {\n allSourceFiles, prodSourceFiles, devSourceFiles,\n }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nexport function getDependenciesFromPackageJson(packageJsonPath: string) {\n const packageJsonFullPath = path.resolve(packageJsonPath)\n const rawContent = fs.readFileSync(packageJsonFullPath, 'utf8')\n const packageJson = JSON.parse(rawContent)\n\n const dependencies = packageJson.dependencies\n ? Object.keys(packageJson.dependencies)\n : []\n\n const devDependencies = packageJson.devDependencies\n ? Object.keys(packageJson.devDependencies)\n : []\n\n const peerDependencies = packageJson.peerDependencies\n ? Object.keys(packageJson.peerDependencies)\n : []\n\n return {\n dependencies, devDependencies, peerDependencies,\n }\n}\n","import fs from 'node:fs'\nimport path from 'node:path'\n\nimport ts from 'typescript'\n\nimport { getBasePackageName } from './getBasePackageName.ts'\n\nexport function getImportsFromFile(filePath: string, importPaths: Record<string, string[]>, typeImportPaths: Record<string, string[]>) {\n const sourceCode = fs.readFileSync(filePath, 'utf8')\n\n const sourceFile = ts.createSourceFile(\n path.basename(filePath),\n sourceCode,\n ts.ScriptTarget.Latest,\n true,\n )\n\n const imports: string[] = []\n const typeImports: string[] = []\n\n const isDeclarationFile = filePath.endsWith('.d.ts')\n\n function visit(node: ts.Node) {\n if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {\n const moduleSpecifier = (node.moduleSpecifier)?.getFullText()\n const isTypeImport = ts.isImportDeclaration(node) ? (node.importClause?.isTypeOnly ?? false) : false\n if (moduleSpecifier) {\n const trimmed = moduleSpecifier.split(\"'\").at(1) ?? moduleSpecifier\n // we are determining if the type import is being imported in an exported d.ts file\n if (isTypeImport && !isDeclarationFile) {\n typeImports.push(trimmed)\n } else {\n imports.push(trimmed)\n }\n }\n } else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {\n const [arg] = node.arguments\n if (ts.isStringLiteral(arg)) {\n const trimmed = arg.text\n imports.push(trimmed)\n }\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n\n const importsStartsWithExcludes = ['.', '#', 'node:']\n\n const cleanedImports = imports.filter(imp => !importsStartsWithExcludes.some(exc => imp.startsWith(exc))).map(getBasePackageName)\n const cleanedTypeImports = typeImports.filter(imp => !importsStartsWithExcludes.some(exc => imp.startsWith(exc))).map(getBasePackageName)\n\n for (const imp of cleanedImports) {\n importPaths[imp] = importPaths[imp] || []\n importPaths[imp].push(filePath)\n }\n\n for (const imp of cleanedTypeImports) {\n typeImportPaths[imp] = typeImportPaths[imp] || []\n typeImportPaths[imp].push(filePath)\n }\n\n return [cleanedImports, cleanedTypeImports]\n}\n","export function getBasePackageName(importName: string) {\n if (importName.startsWith('@')) {\n const parts = importName.split('/')\n return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : importName\n }\n return importName.split('/')[0]\n}\n","import { getImportsFromFile } from './getImportsFromFile.ts'\n\nconst internalImportPrefixes = ['.', '#', 'node:']\n\nconst removeInternalImports = (imports: string[]) => {\n return imports.filter(imp => !internalImportPrefixes.some(prefix => imp.startsWith(prefix)))\n}\n\nexport function getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles }: { devSourceFiles: string[]; prodSourceFiles: string[] }) {\n const prodImportPaths: Record<string, string[]> = {}\n const prodTypeImportPaths: Record<string, string[]> = {}\n const prodImportPairs = prodSourceFiles.map(path => getImportsFromFile(path, prodImportPaths, prodTypeImportPaths))\n const prodImports = prodImportPairs.flatMap(pair => pair[0])\n const prodTypeImports = prodImportPairs.flatMap(pair => pair[1])\n\n const devImportPaths: Record<string, string[]> = {}\n const devTypeImportPaths: Record<string, string[]> = {}\n const devImportPairs = devSourceFiles.map(path => getImportsFromFile(path, devImportPaths, devTypeImportPaths))\n const devImports = devImportPairs.flatMap(pair => pair[0])\n const devTypeImports = devImportPairs.flatMap(pair => pair[1])\n\n const externalProdImports = removeInternalImports(prodImports)\n const externalProdTypeImports = removeInternalImports(prodTypeImports)\n const externalDevImports = removeInternalImports(devImports)\n return {\n prodImports,\n devImports,\n prodImportPaths,\n prodTypeImportPaths,\n devImportPaths,\n externalProdImports,\n externalDevImports,\n prodTypeImports,\n devTypeImports,\n externalProdTypeImports,\n }\n}\n","import chalk from 'chalk'\n\nimport type { Workspace } from '../../../lib/index.ts'\nimport type { CheckPackageParams, CheckSourceParams } from './checkPackageTypes.ts'\n\nexport function getTypesInDependencies({ name, location }: Workspace, { dependencies }: CheckPackageParams, {}: CheckSourceParams) {\n let typesInDependencies = 0\n for (const dep of dependencies) {\n if (dep.startsWith('@types/')) {\n typesInDependencies++\n console.log(`[${chalk.blue(name)}] @types in dependencies in package.json: ${chalk.red(dep)}`)\n console.log(` ${location}/package.json\\n`)\n console.log('')\n }\n }\n return typesInDependencies\n}\n","import chalk from 'chalk'\n\nimport type { Workspace } from '../../../lib/index.ts'\nimport type { CheckPackageParams, CheckSourceParams } from './checkPackageTypes.ts'\n\nexport function getUnlistedDependencies({ name }: Workspace, {\n dependencies, devDependencies, peerDependencies,\n}: CheckPackageParams, {\n externalProdTypeImports, prodTypeImportPaths, externalProdImports, prodImportPaths,\n}: CheckSourceParams) {\n let unlistedDependencies = 0\n for (const imp of externalProdTypeImports) {\n if (!dependencies.includes(imp) && !peerDependencies.includes(imp) && !devDependencies.includes(imp) && !devDependencies.includes(`@types/${imp}`)) {\n unlistedDependencies++\n console.log(`[${chalk.blue(name)}] Missing dependency in package.json: ${chalk.red(imp)}`)\n console.log(` ${prodTypeImportPaths[imp].join('\\n')}`)\n console.log('')\n }\n }\n\n for (const imp of externalProdImports) {\n if (!dependencies.includes(imp) && !peerDependencies.includes(imp)) {\n unlistedDependencies++\n console.log(`[${chalk.blue(name)}] Missing dependency in package.json: ${chalk.red(imp)}`)\n console.log(` ${prodImportPaths[imp].join('\\n')}`)\n console.log('')\n }\n }\n return unlistedDependencies\n}\n","import chalk from 'chalk'\n\nimport type { Workspace } from '../../../lib/index.ts'\nimport type { CheckPackageParams, CheckSourceParams } from './checkPackageTypes.ts'\n\nexport function getUnlistedDevDependencies(\n { name }: Workspace,\n { devDependencies }: CheckPackageParams,\n { devImportPaths, externalDevImports }: CheckSourceParams,\n) {\n let unlistedDevDependencies = 0\n for (const imp of externalDevImports) {\n if (!devDependencies.includes(imp)) {\n unlistedDevDependencies++\n console.log(`[${chalk.blue(name)}] Missing devDependency in package.json: ${chalk.red(imp)}`)\n console.log(` Found in: ${devImportPaths[imp].join(', ')}`)\n }\n }\n return unlistedDevDependencies\n}\n","import chalk from 'chalk'\n\nimport type { Workspace } from '../../../lib/index.ts'\nimport type { CheckPackageParams, CheckSourceParams } from './checkPackageTypes.ts'\n\nexport function getUnusedDependencies(\n { name, location }: Workspace,\n { dependencies }: CheckPackageParams,\n {\n externalProdImports,\n externalProdTypeImports,\n }: CheckSourceParams,\n) {\n let unusedDependencies = 0\n for (const dep of dependencies) {\n if (!externalProdImports.includes(dep) && !externalProdTypeImports.includes(dep)) {\n unusedDependencies++\n console.log(`[${chalk.blue(name)}] Unused dependency in package.json: ${chalk.red(dep)}`)\n console.log(` ${location}/package.json\\n`)\n console.log('')\n }\n }\n return unusedDependencies\n}\n","import chalk from 'chalk'\n\nimport type { Workspace } from '../../../lib/index.ts'\nimport type { CheckPackageParams, CheckSourceParams } from './checkPackageTypes.ts'\n\nexport function getUnusedPeerDependencies(\n { name, location }: Workspace,\n { peerDependencies }: CheckPackageParams,\n { externalProdImports, externalProdTypeImports }: CheckSourceParams,\n) {\n let unusedDependencies = 0\n for (const dep of peerDependencies) {\n if (!externalProdImports.includes(dep) && !externalProdTypeImports.includes(dep)) {\n unusedDependencies++\n console.log(`[${chalk.blue(name)}] Unused peerDependency in package.json: ${chalk.red(dep)}`)\n console.log(` ${location}/package.json\\n`)\n console.log('')\n }\n }\n return unusedDependencies\n}\n","import type { Workspace } from '../../../lib/index.ts'\nimport { findFiles } from '../findFiles.ts'\nimport { getDependenciesFromPackageJson } from '../getDependenciesFromPackageJson.ts'\nimport { getExternalImportsFromFiles } from '../getExternalImportsFromFiles.ts'\nimport { getTypesInDependencies } from './getTypesInDependencies.ts'\nimport { getUnlistedDependencies } from './getUnlistedDependencies.ts'\nimport { getUnlistedDevDependencies } from './getUnlistedDevDependencies.ts'\nimport { getUnusedDependencies } from './getUnusedDependencies.ts'\nimport { getUnusedPeerDependencies } from './getUnusedPeerDependencies.ts'\n\nexport interface CheckPackageOptions extends Workspace {\n deps?: boolean\n devDeps?: boolean\n peerDeps?: boolean\n}\n\nexport function checkPackage({\n name, location, deps = false, devDeps = false, peerDeps = false,\n}: CheckPackageOptions) {\n const { prodSourceFiles, devSourceFiles } = findFiles(location)\n const checkDeps = deps || !(deps || devDeps || peerDeps)\n const checkDevDeps = devDeps || !(deps || devDeps || peerDeps)\n const checkPeerDeps = peerDeps || !(deps || devDeps || peerDeps)\n const sourceParams = getExternalImportsFromFiles({ prodSourceFiles, devSourceFiles })\n\n const packageParams = getDependenciesFromPackageJson(`${location}/package.json`)\n\n const unlistedDependencies = checkDeps ? getUnlistedDependencies({ name, location }, packageParams, sourceParams) : 0\n const unusedDependencies = checkDeps ? getUnusedDependencies({ name, location }, packageParams, sourceParams) : 0\n const typesInDependencies = checkDeps ? getTypesInDependencies({ name, location }, packageParams, sourceParams) : 0\n const unlistedDevDependencies = checkDevDeps ? getUnlistedDevDependencies({ name, location }, packageParams, sourceParams) : 0\n const unusedPeerDependencies = checkPeerDeps ? getUnusedPeerDependencies({ name, location }, packageParams, sourceParams) : 0\n\n const totalErrors = unlistedDependencies + unlistedDevDependencies + unusedDependencies + typesInDependencies + unusedPeerDependencies\n\n return totalErrors\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,SAAS,iBAAiB;AAInB,IAAM,iBAAiB,MAAmB;AAC/C,QAAM,SAAS,UAAU,QAAQ,CAAC,cAAc,QAAQ,UAAU,aAAa,GAAG,EAAE,UAAU,QAAQ,OAAO,KAAK,CAAC;AACnH,MAAI,OAAO,OAAO;AAChB,UAAM,OAAO;AAAA,EACf;AACA,SACE,OAAO,OACJ,SAAS,EAGT,MAAM,IAAI,EACV,MAAM,GAAG,EAAE,EACX,IAAI,CAAC,SAAS;AACb,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,CAAC;AAEP;;;ACjBO,IAAM,gBAAgB,CAAC,QAA2B;AACvD,QAAM,YAAY,eAAe,EAAE,KAAK,CAAC,EAAE,KAAK,MAAM,SAAS,GAAG;AAClE,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,aAAa,GAAG,YAAY;AAC5D,SAAO;AACT;;;ACPA,SAAS,gBAAgB;AAElB,SAAS,gBAAgB,KAAa,SAAiB;AAC5D,SAAO,SAAS,SAAS,EAAE,KAAK,UAAU,KAAK,CAAC;AAClD;;;ACFO,SAAS,UAAUC,OAAc;AACtC,QAAM,mBAAmB,CAAC,uBAAuB,kBAAkB;AACnE,QAAM,sBAAsB,CAAC,YAAY,cAAc;AACvD,QAAM,sBAAsB,CAAC,UAAU,aAAa,WAAW;AAC/D,QAAM,iBAAiB,iBAAiB,QAAQ,aAAW,gBAAgBA,OAAM,OAAO,CAAC;AAEzF,QAAM,kBAAkB,eAAe,OAAO,UAAQ,CAAC,oBAAoB,KAAK,SAAO,KAAK,SAAS,GAAG,CAAC,KACpG,CAAC,oBAAoB,KAAK,UAAQ,KAAK,SAAS,IAAI,CA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A,QAAW;AAAA,QAAM;AAAA,QAAS;AAAA,MAC/B,CAAC;AAAA,IACH;AAEA,QAAI,cAAc,GAAG;AACnB,cAAQ,IAAI,kBAAkBC,OAAM,IAAI,WAAW,CAAC,yBAAyBA,OAAM,IAAI,QAAG,CAAC,EAAE;AAAA,IAC/F,OAAO;AACL,cAAQ,IAAI,0CAA0CA,OAAM,MAAM,QAAG,CAAC,EAAE;AAAA,IAC1E;AAAA,EACF;AACA,SAAO;AACT;","names":["chalk","path","fs","path","fs","path","path","chalk","chalk","chalk","chalk","chalk"]}
|
package/dist/actions/fix.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/actions/lint.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/fix.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } from '../lib/index.ts'\n\nexport interface LintParams {\n fix?: boolean\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface LintPackageParams {\n pkg: string\n verbose?: boolean\n}\n\nexport const lintPackage = ({ pkg, fix }: LintParams & Required<Pick<LintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [${pkg}]`))\n const start = Date.now()\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [${pkg}]`, [\n ['yarn', ['workspace',\n pkg,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n\nexport const lint = ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? lintPackage({ pkg, fix })\n : lintAllPackages({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({ fix = false }: LintParams = {}) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n // const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n // const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']\n const fixOptions = fix ? ['--fix'] : []\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['eslint', ...fixOptions]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import type { LintParams } from './lint.ts'\nimport { lint } from './lint.ts'\n\nexport const fix = (params?: LintParams) => {\n return lint({ ...params, fix: true })\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,OAAO,WAAW;AAEX,IAAM,cAAc,CAAC,MAAc,QAAgB,QAA0B,SAAS,aAAa,UAAU;AAClH,MAAI,QAAQ;AACV,UAAM,UAAU,aAAa,sBAAsB;AACnD,UAAM,YAAY,UAAU,UAAU,MAAM,MAAM,MAAM;AACxD,YAAQ,KAAK,EAAE,UAAU,GAAG,IAAI,QAAQ,MAAM,aAAa,OAAO,EAAE,CAAC;AACrE,QAAI,YAAY;AACd,cAAQ,KAAK,MAAM;AAAA,IACrB;AAAA,EACF;AACF;;;ACXA,OAAOC,YAAW;;;ACAX,IAAM,YAAY,CAEvB,IACA,SACA,YAAY,CAACC,QAAW,CAAC,CAACA,IAAG,QAAQ,CAAC,CAACA,IAAG,YACvC;AACH,SAAO,UAAU,EAAO,IAAI,QAAQ,EAAO,IAAI;AACjD;;;ACLO,IAAM,qBAAqB,CAChC,IAAa,YACV;AACH,SAAO,UAAa,IAAI,SAAS,CAACC,QAAiBA,IAA6B,UAAU,MAAS;AACrG;;;AFDO,IAAM,YAAY,CAAC,OAAgB;AACxC,QAAM,QAAQ,OAAO,OAAO,WAAW,IAAI,MAAM,EAAE,IAAI;AACvD,QAAM,WACF,mBAAmB,OAAO,CAACC,WAAU;AACrC,QAAIA,OAAM,SAAS,UAAU;AAC3B,cAAQ,MAAMC,OAAM,IAAI,IAAID,OAAM,IAAI,cAAc,CAAC;AAAA,IACvD,OAAO;AACL,cAAQ,MAAMC,OAAM,IAAI,UAAUD,OAAM,IAAI,EAAE,CAAC;AAAA,IACjD;AACA,WAAOA,OAAM,SAAS;AAAA,EACxB,CAAC,KACE,UAAU,OAAO,CAACA,WAAU;AAC7B,YAAQ,MAAMC,OAAM,IAAI,GAAGD,OAAM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ACV,KAAK,EAAE,aAAa,KAAK,GAAG,QAAQ,IAAI;AAAA,QACxC,OAAO;AAAA,QACP,OAAO;AAAA,MACT,CAAC,EAAE,UAAU;AACf,kBAAY,MAAM,QAAQ,SAAS,UAAU;AAC7C,qBAAe,UAAU;AAAA,IAC3B;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC,UAAU;AACjB;;;
|
|
1
|
+
{"version":3,"sources":["../../src/actions/lint.ts","../../src/lib/checkResult.ts","../../src/lib/processEx.ts","../../src/lib/withError.ts","../../src/lib/withErrnoException.ts","../../src/lib/safeExit.ts","../../src/lib/runSteps.ts","../../src/actions/fix.ts"],"sourcesContent":["import chalk from 'chalk'\n\nimport { runSteps } from '../lib/index.ts'\n\nexport interface LintParams {\n cache?: boolean\n fix?: boolean\n incremental?: boolean\n pkg?: string\n verbose?: boolean\n}\n\nexport interface LintPackageParams {\n pkg: string\n verbose?: boolean\n}\n\nexport const lintPackage = ({ pkg, fix }: LintParams & Required<Pick<LintParams, 'pkg'>>) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [${pkg}]`))\n const start = Date.now()\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [${pkg}]`, [\n ['yarn', ['workspace',\n pkg,\n 'run',\n fix ? 'package-fix' : 'package-lint',\n ]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n\nexport const lint = ({\n pkg, verbose, incremental, fix,\n}: LintParams = {}) => {\n return pkg\n ? lintPackage({ pkg, fix })\n : lintAllPackages({\n verbose, incremental, fix,\n })\n}\n\nexport const lintAllPackages = ({ fix = false }: LintParams = {}) => {\n console.log(chalk.gray(`${fix ? 'Fix' : 'Lint'} [All-Packages]`))\n const start = Date.now()\n // const verboseOptions = verbose ? ['--verbose'] : ['--no-verbose']\n // const incrementalOptions = incremental ? ['--since', '-Ap'] : ['--parallel', '-Ap']\n const fixOptions = fix ? ['--fix'] : []\n\n const result = runSteps(`${fix ? 'Fix' : 'Lint'} [All-Packages]`, [\n ['yarn', ['eslint', ...fixOptions]],\n ])\n console.log(chalk.gray(`${fix ? 'Fixed in' : 'Linted in'} [${chalk.magenta(((Date.now() - start) / 1000).toFixed(2))}] ${chalk.gray('seconds')}`))\n return result\n}\n","import chalk from 'chalk'\n\nexport const checkResult = (name: string, result: number, level: 'error' | 'warn' = 'error', exitOnFail = false) => {\n if (result) {\n const exiting = exitOnFail ? '[Exiting Process]' : '[Continuing]'\n const chalkFunc = level === 'error' ? chalk.red : chalk.yellow\n console[level](chalkFunc(`${name} had ${result} failures ${exiting}`))\n if (exitOnFail) {\n process.exit(result)\n }\n }\n}\n","import chalk from 'chalk'\n\nimport { withErrnoException } from './withErrnoException.ts'\nimport { withError } from './withError.ts'\n\nexport const processEx = (ex: unknown) => {\n const error = typeof ex === 'string' ? new Error(ex) : ex\n const exitCode\n = withErrnoException(error, (error) => {\n if (error.code === 'ENOENT') {\n console.error(chalk.red(`'${error.path}' not found.`))\n } else {\n console.error(chalk.red(`Errno: ${error.code}`))\n }\n return error.errno ?? -1\n })\n ?? withError(error, (error) => {\n console.error(chalk.red(`${error.name}: ${error.message}`))\n return -1\n })\n ?? (() => {\n console.error(chalk.red(`Unexpected Error: ${JSON.stringify(ex, null, 2)}`))\n return -1\n })()\n // This allows us to use a previously set exit code\n process.exit(process.exitCode ?? exitCode)\n}\n","export const withError = <T extends Error = Error>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ex: any,\n closure: (error: T) => number,\n predicate = (ex: T) => (!!ex.name && !!ex.message),\n) => {\n return predicate(ex as T) ? closure(ex as T) : undefined\n}\n","import { withError } from './withError.ts'\n\nexport const withErrnoException = <T extends NodeJS.ErrnoException = NodeJS.ErrnoException>(\n ex: unknown, closure: (error: T) => number,\n) => {\n return withError<T>(ex, closure, (ex: unknown) => (ex as NodeJS.ErrnoException).errno !== undefined)\n}\n","/** Catch child process a crash and returns the code */\n\nimport { processEx } from './processEx.ts'\n\nconst safeExit = (func: () => number, exitOnFail = true): number => {\n try {\n const result = func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nconst safeExitAsync = async (func: () => Promise<number>, exitOnFail = true): Promise<number> => {\n try {\n const result = await func()\n if (result && exitOnFail) {\n process.exit(result)\n }\n return result\n } catch (ex) {\n return processEx(ex)\n }\n}\n\nexport { safeExit, safeExitAsync }\n","import type { SpawnSyncOptionsWithBufferEncoding } from 'node:child_process'\nimport { spawnSync } from 'node:child_process'\nimport { existsSync } from 'node:fs'\n\nimport chalk from 'chalk'\n\nimport { checkResult } from './checkResult.ts'\nimport { safeExit } from './safeExit.ts'\n\nexport type ScriptStep =\n | [/* command */ 'yarn' | 'node' | 'ts-node-script' | 'tsc' | 'jest', /* arg */ string | string[]]\n | [/* command */ string, /* arg */ string | string[], /* config */ SpawnSyncOptionsWithBufferEncoding]\n\nexport const runSteps = (name: string, steps: ScriptStep[], exitOnFail = true, messages?: string[]): number => {\n return safeExit(() => {\n const pkgName = process.env.npm_package_name\n console.log(chalk.green(`${name} [${pkgName}]`))\n let totalStatus = 0\n for (const [i, [command, args, config]] of steps.entries()) {\n if (messages?.[i]) {\n console.log(chalk.gray(messages?.[i]))\n }\n const argList = Array.isArray(args) ? args : args.split(' ')\n if (command === 'node' && !existsSync(argList[0])) {\n throw new Error(`File not found [${argList[0]}]`)\n }\n const status\n = spawnSync(command, Array.isArray(args) ? args : args.split(' '), {\n ...config,\n encoding: 'utf8',\n env: { FORCE_COLOR: '3', ...process.env },\n shell: true,\n stdio: 'inherit',\n }).status ?? 0\n checkResult(name, status, 'error', exitOnFail)\n totalStatus += status ?? 0\n }\n return totalStatus\n }, !!exitOnFail)\n}\n","import type { LintParams } from './lint.ts'\nimport { lint } from './lint.ts'\n\nexport const fix = (params?: LintParams) => {\n return lint({ ...params, fix: true })\n}\n"],"mappings":";AAA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