-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(import-analysis): preserve importedUrls import order (#14465)
- Loading branch information
Showing
8 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { expect, test } from 'vitest' | ||
import { isServe, page, viteServer } from '~utils' | ||
|
||
test.runIf(isServe)('importedUrls order is preserved', async () => { | ||
const el = page.locator('.imported-urls-order') | ||
expect(await el.textContent()).toBe('[success]') | ||
const mod = await viteServer.moduleGraph.getModuleByUrl( | ||
'/imported-urls-order.js', | ||
) | ||
const importedModuleIds = [...mod.importedModules].map((m) => m.url) | ||
expect(importedModuleIds).toEqual(['\x00virtual:slow-module', '/empty.js']) | ||
}) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { msg } from 'virtual:slow-module' | ||
import './empty.js' | ||
|
||
export default msg | ||
|
||
// This module tests that the import order is preserved in this module's `importedUrls` property | ||
// as the imports can be processed in parallel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<div class="imported-urls-order"></div> | ||
|
||
<script type="module"> | ||
import importedUrlsOrderSuccess from './imported-urls-order' | ||
text('.imported-urls-order', importedUrlsOrderSuccess) | ||
|
||
function text(el, text) { | ||
document.querySelector(el).textContent = text | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "@vitejs/test-hmr", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../packages/vite/bin/vite", | ||
"preview": "vite preview" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { defineConfig } from 'vite' | ||
import type { Plugin } from 'vite' | ||
|
||
export default defineConfig({ | ||
plugins: [slowModulePlugin()], | ||
}) | ||
|
||
function slowModulePlugin(): Plugin { | ||
return { | ||
name: 'slow-module', | ||
resolveId(id) { | ||
if (id === 'virtual:slow-module') { | ||
return '\0virtual:slow-module' | ||
} | ||
}, | ||
async load(id) { | ||
if (id === '\0virtual:slow-module') { | ||
await new Promise((resolve) => setTimeout(resolve, 500)) | ||
return `export const msg = '[success]'` | ||
} | ||
}, | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.