diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index 3f965e99735..548d5d13c6d 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -908,7 +908,7 @@ function importSourceToScope( resolved = resolveExt(filename, fs) } else { // module or aliased import - use full TS resolution, only supported in Node - if (!__NODE_JS__) { + if (!__CJS__) { return ctx.error( `Type import from non-relative sources is not supported in the browser build.`, node, @@ -975,7 +975,7 @@ function resolveWithTS( ts: typeof TS, fs: FS, ): string | undefined { - if (!__NODE_JS__) return + if (!__CJS__) return // 1. resolve tsconfig.json const configPath = ts.findConfigFile(containingFile, fs.fileExists) diff --git a/packages/global.d.ts b/packages/global.d.ts index 1367b69cd5b..704f6d0220d 100644 --- a/packages/global.d.ts +++ b/packages/global.d.ts @@ -7,7 +7,7 @@ declare var __BROWSER__: boolean declare var __GLOBAL__: boolean declare var __ESM_BUNDLER__: boolean declare var __ESM_BROWSER__: boolean -declare var __NODE_JS__: boolean +declare var __CJS__: boolean declare var __SSR__: boolean declare var __COMMIT__: string declare var __VERSION__: string diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 13345b78a45..7d9bd102fb3 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -150,7 +150,7 @@ import { ErrorTypeStrings as _ErrorTypeStrings } from './errorHandling' * @internal */ export const ErrorTypeStrings = ( - __ESM_BUNDLER__ || __NODE_JS__ || __DEV__ ? _ErrorTypeStrings : null + __ESM_BUNDLER__ || __CJS__ || __DEV__ ? _ErrorTypeStrings : null ) as typeof _ErrorTypeStrings // For devtools diff --git a/packages/server-renderer/src/helpers/ssrCompile.ts b/packages/server-renderer/src/helpers/ssrCompile.ts index 6ab296976ac..8412a65e843 100644 --- a/packages/server-renderer/src/helpers/ssrCompile.ts +++ b/packages/server-renderer/src/helpers/ssrCompile.ts @@ -24,7 +24,7 @@ export function ssrCompile( instance: ComponentInternalInstance, ): SSRRenderFunction { // TODO: this branch should now work in ESM builds, enable it in a minor - if (!__NODE_JS__) { + if (!__CJS__) { throw new Error( `On-the-fly template compilation is not supported in the ESM build of ` + `@vue/server-renderer. All templates must be pre-compiled into ` + diff --git a/packages/server-renderer/src/renderToStream.ts b/packages/server-renderer/src/renderToStream.ts index 828e385cb90..60b277a4a9b 100644 --- a/packages/server-renderer/src/renderToStream.ts +++ b/packages/server-renderer/src/renderToStream.ts @@ -108,7 +108,7 @@ export function renderToNodeStream( input: App | VNode, context: SSRContext = {}, ): Readable { - const stream: Readable = __NODE_JS__ + const stream: Readable = __CJS__ ? new (require('node:stream').Readable)({ read() {} }) : null diff --git a/rollup.config.js b/rollup.config.js index b6a098fa69e..657b711b1a3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -122,7 +122,7 @@ function createConfig(format, output, plugins = []) { const isBundlerESMBuild = /esm-bundler/.test(format) const isBrowserESMBuild = /esm-browser/.test(format) const isServerRenderer = name === 'server-renderer' - const isNodeBuild = format === 'cjs' + const isCJSBuild = format === 'cjs' const isGlobalBuild = /global/.test(format) const isCompatPackage = pkg.name === '@vue/compat' || pkg.name === '@vue/compat-canary' @@ -138,7 +138,7 @@ function createConfig(format, output, plugins = []) { **/` output.exports = isCompatPackage ? 'auto' : 'named' - if (isNodeBuild) { + if (isCJSBuild) { output.esModule = true } output.sourcemap = !!process.env.SOURCE_MAP @@ -172,9 +172,9 @@ function createConfig(format, output, plugins = []) { __ESM_BUNDLER__: String(isBundlerESMBuild), __ESM_BROWSER__: String(isBrowserESMBuild), // is targeting Node (SSR)? - __NODE_JS__: String(isNodeBuild), + __CJS__: String(isCJSBuild), // need SSR-specific branches? - __SSR__: String(isNodeBuild || isBundlerESMBuild || isServerRenderer), + __SSR__: String(isCJSBuild || isBundlerESMBuild || isServerRenderer), // 2.x compat build __COMPAT__: String(isCompatBuild), @@ -329,7 +329,7 @@ function createConfig(format, output, plugins = []) { tsconfig: path.resolve(__dirname, 'tsconfig.json'), sourceMap: output.sourcemap, minify: false, - target: isServerRenderer || isNodeBuild ? 'es2019' : 'es2015', + target: isServerRenderer || isCJSBuild ? 'es2019' : 'es2015', define: resolveDefine(), }), ...resolveNodePlugins(), diff --git a/scripts/dev.js b/scripts/dev.js index 2c3cdaf95e2..b015835ab4f 100644 --- a/scripts/dev.js +++ b/scripts/dev.js @@ -119,7 +119,7 @@ esbuild __GLOBAL__: String(format === 'global'), __ESM_BUNDLER__: String(format.includes('esm-bundler')), __ESM_BROWSER__: String(format.includes('esm-browser')), - __NODE_JS__: String(format === 'cjs'), + __CJS__: String(format === 'cjs'), __SSR__: String(format === 'cjs' || format.includes('esm-bundler')), __COMPAT__: String(target === 'vue-compat'), __FEATURE_SUSPENSE__: `true`, diff --git a/vitest.config.ts b/vitest.config.ts index 6b5b93a45f9..e6436408adb 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -11,7 +11,7 @@ export default defineConfig({ __GLOBAL__: false, __ESM_BUNDLER__: true, __ESM_BROWSER__: false, - __NODE_JS__: true, + __CJS__: true, __SSR__: true, __FEATURE_OPTIONS_API__: true, __FEATURE_SUSPENSE__: true,