Skip to content

Commit

Permalink
fix(misc): generate the "types" field in package.json if no set (nrwl…
Browse files Browse the repository at this point in the history
…#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 nrwl#20003
  • Loading branch information
leosvelperez authored Jul 26, 2024
1 parent fa976e0 commit 5e4f05c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
6 changes: 0 additions & 6 deletions packages/js/src/executors/swc/swc.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions packages/js/src/executors/tsc/tsc.batch-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 0 additions & 6 deletions packages/js/src/executors/tsc/tsc.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('updatePackageJson', () => {
main: './index.esm.js',
module: './index.esm.js',
type: 'module',
types: './index.esm.d.ts',
});

spy.mockRestore();
Expand All @@ -59,6 +60,7 @@ describe('updatePackageJson', () => {
},
main: './index.cjs.js',
type: 'commonjs',
types: './index.cjs.d.ts',
});

spy.mockRestore();
Expand Down Expand Up @@ -87,6 +89,7 @@ describe('updatePackageJson', () => {
},
main: './index.cjs.js',
module: './index.esm.js',
types: './index.cjs.d.ts',
});

spy.mockRestore();
Expand Down Expand Up @@ -118,6 +121,7 @@ describe('updatePackageJson', () => {
main: './index.esm.js',
module: './index.esm.js',
type: 'module',
types: './index.esm.d.ts',
});

spy.mockRestore();
Expand All @@ -140,6 +144,7 @@ describe('updatePackageJson', () => {
main: './index.esm.js',
module: './index.esm.js',
type: 'module',
types: './index.esm.d.ts',
});

spy.mockRestore();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export function updatePackageJson(
}
}

packageJson.types ??= packageJson.main.replace(/\.js$/, '.d.ts');

writeJsonFile(
join(workspaceRoot, options.outputPath, 'package.json'),
packageJson
Expand Down

0 comments on commit 5e4f05c

Please sign in to comment.