@christiango/unbarrel 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Christian Gonzalez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @christiango/unbarrel
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/](Speeding up the JavaScript ecosystem - The barrel file debacle)
package/lib/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/lib/cli.js ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const commander_1 = require("commander");
38
+ const unbarrel_1 = require("./unbarrel");
39
+ const path = __importStar(require("path"));
40
+ const program = new commander_1.Command();
41
+ program.name('barrel-file-utils').description('Utilities for working with barrel files').version('1.0.0');
42
+ program
43
+ .command('unbarrel')
44
+ .description('Convert the first export * statement to export {} in a barrel file')
45
+ .argument('<rootBarrelFile>', 'Path to the root barrel file to process')
46
+ .action(async (rootBarrelFile) => {
47
+ try {
48
+ // Resolve to absolute path
49
+ const absolutePath = path.resolve(rootBarrelFile);
50
+ console.log(`Processing barrel file: ${absolutePath}`);
51
+ await (0, unbarrel_1.unbarrel)(absolutePath);
52
+ console.log('✅ Successfully ran unbarrel on the specified file');
53
+ }
54
+ catch (error) {
55
+ console.error('❌ Error:', error instanceof Error ? error.message : String(error));
56
+ process.exit(1);
57
+ }
58
+ });
59
+ program.parse();
60
+ //# sourceMappingURL=cli.js.map
package/lib/cli.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yCAAoC;AACpC,yCAAsC;AACtC,2CAA6B;AAE7B,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,WAAW,CAAC,yCAAyC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAE1G,OAAO;KACJ,OAAO,CAAC,UAAU,CAAC;KACnB,WAAW,CAAC,oEAAoE,CAAC;KACjF,QAAQ,CAAC,kBAAkB,EAAE,yCAAyC,CAAC;KACvE,MAAM,CAAC,KAAK,EAAE,cAAsB,EAAE,EAAE;IACvC,IAAI,CAAC;QACH,2BAA2B;QAC3B,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAElD,OAAO,CAAC,GAAG,CAAC,2BAA2B,YAAY,EAAE,CAAC,CAAC;QAEvD,MAAM,IAAA,mBAAQ,EAAC,YAAY,CAAC,CAAC;QAE7B,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;IACnE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,11 @@
1
+ export interface BarrelFileReference {
2
+ /** The relative path to the barrel file that was found */
3
+ barrelFilePath: string;
4
+ }
5
+ /**
6
+ * Analyzes the exports of the provided file and returns any references to barrel files.
7
+ * @param absoluteFilePath The absolute path the the file we will analyze
8
+ * @returns An array of barrel file references found in the file
9
+ */
10
+ export declare function getBarrelFileReferencesInFile(absoluteFilePath: string): BarrelFileReference[];
11
+ //# sourceMappingURL=getBarrelFileReferencesInFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBarrelFileReferencesInFile.d.ts","sourceRoot":"","sources":["../src/getBarrelFileReferencesInFile.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,mBAAmB;IAClC,0DAA0D;IAC1D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,gBAAgB,EAAE,MAAM,GAAG,mBAAmB,EAAE,CA4B7F"}
@@ -0,0 +1,37 @@
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.getBarrelFileReferencesInFile = getBarrelFileReferencesInFile;
7
+ const getExportsFromModule_1 = require("./getExportsFromModule");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const resolveModulePath_1 = require("./resolveModulePath");
10
+ const importUtils_1 = require("./importUtils");
11
+ /**
12
+ * Analyzes the exports of the provided file and returns any references to barrel files.
13
+ * @param absoluteFilePath The absolute path the the file we will analyze
14
+ * @returns An array of barrel file references found in the file
15
+ */
16
+ function getBarrelFileReferencesInFile(absoluteFilePath) {
17
+ const result = [];
18
+ const exports = (0, getExportsFromModule_1.getExportsFromModule)(absoluteFilePath);
19
+ for (const reExportToVisit of exports.reExports) {
20
+ if ((0, importUtils_1.isInternalModule)(reExportToVisit.importPath)) {
21
+ const potentialBarrelFilePath = (0, resolveModulePath_1.resolveModulePath)(node_path_1.default.resolve(node_path_1.default.dirname(absoluteFilePath), reExportToVisit.importPath));
22
+ const exportsFromPotentialBarrel = (0, getExportsFromModule_1.getExportsFromModule)(potentialBarrelFilePath);
23
+ if (exportsFromPotentialBarrel.reExports.length > 0) {
24
+ result.push({
25
+ barrelFilePath: (0, importUtils_1.convertAbsolutePathToRelativeImportPath)(potentialBarrelFilePath, node_path_1.default.dirname(absoluteFilePath)),
26
+ });
27
+ }
28
+ }
29
+ else {
30
+ result.push({
31
+ barrelFilePath: reExportToVisit.importPath,
32
+ });
33
+ }
34
+ }
35
+ return result;
36
+ }
37
+ //# sourceMappingURL=getBarrelFileReferencesInFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBarrelFileReferencesInFile.js","sourceRoot":"","sources":["../src/getBarrelFileReferencesInFile.ts"],"names":[],"mappings":";;;;;AAeA,sEA4BC;AA3CD,iEAA8D;AAC9D,0DAA6B;AAC7B,2DAAwD;AACxD,+CAA0F;AAO1F;;;;GAIG;AACH,SAAgB,6BAA6B,CAAC,gBAAwB;IACpE,MAAM,MAAM,GAA0B,EAAE,CAAC;IAEzC,MAAM,OAAO,GAAG,IAAA,2CAAoB,EAAC,gBAAgB,CAAC,CAAC;IAEvD,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QAChD,IAAI,IAAA,8BAAgB,EAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,MAAM,uBAAuB,GAAG,IAAA,qCAAiB,EAC/C,mBAAI,CAAC,OAAO,CAAC,mBAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,eAAe,CAAC,UAAU,CAAC,CACzE,CAAC;YACF,MAAM,0BAA0B,GAAG,IAAA,2CAAoB,EAAC,uBAAuB,CAAC,CAAC;YAEjF,IAAI,0BAA0B,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpD,MAAM,CAAC,IAAI,CAAC;oBACV,cAAc,EAAE,IAAA,qDAAuC,EACrD,uBAAuB,EACvB,mBAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAC/B;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC;gBACV,cAAc,EAAE,eAAe,CAAC,UAAU;aAC3C,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,56 @@
1
+ export interface NamedExportDefinition {
2
+ type: 'namedExport';
3
+ /** Set to true if the import is a type only export, false if it is exported as a value */
4
+ typeOnly: boolean;
5
+ /** The name of the export as it is exported from the module */
6
+ name: string;
7
+ }
8
+ export interface DefaultExportDefinition {
9
+ type: 'defaultExport';
10
+ /** Set to true if the import is a type only export, false if it is exported as a value */
11
+ typeOnly: boolean;
12
+ }
13
+ /** An export definition */
14
+ export type ExportDefinition = NamedExportDefinition | DefaultExportDefinition;
15
+ /** This is set for any export * statements */
16
+ export interface ModuleReExportAll {
17
+ type: 'exportAll';
18
+ /** The name of the export as it is imported in the module */
19
+ importPath: string;
20
+ }
21
+ export interface ModuleNamedReExport {
22
+ type: 'namedExport';
23
+ /** The name of the export as it is imported in the module */
24
+ importedName: string;
25
+ /** The name of the export as it is exported from the module, it will not be the same as the imported name when the as operator is used */
26
+ exportedName: string;
27
+ /** The path to the module where this re-export was imported from */
28
+ importPath: string;
29
+ /** Set to true if the import is a type only export, false if it is exported as a value */
30
+ typeOnly: boolean;
31
+ }
32
+ export interface ModuleDefaultReExport {
33
+ type: 'defaultExport';
34
+ /** The name of the export as it is exported from the module, it will not be the same as the imported name when the as operator is used */
35
+ exportedName: string;
36
+ /** The path to the module where this re-export was imported from */
37
+ importPath: string;
38
+ /** Set to true if the import is a type only export, false if it is exported as a value */
39
+ typeOnly: boolean;
40
+ }
41
+ /** An item re-exported by the module */
42
+ export type ModuleReExport = ModuleReExportAll | ModuleNamedReExport | ModuleDefaultReExport;
43
+ /** All the exports in a given module */
44
+ export interface ModuleExports {
45
+ /** The exports whose definition lives in this module */
46
+ definitions: ExportDefinition[];
47
+ /** The exports whose definitions reside in another module */
48
+ reExports: ModuleReExport[];
49
+ }
50
+ /**
51
+ * Gets all the exports from a module, including both definitions and re-exports.
52
+ * @param absoluteFilePath - The absolute path of the file to analyze
53
+ * @returns - The module exports
54
+ */
55
+ export declare function getExportsFromModule(absoluteFilePath: string): ModuleExports;
56
+ //# sourceMappingURL=getExportsFromModule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExportsFromModule.d.ts","sourceRoot":"","sources":["../src/getExportsFromModule.ts"],"names":[],"mappings":"AAmBA,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,CAyI5E"}
@@ -0,0 +1,218 @@
1
+ "use strict";
2
+ var __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.getExportsFromModule = getExportsFromModule;
40
+ const babel = __importStar(require("@babel/core"));
41
+ const fs = __importStar(require("node:fs"));
42
+ const traverse_1 = __importDefault(require("@babel/traverse"));
43
+ /** Parses a typescript file into an AST using babel */
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
+ }
55
+ /**
56
+ * Gets all the exports from a module, including both definitions and re-exports.
57
+ * @param absoluteFilePath - The absolute path of the file to analyze
58
+ * @returns - The module exports
59
+ */
60
+ function getExportsFromModule(absoluteFilePath) {
61
+ const results = {
62
+ definitions: [],
63
+ reExports: [],
64
+ };
65
+ const ast = parseTypescriptFile(absoluteFilePath);
66
+ // For statements like export { foo } with no source, we need to find them source or corresponding export statement.
67
+ // The key here is the local name we are looking for.
68
+ // For export { foo as bar }, the key would be foo
69
+ // For export { foo }, the key would be foo
70
+ const exportsToFindInSecondPass = new Map();
71
+ (0, traverse_1.default)(ast, {
72
+ ExportNamedDeclaration(path) {
73
+ if ('declaration' in path.node && path.node.declaration) {
74
+ const name = getNameFromDeclaration(path.node.declaration);
75
+ results.definitions.push({
76
+ type: 'namedExport',
77
+ name,
78
+ typeOnly: isTypeOnlyDeclaration(path.node.declaration),
79
+ });
80
+ }
81
+ else if (path.node.specifiers) {
82
+ if (path.node.specifiers.length > 0) {
83
+ for (const specifier of path.node.specifiers) {
84
+ if (specifier.type === 'ExportSpecifier' && specifier.exported.type === 'Identifier') {
85
+ if ('source' in path.node && path.node.source) {
86
+ results.reExports.push({
87
+ type: 'namedExport',
88
+ importedName: specifier.local.name,
89
+ exportedName: specifier.exported.name,
90
+ importPath: path.node.source.value,
91
+ typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
92
+ });
93
+ }
94
+ else {
95
+ exportsToFindInSecondPass.set(specifier.local.name, {
96
+ importedName: specifier.local.name,
97
+ exportedName: specifier.exported.name,
98
+ typeOnly: specifier.exportKind === 'type' || path.node.exportKind === 'type',
99
+ });
100
+ }
101
+ }
102
+ }
103
+ }
104
+ }
105
+ },
106
+ ExportDefaultDeclaration(path) {
107
+ if (path.node.declaration) {
108
+ results.definitions.push({
109
+ type: 'defaultExport',
110
+ typeOnly: isTypeOnlyDeclaration(path.node.declaration),
111
+ });
112
+ }
113
+ },
114
+ ExportAllDeclaration(path) {
115
+ if ('source' in path.node && path.node.source) {
116
+ results.reExports.push({
117
+ type: 'exportAll',
118
+ importPath: path.node.source.value,
119
+ });
120
+ }
121
+ },
122
+ });
123
+ if (exportsToFindInSecondPass.size > 0) {
124
+ (0, traverse_1.default)(ast, {
125
+ ImportDeclaration(path) {
126
+ const importPath = path.node.source.value;
127
+ for (const specifier of path.node.specifiers) {
128
+ if (specifier.type === 'ImportDefaultSpecifier' ||
129
+ (specifier.type === 'ImportSpecifier' && getImportedNameFromSpecifier(specifier) === 'default')) {
130
+ const exportedName = specifier.local.name;
131
+ const candidateExportMatch = exportsToFindInSecondPass.get(exportedName);
132
+ if (candidateExportMatch) {
133
+ results.reExports.push({
134
+ type: 'defaultExport',
135
+ exportedName: candidateExportMatch.exportedName,
136
+ importPath,
137
+ typeOnly: candidateExportMatch.typeOnly,
138
+ });
139
+ exportsToFindInSecondPass.delete(exportedName);
140
+ }
141
+ }
142
+ else if (specifier.type === 'ImportSpecifier') {
143
+ const importedName = getImportedNameFromSpecifier(specifier);
144
+ const exportedName = specifier.local.name;
145
+ const candidateExportMatch = exportsToFindInSecondPass.get(exportedName);
146
+ if (candidateExportMatch) {
147
+ results.reExports.push({
148
+ type: 'namedExport',
149
+ importedName,
150
+ exportedName: candidateExportMatch.exportedName,
151
+ importPath,
152
+ typeOnly: candidateExportMatch.typeOnly || specifier.importKind === 'type' || path.node.importKind === 'type',
153
+ });
154
+ exportsToFindInSecondPass.delete(exportedName);
155
+ }
156
+ }
157
+ }
158
+ },
159
+ Declaration(path) {
160
+ if (path.node.type !== 'ImportDeclaration' &&
161
+ path.node.type !== 'ExportNamedDeclaration' &&
162
+ path.node.type !== 'ExportDefaultDeclaration' &&
163
+ path.node.type !== 'ExportAllDeclaration') {
164
+ const name = getNameFromDeclaration(path.node);
165
+ const candidateExportMatch = exportsToFindInSecondPass.get(name);
166
+ if (candidateExportMatch) {
167
+ results.definitions.push({
168
+ type: 'namedExport',
169
+ name: candidateExportMatch.exportedName,
170
+ typeOnly: candidateExportMatch.typeOnly || isTypeOnlyDeclaration(path.node),
171
+ });
172
+ exportsToFindInSecondPass.delete(name);
173
+ }
174
+ }
175
+ },
176
+ });
177
+ }
178
+ if (exportsToFindInSecondPass.size !== 0) {
179
+ throw new Error(`Could not find source for exports: ${[...exportsToFindInSecondPass.keys()].join(',')}`);
180
+ }
181
+ return results;
182
+ }
183
+ function getImportedNameFromSpecifier(specifier) {
184
+ return specifier.imported.type === 'Identifier' ? specifier.imported.name : specifier.imported.value;
185
+ }
186
+ function isTypeOnlyDeclaration(declaration) {
187
+ return declaration.type === 'TSTypeAliasDeclaration' || declaration.type === 'TSInterfaceDeclaration';
188
+ }
189
+ /**
190
+ * Extracts the name of a defined function, class, interface, type alias ,etc
191
+ */
192
+ function getNameFromDeclaration(declaration) {
193
+ if (declaration.type === 'FunctionDeclaration' ||
194
+ declaration.type === 'ClassDeclaration' ||
195
+ declaration.type == 'TSInterfaceDeclaration' ||
196
+ declaration.type === 'TSTypeAliasDeclaration' ||
197
+ declaration.type == 'TSDeclareFunction' ||
198
+ declaration.type === 'TSEnumDeclaration') {
199
+ if (!declaration.id) {
200
+ throw new Error(`${declaration} without an id found, we don't support these yet`);
201
+ }
202
+ return declaration.id?.name;
203
+ }
204
+ if (declaration.type === 'VariableDeclaration') {
205
+ if (declaration.declarations.length === 0) {
206
+ throw new Error(`Variable declaration without any declarators found: ${declaration}`);
207
+ }
208
+ if (declaration.declarations.length > 1) {
209
+ throw new Error(`Variable declaration with multiple declarators found: ${declaration}`);
210
+ }
211
+ if (!('name' in declaration.declarations[0].id)) {
212
+ throw new Error(`Variable declaration without name found: ${declaration}`);
213
+ }
214
+ return declaration.declarations[0].id.name;
215
+ }
216
+ throw new Error(`getNameFromDeclaration currently does not support declaration type: ${declaration.type}`);
217
+ }
218
+ //# sourceMappingURL=getExportsFromModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getExportsFromModule.js","sourceRoot":"","sources":["../src/getExportsFromModule.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,oDAyIC;AA1ND,mDAAqC;AACrC,4CAA8B;AAE9B,+DAAuC;AAEvC,uDAAuD;AACvD,SAAS,mBAAmB,CAAC,gBAAwB;IACnD,MAAM,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAChE,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,YAAY,EAAE;QACpC,UAAU,EAAE,QAAQ;QACpB,OAAO,EAAE,CAAC,CAAC,0BAA0B,EAAE,EAAE,KAAK,EAAE,gBAAgB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC;KAC3G,CAAC,CAAC;IACH,IAAI,CAAC,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C,MAAM,IAAI,KAAK,CAAC,yDAAyD,WAAW,EAAE,CAAC,CAAC;QAC1F,CAAC;QACD,IAAI,CAAC,CAAC,MAAM,IAAI,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,4CAA4C,WAAW,EAAE,CAAC,CAAC;QAC7E,CAAC;QACD,OAAO,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC;IAC7C,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,uEAAuE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;AAC7G,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Returns true if the import path is to an internal module and false if it's an external package
3
+ * @param importPath The path to check
4
+ * @returns true for relative path like './foo' and false for external paths like 'react'
5
+ */
6
+ export declare function isInternalModule(importPath: string): boolean;
7
+ /**
8
+ * Converts node paths into ESM import paths, such as foo/bar into ./foo/bar
9
+ * @param relativePath The path to convert
10
+ * @returns The converted path, which is suitable for ESM imports
11
+ */
12
+ export declare function convertToESMImportPath(relativePath: string): string;
13
+ /**
14
+ * Converts an absolute path to a relative ESM import path. For example /foo/bar/baz.ts turns into ./baz.ts for baseDir /foo/bar
15
+ * @param absolutePath The absolute path to convert into a relative path
16
+ * @param baseDir The base directory to resolve the relative path against
17
+ */
18
+ export declare function convertAbsolutePathToRelativeImportPath(absolutePath: string, baseDir: string): string;
19
+ //# sourceMappingURL=importUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importUtils.d.ts","sourceRoot":"","sources":["../src/importUtils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAE5D;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAMnE;AAED;;;;GAIG;AACH,wBAAgB,uCAAuC,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAGrG"}
@@ -0,0 +1,38 @@
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.isInternalModule = isInternalModule;
7
+ exports.convertToESMImportPath = convertToESMImportPath;
8
+ exports.convertAbsolutePathToRelativeImportPath = convertAbsolutePathToRelativeImportPath;
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ /**
11
+ * Returns true if the import path is to an internal module and false if it's an external package
12
+ * @param importPath The path to check
13
+ * @returns true for relative path like './foo' and false for external paths like 'react'
14
+ */
15
+ function isInternalModule(importPath) {
16
+ return importPath.startsWith('.');
17
+ }
18
+ /**
19
+ * Converts node paths into ESM import paths, such as foo/bar into ./foo/bar
20
+ * @param relativePath The path to convert
21
+ * @returns The converted path, which is suitable for ESM imports
22
+ */
23
+ function convertToESMImportPath(relativePath) {
24
+ if (relativePath.startsWith('.')) {
25
+ return relativePath;
26
+ }
27
+ return './' + relativePath;
28
+ }
29
+ /**
30
+ * Converts an absolute path to a relative ESM import path. For example /foo/bar/baz.ts turns into ./baz.ts for baseDir /foo/bar
31
+ * @param absolutePath The absolute path to convert into a relative path
32
+ * @param baseDir The base directory to resolve the relative path against
33
+ */
34
+ function convertAbsolutePathToRelativeImportPath(absolutePath, baseDir) {
35
+ const relativePath = node_path_1.default.relative(baseDir, absolutePath);
36
+ return convertToESMImportPath(relativePath);
37
+ }
38
+ //# sourceMappingURL=importUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"importUtils.js","sourceRoot":"","sources":["../src/importUtils.ts"],"names":[],"mappings":";;;;;AAOA,4CAEC;AAOD,wDAMC;AAOD,0FAGC;AAhCD,0DAA6B;AAE7B;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,UAAkB;IACjD,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AACpC,CAAC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CAAC,YAAoB;IACzD,IAAI,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,OAAO,IAAI,GAAG,YAAY,CAAC;AAC7B,CAAC;AAED;;;;GAIG;AACH,SAAgB,uCAAuC,CAAC,YAAoB,EAAE,OAAe;IAC3F,MAAM,YAAY,GAAG,mBAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC1D,OAAO,sBAAsB,CAAC,YAAY,CAAC,CAAC;AAC9C,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { getBarrelFileReferencesInFile } from './getBarrelFileReferencesInFile';
2
+ export { getExportsFromModule } from './getExportsFromModule';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getExportsFromModule = exports.getBarrelFileReferencesInFile = void 0;
4
+ var getBarrelFileReferencesInFile_1 = require("./getBarrelFileReferencesInFile");
5
+ Object.defineProperty(exports, "getBarrelFileReferencesInFile", { enumerable: true, get: function () { return getBarrelFileReferencesInFile_1.getBarrelFileReferencesInFile; } });
6
+ var getExportsFromModule_1 = require("./getExportsFromModule");
7
+ Object.defineProperty(exports, "getExportsFromModule", { enumerable: true, get: function () { return getExportsFromModule_1.getExportsFromModule; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iFAAgF;AAAvE,8IAAA,6BAA6B,OAAA;AACtC,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,6 @@
1
+ /** Given a module path, attempts to get the path to that module, accounting to the fact that the absolute path may be missing an extension or pointing to a barrel file (index.ts/js etc)
2
+ * @param absoluteModulePath - The absolute path to the module, which may be missing an extension or pointing to a directory
3
+ * @returns - The resolved absolute path to the module file
4
+ */
5
+ export declare function resolveModulePath(absoluteModulePath: string): string;
6
+ //# sourceMappingURL=resolveModulePath.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveModulePath.d.ts","sourceRoot":"","sources":["../src/resolveModulePath.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAoCpE"}
@@ -0,0 +1,48 @@
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.resolveModulePath = resolveModulePath;
7
+ const node_fs_1 = __importDefault(require("node:fs"));
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ /** Given a module path, attempts to get the path to that module, accounting to the fact that the absolute path may be missing an extension or pointing to a barrel file (index.ts/js etc)
10
+ * @param absoluteModulePath - The absolute path to the module, which may be missing an extension or pointing to a directory
11
+ * @returns - The resolved absolute path to the module file
12
+ */
13
+ function resolveModulePath(absoluteModulePath) {
14
+ // Resolve the actual file path - could be a file or directory with index.ts
15
+ let resolvedFilePath;
16
+ try {
17
+ // Try to resolve as a module first
18
+ resolvedFilePath = require.resolve(absoluteModulePath);
19
+ }
20
+ catch {
21
+ // If that fails, try common TypeScript extensions and index files
22
+ const extensions = ['.ts', '.tsx', '.js', '.jsx'];
23
+ const indexFiles = ['index.ts', 'index.tsx', 'index.js', 'index.jsx'];
24
+ // Try direct file with extensions
25
+ for (const ext of extensions) {
26
+ const filePath = absoluteModulePath + ext;
27
+ if (node_fs_1.default.existsSync(filePath)) {
28
+ resolvedFilePath = filePath;
29
+ break;
30
+ }
31
+ }
32
+ // Try index files in directory
33
+ if (!resolvedFilePath) {
34
+ for (const indexFile of indexFiles) {
35
+ const filePath = node_path_1.default.join(absoluteModulePath, indexFile);
36
+ if (node_fs_1.default.existsSync(filePath)) {
37
+ resolvedFilePath = filePath;
38
+ break;
39
+ }
40
+ }
41
+ }
42
+ }
43
+ if (!resolvedFilePath) {
44
+ throw new Error(`Could not resolve module: ${absoluteModulePath}`);
45
+ }
46
+ return resolvedFilePath;
47
+ }
48
+ //# sourceMappingURL=resolveModulePath.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveModulePath.js","sourceRoot":"","sources":["../src/resolveModulePath.ts"],"names":[],"mappings":";;;;;AAOA,8CAoCC;AA3CD,sDAAyB;AACzB,0DAA6B;AAE7B;;;GAGG;AACH,SAAgB,iBAAiB,CAAC,kBAA0B;IAC1D,4EAA4E;IAC5E,IAAI,gBAAoC,CAAC;IACzC,IAAI,CAAC;QACH,mCAAmC;QACnC,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACzD,CAAC;IAAC,MAAM,CAAC;QACP,kEAAkE;QAClE,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,MAAM,UAAU,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;QAEtE,kCAAkC;QAClC,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;YAC7B,MAAM,QAAQ,GAAG,kBAAkB,GAAG,GAAG,CAAC;YAC1C,IAAI,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC5B,gBAAgB,GAAG,QAAQ,CAAC;gBAC5B,MAAM;YACR,CAAC;QACH,CAAC;QAED,+BAA+B;QAC/B,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,MAAM,QAAQ,GAAG,mBAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE,SAAS,CAAC,CAAC;gBAC1D,IAAI,iBAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;oBAC5B,gBAAgB,GAAG,QAAQ,CAAC;oBAC5B,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,6BAA6B,kBAAkB,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,OAAO,gBAAgB,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * This tool will process a barrel file and make the following optimizations:
3
+ * - Export * statements will be inlined to include the full set of exports reachable by that export *.
4
+ * - All export statements will be updated to point at the module with the declaration, removing all references to other barrel files.
5
+ * @param absoluteRootPath The absolute path to the root file this tool was invoked on
6
+ */
7
+ export declare function unbarrel(absoluteRootPath: string): void;
8
+ //# sourceMappingURL=unbarrel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbarrel.d.ts","sourceRoot":"","sources":["../src/unbarrel.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,QAAI"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unbarrel = unbarrel;
4
+ /**
5
+ * This tool will process a barrel file and make the following optimizations:
6
+ * - Export * statements will be inlined to include the full set of exports reachable by that export *.
7
+ * - All export statements will be updated to point at the module with the declaration, removing all references to other barrel files.
8
+ * @param absoluteRootPath The absolute path to the root file this tool was invoked on
9
+ */
10
+ function unbarrel(absoluteRootPath) { }
11
+ //# sourceMappingURL=unbarrel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unbarrel.js","sourceRoot":"","sources":["../src/unbarrel.ts"],"names":[],"mappings":";;AAMA,4BAAqD;AANrD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,gBAAwB,IAAG,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@christiango/unbarrel",
3
+ "version": "0.0.4",
4
+ "description": "Utilities for optimizing barrel files",
5
+ "main": "lib/index.js",
6
+ "bin": {
7
+ "unbarrel": "lib/cli.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "bundle": "esbuild ./src/cli.ts --bundle --platform=node --outfile=dist/cli.js",
12
+ "test": "npm run build && node --test lib/**/*.test.js",
13
+ "prettier:check": "prettier --check \"**/*.{ts,tsx,json,md}\"",
14
+ "prettier": "prettier --write \"**/*.{ts,tsx,json,md}\"",
15
+ "clean": "node ./scripts/clean.js",
16
+ "scrub": "node ./scripts/clean.js --scrub"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "https://github.com/christiango/unbarrel.git"
21
+ },
22
+ "author": "Christian Gonzalez",
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "@babel/core": "^7.28.0",
26
+ "@babel/plugin-syntax-jsx": "^7.27.1",
27
+ "@babel/plugin-syntax-typescript": "^7.27.1",
28
+ "@babel/preset-typescript": "^7.27.1",
29
+ "@babel/traverse": "^7.28.0",
30
+ "commander": "^14.0.0",
31
+ "esbuild": "^0.25.6"
32
+ },
33
+ "devDependencies": {
34
+ "@types/babel__core": "^7.20.5",
35
+ "@types/babel__traverse": "^7.18.0",
36
+ "@types/mock-fs": "^4.13.4",
37
+ "@types/node": "^22.0.0",
38
+ "mock-fs": "^5.5.0",
39
+ "prettier": "^2.8.0",
40
+ "typescript": "^5.8.3"
41
+ }
42
+ }