Skip to content

Commit

Permalink
fix(js): update babel preset to specify minor version of core-js for …
Browse files Browse the repository at this point in the history
…better optimization (#22433)
  • Loading branch information
jaysoo authored Mar 22, 2024
1 parent 2068f20 commit 61cb63d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion e2e/jest/src/jest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('Jest', () => {
`generate @nx/js:lib ${name} --unitTestRunner=jest --no-interactive`
);

const results = await runCLIAsync(`test ${name}`, {
const results = await runCLIAsync(`test ${name} --skip-nx-cache`, {
silenceError: true,
env: {
...process.env, // need to set this for some reason, or else get "env: node: No such file or directory"
NODE_ENV: 'foobar',
Expand Down
6 changes: 5 additions & 1 deletion packages/js/babel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ module.exports = function (api: any, options: NxWebBabelPresetOptions = {}) {
: {
// Allow importing core-js in entrypoint and use browserslist to select polyfills.
useBuiltIns: options.useBuiltIns ?? 'entry',
corejs: options.useBuiltIns !== false ? 3 : null,
corejs:
options.useBuiltIns !== false
? // Setting the minor version as well for better optimization (See: https://github.com/zloirock/core-js#babelpreset-env)
'3.36'
: null,
// Do not transform modules to CJS
modules: false,
targets: isModern ? { esmodules: 'intersect' } : undefined,
Expand Down
36 changes: 23 additions & 13 deletions packages/rollup/src/utils/ensure-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
type Tree,
} from '@nx/devkit';
import { swcCoreVersion, swcHelpersVersion } from '@nx/js/src/utils/versions';
import { swcLoaderVersion, tsLibVersion } from './versions';
import { coreJsVersion, swcLoaderVersion, tsLibVersion } from './versions';

export type EnsureDependenciesOptions = {
compiler?: 'babel' | 'swc' | 'tsc';
Expand All @@ -14,17 +14,27 @@ export function ensureDependencies(
tree: Tree,
options: EnsureDependenciesOptions
): GeneratorCallback {
if (options.compiler === 'swc') {
return addDependenciesToPackageJson(
tree,
{},
{
'@swc/helpers': swcHelpersVersion,
'@swc/core': swcCoreVersion,
'swc-loader': swcLoaderVersion,
}
);
switch (options.compiler) {
case 'swc':
return addDependenciesToPackageJson(
tree,
{},
{
'@swc/helpers': swcHelpersVersion,
'@swc/core': swcCoreVersion,
'swc-loader': swcLoaderVersion,
}
);
case 'babel':
return addDependenciesToPackageJson(
tree,
{},
{
'core-js': coreJsVersion, // needed for preset-env to work
tslib: tsLibVersion,
}
);
default:
return addDependenciesToPackageJson(tree, {}, { tslib: tsLibVersion });
}

return addDependenciesToPackageJson(tree, {}, { tslib: tsLibVersion });
}
2 changes: 2 additions & 0 deletions packages/rollup/src/utils/versions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const nxVersion = require('../../package.json').version;
export const swcLoaderVersion = '0.1.15';
export const tsLibVersion = '^2.3.0';

export const coreJsVersion = '^3.36.1';
2 changes: 1 addition & 1 deletion packages/storybook/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const storybookVersion = '^7.5.3';
export const reactVersion = '^18.2.0';
export const viteVersion = '~5.0.0';

export const coreJsVersion = '^3.6.5';
export const coreJsVersion = '^3.36.1';

0 comments on commit 61cb63d

Please sign in to comment.