Skip to content

Commit

Permalink
CI for linting swc minification problem
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Apr 4, 2024
1 parent 80d08a0 commit 8140ce7
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 27 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
6 changes: 6 additions & 0 deletions packages/temporal-polyfill/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@
"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:*",
"gzip-size-cli": "^5.1.0",
"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",
Expand All @@ -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"
]
}
}
45 changes: 26 additions & 19 deletions packages/temporal-polyfill/scripts/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()],
})
}
}

Expand Down
12 changes: 9 additions & 3 deletions packages/temporal-polyfill/scripts/test262.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} ...`)

Expand Down
175 changes: 174 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8140ce7

Please sign in to comment.