diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9b604a7d..e0a47703 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,13 +37,13 @@ jobs: strategy: matrix: os: [ubuntu-latest] - node_version: [18, 20] + node_version: [20, 22, 24] include: # Active LTS + other OS - os: macos-latest - node_version: 20 + node_version: 22 - os: windows-latest - node_version: 20 + node_version: 22 fail-fast: false name: "Build&Test: node-${{ matrix.node_version }}, ${{ matrix.os }}" diff --git a/eslint.config.js b/eslint.config.js index c0c7d262..688137a1 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -120,13 +120,13 @@ export default tseslint.config( 'n/no-unsupported-features/es-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', }, ], 'n/no-unsupported-features/node-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', }, ], '@typescript-eslint/explicit-module-boundary-types': 'off', @@ -150,7 +150,7 @@ export default tseslint.config( 'n/no-unsupported-features/node-builtins': [ 'error', { - version: '^18.0.0 || >=20.0.0', + version: '^20.19.0 || >=22.12.0', allowExperimental: true, }, ], diff --git a/package.json b/package.json index 14afee37..c9324ba8 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "type": "module", "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "homepage": "https://github.com/vitejs/vite-plugin-vue/", "repository": { diff --git a/packages/plugin-vue-jsx/build.config.ts b/packages/plugin-vue-jsx/build.config.ts index 360c2e7c..a74f5d85 100644 --- a/packages/plugin-vue-jsx/build.config.ts +++ b/packages/plugin-vue-jsx/build.config.ts @@ -4,7 +4,4 @@ export default defineBuildConfig({ entries: ['src/index'], clean: true, declaration: true, - rollup: { - emitCJS: true, - }, }) diff --git a/packages/plugin-vue-jsx/package.json b/packages/plugin-vue-jsx/package.json index cbb74198..b85b8877 100644 --- a/packages/plugin-vue-jsx/package.json +++ b/packages/plugin-vue-jsx/package.json @@ -1,29 +1,23 @@ { "name": "@vitejs/plugin-vue-jsx", "version": "4.2.0", - "type": "commonjs", + "type": "module", "license": "MIT", "author": "Evan You", "files": [ "dist" ], - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "exports": { - ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } + ".": "./dist/index.mjs", + "./package.json": "./package.json" }, "scripts": { "dev": "unbuild --stub", - "build": "unbuild && pnpm run patch-cjs", - "patch-cjs": "tsx ../../scripts/patchCJS.ts", + "build": "unbuild", "prepublishOnly": "npm run build" }, "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "repository": { "type": "git", diff --git a/packages/plugin-vue-jsx/src/index.ts b/packages/plugin-vue-jsx/src/index.ts index bdec6c58..2bfb06fb 100644 --- a/packages/plugin-vue-jsx/src/index.ts +++ b/packages/plugin-vue-jsx/src/index.ts @@ -12,7 +12,7 @@ import { } from '@rolldown/pluginutils' import type { Options } from './types' -export * from './types' +export type * from './types' const ssrRegisterHelperId = '/__vue-jsx-ssr-register-helper' const ssrRegisterHelperCode = @@ -328,17 +328,17 @@ function isDefineComponentCall( ) } -const hash = - // eslint-disable-next-line n/no-unsupported-features/node-builtins -- crypto.hash is supported in Node 21.7.0+, 20.12.0+ - crypto.hash ?? - (( - algorithm: string, - data: crypto.BinaryLike, - outputEncoding: crypto.BinaryToTextEncoding, - ) => crypto.createHash(algorithm).update(data).digest(outputEncoding)) - function getHash(text: string) { - return hash('sha256', text, 'hex').substring(0, 8) + return crypto.hash('sha256', text, 'hex').substring(0, 8) } export default vueJsxPlugin + +// Compat for require +function vueJsxPluginCjs(this: unknown, options: Options): Plugin { + return vueJsxPlugin.call(this, options) +} +Object.assign(vueJsxPluginCjs, { + default: vueJsxPluginCjs, +}) +export { vueJsxPluginCjs as 'module.exports' } diff --git a/packages/plugin-vue-jsx/tsconfig.json b/packages/plugin-vue-jsx/tsconfig.json index 3a3117f2..4f4926b9 100644 --- a/packages/plugin-vue-jsx/tsconfig.json +++ b/packages/plugin-vue-jsx/tsconfig.json @@ -3,9 +3,9 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "Node", + "target": "es2023", + "module": "preserve", + "moduleResolution": "bundler", "strict": true, "declaration": true, "sourceMap": true, diff --git a/packages/plugin-vue/build.config.ts b/packages/plugin-vue/build.config.ts index 33fef7f6..12d46d0e 100644 --- a/packages/plugin-vue/build.config.ts +++ b/packages/plugin-vue/build.config.ts @@ -6,7 +6,6 @@ export default defineBuildConfig({ clean: true, declaration: 'compatible', rollup: { - emitCJS: true, inlineDependencies: true, }, }) diff --git a/packages/plugin-vue/package.json b/packages/plugin-vue/package.json index 34bec69a..2cc2a9ba 100644 --- a/packages/plugin-vue/package.json +++ b/packages/plugin-vue/package.json @@ -1,29 +1,23 @@ { "name": "@vitejs/plugin-vue", "version": "6.0.0-beta.1", - "type": "commonjs", + "type": "module", "license": "MIT", "author": "Evan You", "files": [ "dist" ], - "main": "./dist/index.cjs", - "module": "./dist/index.mjs", - "types": "./dist/index.d.ts", "exports": { - ".": { - "import": "./dist/index.mjs", - "require": "./dist/index.cjs" - } + ".": "./dist/index.mjs", + "./package.json": "./package.json" }, "scripts": { "dev": "unbuild --stub", - "build": "unbuild && pnpm run patch-cjs", - "patch-cjs": "tsx ../../scripts/patchCJS.ts", + "build": "unbuild", "prepublishOnly": "npm run build" }, "engines": { - "node": "^18.0.0 || >=20.0.0" + "node": "^20.19.0 || >=22.12.0" }, "repository": { "type": "git", diff --git a/packages/plugin-vue/src/index.ts b/packages/plugin-vue/src/index.ts index 8621cfe7..c1af1840 100644 --- a/packages/plugin-vue/src/index.ts +++ b/packages/plugin-vue/src/index.ts @@ -517,3 +517,13 @@ export default function vuePlugin(rawOptions: Options = {}): Plugin { function ensureArray(value: T | T[]): T[] { return Array.isArray(value) ? value : [value] } + +// Compat for require +function vuePluginCjs(this: unknown, options: Options): Plugin { + return vuePlugin.call(this, options) +} +Object.assign(vuePluginCjs, { + default: vuePluginCjs, + parseVueRequest, +}) +export { vuePluginCjs as 'module.exports' } diff --git a/packages/plugin-vue/tsconfig.json b/packages/plugin-vue/tsconfig.json index cec54d61..c22bb7b8 100644 --- a/packages/plugin-vue/tsconfig.json +++ b/packages/plugin-vue/tsconfig.json @@ -3,9 +3,9 @@ "exclude": ["**/*.spec.ts"], "compilerOptions": { "outDir": "dist", - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "node", + "target": "es2023", + "module": "preserve", + "moduleResolution": "bundler", "strict": true, "declaration": true, "sourceMap": true, diff --git a/playground/tsconfig.json b/playground/tsconfig.json index 54fb5cd9..7f7356c8 100644 --- a/playground/tsconfig.json +++ b/playground/tsconfig.json @@ -2,7 +2,7 @@ "include": ["."], "exclude": ["**/dist/**"], "compilerOptions": { - "target": "ES2020", + "target": "ES2023", "module": "ESNext", "outDir": "dist", "baseUrl": ".", diff --git a/scripts/patchCJS.ts b/scripts/patchCJS.ts deleted file mode 100644 index 192264e6..00000000 --- a/scripts/patchCJS.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - -It converts - -```ts -exports.default = vuePlugin; -exports.parseVueRequest = parseVueRequest; -``` - -to - -```ts -module.exports = vuePlugin; -module.exports.default = vuePlugin; -module.exports.parseVueRequest = parseVueRequest; -``` -*/ - -import { readFileSync, writeFileSync } from 'node:fs' -import colors from 'picocolors' - -const indexPath = 'dist/index.cjs' -let code = readFileSync(indexPath, 'utf-8') - -const matchMixed = code.match(/\nexports.default = (\w+);/) -if (matchMixed) { - const name = matchMixed[1] - - const lines = code.trimEnd().split('\n') - - // search from the end to prepend `modules.` to `export[xxx]` - for (let i = lines.length - 1; i > 0; i--) { - if (lines[i].startsWith('exports')) lines[i] = 'module.' + lines[i] - else { - // at the beginning of exports, export the default function - lines[i] += `\nmodule.exports = ${name};` - break - } - } - - writeFileSync(indexPath, lines.join('\n')) - - console.log(colors.bold(`${indexPath} CJS patched`)) - process.exit(0) -} - -const matchDefault = code.match(/\nmodule.exports = (\w+);/) - -if (matchDefault) { - code += `module.exports.default = ${matchDefault[1]};\n` - writeFileSync(indexPath, code) - console.log(colors.bold(`${indexPath} CJS patched`)) - process.exit(0) -} - -console.error(colors.red(`${indexPath} CJS patch failed`)) -process.exit(1) diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index dd4d2c86..67b84be9 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -2,9 +2,9 @@ "$schema": "https://json.schemastore.org/tsconfig", "include": ["."], "compilerOptions": { - "module": "ES2020", - "target": "ES2020", - "moduleResolution": "Node", + "target": "es2023", + "module": "preserve", + "moduleResolution": "bundler", "strict": true, "esModuleInterop": true, "skipLibCheck": true,