@christiango/unbarrel 0.0.8 → 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.
- package/lib/getIssuesInBarrelFile.d.ts +21 -0
- package/lib/getIssuesInBarrelFile.d.ts.map +1 -0
- package/lib/getIssuesInBarrelFile.js +48 -0
- package/lib/getIssuesInBarrelFile.js.map +1 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/lib/getBarrelFileReferencesInFile.d.ts +0 -11
- package/lib/getBarrelFileReferencesInFile.d.ts.map +0 -1
- package/lib/getBarrelFileReferencesInFile.js +0 -35
- package/lib/getBarrelFileReferencesInFile.js.map +0 -1
|
@@ -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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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
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
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.
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "
|
|
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,
|
|
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,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 within the current package. External packages are not included.
|
|
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,CA6B7F"}
|
|
@@ -1,35 +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 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 getBarrelFileReferencesInFile(absoluteFilePath) {
|
|
17
|
-
const result = [];
|
|
18
|
-
const exports = (0, getExportsFromModule_1.getExportsFromModule)(absoluteFilePath);
|
|
19
|
-
for (const reExportToVisit of exports.reExports) {
|
|
20
|
-
// Only consider internal modules (relative paths)
|
|
21
|
-
if ((0, importUtils_1.isInternalModule)(reExportToVisit.importPath)) {
|
|
22
|
-
const potentialBarrelFilePath = (0, resolveModulePath_1.resolveModulePath)(node_path_1.default.resolve(node_path_1.default.dirname(absoluteFilePath), reExportToVisit.importPath));
|
|
23
|
-
const exportsFromPotentialBarrel = (0, getExportsFromModule_1.getExportsFromModule)(potentialBarrelFilePath);
|
|
24
|
-
if (exportsFromPotentialBarrel.reExports.length > 0 &&
|
|
25
|
-
// Don't consider re-exports from external packages a barrel file reference
|
|
26
|
-
exportsFromPotentialBarrel.reExports.filter((e) => (0, importUtils_1.isInternalModule)(e.importPath)).length > 0) {
|
|
27
|
-
result.push({
|
|
28
|
-
barrelFilePath: (0, importUtils_1.convertAbsolutePathToRelativeImportPath)(potentialBarrelFilePath, node_path_1.default.dirname(absoluteFilePath)),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=getBarrelFileReferencesInFile.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getBarrelFileReferencesInFile.js","sourceRoot":"","sources":["../src/getBarrelFileReferencesInFile.ts"],"names":[],"mappings":";;;;;AAeA,sEA6BC;AA5CD,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,kDAAkD;QAClD,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,IACE,0BAA0B,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC;gBAC/C,2EAA2E;gBAC3E,0BAA0B,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,8BAAgB,EAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAC7F,CAAC;gBACD,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;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|