fix(js): handle outputFileName correctly when generating package json (#28915)
<!-- Please make sure you have read the submission guidelines before posting an PR --> <!-- https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr --> <!-- Please make sure that your commit message follows our format --> <!-- Example: `fix(nx): must begin with lowercase` --> <!-- If this is a particularly complex change or feature addition, you can request a dedicated Nx release for this pull request branch. Mention someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they will confirm if the PR warrants its own release for testing purposes, and generate it for you if appropriate. --> ## Current Behavior <!-- This is the behavior we have today --> ## Expected Behavior <!-- This is the behavior we should expect with the changes in this PR --> ## Related Issue(s) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes #28894
This commit is contained in:
parent
dbaeb86102
commit
907e58fda7
@ -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', () => {
|
describe('updatePackageJson', () => {
|
||||||
|
|||||||
@ -242,7 +242,7 @@ export function getExports(
|
|||||||
): Exports {
|
): Exports {
|
||||||
const outputDir = getOutputDir(options);
|
const outputDir = getOutputDir(options);
|
||||||
const mainFile = options.outputFileName
|
const mainFile = options.outputFileName
|
||||||
? options.outputFileName.replace(/\.[tj]s$/, '')
|
? basename(options.outputFileName).replace(/\.[tj]s$/, '')
|
||||||
: basename(options.main).replace(/\.[tj]s$/, '');
|
: basename(options.main).replace(/\.[tj]s$/, '');
|
||||||
const exports: Exports = {
|
const exports: Exports = {
|
||||||
'.': outputDir + mainFile + options.fileExt,
|
'.': outputDir + mainFile + options.fileExt,
|
||||||
@ -377,9 +377,9 @@ export function getOutputDir(
|
|||||||
: options.outputPath;
|
: options.outputPath;
|
||||||
const relativeOutputPath = relative(packageJsonDir, options.outputPath);
|
const relativeOutputPath = relative(packageJsonDir, options.outputPath);
|
||||||
const relativeMainDir = options.outputFileName
|
const relativeMainDir = options.outputFileName
|
||||||
? ''
|
? dirname(options.outputFileName)
|
||||||
: relative(options.rootDir ?? options.projectRoot, dirname(options.main));
|
: relative(options.rootDir ?? options.projectRoot, dirname(options.main));
|
||||||
const outputDir = join(relativeOutputPath, relativeMainDir);
|
const outputDir = joinPathFragments(relativeOutputPath, relativeMainDir);
|
||||||
|
|
||||||
return outputDir === '.' ? `./` : `./${outputDir}/`;
|
return outputDir === '.' ? `./` : `./${outputDir}/`;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user