@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.
@@ -0,0 +1,887 @@
1
+ import { GLOB_EXCLUDE } from './chunk-23MHL5A5.js';
2
+ import { init_esm_shims } from './chunk-V2FABXKB.js';
3
+ import parserJsonc from 'jsonc-eslint-parser';
4
+ import defu from 'defu';
5
+ import fs from 'node:fs';
6
+ import process from 'node:process';
7
+ import { findUpSync } from 'find-up-simple';
8
+ import { normalize, resolve, dirname } from 'pathe';
9
+ import { globSync } from 'tinyglobby';
10
+
11
+ // ../eslint-plugin-bun/src/index.ts
12
+ init_esm_shims();
13
+
14
+ // ../eslint-plugin-bun/src/configs/index.ts
15
+ init_esm_shims();
16
+
17
+ // ../eslint-plugin-bun/src/configs/recommended.ts
18
+ init_esm_shims();
19
+
20
+ // ../eslint-plugin-bun/src/plugin.ts
21
+ init_esm_shims();
22
+
23
+ // ../eslint-plugin-bun/package.json
24
+ var package_default = {
25
+ version: "0.0.1"};
26
+
27
+ // ../eslint-plugin-bun/src/rules/json-enforce-catalog.ts
28
+ init_esm_shims();
29
+
30
+ // ../eslint-plugin-bun/src/helpers/create-rule.ts
31
+ init_esm_shims();
32
+ function RuleCreator(urlCreator) {
33
+ return function createNamedRule({
34
+ name,
35
+ meta,
36
+ ...rule
37
+ }) {
38
+ return createRuleInfo({
39
+ meta: {
40
+ ...meta,
41
+ docs: {
42
+ ...meta.docs,
43
+ url: urlCreator(name)
44
+ }
45
+ },
46
+ ...rule
47
+ });
48
+ };
49
+ }
50
+ function createRuleInfo({
51
+ create,
52
+ defaultOptions,
53
+ meta
54
+ }) {
55
+ return {
56
+ create: ((context) => {
57
+ const optionsWithDefault = context.options.map((options, index) => {
58
+ return defu(defaultOptions?.[index] ?? {}, options);
59
+ });
60
+ return create(context, optionsWithDefault);
61
+ }),
62
+ defaultOptions: defaultOptions ?? {},
63
+ meta
64
+ };
65
+ }
66
+ var createRule = RuleCreator(
67
+ (ruleName) => `https://docs.stormsoftware.com/projects/storm-ops/eslint-plugin-bun/rules/${ruleName}.md`
68
+ );
69
+
70
+ // ../eslint-plugin-bun/src/helpers/bun-workspace.ts
71
+ init_esm_shims();
72
+ function isWorkspaceObject(workspaces) {
73
+ return Boolean(workspaces) && typeof workspaces === "object" && !Array.isArray(workspaces);
74
+ }
75
+ function detectCatalogRoot(data) {
76
+ if (data.catalog || data.catalogs) {
77
+ return "top";
78
+ }
79
+ if (isWorkspaceObject(data.workspaces) && (data.workspaces.catalog || data.workspaces.catalogs)) {
80
+ return "workspaces";
81
+ }
82
+ return isWorkspaceObject(data.workspaces) ? "workspaces" : "top";
83
+ }
84
+ function normalizeCatalogName(name) {
85
+ return name.replace(/\^/g, "h").replace(/~/g, "t").replace(/\./g, "_").replace(/</g, "l").replace(/>/g, "g").replace(/=/g, "e").replace(/\*/g, "s").replace(/@/g, "a").replace(/\|/g, "p").replace(/&/g, "n").replace(/-/g, "m").replace(/\+/g, "u").replace(/\s/g, "_");
86
+ }
87
+ function sortObjectKeys(input) {
88
+ return Object.fromEntries(
89
+ Object.entries(input).sort(([left], [right]) => left.localeCompare(right))
90
+ );
91
+ }
92
+ function isWorkspaceRootPackageJson(data) {
93
+ return Boolean(
94
+ data.workspaces || data.catalog || data.catalogs
95
+ );
96
+ }
97
+ function readBunWorkspace(cwd = process.cwd()) {
98
+ const filepath = findUpSync("package.json", {
99
+ cwd,
100
+ type: "file"
101
+ });
102
+ if (!filepath) {
103
+ throw new Error("package.json not found");
104
+ }
105
+ let current = filepath;
106
+ let content = fs.readFileSync(current, "utf8");
107
+ let data = JSON.parse(content);
108
+ while (!isWorkspaceRootPackageJson(data)) {
109
+ const searchFrom = dirname(dirname(current));
110
+ const next = findUpSync("package.json", {
111
+ cwd: searchFrom,
112
+ type: "file"
113
+ });
114
+ if (!next || normalize(next) === normalize(current)) {
115
+ break;
116
+ }
117
+ current = next;
118
+ content = fs.readFileSync(current, "utf8");
119
+ data = JSON.parse(content);
120
+ }
121
+ if (!isWorkspaceRootPackageJson(data)) {
122
+ throw new Error(
123
+ "Bun workspace root package.json with workspaces/catalog not found"
124
+ );
125
+ }
126
+ let hasChanged = false;
127
+ let queueTimer;
128
+ const queue = [];
129
+ let catalogRoot = detectCatalogRoot(data);
130
+ const write = () => {
131
+ if (!fs.existsSync(current)) {
132
+ return;
133
+ }
134
+ fs.writeFileSync(current, `${JSON.stringify(data, null, 2)}
135
+ `);
136
+ };
137
+ const clearQueue = () => {
138
+ if (queueTimer != null) {
139
+ clearTimeout(queueTimer);
140
+ queueTimer = void 0;
141
+ }
142
+ queue.length = 0;
143
+ };
144
+ const getCatalogContainer = () => {
145
+ if (catalogRoot === "workspaces") {
146
+ if (!isWorkspaceObject(data.workspaces)) {
147
+ data.workspaces = {
148
+ packages: Array.isArray(data.workspaces) ? data.workspaces : [],
149
+ catalog: {},
150
+ catalogs: {}
151
+ };
152
+ }
153
+ return data.workspaces;
154
+ }
155
+ return data;
156
+ };
157
+ const getCatalogData = () => {
158
+ const container = getCatalogContainer();
159
+ return {
160
+ catalog: container.catalog,
161
+ catalogs: container.catalogs
162
+ };
163
+ };
164
+ const setPackage = (catalogName, packageName, specifier) => {
165
+ const container = getCatalogContainer();
166
+ if (catalogName === "default") {
167
+ container.catalog ??= {};
168
+ if (container.catalog[packageName] !== specifier) {
169
+ container.catalog[packageName] = specifier;
170
+ container.catalog = sortObjectKeys(container.catalog);
171
+ hasChanged = true;
172
+ }
173
+ return;
174
+ }
175
+ container.catalogs ??= {};
176
+ container.catalogs[catalogName] ??= {};
177
+ if (container.catalogs[catalogName][packageName] !== specifier) {
178
+ container.catalogs[catalogName][packageName] = specifier;
179
+ container.catalogs[catalogName] = sortObjectKeys(
180
+ container.catalogs[catalogName]
181
+ );
182
+ container.catalogs = sortObjectKeys(container.catalogs);
183
+ hasChanged = true;
184
+ }
185
+ };
186
+ const hasSpecifierConflicts = (catalogName, packageName, specifier) => {
187
+ const { catalog, catalogs } = getCatalogData();
188
+ const existingSpecifier = catalogName === "default" ? catalog?.[packageName] : catalogs?.[catalogName]?.[packageName];
189
+ if (existingSpecifier === specifier) {
190
+ return {
191
+ conflicts: false,
192
+ newCatalogName: catalogName,
193
+ existingSpecifier
194
+ };
195
+ }
196
+ if (existingSpecifier) {
197
+ const versionSuffix = normalizeCatalogName(specifier);
198
+ const newCatalogName = catalogName === "default" ? `conflicts_${packageName}_${versionSuffix}` : `conflicts_${catalogName}_${versionSuffix}`;
199
+ return {
200
+ conflicts: true,
201
+ existingSpecifier,
202
+ newCatalogName
203
+ };
204
+ }
205
+ return {
206
+ conflicts: false,
207
+ newCatalogName: catalogName
208
+ };
209
+ };
210
+ const getPackageCatalogs = (packageName) => {
211
+ const found = [];
212
+ const { catalog, catalogs } = getCatalogData();
213
+ if (catalogs) {
214
+ for (const name of Object.keys(catalogs)) {
215
+ if (catalogs[name]?.[packageName]) {
216
+ found.push(name);
217
+ }
218
+ }
219
+ }
220
+ if (catalog?.[packageName]) {
221
+ found.push("default");
222
+ }
223
+ return found;
224
+ };
225
+ const workspace2 = {
226
+ filepath: current,
227
+ setContent(newContent) {
228
+ content = newContent;
229
+ data = JSON.parse(newContent);
230
+ catalogRoot = detectCatalogRoot(data);
231
+ hasChanged = false;
232
+ },
233
+ hasChanged: () => hasChanged,
234
+ hasQueue: () => queueTimer != null,
235
+ clearQueue,
236
+ queueChange(fn, order) {
237
+ if (order === "pre") {
238
+ queue.unshift(fn);
239
+ } else {
240
+ queue.push(fn);
241
+ }
242
+ if (queueTimer != null) {
243
+ clearTimeout(queueTimer);
244
+ }
245
+ queueTimer = setTimeout(() => {
246
+ queueTimer = void 0;
247
+ const clone = [...queue];
248
+ queue.length = 0;
249
+ for (const queued of clone) {
250
+ queued(workspace2);
251
+ }
252
+ if (hasChanged) {
253
+ write();
254
+ }
255
+ }, 1e3);
256
+ },
257
+ toJSON: () => data,
258
+ toString: () => `${JSON.stringify(data, null, 2)}
259
+ `,
260
+ setPackage,
261
+ setPackageNoConflicts(catalogName, packageName, specifier) {
262
+ const { newCatalogName } = hasSpecifierConflicts(
263
+ catalogName,
264
+ packageName,
265
+ specifier
266
+ );
267
+ setPackage(newCatalogName, packageName, specifier);
268
+ },
269
+ getPackageCatalogs,
270
+ hasSpecifierConflicts,
271
+ getCatalogData,
272
+ getWorkspacePackagePatterns() {
273
+ if (Array.isArray(data.workspaces)) {
274
+ return data.workspaces;
275
+ }
276
+ if (isWorkspaceObject(data.workspaces) && data.workspaces.packages) {
277
+ return data.workspaces.packages;
278
+ }
279
+ return [];
280
+ }
281
+ };
282
+ return workspace2;
283
+ }
284
+ var WORKSPACE_CACHE_TIME = 1e4;
285
+ var workspaceLastRead;
286
+ var workspace;
287
+ function getBunWorkspace(cwd = process.cwd()) {
288
+ if (workspaceLastRead && workspace && !workspace.hasQueue() && Date.now() - workspaceLastRead > WORKSPACE_CACHE_TIME) {
289
+ workspace = void 0;
290
+ }
291
+ if (!workspace) {
292
+ workspace = readBunWorkspace(cwd);
293
+ workspaceLastRead = Date.now();
294
+ }
295
+ return workspace;
296
+ }
297
+ function isRootWorkspacePackageJson(filename, cwd = process.cwd()) {
298
+ try {
299
+ const root = getBunWorkspace(cwd);
300
+ return normalize(root.filepath) === normalize(filename);
301
+ } catch {
302
+ return false;
303
+ }
304
+ }
305
+ function collectWorkspacePackageJsonPaths(workspaceRoot) {
306
+ const root = resolve(dirname(workspaceRoot.filepath));
307
+ const patterns = workspaceRoot.getWorkspacePackagePatterns();
308
+ const dirs = patterns.length ? globSync(patterns, {
309
+ cwd: root,
310
+ dot: false,
311
+ ignore: [
312
+ "**/node_modules/**",
313
+ "**/dist/**",
314
+ "**/build/**"
315
+ ],
316
+ absolute: true,
317
+ expandDirectories: false,
318
+ onlyDirectories: true
319
+ }) : [];
320
+ dirs.push(root);
321
+ return dirs.map((dir) => resolve(dir, "package.json")).filter((path) => fs.existsSync(path)).sort();
322
+ }
323
+
324
+ // ../eslint-plugin-bun/src/helpers/iterate-dependencies.ts
325
+ init_esm_shims();
326
+ function getPackageJsonRootNode(context) {
327
+ if (!context.filename.endsWith("package.json")) {
328
+ return void 0;
329
+ }
330
+ const ast = context.sourceCode.ast;
331
+ const root = ast.body[0];
332
+ if (root?.expression?.type === "JSONObjectExpression") {
333
+ return root.expression;
334
+ }
335
+ return void 0;
336
+ }
337
+ function* iterateDependencies(context, fields) {
338
+ const root = getPackageJsonRootNode(context);
339
+ if (!root) {
340
+ return;
341
+ }
342
+ for (const fieldName of fields) {
343
+ const path = fieldName.split(".");
344
+ let node = root;
345
+ for (const segment of path) {
346
+ const item = node.properties?.find(
347
+ (property) => property.key.type === "JSONLiteral" && property.key.value === segment
348
+ );
349
+ if (!item?.value || item.value.type !== "JSONObjectExpression") {
350
+ node = void 0;
351
+ break;
352
+ }
353
+ node = item.value;
354
+ }
355
+ if (!node || node === root || !node.properties) {
356
+ continue;
357
+ }
358
+ for (const property of node.properties) {
359
+ if (property.value.type !== "JSONLiteral" || property.key.type !== "JSONLiteral") {
360
+ continue;
361
+ }
362
+ if (typeof property.value.value !== "string") {
363
+ continue;
364
+ }
365
+ yield {
366
+ packageName: String(property.key.value),
367
+ specifier: String(property.value.value),
368
+ property
369
+ };
370
+ }
371
+ }
372
+ }
373
+ function getObjectPath(obj, path) {
374
+ let current = obj;
375
+ for (const key of path) {
376
+ if (!current || typeof current !== "object") {
377
+ return void 0;
378
+ }
379
+ current = current[key];
380
+ if (!current) {
381
+ return void 0;
382
+ }
383
+ }
384
+ return current;
385
+ }
386
+
387
+ // ../eslint-plugin-bun/src/rules/json-enforce-catalog.ts
388
+ var RULE_NAME = "json-enforce-catalog";
389
+ var DEFAULT_FIELDS = ["dependencies", "devDependencies"];
390
+ var IGNORED_DEPENDENCIES = ["typescript"];
391
+ var json_enforce_catalog_default = createRule({
392
+ name: RULE_NAME,
393
+ meta: {
394
+ type: "layout",
395
+ docs: {
396
+ description: 'Enforce using "catalog:" in `package.json` and write versions to the Bun workspace root catalog'
397
+ },
398
+ fixable: "code",
399
+ schema: [
400
+ {
401
+ type: "object",
402
+ properties: {
403
+ allowedProtocols: {
404
+ type: "array",
405
+ description: "Allowed protocols in specifier to not be converted to catalog",
406
+ items: { type: "string" }
407
+ },
408
+ autofix: {
409
+ type: "boolean",
410
+ description: "Whether to autofix the linting error",
411
+ default: true
412
+ },
413
+ defaultCatalog: {
414
+ type: "string",
415
+ description: "Default catalog to use when moving version to catalog with autofix"
416
+ },
417
+ reuseExistingCatalog: {
418
+ type: "boolean",
419
+ description: "Whether to reuse existing catalog when moving version to catalog with autofix",
420
+ default: true
421
+ },
422
+ conflicts: {
423
+ type: "string",
424
+ description: "Strategy to handle conflicts when adding packages to catalogs",
425
+ enum: ["new-catalog", "overrides", "error"],
426
+ default: "new-catalog"
427
+ },
428
+ fields: {
429
+ type: "array",
430
+ description: "Fields to check for catalog",
431
+ items: { type: "string" },
432
+ default: DEFAULT_FIELDS
433
+ },
434
+ ignore: {
435
+ type: "array",
436
+ description: "A list of dependencies to ignore",
437
+ items: { type: "string" },
438
+ default: IGNORED_DEPENDENCIES
439
+ }
440
+ },
441
+ additionalProperties: false
442
+ }
443
+ ],
444
+ messages: {
445
+ expectCatalog: 'Expect to use catalog instead of plain specifier, got "{{specifier}}" for package "{{packageName}}".'
446
+ }
447
+ },
448
+ defaultOptions: [{}],
449
+ create(context, [options]) {
450
+ const {
451
+ allowedProtocols = ["workspace", "link", "file"],
452
+ defaultCatalog = "default",
453
+ autofix = true,
454
+ reuseExistingCatalog = true,
455
+ conflicts = "new-catalog",
456
+ fields = DEFAULT_FIELDS,
457
+ ignore = IGNORED_DEPENDENCIES
458
+ } = options || {};
459
+ for (const { packageName, specifier, property } of iterateDependencies(
460
+ context,
461
+ fields
462
+ )) {
463
+ if (ignore?.some((name) => name === packageName)) {
464
+ continue;
465
+ }
466
+ if (specifier.startsWith("catalog:")) {
467
+ continue;
468
+ }
469
+ if (allowedProtocols?.some((protocol) => specifier.startsWith(protocol))) {
470
+ continue;
471
+ }
472
+ let workspace2;
473
+ try {
474
+ workspace2 = getBunWorkspace();
475
+ } catch {
476
+ return {};
477
+ }
478
+ let targetCatalog = reuseExistingCatalog ? workspace2.getPackageCatalogs(packageName)[0] || defaultCatalog : defaultCatalog;
479
+ const resolvedConflicts = workspace2.hasSpecifierConflicts(
480
+ targetCatalog,
481
+ packageName,
482
+ specifier
483
+ );
484
+ let shouldFix = autofix;
485
+ if (conflicts === "error" && resolvedConflicts.conflicts) {
486
+ shouldFix = false;
487
+ }
488
+ if (conflicts === "new-catalog" && resolvedConflicts.conflicts) {
489
+ targetCatalog = resolvedConflicts.newCatalogName;
490
+ }
491
+ context.report({
492
+ node: property.value,
493
+ messageId: "expectCatalog",
494
+ data: {
495
+ specifier,
496
+ packageName
497
+ },
498
+ fix: shouldFix ? (fixer) => {
499
+ workspace2.queueChange(() => {
500
+ workspace2.setPackage(targetCatalog, packageName, specifier);
501
+ });
502
+ return fixer.replaceText(
503
+ property.value,
504
+ targetCatalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${targetCatalog}`)
505
+ );
506
+ } : void 0
507
+ });
508
+ }
509
+ return {};
510
+ }
511
+ });
512
+
513
+ // ../eslint-plugin-bun/src/rules/json-no-duplicate-catalog-item.ts
514
+ init_esm_shims();
515
+ var RULE_NAME2 = "json-no-duplicate-catalog-item";
516
+ function getProperty(node, key) {
517
+ return node?.properties?.find(
518
+ (property) => property.key.type === "JSONLiteral" && property.key.value === key
519
+ );
520
+ }
521
+ var json_no_duplicate_catalog_item_default = createRule({
522
+ name: RULE_NAME2,
523
+ meta: {
524
+ type: "problem",
525
+ docs: {
526
+ description: "Disallow duplicate catalog items in the Bun workspace root `package.json`"
527
+ },
528
+ schema: [
529
+ {
530
+ type: "object",
531
+ properties: {
532
+ allow: {
533
+ type: "array",
534
+ items: { type: "string" }
535
+ }
536
+ },
537
+ additionalProperties: false
538
+ }
539
+ ],
540
+ messages: {
541
+ duplicateCatalogItem: 'Catalog item "{{name}}" is already defined in the "{{existingCatalog}}" catalog. You may want to remove one of them.'
542
+ }
543
+ },
544
+ defaultOptions: [{}],
545
+ create(context, [options = {}]) {
546
+ if (!isRootWorkspacePackageJson(context.filename)) {
547
+ return {};
548
+ }
549
+ let workspace2;
550
+ try {
551
+ workspace2 = getBunWorkspace();
552
+ } catch {
553
+ return {};
554
+ }
555
+ if (workspace2.hasChanged() || workspace2.hasQueue()) {
556
+ return {};
557
+ }
558
+ workspace2.setContent(context.sourceCode.text);
559
+ const root = getPackageJsonRootNode(context);
560
+ if (!root) {
561
+ return {};
562
+ }
563
+ const { allow = [] } = options;
564
+ const topCatalog = getProperty(root, "catalog");
565
+ const topCatalogs = getProperty(root, "catalogs");
566
+ const workspaces = getProperty(root, "workspaces");
567
+ const workspacesCatalog = workspaces?.value?.type === "JSONObjectExpression" ? getProperty(workspaces.value, "catalog") : void 0;
568
+ const workspacesCatalogs = workspaces?.value?.type === "JSONObjectExpression" ? getProperty(workspaces.value, "catalogs") : void 0;
569
+ const catalogNode = topCatalog ?? workspacesCatalog;
570
+ const catalogsNode = topCatalogs ?? workspacesCatalogs;
571
+ const exists = /* @__PURE__ */ new Map();
572
+ const catalogEntries = [];
573
+ if (catalogNode?.value?.type === "JSONObjectExpression") {
574
+ for (const property of catalogNode.value.properties || []) {
575
+ catalogEntries.push({ catalogName: "default", property });
576
+ }
577
+ }
578
+ if (catalogsNode?.value?.type === "JSONObjectExpression") {
579
+ for (const named of catalogsNode.value.properties || []) {
580
+ if (named.value.type !== "JSONObjectExpression") {
581
+ continue;
582
+ }
583
+ const catalogName = String(named.key.value);
584
+ for (const property of named.value.properties || []) {
585
+ catalogEntries.push({ catalogName, property });
586
+ }
587
+ }
588
+ }
589
+ for (const { catalogName, property } of catalogEntries) {
590
+ const key = String(property.key.value);
591
+ if (allow.includes(key)) {
592
+ continue;
593
+ }
594
+ if (exists.has(key)) {
595
+ context.report({
596
+ node: property.value,
597
+ messageId: "duplicateCatalogItem",
598
+ data: {
599
+ name: key,
600
+ currentCatalog: catalogName,
601
+ existingCatalog: exists.get(key)
602
+ }
603
+ });
604
+ } else {
605
+ exists.set(key, catalogName);
606
+ }
607
+ }
608
+ return {};
609
+ }
610
+ });
611
+
612
+ // ../eslint-plugin-bun/src/rules/json-no-unused-catalog-item.ts
613
+ init_esm_shims();
614
+ var RULE_NAME3 = "json-no-unused-catalog-item";
615
+ var FIELDS = [
616
+ "dependencies",
617
+ "devDependencies",
618
+ "peerDependencies",
619
+ "optionalDependencies",
620
+ "overrides",
621
+ "resolutions"
622
+ ];
623
+ function getProperty2(node, key) {
624
+ return node?.properties?.find(
625
+ (property) => property.key.type === "JSONLiteral" && property.key.value === key
626
+ );
627
+ }
628
+ var json_no_unused_catalog_item_default = createRule({
629
+ name: RULE_NAME3,
630
+ meta: {
631
+ type: "problem",
632
+ docs: {
633
+ description: "Disallow unused catalog items in the Bun workspace root `package.json`"
634
+ },
635
+ schema: [],
636
+ messages: {
637
+ unusedCatalogItem: 'Catalog item "{{catalogItem}}" is not used in any package.json.'
638
+ }
639
+ },
640
+ defaultOptions: [],
641
+ create(context) {
642
+ if (!isRootWorkspacePackageJson(context.filename)) {
643
+ return {};
644
+ }
645
+ let workspace2;
646
+ try {
647
+ workspace2 = getBunWorkspace();
648
+ } catch {
649
+ return {};
650
+ }
651
+ if (workspace2.hasChanged() || workspace2.hasQueue()) {
652
+ return {};
653
+ }
654
+ workspace2.setContent(context.sourceCode.text);
655
+ const root = getPackageJsonRootNode(context);
656
+ if (!root) {
657
+ return {};
658
+ }
659
+ const topCatalog = getProperty2(root, "catalog");
660
+ const topCatalogs = getProperty2(root, "catalogs");
661
+ const workspaces = getProperty2(root, "workspaces");
662
+ const workspacesCatalog = workspaces?.value?.type === "JSONObjectExpression" ? getProperty2(workspaces.value, "catalog") : void 0;
663
+ const workspacesCatalogs = workspaces?.value?.type === "JSONObjectExpression" ? getProperty2(workspaces.value, "catalogs") : void 0;
664
+ const catalogNode = topCatalog ?? workspacesCatalog;
665
+ const catalogsNode = topCatalogs ?? workspacesCatalogs;
666
+ const entries = /* @__PURE__ */ new Map();
667
+ if (catalogNode?.value?.type === "JSONObjectExpression") {
668
+ for (const property of catalogNode.value.properties || []) {
669
+ entries.set(`${String(property.key.value)}:default`, property);
670
+ }
671
+ }
672
+ if (catalogsNode?.value?.type === "JSONObjectExpression") {
673
+ for (const named of catalogsNode.value.properties || []) {
674
+ if (named.value.type !== "JSONObjectExpression") {
675
+ continue;
676
+ }
677
+ const catalogName = String(named.key.value);
678
+ for (const property of named.value.properties || []) {
679
+ entries.set(`${String(property.key.value)}:${catalogName}`, property);
680
+ }
681
+ }
682
+ }
683
+ if (entries.size === 0) {
684
+ return {};
685
+ }
686
+ const packages = collectWorkspacePackageJsonPaths(workspace2);
687
+ for (const path of packages) {
688
+ const pkg = JSON.parse(fs.readFileSync(path, "utf8"));
689
+ for (const field of FIELDS) {
690
+ const map = getObjectPath(pkg, field.split("."));
691
+ if (!map) {
692
+ continue;
693
+ }
694
+ for (const [name, value] of Object.entries(map)) {
695
+ if (typeof value !== "string" || !value.startsWith("catalog:")) {
696
+ continue;
697
+ }
698
+ const catalogName = value.slice(8) || "default";
699
+ entries.delete(`${name}:${catalogName}`);
700
+ }
701
+ }
702
+ }
703
+ if (entries.size > 0) {
704
+ for (const [key, property] of Array.from(entries.entries()).sort(
705
+ (a, b) => a[0].localeCompare(b[0])
706
+ )) {
707
+ context.report({
708
+ node: property.value,
709
+ messageId: "unusedCatalogItem",
710
+ data: { catalogItem: key }
711
+ });
712
+ }
713
+ }
714
+ return {};
715
+ }
716
+ });
717
+
718
+ // ../eslint-plugin-bun/src/rules/json-valid-catalog.ts
719
+ init_esm_shims();
720
+ var RULE_NAME4 = "json-valid-catalog";
721
+ var DEFAULT_FIELDS2 = [
722
+ "dependencies",
723
+ "devDependencies",
724
+ "optionalDependencies",
725
+ "peerDependencies",
726
+ "resolutions",
727
+ "overrides"
728
+ ];
729
+ var json_valid_catalog_default = createRule({
730
+ name: RULE_NAME4,
731
+ meta: {
732
+ type: "layout",
733
+ docs: {
734
+ description: "Enforce using valid Bun catalog references in `package.json`"
735
+ },
736
+ fixable: "code",
737
+ schema: [
738
+ {
739
+ type: "object",
740
+ properties: {
741
+ autoInsert: {
742
+ type: "boolean",
743
+ description: "Whether to auto insert to catalog if missing",
744
+ default: true
745
+ },
746
+ autoInsertDefaultSpecifier: {
747
+ type: "string",
748
+ description: "Default specifier to use when auto inserting to catalog",
749
+ default: "^0.0.0"
750
+ },
751
+ autofix: {
752
+ type: "boolean",
753
+ description: "Whether to autofix the linting error",
754
+ default: true
755
+ },
756
+ fields: {
757
+ type: "array",
758
+ description: "Fields to check for catalog",
759
+ default: DEFAULT_FIELDS2
760
+ }
761
+ },
762
+ additionalProperties: false
763
+ }
764
+ ],
765
+ messages: {
766
+ invalidCatalog: 'Catalog "{{specifier}}" for package "{{packageName}}" is not defined in the workspace root `package.json`.'
767
+ }
768
+ },
769
+ defaultOptions: [{}],
770
+ create(context, [options = {}]) {
771
+ const {
772
+ autoInsert = true,
773
+ autofix = true,
774
+ autoInsertDefaultSpecifier = "^0.0.0",
775
+ fields = DEFAULT_FIELDS2
776
+ } = options || {};
777
+ for (const { packageName, specifier, property } of iterateDependencies(
778
+ context,
779
+ fields
780
+ )) {
781
+ if (!specifier.startsWith("catalog:")) {
782
+ continue;
783
+ }
784
+ let workspace2;
785
+ try {
786
+ workspace2 = getBunWorkspace();
787
+ } catch {
788
+ return {};
789
+ }
790
+ const currentCatalog = specifier.replace(/^catalog:/, "").trim() || "default";
791
+ const existingCatalogs = workspace2.getPackageCatalogs(packageName);
792
+ if (!existingCatalogs.includes(currentCatalog)) {
793
+ context.report({
794
+ node: property.value,
795
+ messageId: "invalidCatalog",
796
+ data: {
797
+ specifier,
798
+ packageName
799
+ },
800
+ fix: !autofix || !autoInsert && !existingCatalogs.length ? void 0 : (fixer) => {
801
+ let catalog = existingCatalogs[0];
802
+ if (!catalog && autoInsert) {
803
+ catalog = currentCatalog;
804
+ workspace2.queueChange(() => {
805
+ workspace2.setPackage(
806
+ catalog,
807
+ packageName,
808
+ autoInsertDefaultSpecifier
809
+ );
810
+ }, "pre");
811
+ }
812
+ return fixer.replaceText(
813
+ property.value,
814
+ catalog === "default" ? JSON.stringify("catalog:") : JSON.stringify(`catalog:${catalog}`)
815
+ );
816
+ }
817
+ });
818
+ }
819
+ }
820
+ return {};
821
+ }
822
+ });
823
+
824
+ // ../eslint-plugin-bun/src/plugin.ts
825
+ var plugin = {
826
+ meta: {
827
+ name: "bun",
828
+ version: package_default.version
829
+ },
830
+ rules: {
831
+ "json-enforce-catalog": json_enforce_catalog_default,
832
+ "json-valid-catalog": json_valid_catalog_default,
833
+ "json-no-unused-catalog-item": json_no_unused_catalog_item_default,
834
+ "json-no-duplicate-catalog-item": json_no_duplicate_catalog_item_default
835
+ }
836
+ };
837
+
838
+ // ../eslint-plugin-bun/src/configs/recommended.ts
839
+ var config = [
840
+ {
841
+ name: "bun/recommended/setup",
842
+ plugins: {
843
+ bun: plugin
844
+ }
845
+ },
846
+ {
847
+ name: "bun/recommended/package-json",
848
+ ignores: GLOB_EXCLUDE,
849
+ files: ["package.json", "**/package.json"],
850
+ languageOptions: {
851
+ parser: parserJsonc
852
+ },
853
+ rules: {
854
+ "bun/json-enforce-catalog": [
855
+ "error",
856
+ {
857
+ autofix: true,
858
+ allowedProtocols: ["workspace", "link", "file"],
859
+ defaultCatalog: "default",
860
+ reuseExistingCatalog: true,
861
+ conflicts: "overrides",
862
+ fields: ["dependencies", "devDependencies"],
863
+ ignore: ["typescript"]
864
+ }
865
+ ],
866
+ "bun/json-valid-catalog": "error",
867
+ "bun/json-no-unused-catalog-item": "error",
868
+ "bun/json-no-duplicate-catalog-item": "error"
869
+ }
870
+ }
871
+ ];
872
+ var recommended_default = config;
873
+
874
+ // ../eslint-plugin-bun/src/configs/index.ts
875
+ var configs = {
876
+ recommended: recommended_default
877
+ };
878
+
879
+ // ../eslint-plugin-bun/src/index.ts
880
+ var eslintPlugin = {
881
+ ...plugin,
882
+ configs
883
+ };
884
+ var src_default = eslintPlugin;
885
+ var rules = plugin.rules;
886
+
887
+ export { configs, src_default as default, rules };