diff --git a/e2e/js/src/js-executor-node.test.ts b/e2e/js/src/js-executor-node.test.ts index ad4cde362cf597..a301ff748ab5b2 100644 --- a/e2e/js/src/js-executor-node.test.ts +++ b/e2e/js/src/js-executor-node.test.ts @@ -50,8 +50,7 @@ describe('js:node executor', () => { expect(output).toContain('This is an error'); }, 240_000); - // TODO: Re-enable this when it is passing - xit('should execute library compiled with rollup', async () => { + it('should execute library compiled with rollup', async () => { const rollupLib = uniq('rolluplib'); runCLI( diff --git a/e2e/js/src/js-packaging.test.ts b/e2e/js/src/js-packaging.test.ts index f8f2d64177f25b..73768826c2220a 100644 --- a/e2e/js/src/js-packaging.test.ts +++ b/e2e/js/src/js-packaging.test.ts @@ -22,8 +22,7 @@ describe('packaging libs', () => { afterEach(() => cleanupProject()); - // TODO Re-enable this when it is passing - xit('should bundle libs using esbuild, vite, rollup and be used in CJS/ESM projects', () => { + it('should bundle libs using esbuild, vite, rollup and be used in CJS/ESM projects', () => { const esbuildLib = uniq('esbuildlib'); const viteLib = uniq('vitelib'); const rollupLib = uniq('rolluplib'); @@ -130,8 +129,7 @@ describe('packaging libs', () => { expect(output).toContain('rollup default'); }, 500_000); - // TODO Re-enable this when it is passing - xit('should build with tsc, swc and be used in CJS/ESM projects', async () => { + it('should build with tsc, swc and be used in CJS/ESM projects', async () => { const tscLib = uniq('tsclib'); const swcLib = uniq('swclib'); const tscEsmLib = uniq('tscesmlib'); diff --git a/e2e/rollup/src/rollup.test.ts b/e2e/rollup/src/rollup.test.ts index 9da8cb1deffeb9..237fcbfaf26378 100644 --- a/e2e/rollup/src/rollup.test.ts +++ b/e2e/rollup/src/rollup.test.ts @@ -114,8 +114,7 @@ describe('Rollup Plugin', () => { }); }); - // TODO: Re-enable this when it is passing - xit('should be able to build libs generated with @nx/js:lib --bundler rollup', () => { + it('should be able to build libs generated with @nx/js:lib --bundler rollup', () => { const jsLib = uniq('jslib'); runCLI(`generate @nx/js:lib ${jsLib} --bundler rollup`); expect(() => runCLI(`build ${jsLib}`)).not.toThrow(); diff --git a/packages/js/migrations.json b/packages/js/migrations.json index 9f0ced6950a751..0676d4e384ea45 100644 --- a/packages/js/migrations.json +++ b/packages/js/migrations.json @@ -47,6 +47,12 @@ "version": "16.6.0-beta.0", "description": "Explicitly set 'updateBuildableProjectDepsInPackageJson' to 'true' in targets that rely on that value as the default.", "factory": "./src/migrations/update-16-6-0/explicitly-set-projects-to-update-buildable-deps" + }, + "16-8-2-update-swcrc": { + "cli": "nx", + "version": "16.8.2-beta.0", + "description": "Remove invalid options (strict, noInterop) for ES6 type modules.", + "factory": "./src/migrations/update-16-8-2/update-swcrc" } }, "packageJsonUpdates": { diff --git a/packages/js/src/migrations/update-16-8-2/update-swcrc.spec.ts b/packages/js/src/migrations/update-16-8-2/update-swcrc.spec.ts new file mode 100644 index 00000000000000..7c8e06e7e79b5e --- /dev/null +++ b/packages/js/src/migrations/update-16-8-2/update-swcrc.spec.ts @@ -0,0 +1,82 @@ +import { addProjectConfiguration, readJson, Tree, writeJson } from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; +import update from './update-swcrc'; + +describe('Migration: update .swcrc', () => { + let tree: Tree; + + beforeEach(async () => { + tree = createTreeWithEmptyWorkspace(); + }); + + it('should remove invalid options for ES6 modules', async () => { + addProjectConfiguration(tree, 'pkg', { + root: 'pkg', + }); + writeJson(tree, 'pkg/.swcrc', { + module: { + type: 'es6', + strict: true, + noInterop: true, + }, + }); + + await update(tree); + + expect(readJson(tree, 'pkg/.swcrc')).toEqual({ + module: { + type: 'es6', + }, + }); + }); + + it('should keep options for CommonJS modules', async () => { + addProjectConfiguration(tree, 'pkg', { + root: 'pkg', + }); + writeJson(tree, 'pkg/.swcrc', { + module: { + type: 'commonjs', + strict: true, + noInterop: true, + }, + }); + + await update(tree); + + expect(readJson(tree, 'pkg/.swcrc')).toEqual({ + module: { + type: 'commonjs', + strict: true, + noInterop: true, + }, + }); + }); + + it('should ignore projects without module options in .swcrc', async () => { + addProjectConfiguration(tree, 'pkg', { + root: 'pkg', + }); + writeJson(tree, 'pkg/.swcrc', { + jsc: { + target: 'es2017', + }, + }); + + await expect(update(tree)).resolves.not.toThrow(); + + expect(readJson(tree, 'pkg/.swcrc')).toEqual({ + jsc: { + target: 'es2017', + }, + }); + }); + + it('should ignore projects without .swcrc', async () => { + addProjectConfiguration(tree, 'pkg', { + root: 'pkg', + }); + + await expect(update(tree)).resolves.not.toThrow(); + }); +}); diff --git a/packages/js/src/migrations/update-16-8-2/update-swcrc.ts b/packages/js/src/migrations/update-16-8-2/update-swcrc.ts new file mode 100644 index 00000000000000..359a38a28493e0 --- /dev/null +++ b/packages/js/src/migrations/update-16-8-2/update-swcrc.ts @@ -0,0 +1,30 @@ +import { + formatFiles, + getProjects, + readJson, + Tree, + writeJson, +} from '@nx/devkit'; +import { join } from 'path'; + +export default async function update(tree: Tree) { + const projects = getProjects(tree); + + for (const config of projects.values()) { + const swcrcPath = join(config.root, '.swcrc'); + if (!tree.exists(swcrcPath)) continue; + const json = readJson(tree, swcrcPath); + // No longer need strict or noInterop for es6 modules + // See: https://github.com/swc-project/swc/commit/7e8d72d + if ( + json.module?.type === 'es6' && + (json.module?.strict || json.module?.noInterop) + ) { + delete json.module.noInterop; + delete json.module.strict; + writeJson(tree, swcrcPath, json); + } + } + + await formatFiles(tree); +}