Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(misc): generate the "types" field in package.json if no set #27147

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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