@christiango/unbarrel 0.10.0 → 0.10.2
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 +18 -8
- package/lib/fixIssuesInBarrelFile.js.map +1 -1
- package/lib/flattenExportStar.d.ts +2 -1
- package/lib/flattenExportStar.d.ts.map +1 -1
- package/lib/flattenExportStar.js +8 -4
- package/lib/flattenExportStar.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":"AA0EA;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,QAkD7D"}
|
|
@@ -77,18 +77,26 @@ function createExportStatements(exportsByPath) {
|
|
|
77
77
|
return statements;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
|
-
* Deduplicates exports by exportedName
|
|
80
|
+
* Deduplicates exports by exportedName.
|
|
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).
|
|
81
84
|
*/
|
|
82
85
|
function deduplicateExports(exports) {
|
|
83
|
-
const
|
|
84
|
-
const result = [];
|
|
86
|
+
const exportsByName = new Map();
|
|
85
87
|
for (const exp of exports) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
const existing = exportsByName.get(exp.exportedName);
|
|
89
|
+
if (!existing) {
|
|
90
|
+
// First occurrence of this export name
|
|
91
|
+
exportsByName.set(exp.exportedName, exp);
|
|
89
92
|
}
|
|
93
|
+
else if (existing.typeOnly && !exp.typeOnly) {
|
|
94
|
+
// Replace type-only export with value export (value takes precedence)
|
|
95
|
+
exportsByName.set(exp.exportedName, exp);
|
|
96
|
+
}
|
|
97
|
+
// Otherwise keep the existing export (either both are same typeOnly, or existing is value and new is type)
|
|
90
98
|
}
|
|
91
|
-
return
|
|
99
|
+
return Array.from(exportsByName.values());
|
|
92
100
|
}
|
|
93
101
|
/**
|
|
94
102
|
* Fixes any issues in the referenced barrel file.
|
|
@@ -102,8 +110,10 @@ function fixIssuesInBarrelFile(absoluteFilePath) {
|
|
|
102
110
|
(0, traverse_1.default)(ast, {
|
|
103
111
|
ExportAllDeclaration(path) {
|
|
104
112
|
const importPath = path.node.source.value;
|
|
113
|
+
// Check if this is `export type *` (type-only export star)
|
|
114
|
+
const isExportTypeStar = path.node.exportKind === 'type';
|
|
105
115
|
// Flatten the export * into named exports
|
|
106
|
-
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, importPath);
|
|
116
|
+
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, importPath, isExportTypeStar);
|
|
107
117
|
exportStarPaths.push(path);
|
|
108
118
|
allFlattenedExports.push(...flattened);
|
|
109
119
|
},
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8EA,sDAkDC;AAhID,4CAA8B;AAE9B,+DAAuC;AACvC,iEAAwC;AACxC,gDAAkC;AAClC,2DAAwD;AAExD,6CAAmD;AAEnD;;GAEG;AACH,SAAS,kBAAkB,CAAC,OAAmC;IAC7D,MAAM,aAAa,G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,GAAG,SAAS,CAAC,CAAC;QACzC,CAAC;KACF,CAAC,CAAC;IAEH,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO;IACT,CAAC;IAED,8CAA8C;IAC9C,MAAM,YAAY,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAAC;IAE7D,uBAAuB;IACvB,MAAM,OAAO,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;IAEjD,uCAAuC;IACvC,MAAM,aAAa,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IAEtD,4DAA4D;IAC5D,eAAe,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,aAAa,CAAC,CAAC;IAEtD,oCAAoC;IACpC,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,kCAAkC;IAClC,MAAM,MAAM,GAAG,IAAA,mBAAQ,EAAC,GAAG,EAAE;QAC3B,WAAW,EAAE,KAAK;QAClB,QAAQ,EAAE,IAAI;KACf,CAAC,CAAC;IAEH,EAAE,CAAC,aAAa,CAAC,gBAAgB,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { ResolvedModuleDefinition } from './getExportDefinitionFromReExport';
|
|
|
3
3
|
* Takes an export star and gets the list of fully resolved named exports that are currently reachable by the export *
|
|
4
4
|
* @param absolutePathOfBarrelFile - The absolute path of the barrel file with the export * in it
|
|
5
5
|
* @param importPath - The relative path of the module that is being referenced by the export *
|
|
6
|
+
* @param isExportTypeStar - If true, all exports will be marked as type-only (for `export type *` statements)
|
|
6
7
|
*/
|
|
7
|
-
export declare function flattenExportStar(absolutePathOfBarrelFile: string, importPath: string): ResolvedModuleDefinition[];
|
|
8
|
+
export declare function flattenExportStar(absolutePathOfBarrelFile: string, importPath: string, isExportTypeStar?: boolean): ResolvedModuleDefinition[];
|
|
8
9
|
//# sourceMappingURL=flattenExportStar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportStar.d.ts","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAG9G
|
|
1
|
+
{"version":3,"file":"flattenExportStar.d.ts","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAG9G;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,wBAAwB,EAAE,MAAM,EAChC,UAAU,EAAE,MAAM,EAClB,gBAAgB,GAAE,OAAe,GAChC,wBAAwB,EAAE,CAoC5B"}
|
package/lib/flattenExportStar.js
CHANGED
|
@@ -9,8 +9,9 @@ const getAllExportDefinitionsReachableFromModule_1 = require("./getAllExportDefi
|
|
|
9
9
|
* Takes an export star and gets the list of fully resolved named exports that are currently reachable by the export *
|
|
10
10
|
* @param absolutePathOfBarrelFile - The absolute path of the barrel file with the export * in it
|
|
11
11
|
* @param importPath - The relative path of the module that is being referenced by the export *
|
|
12
|
+
* @param isExportTypeStar - If true, all exports will be marked as type-only (for `export type *` statements)
|
|
12
13
|
*/
|
|
13
|
-
function flattenExportStar(absolutePathOfBarrelFile, importPath) {
|
|
14
|
+
function flattenExportStar(absolutePathOfBarrelFile, importPath, isExportTypeStar = false) {
|
|
14
15
|
const result = [];
|
|
15
16
|
const importAbsolutePath = (0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, importPath);
|
|
16
17
|
const moduleExports = (0, getExportsFromModule_1.getExportsFromModule)(importAbsolutePath);
|
|
@@ -21,15 +22,18 @@ function flattenExportStar(absolutePathOfBarrelFile, importPath) {
|
|
|
21
22
|
exportedName: importName,
|
|
22
23
|
importedName: importName,
|
|
23
24
|
importPath,
|
|
24
|
-
|
|
25
|
+
// If the export star is type-only, all exports become type-only
|
|
26
|
+
typeOnly: isExportTypeStar || definition.typeOnly,
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
for (const reExport of moduleExports.reExports) {
|
|
28
30
|
if (reExport.type === 'exportAll') {
|
|
29
|
-
|
|
31
|
+
const reachableExports = (0, getAllExportDefinitionsReachableFromModule_1.getAllExportDefinitionsReachableFromModule)((0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, reExport.importPath), absolutePathOfBarrelFile);
|
|
32
|
+
result.push(...reachableExports.map((exp) => ({ ...exp, typeOnly: isExportTypeStar || exp.typeOnly })));
|
|
30
33
|
}
|
|
31
34
|
else {
|
|
32
|
-
|
|
35
|
+
const resolved = (0, getExportDefinitionFromReExport_1.getExportDefinitionFromReExport)((0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, reExport.importPath), reExport);
|
|
36
|
+
result.push({ ...resolved, typeOnly: isExportTypeStar || resolved.typeOnly });
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flattenExportStar.js","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"flattenExportStar.js","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":";;AAWA,8CAwCC;AAnDD,iEAA8D;AAC9D,+CAAwD;AACxD,uFAA8G;AAC9G,6GAA0G;AAE1G;;;;;GAKG;AACH,SAAgB,iBAAiB,CAC/B,wBAAgC,EAChC,UAAkB,EAClB,mBAA4B,KAAK;IAEjC,MAAM,MAAM,GAA+B,EAAE,CAAC;IAE9C,MAAM,kBAAkB,GAAG,IAAA,qCAAuB,EAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;IACzF,MAAM,aAAa,GAAG,IAAA,2CAAo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