Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: prebundle dep with colon (#7006)
  • Loading branch information
bluwy committed Feb 20, 2022
1 parent 983feb2 commit 2136f2b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
Expand Up @@ -87,3 +87,7 @@ test('import from hidden dir', async () => {
test('import optimize-excluded package that imports optimized-included package', async () => {
expect(await page.textContent('.nested-include')).toBe('nested-include')
})

test('import aliased package with colon', async () => {
expect(await page.textContent('.url')).toBe('vitejs.dev')
})
6 changes: 6 additions & 0 deletions packages/playground/optimize-deps/index.html
Expand Up @@ -53,6 +53,9 @@ <h2>Dep from hidden dir</h2>
<h2>Nested include</h2>
<div>Module path: <span class="nested-include"></span></div>

<h2>Alias with colon</h2>
<div>URL: <span class="url"></span></div>

<script type="module">
// test dep detection in globbed files
const globbed = import.meta.globEager('./glob/*.js')
Expand Down Expand Up @@ -85,6 +88,9 @@ <h2>Nested include</h2>
import { nestedInclude } from 'nested-exclude'
text('.nested-include', nestedInclude)

import { parse } from 'node:url'
text('.url', parse('https://vitejs.dev').hostname)

function text(el, text) {
document.querySelector(el).textContent = text
}
Expand Down
1 change: 1 addition & 0 deletions packages/playground/optimize-deps/package.json
Expand Up @@ -23,6 +23,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"resolve-linked": "workspace:0.0.0",
"url": "^0.11.0",
"vue": "^3.2.25",
"vuex": "^4.0.0"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/playground/optimize-deps/vite.config.js
Expand Up @@ -5,7 +5,10 @@ const vue = require('@vitejs/plugin-vue')
*/
module.exports = {
resolve: {
dedupe: ['react']
dedupe: ['react'],
alias: {
'node:url': 'url'
}
},

optimizeDeps: {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/utils.ts
Expand Up @@ -33,7 +33,7 @@ export function unwrapId(id: string): string {
}

export const flattenId = (id: string): string =>
id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.]/g, '_')
id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.:]/g, '_')

export const normalizeId = (id: string): string =>
id.replace(/(\s*>\s*)/g, ' > ')
Expand Down
19 changes: 19 additions & 0 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 2136f2b

Please sign in to comment.