-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathno-barrel-imports.cjs
More file actions
671 lines (603 loc) · 22.9 KB
/
Copy pathno-barrel-imports.cjs
File metadata and controls
671 lines (603 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
'use strict';
const fs = require('node:fs');
const path = require('node:path');
const { parse } = require('@typescript-eslint/typescript-estree');
const WORKSPACE_ROOT = path.resolve(__dirname, '..');
const PACKAGES_ROOT = path.join(WORKSPACE_ROOT, 'packages');
const moduleCache = new Map();
const owningPackageCache = new Map();
const wildcardExportsCache = new Map();
// Barrels we deliberately don't rewrite imports from. `@glimmer/component`
// has its own legacy-resolution tsconfig that can't follow deep paths;
// `@ember/version` is a one-line shim that re-exports from `ember/version`
// (a different package), and we want to keep `@ember/version` as the canonical
// import path for the framework version.
const EXCLUDED_BARRELS = new Set(['@glimmer/component', '@ember/version']);
const idOrStr = (n) => (n.type === 'Identifier' ? n.name : n.value);
function resolveBarrelPath(specifier) {
if (!specifier?.startsWith('@ember/') && !specifier?.startsWith('@glimmer/')) return null;
for (const ext of ['.ts', '.js']) {
const p = path.join(PACKAGES_ROOT, specifier, `index${ext}`);
if (fs.existsSync(p)) return p;
}
return null;
}
function resolveImportSource(spec, fromFile) {
if (!spec.startsWith('.')) return resolveBarrelPath(spec);
const base = path.resolve(path.dirname(fromFile), spec);
for (const c of [
base,
base + '.ts',
base + '.js',
path.join(base, 'index.ts'),
path.join(base, 'index.js'),
]) {
if (fs.existsSync(c)) return c;
}
return null;
}
// A name may be exported both as a value and as a type with the same identifier
// (e.g. `export const X = ...; export type X = typeof X`). When merging entries
// for the same name, treat the export as a value if any declaration is a value.
function setExport(exports, name, entry) {
const existing = exports.get(name);
if (existing) {
exports.set(name, { ...entry, isType: existing.isType && entry.isType });
} else {
exports.set(name, entry);
}
}
function declarationNames(decl) {
if (!decl) return [];
switch (decl.type) {
case 'VariableDeclaration':
return decl.declarations
.filter((v) => v.id?.type === 'Identifier')
.map((v) => ({ name: v.id.name, isType: false }));
case 'FunctionDeclaration':
case 'ClassDeclaration':
case 'TSEnumDeclaration':
return decl.id ? [{ name: decl.id.name, isType: false }] : [];
case 'TSInterfaceDeclaration':
case 'TSTypeAliasDeclaration':
case 'TSModuleDeclaration':
return decl.id?.name ? [{ name: decl.id.name, isType: true }] : [];
default:
return [];
}
}
function getModuleExports(filepath, stack = new Set()) {
if (moduleCache.has(filepath)) return moduleCache.get(filepath);
if (stack.has(filepath)) return new Map();
stack.add(filepath);
let ast;
try {
ast = parse(fs.readFileSync(filepath, 'utf8'), { jsx: false, range: true, loc: true });
} catch {
moduleCache.set(filepath, null);
stack.delete(filepath);
return null;
}
const localImports = collectLocalImports(ast.body);
const exports = new Map();
for (const stmt of ast.body) {
if (stmt.type === 'ExportNamedDeclaration')
collectNamedExports(stmt, exports, filepath, stack, localImports);
else if (stmt.type === 'ExportAllDeclaration')
collectStarExports(stmt, exports, filepath, stack);
else if (stmt.type === 'ExportDefaultDeclaration') {
setExport(exports, 'default', {
source: filepath,
localName: 'default',
isType: false,
kind: 'local',
});
}
}
moduleCache.set(filepath, exports);
stack.delete(filepath);
return exports;
}
// Collect value-level named/default imports so that `export const X = Y`
// can be resolved as a re-export of Y's original source. We skip type-only
// imports (they can't legally appear in a value-position initializer).
function collectLocalImports(body) {
const map = new Map();
for (const stmt of body) {
if (stmt.type !== 'ImportDeclaration') continue;
if (stmt.importKind === 'type') continue;
const sourceSpec = stmt.source.value;
for (const spec of stmt.specifiers) {
if (spec.importKind === 'type') continue;
if (spec.type === 'ImportSpecifier') {
map.set(spec.local.name, { sourceSpec, importedName: idOrStr(spec.imported) });
} else if (spec.type === 'ImportDefaultSpecifier') {
map.set(spec.local.name, { sourceSpec, importedName: 'default' });
}
}
}
return map;
}
// Strip TS `as`/type-assertion wrappers from an initializer and return the
// inner identifier name if the whole expression is just `Ident (as T)*`.
function unwrapAliasInit(node) {
let cur = node;
while (cur && (cur.type === 'TSAsExpression' || cur.type === 'TSTypeAssertion')) {
cur = cur.expression;
}
return cur && cur.type === 'Identifier' ? cur.name : null;
}
function buildAliasExport(importEntry, fromFile, stack, stmtIsType) {
const { sourceSpec, importedName } = importEntry;
const targetFile = resolveImportSource(sourceSpec, fromFile);
const isBare = !sourceSpec.startsWith('.');
let source = targetFile;
let bareSource = !targetFile && isBare ? sourceSpec : null;
let local = importedName;
if (targetFile) {
const nested = getModuleExports(targetFile, stack);
const nestedEntry = nested?.get(importedName);
if (nestedEntry && nestedEntry.kind !== 'namespace') {
if (nestedEntry.source) {
source = nestedEntry.source;
bareSource = null;
local = nestedEntry.localName;
} else if (nestedEntry.bareSource) {
source = null;
bareSource = nestedEntry.bareSource;
local = nestedEntry.localName;
}
}
}
return { source, bareSource, localName: local, isType: stmtIsType, kind: 'named' };
}
function collectNamedExports(stmt, exports, filepath, stack, localImports) {
const stmtIsType = stmt.exportKind === 'type';
if (stmt.declaration) {
// `export const X = Y [as T]` where Y is a top-level imported binding is
// treated as a re-export of Y's original source. This intentionally drops
// any branding/cast type — internal call sites don't need it, and it lets
// consumers import the implementation directly for tree-shaking.
if (stmt.declaration.type === 'VariableDeclaration') {
for (const v of stmt.declaration.declarations) {
if (v.id?.type !== 'Identifier') continue;
const name = v.id.name;
const aliased = v.init ? unwrapAliasInit(v.init) : null;
const importEntry = aliased ? localImports.get(aliased) : null;
if (importEntry) {
setExport(exports, name, buildAliasExport(importEntry, filepath, stack, stmtIsType));
} else {
setExport(exports, name, {
source: filepath,
localName: name,
isType: stmtIsType,
kind: 'local',
});
}
}
return;
}
for (const { name, isType } of declarationNames(stmt.declaration)) {
setExport(exports, name, {
source: filepath,
localName: name,
isType: isType || stmtIsType,
kind: 'local',
});
}
return;
}
if (!stmt.source) {
for (const spec of stmt.specifiers ?? []) {
if (spec.type !== 'ExportSpecifier') continue;
setExport(exports, idOrStr(spec.exported), {
source: filepath,
localName: idOrStr(spec.local),
isType: stmtIsType || spec.exportKind === 'type',
kind: 'local',
});
}
return;
}
const sourceSpec = stmt.source.value;
const targetFile = resolveImportSource(sourceSpec, filepath);
const isBare = !sourceSpec.startsWith('.');
const nested = targetFile ? getModuleExports(targetFile, stack) : null;
for (const spec of stmt.specifiers) {
if (spec.type !== 'ExportSpecifier') continue;
const isType = stmtIsType || spec.exportKind === 'type';
let source = targetFile;
let bareSource = !targetFile && isBare ? sourceSpec : null;
let local = idOrStr(spec.local);
const nestedEntry = nested?.get(local);
if (nestedEntry && nestedEntry.kind !== 'namespace') {
if (nestedEntry.source) {
source = nestedEntry.source;
bareSource = null;
local = nestedEntry.localName;
} else if (nestedEntry.bareSource) {
source = null;
bareSource = nestedEntry.bareSource;
local = nestedEntry.localName;
}
}
setExport(exports, idOrStr(spec.exported), {
source,
bareSource,
localName: local,
isType,
kind: 'named',
});
}
}
function collectStarExports(stmt, exports, filepath, stack) {
const stmtIsType = stmt.exportKind === 'type';
const targetFile = resolveImportSource(stmt.source.value, filepath);
if (stmt.exported) {
setExport(exports, idOrStr(stmt.exported), {
source: targetFile,
isType: stmtIsType,
kind: 'namespace',
});
return;
}
if (!targetFile) return;
const nested = getModuleExports(targetFile, stack);
if (!nested) return;
for (const [name, entry] of nested) {
if (name === 'default' || exports.has(name)) continue;
exports.set(name, { ...entry, isType: entry.isType || stmtIsType });
}
}
const SCOPE_PREFIXES = [
path.join(PACKAGES_ROOT, '@ember') + path.sep,
path.join(PACKAGES_ROOT, '@glimmer') + path.sep,
];
const EXCLUDED_FILE_PREFIXES = [path.join(PACKAGES_ROOT, '@glimmer/component') + path.sep];
const TEST_DIR_RE = /[\\/](?:test|tests)[\\/]/;
const isInScope = (filename) => SCOPE_PREFIXES.some((p) => filename.startsWith(p));
const isExcludedFile = (filename) => EXCLUDED_FILE_PREFIXES.some((p) => filename.startsWith(p));
const isInTestFile = (filename) =>
TEST_DIR_RE.test(filename) || filename.includes(`${path.sep}internal-test-helpers${path.sep}`);
const stripExt = (p) => p.replace(/\.(?:d\.ts|[mc]?[jt]sx?)$/, '');
const toPosix = (p) => (path.sep === '/' ? p : p.replaceAll(path.sep, '/'));
// Map an absolute file path back to (packageRoot, bareSpec) by convention:
// `@ember/-internals/<x>` is depth-3, all other `@ember/<x>` and `@glimmer/<x>` are depth-2.
function getPackageInfo(absFile) {
if (!absFile.startsWith(PACKAGES_ROOT + path.sep)) return null;
const parts = toPosix(absFile.slice(PACKAGES_ROOT.length + 1)).split('/');
const depth = parts[0] === '@ember' && parts[1] === '-internals' ? 3 : 2;
const bareSpec = parts.slice(0, depth).join('/');
return { packageRoot: path.join(PACKAGES_ROOT, ...bareSpec.split('/')), bareSpec };
}
function findOwningPackage(absFile) {
if (owningPackageCache.has(absFile)) return owningPackageCache.get(absFile);
let dir = path.dirname(absFile);
let result = null;
while (dir.length >= PACKAGES_ROOT.length && dir.startsWith(PACKAGES_ROOT)) {
if (fs.existsSync(path.join(dir, 'package.json'))) {
result = dir;
break;
}
dir = path.dirname(dir);
}
owningPackageCache.set(absFile, result);
return result;
}
function packageHasWildcardSourceExports(packageRoot) {
if (wildcardExportsCache.has(packageRoot)) return wildcardExportsCache.get(packageRoot);
let allowed = false;
try {
const pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
const wildcard = pkg.exports?.['./*'];
const matches = (v) => v === './*.ts';
allowed =
matches(wildcard) ||
(wildcard && typeof wildcard === 'object' && Object.values(wildcard).some(matches));
} catch {
/* ignore */
}
wildcardExportsCache.set(packageRoot, allowed);
return allowed;
}
function computeNewSpecifier(targetAbs, currentFile) {
const targetInfo = getPackageInfo(targetAbs);
if (!targetInfo) return null;
const tail = toPosix(path.relative(targetInfo.packageRoot, targetAbs));
// If the target IS the package's own index file, use just the bare specifier
// (any `/index` suffix is redundant and confuses TS's module resolution).
const isPackageIndex = /^index\.[mc]?[jt]sx?$/.test(tail);
const currentInfo = getPackageInfo(currentFile);
if (currentInfo?.bareSpec === targetInfo.bareSpec) {
let rel = toPosix(path.relative(path.dirname(currentFile), targetAbs));
if (!rel.startsWith('.')) rel = './' + rel;
return { newSpec: stripExt(rel), deep: false };
}
if (isPackageIndex) {
return { newSpec: targetInfo.bareSpec, deep: false };
}
return {
newSpec: stripExt(path.posix.join(targetInfo.bareSpec, tail)),
deep: true,
owningPackageRoot: findOwningPackage(targetAbs),
};
}
function specPart(item, statementIsType) {
const typePrefix = !statementIsType && item.isType ? 'type ' : '';
if (item.sourceName === item.localName) return `${typePrefix}${item.sourceName}`;
return `${typePrefix}${item.sourceName} as ${item.localName}`;
}
function buildImportStatements(groups, allTypes) {
const out = [];
for (const [newSpec, items] of groups) {
const useType = allTypes || items.every((it) => it.isType);
const typeKw = useType ? 'type ' : '';
if (items.length === 1 && items[0].sourceName === 'default') {
out.push(`import ${typeKw}${items[0].localName} from '${newSpec}';`);
} else {
const parts = items.map((it) => specPart(it, useType));
out.push(`import ${typeKw}{ ${parts.join(', ')} } from '${newSpec}';`);
}
}
return out.join('\n');
}
function buildExportStatements(groups, allTypes) {
const out = [];
for (const [newSpec, items] of groups) {
const useType = allTypes || items.every((it) => it.isType);
const typeKw = useType ? 'type ' : '';
const parts = items.map((it) => {
const tp = !useType && it.isType ? 'type ' : '';
return it.sourceName === it.exportedName
? `${tp}${it.sourceName}`
: `${tp}${it.sourceName} as ${it.exportedName}`;
});
out.push(`export ${typeKw}{ ${parts.join(', ')} } from '${newSpec}';`);
}
return out.join('\n');
}
function pushGroup(groups, key, item) {
const items = groups.get(key) ?? [];
items.push(item);
groups.set(key, items);
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
fixable: 'code',
schema: [],
docs: {
description:
'Disallow imports from barrel index files within @ember and @glimmer source code; prefer direct imports from source files for tree-shaking.',
},
messages: {
barrelImport:
'Avoid importing from the "{{spec}}" barrel; import directly from the source file ({{names}}).',
barrelImportUnresolved:
'Avoid importing from the "{{spec}}" barrel; import directly from the source file. Could not auto-fix: {{names}}.',
missingWildcardExports:
'Avoid importing from the "{{spec}}" barrel. Cannot auto-fix because {{packages}} {{verb}} missing `"./*": "./*.ts"` in the `exports` field — add it to enable direct imports.',
},
},
create(context) {
const { filename } = context;
if (!filename || !isInScope(filename) || isInTestFile(filename) || isExcludedFile(filename)) {
return {};
}
function resolveSpecifier(moduleExports, importedName, barrelPath, originalSpec) {
const entry = moduleExports.get(importedName);
if (!entry) return { unresolved: true };
if (entry.source === barrelPath) return { local: true };
let newSpec;
let owningPackageRoot = null;
if (entry.source) {
const computed = computeNewSpecifier(entry.source, filename);
newSpec = computed?.newSpec;
if (computed?.deep) owningPackageRoot = computed.owningPackageRoot;
} else if (entry.bareSource && entry.bareSource !== originalSpec) {
newSpec = entry.bareSource;
}
if (!newSpec) return { unresolved: true };
return {
newSpecifier: newSpec,
localName: entry.localName,
isType: entry.isType,
namespace: entry.kind === 'namespace',
owningPackageRoot,
};
}
function reportUnresolved(node, spec, names) {
context.report({
node,
messageId: 'barrelImportUnresolved',
data: { spec, names: names.join(', ') || '(see above)' },
});
}
function reportMissingExports(node, spec, packageRoots) {
const paths = [...packageRoots]
.map((root) => path.relative(WORKSPACE_ROOT, path.join(root, 'package.json')))
.sort();
context.report({
node,
messageId: 'missingWildcardExports',
data: {
spec,
packages: paths.join(', '),
verb: paths.length > 1 ? 'are' : 'is',
},
});
}
function collectMissingExports(items) {
const missing = new Set();
for (const item of items) {
if (item.owningPackageRoot && !packageHasWildcardSourceExports(item.owningPackageRoot)) {
missing.add(item.owningPackageRoot);
}
}
return missing;
}
function check(node) {
const spec = node.source?.value;
if (typeof spec !== 'string') return;
if (EXCLUDED_BARRELS.has(spec)) return;
const barrelPath = resolveBarrelPath(spec);
if (!barrelPath || filename === barrelPath) return;
const moduleExports = getModuleExports(barrelPath);
if (!moduleExports) {
reportUnresolved(node, spec, ['(could not parse barrel)']);
return;
}
if (node.type === 'ImportDeclaration')
return handleImport(node, moduleExports, spec, barrelPath);
if (node.type === 'ExportNamedDeclaration')
return handleExportNamed(node, moduleExports, spec, barrelPath);
if (node.type === 'ExportAllDeclaration') reportUnresolved(node, spec, ['*']);
}
function handleImport(node, moduleExports, spec, barrelPath) {
const isWholeTypeImport = node.importKind === 'type';
const groups = new Map();
const namespaceImports = [];
const kept = []; // specifiers that must stay with the original barrel spec
const unresolved = [];
let allLocal = node.specifiers.length > 0;
for (const sp of node.specifiers) {
if (sp.type === 'ImportNamespaceSpecifier') {
unresolved.push('* as ' + sp.local.name);
allLocal = false;
continue;
}
const importedName =
sp.type === 'ImportDefaultSpecifier'
? 'default'
: sp.type === 'ImportSpecifier'
? idOrStr(sp.imported)
: null;
if (importedName === null) continue;
const local = sp.local.name;
const specIsType = isWholeTypeImport || sp.importKind === 'type';
const r = resolveSpecifier(moduleExports, importedName, barrelPath, spec);
if (r.local) {
kept.push({ sourceName: importedName, localName: local, isType: specIsType });
continue;
}
allLocal = false;
if (r.unresolved) {
unresolved.push(importedName);
continue;
}
if (r.namespace) {
namespaceImports.push({
newSpec: r.newSpecifier,
localName: local,
isType: specIsType || r.isType,
owningPackageRoot: r.owningPackageRoot,
});
continue;
}
pushGroup(groups, r.newSpecifier, {
sourceName: r.localName,
localName: local,
isType: specIsType || r.isType,
owningPackageRoot: r.owningPackageRoot,
});
}
if (allLocal) return;
if (unresolved.length > 0) {
reportUnresolved(node, spec, unresolved);
return;
}
if (groups.size === 0 && namespaceImports.length === 0) return;
const allItems = [...namespaceImports, ...[...groups.values()].flat()];
const missing = collectMissingExports(allItems);
if (missing.size > 0) {
reportMissingExports(node, spec, missing);
return;
}
// Locally-defined symbols stay with the original barrel — they can't
// be sourced from a sub-file because they don't live in one.
for (const item of kept) pushGroup(groups, spec, item);
const statements = namespaceImports.map((ns) => {
const useType = isWholeTypeImport || ns.isType;
return `import ${useType ? 'type ' : ''}* as ${ns.localName} from '${ns.newSpec}';`;
});
if (groups.size > 0) statements.push(buildImportStatements(groups, isWholeTypeImport));
const allSpecs = [...namespaceImports.map((n) => n.newSpec), ...groups.keys()];
context.report({
node,
messageId: 'barrelImport',
data: { spec, names: allSpecs.join(', ') },
fix: (fixer) => fixer.replaceText(node, statements.join('\n')),
});
}
function handleExportNamed(node, moduleExports, spec, barrelPath) {
const isWholeTypeExport = node.exportKind === 'type';
const groups = new Map();
const namespaceExports = [];
const kept = [];
const unresolved = [];
let allLocal = node.specifiers.length > 0;
for (const sp of node.specifiers) {
if (sp.type !== 'ExportSpecifier') continue;
const importedName = idOrStr(sp.local);
const exportedName = idOrStr(sp.exported);
const specIsType = isWholeTypeExport || sp.exportKind === 'type';
const r = resolveSpecifier(moduleExports, importedName, barrelPath, spec);
if (r.local) {
kept.push({ sourceName: importedName, exportedName, isType: specIsType });
continue;
}
allLocal = false;
if (r.unresolved) {
unresolved.push(importedName);
continue;
}
if (r.namespace) {
namespaceExports.push({
newSpec: r.newSpecifier,
exportedName,
isType: specIsType || r.isType,
owningPackageRoot: r.owningPackageRoot,
});
continue;
}
pushGroup(groups, r.newSpecifier, {
sourceName: r.localName,
exportedName,
isType: specIsType || r.isType,
owningPackageRoot: r.owningPackageRoot,
});
}
if (allLocal) return;
if (unresolved.length > 0) {
reportUnresolved(node, spec, unresolved);
return;
}
if (groups.size === 0 && namespaceExports.length === 0) return;
const allItems = [...namespaceExports, ...[...groups.values()].flat()];
const missing = collectMissingExports(allItems);
if (missing.size > 0) {
reportMissingExports(node, spec, missing);
return;
}
for (const item of kept) pushGroup(groups, spec, item);
const statements = namespaceExports.map((ns) => {
const useType = isWholeTypeExport || ns.isType;
return `export ${useType ? 'type ' : ''}* as ${ns.exportedName} from '${ns.newSpec}';`;
});
if (groups.size > 0) statements.push(buildExportStatements(groups, isWholeTypeExport));
const allSpecs = [...namespaceExports.map((n) => n.newSpec), ...groups.keys()];
context.report({
node,
messageId: 'barrelImport',
data: { spec, names: allSpecs.join(', ') },
fix: (fixer) => fixer.replaceText(node, statements.join('\n')),
});
}
return {
ImportDeclaration: check,
ExportNamedDeclaration: (node) => node.source && check(node),
ExportAllDeclaration: check,
};
},
};