Skip to content

Commit

Permalink
fix(misc): generate the "types" field in package.json if no set in ro…
Browse files Browse the repository at this point in the history
…llup, swc and tsc executors
  • Loading branch information
leosvelperez committed Jul 26, 2024
1 parent 09b0b38 commit 4db4509
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 4db4509

Please sign in to comment.