Skip to content

Commit

Permalink
chore(build): rename __NODE_JS__ build flag to __CJS__
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 11, 2024
1 parent 8fda856 commit bceccf9
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/compiler-sfc/src/script/resolveType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/server-renderer/src/helpers/ssrCompile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ` +
Expand Down
2 changes: 1 addition & 1 deletion packages/server-renderer/src/renderToStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion scripts/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bceccf9

Please sign in to comment.