@christiango/unbarrel 0.10.2 → 0.10.4
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/lib/fixIssuesInBarrelFile.d.ts.map +1 -1
- package/lib/fixIssuesInBarrelFile.js +162 -56
- package/lib/fixIssuesInBarrelFile.js.map +1 -1
- package/lib/getIssuesInBarrelFile.d.ts +9 -0
- package/lib/getIssuesInBarrelFile.d.ts.map +1 -1
- package/lib/getIssuesInBarrelFile.js +30 -16
- package/lib/getIssuesInBarrelFile.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixIssuesInBarrelFile.d.ts","sourceRoot":"","sources":["../src/fixIssuesInBarrelFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixIssuesInBarrelFile.d.ts","sourceRoot":"","sources":["../src/fixIssuesInBarrelFile.ts"],"names":[],"mappings":"AA8HA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,QAyH7D"}
|
|
@@ -42,61 +42,96 @@ const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
|
42
42
|
const generator_1 = __importDefault(require("@babel/generator"));
|
|
43
43
|
const t = __importStar(require("@babel/types"));
|
|
44
44
|
const flattenExportStar_1 = require("./flattenExportStar");
|
|
45
|
+
const getExportDefinitionFromReExport_1 = require("./getExportDefinitionFromReExport");
|
|
45
46
|
const parseUtils_1 = require("./parseUtils");
|
|
47
|
+
const getIssuesInBarrelFile_1 = require("./getIssuesInBarrelFile");
|
|
48
|
+
const importUtils_1 = require("./importUtils");
|
|
46
49
|
/**
|
|
47
50
|
* Groups resolved exports by their import path
|
|
48
51
|
*/
|
|
49
52
|
function groupExportsByPath(exports) {
|
|
50
|
-
const
|
|
53
|
+
const grouped = new Map();
|
|
51
54
|
for (const exp of exports) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
const list = grouped.get(exp.importPath) || [];
|
|
56
|
+
list.push(exp);
|
|
57
|
+
grouped.set(exp.importPath, list);
|
|
55
58
|
}
|
|
56
|
-
return
|
|
59
|
+
return grouped;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
|
-
*
|
|
62
|
+
* Deduplicates exports by exportedName.
|
|
63
|
+
* Value exports take precedence over type-only exports.
|
|
60
64
|
*/
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
for (const
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// Set exportKind to 'type' for type-only exports
|
|
69
|
-
if (e.typeOnly) {
|
|
70
|
-
specifier.exportKind = 'type';
|
|
71
|
-
}
|
|
72
|
-
return specifier;
|
|
73
|
-
});
|
|
74
|
-
const exportDecl = t.exportNamedDeclaration(null, specifiers, t.stringLiteral(importPath));
|
|
75
|
-
statements.push(exportDecl);
|
|
65
|
+
function deduplicateExports(exports) {
|
|
66
|
+
const byName = new Map();
|
|
67
|
+
for (const exp of exports) {
|
|
68
|
+
const existing = byName.get(exp.exportedName);
|
|
69
|
+
if (!existing || (existing.typeOnly && !exp.typeOnly)) {
|
|
70
|
+
byName.set(exp.exportedName, exp);
|
|
71
|
+
}
|
|
76
72
|
}
|
|
77
|
-
return
|
|
73
|
+
return Array.from(byName.values());
|
|
78
74
|
}
|
|
79
75
|
/**
|
|
80
|
-
*
|
|
81
|
-
* When there are multiple exports with the same name, value exports (typeOnly: false)
|
|
82
|
-
* take precedence over type-only exports (typeOnly: true), because a value export
|
|
83
|
-
* can be used as both a value and a type (via typeof).
|
|
76
|
+
* Creates an export specifier AST node from a resolved export
|
|
84
77
|
*/
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
function createExportSpecifier(exp) {
|
|
79
|
+
const specifier = t.exportSpecifier(t.identifier(exp.importedName), t.identifier(exp.exportedName));
|
|
80
|
+
if (exp.typeOnly) {
|
|
81
|
+
specifier.exportKind = 'type';
|
|
82
|
+
}
|
|
83
|
+
return specifier;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Fixes barrel file references by resolving exports to their true source
|
|
87
|
+
*/
|
|
88
|
+
function fixBarrelFileReferences(absoluteFilePath, nodesToFix, barrelRefNames) {
|
|
89
|
+
for (const nodePath of nodesToFix) {
|
|
90
|
+
const sourcePath = nodePath.node.source.value;
|
|
91
|
+
const resolvedByPath = new Map();
|
|
92
|
+
const unchangedSpecifiers = [];
|
|
93
|
+
for (const specifier of nodePath.node.specifiers) {
|
|
94
|
+
if (specifier.type !== 'ExportSpecifier' || specifier.exported.type !== 'Identifier') {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const exportedName = specifier.exported.name;
|
|
98
|
+
const importedName = specifier.local.name;
|
|
99
|
+
const typeOnly = specifier.exportKind === 'type' || nodePath.node.exportKind === 'type';
|
|
100
|
+
if (!barrelRefNames.has(exportedName)) {
|
|
101
|
+
unchangedSpecifiers.push(specifier);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
// Resolve this export to its true source
|
|
105
|
+
const resolved = (0, getExportDefinitionFromReExport_1.getExportDefinitionFromReExport)(absoluteFilePath, {
|
|
106
|
+
type: importedName === 'default' ? 'defaultExport' : 'namedExport',
|
|
107
|
+
importedName,
|
|
108
|
+
exportedName,
|
|
109
|
+
importPath: sourcePath,
|
|
110
|
+
typeOnly,
|
|
111
|
+
});
|
|
112
|
+
const newSpecifier = t.exportSpecifier(t.identifier(resolved.importedName), t.identifier(resolved.exportedName));
|
|
113
|
+
if (resolved.typeOnly || typeOnly) {
|
|
114
|
+
newSpecifier.exportKind = 'type';
|
|
115
|
+
}
|
|
116
|
+
const list = resolvedByPath.get(resolved.importPath) || [];
|
|
117
|
+
list.push(newSpecifier);
|
|
118
|
+
resolvedByPath.set(resolved.importPath, list);
|
|
119
|
+
}
|
|
120
|
+
// Build replacement statements
|
|
121
|
+
const newStatements = [];
|
|
122
|
+
if (unchangedSpecifiers.length > 0) {
|
|
123
|
+
newStatements.push(t.exportNamedDeclaration(null, unchangedSpecifiers, t.stringLiteral(sourcePath)));
|
|
124
|
+
}
|
|
125
|
+
for (const [importPath, specifiers] of resolvedByPath) {
|
|
126
|
+
newStatements.push(t.exportNamedDeclaration(null, specifiers, t.stringLiteral(importPath)));
|
|
92
127
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
128
|
+
if (newStatements.length > 0) {
|
|
129
|
+
nodePath.replaceWithMultiple(newStatements);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
nodePath.remove();
|
|
96
133
|
}
|
|
97
|
-
// Otherwise keep the existing export (either both are same typeOnly, or existing is value and new is type)
|
|
98
134
|
}
|
|
99
|
-
return Array.from(exportsByName.values());
|
|
100
135
|
}
|
|
101
136
|
/**
|
|
102
137
|
* Fixes any issues in the referenced barrel file.
|
|
@@ -104,40 +139,111 @@ function deduplicateExports(exports) {
|
|
|
104
139
|
*/
|
|
105
140
|
function fixIssuesInBarrelFile(absoluteFilePath) {
|
|
106
141
|
const ast = (0, parseUtils_1.parseTypescriptFile)(absoluteFilePath);
|
|
107
|
-
// Collect all
|
|
142
|
+
// Collect all exports and detect issues in a single traverse pass
|
|
143
|
+
const existingExportsByName = new Map();
|
|
144
|
+
const existingStatementsByPath = new Map();
|
|
108
145
|
const exportStarPaths = [];
|
|
109
146
|
const allFlattenedExports = [];
|
|
147
|
+
const barrelRefExportsToFix = [];
|
|
148
|
+
const barrelFileRefs = new Set();
|
|
110
149
|
(0, traverse_1.default)(ast, {
|
|
150
|
+
ExportNamedDeclaration(path) {
|
|
151
|
+
if (!path.node.source)
|
|
152
|
+
return;
|
|
153
|
+
const sourcePath = path.node.source.value;
|
|
154
|
+
const namedExport = {
|
|
155
|
+
path,
|
|
156
|
+
sourcePath,
|
|
157
|
+
};
|
|
158
|
+
existingStatementsByPath.set(namedExport.sourcePath, namedExport);
|
|
159
|
+
let hasBarrelRef = false;
|
|
160
|
+
path.node.specifiers.forEach((specifier, i) => {
|
|
161
|
+
if (specifier.type === 'ExportSpecifier' && specifier.exported.type === 'Identifier') {
|
|
162
|
+
const exportedName = specifier.exported.name;
|
|
163
|
+
const importedName = specifier.local.name;
|
|
164
|
+
existingExportsByName.set(exportedName, {
|
|
165
|
+
namedExport,
|
|
166
|
+
specifierIndex: i,
|
|
167
|
+
typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
|
|
168
|
+
});
|
|
169
|
+
// Check if this specifier is a barrel file reference
|
|
170
|
+
if ((0, importUtils_1.isInternalModule)(sourcePath) && (0, getIssuesInBarrelFile_1.isBarrelFileReference)(absoluteFilePath, sourcePath, importedName)) {
|
|
171
|
+
barrelFileRefs.add(exportedName);
|
|
172
|
+
hasBarrelRef = true;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
if (hasBarrelRef) {
|
|
177
|
+
barrelRefExportsToFix.push(path);
|
|
178
|
+
}
|
|
179
|
+
},
|
|
111
180
|
ExportAllDeclaration(path) {
|
|
112
|
-
const importPath = path.node.source.value;
|
|
113
|
-
// Check if this is `export type *` (type-only export star)
|
|
114
181
|
const isExportTypeStar = path.node.exportKind === 'type';
|
|
115
|
-
|
|
116
|
-
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, importPath, isExportTypeStar);
|
|
182
|
+
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, path.node.source.value, isExportTypeStar);
|
|
117
183
|
exportStarPaths.push(path);
|
|
118
184
|
allFlattenedExports.push(...flattened);
|
|
119
185
|
},
|
|
120
186
|
});
|
|
187
|
+
// Handle barrel file references
|
|
188
|
+
if (barrelRefExportsToFix.length > 0) {
|
|
189
|
+
fixBarrelFileReferences(absoluteFilePath, barrelRefExportsToFix, barrelFileRefs);
|
|
190
|
+
}
|
|
121
191
|
if (exportStarPaths.length === 0) {
|
|
192
|
+
if (barrelRefExportsToFix.length > 0) {
|
|
193
|
+
const output = (0, generator_1.default)(ast, { retainLines: false, comments: true });
|
|
194
|
+
fs.writeFileSync(absoluteFilePath, output.code, 'utf8');
|
|
195
|
+
}
|
|
122
196
|
return;
|
|
123
197
|
}
|
|
124
|
-
// Deduplicate
|
|
198
|
+
// Deduplicate and filter exports
|
|
125
199
|
const deduplicated = deduplicateExports(allFlattenedExports);
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
200
|
+
const toRemove = [];
|
|
201
|
+
const filteredExports = deduplicated.filter((exp) => {
|
|
202
|
+
const existing = existingExportsByName.get(exp.exportedName);
|
|
203
|
+
if (!existing)
|
|
204
|
+
return true;
|
|
205
|
+
// Upgrade type-only to value export
|
|
206
|
+
if (existing.typeOnly && !exp.typeOnly) {
|
|
207
|
+
toRemove.push(existing);
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
});
|
|
212
|
+
// Remove specifiers being upgraded from type to value
|
|
213
|
+
for (const { namedExport, specifierIndex } of toRemove) {
|
|
214
|
+
const specifiers = namedExport.path.node.specifiers;
|
|
215
|
+
if (specifiers.length === 1) {
|
|
216
|
+
namedExport.path.remove();
|
|
217
|
+
existingStatementsByPath.delete(namedExport.sourcePath);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
specifiers.splice(specifierIndex, 1);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Group filtered exports and create/update statements
|
|
224
|
+
const grouped = groupExportsByPath(filteredExports);
|
|
225
|
+
const newStatements = [];
|
|
226
|
+
for (const [importPath, exps] of grouped) {
|
|
227
|
+
const existing = existingStatementsByPath.get(importPath);
|
|
228
|
+
if (existing) {
|
|
229
|
+
existing.path.node.specifiers.push(...exps.map(createExportSpecifier));
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
newStatements.push(t.exportNamedDeclaration(null, exps.map(createExportSpecifier), t.stringLiteral(importPath)));
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Replace export stars
|
|
236
|
+
if (newStatements.length > 0) {
|
|
237
|
+
exportStarPaths[0].replaceWithMultiple(newStatements);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
exportStarPaths[0].remove();
|
|
241
|
+
}
|
|
133
242
|
for (let i = 1; i < exportStarPaths.length; i++) {
|
|
134
243
|
exportStarPaths[i].remove();
|
|
135
244
|
}
|
|
136
|
-
//
|
|
137
|
-
const output = (0, generator_1.default)(ast, {
|
|
138
|
-
retainLines: false,
|
|
139
|
-
comments: true,
|
|
140
|
-
});
|
|
245
|
+
// Write output
|
|
246
|
+
const output = (0, generator_1.default)(ast, { retainLines: false, comments: true });
|
|
141
247
|
fs.writeFileSync(absoluteFilePath, output.code, 'utf8');
|
|
142
248
|
}
|
|
143
249
|
//# sourceMappingURL=fixIssuesInBarrelFile.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/fixIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"fixIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/fixIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,sDAyHC;AA3PD,4CAA8B;AAE9B,+DAAuC;AACvC,iEAAwC;AACxC,gDAAkC;AAClC,2DAAwD;AACxD,uFAA8G;AAC9G,6CAAmD;AACnD,mEAAgE;AAChE,+CAAiD;AAEjD;;GAEG;AACH,SAAS,kBAAkB,CAAC,OAAmC;IAC7D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC9D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,IAAI,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E,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACnH,CAAC;IACH,CAAC;IAED,uBAAuB;IACvB,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC7B,eAAe,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IACxD,CAAC;SAAM,CAAC;QACN,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAChD,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED,eAAe;IACf,MAAM,MAAM,GAAG,IAAA,mBAAQ,EAAC,GAAG,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -12,6 +12,15 @@ export interface ExportAllError {
|
|
|
12
12
|
barrelFilePath: string;
|
|
13
13
|
}
|
|
14
14
|
export type BarrelFileIssue = BarrelFileReferenceError | ExportAllError;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if a named re-export is a barrel file reference (i.e., re-exports from an intermediate barrel file
|
|
17
|
+
* rather than from the module that defines the export).
|
|
18
|
+
* @param absoluteFilePath - The absolute path of the module containing the re-export
|
|
19
|
+
* @param importPath - The import path of the re-export (must be an internal/relative path)
|
|
20
|
+
* @param importedName - The name being imported from the target module
|
|
21
|
+
* @returns true if this is a barrel file reference
|
|
22
|
+
*/
|
|
23
|
+
export declare function isBarrelFileReference(absoluteFilePath: string, importPath: string, importedName: string): boolean;
|
|
15
24
|
/**
|
|
16
25
|
* Analyzes the exports of the provided file and returns any references to barrel files within the current package. External packages are not included.
|
|
17
26
|
* @param absoluteFilePath The absolute path the the file we will analyze
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIssuesInBarrelFile.d.ts","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":"AAKA,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,qBAAqB,CAAC;IAE5B,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IAErB,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG,wBAAwB,GAAG,cAAc,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"getIssuesInBarrelFile.d.ts","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":"AAKA,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,qBAAqB,CAAC;IAE5B,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IAErB,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG,wBAAwB,GAAG,cAAc,CAAC;AAExE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAmBjH;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,eAAe,EAAE,CAgCjF"}
|
|
@@ -3,11 +3,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isBarrelFileReference = isBarrelFileReference;
|
|
6
7
|
exports.getIssuesInBarrelFile = getIssuesInBarrelFile;
|
|
7
8
|
const getExportsFromModule_1 = require("./getExportsFromModule");
|
|
8
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
10
|
const resolveModulePath_1 = require("./resolveModulePath");
|
|
10
11
|
const importUtils_1 = require("./importUtils");
|
|
12
|
+
/**
|
|
13
|
+
* Checks if a named re-export is a barrel file reference (i.e., re-exports from an intermediate barrel file
|
|
14
|
+
* rather than from the module that defines the export).
|
|
15
|
+
* @param absoluteFilePath - The absolute path of the module containing the re-export
|
|
16
|
+
* @param importPath - The import path of the re-export (must be an internal/relative path)
|
|
17
|
+
* @param importedName - The name being imported from the target module
|
|
18
|
+
* @returns true if this is a barrel file reference
|
|
19
|
+
*/
|
|
20
|
+
function isBarrelFileReference(absoluteFilePath, importPath, importedName) {
|
|
21
|
+
const targetFilePath = (0, resolveModulePath_1.resolveModulePath)(node_path_1.default.resolve(node_path_1.default.dirname(absoluteFilePath), importPath));
|
|
22
|
+
const targetExports = (0, getExportsFromModule_1.getExportsFromModule)(targetFilePath);
|
|
23
|
+
// Check if the name exists as a definition in the target module
|
|
24
|
+
const matchingExport = targetExports.definitions.find((definition) => definition.type === 'namedExport' && definition.name === importedName);
|
|
25
|
+
if (matchingExport) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
// Check if it's a re-export from an internal module (barrel file reference)
|
|
29
|
+
const matchingReExport = targetExports.reExports.find((reExport) => reExport.type === 'namedExport' && reExport.exportedName === importedName);
|
|
30
|
+
return matchingReExport !== undefined && (0, importUtils_1.isInternalModule)(matchingReExport.importPath);
|
|
31
|
+
}
|
|
11
32
|
/**
|
|
12
33
|
* Analyzes the exports of the provided file and returns any references to barrel files within the current package. External packages are not included.
|
|
13
34
|
* @param absoluteFilePath The absolute path the the file we will analyze
|
|
@@ -24,22 +45,15 @@ function getIssuesInBarrelFile(absoluteFilePath) {
|
|
|
24
45
|
barrelFilePath: absoluteFilePath,
|
|
25
46
|
});
|
|
26
47
|
}
|
|
27
|
-
// Only consider internal modules (relative paths)
|
|
28
|
-
else if ((0, importUtils_1.isInternalModule)(reExportToVisit.importPath)) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (matchingReExport && (0, importUtils_1.isInternalModule)(matchingReExport.importPath)) {
|
|
37
|
-
result.push({
|
|
38
|
-
type: 'barrelFileReference',
|
|
39
|
-
exportedName: reExportToVisit.exportedName,
|
|
40
|
-
barrelFilePath: (0, importUtils_1.convertAbsolutePathToRelativeImportPath)(potentialBarrelFilePath, node_path_1.default.dirname(absoluteFilePath)),
|
|
41
|
-
});
|
|
42
|
-
}
|
|
48
|
+
// Only consider internal modules (relative paths) and named re-exports
|
|
49
|
+
else if (reExportToVisit.type === 'namedExport' && (0, importUtils_1.isInternalModule)(reExportToVisit.importPath)) {
|
|
50
|
+
if (isBarrelFileReference(absoluteFilePath, reExportToVisit.importPath, reExportToVisit.importedName)) {
|
|
51
|
+
const potentialBarrelFilePath = (0, resolveModulePath_1.resolveModulePath)(node_path_1.default.resolve(node_path_1.default.dirname(absoluteFilePath), reExportToVisit.importPath));
|
|
52
|
+
result.push({
|
|
53
|
+
type: 'barrelFileReference',
|
|
54
|
+
exportedName: reExportToVisit.exportedName,
|
|
55
|
+
barrelFilePath: (0, importUtils_1.convertAbsolutePathToRelativeImportPath)(potentialBarrelFilePath, node_path_1.default.dirname(absoluteFilePath)),
|
|
56
|
+
});
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"getIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;AAgCA,sDAmBC;AAOD,sDAgCC;AA1FD,iEAA8D;AAC9D,0DAA6B;AAC7B,2DAAwD;AACxD,+CAA0F;AAqB1F;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CAAC,gBAAwB,EAAE,UAAkB,EAAE,YAAoB;IACtG,MAAM,cAAc,GAAG,IAAA,qCAAiB,EAAC,mBAAI,CAAC,OAAO,CAAC,mBAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC,CAAC,CAAC;IACnG,MAAM,aAAa,GAAG,IAAA,2CAAoB,EAAC,cAAc,CAAC,CAAC;IAE3D,gEAAgE;IAChE,MAAM,cAAc,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,CACnD,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,aAAa,IAAI,UAAU,CAAC,IAAI,KAAK,YAAY,CACtF,CAAC;IAEF,IAAI,cAAc,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,4EAA4E;IAC5E,MAAM,gBAAgB,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CACnD,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,aAAa,IAAI,QAAQ,CAAC,YAAY,KAAK,YAAY,CACxF,CAAC;IAEF,OAAO,gBAAgB,KAAK,SAAS,IAAI,IAAA,8BAAgB,EAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;AACzF,CAAC;AAED;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,gBAAwB;IAC5D,MAAM,MA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