@christiango/unbarrel 0.10.1 → 0.10.3
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.
|
@@ -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":"AA2DA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,QA+F7D"}
|
|
@@ -47,48 +47,37 @@ const parseUtils_1 = require("./parseUtils");
|
|
|
47
47
|
* Groups resolved exports by their import path
|
|
48
48
|
*/
|
|
49
49
|
function groupExportsByPath(exports) {
|
|
50
|
-
const
|
|
50
|
+
const grouped = new Map();
|
|
51
51
|
for (const exp of exports) {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
const list = grouped.get(exp.importPath) || [];
|
|
53
|
+
list.push(exp);
|
|
54
|
+
grouped.set(exp.importPath, list);
|
|
55
55
|
}
|
|
56
|
-
return
|
|
56
|
+
return grouped;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
*
|
|
59
|
+
* Deduplicates exports by exportedName.
|
|
60
|
+
* Value exports take precedence over type-only exports.
|
|
60
61
|
*/
|
|
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);
|
|
62
|
+
function deduplicateExports(exports) {
|
|
63
|
+
const byName = new Map();
|
|
64
|
+
for (const exp of exports) {
|
|
65
|
+
const existing = byName.get(exp.exportedName);
|
|
66
|
+
if (!existing || (existing.typeOnly && !exp.typeOnly)) {
|
|
67
|
+
byName.set(exp.exportedName, exp);
|
|
68
|
+
}
|
|
76
69
|
}
|
|
77
|
-
return
|
|
70
|
+
return Array.from(byName.values());
|
|
78
71
|
}
|
|
79
72
|
/**
|
|
80
|
-
*
|
|
73
|
+
* Creates an export specifier AST node from a resolved export
|
|
81
74
|
*/
|
|
82
|
-
function
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (!seen.has(exp.exportedName)) {
|
|
87
|
-
seen.add(exp.exportedName);
|
|
88
|
-
result.push(exp);
|
|
89
|
-
}
|
|
75
|
+
function createExportSpecifier(exp) {
|
|
76
|
+
const specifier = t.exportSpecifier(t.identifier(exp.importedName), t.identifier(exp.exportedName));
|
|
77
|
+
if (exp.typeOnly) {
|
|
78
|
+
specifier.exportKind = 'type';
|
|
90
79
|
}
|
|
91
|
-
return
|
|
80
|
+
return specifier;
|
|
92
81
|
}
|
|
93
82
|
/**
|
|
94
83
|
* Fixes any issues in the referenced barrel file.
|
|
@@ -96,16 +85,33 @@ function deduplicateExports(exports) {
|
|
|
96
85
|
*/
|
|
97
86
|
function fixIssuesInBarrelFile(absoluteFilePath) {
|
|
98
87
|
const ast = (0, parseUtils_1.parseTypescriptFile)(absoluteFilePath);
|
|
99
|
-
// Collect all
|
|
88
|
+
// Collect all exports in a single traverse pass
|
|
89
|
+
const existingExportsByName = new Map();
|
|
90
|
+
const existingStatementsByPath = new Map();
|
|
100
91
|
const exportStarPaths = [];
|
|
101
92
|
const allFlattenedExports = [];
|
|
102
93
|
(0, traverse_1.default)(ast, {
|
|
94
|
+
ExportNamedDeclaration(path) {
|
|
95
|
+
if (!path.node.source)
|
|
96
|
+
return;
|
|
97
|
+
const namedExport = {
|
|
98
|
+
path,
|
|
99
|
+
sourcePath: path.node.source.value,
|
|
100
|
+
};
|
|
101
|
+
existingStatementsByPath.set(namedExport.sourcePath, namedExport);
|
|
102
|
+
path.node.specifiers.forEach((specifier, i) => {
|
|
103
|
+
if (specifier.type === 'ExportSpecifier' && specifier.exported.type === 'Identifier') {
|
|
104
|
+
existingExportsByName.set(specifier.exported.name, {
|
|
105
|
+
namedExport,
|
|
106
|
+
specifierIndex: i,
|
|
107
|
+
typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
},
|
|
103
112
|
ExportAllDeclaration(path) {
|
|
104
|
-
const importPath = path.node.source.value;
|
|
105
|
-
// Check if this is `export type *` (type-only export star)
|
|
106
113
|
const isExportTypeStar = path.node.exportKind === 'type';
|
|
107
|
-
|
|
108
|
-
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, importPath, isExportTypeStar);
|
|
114
|
+
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, path.node.source.value, isExportTypeStar);
|
|
109
115
|
exportStarPaths.push(path);
|
|
110
116
|
allFlattenedExports.push(...flattened);
|
|
111
117
|
},
|
|
@@ -113,23 +119,55 @@ function fixIssuesInBarrelFile(absoluteFilePath) {
|
|
|
113
119
|
if (exportStarPaths.length === 0) {
|
|
114
120
|
return;
|
|
115
121
|
}
|
|
116
|
-
// Deduplicate
|
|
122
|
+
// Deduplicate and filter exports
|
|
117
123
|
const deduplicated = deduplicateExports(allFlattenedExports);
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
124
|
+
const toRemove = [];
|
|
125
|
+
const filteredExports = deduplicated.filter((exp) => {
|
|
126
|
+
const existing = existingExportsByName.get(exp.exportedName);
|
|
127
|
+
if (!existing)
|
|
128
|
+
return true;
|
|
129
|
+
// Upgrade type-only to value export
|
|
130
|
+
if (existing.typeOnly && !exp.typeOnly) {
|
|
131
|
+
toRemove.push(existing);
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return false;
|
|
135
|
+
});
|
|
136
|
+
// Remove specifiers being upgraded from type to value
|
|
137
|
+
for (const { namedExport, specifierIndex } of toRemove) {
|
|
138
|
+
const specifiers = namedExport.path.node.specifiers;
|
|
139
|
+
if (specifiers.length === 1) {
|
|
140
|
+
namedExport.path.remove();
|
|
141
|
+
existingStatementsByPath.delete(namedExport.sourcePath);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
specifiers.splice(specifierIndex, 1);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// Group filtered exports and create/update statements
|
|
148
|
+
const grouped = groupExportsByPath(filteredExports);
|
|
149
|
+
const newStatements = [];
|
|
150
|
+
for (const [importPath, exps] of grouped) {
|
|
151
|
+
const existing = existingStatementsByPath.get(importPath);
|
|
152
|
+
if (existing) {
|
|
153
|
+
existing.path.node.specifiers.push(...exps.map(createExportSpecifier));
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
newStatements.push(t.exportNamedDeclaration(null, exps.map(createExportSpecifier), t.stringLiteral(importPath)));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
// Replace export stars
|
|
160
|
+
if (newStatements.length > 0) {
|
|
161
|
+
exportStarPaths[0].replaceWithMultiple(newStatements);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
exportStarPaths[0].remove();
|
|
165
|
+
}
|
|
125
166
|
for (let i = 1; i < exportStarPaths.length; i++) {
|
|
126
167
|
exportStarPaths[i].remove();
|
|
127
168
|
}
|
|
128
|
-
//
|
|
129
|
-
const output = (0, generator_1.default)(ast, {
|
|
130
|
-
retainLines: false,
|
|
131
|
-
comments: true,
|
|
132
|
-
});
|
|
169
|
+
// Write output
|
|
170
|
+
const output = (0, generator_1.default)(ast, { retainLines: false, comments: true });
|
|
133
171
|
fs.writeFileSync(absoluteFilePath, output.code, 'utf8');
|
|
134
172
|
}
|
|
135
173
|
//# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,sDA+FC;AA9JD,4CAA8B;AAE9B,+DAAuC;AACvC,iEAAwC;AACxC,gDAAkC;AAClC,2DAAwD;AAExD,6CAAmD;AAEnD;;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,GAAG,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC/C,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACf,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED;;;GAGG;AACH,SAAS,kBAAkB,CAAC,OAAmC;IAC7D,MAAM,MAAM,GAAG,IAAI,GAAG,EAAoC,CAAC;IAC3D,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAI,CAAC,QAAQ,IAAI,CAAC,QAAQ,CAAC,QAAQ,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC;YACtD,MAAM,C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