@christiango/unbarrel 0.0.7 → 0.0.9

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.
@@ -0,0 +1,21 @@
1
+ /** Error when one of the exports of the barrel file is from another barrel file */
2
+ export interface BarrelFileReferenceError {
3
+ type: 'barrelFileReference';
4
+ /** The name of the export that references the barrel file */
5
+ exportedName: string;
6
+ /** The relative path to the barrel file that gets referenced */
7
+ barrelFilePath: string;
8
+ }
9
+ export interface ExportAllError {
10
+ type: 'exportAll';
11
+ /** The name of the export that references the barrel file */
12
+ barrelFilePath: string;
13
+ }
14
+ export type BarrelFileIssue = BarrelFileReferenceError | ExportAllError;
15
+ /**
16
+ * Analyzes the exports of the provided file and returns any references to barrel files within the current package. External packages are not included.
17
+ * @param absoluteFilePath The absolute path the the file we will analyze
18
+ * @returns An array of barrel file references found in the file
19
+ */
20
+ export declare function getIssuesInBarrelFile(absoluteFilePath: string): BarrelFileIssue[];
21
+ //# sourceMappingURL=getIssuesInBarrelFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIssuesInBarrelFile.d.ts","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":"AAKA,mFAAmF;AACnF,MAAM,WAAW,wBAAwB;IACvC,IAAI,EAAE,qBAAqB,CAAC;IAE5B,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IAErB,gEAAgE;IAChE,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,WAAW,CAAC;IAClB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,eAAe,GAAG,wBAAwB,GAAG,cAAc,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,GAAG,eAAe,EAAE,CA8CjF"}
@@ -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.getIssuesInBarrelFile = getIssuesInBarrelFile;
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 within the current package. External packages are not included.
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 getIssuesInBarrelFile(absoluteFilePath) {
17
+ const result = [];
18
+ const exports = (0, getExportsFromModule_1.getExportsFromModule)(absoluteFilePath);
19
+ for (const reExportToVisit of exports.reExports) {
20
+ // An export star makes the current file a barrel file!
21
+ if (reExportToVisit.type === 'exportAll') {
22
+ result.push({
23
+ type: 'exportAll',
24
+ barrelFilePath: absoluteFilePath,
25
+ });
26
+ }
27
+ // Only consider internal modules (relative paths)
28
+ else if ((0, importUtils_1.isInternalModule)(reExportToVisit.importPath)) {
29
+ const potentialBarrelFilePath = (0, resolveModulePath_1.resolveModulePath)(node_path_1.default.resolve(node_path_1.default.dirname(absoluteFilePath), reExportToVisit.importPath));
30
+ const exportsFromPotentialBarrel = (0, getExportsFromModule_1.getExportsFromModule)(potentialBarrelFilePath);
31
+ const matchingExport = exportsFromPotentialBarrel.definitions.find((definition) => definition.type === 'namedExport' && definition.name === reExportToVisit.exportedName);
32
+ // If we couldn't find a matching named export in the other file that defines the export, it likely is a barrel file reference
33
+ if (!matchingExport) {
34
+ const matchingReExport = exportsFromPotentialBarrel.reExports.find((reExport) => reExport.type === 'namedExport' && reExport.exportedName === reExportToVisit.exportedName);
35
+ // If it's a re-export from an external package, we don't consider it a barrel file reference
36
+ if (matchingReExport && (0, importUtils_1.isInternalModule)(matchingReExport.importPath)) {
37
+ result.push({
38
+ type: 'barrelFileReference',
39
+ exportedName: reExportToVisit.exportedName,
40
+ barrelFilePath: (0, importUtils_1.convertAbsolutePathToRelativeImportPath)(potentialBarrelFilePath, node_path_1.default.dirname(absoluteFilePath)),
41
+ });
42
+ }
43
+ }
44
+ }
45
+ }
46
+ return result;
47
+ }
48
+ //# sourceMappingURL=getIssuesInBarrelFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getIssuesInBarrelFile.js","sourceRoot":"","sources":["../src/getIssuesInBarrelFile.ts"],"names":[],"mappings":";;;;;AA6BA,sDA8CC;AA3ED,iEAA8D;AAC9D,0DAA6B;AAC7B,2DAAwD;AACxD,+CAA0F;AAqB1F;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,gBAAwB;IAC5D,MAAM,MAAM,GAAsB,EAAE,CAAC;IAErC,MAAM,OAAO,GAAG,IAAA,2CAAoB,EAAC,gBAAgB,CAAC,CAAC;IAEvD,KAAK,MAAM,eAAe,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QAChD,uDAAuD;QACvD,IAAI,eAAe,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACzC,MAAM,CAAC,IAAI,CAAC;gBACV,IAAI,EAAE,WAAW;gBACjB,cAAc,EAAE,gBAAgB;aACjC,CAAC,CAAC;QACL,CAAC;QACD,kDAAkD;aAC7C,IAAI,IAAA,8BAAgB,EAAC,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;YACtD,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,MAAM,cAAc,GAAG,0BAA0B,CAAC,WAAW,CAAC,IAAI,CAChE,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,KAAK,aAAa,IAAI,UAAU,CAAC,IAAI,KAAK,eAAe,CAAC,YAAY,CACtG,CAAC;YAEF,8HAA8H;YAC9H,IAAI,CAAC,cAAc,EAAE,CAAC;gBACpB,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,SAAS,CAAC,IAAI,CAChE,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,aAAa,IAAI,QAAQ,CAAC,YAAY,KAAK,eAAe,CAAC,YAAY,CACxG,CAAC;gBAEF,6FAA6F;gBAC7F,IAAI,gBAAgB,IAAI,IAAA,8BAAgB,EAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;oBACtE,MAAM,CAAC,IAAI,CAAC;wBACV,IAAI,EAAE,qBAAqB;wBAC3B,YAAY,EAAE,eAAe,CAAC,YAAY;wBAC1C,cAAc,EAAE,IAAA,qDAAuC,EACrD,uBAAuB,EACvB,mBAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAC/B;qBACF,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { getBarrelFileReferencesInFile } from './getBarrelFileReferencesInFile';
1
+ export { getIssuesInBarrelFile } from './getIssuesInBarrelFile';
2
2
  export { getExportsFromModule } from './getExportsFromModule';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
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; } });
3
+ exports.getExportsFromModule = exports.getIssuesInBarrelFile = void 0;
4
+ var getIssuesInBarrelFile_1 = require("./getIssuesInBarrelFile");
5
+ Object.defineProperty(exports, "getIssuesInBarrelFile", { enumerable: true, get: function () { return getIssuesInBarrelFile_1.getIssuesInBarrelFile; } });
6
6
  var getExportsFromModule_1 = require("./getExportsFromModule");
7
7
  Object.defineProperty(exports, "getExportsFromModule", { enumerable: true, get: function () { return getExportsFromModule_1.getExportsFromModule; } });
8
8
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +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"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,iEAAgE;AAAvD,8HAAA,qBAAqB,OAAA;AAC9B,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@christiango/unbarrel",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Utilities for optimizing barrel files",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,37 +0,0 @@
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
@@ -1 +0,0 @@
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"}