From 2a988e454bd8fd163b567e5fa2e67ab89864c3f3 Mon Sep 17 00:00:00 2001 From: yeliex Date: Wed, 11 Sep 2024 18:25:34 +0800 Subject: [PATCH] fix: support file names with `.` (#88) --- src/utils/get-rollup-configs.ts | 2 +- tests/specs/builds/package-exports.ts | 40 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/utils/get-rollup-configs.ts b/src/utils/get-rollup-configs.ts index f4c16ee..ce254c5 100644 --- a/src/utils/get-rollup-configs.ts +++ b/src/utils/get-rollup-configs.ts @@ -262,7 +262,7 @@ export const getRollupConfigs = async ( entryFileNames: (chunk) => { const realPath = fs.realpathSync.native(stripQuery(chunk.facadeModuleId!)); const relativePath = realPath.slice(sourceDirectoryPath.length); - const [filePath] = relativePath.split('.'); + const filePath = path.join(path.dirname(relativePath), chunk.name); return filePath + distExtension; }, }; diff --git a/tests/specs/builds/package-exports.ts b/tests/specs/builds/package-exports.ts index da5ead5..45cdec6 100644 --- a/tests/specs/builds/package-exports.ts +++ b/tests/specs/builds/package-exports.ts @@ -136,5 +136,45 @@ export default testSuite(({ describe }, nodePath: string) => { const utilsMjs = await fixture.readFile('dist/utils.js', 'utf8'); expect(utilsMjs).toMatch('exports.sayHello ='); }); + + test('get basename with dot', async () => { + await using fixture = await createFixture({ + ...packageFixture({ + installTypeScript: true, + }), + src: { + 'index.node.ts': 'export default () => "foo";', + nested: { + 'index.node.ts': 'export default () => "foo";', + }, + }, + 'package.json': createPackageJson({ + exports: { + './': { + default: './dist/index.node.js', + types: './dist/index.node.d.ts', + }, + './nested': { + default: './dist/nested/index.node.js', + types: './dist/nested/index.node.d.ts', + }, + }, + }), + }); + + const pkgrollProcess = await pkgroll([], { + cwd: fixture.path, + nodePath, + }); + + expect(pkgrollProcess.exitCode).toBe(0); + expect(pkgrollProcess.stderr).toBe(''); + + const content = await fixture.readFile('dist/index.node.js', 'utf8'); + expect(content).toMatch('module.exports ='); + await fixture.exists('dist/index.node.d.ts'); + await fixture.exists('dist/nested/index.node.js'); + await fixture.exists('dist/nested/index.node.d.ts'); + }); }); });