From 8140ce7d4990cf72b1d82aafdd37220f9a85f4ee Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 4 Apr 2024 16:20:05 -0400 Subject: [PATCH] CI for linting swc minification problem --- .github/workflows/ci.yml | 18 +- packages/temporal-polyfill/package.json | 6 + packages/temporal-polyfill/scripts/bundle.js | 45 +++-- packages/temporal-polyfill/scripts/test262.js | 12 +- pnpm-lock.yaml | 175 +++++++++++++++++- 5 files changed, 229 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06674c5a..9a703e03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,15 @@ jobs: strategy: fail-fast: false matrix: - node: [14.21.3, 16.20.0, 18.19.0, 20.10.0] + TEST262_NODE_VERSION: [14.21.3, 16.20.0, 18.19.0, 20.10.0] + include: + - TEST262_NODE_VERSION: 14.21.3 + TEST262_ESM: 1 + LINTING: 1 + - TEST262_NODE_VERSION: 16.20.0 + TEST262_ESM: terser + - TEST262_NODE_VERSION: 18.19.0 + TEST262_ESM: swc steps: - name: Checkout @@ -41,12 +49,14 @@ jobs: run: pnpm install - name: Lint - # Only for the first Node version - if: matrix.node == '14.21.3' + if: matrix.LINTING run: pnpm run lint - name: Build run: pnpm run build - name: Test - run: TEST262_NODE_VERSION=${{ matrix.node }} pnpm run test + run: > + TEST262_NODE_VERSION=${{ matrix.TEST262_NODE_VERSION }} + TEST262_ESM=${{ matrix.TEST262_ESM }} + pnpm run test diff --git a/packages/temporal-polyfill/package.json b/packages/temporal-polyfill/package.json index 64c03d71..2ef49458 100644 --- a/packages/temporal-polyfill/package.json +++ b/packages/temporal-polyfill/package.json @@ -93,6 +93,7 @@ "devDependencies": { "@biomejs/biome": "1.5.1", "@js-temporal/temporal-test262-runner": "workspace:*", + "@swc/core": "1.4.11", "@types/node": "^18.11.9", "concurrently": "^8.2.0", "export-size": "workspace:*", @@ -100,6 +101,7 @@ "rollup": "^4.9.6", "rollup-plugin-dts": "^6.1.0", "rollup-plugin-sourcemaps": "^0.6.3", + "rollup-plugin-swc3": "^0.11.0", "terser": "^5.27.0", "typescript": "~5.3.3", "vitest": "^1.2.2", @@ -109,6 +111,10 @@ "@biomejs/biome": [ "BUG: Pinned to 1.5.1 due to this regression in 1.5.3:", "https://github.com/biomejs/biome/issues/1654" + ], + "@swc/core": [ + "Locked a version to test workaround for this bug:", + "https://github.com/swc-project/swc/issues/8806" ] } } diff --git a/packages/temporal-polyfill/scripts/bundle.js b/packages/temporal-polyfill/scripts/bundle.js index 1f75c13d..80f2f8af 100755 --- a/packages/temporal-polyfill/scripts/bundle.js +++ b/packages/temporal-polyfill/scripts/bundle.js @@ -10,6 +10,7 @@ import { readFile } from 'fs/promises' import { rollup as rollupBuild, watch as rollupWatch } from 'rollup' import { dts } from 'rollup-plugin-dts' import sourcemaps from 'rollup-plugin-sourcemaps' +import { minify as swcMinify } from 'rollup-plugin-swc3' import { extensions } from './lib/config.js' import { pureTopLevel } from './lib/pure-top-level.js' import { terserSimple } from './lib/terser-simple.js' @@ -18,33 +19,39 @@ const argv = process.argv.slice(2) writeBundles( joinPaths(process.argv[1], '../..'), argv.includes('--dev'), - argv.includes('--esm') || process.env.CI, + argv.includes('--esm') || process.env.TEST262_ESM === '1', + argv.includes('--esm-terser') || process.env.TEST262_ESM === 'terser', + argv.includes('--esm-swc') || process.env.TEST262_ESM === 'swc', ) -async function writeBundles(pkgDir, isDev, bundleDistEsm) { +async function writeBundles( + pkgDir, + isDev, + bundleEsm, + bundleEsmTerser, + bundleEsmSwc, +) { const configs = await buildConfigs(pkgDir, isDev) await (isDev ? watchWithConfigs : buildWithConfigs)(configs) - if (bundleDistEsm) { + if (bundleEsm || bundleEsmTerser || bundleEsmSwc) { const esmBundle = await rollupBuild({ input: joinPaths(pkgDir, 'dist', 'global' + extensions.esm), }) - await Promise.all([ - esmBundle.write({ - format: 'iife', - file: joinPaths(pkgDir, 'dist', '.bundled', 'global' + extensions.iife), - }), - esmBundle.write({ - format: 'iife', - file: joinPaths( - pkgDir, - 'dist', - '.bundled', - 'global' + extensions.iifeMin, - ), - plugins: [terserSimple()], - }), - ]) + + const filename = + 'global' + + (bundleEsmTerser + ? '.terser' + extensions.iifeMin + : bundleEsmSwc + ? '.swc' + extensions.iifeMin + : extensions.iife) + + await esmBundle.write({ + format: 'iife', + file: joinPaths(pkgDir, 'dist', '.bundled', filename), + plugins: [bundleEsmTerser && terserSimple(), bundleEsmSwc && swcMinify()], + }) } } diff --git a/packages/temporal-polyfill/scripts/test262.js b/packages/temporal-polyfill/scripts/test262.js index 459127c5..32e71e6b 100755 --- a/packages/temporal-polyfill/scripts/test262.js +++ b/packages/temporal-polyfill/scripts/test262.js @@ -101,9 +101,15 @@ yargs(hideBin(process.argv)) min = min || Boolean(Math.floor(currentNodeMajorVersion / 2) % 2) } - const polyfillPath = // from package root - (esm ? './dist/.bundled/global' : './dist/global') + - (min ? extensions.iifeMin : extensions.iife) + const esmOpt = process.env.TEST262_ESM + + // from package root + const polyfillPath = esmOpt + ? './dist/.bundled/global' + + (esmOpt === 'terser' || esmOpt === 'swc' + ? '.' + esmOpt + extensions.iifeMin + : extensions.iife) + : './dist/global' + extensions.iife console.log(`Testing ${polyfillPath} with Node ${currentNodeVersion} ...`) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2ac4878f..2e463224 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,6 +105,9 @@ importers: '@js-temporal/temporal-test262-runner': specifier: workspace:* version: link:../temporal-test262-runner + '@swc/core': + specifier: 1.4.11 + version: 1.4.11 '@types/node': specifier: ^18.11.9 version: 18.11.9 @@ -126,6 +129,9 @@ importers: rollup-plugin-sourcemaps: specifier: ^0.6.3 version: 0.6.3(patch_hash=pv36xcczr5gjtywakxwkjo5sue)(@types/node@18.11.9)(rollup@4.9.6) + rollup-plugin-swc3: + specifier: ^0.11.0 + version: 0.11.0(@swc/core@1.4.11)(rollup@4.9.6) terser: specifier: ^5.27.0 version: 5.27.0 @@ -858,6 +864,10 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true + /@fastify/deepmerge@1.3.0: + resolution: {integrity: sha512-J8TOSBq3SoZbDhM9+R/u77hP93gz/rajSA+K2kGyijPpORPWUXHUpTaleoj+92As0S9uPRP7Oi8IqMf0u+ro6A==} + dev: true + /@humanwhocodes/config-array@0.11.14: resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} engines: {node: '>=10.10.0'} @@ -1011,6 +1021,21 @@ packages: rollup: 3.29.4 dev: false + /@rollup/pluginutils@5.1.0(rollup@4.9.6): + resolution: {integrity: sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==} + engines: {node: '>=14.0.0'} + peerDependencies: + rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 + peerDependenciesMeta: + rollup: + optional: true + dependencies: + '@types/estree': 1.0.5 + estree-walker: 2.0.2 + picomatch: 2.3.1 + rollup: 4.9.6 + dev: true + /@rollup/rollup-android-arm-eabi@4.9.6: resolution: {integrity: sha512-MVNXSSYN6QXOulbHpLMKYi60ppyO13W9my1qogeiAqtjb2yR4LSmfU2+POvDkLzhjYLXz9Rf9+9a3zFHW1Lecg==} cpu: [arm] @@ -1173,6 +1198,131 @@ packages: - typescript dev: true + /@swc/core-darwin-arm64@1.4.11: + resolution: {integrity: sha512-C1j1Qp/IHSelVWdEnT7f0iONWxQz6FAqzjCF2iaL+0vFg4V5f2nlgrueY8vj5pNNzSGhrAlxsMxEIp4dj1MXkg==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@swc/core-darwin-x64@1.4.11: + resolution: {integrity: sha512-0TTy3Ni8ncgaMCchSQ7FK8ZXQLlamy0FXmGWbR58c+pVZWYZltYPTmheJUvVcR0H2+gPAymRKyfC0iLszDALjg==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@swc/core-linux-arm-gnueabihf@1.4.11: + resolution: {integrity: sha512-XJLB71uw0rog4DjYAPxFGAuGCBQpgJDlPZZK6MTmZOvI/1t0+DelJ24IjHIxk500YYM26Yv47xPabqFPD7I2zQ==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@swc/core-linux-arm64-gnu@1.4.11: + resolution: {integrity: sha512-vYQwzJvm/iu052d5Iw27UFALIN5xSrGkPZXxLNMHPySVko2QMNNBv35HLatkEQHbQ3X+VKSW9J9SkdtAvAVRAQ==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@swc/core-linux-arm64-musl@1.4.11: + resolution: {integrity: sha512-eV+KduiRYUFjPsvbZuJ9aknQH9Tj0U2/G9oIZSzLx/18WsYi+upzHbgxmIIHJ2VJgfd7nN40RI/hMtxNsUzR/g==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@swc/core-linux-x64-gnu@1.4.11: + resolution: {integrity: sha512-WA1iGXZ2HpqM1OR9VCQZJ8sQ1KP2or9O4bO8vWZo6HZJIeoQSo7aa9waaCLRpkZvkng1ct/TF/l6ymqSNFXIzQ==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@swc/core-linux-x64-musl@1.4.11: + resolution: {integrity: sha512-UkVJToKf0owwQYRnGvjHAeYVDfeimCEcx0VQSbJoN7Iy0ckRZi7YPlmWJU31xtKvikE2bQWCOVe0qbSDqqcWXA==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@swc/core-win32-arm64-msvc@1.4.11: + resolution: {integrity: sha512-35khwkyly7lF5NDSyvIrukBMzxPorgc5iTSDfVO/LvnmN5+fm4lTlrDr4tUfTdOhv3Emy7CsKlsNAeFRJ+Pm+w==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@swc/core-win32-ia32-msvc@1.4.11: + resolution: {integrity: sha512-Wx8/6f0ufgQF2pbVPsJ2dAmFLwIOW+xBE5fxnb7VnEbGkTgP1qMDWiiAtD9rtvDSuODG3i1AEmAak/2HAc6i6A==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@swc/core-win32-x64-msvc@1.4.11: + resolution: {integrity: sha512-0xRFW6K9UZQH2NVC/0pVB0GJXS45lY24f+6XaPBF1YnMHd8A8GoHl7ugyM5yNUTe2AKhSgk5fJV00EJt/XBtdQ==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@swc/core@1.4.11: + resolution: {integrity: sha512-WKEakMZxkVwRdgMN4AMJ9K5nysY8g8npgQPczmjBeNK5In7QEAZAJwnyccrWwJZU0XjVeHn2uj+XbOKdDW17rg==} + engines: {node: '>=10'} + requiresBuild: true + peerDependencies: + '@swc/helpers': ^0.5.0 + peerDependenciesMeta: + '@swc/helpers': + optional: true + dependencies: + '@swc/counter': 0.1.3 + '@swc/types': 0.1.6 + optionalDependencies: + '@swc/core-darwin-arm64': 1.4.11 + '@swc/core-darwin-x64': 1.4.11 + '@swc/core-linux-arm-gnueabihf': 1.4.11 + '@swc/core-linux-arm64-gnu': 1.4.11 + '@swc/core-linux-arm64-musl': 1.4.11 + '@swc/core-linux-x64-gnu': 1.4.11 + '@swc/core-linux-x64-musl': 1.4.11 + '@swc/core-win32-arm64-msvc': 1.4.11 + '@swc/core-win32-ia32-msvc': 1.4.11 + '@swc/core-win32-x64-msvc': 1.4.11 + dev: true + + /@swc/counter@0.1.3: + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + dev: true + + /@swc/types@0.1.6: + resolution: {integrity: sha512-/JLo/l2JsT/LRd80C3HfbmVpxOAJ11FO2RCEslFrgzLltoP9j8XIbsyDcfCt2WWyX+CM96rBoNM+IToAkFOugg==} + dependencies: + '@swc/counter': 0.1.3 + dev: true + /@types/cli-progress@3.11.4: resolution: {integrity: sha512-yufTxeeNCZuEIxx2uebK8lpSAsJM4lvzakm/VxzYhDtqhXCzwH9jpn7nPCxzrROuEbLATqhFq4MIPoG0tlrsvw==} dependencies: @@ -2521,7 +2671,6 @@ packages: /estree-walker@2.0.2: resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} - dev: false /estree-walker@3.0.3: resolution: {integrity: sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==} @@ -4156,6 +4305,30 @@ packages: dev: true patched: true + /rollup-plugin-swc3@0.11.0(@swc/core@1.4.11)(rollup@4.9.6): + resolution: {integrity: sha512-luB9Ngb1YieWPpJttKvkmjN3lG5l28SmASLbf2CoScUB2+EImU0bE8wX4EYKEqv5clVulhWRQHQvE+H33X/03g==} + engines: {node: '>=12'} + peerDependencies: + '@swc/core': '>=1.2.165' + rollup: ^2.0.0 || ^3.0.0 || ^4.0.0 + dependencies: + '@fastify/deepmerge': 1.3.0 + '@rollup/pluginutils': 5.1.0(rollup@4.9.6) + '@swc/core': 1.4.11 + get-tsconfig: 4.7.2 + rollup: 4.9.6 + rollup-preserve-directives: 1.1.1(rollup@4.9.6) + dev: true + + /rollup-preserve-directives@1.1.1(rollup@4.9.6): + resolution: {integrity: sha512-+eQafbuEfDPfxQ9hQPlwaROfin4yiVRxap8hnrvvvcSGoukv1tTiYpAW9mvm3uR8J+fe4xd8FdVd5rz9q7jZ+Q==} + peerDependencies: + rollup: ^2.0.0 || ^3.0.0 || ^4.0.0 + dependencies: + magic-string: 0.30.5 + rollup: 4.9.6 + dev: true + /rollup@3.29.4: resolution: {integrity: sha512-oWzmBZwvYrU0iJHtDmhsm662rC15FRXmcjCk1xD771dFDx5jJ02ufAQQTn0etB2emNk4J9EZg/yWKpsn9BWGRw==} engines: {node: '>=14.18.0', npm: '>=8.0.0'}