Skip to content

Commit

Permalink
fix(js): generate exports without the filename for barrel files
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Jul 25, 2024
1 parent 1774edd commit 232e2db
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
25 changes: 23 additions & 2 deletions packages/js/src/utils/package-json/update-package-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ describe('getUpdatedPackageJsonContent', () => {
'proj/src/foo.ts',
'proj/src/bar.ts',
'proj/migrations.json',
'proj/feature/index.ts',
],
outputPath: 'dist/proj',
projectRoot: 'proj',
Expand All @@ -219,6 +220,8 @@ describe('getUpdatedPackageJsonContent', () => {
'./bar': './src/bar.js',
'./package.json': './package.json',
'./migrations.json': './migrations.json',
'./feature': './feature/index.js',
'./feature/index': './feature/index.js',
},
});

Expand All @@ -231,7 +234,11 @@ describe('getUpdatedPackageJsonContent', () => {
},
{
main: 'proj/src/index.ts',
additionalEntryPoints: ['proj/src/foo.ts', 'proj/src/bar.ts'],
additionalEntryPoints: [
'proj/src/foo.ts',
'proj/src/bar.ts',
'proj/feature/index.ts',
],
outputPath: 'dist/proj',
projectRoot: 'proj',
format: ['esm'],
Expand All @@ -250,6 +257,8 @@ describe('getUpdatedPackageJsonContent', () => {
'./foo': './src/foo.js',
'./bar': './src/bar.js',
'./package.json': './package.json',
'./feature': './feature/index.js',
'./feature/index': './feature/index.js',
},
});

Expand All @@ -262,7 +271,11 @@ describe('getUpdatedPackageJsonContent', () => {
},
{
main: 'proj/src/index.ts',
additionalEntryPoints: ['proj/src/foo.ts', 'proj/src/bar.ts'],
additionalEntryPoints: [
'proj/src/foo.ts',
'proj/src/bar.ts',
'proj/feature/index.ts',
],
outputPath: 'dist/proj',
projectRoot: 'proj',
format: ['cjs', 'esm'],
Expand All @@ -289,6 +302,14 @@ describe('getUpdatedPackageJsonContent', () => {
import: './src/bar.js',
default: './src/bar.cjs',
},
'./feature': {
import: './feature/index.js',
default: './feature/index.cjs',
},
'./feature/index': {
import: './feature/index.js',
default: './feature/index.cjs',
},
'./package.json': './package.json',
},
});
Expand Down
7 changes: 6 additions & 1 deletion packages/js/src/utils/package-json/update-package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,13 @@ export function getExports(
options.projectRoot
);
const sourceFilePath = relativeDir + fileName;
const entryFilepath = sourceFilePath.replace(/^\.\/src\//, './');
const entryRelativeDir = relativeDir.replace(/^\.\/src\//, './');
const entryFilepath = entryRelativeDir + fileName;
const isJsFile = jsRegex.test(fileExt);
if (isJsFile && fileName === 'index') {
const barrelEntry = entryRelativeDir.replace(/\/$/, '');
exports[barrelEntry] = sourceFilePath + options.fileExt;
}
exports[isJsFile ? entryFilepath : entryFilepath + fileExt] =
sourceFilePath + (isJsFile ? options.fileExt : fileExt);
}
Expand Down

0 comments on commit 232e2db

Please sign in to comment.