Skip to content

Commit

Permalink
fix(config): support builtin modules and deno (#10457)
Browse files Browse the repository at this point in the history
* fix(config): skip resolve builtin modules (#10420)

* fix(config): partial deno support (#10446)
  • Loading branch information
bluwy authored Oct 13, 2022
1 parent 94abccc commit 8fbae69
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
11 changes: 6 additions & 5 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
createDebugger,
createFilter,
dynamicImport,
isBuiltin,
isExternalUrl,
isObject,
lookupFile,
Expand Down Expand Up @@ -972,7 +973,11 @@ async function bundleConfigFile(

build.onResolve({ filter: /.*/ }, ({ path: id, importer, kind }) => {
// externalize bare imports
if (id[0] !== '.' && !isAbsolute(id)) {
if (id[0] !== '.' && !path.isAbsolute(id) && !isBuiltin(id)) {
// partial deno support as `npm:` does not work in `tryNodeResolve`
if (id.startsWith('npm:')) {
return { external: true }
}
let idFsPath = tryNodeResolve(id, importer, options, false)?.id
if (idFsPath && (isESM || kind === 'dynamic-import')) {
idFsPath = pathToFileURL(idFsPath).href
Expand Down Expand Up @@ -1103,7 +1108,3 @@ export function isDepsOptimizerEnabled(
(command === 'serve' && disabled === 'dev')
)
}

function isAbsolute(id: string) {
return path.isAbsolute(id) || path.posix.isAbsolute(id)
}
3 changes: 3 additions & 0 deletions playground/cli-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"build": "vite build",
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
"serve": "vite preview"
},
"devDependencies": {
"url": "^0.11.0"
}
}
6 changes: 6 additions & 0 deletions playground/cli-module/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// eslint-disable-next-line import/no-nodejs-modules
import { URL } from 'url'
import { defineConfig } from 'vite'

// make sure bundling works even if `url` refers to the locally installed
// `url` package instead of the built-in `url` nodejs module
globalThis.__test_url = URL

export default defineConfig({
server: {
host: 'localhost'
Expand Down
12 changes: 6 additions & 6 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 8fbae69

Please sign in to comment.