diff --git a/packages/js/src/utils/package-json/update-package-json.spec.ts b/packages/js/src/utils/package-json/update-package-json.spec.ts index 784cd866c1530..e2d225a6b7e5b 100644 --- a/packages/js/src/utils/package-json/update-package-json.spec.ts +++ b/packages/js/src/utils/package-json/update-package-json.spec.ts @@ -405,6 +405,38 @@ describe('getUpdatedPackageJsonContent', () => { }, }); }); + + it('should handle outputFileName correctly', () => { + expect( + getUpdatedPackageJsonContent( + { + name: 'test', + version: '0.0.1', + }, + { + main: 'proj/src/index.ts', + outputPath: 'dist/proj', + projectRoot: 'proj', + format: ['cjs'], + generateExportsField: true, + outputFileName: 'src/index.js', + } + ) + ).toEqual({ + name: 'test', + main: './src/index.js', + types: './src/index.d.ts', + version: '0.0.1', + type: 'commonjs', + exports: { + '.': { + default: './src/index.js', + types: './src/index.d.ts', + }, + './package.json': './package.json', + }, + }); + }); }); describe('updatePackageJson', () => { diff --git a/packages/js/src/utils/package-json/update-package-json.ts b/packages/js/src/utils/package-json/update-package-json.ts index 523a12774c948..c8776a6710f16 100644 --- a/packages/js/src/utils/package-json/update-package-json.ts +++ b/packages/js/src/utils/package-json/update-package-json.ts @@ -242,7 +242,7 @@ export function getExports( ): Exports { const outputDir = getOutputDir(options); const mainFile = options.outputFileName - ? options.outputFileName.replace(/\.[tj]s$/, '') + ? basename(options.outputFileName).replace(/\.[tj]s$/, '') : basename(options.main).replace(/\.[tj]s$/, ''); const exports: Exports = { '.': outputDir + mainFile + options.fileExt, @@ -377,9 +377,9 @@ export function getOutputDir( : options.outputPath; const relativeOutputPath = relative(packageJsonDir, options.outputPath); const relativeMainDir = options.outputFileName - ? '' + ? dirname(options.outputFileName) : relative(options.rootDir ?? options.projectRoot, dirname(options.main)); - const outputDir = join(relativeOutputPath, relativeMainDir); + const outputDir = joinPathFragments(relativeOutputPath, relativeMainDir); return outputDir === '.' ? `./` : `./${outputDir}/`; }