From b14d465006c6fd77485cb946a2e52e314c11112f Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:28:46 +0100 Subject: [PATCH 1/2] Use SWC --- .../@glimmer-workspace/build/lib/config.js | 85 +++++++++-- .../@glimmer-workspace/build/package.json | 2 + pnpm-lock.yaml | 144 +++++++++++++++++- 3 files changed, 217 insertions(+), 14 deletions(-) diff --git a/packages/@glimmer-workspace/build/lib/config.js b/packages/@glimmer-workspace/build/lib/config.js index 78e008bf01..5c9fe69183 100644 --- a/packages/@glimmer-workspace/build/lib/config.js +++ b/packages/@glimmer-workspace/build/lib/config.js @@ -86,26 +86,87 @@ export function typescript(pkg, config) { }, }; - /** @type {[string, object][]} */ - const presets = [['@babel/preset-typescript', { allowDeclareFields: true }]]; - const ts = tsconfig(typeScriptConfig); /** * TODO: migrate off of rollupTS, it has too many bugs */ return rollupTS({ - transpiler: 'babel', + transpiler: 'swc', transpileOnly: true, - babelConfig: { - presets, - plugins: [require.resolve('@glimmer/local-debug-babel-plugin')], + swcConfig: { + jsc: { + parser: { + syntax: 'typescript', + tsx: false, + }, + target: 'es2022', + loose: false, + minify: { + compress: { + arguments: false, + arrows: true, + booleans: true, + booleans_as_integers: false, + collapse_vars: true, + comparisons: true, + computed_props: true, + conditionals: true, + dead_code: true, + directives: true, + drop_console: false, + drop_debugger: true, + evaluate: true, + expression: false, + hoist_funs: false, + hoist_props: true, + hoist_vars: false, + if_return: true, + join_vars: true, + keep_classnames: false, + keep_fargs: true, + keep_fnames: false, + keep_infinity: false, + loops: true, + negate_iife: true, + properties: true, + reduce_funcs: false, + reduce_vars: false, + side_effects: true, + switches: true, + typeofs: true, + unsafe: false, + unsafe_arrows: false, + unsafe_comps: false, + unsafe_Function: false, + unsafe_math: false, + unsafe_symbols: false, + unsafe_methods: false, + unsafe_proto: false, + unsafe_regexp: false, + unsafe_undefined: false, + unused: true, + const_to_let: true, + pristine_globals: true, + }, + mangle: false, + }, + transform: { + constModules: { + globals: { + debug: { + 'import.meta.env.VM_LOCAL_DEV': 'false', + }, + }, + }, + }, + }, + module: { + type: 'es6', + }, + minify: false, + isModule: true, }, - /** - * This shouldn't be required, but it is. - * If we use @rollup/plugin-babel, we can remove this. - */ - browserslist: [`last 1 chrome versions`], tsconfig: ts, }); } diff --git a/packages/@glimmer-workspace/build/package.json b/packages/@glimmer-workspace/build/package.json index 8705cec9ca..57e856419b 100644 --- a/packages/@glimmer-workspace/build/package.json +++ b/packages/@glimmer-workspace/build/package.json @@ -18,6 +18,8 @@ "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.5", "@rollup/plugin-terser": "^0.4.4", + "@swc/core": "^1.7.26", + "@swc/helpers": "^0.5.13", "eslint": "^8.52.0", "eslint-plugin-import": "^2.29.0", "eslint-plugin-json": "^3.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8ec1a0a344..f3bbbad90f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -357,6 +357,12 @@ importers: '@rollup/plugin-terser': specifier: ^0.4.4 version: 0.4.4(rollup@4.5.1) + '@swc/core': + specifier: ^1.7.26 + version: 1.7.26(@swc/helpers@0.5.13) + '@swc/helpers': + specifier: ^0.5.13 + version: 0.5.13 eslint: specifier: ^8.52.0 version: 8.54.0 @@ -395,7 +401,7 @@ importers: version: 4.0.2(postcss@8.4.31)(ts-node@10.9.1) rollup-plugin-ts: specifier: ^3.4.5 - version: 3.4.5(@babel/core@7.25.2)(@babel/plugin-transform-runtime@7.23.4)(@babel/preset-env@7.23.3)(@babel/preset-typescript@7.23.3)(@babel/runtime@7.23.4)(rollup@4.5.1)(typescript@5.0.4) + version: 3.4.5(@babel/core@7.25.2)(@babel/plugin-transform-runtime@7.23.4)(@babel/preset-env@7.23.3)(@babel/preset-typescript@7.23.3)(@babel/runtime@7.23.4)(@swc/core@1.7.26)(@swc/helpers@0.5.13)(rollup@4.5.1)(typescript@5.0.4) unplugin-fonts: specifier: ^1.0.3 version: 1.0.3(vite@5.0.12) @@ -4047,6 +4053,138 @@ packages: resolution: {integrity: sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==} dev: true + /@swc/core-darwin-arm64@1.7.26: + resolution: {integrity: sha512-FF3CRYTg6a7ZVW4yT9mesxoVVZTrcSWtmZhxKCYJX9brH4CS/7PRPjAKNk6kzWgWuRoglP7hkjQcd6EpMcZEAw==} + engines: {node: '>=10'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@swc/core-darwin-x64@1.7.26: + resolution: {integrity: sha512-az3cibZdsay2HNKmc4bjf62QVukuiMRh5sfM5kHR/JMTrLyS6vSw7Ihs3UTkZjUxkLTT8ro54LI6sV6sUQUbLQ==} + engines: {node: '>=10'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false + optional: true + + /@swc/core-linux-arm-gnueabihf@1.7.26: + resolution: {integrity: sha512-VYPFVJDO5zT5U3RpCdHE5v1gz4mmR8BfHecUZTmD2v1JeFY6fv9KArJUpjrHEEsjK/ucXkQFmJ0jaiWXmpOV9Q==} + engines: {node: '>=10'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@swc/core-linux-arm64-gnu@1.7.26: + resolution: {integrity: sha512-YKevOV7abpjcAzXrhsl+W48Z9mZvgoVs2eP5nY+uoMAdP2b3GxC0Df1Co0I90o2lkzO4jYBpTMcZlmUXLdXn+Q==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@swc/core-linux-arm64-musl@1.7.26: + resolution: {integrity: sha512-3w8iZICMkQQON0uIcvz7+Q1MPOW6hJ4O5ETjA0LSP/tuKqx30hIniCGOgPDnv3UTMruLUnQbtBwVCZTBKR3Rkg==} + engines: {node: '>=10'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@swc/core-linux-x64-gnu@1.7.26: + resolution: {integrity: sha512-c+pp9Zkk2lqb06bNGkR2Looxrs7FtGDMA4/aHjZcCqATgp348hOKH5WPvNLBl+yPrISuWjbKDVn3NgAvfvpH4w==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@swc/core-linux-x64-musl@1.7.26: + resolution: {integrity: sha512-PgtyfHBF6xG87dUSSdTJHwZ3/8vWZfNIXQV2GlwEpslrOkGqy+WaiiyE7Of7z9AvDILfBBBcJvJ/r8u980wAfQ==} + engines: {node: '>=10'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false + optional: true + + /@swc/core-win32-arm64-msvc@1.7.26: + resolution: {integrity: sha512-9TNXPIJqFynlAOrRD6tUQjMq7KApSklK3R/tXgIxc7Qx+lWu8hlDQ/kVPLpU7PWvMMwC/3hKBW+p5f+Tms1hmA==} + engines: {node: '>=10'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@swc/core-win32-ia32-msvc@1.7.26: + resolution: {integrity: sha512-9YngxNcG3177GYdsTum4V98Re+TlCeJEP4kEwEg9EagT5s3YejYdKwVAkAsJszzkXuyRDdnHUpYbTrPG6FiXrQ==} + engines: {node: '>=10'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@swc/core-win32-x64-msvc@1.7.26: + resolution: {integrity: sha512-VR+hzg9XqucgLjXxA13MtV5O3C0bK0ywtLIBw/+a+O+Oc6mxFWHtdUeXDbIi5AiPbn0fjgVJMqYnyjGyyX8u0w==} + engines: {node: '>=10'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false + optional: true + + /@swc/core@1.7.26(@swc/helpers@0.5.13): + resolution: {integrity: sha512-f5uYFf+TmMQyYIoxkn/evWhNGuUzC730dFwAKGwBVHHVoPyak1/GvJUm6i1SKl+2Hrj9oN0i3WSoWWZ4pgI8lw==} + engines: {node: '>=10'} + requiresBuild: true + peerDependencies: + '@swc/helpers': '*' + peerDependenciesMeta: + '@swc/helpers': + optional: true + dependencies: + '@swc/counter': 0.1.3 + '@swc/helpers': 0.5.13 + '@swc/types': 0.1.12 + optionalDependencies: + '@swc/core-darwin-arm64': 1.7.26 + '@swc/core-darwin-x64': 1.7.26 + '@swc/core-linux-arm-gnueabihf': 1.7.26 + '@swc/core-linux-arm64-gnu': 1.7.26 + '@swc/core-linux-arm64-musl': 1.7.26 + '@swc/core-linux-x64-gnu': 1.7.26 + '@swc/core-linux-x64-musl': 1.7.26 + '@swc/core-win32-arm64-msvc': 1.7.26 + '@swc/core-win32-ia32-msvc': 1.7.26 + '@swc/core-win32-x64-msvc': 1.7.26 + dev: false + + /@swc/counter@0.1.3: + resolution: {integrity: sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==} + dev: false + + /@swc/helpers@0.5.13: + resolution: {integrity: sha512-UoKGxQ3r5kYI9dALKJapMmuK+1zWM/H17Z1+iwnNmzcJRnfFuevZs375TA5rW31pu4BS4NoSy1fRsexDXfWn5w==} + dependencies: + tslib: 2.6.2 + dev: false + + /@swc/types@0.1.12: + resolution: {integrity: sha512-wBJA+SdtkbFhHjTMYH+dEH1y4VpfGdAc2Kw/LK09i9bXd/K6j6PkDcFCEzb6iVfZMkPRrl/q0e3toqTAJdkIVA==} + dependencies: + '@swc/counter': 0.1.3 + dev: false + /@szmarczak/http-timer@1.1.2: resolution: {integrity: sha512-XIB2XbzHTN6ieIjfIMV9hlVcfPU26s2vafYWQcZHWXHOxiaRZYEDKEwdl129Zyg50+foYV2jCgtrqSA6qNuNSA==} engines: {node: '>=6'} @@ -15518,7 +15656,7 @@ packages: - ts-node dev: false - /rollup-plugin-ts@3.4.5(@babel/core@7.25.2)(@babel/plugin-transform-runtime@7.23.4)(@babel/preset-env@7.23.3)(@babel/preset-typescript@7.23.3)(@babel/runtime@7.23.4)(rollup@4.5.1)(typescript@5.0.4): + /rollup-plugin-ts@3.4.5(@babel/core@7.25.2)(@babel/plugin-transform-runtime@7.23.4)(@babel/preset-env@7.23.3)(@babel/preset-typescript@7.23.3)(@babel/runtime@7.23.4)(@swc/core@1.7.26)(@swc/helpers@0.5.13)(rollup@4.5.1)(typescript@5.0.4): resolution: {integrity: sha512-9iCstRJpEZXSRQuXitlSZAzcGlrqTbJg1pE4CMbEi6xYldxVncdPyzA2I+j6vnh73wBymZckerS+Q/iEE/M3Ow==} engines: {node: '>=16.15.1', npm: '>=7.0.0', pnpm: '>=3.2.0', yarn: '>=1.13'} peerDependencies: @@ -15553,6 +15691,8 @@ packages: '@babel/preset-typescript': 7.23.3(@babel/core@7.25.2) '@babel/runtime': 7.23.4 '@rollup/pluginutils': 5.0.5(rollup@4.5.1) + '@swc/core': 1.7.26(@swc/helpers@0.5.13) + '@swc/helpers': 0.5.13 '@wessberg/stringutil': 1.0.19 ansi-colors: 4.1.3 browserslist: 4.22.1 From 7a90c98c630c8658047e4b5486ef9fc017663b35 Mon Sep 17 00:00:00 2001 From: NullVoxPopuli <199018+NullVoxPopuli@users.noreply.github.com> Date: Wed, 11 Sep 2024 17:29:57 +0100 Subject: [PATCH 2/2] Don't use terser --- .../@glimmer-workspace/build/lib/config.js | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/packages/@glimmer-workspace/build/lib/config.js b/packages/@glimmer-workspace/build/lib/config.js index 5c9fe69183..da2a5abe9e 100644 --- a/packages/@glimmer-workspace/build/lib/config.js +++ b/packages/@glimmer-workspace/build/lib/config.js @@ -1,20 +1,16 @@ /* eslint-disable no-console */ // @ts-check import { existsSync, readFileSync } from 'node:fs'; -import { createRequire } from 'node:module'; import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import replace from '@rollup/plugin-replace'; -import terser from '@rollup/plugin-terser'; import * as insert from 'rollup-plugin-insert'; import rollupTS from 'rollup-plugin-ts'; import ts from 'typescript'; import inline from './inline.js'; -const require = createRequire(import.meta.url); - // eslint-disable-next-line import/no-named-as-default-member const { ModuleKind, ModuleResolutionKind, ScriptTarget, ImportsNotUsedAsValues } = ts; @@ -380,31 +376,6 @@ export class Package { commonjs(), nodeResolve(), ...this.replacements(env), - ...(env === 'prod' - ? [ - terser({ - module: true, - // to debug the output, uncomment this so you can read the - // identifiers, unchanged - // mangle: false, - compress: { - passes: 3, - }, - }), - ] - : [ - terser({ - module: true, - mangle: false, - compress: { - passes: 3, - }, - format: { - comments: 'all', - beautify: true, - }, - }), - ]), postcss(), typescript(this.#package, { target: ScriptTarget.ES2022,