Skip to content

Commit

Permalink
fix(bundling): added back code to handle skipTypeField option of roll…
Browse files Browse the repository at this point in the history
…up executor options + tests (#20460)
  • Loading branch information
yann510 authored Dec 19, 2023
1 parent 2b4f7b8 commit b40773c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,88 @@ describe('updatePackageJson', () => {
spy.mockRestore();
});
});

describe('skipTypeField', () => {
it('should not include type field if skipTypeField is true', () => {
const spy = jest.spyOn(utils, 'writeJsonFile');

updatePackageJson(
{
...commonOptions,
format: ['esm'],
skipTypeField: true,
},
{
exports: {
'./foo': './foo.esm.js',
},
} as unknown as PackageJson
);

expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
main: './index.esm.js',
module: './index.esm.js',
exports: {
'./foo': './foo.esm.js',
},
});

spy.mockRestore();
});

it('should include type field if skipTypeField is undefined', () => {
const spy = jest.spyOn(utils, 'writeJsonFile');

updatePackageJson(
{
...commonOptions,
format: ['esm'],
},
{
exports: {
'./foo': './foo.esm.js',
},
} as unknown as PackageJson
);

expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
main: './index.esm.js',
module: './index.esm.js',
type: 'module',
exports: {
'./foo': './foo.esm.js',
},
});

spy.mockRestore();
});

it('should include type field if skipTypeField is false', () => {
const spy = jest.spyOn(utils, 'writeJsonFile');

updatePackageJson(
{
...commonOptions,
format: ['esm'],
skipTypeField: false,
},
{
exports: {
'./foo': './foo.esm.js',
},
} as unknown as PackageJson
);

expect(utils.writeJsonFile).toHaveBeenCalledWith(expect.anything(), {
main: './index.esm.js',
module: './index.esm.js',
type: 'module',
exports: {
'./foo': './foo.esm.js',
},
});

spy.mockRestore();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function updatePackageJson(
packageJson.module = esmExports['.'];

if (!hasCjsFormat) {
packageJson.type = 'module';
if (!options.skipTypeField) packageJson.type = 'module';
packageJson.main ??= esmExports['.'];
}

Expand Down

0 comments on commit b40773c

Please sign in to comment.