Skip to content

Commit

Permalink
fix: isBuiltin using patched native builtinModules (#5827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Niputi authored Nov 27, 2021
1 parent 19d2b6a commit 4a05a6e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 0 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"acorn": "^8.6.0",
"acorn-class-fields": "^1.0.0",
"acorn-static-class-features": "^1.0.0",
"builtin-modules": "^3.2.0",
"cac": "6.7.9",
"chalk": "^4.1.2",
"chokidar": "^3.5.2",
Expand Down
24 changes: 20 additions & 4 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
ENV_PUBLIC_PATH
} from './constants'
import resolve from 'resolve'
import builtins from 'builtin-modules'
import { builtinModules } from 'module'
import { FSWatcher } from 'chokidar'
import remapping from '@ampproject/remapping'
import {
Expand All @@ -37,10 +37,26 @@ export const flattenId = (id: string): string =>
export const normalizeId = (id: string): string =>
id.replace(/(\s*>\s*)/g, ' > ')

//TODO: revisit later to see if the edge case that "compiling using node v12 code to be run in node v16 in the server" is what we intend to support.
const builtins = new Set([
...builtinModules,
'assert/strict',
'diagnostics_channel',
'dns/promises',
'fs/promises',
'path/posix',
'path/win32',
'readline/promises',
'stream/consumers',
'stream/promises',
'stream/web',
'timers/promises',
'util/types',
'wasi'
])

export function isBuiltin(id: string): boolean {
const deepMatch = id.match(deepImportRE)
id = deepMatch ? deepMatch[1] || deepMatch[2] : id
return builtins.includes(id)
return builtins.has(id.replace(/^node:/, ''))
}

export function moduleListContains(
Expand Down
2 changes: 0 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a05a6e

Please sign in to comment.