@christiango/unbarrel 0.0.9 → 0.10.0
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/.prettierignore +10 -0
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.12.0.cjs +942 -0
- package/.yarnrc.yml +3 -0
- package/README.md +35 -1
- package/lib/cli.js +10 -11
- package/lib/cli.js.map +1 -1
- package/lib/fixIssuesInBarrelFile.d.ts +6 -0
- package/lib/fixIssuesInBarrelFile.d.ts.map +1 -0
- package/lib/fixIssuesInBarrelFile.js +133 -0
- package/lib/fixIssuesInBarrelFile.js.map +1 -0
- package/lib/flattenExportStar.d.ts +8 -0
- package/lib/flattenExportStar.d.ts.map +1 -0
- package/lib/flattenExportStar.js +37 -0
- package/lib/flattenExportStar.js.map +1 -0
- package/lib/getAllExportDefinitionsReachableFromModule.d.ts +8 -0
- package/lib/getAllExportDefinitionsReachableFromModule.d.ts.map +1 -0
- package/lib/getAllExportDefinitionsReachableFromModule.js +44 -0
- package/lib/getAllExportDefinitionsReachableFromModule.js.map +1 -0
- package/lib/getExportDefinitionFromReExport.d.ts +20 -0
- package/lib/getExportDefinitionFromReExport.d.ts.map +1 -0
- package/lib/getExportDefinitionFromReExport.js +85 -0
- package/lib/getExportDefinitionFromReExport.js.map +1 -0
- package/lib/getExportsFromModule.d.ts.map +1 -1
- package/lib/getExportsFromModule.js +63 -35
- package/lib/getExportsFromModule.js.map +1 -1
- package/lib/importUtils.d.ts +6 -0
- package/lib/importUtils.d.ts.map +1 -1
- package/lib/importUtils.js +12 -0
- package/lib/importUtils.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/parseUtils.d.ts +8 -0
- package/lib/parseUtils.d.ts.map +1 -0
- package/lib/parseUtils.js +55 -0
- package/lib/parseUtils.js.map +1 -0
- package/package.json +5 -6
- package/lib/unbarrel.d.ts +0 -8
- package/lib/unbarrel.d.ts.map +0 -1
- package/lib/unbarrel.js +0 -11
- package/lib/unbarrel.js.map +0 -1
package/.yarnrc.yml
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
1
|
# @christiango/unbarrel
|
|
2
2
|
|
|
3
|
-
This is a package that contains some utilities that can be used to fix and enforce any problematic patterns with barrel files in your repo. In general, layers of barrel files tend to be problematic for the performance of tools like jest and webpack. For more details on the performance problems that come with barrel files check out [https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/
|
|
3
|
+
This is a package that contains some utilities that can be used to fix and enforce any problematic patterns with barrel files in your repo. In general, layers of barrel files tend to be problematic for the performance of tools like jest and webpack. For more details on the performance problems that come with barrel files check out [Speeding up the JavaScript ecosystem - The barrel file debacle](https://marvinh.dev/blog/speeding-up-javascript-ecosystem-part-7/)
|
|
4
|
+
|
|
5
|
+
## CLI
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @christiango/unbarrel
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Commands
|
|
14
|
+
|
|
15
|
+
#### `unbarrel fix <barrelFile>`
|
|
16
|
+
|
|
17
|
+
Converts all `export * from '...'` statements in a barrel file to explicit named exports.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
unbarrel fix ./src/index.ts
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
**Before:**
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
export * from './utils';
|
|
27
|
+
export * from './components';
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**After:**
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export { helper, formatDate } from './utils';
|
|
34
|
+
export { Button, Input } from './components';
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
This improves tree-shaking and reduces the performance overhead caused by wildcard re-exports.
|
package/lib/cli.js
CHANGED
|
@@ -35,24 +35,23 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
})();
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
const commander_1 = require("commander");
|
|
38
|
-
const unbarrel_1 = require("./unbarrel");
|
|
39
38
|
const path = __importStar(require("path"));
|
|
39
|
+
const fixIssuesInBarrelFile_1 = require("./fixIssuesInBarrelFile");
|
|
40
40
|
const program = new commander_1.Command();
|
|
41
|
-
program.name('
|
|
41
|
+
program.name('unbarrel').description('Utilities for working with barrel files').version('0.0.0');
|
|
42
42
|
program
|
|
43
|
-
.command('
|
|
44
|
-
.description('Convert
|
|
45
|
-
.argument('<
|
|
46
|
-
.action(
|
|
43
|
+
.command('fix')
|
|
44
|
+
.description('Convert all export * from ... statements in a barrel file to explicit exports')
|
|
45
|
+
.argument('<barrelFile>', 'Path to the barrel file to process')
|
|
46
|
+
.action((barrelFile) => {
|
|
47
47
|
try {
|
|
48
|
-
|
|
49
|
-
const absolutePath = path.resolve(rootBarrelFile);
|
|
48
|
+
const absolutePath = path.resolve(barrelFile);
|
|
50
49
|
console.log(`Processing barrel file: ${absolutePath}`);
|
|
51
|
-
|
|
52
|
-
console.log('
|
|
50
|
+
(0, fixIssuesInBarrelFile_1.fixIssuesInBarrelFile)(absolutePath);
|
|
51
|
+
console.log('Successfully fixed barrel file');
|
|
53
52
|
}
|
|
54
53
|
catch (error) {
|
|
55
|
-
console.error('
|
|
54
|
+
console.error('Error:', error instanceof Error ? error.message : String(error));
|
|
56
55
|
process.exit(1);
|
|
57
56
|
}
|
|
58
57
|
});
|
package/lib/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":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__createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.fixIssuesInBarrelFile = fixIssuesInBarrelFile;
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
42
|
+
const generator_1 = __importDefault(require("@babel/generator"));
|
|
43
|
+
const t = __importStar(require("@babel/types"));
|
|
44
|
+
const flattenExportStar_1 = require("./flattenExportStar");
|
|
45
|
+
const parseUtils_1 = require("./parseUtils");
|
|
46
|
+
/**
|
|
47
|
+
* Groups resolved exports by their import path
|
|
48
|
+
*/
|
|
49
|
+
function groupExportsByPath(exports) {
|
|
50
|
+
const exportsByPath = new Map();
|
|
51
|
+
for (const exp of exports) {
|
|
52
|
+
const existing = exportsByPath.get(exp.importPath) || [];
|
|
53
|
+
existing.push(exp);
|
|
54
|
+
exportsByPath.set(exp.importPath, existing);
|
|
55
|
+
}
|
|
56
|
+
return exportsByPath;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Creates export named declaration AST nodes from grouped exports
|
|
60
|
+
*/
|
|
61
|
+
function createExportStatements(exportsByPath) {
|
|
62
|
+
const statements = [];
|
|
63
|
+
for (const [importPath, exps] of exportsByPath) {
|
|
64
|
+
const specifiers = exps.map((e) => {
|
|
65
|
+
const local = t.identifier(e.importedName);
|
|
66
|
+
const exported = t.identifier(e.exportedName);
|
|
67
|
+
const specifier = t.exportSpecifier(local, exported);
|
|
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);
|
|
76
|
+
}
|
|
77
|
+
return statements;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Deduplicates exports by exportedName, keeping the first occurrence
|
|
81
|
+
*/
|
|
82
|
+
function deduplicateExports(exports) {
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
const result = [];
|
|
85
|
+
for (const exp of exports) {
|
|
86
|
+
if (!seen.has(exp.exportedName)) {
|
|
87
|
+
seen.add(exp.exportedName);
|
|
88
|
+
result.push(exp);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fixes any issues in the referenced barrel file.
|
|
95
|
+
* @param absoluteFilePath - the absolute path of the barrel file to fix
|
|
96
|
+
*/
|
|
97
|
+
function fixIssuesInBarrelFile(absoluteFilePath) {
|
|
98
|
+
const ast = (0, parseUtils_1.parseTypescriptFile)(absoluteFilePath);
|
|
99
|
+
// Collect all export star declarations and their flattened exports
|
|
100
|
+
const exportStarPaths = [];
|
|
101
|
+
const allFlattenedExports = [];
|
|
102
|
+
(0, traverse_1.default)(ast, {
|
|
103
|
+
ExportAllDeclaration(path) {
|
|
104
|
+
const importPath = path.node.source.value;
|
|
105
|
+
// Flatten the export * into named exports
|
|
106
|
+
const flattened = (0, flattenExportStar_1.flattenExportStar)(absoluteFilePath, importPath);
|
|
107
|
+
exportStarPaths.push(path);
|
|
108
|
+
allFlattenedExports.push(...flattened);
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
if (exportStarPaths.length === 0) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Deduplicate exports across all export stars
|
|
115
|
+
const deduplicated = deduplicateExports(allFlattenedExports);
|
|
116
|
+
// Group by import path
|
|
117
|
+
const grouped = groupExportsByPath(deduplicated);
|
|
118
|
+
// Create replacement export statements
|
|
119
|
+
const newStatements = createExportStatements(grouped);
|
|
120
|
+
// Replace the first export star with all the new statements
|
|
121
|
+
exportStarPaths[0].replaceWithMultiple(newStatements);
|
|
122
|
+
// Remove the remaining export stars
|
|
123
|
+
for (let i = 1; i < exportStarPaths.length; i++) {
|
|
124
|
+
exportStarPaths[i].remove();
|
|
125
|
+
}
|
|
126
|
+
// Generate code from modified AST
|
|
127
|
+
const output = (0, generator_1.default)(ast, {
|
|
128
|
+
retainLines: false,
|
|
129
|
+
comments: true,
|
|
130
|
+
});
|
|
131
|
+
fs.writeFileSync(absoluteFilePath, output.code, 'utf8');
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=fixIssuesInBarrelFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fixIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/fixIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,sDA+CC;AAtHD,4CAA8B;AAE9B,+DAAuC;AACvC,iEAAwC;AACxC,gDAAkC;AAClC,2DAAwD;AAExD,6CAAmD;AAEnD;;GAEG;AACH,SAAS,kBAAkB,CAAC,OAAmC;IAC7D,MAAM,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IACpE,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE,CAAC;QAC1B,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QACzD,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACnB,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAAC,aAAsD;IACpF,MAAM,UAAU,GAA+B,EAAE,CAAC;IAElD,KAAK,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC,IAAI,aAAa,EAAE,CAAC;QAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAChC,MAAM,KAAK,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY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,KAAK,CAAC;YAE1C,0CAA0C;YAC1C,MAAM,SAAS,GAAG,IAAA,qCAAiB,EAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC;YAElE,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC3B,mBAAmB,CAAC,IAAI,CAAC,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResolvedModuleDefinition } from './getExportDefinitionFromReExport';
|
|
2
|
+
/**
|
|
3
|
+
* Takes an export star and gets the list of fully resolved named exports that are currently reachable by the export *
|
|
4
|
+
* @param absolutePathOfBarrelFile - The absolute path of the barrel file with the export * in it
|
|
5
|
+
* @param importPath - The relative path of the module that is being referenced by the export *
|
|
6
|
+
*/
|
|
7
|
+
export declare function flattenExportStar(absolutePathOfBarrelFile: string, importPath: string): ResolvedModuleDefinition[];
|
|
8
|
+
//# sourceMappingURL=flattenExportStar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenExportStar.d.ts","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":"AAEA,OAAO,EAAmC,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAG9G;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,wBAAwB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,wBAAwB,EAAE,CAqClH"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flattenExportStar = flattenExportStar;
|
|
4
|
+
const getExportsFromModule_1 = require("./getExportsFromModule");
|
|
5
|
+
const importUtils_1 = require("./importUtils");
|
|
6
|
+
const getExportDefinitionFromReExport_1 = require("./getExportDefinitionFromReExport");
|
|
7
|
+
const getAllExportDefinitionsReachableFromModule_1 = require("./getAllExportDefinitionsReachableFromModule");
|
|
8
|
+
/**
|
|
9
|
+
* Takes an export star and gets the list of fully resolved named exports that are currently reachable by the export *
|
|
10
|
+
* @param absolutePathOfBarrelFile - The absolute path of the barrel file with the export * in it
|
|
11
|
+
* @param importPath - The relative path of the module that is being referenced by the export *
|
|
12
|
+
*/
|
|
13
|
+
function flattenExportStar(absolutePathOfBarrelFile, importPath) {
|
|
14
|
+
const result = [];
|
|
15
|
+
const importAbsolutePath = (0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, importPath);
|
|
16
|
+
const moduleExports = (0, getExportsFromModule_1.getExportsFromModule)(importAbsolutePath);
|
|
17
|
+
for (const definition of moduleExports.definitions) {
|
|
18
|
+
const importName = definition.type === 'defaultExport' ? 'default' : definition.name;
|
|
19
|
+
result.push({
|
|
20
|
+
type: 'resolvedModuleDefinition',
|
|
21
|
+
exportedName: importName,
|
|
22
|
+
importedName: importName,
|
|
23
|
+
importPath,
|
|
24
|
+
typeOnly: definition.typeOnly,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
for (const reExport of moduleExports.reExports) {
|
|
28
|
+
if (reExport.type === 'exportAll') {
|
|
29
|
+
result.push(...(0, getAllExportDefinitionsReachableFromModule_1.getAllExportDefinitionsReachableFromModule)((0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, reExport.importPath), absolutePathOfBarrelFile));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
result.push((0, getExportDefinitionFromReExport_1.getExportDefinitionFromReExport)((0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfBarrelFile, reExport.importPath), reExport));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=flattenExportStar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenExportStar.js","sourceRoot":"","sources":["../src/flattenExportStar.ts"],"names":[],"mappings":";;AAUA,8CAqCC;AA/CD,iEAA8D;AAC9D,+CAAwD;AACxD,uFAA8G;AAC9G,6GAA0G;AAE1G;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,wBAAgC,EAAE,UAAkB;IACpF,MAAM,MAAM,GAA+B,EAAE,CAAC;IAE9C,MAAM,kBAAkB,GAAG,IAAA,qCAAuB,EAAC,wBAAwB,EAAE,UAAU,CAAC,CAAC;IACzF,MAAM,aAAa,GAAG,IAAA,2CAAoB,EAAC,kBAAkB,CAAC,CAAC;IAE/D,KAAK,MAAM,UAAU,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;QACnD,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QAErF,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,0BAA0B;YAChC,YAAY,EAAE,UAAU;YACxB,YAAY,EAAE,UAAU;YACxB,UAAU;YACV,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,QAAQ,IAAI,aAAa,CAAC,SAAS,EAAE,CAAC;QAC/C,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CACT,GAAG,IAAA,uFAA0C,EAC3C,IAAA,qCAAuB,EAAC,wBAAwB,EAAE,QAAQ,CAAC,UAAU,CAAC,EACtE,wBAAwB,CACzB,CACF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CACT,IAAA,iEAA+B,EAC7B,IAAA,qCAAuB,EAAC,wBAAwB,EAAE,QAAQ,CAAC,UAAU,CAAC,EACtE,QAAQ,CACT,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ResolvedModuleDefinition } from './getExportDefinitionFromReExport';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a named re-export to it's source definition
|
|
4
|
+
* @param absolutePathOfModule - the absolute path of the module where the re-export resides
|
|
5
|
+
* @param baseModulePath - the absolute path of the base module to compute relative paths from (defaults to absolutePathOfModule for external callers)
|
|
6
|
+
*/
|
|
7
|
+
export declare function getAllExportDefinitionsReachableFromModule(absolutePathOfModule: string, baseModulePath?: string): ResolvedModuleDefinition[];
|
|
8
|
+
//# sourceMappingURL=getAllExportDefinitionsReachableFromModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllExportDefinitionsReachableFromModule.d.ts","sourceRoot":"","sources":["../src/getAllExportDefinitionsReachableFromModule.ts"],"names":[],"mappings":"AACA,OAAO,EAAmC,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAI9G;;;;GAIG;AACH,wBAAgB,0CAA0C,CACxD,oBAAoB,EAAE,MAAM,EAC5B,cAAc,GAAE,MAA6B,GAC5C,wBAAwB,EAAE,CAqC5B"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAllExportDefinitionsReachableFromModule = getAllExportDefinitionsReachableFromModule;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const getExportDefinitionFromReExport_1 = require("./getExportDefinitionFromReExport");
|
|
9
|
+
const getExportsFromModule_1 = require("./getExportsFromModule");
|
|
10
|
+
const importUtils_1 = require("./importUtils");
|
|
11
|
+
/**
|
|
12
|
+
* Resolves a named re-export to it's source definition
|
|
13
|
+
* @param absolutePathOfModule - the absolute path of the module where the re-export resides
|
|
14
|
+
* @param baseModulePath - the absolute path of the base module to compute relative paths from (defaults to absolutePathOfModule for external callers)
|
|
15
|
+
*/
|
|
16
|
+
function getAllExportDefinitionsReachableFromModule(absolutePathOfModule, baseModulePath = absolutePathOfModule) {
|
|
17
|
+
const result = [];
|
|
18
|
+
const exportsInModule = (0, getExportsFromModule_1.getExportsFromModule)(absolutePathOfModule);
|
|
19
|
+
// Compute relative path from base module's directory to current module
|
|
20
|
+
const baseDir = node_path_1.default.dirname(baseModulePath);
|
|
21
|
+
const relativeImportPath = absolutePathOfModule === baseModulePath
|
|
22
|
+
? '.'
|
|
23
|
+
: (0, importUtils_1.convertToESMImportPath)(node_path_1.default.relative(baseDir, absolutePathOfModule).replace(/\.\w+$/, ''));
|
|
24
|
+
for (const definition of exportsInModule.definitions) {
|
|
25
|
+
const importName = definition.type === 'defaultExport' ? 'default' : definition.name;
|
|
26
|
+
result.push({
|
|
27
|
+
type: 'resolvedModuleDefinition',
|
|
28
|
+
importedName: importName,
|
|
29
|
+
exportedName: importName,
|
|
30
|
+
importPath: relativeImportPath,
|
|
31
|
+
typeOnly: definition.typeOnly,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
for (const reExport of exportsInModule.reExports) {
|
|
35
|
+
if (reExport.type === 'exportAll') {
|
|
36
|
+
result.push(...getAllExportDefinitionsReachableFromModule((0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfModule, reExport.importPath), baseModulePath));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
result.push((0, getExportDefinitionFromReExport_1.getExportDefinitionFromReExport)(absolutePathOfModule, reExport));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=getAllExportDefinitionsReachableFromModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getAllExportDefinitionsReachableFromModule.js","sourceRoot":"","sources":["../src/getAllExportDefinitionsReachableFromModule.ts"],"names":[],"mappings":";;;;;AAUA,gGAwCC;AAlDD,0DAA6B;AAC7B,uFAA8G;AAC9G,iEAA8D;AAC9D,+CAAgF;AAEhF;;;;GAIG;AACH,SAAgB,0CAA0C,CACxD,oBAA4B,EAC5B,iBAAyB,oBAAoB;IAE7C,MAAM,MAAM,GAA+B,EAAE,CAAC;IAE9C,MAAM,eAAe,GAAG,IAAA,2CAAoB,EAAC,oBAAoB,CAAC,CAAC;IAEnE,uEAAuE;IACvE,MAAM,OAAO,GAAG,mBAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7C,MAAM,kBAAkB,GACtB,oBAAoB,KAAK,cAAc;QACrC,CAAC,CAAC,GAAG;QACL,CAAC,CAAC,IAAA,oCAAsB,EAAC,mBAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;IAEjG,KAAK,MAAM,UAAU,IAAI,eAAe,CAAC,WAAW,EAAE,CAAC;QACrD,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC;QACrF,MAAM,CAAC,IAAI,CAAC;YACV,IAAI,EAAE,0BAA0B;YAChC,YAAY,EAAE,UAAU;YACxB,YAAY,EAAE,UAAU;YACxB,UAAU,EAAE,kBAAkB;YAC9B,QAAQ,EAAE,UAAU,CAAC,QAAQ;SAC9B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,MAAM,QAAQ,IAAI,eAAe,CAAC,SAAS,EAAE,CAAC;QACjD,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,CAAC,IAAI,CACT,GAAG,0CAA0C,CAC3C,IAAA,qCAAuB,EAAC,oBAAoB,EAAE,QAAQ,CAAC,UAAU,CAAC,EAClE,cAAc,CACf,CACF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,IAAA,iEAA+B,EAAC,oBAAoB,EAAE,QAAQ,CAAC,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ModuleDefaultReExport, ModuleNamedReExport } from './getExportsFromModule';
|
|
2
|
+
/** Points to the corresponding definition of an entity that was re-export from a module. */
|
|
3
|
+
export interface ResolvedModuleDefinition {
|
|
4
|
+
type: 'resolvedModuleDefinition';
|
|
5
|
+
/** The path of the definition of this import relative to the location where it was re-exported */
|
|
6
|
+
importPath: string;
|
|
7
|
+
/** The name that was used as the export name in the module that defined this entity */
|
|
8
|
+
importedName: string;
|
|
9
|
+
/** The name of the export in the module where the re-export takes place. This won't match importedName if the re-export renames the module */
|
|
10
|
+
exportedName: string;
|
|
11
|
+
/** Set to true if the export is a type only export */
|
|
12
|
+
typeOnly: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Resolves a named re-export to it's source definition
|
|
16
|
+
* @param absolutePathOfModule - the absolute path of the module where the re-export resides
|
|
17
|
+
* @param reExportToResolve - the relative path of the import for the re-export
|
|
18
|
+
*/
|
|
19
|
+
export declare function getExportDefinitionFromReExport(absolutePathOfModule: string, reExportToResolve: ModuleNamedReExport | ModuleDefaultReExport): ResolvedModuleDefinition;
|
|
20
|
+
//# sourceMappingURL=getExportDefinitionFromReExport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExportDefinitionFromReExport.d.ts","sourceRoot":"","sources":["../src/getExportDefinitionFromReExport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwB,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAI1G,4FAA4F;AAC5F,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,0BAA0B,CAAC;IACjC,kGAAkG;IAClG,UAAU,EAAE,MAAM,CAAC;IACnB,uFAAuF;IACvF,YAAY,EAAE,MAAM,CAAC;IACrB,8IAA8I;IAC9I,YAAY,EAAE,MAAM,CAAC;IACrB,sDAAsD;IACtD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,oBAAoB,EAAE,MAAM,EAC5B,iBAAiB,EAAE,mBAAmB,GAAG,qBAAqB,GAC7D,wBAAwB,CA4E1B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getExportDefinitionFromReExport = getExportDefinitionFromReExport;
|
|
7
|
+
const getExportsFromModule_1 = require("./getExportsFromModule");
|
|
8
|
+
const importUtils_1 = require("./importUtils");
|
|
9
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a named re-export to it's source definition
|
|
12
|
+
* @param absolutePathOfModule - the absolute path of the module where the re-export resides
|
|
13
|
+
* @param reExportToResolve - the relative path of the import for the re-export
|
|
14
|
+
*/
|
|
15
|
+
function getExportDefinitionFromReExport(absolutePathOfModule, reExportToResolve) {
|
|
16
|
+
const importAbsolutePath = (0, importUtils_1.getAbsolutePathOfImport)(absolutePathOfModule, reExportToResolve.importPath);
|
|
17
|
+
const exportsInModule = (0, getExportsFromModule_1.getExportsFromModule)(importAbsolutePath);
|
|
18
|
+
for (const definition of exportsInModule.definitions) {
|
|
19
|
+
if (definition.type === 'namedExport') {
|
|
20
|
+
if (reExportToResolve.type === 'namedExport' && definition.name === reExportToResolve.importedName) {
|
|
21
|
+
return {
|
|
22
|
+
type: 'resolvedModuleDefinition',
|
|
23
|
+
importPath: reExportToResolve.importPath,
|
|
24
|
+
importedName: definition.name,
|
|
25
|
+
exportedName: reExportToResolve.exportedName,
|
|
26
|
+
typeOnly: definition.typeOnly,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else if (definition.type === 'defaultExport') {
|
|
31
|
+
if (reExportToResolve.type === 'defaultExport' ||
|
|
32
|
+
(reExportToResolve.type === 'namedExport' && reExportToResolve.importedName === 'default')) {
|
|
33
|
+
return {
|
|
34
|
+
type: 'resolvedModuleDefinition',
|
|
35
|
+
importPath: reExportToResolve.importPath,
|
|
36
|
+
importedName: 'default',
|
|
37
|
+
exportedName: reExportToResolve.exportedName,
|
|
38
|
+
typeOnly: reExportToResolve.typeOnly,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (const reExport of exportsInModule.reExports) {
|
|
44
|
+
if (reExport.type === 'namedExport') {
|
|
45
|
+
if (reExportToResolve.type === 'namedExport' && reExport.exportedName === reExportToResolve.importedName) {
|
|
46
|
+
const matchingDefinition = getExportDefinitionFromReExport(importAbsolutePath, reExport);
|
|
47
|
+
// Fix up the import path to be relative to the original module and handle any renames
|
|
48
|
+
return {
|
|
49
|
+
...matchingDefinition,
|
|
50
|
+
importPath: (0, importUtils_1.convertToESMImportPath)(node_path_1.default.join(reExportToResolve.importPath, matchingDefinition.importPath)),
|
|
51
|
+
exportedName: reExportToResolve.exportedName,
|
|
52
|
+
typeOnly: matchingDefinition.typeOnly,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else if (reExport.type === 'defaultExport') {
|
|
57
|
+
if (reExportToResolve.type === 'defaultExport' ||
|
|
58
|
+
(reExportToResolve.type === 'namedExport' && reExportToResolve.importedName === 'default')) {
|
|
59
|
+
const matchingDefinition = getExportDefinitionFromReExport(importAbsolutePath, reExport);
|
|
60
|
+
// Fix up the import path to be relative to the original module and handle any renames
|
|
61
|
+
return {
|
|
62
|
+
...matchingDefinition,
|
|
63
|
+
importPath: (0, importUtils_1.convertToESMImportPath)(node_path_1.default.join(reExportToResolve.importPath, matchingDefinition.importPath)),
|
|
64
|
+
exportedName: reExportToResolve.exportedName,
|
|
65
|
+
typeOnly: matchingDefinition.typeOnly,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (reExport.type === 'exportAll') {
|
|
70
|
+
const matchingDefinition = getExportDefinitionFromReExport(importAbsolutePath, {
|
|
71
|
+
...reExportToResolve,
|
|
72
|
+
importPath: reExport.importPath,
|
|
73
|
+
});
|
|
74
|
+
// Fix up the import path to be relative to the original module and handle any renames
|
|
75
|
+
return {
|
|
76
|
+
...matchingDefinition,
|
|
77
|
+
importPath: (0, importUtils_1.convertToESMImportPath)(node_path_1.default.join(reExportToResolve.importPath, matchingDefinition.importPath)),
|
|
78
|
+
exportedName: reExportToResolve.exportedName,
|
|
79
|
+
typeOnly: matchingDefinition.typeOnly,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
throw new Error(`Could not resolve re-export ${reExportToResolve.exportedName} from ${absolutePathOfModule}`);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=getExportDefinitionFromReExport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getExportDefinitionFromReExport.js","sourceRoot":"","sources":["../src/getExportDefinitionFromReExport.ts"],"names":[],"mappings":";;;;;AAsBA,0EA+EC;AArGD,iEAA0G;AAC1G,+CAAgF;AAChF,0DAA6B;AAe7B;;;;GAIG;AACH,SAAgB,+BAA+B,CAC7C,oBAA4B,EAC5B,iBAA8D;IAE9D,MAAM,kBAAkB,GAAG,IAAA,qCAAuB,EAAC,oBAAoB,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACvG,MAAM,eAAe,GAAG,IAAA,2CAAoB,EAAC,kBAAkB,CAAC,CAAC;IAEjE,KAAK,MAAM,UAAU,IAAI,eAAe,CAAC,WAAW,EAAE,CAAC;QACrD,IAAI,UAAU,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACtC,IAAI,iBAAiB,CAAC,IAAI,KAAK,aAAa,IAAI,UAAU,CAAC,IAAI,KAAK,iBAAiB,CAAC,YAAY,EAAE,CAAC;gBACnG,OAAO;oBACL,IAAI,EAAE,0BAA0B;oBAChC,UAAU,EAAE,iBAAiB,CAAC,UAAU;oBACxC,YAAY,EAAE,UAAU,CAAC,IAAI;oBAC7B,YAAY,EAAE,iBAAiB,CAAC,YAAY;oBAC5C,QAAQ,EAAE,UAAU,CAAC,QAAQ;iBAC9B,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,IAAI,UAAU,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;YAC/C,IACE,iBAAiB,CAAC,IAAI,KAAK,eAAe;gBAC1C,CAAC,iBAAiB,CAAC,IAAI,KAAK,aAAa,IAAI,iBAAiB,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B,EAAC,mBAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;oBAC1G,YAAY,EAAE,iBAAiB,CAAC,YAAY;oBAC5C,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;iBACtC,CAAC;YACJ,CAAC;QACH,CAAC;aAAM,IAAI,QAAQ,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACzC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC,kBAAkB,EAAE;gBAC7E,GAAG,iBAAiB;gBACpB,UAAU,EAAE,QAAQ,CAAC,UAAU;aAChC,CAAC,CAAC;YAEH,sFAAsF;YACtF,OAAO;gBACL,GAAG,kBAAkB;gBACrB,UAAU,EAAE,IAAA,oCAAsB,EAAC,mBAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;gBAC1G,YAAY,EAAE,iBAAiB,CAAC,YAAY;gBAC5C,QAAQ,EAAE,kBAAkB,CAAC,QAAQ;aACtC,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,+BAA+B,iBAAiB,CAAC,YAAY,SAAS,oBAAoB,EAAE,CAAC,CAAC;AAChH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getExportsFromModule.d.ts","sourceRoot":"","sources":["../src/getExportsFromModule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getExportsFromModule.d.ts","sourceRoot":"","sources":["../src/getExportsFromModule.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,aAAa,CAAC;IACpB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;IAClB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,eAAe,CAAC;IACtB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,2BAA2B;AAC3B,MAAM,MAAM,gBAAgB,GAAG,qBAAqB,GAAG,uBAAuB,CAAC;AAE/E,8CAA8C;AAC9C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,6DAA6D;IAC7D,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,aAAa,CAAC;IACpB,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,0IAA0I;IAC1I,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,eAAe,CAAC;IACtB,0IAA0I;IAC1I,YAAY,EAAE,MAAM,CAAC;IACrB,oEAAoE;IACpE,UAAU,EAAE,MAAM,CAAC;IACnB,0FAA0F;IAC1F,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,wCAAwC;AACxC,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,mBAAmB,GAAG,qBAAqB,CAAC;AAE7F,wCAAwC;AACxC,MAAM,WAAW,aAAa;IAC5B,yDAAyD;IACzD,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAChC,6DAA6D;IAC7D,SAAS,EAAE,cAAc,EAAE,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,gBAAgB,EAAE,MAAM,GAAG,aAAa,CA8M5E"}
|
|
@@ -38,20 +38,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.getExportsFromModule = getExportsFromModule;
|
|
40
40
|
const babel = __importStar(require("@babel/core"));
|
|
41
|
-
const fs = __importStar(require("node:fs"));
|
|
42
41
|
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
43
|
-
|
|
44
|
-
function parseTypescriptFile(absoluteFilePath) {
|
|
45
|
-
const fileContents = fs.readFileSync(absoluteFilePath, 'utf-8');
|
|
46
|
-
const ast = babel.parse(fileContents, {
|
|
47
|
-
sourceType: 'module',
|
|
48
|
-
presets: [['@babel/preset-typescript', { isTSX: absoluteFilePath.endsWith('.tsx'), allExtensions: true }]],
|
|
49
|
-
});
|
|
50
|
-
if (!ast) {
|
|
51
|
-
throw new Error(`Failed to parse file: ${absoluteFilePath}`);
|
|
52
|
-
}
|
|
53
|
-
return ast;
|
|
54
|
-
}
|
|
42
|
+
const parseUtils_1 = require("./parseUtils");
|
|
55
43
|
/**
|
|
56
44
|
* Gets all the exports from a module, including both definitions and re-exports.
|
|
57
45
|
* @param absoluteFilePath - The absolute path of the file to analyze
|
|
@@ -62,7 +50,7 @@ function getExportsFromModule(absoluteFilePath) {
|
|
|
62
50
|
definitions: [],
|
|
63
51
|
reExports: [],
|
|
64
52
|
};
|
|
65
|
-
const ast = parseTypescriptFile(absoluteFilePath);
|
|
53
|
+
const ast = (0, parseUtils_1.parseTypescriptFile)(absoluteFilePath);
|
|
66
54
|
// For statements like export { foo } with no source, we need to find them source or corresponding export statement.
|
|
67
55
|
// The key here is the local name we are looking for.
|
|
68
56
|
// For export { foo as bar }, the key would be foo
|
|
@@ -97,13 +85,24 @@ function getExportsFromModule(absoluteFilePath) {
|
|
|
97
85
|
for (const specifier of path.node.specifiers) {
|
|
98
86
|
if (specifier.type === 'ExportSpecifier' && specifier.exported.type === 'Identifier') {
|
|
99
87
|
if ('source' in path.node && path.node.source) {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
88
|
+
// Check if this is a default re-export: export { default } from "./module"
|
|
89
|
+
if (specifier.local.name === 'default' && specifier.exported.name === 'default') {
|
|
90
|
+
results.reExports.push({
|
|
91
|
+
type: 'defaultExport',
|
|
92
|
+
exportedName: 'default',
|
|
93
|
+
importPath: path.node.source.value,
|
|
94
|
+
typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
results.reExports.push({
|
|
99
|
+
type: 'namedExport',
|
|
100
|
+
importedName: specifier.local.name,
|
|
101
|
+
exportedName: specifier.exported.name,
|
|
102
|
+
importPath: path.node.source.value,
|
|
103
|
+
typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
|
|
104
|
+
});
|
|
105
|
+
}
|
|
107
106
|
}
|
|
108
107
|
else {
|
|
109
108
|
exportsToFindInSecondPass.set(specifier.local.name, {
|
|
@@ -119,10 +118,21 @@ function getExportsFromModule(absoluteFilePath) {
|
|
|
119
118
|
},
|
|
120
119
|
ExportDefaultDeclaration(path) {
|
|
121
120
|
if (path.node.declaration) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
121
|
+
// If the declaration is an identifier, it might be a re-export of an imported value
|
|
122
|
+
// e.g., import foo from './foo'; export default foo;
|
|
123
|
+
if (path.node.declaration.type === 'Identifier') {
|
|
124
|
+
exportsToFindInSecondPass.set(path.node.declaration.name, {
|
|
125
|
+
importedName: path.node.declaration.name,
|
|
126
|
+
exportedName: 'default',
|
|
127
|
+
typeOnly: false,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
results.definitions.push({
|
|
132
|
+
type: 'defaultExport',
|
|
133
|
+
typeOnly: isTypeOnlyDeclaration(path.node.declaration),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
126
136
|
}
|
|
127
137
|
},
|
|
128
138
|
ExportAllDeclaration(path) {
|
|
@@ -182,11 +192,20 @@ function getExportsFromModule(absoluteFilePath) {
|
|
|
182
192
|
for (const name of names) {
|
|
183
193
|
const candidateExportMatch = exportsToFindInSecondPass.get(name);
|
|
184
194
|
if (candidateExportMatch) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
195
|
+
// Check if this is a default export (export default localVar)
|
|
196
|
+
if (candidateExportMatch.exportedName === 'default') {
|
|
197
|
+
results.definitions.push({
|
|
198
|
+
type: 'defaultExport',
|
|
199
|
+
typeOnly: candidateExportMatch.typeOnly || isTypeOnlyDeclaration(path.node),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
results.definitions.push({
|
|
204
|
+
type: 'namedExport',
|
|
205
|
+
name: candidateExportMatch.exportedName,
|
|
206
|
+
typeOnly: candidateExportMatch.typeOnly || isTypeOnlyDeclaration(path.node),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
190
209
|
exportsToFindInSecondPass.delete(name);
|
|
191
210
|
}
|
|
192
211
|
}
|
|
@@ -196,11 +215,20 @@ function getExportsFromModule(absoluteFilePath) {
|
|
|
196
215
|
const name = getNameFromDeclaration(path.node);
|
|
197
216
|
const candidateExportMatch = exportsToFindInSecondPass.get(name);
|
|
198
217
|
if (candidateExportMatch) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
218
|
+
// Check if this is a default export (export default localVar)
|
|
219
|
+
if (candidateExportMatch.exportedName === 'default') {
|
|
220
|
+
results.definitions.push({
|
|
221
|
+
type: 'defaultExport',
|
|
222
|
+
typeOnly: candidateExportMatch.typeOnly || isTypeOnlyDeclaration(path.node),
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
results.definitions.push({
|
|
227
|
+
type: 'namedExport',
|
|
228
|
+
name: candidateExportMatch.exportedName,
|
|
229
|
+
typeOnly: candidateExportMatch.typeOnly || isTypeOnlyDeclaration(path.node),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
204
232
|
exportsToFindInSecondPass.delete(name);
|
|
205
233
|
}
|
|
206
234
|
}
|