feat(providence-analytics): support multi lvl globs for export maps
This commit is contained in:
parent
78697d3b00
commit
07a95a1a67
2 changed files with 31 additions and 4 deletions
|
|
@ -513,7 +513,9 @@ class InputDataService {
|
||||||
const exposedAndInternalPaths = this.getPathsFromExportMap(pkgJson.exports, {
|
const exposedAndInternalPaths = this.getPathsFromExportMap(pkgJson.exports, {
|
||||||
packageRootPath: startPath,
|
packageRootPath: startPath,
|
||||||
});
|
});
|
||||||
return exposedAndInternalPaths.map(p => p.internal);
|
return exposedAndInternalPaths
|
||||||
|
.map(p => p.internal)
|
||||||
|
.filter(p => cfg.extensions.includes(`${pathLib.extname(p)}`));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @type {string[]} */
|
/** @type {string[]} */
|
||||||
|
|
@ -650,7 +652,8 @@ class InputDataService {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const valueToUseForGlob = stripDotSlashFromLocalPath(resolvedVal);
|
// https://nodejs.org/api/packages.html#subpath-exports
|
||||||
|
const valueToUseForGlob = stripDotSlashFromLocalPath(resolvedVal).replace('*', '**/*');
|
||||||
|
|
||||||
// Generate all possible entries via glob, first strip './'
|
// Generate all possible entries via glob, first strip './'
|
||||||
const internalExportMapPathsForKeyRaw = glob.sync(valueToUseForGlob, {
|
const internalExportMapPathsForKeyRaw = glob.sync(valueToUseForGlob, {
|
||||||
|
|
|
||||||
|
|
@ -540,7 +540,7 @@ build/
|
||||||
it('supports "*" on file level inside key and value of export map entry', async () => {
|
it('supports "*" on file level inside key and value of export map entry', async () => {
|
||||||
const fakeFs = {
|
const fakeFs = {
|
||||||
'/my/proj/internal-folder/file-a.js': 'export const a = 1;',
|
'/my/proj/internal-folder/file-a.js': 'export const a = 1;',
|
||||||
'/my/proj/internal-folder/file-b.js': 'export const b = 2;',
|
'/my/proj/internal-folder/another-folder/file-b.js': 'export const b = 2;',
|
||||||
};
|
};
|
||||||
mock(fakeFs);
|
mock(fakeFs);
|
||||||
const exports = {
|
const exports = {
|
||||||
|
|
@ -550,8 +550,11 @@ build/
|
||||||
packageRootPath: '/my/proj',
|
packageRootPath: '/my/proj',
|
||||||
});
|
});
|
||||||
expect(exportMapPaths).to.eql([
|
expect(exportMapPaths).to.eql([
|
||||||
|
{
|
||||||
|
internal: './internal-folder/another-folder/file-b.js',
|
||||||
|
exposed: './exposed-folder/another-folder/file-b.js',
|
||||||
|
},
|
||||||
{ internal: './internal-folder/file-a.js', exposed: './exposed-folder/file-a.js' },
|
{ internal: './internal-folder/file-a.js', exposed: './exposed-folder/file-a.js' },
|
||||||
{ internal: './internal-folder/file-b.js', exposed: './exposed-folder/file-b.js' },
|
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -574,6 +577,27 @@ build/
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// TDOO: implement
|
||||||
|
it.skip('supports private internal => ""./features/private-internal/*": null"', async () => {
|
||||||
|
const fakeFs = {
|
||||||
|
'/my/proj/internal-folder/file-a.js': 'export const a = 1;',
|
||||||
|
'/my/proj/internal-folder/private-folder/file-b.js': 'export const b = 2;',
|
||||||
|
};
|
||||||
|
mock(fakeFs);
|
||||||
|
const exports = {
|
||||||
|
'./exposed-folder/*.js': './internal-folder/*.js',
|
||||||
|
'./exposed-folder/private-folder/*.js': null,
|
||||||
|
};
|
||||||
|
const exportMapPaths = await InputDataService.getPathsFromExportMap(exports, {
|
||||||
|
packageRootPath: '/my/proj',
|
||||||
|
});
|
||||||
|
expect(exportMapPaths).to.eql([
|
||||||
|
{ internal: './internal-folder/file-a.js', exposed: './exposed-folder/file-a.js' },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: short notation => {"exports": "./index.js"}
|
||||||
|
|
||||||
describe('ResolveMode', () => {
|
describe('ResolveMode', () => {
|
||||||
it('has nodeResolveMode "default" when nothing specified', async () => {
|
it('has nodeResolveMode "default" when nothing specified', async () => {
|
||||||
const fakeFs = {
|
const fakeFs = {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue