feat: add Modern ESModule target via Vite

This commit is contained in:
Amin Yahyaabadi 2024-09-03 23:19:49 -07:00
parent 4e90bbcbd8
commit 8db3315e6c
No known key found for this signature in database
GPG Key ID: F52AF77F636088F0
26 changed files with 1149 additions and 119 deletions

View File

@ -214,7 +214,7 @@ jobs:
node-version: 16
- name: Smoke Test Node 16
run: |
node ./dist/modern/setup-cpp.js --help
node ./dist/modern/setup-cpp.mjs --help
Docker:
name: Docker-${{ matrix.container.image }}

View File

@ -1,2 +0,0 @@
const { buildTerserOptions } = require("terser-config-atomic/dist/builder")
module.exports = buildTerserOptions(process.env.NODE_ENV, undefined, true)

2
.terserrc.mjs Normal file
View File

@ -0,0 +1,2 @@
import { buildTerserOptions } from "terser-config-atomic/dist/builder.js"
export default buildTerserOptions(process.env.NODE_ENV, undefined, true)

View File

@ -100,7 +100,7 @@ inputs:
runs:
using: "node20"
main: "dist/modern/setup-cpp.js"
main: "dist/modern/setup-cpp.mjs"
branding:
icon: "award"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/modern/assets/hdi-CLiriP2M.mjs vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

3
dist/modern/setup-cpp.mjs vendored Normal file

File diff suppressed because one or more lines are too long

1
dist/modern/setup-cpp.mjs.map vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -6,8 +6,8 @@
"license": "Apache-2.0",
"author": "Amin Yahyaabadi",
"main": "dist/legacy/setup-cpp.js",
"modern": "./dist/modern/setup-cpp.js",
"source": "./src/main.ts",
"modern": "./dist/modern/setup-cpp.mjs",
"source": "./src/setup-cpp.ts",
"bin": {
"setup-cpp": "dist/legacy/setup-cpp.js"
},
@ -26,12 +26,13 @@
"tsconfig.json"
],
"scripts": {
"build": "turbo build && run-p lint.root.tsc build.parcel copy.matchers && run-s build.babel",
"build": "turbo build && run-p lint.root.tsc build.parcel build.vite && run-p build.babel copy.json",
"build.parcel": "cross-env NODE_ENV=production parcel build",
"build.babel": "babel ./dist --out-dir dist --plugins @upleveled/babel-plugin-remove-node-prefix --plugins @babel/plugin-transform-private-methods --compact --no-babelrc --source-maps true",
"build.vite": "cross-env NODE_ENV=production vite build",
"build.babel": "babel ./dist/legacy --out-dir ./dist/legacy --plugins @upleveled/babel-plugin-remove-node-prefix --plugins @babel/plugin-transform-private-methods --compact --no-babelrc --source-maps true",
"bump": "ncu -u -x numerous,execa,prettier,@types/node,eslint,@types/eslint && pnpm update && pnpx typesync && pnpm run clean",
"clean": "shx rm -rf ./dist ./packages/*/dist ./exe ./.parcel-cache && shx mkdir -p ./dist/legacy ./dist/modern ./dist/modern ",
"copy.matchers": "shx cp ./src/*/*.json ./dist/legacy/ && shx cp ./dist/legacy/*.json ./dist/modern",
"copy.json": "shx cp ./src/*/*.json ./dist/legacy/ && shx cp ./dist/legacy/*.json ./dist/modern",
"dev.parcel": "cross-env NODE_ENV=development parcel watch",
"dev.packages": "turbo dev",
"dev": "run-p dev.packages dev.parcel",
@ -124,6 +125,7 @@
"setup-python": "github:aminya/setup-python#a783db655c6e40317e2c0c96f9d162d9c9f4a751",
"shx": "0.3.4",
"simple-update-notifier": "^2.0.0",
"terser": "^5.31.6",
"terser-config-atomic": "^1.0.0",
"time-delta": "github:aminya/time-delta#69d91a41cef28e569be9a2991129f5f7d1f0d00e",
"ts-node": "^10.9.2",
@ -133,6 +135,8 @@
"ubuntu-version": "^2.0.0",
"untildify-user": "workspace:*",
"util.types": "^0.0.2",
"vite": "^5.4.3",
"vite-plugin-node": "^3.1.0",
"web-streams-polyfill": "^4.0.0",
"which": "^4.0.0"
},
@ -219,15 +223,6 @@
"includeNodeModules": true,
"optimize": true,
"outputFormat": "commonjs"
},
"modern": {
"context": "node",
"engines": {
"node": ">=20.x"
},
"includeNodeModules": true,
"optimize": true,
"outputFormat": "commonjs"
}
},
"pnpm": {

File diff suppressed because it is too large Load Diff

View File

@ -287,8 +287,8 @@ async function getGccCmdVersion(binDir: string, givenVersion: string) {
// try to find the gcc exe in the bin dir
const files = (await readdir(binDir)).sort(
(exe1, exe2) => {
const version1 = exe1.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
const version2 = exe2.match(/^gcc-?(.*)(\.exe)?$/)?.[1] || ""
const version1 = exe1.match(/^gcc-?(.*)(\.exe)?$/)?.[1] ?? ""
const version2 = exe2.match(/^gcc-?(.*)(\.exe)?$/)?.[1] ?? ""
return compareVersion(version1, version2)
},
)

View File

@ -21,7 +21,9 @@
"allowImportingTsExtensions": true,
"noEmit": true,
// target Node.js 12 https://node.green/#ES2019
"lib": ["ES2019"],
"lib": [
"ES2019"
],
"target": "ESNext",
"allowJs": true,
"esModuleInterop": true,
@ -36,6 +38,7 @@
"./src",
"./dev/",
"./*.ts",
"jest.config.mjs"
"jest.config.mjs",
"vite.config.mts"
]
}

21
vite.config.mts Normal file
View File

@ -0,0 +1,21 @@
import module from "module"
import { type TerserOptions, defineConfig } from "vite"
import terserRc from "./.terserrc.mjs"
const viteConfig = defineConfig({
build: {
ssr: "./src/setup-cpp.ts",
outDir: "./dist/modern",
target: "node20",
minify: "terser",
terserOptions: terserRc as TerserOptions,
sourcemap: true,
},
ssr: {
target: "node",
noExternal: true,
external: module.builtinModules,
},
})
export default viteConfig