@storm-software/eslint 0.170.147 → 0.170.148
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/{chunk-BMVXVU4C.js → chunk-23MHL5A5.js} +1 -1
- package/dist/{chunk-AQ6O65DK.js → chunk-2GBBEPXG.js} +1 -1
- package/dist/{chunk-EEYALP2Y.js → chunk-IANE44ON.js} +3 -3
- package/dist/{chunk-KSLOOUHT.js → chunk-RHHQGJPE.js} +626 -1301
- package/dist/{chunk-3TEXQ75B.js → chunk-S3KJ56KD.js} +1 -1
- package/dist/{chunk-E2NGV25P.js → chunk-TXQW75XG.js} +2 -2
- package/dist/{chunk-KKSKXDKN.js → chunk-V2FABXKB.js} +1 -1
- package/dist/chunk-YQLFHRZH.js +19 -0
- package/dist/index.cjs +4881 -3585
- package/dist/index.d.cts +5 -3
- package/dist/index.d.ts +5 -3
- package/dist/index.js +9 -8
- package/dist/preset.cjs +4880 -3585
- package/dist/preset.js +8 -7
- package/dist/{src-5RYCJUL6.js → src-HWOXXYDT.js} +3 -3
- package/dist/src-PMVM4MJ3.js +887 -0
- package/dist/src-UCLM7J4T.js +779 -0
- package/dist/types.d.cts +88 -2
- package/dist/types.d.ts +88 -2
- package/dist/types.js +1 -1
- package/dist/utils/combine.js +1 -1
- package/dist/utils/correct-paths.js +2 -2
- package/dist/utils/find-workspace-root.js +3 -3
- package/dist/utils/format-config.js +1 -1
- package/dist/utils/helpers.cjs +1 -1
- package/dist/utils/helpers.js +2 -2
- package/dist/utils/package-manager.cjs +199 -0
- package/dist/utils/package-manager.d.cts +8 -0
- package/dist/utils/package-manager.d.ts +8 -0
- package/dist/utils/package-manager.js +4 -0
- package/dist/utils/tsconfig.js +4 -4
- package/package.json +16 -10
|
@@ -0,0 +1,779 @@
|
|
|
1
|
+
import { GLOB_EXCLUDE } from './chunk-23MHL5A5.js';
|
|
2
|
+
import { init_esm_shims } from './chunk-V2FABXKB.js';
|
|
3
|
+
import * as jsoncParser from 'jsonc-eslint-parser';
|
|
4
|
+
import jsoncParser__default from 'jsonc-eslint-parser';
|
|
5
|
+
import * as yamlParser from 'yaml-eslint-parser';
|
|
6
|
+
import yamlParser__default from 'yaml-eslint-parser';
|
|
7
|
+
import fs, { existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import process from 'node:process';
|
|
9
|
+
import { findUpSync } from 'find-up-simple';
|
|
10
|
+
import { parsePnpmWorkspaceYaml } from 'pnpm-workspace-yaml';
|
|
11
|
+
import { basename, normalize, resolve, dirname } from 'pathe';
|
|
12
|
+
import { globSync } from 'tinyglobby';
|
|
13
|
+
|
|
14
|
+
// ../eslint-plugin-pnpm/src/index.ts
|
|
15
|
+
init_esm_shims();
|
|
16
|
+
|
|
17
|
+
// ../eslint-plugin-pnpm/src/configs/index.ts
|
|
18
|
+
init_esm_shims();
|
|
19
|
+
|
|
20
|
+
// ../eslint-plugin-pnpm/src/configs/recommended.ts
|
|
21
|
+
init_esm_shims();
|
|
22
|
+
|
|
23
|
+
// ../eslint-plugin-pnpm/src/plugin.ts
|
|
24
|
+
init_esm_shims();
|
|
25
|
+
|
|
26
|
+
// ../../node_modules/.pnpm/eslint-plugin-pnpm@0.3.0_patch_hash=72dcde755c336eeca3e6170de1106fd85ecb66171e060788f80_f126904b94a1635d882631163ea19421/node_modules/eslint-plugin-pnpm/dist/index.mjs
|
|
27
|
+
init_esm_shims();
|
|
28
|
+
var name = "eslint-plugin-pnpm";
|
|
29
|
+
var version = "0.3.0";
|
|
30
|
+
var blobUrl = "https://github.com/antfu/eslint-plugin-pnpm/blob/main/src/rules/";
|
|
31
|
+
function RuleCreator(urlCreator) {
|
|
32
|
+
return function createNamedRule({
|
|
33
|
+
name: name2,
|
|
34
|
+
meta,
|
|
35
|
+
...rule
|
|
36
|
+
}) {
|
|
37
|
+
return createRule({
|
|
38
|
+
meta: {
|
|
39
|
+
...meta,
|
|
40
|
+
docs: {
|
|
41
|
+
...meta.docs,
|
|
42
|
+
url: urlCreator(name2)
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
...rule
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function createRule({
|
|
50
|
+
create,
|
|
51
|
+
defaultOptions,
|
|
52
|
+
meta
|
|
53
|
+
}) {
|
|
54
|
+
return {
|
|
55
|
+
create: (context) => {
|
|
56
|
+
const optionsWithDefault = context.options.map((options, index) => {
|
|
57
|
+
return {
|
|
58
|
+
...defaultOptions[index] || {},
|
|
59
|
+
...options || {}
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
return create(context, optionsWithDefault);
|
|
63
|
+
},
|
|
64
|
+
defaultOptions,
|
|
65
|
+
meta
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
var createEslintRule = RuleCreator(
|
|
69
|
+
(ruleName) => `${blobUrl}${ruleName}.test.ts`
|
|
70
|
+
);
|
|
71
|
+
function getPackageJsonRootNode(context) {
|
|
72
|
+
if (!context.filename.endsWith("package.json"))
|
|
73
|
+
return;
|
|
74
|
+
const ast = context.sourceCode.ast;
|
|
75
|
+
const root = ast.body[0];
|
|
76
|
+
if (root.expression.type === "JSONObjectExpression")
|
|
77
|
+
return root.expression;
|
|
78
|
+
}
|
|
79
|
+
function* iterateDependencies(context, fields) {
|
|
80
|
+
const root = getPackageJsonRootNode(context);
|
|
81
|
+
if (!root)
|
|
82
|
+
return;
|
|
83
|
+
for (const fieldName of fields) {
|
|
84
|
+
const path = fieldName.split(".");
|
|
85
|
+
let node = root;
|
|
86
|
+
for (let i = 0; i < path.length; i++) {
|
|
87
|
+
const item = node.properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === path[i]);
|
|
88
|
+
if (!item?.value || item.value.type !== "JSONObjectExpression") {
|
|
89
|
+
node = void 0;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
node = item.value;
|
|
93
|
+
}
|
|
94
|
+
if (!node || node === root)
|
|
95
|
+
continue;
|
|
96
|
+
for (const property of node.properties) {
|
|
97
|
+
if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral")
|
|
98
|
+
continue;
|
|
99
|
+
if (typeof property.value.value !== "string")
|
|
100
|
+
continue;
|
|
101
|
+
const packageName = String(property.key.value);
|
|
102
|
+
const specifier = String(property.value.value);
|
|
103
|
+
yield {
|
|
104
|
+
packageName,
|
|
105
|
+
specifier,
|
|
106
|
+
property
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function readPnpmWorkspace() {
|
|
112
|
+
const filepath = findUpSync("pnpm-workspace.yaml", { cwd: process.cwd() });
|
|
113
|
+
if (!filepath)
|
|
114
|
+
throw new Error("pnpm-workspace.yaml not found");
|
|
115
|
+
const content = fs.readFileSync(filepath, "utf-8");
|
|
116
|
+
const workspace2 = parsePnpmWorkspaceYaml(content);
|
|
117
|
+
let queueTimer;
|
|
118
|
+
const queue = [];
|
|
119
|
+
const write = () => {
|
|
120
|
+
fs.writeFileSync(filepath, workspace2.toString());
|
|
121
|
+
};
|
|
122
|
+
const hasQueue = () => queueTimer != null;
|
|
123
|
+
const queueChange = (fn, order) => {
|
|
124
|
+
if (order === "pre")
|
|
125
|
+
queue.unshift(fn);
|
|
126
|
+
else
|
|
127
|
+
queue.push(fn);
|
|
128
|
+
if (queueTimer != null)
|
|
129
|
+
clearTimeout(queueTimer);
|
|
130
|
+
queueTimer = setTimeout(() => {
|
|
131
|
+
queueTimer = void 0;
|
|
132
|
+
const clone = [...queue];
|
|
133
|
+
queue.length = 0;
|
|
134
|
+
for (const fn2 of clone)
|
|
135
|
+
fn2(workspace2);
|
|
136
|
+
if (workspace2.hasChanged())
|
|
137
|
+
write();
|
|
138
|
+
}, 1e3);
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
filepath,
|
|
142
|
+
...workspace2,
|
|
143
|
+
hasQueue,
|
|
144
|
+
queueChange
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
var WORKSPACE_CACHE_TIME = 1e4;
|
|
148
|
+
var workspaceLastRead;
|
|
149
|
+
var workspace;
|
|
150
|
+
function getPnpmWorkspace() {
|
|
151
|
+
if (workspaceLastRead && workspace && !workspace.hasQueue() && Date.now() - workspaceLastRead > WORKSPACE_CACHE_TIME) {
|
|
152
|
+
workspace = void 0;
|
|
153
|
+
}
|
|
154
|
+
if (!workspace) {
|
|
155
|
+
workspace = readPnpmWorkspace();
|
|
156
|
+
workspaceLastRead = Date.now();
|
|
157
|
+
}
|
|
158
|
+
return workspace;
|
|
159
|
+
}
|
|
160
|
+
var RULE_NAME$4 = "json-enforce-catalog";
|
|
161
|
+
var DEFAULT_FIELDS$1 = [
|
|
162
|
+
"dependencies",
|
|
163
|
+
"devDependencies"
|
|
164
|
+
];
|
|
165
|
+
var IGNORED_DEPENDENCIES = [
|
|
166
|
+
"typescript"
|
|
167
|
+
];
|
|
168
|
+
var enforceCatalog = createEslintRule({
|
|
169
|
+
name: RULE_NAME$4,
|
|
170
|
+
meta: {
|
|
171
|
+
type: "layout",
|
|
172
|
+
docs: {
|
|
173
|
+
description: 'Enforce using "catalog:" in `package.json`'
|
|
174
|
+
},
|
|
175
|
+
fixable: "code",
|
|
176
|
+
schema: [
|
|
177
|
+
{
|
|
178
|
+
type: "object",
|
|
179
|
+
properties: {
|
|
180
|
+
allowedProtocols: {
|
|
181
|
+
type: "array",
|
|
182
|
+
description: "Allowed protocols in specifier to not be converted to catalog",
|
|
183
|
+
items: {
|
|
184
|
+
type: "string"
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
autofix: {
|
|
188
|
+
type: "boolean",
|
|
189
|
+
description: "Whether to autofix the linting error",
|
|
190
|
+
default: true
|
|
191
|
+
},
|
|
192
|
+
defaultCatalog: {
|
|
193
|
+
type: "string",
|
|
194
|
+
description: "Default catalog to use when moving version to catalog with autofix"
|
|
195
|
+
},
|
|
196
|
+
reuseExistingCatalog: {
|
|
197
|
+
type: "boolean",
|
|
198
|
+
description: "Whether to reuse existing catalog when moving version to catalog with autofix",
|
|
199
|
+
default: true
|
|
200
|
+
},
|
|
201
|
+
conflicts: {
|
|
202
|
+
type: "string",
|
|
203
|
+
description: "Strategy to handle conflicts when adding packages to catalogs",
|
|
204
|
+
enum: ["new-catalog", "overrides", "error"],
|
|
205
|
+
default: "new-catalog"
|
|
206
|
+
},
|
|
207
|
+
fields: {
|
|
208
|
+
type: "array",
|
|
209
|
+
description: "Fields to check for catalog",
|
|
210
|
+
items: { type: "string" },
|
|
211
|
+
default: DEFAULT_FIELDS$1
|
|
212
|
+
},
|
|
213
|
+
ignore: {
|
|
214
|
+
type: "array",
|
|
215
|
+
description: "A list of dependencies to ignore",
|
|
216
|
+
items: { type: "string" },
|
|
217
|
+
default: IGNORED_DEPENDENCIES
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
additionalProperties: false
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
messages: {
|
|
224
|
+
expectCatalog: 'Expect to use catalog instead of plain specifier, got "{{specifier}}" for package "{{packageName}}".'
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
defaultOptions: [{}],
|
|
228
|
+
create(context, [options]) {
|
|
229
|
+
const {
|
|
230
|
+
allowedProtocols = ["workspace", "link", "file"],
|
|
231
|
+
defaultCatalog = "default",
|
|
232
|
+
autofix = true,
|
|
233
|
+
reuseExistingCatalog = true,
|
|
234
|
+
conflicts = "new-catalog",
|
|
235
|
+
fields = DEFAULT_FIELDS$1,
|
|
236
|
+
ignore = IGNORED_DEPENDENCIES
|
|
237
|
+
} = options || {};
|
|
238
|
+
for (const { packageName, specifier, property } of iterateDependencies(context, fields)) {
|
|
239
|
+
if (ignore?.some((i) => i === packageName))
|
|
240
|
+
continue;
|
|
241
|
+
if (specifier.startsWith("catalog:"))
|
|
242
|
+
continue;
|
|
243
|
+
if (allowedProtocols?.some((p) => specifier.startsWith(p)))
|
|
244
|
+
continue;
|
|
245
|
+
const workspace2 = getPnpmWorkspace();
|
|
246
|
+
if (!workspace2)
|
|
247
|
+
return {};
|
|
248
|
+
let targetCatalog = reuseExistingCatalog ? workspace2.getPackageCatalogs(packageName)[0] || defaultCatalog : defaultCatalog;
|
|
249
|
+
const resolvedConflicts = workspace2.hasSpecifierConflicts(
|
|
250
|
+
targetCatalog,
|
|
251
|
+
packageName,
|
|
252
|
+
specifier
|
|
253
|
+
);
|
|
254
|
+
let shouldFix = autofix;
|
|
255
|
+
if (conflicts === "error") {
|
|
256
|
+
if (resolvedConflicts.conflicts) {
|
|
257
|
+
shouldFix = false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (conflicts === "new-catalog" && resolvedConflicts.conflicts) {
|
|
261
|
+
targetCatalog = resolvedConflicts.newCatalogName;
|
|
262
|
+
}
|
|
263
|
+
context.report({
|
|
264
|
+
node: property.value,
|
|
265
|
+
messageId: "expectCatalog",
|
|
266
|
+
data: {
|
|
267
|
+
specifier,
|
|
268
|
+
packageName
|
|
269
|
+
},
|
|
270
|
+
fix: shouldFix ? (fixer) => {
|
|
271
|
+
workspace2.queueChange(() => {
|
|
272
|
+
workspace2.setPackage(targetCatalog, packageName, specifier);
|
|
273
|
+
});
|
|
274
|
+
return fixer.replaceText(
|
|
275
|
+
property.value,
|
|
276
|
+
targetCatalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${targetCatalog}`)
|
|
277
|
+
);
|
|
278
|
+
} : void 0
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
return {};
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
var RULE_NAME$3 = "json-prefer-workspace-settings";
|
|
285
|
+
var preferWorkspaceSettings = createEslintRule({
|
|
286
|
+
name: RULE_NAME$3,
|
|
287
|
+
meta: {
|
|
288
|
+
type: "layout",
|
|
289
|
+
docs: {
|
|
290
|
+
description: "Prefer having pnpm settings in `pnpm-workspace.yaml` instead of `package.json`. This would requires pnpm v10.6+, see https://github.com/orgs/pnpm/discussions/9037."
|
|
291
|
+
},
|
|
292
|
+
fixable: "code",
|
|
293
|
+
schema: [
|
|
294
|
+
{
|
|
295
|
+
type: "object",
|
|
296
|
+
properties: {
|
|
297
|
+
autofix: {
|
|
298
|
+
type: "boolean",
|
|
299
|
+
description: "Whether to autofix the linting error",
|
|
300
|
+
default: true
|
|
301
|
+
}
|
|
302
|
+
},
|
|
303
|
+
additionalProperties: false
|
|
304
|
+
}
|
|
305
|
+
],
|
|
306
|
+
messages: {
|
|
307
|
+
unexpectedPnpmSettings: "Unexpected pnpm settings in package.json, should move to pnpm-workspace.yaml"
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
defaultOptions: [{}],
|
|
311
|
+
create(context, [options = {}]) {
|
|
312
|
+
const {
|
|
313
|
+
autofix = true
|
|
314
|
+
} = options || {};
|
|
315
|
+
const root = getPackageJsonRootNode(context);
|
|
316
|
+
if (!root)
|
|
317
|
+
return {};
|
|
318
|
+
const pnpmNode = root.properties.find((property) => property.key.type === "JSONLiteral" && property.key.value === "pnpm");
|
|
319
|
+
if (!pnpmNode)
|
|
320
|
+
return {};
|
|
321
|
+
const workspace2 = getPnpmWorkspace();
|
|
322
|
+
if (!workspace2)
|
|
323
|
+
return {};
|
|
324
|
+
context.report({
|
|
325
|
+
node: pnpmNode,
|
|
326
|
+
messageId: "unexpectedPnpmSettings",
|
|
327
|
+
fix: autofix ? (fixer) => {
|
|
328
|
+
const json = JSON.parse(context.sourceCode.text);
|
|
329
|
+
const pnpmSettings = json.pnpm;
|
|
330
|
+
const flatValueParis = [];
|
|
331
|
+
function traverse(value, paths) {
|
|
332
|
+
if (typeof value === "object" && value !== null && !Array.isArray(value)) {
|
|
333
|
+
for (const key in value) {
|
|
334
|
+
traverse(value[key], [...paths, key]);
|
|
335
|
+
}
|
|
336
|
+
} else {
|
|
337
|
+
flatValueParis.push([paths, value]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
traverse(pnpmSettings, []);
|
|
341
|
+
workspace2.queueChange(() => {
|
|
342
|
+
for (const [paths, value] of flatValueParis) {
|
|
343
|
+
workspace2.setPath(paths, value);
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
let start = pnpmNode.range[0];
|
|
347
|
+
let end = pnpmNode.range[1];
|
|
348
|
+
const before = context.sourceCode.getTokenBefore(pnpmNode);
|
|
349
|
+
if (before)
|
|
350
|
+
start = before.range[1];
|
|
351
|
+
const after = context.sourceCode.getTokenAfter(pnpmNode);
|
|
352
|
+
if (after?.type === "Punctuator" && after.value === ",")
|
|
353
|
+
end = after.range[1];
|
|
354
|
+
return fixer.removeRange([start, end]);
|
|
355
|
+
} : void 0
|
|
356
|
+
});
|
|
357
|
+
return {};
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
var RULE_NAME$2 = "json-valid-catalog";
|
|
361
|
+
var DEFAULT_FIELDS = [
|
|
362
|
+
"dependencies",
|
|
363
|
+
"devDependencies",
|
|
364
|
+
"optionalDependencies",
|
|
365
|
+
"peerDependencies",
|
|
366
|
+
"resolutions",
|
|
367
|
+
"overrides",
|
|
368
|
+
"pnpm.overrides"
|
|
369
|
+
];
|
|
370
|
+
var validCatalog = createEslintRule({
|
|
371
|
+
name: RULE_NAME$2,
|
|
372
|
+
meta: {
|
|
373
|
+
type: "layout",
|
|
374
|
+
docs: {
|
|
375
|
+
description: "Enforce using valid catalog in `package.json`"
|
|
376
|
+
},
|
|
377
|
+
fixable: "code",
|
|
378
|
+
schema: [
|
|
379
|
+
{
|
|
380
|
+
type: "object",
|
|
381
|
+
properties: {
|
|
382
|
+
autoInsert: {
|
|
383
|
+
type: "boolean",
|
|
384
|
+
description: "Whether to auto insert to catalog if missing",
|
|
385
|
+
default: true
|
|
386
|
+
},
|
|
387
|
+
autoInsertDefaultSpecifier: {
|
|
388
|
+
type: "string",
|
|
389
|
+
description: "Default specifier to use when auto inserting to catalog",
|
|
390
|
+
default: "^0.0.0"
|
|
391
|
+
},
|
|
392
|
+
autofix: {
|
|
393
|
+
type: "boolean",
|
|
394
|
+
description: "Whether to autofix the linting error",
|
|
395
|
+
default: true
|
|
396
|
+
},
|
|
397
|
+
enforceNoConflict: {
|
|
398
|
+
type: "boolean",
|
|
399
|
+
description: "Whether to enforce no conflicts when adding packages to catalogs (will create version-specific catalogs)",
|
|
400
|
+
default: true
|
|
401
|
+
},
|
|
402
|
+
fields: {
|
|
403
|
+
type: "array",
|
|
404
|
+
description: "Fields to check for catalog",
|
|
405
|
+
default: DEFAULT_FIELDS
|
|
406
|
+
}
|
|
407
|
+
},
|
|
408
|
+
additionalProperties: false
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
messages: {
|
|
412
|
+
invalidCatalog: 'Catalog "{{specifier}}" for package "{{packageName}}" is not defined in `pnpm-workspace.yaml`.'
|
|
413
|
+
}
|
|
414
|
+
},
|
|
415
|
+
defaultOptions: [{}],
|
|
416
|
+
create(context, [options = {}]) {
|
|
417
|
+
const {
|
|
418
|
+
autoInsert = true,
|
|
419
|
+
autofix = true,
|
|
420
|
+
autoInsertDefaultSpecifier = "^0.0.0",
|
|
421
|
+
fields = DEFAULT_FIELDS
|
|
422
|
+
} = options || {};
|
|
423
|
+
for (const { packageName, specifier, property } of iterateDependencies(context, fields)) {
|
|
424
|
+
if (!specifier.startsWith("catalog:"))
|
|
425
|
+
continue;
|
|
426
|
+
const workspace2 = getPnpmWorkspace();
|
|
427
|
+
if (!workspace2)
|
|
428
|
+
return {};
|
|
429
|
+
const currentCatalog = specifier.replace(/^catalog:/, "").trim() || "default";
|
|
430
|
+
const existingCatalogs = workspace2.getPackageCatalogs(packageName);
|
|
431
|
+
if (!existingCatalogs.includes(currentCatalog)) {
|
|
432
|
+
context.report({
|
|
433
|
+
node: property.value,
|
|
434
|
+
messageId: "invalidCatalog",
|
|
435
|
+
data: {
|
|
436
|
+
specifier,
|
|
437
|
+
packageName
|
|
438
|
+
},
|
|
439
|
+
fix: !autofix || !autoInsert && !existingCatalogs.length ? void 0 : (fixer) => {
|
|
440
|
+
let catalog = existingCatalogs[0];
|
|
441
|
+
if (!catalog && autoInsert) {
|
|
442
|
+
catalog = currentCatalog;
|
|
443
|
+
workspace2.queueChange(() => {
|
|
444
|
+
workspace2.setPackage(catalog, packageName, autoInsertDefaultSpecifier);
|
|
445
|
+
}, "pre");
|
|
446
|
+
}
|
|
447
|
+
return fixer.replaceText(
|
|
448
|
+
property.value,
|
|
449
|
+
catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`)
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
return {};
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
var rules$2 = {
|
|
459
|
+
"json-enforce-catalog": enforceCatalog,
|
|
460
|
+
"json-valid-catalog": validCatalog,
|
|
461
|
+
"json-prefer-workspace-settings": preferWorkspaceSettings
|
|
462
|
+
};
|
|
463
|
+
var RULE_NAME$1 = "yaml-no-duplicate-catalog-item";
|
|
464
|
+
var noDuplicateCatalogItem = createEslintRule({
|
|
465
|
+
name: RULE_NAME$1,
|
|
466
|
+
meta: {
|
|
467
|
+
type: "problem",
|
|
468
|
+
docs: {
|
|
469
|
+
description: "Disallow unused catalogs in `pnpm-workspace.yaml`"
|
|
470
|
+
},
|
|
471
|
+
fixable: "code",
|
|
472
|
+
schema: [
|
|
473
|
+
{
|
|
474
|
+
type: "object",
|
|
475
|
+
properties: {
|
|
476
|
+
allow: {
|
|
477
|
+
type: "array",
|
|
478
|
+
items: { type: "string" }
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
additionalProperties: false
|
|
482
|
+
}
|
|
483
|
+
],
|
|
484
|
+
messages: {
|
|
485
|
+
duplicateCatalogItem: 'Catalog item "{{name}}" is already defined in the "{{existingCatalog}}" catalog. You may want to remove one of them.'
|
|
486
|
+
}
|
|
487
|
+
},
|
|
488
|
+
defaultOptions: [{}],
|
|
489
|
+
create(context, [options = {}]) {
|
|
490
|
+
if (basename(context.filename) !== "pnpm-workspace.yaml")
|
|
491
|
+
return {};
|
|
492
|
+
const workspace2 = getPnpmWorkspace();
|
|
493
|
+
if (!workspace2 || normalize(workspace2.filepath) !== normalize(context.filename))
|
|
494
|
+
return {};
|
|
495
|
+
if (workspace2.hasChanged() || workspace2.hasQueue())
|
|
496
|
+
return {};
|
|
497
|
+
const { allow = [] } = options;
|
|
498
|
+
workspace2.setContent(context.sourceCode.text);
|
|
499
|
+
const json = workspace2.toJSON() || {};
|
|
500
|
+
const exists = /* @__PURE__ */ new Map();
|
|
501
|
+
const catalogs = {
|
|
502
|
+
...json.catalogs,
|
|
503
|
+
default: json.catalog
|
|
504
|
+
};
|
|
505
|
+
const doc = workspace2.getDocument();
|
|
506
|
+
for (const [catalog, object] of Object.entries(catalogs)) {
|
|
507
|
+
if (!object)
|
|
508
|
+
continue;
|
|
509
|
+
for (const key of Object.keys(object)) {
|
|
510
|
+
if (allow.includes(key))
|
|
511
|
+
continue;
|
|
512
|
+
if (exists.has(key)) {
|
|
513
|
+
const existingCatalog = exists.get(key);
|
|
514
|
+
const node = doc.getIn(catalog === "default" ? ["catalog", key] : ["catalogs", catalog, key], true);
|
|
515
|
+
const start = context.sourceCode.getLocFromIndex(node.range[0]);
|
|
516
|
+
const end = context.sourceCode.getLocFromIndex(node.range[1]);
|
|
517
|
+
context.report({
|
|
518
|
+
loc: {
|
|
519
|
+
start,
|
|
520
|
+
end
|
|
521
|
+
},
|
|
522
|
+
messageId: "duplicateCatalogItem",
|
|
523
|
+
data: {
|
|
524
|
+
name: key,
|
|
525
|
+
currentCatalog: catalog,
|
|
526
|
+
existingCatalog
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
} else {
|
|
530
|
+
exists.set(key, catalog);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return {};
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
var RULE_NAME = "yaml-no-unused-catalog-item";
|
|
538
|
+
var noUnusedCatalogItem = createEslintRule({
|
|
539
|
+
name: RULE_NAME,
|
|
540
|
+
meta: {
|
|
541
|
+
type: "problem",
|
|
542
|
+
docs: {
|
|
543
|
+
description: "Disallow unused catalogs in `pnpm-workspace.yaml`"
|
|
544
|
+
},
|
|
545
|
+
fixable: "code",
|
|
546
|
+
schema: [],
|
|
547
|
+
messages: {
|
|
548
|
+
unusedCatalogItem: 'Catalog item "{{catalogItem}}" is not used in any package.json.'
|
|
549
|
+
}
|
|
550
|
+
},
|
|
551
|
+
defaultOptions: [],
|
|
552
|
+
create(context) {
|
|
553
|
+
if (basename(context.filename) !== "pnpm-workspace.yaml")
|
|
554
|
+
return {};
|
|
555
|
+
const workspace2 = getPnpmWorkspace();
|
|
556
|
+
if (!workspace2 || normalize(workspace2.filepath) !== normalize(context.filename))
|
|
557
|
+
return {};
|
|
558
|
+
if (workspace2.hasChanged() || workspace2.hasQueue())
|
|
559
|
+
return {};
|
|
560
|
+
workspace2.setContent(context.sourceCode.text);
|
|
561
|
+
const parsed = workspace2.toJSON() || {};
|
|
562
|
+
const root = resolve(dirname(context.filename));
|
|
563
|
+
const entries = /* @__PURE__ */ new Map();
|
|
564
|
+
const doc = workspace2.getDocument();
|
|
565
|
+
const catalogs = {
|
|
566
|
+
default: doc.getIn(["catalog"])
|
|
567
|
+
};
|
|
568
|
+
for (const item of doc.getIn(["catalogs"])?.items || [])
|
|
569
|
+
catalogs[String(item.key)] = item.value;
|
|
570
|
+
for (const [catalog, map] of Object.entries(catalogs)) {
|
|
571
|
+
if (!map)
|
|
572
|
+
continue;
|
|
573
|
+
for (const item of map.items) {
|
|
574
|
+
entries.set(`${String(item.key)}:${catalog}`, item);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
if (entries.size === 0)
|
|
578
|
+
return {};
|
|
579
|
+
const dirs = parsed.packages ? globSync(parsed.packages, {
|
|
580
|
+
cwd: root,
|
|
581
|
+
dot: false,
|
|
582
|
+
ignore: [
|
|
583
|
+
"**/node_modules/**",
|
|
584
|
+
"**/dist/**",
|
|
585
|
+
"**/build/**",
|
|
586
|
+
"**/dist/**",
|
|
587
|
+
"**/dist/**"
|
|
588
|
+
],
|
|
589
|
+
absolute: true,
|
|
590
|
+
expandDirectories: false,
|
|
591
|
+
onlyDirectories: true
|
|
592
|
+
}) : [];
|
|
593
|
+
dirs.push(root);
|
|
594
|
+
const packages = dirs.map((dir) => resolve(dir, "package.json")).filter((x) => existsSync(x)).sort();
|
|
595
|
+
const FIELDS = [
|
|
596
|
+
"dependencies",
|
|
597
|
+
"devDependencies",
|
|
598
|
+
"peerDependencies",
|
|
599
|
+
"optionalDependencies",
|
|
600
|
+
"overrides",
|
|
601
|
+
"resolutions",
|
|
602
|
+
"pnpm.overrides"
|
|
603
|
+
];
|
|
604
|
+
for (const path of packages) {
|
|
605
|
+
const pkg = JSON.parse(readFileSync(path, "utf-8"));
|
|
606
|
+
for (const field of FIELDS) {
|
|
607
|
+
const map = getObjectPath(pkg, field.split("."));
|
|
608
|
+
if (!map)
|
|
609
|
+
continue;
|
|
610
|
+
for (const [name2, value] of Object.entries(map)) {
|
|
611
|
+
if (!value.startsWith("catalog:"))
|
|
612
|
+
continue;
|
|
613
|
+
const catalog = value.slice(8) || "default";
|
|
614
|
+
const key = `${name2}:${catalog}`;
|
|
615
|
+
entries.delete(key);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
if (entries.size > 0) {
|
|
620
|
+
for (const [key, value] of Array.from(entries.entries()).sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
621
|
+
const start = context.sourceCode.getLocFromIndex(value.key.range[0]);
|
|
622
|
+
const end = context.sourceCode.getLocFromIndex(value.value.range.at(-1));
|
|
623
|
+
context.report({
|
|
624
|
+
loc: {
|
|
625
|
+
start,
|
|
626
|
+
end
|
|
627
|
+
},
|
|
628
|
+
messageId: "unusedCatalogItem",
|
|
629
|
+
data: { catalogItem: key }
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return {};
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
function getObjectPath(obj, path) {
|
|
637
|
+
let current = obj;
|
|
638
|
+
for (const key of path) {
|
|
639
|
+
current = current[key];
|
|
640
|
+
if (!current)
|
|
641
|
+
return void 0;
|
|
642
|
+
}
|
|
643
|
+
return current;
|
|
644
|
+
}
|
|
645
|
+
var rules$1 = {
|
|
646
|
+
"yaml-no-unused-catalog-item": noUnusedCatalogItem,
|
|
647
|
+
"yaml-no-duplicate-catalog-item": noDuplicateCatalogItem
|
|
648
|
+
};
|
|
649
|
+
var rules = {
|
|
650
|
+
...rules$2,
|
|
651
|
+
...rules$1
|
|
652
|
+
};
|
|
653
|
+
var plugin = {
|
|
654
|
+
meta: {
|
|
655
|
+
name,
|
|
656
|
+
version
|
|
657
|
+
},
|
|
658
|
+
rules
|
|
659
|
+
};
|
|
660
|
+
var configsJson = [
|
|
661
|
+
{
|
|
662
|
+
name: "pnpm/package.json",
|
|
663
|
+
files: [
|
|
664
|
+
"package.json",
|
|
665
|
+
"**/package.json"
|
|
666
|
+
],
|
|
667
|
+
languageOptions: {
|
|
668
|
+
parser: jsoncParser
|
|
669
|
+
},
|
|
670
|
+
plugins: {
|
|
671
|
+
pnpm: plugin
|
|
672
|
+
},
|
|
673
|
+
rules: {
|
|
674
|
+
"pnpm/json-enforce-catalog": "error",
|
|
675
|
+
"pnpm/json-valid-catalog": "error",
|
|
676
|
+
"pnpm/json-prefer-workspace-settings": "error"
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
];
|
|
680
|
+
var configsYaml = [
|
|
681
|
+
{
|
|
682
|
+
name: "pnpm/pnpm-workspace-yaml",
|
|
683
|
+
files: ["pnpm-workspace.yaml"],
|
|
684
|
+
languageOptions: {
|
|
685
|
+
parser: yamlParser
|
|
686
|
+
},
|
|
687
|
+
plugins: {
|
|
688
|
+
pnpm: plugin
|
|
689
|
+
},
|
|
690
|
+
rules: {
|
|
691
|
+
"pnpm/yaml-no-unused-catalog-item": "error",
|
|
692
|
+
"pnpm/yaml-no-duplicate-catalog-item": "error"
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
];
|
|
696
|
+
var configs = {
|
|
697
|
+
recommended: [
|
|
698
|
+
...configsJson
|
|
699
|
+
// Yaml support is still experimental
|
|
700
|
+
// ...configsYaml,
|
|
701
|
+
],
|
|
702
|
+
json: configsJson,
|
|
703
|
+
yaml: configsYaml
|
|
704
|
+
};
|
|
705
|
+
plugin.configs = configs;
|
|
706
|
+
|
|
707
|
+
// ../eslint-plugin-pnpm/package.json
|
|
708
|
+
var package_default = {
|
|
709
|
+
version: "0.0.76"};
|
|
710
|
+
|
|
711
|
+
// ../eslint-plugin-pnpm/src/plugin.ts
|
|
712
|
+
var plugin2 = {
|
|
713
|
+
...plugin,
|
|
714
|
+
meta: {
|
|
715
|
+
name: "pnpm",
|
|
716
|
+
version: package_default.version
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// ../eslint-plugin-pnpm/src/configs/recommended.ts
|
|
721
|
+
var config = [
|
|
722
|
+
{
|
|
723
|
+
name: "pnpm/recommended/setup",
|
|
724
|
+
plugins: {
|
|
725
|
+
pnpm: plugin2
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
name: "pnpm/recommended/package-json",
|
|
730
|
+
ignores: GLOB_EXCLUDE,
|
|
731
|
+
files: ["package.json", "**/package.json"],
|
|
732
|
+
languageOptions: {
|
|
733
|
+
parser: jsoncParser__default
|
|
734
|
+
},
|
|
735
|
+
rules: {
|
|
736
|
+
"pnpm/json-enforce-catalog": [
|
|
737
|
+
"error",
|
|
738
|
+
{
|
|
739
|
+
autofix: true,
|
|
740
|
+
allowedProtocols: ["workspace", "link", "file"],
|
|
741
|
+
defaultCatalog: "default",
|
|
742
|
+
reuseExistingCatalog: true,
|
|
743
|
+
conflicts: "overrides",
|
|
744
|
+
fields: ["dependencies", "devDependencies"]
|
|
745
|
+
}
|
|
746
|
+
],
|
|
747
|
+
"pnpm/json-valid-catalog": "error",
|
|
748
|
+
"pnpm/json-prefer-workspace-settings": "error"
|
|
749
|
+
}
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
name: "pnpm/recommended/pnpm-workspace",
|
|
753
|
+
ignores: GLOB_EXCLUDE,
|
|
754
|
+
files: ["pnpm-workspace.yaml", "**/pnpm-workspace.yaml"],
|
|
755
|
+
languageOptions: {
|
|
756
|
+
parser: yamlParser__default
|
|
757
|
+
},
|
|
758
|
+
rules: {
|
|
759
|
+
"pnpm/yaml-no-unused-catalog-item": "error",
|
|
760
|
+
"pnpm/yaml-no-duplicate-catalog-item": "error"
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
];
|
|
764
|
+
var recommended_default = config;
|
|
765
|
+
|
|
766
|
+
// ../eslint-plugin-pnpm/src/configs/index.ts
|
|
767
|
+
var configs2 = {
|
|
768
|
+
recommended: recommended_default
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
// ../eslint-plugin-pnpm/src/index.ts
|
|
772
|
+
var eslintPlugin = {
|
|
773
|
+
...plugin2,
|
|
774
|
+
configs: configs2
|
|
775
|
+
};
|
|
776
|
+
var src_default = eslintPlugin;
|
|
777
|
+
var rules2 = plugin2.rules;
|
|
778
|
+
|
|
779
|
+
export { configs2 as configs, src_default as default, rules2 as rules };
|