From f9d925c16ca423838391b9f0da523acf2e391d7d Mon Sep 17 00:00:00 2001 From: Jerry_Wu <409187100@qq.com> Date: Mon, 10 Nov 2025 16:14:24 +0800 Subject: [PATCH 1/4] refactor: replace cross-spawn with execa --- package.json | 2 - packages/qwik/src/cli/utils/utils.ts | 54 +++++++------------- scripts/binding-platform.ts | 76 +++++++++------------------- scripts/binding-wasm.ts | 31 +++++------- scripts/submodule-cli.ts | 2 +- 5 files changed, 57 insertions(+), 108 deletions(-) diff --git a/package.json b/package.json index dfb21f5a216..77ef2a2838c 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,6 @@ "@qwik.dev/router": "workspace:*", "@types/brotli": "1.3.4", "@types/bun": "1.2.21", - "@types/cross-spawn": "6.0.6", "@types/express": "5.0.3", "@types/node": "24.3.0", "@types/path-browserify": "1.0.3", @@ -122,7 +121,6 @@ "all-contributors-cli": "6.26.1", "brotli": "1.3.3", "create-qwik": "workspace:*", - "cross-spawn": "7.0.6", "csstype": "3.1.3", "dotenv": "16.5.0", "esbuild": "0.25.10", diff --git a/packages/qwik/src/cli/utils/utils.ts b/packages/qwik/src/cli/utils/utils.ts index 7e692dcd3f0..8db826d451a 100644 --- a/packages/qwik/src/cli/utils/utils.ts +++ b/packages/qwik/src/cli/utils/utils.ts @@ -1,52 +1,36 @@ import { blue, gray, green, magenta, red, reset, white } from 'kleur/colors'; import { log, outro } from '@clack/prompts'; - -import type { ChildProcess } from 'node:child_process'; import type { IntegrationPackageJson } from '../types'; import detectPackageManager from 'which-pm-runs'; import fs from 'node:fs'; import { join } from 'node:path'; -import spawn from 'cross-spawn'; - +import { execa } from 'execa'; export function runCommand(cmd: string, args: string[], cwd: string) { - let child: ChildProcess; - - const install = new Promise((resolve) => { - try { - child = spawn(cmd, args, { - cwd, - stdio: 'ignore', - }); - - child.on('error', (e) => { - if (e) { - if (e.message) { - log.error(red(String(e.message)) + `\n\n`); - } else { - log.error(red(String(e)) + `\n\n`); - } - } - resolve(false); - }); + const child = execa(cmd, args, { + cwd, + stdio: 'ignore', + }); - child.on('close', (code) => { - if (code === 0) { - resolve(true); + const install: Promise = child + .then(() => { + return true; + }) + .catch((e) => { + if (e) { + if (e.message) { + log.error(red(String(e.message)) + `\n\n`); } else { - resolve(false); + log.error(red(String(e)) + `\n\n`); } - }); - } catch (e) { - resolve(false); - } - }); + } + return false; + }); const abort = async () => { - if (child) { - child.kill('SIGINT'); - } + child.kill('SIGINT'); }; + // 5. Return the object synchronously return { abort, install }; } diff --git a/scripts/binding-platform.ts b/scripts/binding-platform.ts index 7bb25f7a1af..d7fc6439896 100644 --- a/scripts/binding-platform.ts +++ b/scripts/binding-platform.ts @@ -1,48 +1,36 @@ -import spawn from 'cross-spawn'; +import { execa } from 'execa'; import { copyFile, writeFile } from 'fs/promises'; import { existsSync } from 'node:fs'; import { join } from 'node:path'; import { ensureDir, type BuildConfig } from './util.ts'; export async function buildPlatformBinding(config: BuildConfig) { - await new Promise((resolve, reject) => { - try { - ensureDir(config.distQwikPkgDir); - ensureDir(config.distBindingsDir); - - const cmd = `napi`; - const args = [ - `build`, - `--cargo-name`, - 'qwik_napi', - `--platform`, - `--config=packages/qwik/src/napi/napi.config.json`, - config.distBindingsDir, - ]; - - if (config.platformTarget) { - args.push(`--target`, config.platformTarget); - } - if (!config.dev) { - args.push(`--release`); - args.push(`--strip`); - } + ensureDir(config.distQwikPkgDir); + ensureDir(config.distBindingsDir); - const napiCwd = join(config.rootDir); + const cmd = `napi`; + const args = [ + `build`, + `--cargo-name`, + 'qwik_napi', + `--platform`, + `--config=packages/qwik/src/napi/napi.config.json`, + config.distBindingsDir, + ]; + + if (config.platformTarget) { + args.push(`--target`, config.platformTarget); + } + if (!config.dev) { + args.push(`--release`); + args.push(`--strip`); + } - const child = spawn(cmd, args, { stdio: 'inherit', cwd: napiCwd }); - child.on('error', reject); + const napiCwd = join(config.rootDir); - child.on('close', (code) => { - if (code === 0) { - resolve(child.stdout); - } else { - reject(`napi exited with code ${code}`); - } - }); - } catch (e) { - reject(e); - } + await execa(cmd, args, { + stdio: 'inherit', + cwd: napiCwd, }); console.log('🐯 native binding'); @@ -99,21 +87,7 @@ export async function copyPlatformBindingWasm(config: BuildConfig) { // now unpack the package using tar, into the cache directory const unpackedPath = join(cacheDir, `${realPackageName}-unpacked`); ensureDir(unpackedPath); - await new Promise((resolve, reject) => { - const child = spawn('tar', ['-xvf', cachedPath, '-C', unpackedPath]); - child.on('error', (e) => { - console.error(e); - reject(e); - }); - child.on('close', (code) => { - if (code === 0) { - resolve(child.stdout); - } else { - console.error(child.stdout); - reject(`tar exited with code ${code}`); - } - }); - }); + await execa('tar', ['-xvf', cachedPath, '-C', unpackedPath]); // now we need to find the bindings in the package cacheVersionDir = join(unpackedPath, 'package', 'bindings'); diff --git a/scripts/binding-wasm.ts b/scripts/binding-wasm.ts index b963698d325..af735f09342 100644 --- a/scripts/binding-wasm.ts +++ b/scripts/binding-wasm.ts @@ -1,5 +1,5 @@ import { type BuildConfig, copyFile, emptyDir, ensureDir } from './util.ts'; -import spawn from 'cross-spawn'; +import { execa } from 'execa'; import { join } from 'node:path'; import { rollup } from 'rollup'; @@ -18,25 +18,18 @@ export async function buildWasmBinding(config: BuildConfig) { args.push(`--release`); } - await new Promise((resolve, reject) => { - const child = spawn(cmd, args, { - stdio: 'inherit', - shell: true, - env: { - ...process.env, - ...env, - }, - }); - child.on('error', reject); - - child.on('close', (code) => { - if (code === 0) { - resolve(child.stdout); - } else { - reject(`wasm-pack exited with code ${code}`); - } - }); + // 2. Replace the entire Promise wrapper with one line + // execa handles errors and non-zero exit codes automatically. + await execa(cmd, args, { + stdio: 'inherit', // 'inherit' is still used to show build output + shell: true, + env: { + ...process.env, + ...env, + }, }); + + // 3. The return statement is unchanged return join(tmpBuildDir, 'qwik_wasm.js'); } diff --git a/scripts/submodule-cli.ts b/scripts/submodule-cli.ts index cd12dbcde01..829a7f9fce3 100644 --- a/scripts/submodule-cli.ts +++ b/scripts/submodule-cli.ts @@ -35,7 +35,7 @@ export async function submoduleCli(config: BuildConfig) { }, }, ], - external: ['prettier', 'typescript', 'ts-morph', 'semver', 'ignore'], + external: ['prettier', 'typescript', 'ts-morph', 'semver', 'ignore', 'execa'], define: { 'globalThis.CODE_MOD': 'true', 'globalThis.QWIK_VERSION': JSON.stringify(config.distVersion), From 022969ace44a07a40ab73daeae0e414fc3200ba9 Mon Sep 17 00:00:00 2001 From: Jerry_Wu <409187100@qq.com> Date: Fri, 7 Nov 2025 09:54:12 +0800 Subject: [PATCH 2/4] refactor: migrate from CommonJS to ESM by removing CJS builds and updating scripts and package configurations rename changeset --- .changeset/empty-mails-laugh.md | 9 ++ e2e/qwik-cli-e2e/README.md | 2 +- e2e/qwik-cli-e2e/utils/index.ts | 2 +- package.json | 4 +- packages/create-qwik/create-qwik.cjs | 3 - packages/create-qwik/create-qwik.mjs | 3 + packages/create-qwik/package.json | 9 +- packages/qwik-react/package.json | 6 +- packages/qwik-react/vite.config.ts | 4 +- packages/qwik-router/package.json | 54 ++++-------- .../qwik-router/src/buildtime/vite/plugin.ts | 12 +-- packages/qwik-router/vite.config.ts | 11 +-- packages/qwik/package.json | 58 +++---------- packages/qwik/{qwik-cli.cjs => qwik-cli.mjs} | 2 +- packages/qwik/src/cli/{qwik.cjs => qwik.mjs} | 2 +- packages/qwik/src/cli/utils/integrations.ts | 5 +- packages/qwik/src/cli/utils/templates.ts | 5 +- packages/qwik/src/optimizer/src/platform.ts | 86 +------------------ .../supabase-auth-helpers-qwik/package.json | 3 +- .../supabase-auth-helpers-qwik/vite.config.ts | 4 +- pnpm-lock.yaml | 19 +--- scripts/binding-wasm.ts | 6 -- scripts/build.ts | 8 -- scripts/create-qwik-cli.ts | 6 +- scripts/submodule-backpatch.ts | 6 -- scripts/submodule-build.ts | 15 +--- scripts/submodule-cli.ts | 6 +- scripts/submodule-core.ts | 54 +----------- scripts/submodule-insights.ts | 10 +-- scripts/submodule-optimizer.ts | 30 +------ scripts/submodule-preloader.ts | 4 +- scripts/submodule-qwikloader.ts | 6 -- scripts/submodule-server.ts | 61 +------------ scripts/submodule-testing.ts | 25 +----- scripts/util.ts | 2 +- scripts/validate-build.ts | 9 -- scripts/validate-cli.ts | 2 +- .../storybook/.storybook/tsconfig.json | 1 - 38 files changed, 100 insertions(+), 454 deletions(-) create mode 100644 .changeset/empty-mails-laugh.md delete mode 100755 packages/create-qwik/create-qwik.cjs create mode 100755 packages/create-qwik/create-qwik.mjs rename packages/qwik/{qwik-cli.cjs => qwik-cli.mjs} (66%) rename packages/qwik/src/cli/{qwik.cjs => qwik.mjs} (50%) diff --git a/.changeset/empty-mails-laugh.md b/.changeset/empty-mails-laugh.md new file mode 100644 index 00000000000..41b12ffda5a --- /dev/null +++ b/.changeset/empty-mails-laugh.md @@ -0,0 +1,9 @@ +--- +'supabase-auth-helpers-qwik': major +'create-qwik': major +'@qwik.dev/router': major +'@qwik.dev/react': major +'@qwik.dev/core': major +--- + +BREAKING: the CJS/UMD builds have been removed; ESM is well-supported everywhere and allows better optimizations. diff --git a/e2e/qwik-cli-e2e/README.md b/e2e/qwik-cli-e2e/README.md index fd879fc283d..a406f05f0eb 100644 --- a/e2e/qwik-cli-e2e/README.md +++ b/e2e/qwik-cli-e2e/README.md @@ -12,7 +12,7 @@ E2E project does the following internally: 0. Vitest is configured to run a setup function once **PRIOR TO ALL** tests. During the setup `@qwik.dev/core`, `@qwik.dev/router` and `eslint-plugin-qwik` packages will be packed with `pnpm pack` Those will be used at a step 2 for every test. Tarballs are located in `temp/tarballs` folder within this repo. It is assumed that packages are built before E2E is executed. -1. Simulates `npm create qwik` locally using direct command `node packages/create-qwik/create-qwik.cjs playground {outputDir}` +1. Simulates `npm create qwik` locally using direct command `node packages/create-qwik/create-qwik.mjs playground {outputDir}` - By default `outputDir` is an auto-generated one using `tmp` npm package. The application that is created here will be removed after the test is executed - It is possible to install into custom folder using environment variable `TEMP_E2E_PATH`. Here's how the command would look like in this case: - with absolute path `TEMP_E2E_PATH=/Users/name/projects/tests pnpm run test.e2e.cli` diff --git a/e2e/qwik-cli-e2e/utils/index.ts b/e2e/qwik-cli-e2e/utils/index.ts index 72db5824710..d421c5b6ab0 100644 --- a/e2e/qwik-cli-e2e/utils/index.ts +++ b/e2e/qwik-cli-e2e/utils/index.ts @@ -61,7 +61,7 @@ function getTmpDirSync(tmpDirOverride?: string) { function runCreateQwikCommand(tmpDir: string, type: 'playground' | 'library' | 'empty'): string { const appDir = 'e2e-app'; execSync( - `node "${workspaceRoot}/packages/create-qwik/create-qwik.cjs" ${type} "${join(tmpDir, appDir)}"` + `node "${workspaceRoot}/packages/create-qwik/create-qwik.mjs" ${type} "${join(tmpDir, appDir)}"` ); return join(tmpDir, appDir); } diff --git a/package.json b/package.json index 77ef2a2838c..50578ba2b10 100644 --- a/package.json +++ b/package.json @@ -195,8 +195,8 @@ "build.wasm": "node --require ./scripts/runBefore.ts scripts/index.ts --wasm", "build.watch": "node --require ./scripts/runBefore.ts scripts/index.ts --qwik --qwikrouter --watch --dev --platform-binding", "change": "changeset", - "cli": "pnpm build.cli && node packages/create-qwik/create-qwik.cjs && node --require ./scripts/runBefore.ts scripts/validate-cli.ts --copy-local-qwik-dist", - "cli.qwik": "pnpm build.cli && node packages/qwik/qwik-cli.cjs", + "cli": "pnpm build.cli && node packages/create-qwik/create-qwik.mjs && node --require ./scripts/runBefore.ts scripts/validate-cli.ts --copy-local-qwik-dist", + "cli.qwik": "pnpm build.cli && node packages/qwik/qwik-cli.mjs", "cli.validate": "node --require ./scripts/runBefore.ts scripts/validate-cli.ts", "deps": "corepack pnpm upgrade -i -r --latest && syncpack fix-mismatches && corepack pnpm dedupe", "docs.dev": "pnpm -C packages/docs build.repl-sw && pnpm -C packages/docs dev", diff --git a/packages/create-qwik/create-qwik.cjs b/packages/create-qwik/create-qwik.cjs deleted file mode 100755 index 28182bf4a1b..00000000000 --- a/packages/create-qwik/create-qwik.cjs +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env node -const createQwik = require('./dist/index.cjs'); -createQwik.runCli(); diff --git a/packages/create-qwik/create-qwik.mjs b/packages/create-qwik/create-qwik.mjs new file mode 100755 index 00000000000..ae2899d5056 --- /dev/null +++ b/packages/create-qwik/create-qwik.mjs @@ -0,0 +1,3 @@ +#!/usr/bin/env node +import * as createQwik from './dist/index.mjs'; +createQwik.runCli(); diff --git a/packages/create-qwik/package.json b/packages/create-qwik/package.json index 1c7c74fb323..2c6db15bdba 100644 --- a/packages/create-qwik/package.json +++ b/packages/create-qwik/package.json @@ -3,7 +3,7 @@ "description": "Interactive CLI for create Qwik projects and adding features.", "version": "2.0.0-beta.13", "author": "Qwik Team", - "bin": "./create-qwik.cjs", + "bin": "./create-qwik.mjs", "bugs": "https://github.com/QwikDev/qwik/issues", "devDependencies": { "@clack/prompts": "0.11.0", @@ -20,7 +20,7 @@ "engines-annotation": "Mostly required by sharp which needs a Node-API v9 compatible runtime", "files": [ "README.md", - "create-qwik.cjs", + "create-qwik.mjs", "dist" ], "homepage": "https://qwik.dev/", @@ -31,10 +31,11 @@ "template" ], "license": "MIT", - "main": "./dist/index.cjs", + "main": "./dist/index.mjs", "repository": { "type": "git", "url": "https://github.com/QwikDev/qwik.git", "directory": "packages/create-qwik" - } + }, + "type": "module" } diff --git a/packages/qwik-react/package.json b/packages/qwik-react/package.json index e33aef4fbfe..be4c0a7f639 100644 --- a/packages/qwik-react/package.json +++ b/packages/qwik-react/package.json @@ -18,13 +18,11 @@ "exports": { ".": { "types": "./lib/types/index.qwik.d.ts", - "import": "./lib/index.qwik.mjs", - "require": "./lib/index.qwik.cjs" + "import": "./lib/index.qwik.mjs" }, "./vite": { "types": "./lib/types/vite.d.ts", - "import": "./lib/vite.mjs", - "require": "./lib/vite.cjs" + "import": "./lib/vite.mjs" } }, "files": [ diff --git a/packages/qwik-react/vite.config.ts b/packages/qwik-react/vite.config.ts index b00fd97cca5..a2c2ba1eb63 100644 --- a/packages/qwik-react/vite.config.ts +++ b/packages/qwik-react/vite.config.ts @@ -8,8 +8,8 @@ export default defineConfig(() => { target: 'es2020', lib: { entry: ['./src/index.qwik.ts', './src/vite.ts'], - formats: ['es', 'cjs'], - fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`, + formats: ['es'], + fileName: (format, entryName) => `${entryName}.mjs`, }, rollupOptions: { external: [ diff --git a/packages/qwik-router/package.json b/packages/qwik-router/package.json index a3eef36f1ba..f88abbd3463 100644 --- a/packages/qwik-router/package.json +++ b/packages/qwik-router/package.json @@ -48,63 +48,51 @@ "exports": { ".": { "types": "./lib/index.d.ts", - "import": "./lib/index.qwik.mjs", - "require": "./lib/index.qwik.cjs" + "import": "./lib/index.qwik.mjs" }, "./adapters/azure-swa/vite": { "types": "./lib/adapters/azure-swa/vite/index.d.ts", - "import": "./lib/adapters/azure-swa/vite/index.mjs", - "require": "./lib/adapters/azure-swa/vite/index.cjs" + "import": "./lib/adapters/azure-swa/vite/index.mjs" }, "./adapters/cloudflare-pages/vite": { "types": "./lib/adapters/cloudflare-pages/vite/index.d.ts", - "import": "./lib/adapters/cloudflare-pages/vite/index.mjs", - "require": "./lib/adapters/cloudflare-pages/vite/index.cjs" + "import": "./lib/adapters/cloudflare-pages/vite/index.mjs" }, "./adapters/cloud-run/vite": { "types": "./lib/adapters/cloud-run/vite/index.d.ts", - "import": "./lib/adapters/cloud-run/vite/index.mjs", - "require": "./lib/adapters/cloud-run/vite/index.cjs" + "import": "./lib/adapters/cloud-run/vite/index.mjs" }, "./adapters/bun-server/vite": { "types": "./lib/adapters/bun-server/vite/index.d.ts", - "import": "./lib/adapters/bun-server/vite/index.mjs", - "require": "./lib/adapters/bun-server/vite/index.cjs" + "import": "./lib/adapters/bun-server/vite/index.mjs" }, "./adapters/deno-server/vite": { "types": "./lib/adapters/deno-server/vite/index.d.ts", - "import": "./lib/adapters/deno-server/vite/index.mjs", - "require": "./lib/adapters/deno-server/vite/index.cjs" + "import": "./lib/adapters/deno-server/vite/index.mjs" }, "./adapters/node-server/vite": { "types": "./lib/adapters/node-server/vite/index.d.ts", - "import": "./lib/adapters/node-server/vite/index.mjs", - "require": "./lib/adapters/node-server/vite/index.cjs" + "import": "./lib/adapters/node-server/vite/index.mjs" }, "./adapters/netlify-edge/vite": { "types": "./lib/adapters/netlify-edge/vite/index.d.ts", - "import": "./lib/adapters/netlify-edge/vite/index.mjs", - "require": "./lib/adapters/netlify-edge/vite/index.cjs" + "import": "./lib/adapters/netlify-edge/vite/index.mjs" }, "./adapters/shared/vite": { "types": "./lib/adapters/shared/vite/index.d.ts", - "import": "./lib/adapters/shared/vite/index.mjs", - "require": "./lib/adapters/shared/vite/index.cjs" + "import": "./lib/adapters/shared/vite/index.mjs" }, "./adapters/static/vite": { "types": "./lib/adapters/ssg/vite/index.d.ts", - "import": "./lib/adapters/ssg/vite/index.mjs", - "require": "./lib/adapters/ssg/vite/index.cjs" + "import": "./lib/adapters/ssg/vite/index.mjs" }, "./adapters/ssg/vite": { "types": "./lib/adapters/ssg/vite/index.d.ts", - "import": "./lib/adapters/ssg/vite/index.mjs", - "require": "./lib/adapters/ssg/vite/index.cjs" + "import": "./lib/adapters/ssg/vite/index.mjs" }, "./adapters/vercel-edge/vite": { "types": "./lib/adapters/vercel-edge/vite/index.d.ts", - "import": "./lib/adapters/vercel-edge/vite/index.mjs", - "require": "./lib/adapters/vercel-edge/vite/index.cjs" + "import": "./lib/adapters/vercel-edge/vite/index.mjs" }, "./middleware/azure-swa": { "types": "./lib/middleware/azure-swa/index.d.ts", @@ -136,13 +124,11 @@ }, "./middleware/node": { "types": "./lib/middleware/node/index.d.ts", - "import": "./lib/middleware/node/index.mjs", - "require": "./lib/middleware/node/index.cjs" + "import": "./lib/middleware/node/index.mjs" }, "./middleware/request-handler": { "types": "./lib/middleware/request-handler/index.d.ts", - "import": "./lib/middleware/request-handler/index.mjs", - "require": "./lib/middleware/request-handler/index.cjs" + "import": "./lib/middleware/request-handler/index.mjs" }, "./middleware/vercel-edge": { "types": "./lib/middleware/vercel-edge/index.d.ts", @@ -150,23 +136,19 @@ }, "./static": { "types": "./lib/ssg/index.d.ts", - "import": "./lib/ssg/index.mjs", - "require": "./lib/ssg/index.cjs" + "import": "./lib/ssg/index.mjs" }, "./ssg": { "types": "./lib/ssg/index.d.ts", - "import": "./lib/ssg/index.mjs", - "require": "./lib/ssg/index.cjs" + "import": "./lib/ssg/index.mjs" }, "./vite": { "types": "./lib/vite/index.d.ts", - "import": "./lib/vite/index.mjs", - "require": "./lib/vite/index.cjs" + "import": "./lib/vite/index.mjs" }, "./service-worker": { "types": "./service-worker.d.ts", - "import": "./lib/service-worker.mjs", - "require": "./lib/service-worker.cjs" + "import": "./lib/service-worker.mjs" }, "./package.json": "./package.json" }, diff --git a/packages/qwik-router/src/buildtime/vite/plugin.ts b/packages/qwik-router/src/buildtime/vite/plugin.ts index ff172b5fd74..227bb555150 100644 --- a/packages/qwik-router/src/buildtime/vite/plugin.ts +++ b/packages/qwik-router/src/buildtime/vite/plugin.ts @@ -46,7 +46,6 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any { let mdxTransform: MdxTransform | null = null; let rootDir: string | null = null; let qwikPlugin: QwikVitePlugin | null; - let ssrFormat: 'esm' | 'cjs' = 'esm'; let outDir: string | null = null; let viteCommand: string; let devServer: ViteDevServer | null = null; @@ -160,11 +159,6 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any { qwikPlugin.api.registerBundleGraphAdder?.((manifest) => { return getRouteImports(ctx!.routes, manifest); }); - - // @ts-ignore `format` removed in Vite 5 - if (config.ssr?.format === 'cjs') { - ssrFormat = 'cjs'; - } outDir = config.build?.outDir; }, @@ -333,7 +327,7 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any { sequential: true, async handler() { if (ctx?.target === 'ssr' && outDir) { - await generateServerPackageJson(outDir, ssrFormat); + await generateServerPackageJson(outDir); } }, }, @@ -342,7 +336,7 @@ function qwikRouterPlugin(userOpts?: QwikRouterVitePluginOptions): any { return plugin; } -async function generateServerPackageJson(outDir: string, ssrFormat: 'esm' | 'cjs') { +async function generateServerPackageJson(outDir: string) { await fs.promises.mkdir(outDir, { recursive: true }); const serverPackageJsonPath = join(outDir, 'package.json'); @@ -359,7 +353,7 @@ async function generateServerPackageJson(outDir: string, ssrFormat: 'esm' | 'cjs packageJson = { ...packageJson, - type: ssrFormat == 'cjs' ? 'commonjs' : 'module', + type: 'module', }; const serverPackageJsonCode = JSON.stringify(packageJson, null, 2); diff --git a/packages/qwik-router/vite.config.ts b/packages/qwik-router/vite.config.ts index c434fd4dd7b..31f990e0394 100644 --- a/packages/qwik-router/vite.config.ts +++ b/packages/qwik-router/vite.config.ts @@ -8,7 +8,7 @@ export default defineConfig(() => { emptyOutDir: false, ssr: true, modulePreload: false, - target: 'es2020', + target: 'esnext', outDir: 'lib', minify: false, rollupOptions: { @@ -48,15 +48,6 @@ export default defineConfig(() => { entryFileNames: (chunkInfo) => chunkInfo.name === 'index' ? '[name].qwik.mjs' : '[name]/index.mjs', }, - { - format: 'cjs', - chunkFileNames: (chunkInfo) => - chunkInfo.moduleIds.some((id) => id.includes('runtime')) - ? 'chunks/[name].qwik.cjs' - : 'chunks/[name].cjs', - entryFileNames: (chunkInfo) => - chunkInfo.name === 'index' ? '[name].qwik.cjs' : '[name]/index.cjs', - }, ], external: [ /node:.*/, diff --git a/packages/qwik/package.json b/packages/qwik/package.json index 5279e400f05..c1bb72b2cdb 100644 --- a/packages/qwik/package.json +++ b/packages/qwik/package.json @@ -4,13 +4,14 @@ "version": "2.0.0-beta.13", "author": "Qwik Team", "bin": { - "qwik": "./qwik-cli.cjs" + "qwik": "./qwik-cli.mjs" }, "bugs": "https://github.com/QwikDev/qwik/issues", "dependencies": { "csstype": "^3.1.3", "launch-editor": "^2.11.1", - "rollup": "^4.52.4" + "rollup": "^4.52.4", + "ts-morph": "23.0.0" }, "devDependencies": { "@croct/json5-parser": "0.2.1", @@ -21,7 +22,6 @@ "image-size": "1.2.1", "kleur": "4.1.5", "prettier": "3.6.2", - "ts-morph": "23.0.0", "vitest": "4.0.1" }, "engines": { @@ -35,15 +35,10 @@ "production": "./dist/core.prod.mjs", "min": "./dist/core.min.mjs", "default": "./dist/core.prod.mjs" - }, - "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.prod.cjs" } }, "./cli": { - "require": "./dist/cli.cjs" + "require": "./dist/cli.mjs" }, "./handlers.mjs": "./handlers.mjs", "./internal": { @@ -53,11 +48,6 @@ "production": "./dist/core.prod.mjs", "min": "./dist/core.min.mjs", "default": "./dist/core.prod.mjs" - }, - "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.prod.cjs" } }, "./jsx-runtime": { @@ -67,11 +57,6 @@ "production": "./dist/core.prod.mjs", "min": "./dist/core.min.mjs", "default": "./dist/core.prod.mjs" - }, - "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.prod.cjs" } }, "./jsx-dev-runtime": { @@ -81,11 +66,6 @@ "production": "./dist/core.prod.mjs", "min": "./dist/core.min.mjs", "default": "./dist/core.mjs" - }, - "require": { - "development": "./dist/core.cjs", - "production": "./dist/core.prod.cjs", - "default": "./dist/core.cjs" } }, "./build": { @@ -94,50 +74,36 @@ "development": "./dist/build/index.dev.mjs", "production": "./dist/build/index.prod.mjs", "default": "./dist/build/index.mjs" - }, - "require": { - "development": "./dist/build/index.dev.cjs", - "production": "./dist/build/index.prod.cjs", - "default": "./dist/build/index.cjs" } }, "./loader": { "types": "./dist/loader/index.d.ts", - "import": "./dist/loader/index.mjs", - "require": "./dist/loader/index.cjs" + "import": "./dist/loader/index.mjs" }, "./insights": { "types": "./dist/insights.d.ts", - "import": "./dist/insights/index.qwik.mjs", - "require": "./dist/insights/index.qwik.cjs" + "import": "./dist/insights/index.qwik.mjs" }, "./insights/vite": { "types": "./dist/insights/vite.d.ts", - "import": "./dist/insights/vite/index.mjs", - "require": "./dist/insights/vite/index.cjs" + "import": "./dist/insights/vite/index.mjs" }, - "./optimizer.cjs": "./dist/optimizer.cjs", "./optimizer.mjs": "./dist/optimizer.mjs", "./optimizer": { "types": "./dist/optimizer.d.ts", - "import": "./dist/optimizer.mjs", - "require": "./dist/optimizer.cjs" + "import": "./dist/optimizer.mjs" }, "./preloader": { - "import": "./dist/preloader.mjs", - "require": "./dist/preloader.cjs" + "import": "./dist/preloader.mjs" }, - "./server.cjs": "./dist/server.cjs", "./server.mjs": "./dist/server.mjs", "./server": { "types": "./server.d.ts", - "import": "./dist/server.mjs", - "require": "./dist/server.cjs" + "import": "./dist/server.mjs" }, "./testing": { "types": "./dist/testing/index.d.ts", - "import": "./dist/testing/index.mjs", - "require": "./dist/testing/index.cjs" + "import": "./dist/testing/index.mjs" }, "./qwikloader.js": "./dist/qwikloader.js", "./qwikloader.debug.js": "./dist/qwikloader.debug.js", @@ -161,7 +127,7 @@ "public.d.ts", "server.d.ts", "testing.d.ts", - "qwik-cli.cjs" + "qwik-cli.mjs" ], "homepage": "https://qwik.dev/", "keywords": [ diff --git a/packages/qwik/qwik-cli.cjs b/packages/qwik/qwik-cli.mjs similarity index 66% rename from packages/qwik/qwik-cli.cjs rename to packages/qwik/qwik-cli.mjs index 9a0e313e3f3..cc75e0cc05b 100755 --- a/packages/qwik/qwik-cli.cjs +++ b/packages/qwik/qwik-cli.mjs @@ -1,4 +1,4 @@ #!/usr/bin/env node // This requires the build to be run first. -const qwik = require('./dist/cli.cjs'); +import * as qwik from './dist/cli.mjs'; qwik.runCli(); diff --git a/packages/qwik/src/cli/qwik.cjs b/packages/qwik/src/cli/qwik.mjs similarity index 50% rename from packages/qwik/src/cli/qwik.cjs rename to packages/qwik/src/cli/qwik.mjs index ca86a86a9b4..e44616f27c7 100644 --- a/packages/qwik/src/cli/qwik.cjs +++ b/packages/qwik/src/cli/qwik.mjs @@ -1,3 +1,3 @@ #!/usr/bin/env node -const qwik = require('./cli.cjs'); +import * as qwik from './cli.mjs'; qwik.runCli(); diff --git a/packages/qwik/src/cli/utils/integrations.ts b/packages/qwik/src/cli/utils/integrations.ts index 99bfd386b8c..b422c162107 100644 --- a/packages/qwik/src/cli/utils/integrations.ts +++ b/packages/qwik/src/cli/utils/integrations.ts @@ -1,8 +1,11 @@ import fs from 'node:fs'; -import { join } from 'node:path'; +import { join, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { IntegrationData, IntegrationType } from '../types'; import { dashToTitleCase, limitLength, readPackageJson } from './utils'; +const __dirname = dirname(fileURLToPath(import.meta.url)); + let integrations: IntegrationData[] | null = null; export async function sortIntegrationsAndReturnAsClackOptions( diff --git a/packages/qwik/src/cli/utils/templates.ts b/packages/qwik/src/cli/utils/templates.ts index 2ed41a62565..d90f5b720af 100644 --- a/packages/qwik/src/cli/utils/templates.ts +++ b/packages/qwik/src/cli/utils/templates.ts @@ -1,8 +1,11 @@ import fs from 'node:fs'; -import { join, sep } from 'node:path'; +import { join, sep, dirname } from 'node:path'; +import { fileURLToPath } from 'node:url'; import type { TemplateSet } from '../types'; import { getFilesDeep } from './utils'; +const __dirname = dirname(fileURLToPath(import.meta.url)); + let templates: TemplateSet[] | null = null; export async function loadTemplates() { diff --git a/packages/qwik/src/optimizer/src/platform.ts b/packages/qwik/src/optimizer/src/platform.ts index 522a21288fb..79ef25842ae 100644 --- a/packages/qwik/src/optimizer/src/platform.ts +++ b/packages/qwik/src/optimizer/src/platform.ts @@ -6,7 +6,6 @@ import type { } from './types'; import { createPath } from './path'; import { QWIK_BINDING_MAP } from './qwik-binding-map'; -import { versions } from './versions'; export async function getSystem() { const sysEnv = getEnv(); @@ -34,33 +33,6 @@ export async function getSystem() { sys.strictDynamicImport = sys.dynamicImport = (path) => import(path); } - if (globalThis.IS_CJS) { - if (sysEnv === 'node' || sysEnv === 'bun') { - // using this api object as a way to ensure bundlers - // do not try to inline or rewrite require() - sys.dynamicImport = (path) => require(path); - sys.strictDynamicImport = (path) => import(path); - - if (typeof TextEncoder === 'undefined') { - // TextEncoder/TextDecoder needs to be on the global scope for the WASM file - // https://nodejs.org/api/util.html#class-utiltextdecoder - const nodeUtil: typeof import('util') = await sys.dynamicImport('node:util'); - globalThis.TextEncoder = nodeUtil.TextEncoder; - globalThis.TextDecoder = nodeUtil.TextDecoder; - } - } else if (sysEnv === 'webworker' || sysEnv === 'browsermain') { - sys.strictDynamicImport = (path) => import(path); - sys.dynamicImport = async (path: string) => { - const cjsRsp = await fetch(path); - const cjsCode = await cjsRsp.text(); - const cjsModule: any = { exports: {} }; - // eslint-disable-next-line no-new-func - const cjsRun = new Function('module', 'exports', cjsCode); - cjsRun(cjsModule, cjsModule.exports); - return cjsModule.exports; - }; - } - } if (sysEnv !== 'webworker' && sysEnv !== 'browsermain') { try { sys.path = await sys.dynamicImport('node:path'); @@ -167,62 +139,6 @@ export async function loadPlatformBinding(sys: OptimizerSystem) { } } - if (globalThis.IS_CJS) { - // CJS WASM - - if (sysEnv === 'node' || sysEnv === 'bun') { - // CJS WASM Node.js - const wasmPath = sys.path.join(__dirname, '..', 'bindings', 'qwik_wasm_bg.wasm'); - const mod = await sys.dynamicImport(`../bindings/qwik.wasm.cjs`); - const fs: typeof import('fs') = await sys.dynamicImport('node:fs'); - - const buf = await fs.promises.readFile(wasmPath); - const wasm = await WebAssembly.compile(buf as any); - await mod.default(wasm); - return mod; - } - - if (sysEnv === 'webworker' || sysEnv === 'browsermain') { - // CJS WASM Browser - let version = versions.qwik; - const cachedCjsCode = `qwikWasmCjs${version}`; - const cachedWasmRsp = `qwikWasmRsp${version}`; - - let cjsCode: string = (globalThis as any)[cachedCjsCode]; - let wasmRsp: Response = (globalThis as any)[cachedWasmRsp]; - - if (!cjsCode || !wasmRsp) { - version = versions.qwik.split('-dev')[0]; - const cdnUrl = `https://cdn.jsdelivr.net/npm/@qwik.dev/core@${version}/bindings/`; - const cjsModuleUrl = new URL(`./qwik.wasm.cjs`, cdnUrl).href; - const wasmUrl = new URL(`./qwik_wasm_bg.wasm`, cdnUrl).href; - - const rsps = await Promise.all([fetch(cjsModuleUrl), fetch(wasmUrl)]); - - for (const rsp of rsps) { - if (!rsp.ok) { - throw new Error(`Unable to fetch Qwik WASM binding from ${rsp.url}`); - } - } - - const cjsRsp = rsps[0]; - (globalThis as any)[cachedCjsCode] = cjsCode = await cjsRsp.text(); - (globalThis as any)[cachedWasmRsp] = wasmRsp = rsps[1]; - } - - const cjsModule: any = { exports: {} }; - // eslint-disable-next-line no-new-func - const cjsRun = new Function('module', 'exports', cjsCode); - cjsRun(cjsModule, cjsModule.exports); - const mod = cjsModule.exports; - - // init - await mod.default(wasmRsp.clone()); - - return mod; - } - } - if (globalThis.IS_ESM) { if (sysEnv === 'node' || sysEnv === 'bun') { // ESM WASM Node.js @@ -302,7 +218,7 @@ const extensions: { [ext: string]: boolean } = { '.mjs': true, }; -declare const globalThis: { IS_CJS: boolean; IS_ESM: boolean; [key: string]: any }; +declare const globalThis: { IS_ESM: boolean; [key: string]: any }; declare const WorkerGlobalScope: any; declare const Deno: any; declare const Bun: any; diff --git a/packages/supabase-auth-helpers-qwik/package.json b/packages/supabase-auth-helpers-qwik/package.json index e8195f32cfe..7ad737a5c28 100644 --- a/packages/supabase-auth-helpers-qwik/package.json +++ b/packages/supabase-auth-helpers-qwik/package.json @@ -13,8 +13,7 @@ "exports": { ".": { "types": "./lib/types/index.d.ts", - "import": "./lib/index.qwik.mjs", - "require": "./lib/index.qwik.cjs" + "import": "./lib/index.qwik.mjs" } }, "files": [ diff --git a/packages/supabase-auth-helpers-qwik/vite.config.ts b/packages/supabase-auth-helpers-qwik/vite.config.ts index cc61d20c191..9fc503607a9 100644 --- a/packages/supabase-auth-helpers-qwik/vite.config.ts +++ b/packages/supabase-auth-helpers-qwik/vite.config.ts @@ -10,8 +10,8 @@ export default defineConfig((config) => { outDir: 'lib', lib: { entry: ['./src/index.ts'], - formats: ['es', 'cjs'], - fileName: (format) => `index.qwik.${format === 'es' ? 'mjs' : 'cjs'}`, + formats: ['es'], + fileName: () => `index.qwik.mjs`, }, rollupOptions: { external: [ diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a28700eb74c..56287d61695 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -79,9 +79,6 @@ importers: '@types/bun': specifier: 1.2.21 version: 1.2.21(@types/react@19.1.13) - '@types/cross-spawn': - specifier: 6.0.6 - version: 6.0.6 '@types/express': specifier: 5.0.3 version: 5.0.3 @@ -121,9 +118,6 @@ importers: create-qwik: specifier: workspace:* version: link:packages/create-qwik - cross-spawn: - specifier: 7.0.6 - version: 7.0.6 csstype: specifier: 3.1.3 version: 3.1.3 @@ -593,6 +587,9 @@ importers: rollup: specifier: ^4.52.4 version: 4.52.4 + ts-morph: + specifier: 23.0.0 + version: 23.0.0 devDependencies: '@croct/json5-parser': specifier: 0.2.1 @@ -618,9 +615,6 @@ importers: prettier: specifier: 3.6.2 version: 3.6.2 - ts-morph: - specifier: 23.0.0 - version: 23.0.0 vitest: specifier: 4.0.1 version: 4.0.1(@types/debug@4.1.12)(@types/node@24.3.0)(jiti@2.6.0)(lightningcss@1.30.1)(terser@5.44.0)(yaml@2.8.1) @@ -3135,9 +3129,6 @@ packages: '@types/connect@3.4.38': resolution: {integrity: sha512-K6uROf1LD88uDQqJCktA4yzL1YYAK6NgfsI0v/mTgyPKWsX1CnJ0XPSDhViejru1GcRkLWb8RlzFYJRqGUbaug==} - '@types/cross-spawn@6.0.6': - resolution: {integrity: sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==} - '@types/debug@4.1.12': resolution: {integrity: sha512-vIChWdVG3LG1SMxEvI/AK+FWJthlrqlTu7fbrlywTkkaONwk/UAGaULXRlf8vkzFBLVm0zkMdCquhL5aOjhXPQ==} @@ -11828,10 +11819,6 @@ snapshots: dependencies: '@types/node': 24.3.0 - '@types/cross-spawn@6.0.6': - dependencies: - '@types/node': 24.3.0 - '@types/debug@4.1.12': dependencies: '@types/ms': 2.1.0 diff --git a/scripts/binding-wasm.ts b/scripts/binding-wasm.ts index af735f09342..b0aa41e0949 100644 --- a/scripts/binding-wasm.ts +++ b/scripts/binding-wasm.ts @@ -49,12 +49,6 @@ export async function buildWasmBinding(config: BuildConfig) { exports: 'named', }); - await build.write({ - format: 'cjs', - file: join(config.distBindingsDir, 'qwik.wasm.cjs'), - exports: 'named', - }); - await copyFile( join(tmpBuildDir, 'qwik_wasm_bg.wasm'), join(config.distBindingsDir, 'qwik_wasm_bg.wasm') diff --git a/scripts/build.ts b/scripts/build.ts index b5918befea8..a34e8243ba5 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -159,18 +159,10 @@ export async function build(config: BuildConfig) { await watchDirectories({ [join(config.srcQwikDir, 'core')]: async () => { await submoduleCore({ ...config, dev: true }); - await copyFile( - join(config.srcQwikDir, '..', 'dist', 'core.cjs'), - join(config.srcQwikDir, '..', 'dist', 'core.prod.cjs') - ); await copyFile( join(config.srcQwikDir, '..', 'dist', 'core.mjs'), join(config.srcQwikDir, '..', 'dist', 'core.prod.mjs') ); - console.log( - join(config.srcQwikDir, '..', 'dist', 'core.cjs'), - join(config.srcQwikDir, '..', 'dist', 'core.prod.cjs') - ); }, [join(config.srcQwikDir, 'cli')]: () => submoduleCli(config), [join(config.srcQwikDir, 'optimizer')]: () => submoduleOptimizer(config), diff --git a/scripts/create-qwik-cli.ts b/scripts/create-qwik-cli.ts index 40cdda7432a..0b51042d167 100644 --- a/scripts/create-qwik-cli.ts +++ b/scripts/create-qwik-cli.ts @@ -34,10 +34,10 @@ async function bundleCreateQwikCli(config: BuildConfig, srcCliDir: string, distC await build({ entryPoints: [join(srcCliDir, 'index.ts')], - outfile: join(distCliDir, 'index.cjs'), + outfile: join(distCliDir, 'index.mjs'), target: nodeTarget, platform: 'node', - format: 'cjs', + format: 'esm', bundle: true, sourcemap: false, minify: !config.dev, @@ -58,7 +58,7 @@ async function bundleCreateQwikCli(config: BuildConfig, srcCliDir: string, distC }, }, ], - external: ['prettier', 'typescript', 'ts-morph', 'semver', 'ignore'], + external: ['prettier', 'typescript', 'ts-morph', 'semver', 'ignore', 'execa'], define: { 'globalThis.CODE_MOD': 'false', 'globalThis.QWIK_VERSION': JSON.stringify(config.distVersion), diff --git a/scripts/submodule-backpatch.ts b/scripts/submodule-backpatch.ts index 756a72d3c01..3ccb8b6d86c 100644 --- a/scripts/submodule-backpatch.ts +++ b/scripts/submodule-backpatch.ts @@ -71,11 +71,6 @@ export async function generateBackpatchSubmodule(config: BuildConfig) { ...code, `export { QWIK_BACKPATCH_EXECUTOR_MINIFIED, QWIK_BACKPATCH_EXECUTOR_DEBUG };`, ]; - const cjsCode = [ - ...code, - `exports.QWIK_BACKPATCH_EXECUTOR_MINIFIED = QWIK_BACKPATCH_EXECUTOR_MINIFIED;`, - `exports.QWIK_BACKPATCH_EXECUTOR_DEBUG = QWIK_BACKPATCH_EXECUTOR_DEBUG;`, - ]; const dtsCode = [ `export declare const QWIK_BACKPATCH_EXECUTOR_MINIFIED: string;`, `export declare const QWIK_BACKPATCH_EXECUTOR_DEBUG: string;`, @@ -83,7 +78,6 @@ export async function generateBackpatchSubmodule(config: BuildConfig) { ensureDir(backpatchDistDir); await writeFile(join(backpatchDistDir, 'index.mjs'), esmCode.join('\n') + '\n'); - await writeFile(join(backpatchDistDir, 'index.cjs'), cjsCode.join('\n') + '\n'); await writeFile(join(backpatchDistDir, 'index.d.ts'), dtsCode.join('\n') + '\n'); const backpatchPkg: PackageJSON = { diff --git a/scripts/submodule-build.ts b/scripts/submodule-build.ts index 29f1a47fc92..ba588083f0f 100644 --- a/scripts/submodule-build.ts +++ b/scripts/submodule-build.ts @@ -50,18 +50,5 @@ export async function bundleIndex(config: BuildConfig, entryName: string) { outExtension: { '.js': '.mjs' }, }); - const cjs = build({ - ...opts, - format: 'cjs', - - banner: { - js: `globalThis.qwikBuild = (function (module) {`, - }, - footer: { - js: `return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });`, - }, - outExtension: { '.js': '.cjs' }, - }); - - await Promise.all([esm, cjs]); + await Promise.all([esm]); } diff --git a/scripts/submodule-cli.ts b/scripts/submodule-cli.ts index 829a7f9fce3..232877086dd 100644 --- a/scripts/submodule-cli.ts +++ b/scripts/submodule-cli.ts @@ -10,14 +10,14 @@ export async function submoduleCli(config: BuildConfig) { await build({ entryPoints: [join(config.srcQwikDir, submodule, 'index.ts')], - outfile: join(config.distQwikPkgDir, 'cli.cjs'), - format: 'cjs', + outfile: join(config.distQwikPkgDir, 'cli.mjs'), + format: 'esm', platform: 'node', target: nodeTarget, sourcemap: false, bundle: true, banner: { js: getBanner('@qwik.dev/core/cli', config.distVersion) }, - outExtension: { '.js': '.cjs' }, + outExtension: { '.js': '.mjs' }, plugins: [ { name: 'colorAlias', diff --git a/scripts/submodule-core.ts b/scripts/submodule-core.ts index 70011cce681..4d22f1161a3 100644 --- a/scripts/submodule-core.ts +++ b/scripts/submodule-core.ts @@ -56,23 +56,9 @@ async function submoduleCoreProd(config: BuildConfig) { banner: getBanner('@qwik.dev/core', config.distVersion), }; - const cjsOutput: OutputOptions = { - dir: join(config.distQwikPkgDir), - format: 'umd', - name: 'qwikCore', - entryFileNames: 'core.cjs', - sourcemap: true, - globals: { - '@qwik.dev/core/build': 'qwikBuild', - // not actually used - '@qwik.dev/core/preloader': 'qwikPreloader', - }, - banner: getBanner('@qwik.dev/core', config.distVersion), - }; - const build = await rollup(input); - await Promise.all([build.write(esmOutput), build.write(cjsOutput)]); + await Promise.all([build.write(esmOutput)]); console.log('🦊 core.mjs:', await fileSize(join(config.distQwikPkgDir, 'core.mjs'))); @@ -174,13 +160,7 @@ async function submoduleCoreProd(config: BuildConfig) { console.log('🐭 core.min.mjs:', await fileSize(join(config.distQwikPkgDir, 'core.min.mjs'))); let esmCode = await readFile(join(config.distQwikPkgDir, 'core.mjs'), 'utf-8'); - let cjsCode = await readFile(join(config.distQwikPkgDir, 'core.cjs'), 'utf-8'); - // fixup the Vite base url - cjsCode = cjsCode.replaceAll('undefined.BASE_URL', 'globalThis.BASE_URL||"/"'); - await writeFile(join(config.distQwikPkgDir, 'core.cjs'), cjsCode); - await submoduleCoreProduction(config, esmCode, join(config.distQwikPkgDir, 'core.prod.mjs')); - await submoduleCoreProduction(config, cjsCode, join(config.distQwikPkgDir, 'core.prod.cjs')); } async function submoduleCoreProduction(config: BuildConfig, code: string, outPath: string) { @@ -238,41 +218,11 @@ async function submoduleCoreDev(config: BuildConfig) { outExtension: { '.js': '.mjs' }, }); - // We do a CJS build, only for the repl service worker - const cjs = build({ - ...opts, - // we don't externalize qwik build because then the repl service worker sees require() - define: { - ...opts.define, - // We need to get rid of the import.meta.env values - // Vite's base url - 'import.meta.env.BASE_URL': 'globalThis.BASE_URL', - // Vite's devserver mode - 'import.meta.env.DEV': 'false', - }, - format: 'cjs', - outExtension: { '.js': '.cjs' }, - banner: { - js: `globalThis.qwikCore = (function (module) {`, - }, - footer: { - js: `return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });`, - }, - }); - - await Promise.all([esm, cjs]); + await Promise.all([esm]); // Point the minified and prod versions to the dev versions await writeFile(join(config.distQwikPkgDir, 'core.prod.mjs'), `export * from './core.mjs';\n`); - await writeFile( - join(config.distQwikPkgDir, 'core.prod.cjs'), - `module.exports = require('./core.cjs');\n` - ); await writeFile(join(config.distQwikPkgDir, 'core.min.mjs'), `export * from './core.mjs';\n`); - await writeFile( - join(config.distQwikPkgDir, 'core.min.cjs'), - `module.exports = require('./core.cjs');\n` - ); console.log('🐬', submodule, '(dev)'); } diff --git a/scripts/submodule-insights.ts b/scripts/submodule-insights.ts index f069b170982..d687fe04138 100644 --- a/scripts/submodule-insights.ts +++ b/scripts/submodule-insights.ts @@ -17,12 +17,12 @@ async function buildComponents(config: BuildConfig) { build: { lib: { entry: entryPoint, - formats: ['es', 'cjs'], - fileName: (format) => `index.qwik.${format === 'es' ? 'mjs' : 'cjs'}`, + formats: ['es'], + fileName: () => 'index.qwik.mjs', }, outDir: distBase, emptyOutDir: false, - target: 'es2020', + target: 'es2022', minify: true, rollupOptions: { external: (id) => /^(@|node:)/i.test(id), @@ -39,8 +39,8 @@ async function buildVite(config: BuildConfig) { build: { lib: { entry: entryPoint, - formats: ['es', 'cjs'], - fileName: (format) => (format === 'es' ? 'index.mjs' : 'index.cjs'), + formats: ['es'], + fileName: () => 'index.mjs', }, outDir: distBase, emptyOutDir: false, diff --git a/scripts/submodule-optimizer.ts b/scripts/submodule-optimizer.ts index e150a59fae0..ed5f28b3fbf 100644 --- a/scripts/submodule-optimizer.ts +++ b/scripts/submodule-optimizer.ts @@ -30,7 +30,7 @@ export async function submoduleOptimizer(config: BuildConfig) { lib: { entry: entryPoint, name: 'optimizer', - fileName: (format) => `optimizer.${format === 'es' ? 'mjs' : 'cjs'}`, + fileName: () => `optimizer.mjs`, }, }, define: { @@ -73,38 +73,12 @@ export async function submoduleOptimizer(config: BuildConfig) { }, define: { ...commonConfig.define, - 'globalThis.IS_CJS': 'false', 'globalThis.IS_ESM': 'true', }, }; - // CJS Build - const cjsConfig: UserConfig = { - ...commonConfig, - build: { - ...commonConfig.build, - outDir: config.distQwikPkgDir, - lib: { - ...commonConfig.build!.lib, - formats: ['cjs'], - }, - rollupOptions: { - ...commonConfig.build?.rollupOptions, - output: { - banner: `globalThis.qwikOptimizer = (function (module) {\n${getBanner('@qwik.dev/core/optimizer', config.distVersion)}`, - footer: `return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });`, - }, - }, - }, - define: { - ...commonConfig.define, - 'globalThis.IS_CJS': 'true', - 'globalThis.IS_ESM': 'false', - }, - }; - // Build both formats - await Promise.all([viteBuild(esmConfig), viteBuild(cjsConfig)]); + await Promise.all([viteBuild(esmConfig)]); // Note: Minification is now handled automatically by Vite in production builds // The output files will be minified when config.dev is false diff --git a/scripts/submodule-preloader.ts b/scripts/submodule-preloader.ts index 541363451c1..693ae901333 100644 --- a/scripts/submodule-preloader.ts +++ b/scripts/submodule-preloader.ts @@ -55,8 +55,8 @@ export async function submodulePreloader(config: BuildConfig) { copyPublicDir: false, lib: { entry: join(config.srcQwikDir, 'core/preloader'), - formats: ['es', 'cjs'], - fileName: (format) => (format === 'es' ? 'preloader.mjs' : 'preloader.cjs'), + formats: ['es'], + fileName: () => 'preloader.mjs', }, rollupOptions: { external: ['@qwik.dev/core/build'], diff --git a/scripts/submodule-qwikloader.ts b/scripts/submodule-qwikloader.ts index 9b16aabe473..610bb735e2e 100644 --- a/scripts/submodule-qwikloader.ts +++ b/scripts/submodule-qwikloader.ts @@ -111,11 +111,6 @@ async function generateLoaderSubmodule(config: BuildConfig) { ]; const esmCode = [...code, `export { QWIK_LOADER, QWIK_LOADER_DEBUG };`]; - const cjsCode = [ - ...code, - `exports.QWIK_LOADER = QWIK_LOADER;`, - `exports.QWIK_LOADER_DEBUG = QWIK_LOADER_DEBUG;`, - ]; const dtsCode = [ `export declare const QWIK_LOADER: string;`, `export declare const QWIK_LOADER_DEBUG: string;`, @@ -123,7 +118,6 @@ async function generateLoaderSubmodule(config: BuildConfig) { ensureDir(loaderDistDir); await writeFile(join(loaderDistDir, 'index.mjs'), esmCode.join('\n') + '\n'); - await writeFile(join(loaderDistDir, 'index.cjs'), cjsCode.join('\n') + '\n'); await writeFile(join(loaderDistDir, 'index.d.ts'), dtsCode.join('\n') + '\n'); const loaderPkg: PackageJSON = { diff --git a/scripts/submodule-server.ts b/scripts/submodule-server.ts index c218ffee4c1..76c00b069e8 100644 --- a/scripts/submodule-server.ts +++ b/scripts/submodule-server.ts @@ -3,7 +3,7 @@ import { join } from 'node:path'; import { readPackageJson } from './package-json.ts'; import { inlineQwikScriptsEsBuild } from './submodule-qwikloader.ts'; import { inlineBackpatchScriptsEsBuild } from './submodule-backpatch.ts'; -import { type BuildConfig, getBanner, importPath, nodeTarget, target } from './util.ts'; +import { type BuildConfig, getBanner, importPath, target } from './util.ts'; /** * Builds @qwik.dev/core/server @@ -76,47 +76,13 @@ export async function submoduleServer(config: BuildConfig) { define: { ...(await inlineQwikScriptsEsBuild(config)), ...(await inlineBackpatchScriptsEsBuild(config)), - 'globalThis.IS_CJS': 'false', 'globalThis.IS_ESM': 'true', 'globalThis.QWIK_VERSION': JSON.stringify(config.distVersion), 'globalThis.QWIK_DOM_VERSION': JSON.stringify(qwikDomVersion), }, }); - const cjsBanner = [ - getBanner('@qwik.dev/core/server', config.distVersion), - `globalThis.qwikServer = (function (module) {`, - browserCjsRequireShim, - ].join('\n'); - - const cjs = build({ - ...opts, - format: 'cjs', - banner: { - js: cjsBanner, - }, - footer: { - js: `return module.exports; })(typeof module === 'object' && module.exports ? module : { exports: {} });`, - }, - outExtension: { '.js': '.cjs' }, - plugins: [importPath(/^@qwik\.dev\/core$/, '@qwik.dev/core'), qwikDomPlugin], - target: nodeTarget, - define: { - ...(await inlineQwikScriptsEsBuild(config)), - ...(await inlineBackpatchScriptsEsBuild(config)), - 'globalThis.IS_CJS': 'true', - 'globalThis.IS_ESM': 'false', - 'globalThis.QWIK_VERSION': JSON.stringify(config.distVersion), - 'globalThis.QWIK_DOM_VERSION': JSON.stringify(qwikDomVersion), - // We need to get rid of the import.meta.env values - // Vite's base url - 'import.meta.env.BASE_URL': 'globalThis.BASE_URL', - // Vite's devserver mode - 'import.meta.env.DEV': 'false', - }, - }); - - await Promise.all([esm, cjs]); + await Promise.all([esm]); console.log('🐰', submodule); } @@ -156,26 +122,3 @@ async function getQwikDomVersion(config: BuildConfig) { const pkgJson = await readPackageJson(pkgJsonPath); return pkgJson.version; } - -const browserCjsRequireShim = ` -if (typeof require !== 'function' && typeof location !== 'undefined' && typeof navigator !== 'undefined') { - // shim cjs require() for core.cjs within a browser - globalThis.require = function(path) { - if (path === './core.cjs' || path === '@qwik.dev/core') { - if (!self.qwikCore) { - throw new Error('Qwik Core global, "globalThis.qwikCore", must already be loaded for the Qwik Server to be used within a browser.'); - } - return self.qwikCore; - } - if (path === '@qwik.dev/core/build') { - if (!self.qwikBuild) { - throw new Error('Qwik Build global, "globalThis.qwikBuild", must already be loaded for the Qwik Server to be used within a browser.'); - } - return self.qwikBuild; - } - if (path === '@qwik-client-manifest') { - return {}; - } - throw new Error('Unable to require() path "' + path + '" from a browser environment.'); - }; -}`; diff --git a/scripts/submodule-testing.ts b/scripts/submodule-testing.ts index b92f31c1156..c0fb0045ec0 100644 --- a/scripts/submodule-testing.ts +++ b/scripts/submodule-testing.ts @@ -1,4 +1,4 @@ -import { getBanner, importPath, nodeTarget, target, externalImportNoEffects } from './util.ts'; +import { getBanner, importPath, target, externalImportNoEffects } from './util.ts'; import { build, type BuildOptions } from 'esbuild'; import { type BuildConfig, type PackageJSON } from './util.ts'; import { join } from 'node:path'; @@ -43,28 +43,7 @@ export async function submoduleTesting(config: BuildConfig) { target: 'es2020' /* needed for import.meta */, }); - const cjs = build({ - ...opts, - format: 'cjs', - outExtension: { '.js': '.cjs' }, - banner: { - js: getBanner('@qwik.dev/core/testing', config.distVersion), - }, - plugins: [ - importPath(/^@qwik\.dev\/core$/, '../core.cjs'), - importPath(/^@qwik\.dev\/core\/optimizer$/, '../optimizer.cjs'), - importPath(/^@qwik\.dev\/core\/server$/, '../server.cjs'), - externalImportNoEffects(/^(@qwik\.dev\/core\/build|prettier|vitest)$/), - ], - define: { - 'globalThis.MODULE_EXT': `"cjs"`, - 'globalThis.RUNNER': `false`, - }, - platform: 'node', - target: nodeTarget, - }); - - await Promise.all([esm, cjs]); + await Promise.all([esm]); await generateTestingPackageJson(config); diff --git a/scripts/util.ts b/scripts/util.ts index e6e7d299d4d..1de7a77651d 100644 --- a/scripts/util.ts +++ b/scripts/util.ts @@ -203,7 +203,7 @@ export const getBanner = (moduleName: string, version: string) => { */ export const target = 'es2020'; -export const nodeTarget = 'node16'; +export const nodeTarget = 'es2020'; /** Helper just to know which Node.js modules that should stay external. */ export const nodeBuiltIns = [ diff --git a/scripts/validate-build.ts b/scripts/validate-build.ts index f73e5befdb1..c8570ca8808 100644 --- a/scripts/validate-build.ts +++ b/scripts/validate-build.ts @@ -1,5 +1,4 @@ import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'; -import { createRequire } from 'node:module'; import { basename, extname, join } from 'node:path'; import { pathToFileURL } from 'node:url'; import { rollup } from 'rollup'; @@ -16,7 +15,6 @@ export async function validateBuild(config: BuildConfig) { const pkgPath = join(config.distQwikPkgDir, 'package.json'); const pkg: PackageJSON = JSON.parse(await readFile(pkgPath, 'utf-8')); const errors: string[] = []; - const require = createRequire(import.meta.url); // triple checks these package files all exist and parse const pkgFiles = [...pkg.files!, 'LICENSE', 'README.md', 'package.json']; @@ -42,13 +40,6 @@ export async function validateBuild(config: BuildConfig) { const ext = extname(filePath); switch (ext) { - case '.cjs': - const f = basename(filePath); - if (f !== 'qwik.cjs') { - require(filePath); - console.log(`✅ ${filePath}`); - } - break; case '.mjs': if (config.esmNode) { await import(pathToFileURL(filePath).href); diff --git a/scripts/validate-cli.ts b/scripts/validate-cli.ts index 4cea7f2d0fb..f213688a036 100644 --- a/scripts/validate-cli.ts +++ b/scripts/validate-cli.ts @@ -24,7 +24,7 @@ async function validateCreateQwikCli() { const cliDir = join(__dirname, '..', 'packages', 'create-qwik'); accessSync(cliDir); - const cliBin = join(cliDir, 'create-qwik.cjs'); + const cliBin = join(cliDir, 'create-qwik.mjs'); accessSync(cliBin); const cliPkgJsonPath = join(cliDir, 'package.json'); diff --git a/starters/features/storybook/.storybook/tsconfig.json b/starters/features/storybook/.storybook/tsconfig.json index be5572ac7be..a29b76c66ec 100644 --- a/starters/features/storybook/.storybook/tsconfig.json +++ b/starters/features/storybook/.storybook/tsconfig.json @@ -4,7 +4,6 @@ "experimentalDecorators": true, "emitDecoratorMetadata": true }, - "exclude": [ "../**/*.spec.ts", "../**/*.test.ts", From cf2d43601499e648cd89ba8991516cdac5fd889c Mon Sep 17 00:00:00 2001 From: Jerry_Wu <409187100@qq.com> Date: Mon, 10 Nov 2025 14:52:24 +0800 Subject: [PATCH 3/4] chore: update package.json files to use "module" type and remove globalThis.IS_ESM references --- e2e/docs-e2e/package.json | 2 +- e2e/qwik-cli-e2e/package.json | 3 +- packages/qwik/src/optimizer/src/platform.ts | 51 ++++++++----------- scripts/submodule-optimizer.ts | 1 - scripts/submodule-server.ts | 1 - starters/adapters/aws-lambda/package.json | 3 +- starters/adapters/azure-swa/package.json | 3 +- starters/adapters/bun/package.json | 3 +- starters/adapters/cloud-run/package.json | 3 +- .../adapters/cloudflare-pages/package.json | 3 +- starters/adapters/deno/package.json | 3 +- starters/adapters/express/package.json | 3 +- starters/adapters/fastify/package.json | 3 +- starters/adapters/firebase/package.json | 3 +- starters/adapters/netlify-edge/package.json | 3 +- starters/adapters/node-server/package.json | 3 +- starters/adapters/ssg/package.json | 3 +- starters/adapters/vercel-edge/package.json | 3 +- .../styled-vanilla-extract/package.json | 3 +- 19 files changed, 52 insertions(+), 48 deletions(-) diff --git a/e2e/docs-e2e/package.json b/e2e/docs-e2e/package.json index 8608d47916e..73265761ac4 100644 --- a/e2e/docs-e2e/package.json +++ b/e2e/docs-e2e/package.json @@ -14,5 +14,5 @@ "test": "pnpm exec playwright test --config=playwright.config.ts --project=chromium", "test-ui": "pnpm exec playwright test --config=playwright.config.ts --project=chromium --ui" }, - "type": "commonjs" + "type": "module" } diff --git a/e2e/qwik-cli-e2e/package.json b/e2e/qwik-cli-e2e/package.json index da4cfaf7954..3fbc05e7122 100644 --- a/e2e/qwik-cli-e2e/package.json +++ b/e2e/qwik-cli-e2e/package.json @@ -8,5 +8,6 @@ "scripts": { "e2e": "vitest run --config=vite.config.ts", "e2e.watch": "vitest watch --config=vite.config.ts" - } + }, + "type": "module" } diff --git a/packages/qwik/src/optimizer/src/platform.ts b/packages/qwik/src/optimizer/src/platform.ts index 79ef25842ae..a9250d14bb2 100644 --- a/packages/qwik/src/optimizer/src/platform.ts +++ b/packages/qwik/src/optimizer/src/platform.ts @@ -29,9 +29,7 @@ export async function getSystem() { sys.path = createPath(sys); - if (globalThis.IS_ESM) { - sys.strictDynamicImport = sys.dynamicImport = (path) => import(path); - } + sys.strictDynamicImport = sys.dynamicImport = (path) => import(path); if (sysEnv !== 'webworker' && sysEnv !== 'browsermain') { try { @@ -119,14 +117,10 @@ export async function loadPlatformBinding(sys: OptimizerSystem) { for (const triple of triples) { // Node.js - Native Binding try { - if (globalThis.IS_ESM) { - const module = await sys.dynamicImport('node:module'); - const mod = module.default.createRequire(import.meta.url)( - `../bindings/${triple.platformArchABI}` - ); - return mod; - } - const mod = await sys.dynamicImport(`../bindings/${triple.platformArchABI}`); + const module = await sys.dynamicImport('node:module'); + const mod = module.default.createRequire(import.meta.url)( + `../bindings/${triple.platformArchABI}` + ); return mod; } catch (e) { console.warn( @@ -139,24 +133,22 @@ export async function loadPlatformBinding(sys: OptimizerSystem) { } } - if (globalThis.IS_ESM) { - if (sysEnv === 'node' || sysEnv === 'bun') { - // ESM WASM Node.js - const url: typeof import('url') = await sys.dynamicImport('node:url'); - const __dirname = sys.path.dirname(url.fileURLToPath(import.meta.url)); - const wasmPath = sys.path.join(__dirname, '..', 'bindings', 'qwik_wasm_bg.wasm'); - const mod = await sys.dynamicImport(`../bindings/qwik.wasm.mjs`); - const fs: typeof import('fs') = await sys.dynamicImport('node:fs'); - - const buf = await fs.promises.readFile(wasmPath); - const wasm = await WebAssembly.compile(buf as any); - await mod.default(wasm); - return mod; - } else { - const module = await sys.dynamicImport(`../bindings/qwik.wasm.mjs`); - await module.default(); - return module; - } + if (sysEnv === 'node' || sysEnv === 'bun') { + // ESM WASM Node.js + const url: typeof import('url') = await sys.dynamicImport('node:url'); + const __dirname = sys.path.dirname(url.fileURLToPath(import.meta.url)); + const wasmPath = sys.path.join(__dirname, '..', 'bindings', 'qwik_wasm_bg.wasm'); + const mod = await sys.dynamicImport(`../bindings/qwik.wasm.mjs`); + const fs: typeof import('fs') = await sys.dynamicImport('node:fs'); + + const buf = await fs.promises.readFile(wasmPath); + const wasm = await WebAssembly.compile(buf as any); + await mod.default(wasm); + return mod; + } else { + const module = await sys.dynamicImport(`../bindings/qwik.wasm.mjs`); + await module.default(); + return module; } throw new Error(`Platform not supported`); @@ -218,7 +210,6 @@ const extensions: { [ext: string]: boolean } = { '.mjs': true, }; -declare const globalThis: { IS_ESM: boolean; [key: string]: any }; declare const WorkerGlobalScope: any; declare const Deno: any; declare const Bun: any; diff --git a/scripts/submodule-optimizer.ts b/scripts/submodule-optimizer.ts index ed5f28b3fbf..5e316f84638 100644 --- a/scripts/submodule-optimizer.ts +++ b/scripts/submodule-optimizer.ts @@ -73,7 +73,6 @@ export async function submoduleOptimizer(config: BuildConfig) { }, define: { ...commonConfig.define, - 'globalThis.IS_ESM': 'true', }, }; diff --git a/scripts/submodule-server.ts b/scripts/submodule-server.ts index 76c00b069e8..82d72692de3 100644 --- a/scripts/submodule-server.ts +++ b/scripts/submodule-server.ts @@ -76,7 +76,6 @@ export async function submoduleServer(config: BuildConfig) { define: { ...(await inlineQwikScriptsEsBuild(config)), ...(await inlineBackpatchScriptsEsBuild(config)), - 'globalThis.IS_ESM': 'true', 'globalThis.QWIK_VERSION': JSON.stringify(config.distVersion), 'globalThis.QWIK_DOM_VERSION': JSON.stringify(qwikDomVersion), }, diff --git a/starters/adapters/aws-lambda/package.json b/starters/adapters/aws-lambda/package.json index 3549d30dd92..eb18ff0c357 100755 --- a/starters/adapters/aws-lambda/package.json +++ b/starters/adapters/aws-lambda/package.json @@ -19,5 +19,6 @@ "https://aws.amazon.com/es/lambda/", "https://www.serverless.com/cloud/docs/get-started" ] - } + }, + "type": "module" } diff --git a/starters/adapters/azure-swa/package.json b/starters/adapters/azure-swa/package.json index 9fbe555e229..0f768ce220a 100644 --- a/starters/adapters/azure-swa/package.json +++ b/starters/adapters/azure-swa/package.json @@ -24,5 +24,6 @@ "- pnpm run deploy: it will use the SWA CLI to deploy your site" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/bun/package.json b/starters/adapters/bun/package.json index 118eb8a04ef..bd70a8dd1da 100644 --- a/starters/adapters/bun/package.json +++ b/starters/adapters/bun/package.json @@ -23,5 +23,6 @@ }, "devDependencies": { "@types/bun": "*" - } + }, + "type": "module" } diff --git a/starters/adapters/cloud-run/package.json b/starters/adapters/cloud-run/package.json index caef0f535ba..9e507e2e1c2 100644 --- a/starters/adapters/cloud-run/package.json +++ b/starters/adapters/cloud-run/package.json @@ -20,5 +20,6 @@ "- pnpm run deploy: it will use the gcloud CLI to deploy your site" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/cloudflare-pages/package.json b/starters/adapters/cloudflare-pages/package.json index 7a8c5e8ca29..57433767ad4 100644 --- a/starters/adapters/cloudflare-pages/package.json +++ b/starters/adapters/cloudflare-pages/package.json @@ -24,5 +24,6 @@ "- pnpm run deploy: it will use the Cloudflare CLI to deploy your site" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/deno/package.json b/starters/adapters/deno/package.json index b572cfa3181..6144f480924 100644 --- a/starters/adapters/deno/package.json +++ b/starters/adapters/deno/package.json @@ -20,5 +20,6 @@ "- pnpm run serve: runs the production server locally" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/express/package.json b/starters/adapters/express/package.json index 564e917f520..5065a0c9707 100644 --- a/starters/adapters/express/package.json +++ b/starters/adapters/express/package.json @@ -29,5 +29,6 @@ "- pnpm run serve: runs the production server locally" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/fastify/package.json b/starters/adapters/fastify/package.json index 6e97e6da402..46b78e5bd81 100644 --- a/starters/adapters/fastify/package.json +++ b/starters/adapters/fastify/package.json @@ -29,5 +29,6 @@ "- pnpm run serve: runs the production server locally" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/firebase/package.json b/starters/adapters/firebase/package.json index fa02884a257..7b5793255f9 100644 --- a/starters/adapters/firebase/package.json +++ b/starters/adapters/firebase/package.json @@ -20,5 +20,6 @@ "- cd functions && pnpm i" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/netlify-edge/package.json b/starters/adapters/netlify-edge/package.json index 2febbffebcf..3a29cc8428f 100644 --- a/starters/adapters/netlify-edge/package.json +++ b/starters/adapters/netlify-edge/package.json @@ -25,5 +25,6 @@ "- pnpm run deploy: it will use the netlify CLI to deploy your site" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/node-server/package.json b/starters/adapters/node-server/package.json index 2b97a3a85a9..8db70eb06e0 100644 --- a/starters/adapters/node-server/package.json +++ b/starters/adapters/node-server/package.json @@ -19,5 +19,6 @@ "- pnpm run serve: runs the production server locally" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/ssg/package.json b/starters/adapters/ssg/package.json index 7c266129e9d..e1994c8ca79 100644 --- a/starters/adapters/ssg/package.json +++ b/starters/adapters/ssg/package.json @@ -15,5 +15,6 @@ "inside './adapters/ssg/vite.config.ts'" ] } - } + }, + "type": "module" } diff --git a/starters/adapters/vercel-edge/package.json b/starters/adapters/vercel-edge/package.json index fbf007e12fc..f8f9f44673b 100644 --- a/starters/adapters/vercel-edge/package.json +++ b/starters/adapters/vercel-edge/package.json @@ -24,5 +24,6 @@ "- pnpm run deploy: it will use the Vercel CLI to deploy your site" ] } - } + }, + "type": "module" } diff --git a/starters/features/styled-vanilla-extract/package.json b/starters/features/styled-vanilla-extract/package.json index 46723648ebf..559f4738285 100644 --- a/starters/features/styled-vanilla-extract/package.json +++ b/starters/features/styled-vanilla-extract/package.json @@ -26,5 +26,6 @@ "@vanilla-extract/css": "^1.12.0", "styled-vanilla-extract": "^0.5.4", "@vanilla-extract/vite-plugin": "^5.0.1" - } + }, + "type": "module" } From fe3fbb6910a542d873802d767fea1bdb6b2788e7 Mon Sep 17 00:00:00 2001 From: Jerry_Wu <409187100@qq.com> Date: Mon, 10 Nov 2025 15:25:17 +0800 Subject: [PATCH 4/4] chore: minimum node version for TS support --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 50578ba2b10..1bbbbfc5d62 100644 --- a/package.json +++ b/package.json @@ -164,7 +164,7 @@ "zod": "3.25.48" }, "engines": { - "node": "^18.17.0 || ^20.3.0 || >=21.0.0", + "node": ">=22.18.0", "npm": "please-use-pnpm", "yarn": "please-use-pnpm", "pnpm": ">=10.14.0"