fix(misc): generate the "types" field in package.json if no set (#27147)
<!-- 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 #20003
This commit is contained in:
parent
fa976e04c8
commit
5e4f05c52b
@ -170,9 +170,6 @@ export async function* swcExecutor(
|
||||
format: [
|
||||
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
||||
],
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
},
|
||||
context
|
||||
);
|
||||
@ -192,9 +189,6 @@ export async function* swcExecutor(
|
||||
format: [
|
||||
determineModuleFormatFromSwcrc(options.swcCliOptions.swcrcPath),
|
||||
],
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
extraDependencies: swcHelperDependency ? [swcHelperDependency] : [],
|
||||
},
|
||||
context
|
||||
|
||||
@ -96,9 +96,6 @@ export async function* tscBatchExecutor(
|
||||
context.root
|
||||
),
|
||||
format: [determineModuleFormatFromTsConfig(tsConfig)],
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
},
|
||||
taskInfo.context,
|
||||
taskInfo.projectGraphNode,
|
||||
@ -144,9 +141,6 @@ export async function* tscBatchExecutor(
|
||||
context.root
|
||||
),
|
||||
format: [determineModuleFormatFromTsConfig(t.options.tsConfig)],
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
},
|
||||
t.context,
|
||||
t.projectGraphNode,
|
||||
|
||||
@ -117,9 +117,6 @@ export async function* tscExecutor(
|
||||
context.root
|
||||
),
|
||||
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
},
|
||||
context,
|
||||
target,
|
||||
@ -155,9 +152,6 @@ export async function* tscExecutor(
|
||||
options.additionalEntryPoints,
|
||||
context.root
|
||||
),
|
||||
// As long as d.ts files match their .js counterparts, we don't need to emit them.
|
||||
// TSC can match them correctly based on file names.
|
||||
skipTypings: true,
|
||||
format: [determineModuleFormatFromTsConfig(options.tsConfig)],
|
||||
},
|
||||
context,
|
||||
|
||||
@ -35,6 +35,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -59,6 +60,7 @@ describe('updatePackageJson', () => {
|
||||
},
|
||||
main: './index.cjs.js',
|
||||
type: 'commonjs',
|
||||
types: './index.cjs.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -87,6 +89,7 @@ describe('updatePackageJson', () => {
|
||||
},
|
||||
main: './index.cjs.js',
|
||||
module: './index.esm.js',
|
||||
types: './index.cjs.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -118,6 +121,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -140,6 +144,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -159,6 +164,7 @@ describe('updatePackageJson', () => {
|
||||
expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
|
||||
main: './index.cjs.js',
|
||||
type: 'commonjs',
|
||||
types: './index.cjs.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -178,6 +184,7 @@ describe('updatePackageJson', () => {
|
||||
expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
|
||||
main: './index.cjs.js',
|
||||
module: './index.esm.js',
|
||||
types: './index.cjs.d.ts',
|
||||
});
|
||||
|
||||
spy.mockRestore();
|
||||
@ -202,6 +209,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
},
|
||||
@ -231,6 +239,7 @@ describe('updatePackageJson', () => {
|
||||
expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
types: './index.esm.d.ts',
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
},
|
||||
@ -258,6 +267,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
},
|
||||
@ -286,6 +296,7 @@ describe('updatePackageJson', () => {
|
||||
main: './index.esm.js',
|
||||
module: './index.esm.js',
|
||||
type: 'module',
|
||||
types: './index.esm.d.ts',
|
||||
exports: {
|
||||
'./foo': './foo.esm.js',
|
||||
},
|
||||
|
||||
@ -102,6 +102,8 @@ export function updatePackageJson(
|
||||
}
|
||||
}
|
||||
|
||||
packageJson.types ??= packageJson.main.replace(/\.js$/, '.d.ts');
|
||||
|
||||
writeJsonFile(
|
||||
join(workspaceRoot, options.outputPath, 'package.json'),
|
||||
packageJson
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user