-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
feat: use module runner to import the config #18637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
patak-cat
merged 29 commits into
vitejs:main
from
sheremet-va:feat/use-runner-to-import
Jan 23, 2025
Merged
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
547d1c7
feat: use module runner to import the config
sheremet-va 2454b66
chore: todo
sheremet-va 1cf3da7
chore: merge
sheremet-va df1efe3
chore: use RunnableDevEnvironment instead
sheremet-va e55e083
chore: make it run faster in tests
sheremet-va c9e908e
fix: support cjs globals in default modules evaluator
sheremet-va b4c41d3
feat: add `--bundleConfig` flag to opt-out of bundling
sheremet-va 7c5dcf0
chore: remove cjs support
sheremet-va aad578d
chore: cleanup
sheremet-va d8f8771
test: add tests for inlineImport
sheremet-va 0d16f85
chore: update public cjs export
sheremet-va f295303
refactor: rename bundleConfig to configLoader
sheremet-va d453876
test: fix windows pathing
sheremet-va 65578af
fix: rename the option in the cli config
sheremet-va df7d928
docs: add a note to docs
sheremet-va 001f7e9
docs: rename the heading
sheremet-va 1adc486
fix: revert isModuleSyncConditionEnabled, fix types
sheremet-va 5ecd529
test: add comment for moduleDirectories
sheremet-va 275a593
test: add workspace test
sheremet-va b383651
refactor: mark configLoader as experimental
sheremet-va 14571ac
perf: disable config, envFile and cacheDir
sheremet-va d847961
chore: remove unused directive
sheremet-va 07867ae
chore: rename to runnerImport, rename test packages
sheremet-va 646a069
lint: remove unesed ts-expect-error
sheremet-va 9b2179a
fix: update other names
bluwy 8669489
refactor: move configLoader validation
sheremet-va 19c5019
test: dynamic import
hi-ogawa e06731d
Merge branch 'main' into pr/sheremet-va/18637
bluwy a960fd4
Merge branch 'main' into feat/use-runner-to-import
patak-cat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/runner-import/basic.ts
This file contains hidden or 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 @@ | ||
| interface Test { | ||
| field: true | ||
| } | ||
|
|
||
| export const test: Test = { | ||
| field: true, | ||
| } |
This file contains hidden or 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 @@ | ||
| module.exports = {} |
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/runner-import/plugin.ts
This file contains hidden or 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 { Plugin } from 'vite' | ||
|
|
||
| export default function testPlugin(): Plugin { | ||
| return { | ||
| name: 'test', | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.outside-pkg-import.mts
This file contains hidden or 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,5 @@ | ||
| import parent from '@vitejs/parent' | ||
|
|
||
| export default { | ||
| __injected: parent.child, | ||
| } |
7 changes: 7 additions & 0 deletions
7
packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.ts
This file contains hidden or 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 { defineConfig } from 'vite' | ||
| import plugin from './plugin' | ||
|
|
||
| export default defineConfig({ | ||
| root: './test', | ||
| plugins: [plugin()], | ||
| }) |
This file contains hidden or 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 hidden or 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 @@ | ||
| export default true |
This file contains hidden or 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,5 @@ | ||
| { | ||
| "name": "@vitejs/child", | ||
| "type": "module", | ||
| "main": "./index.js" | ||
| } |
This file contains hidden or 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,6 @@ | ||
| // @ts-expect-error not typed | ||
| import child from '@vitejs/child' | ||
|
|
||
| export default { | ||
| child, | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/vite/src/node/__tests__/packages/parent/package.json
This file contains hidden or 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,8 @@ | ||
| { | ||
| "name": "@vitejs/parent", | ||
| "type": "module", | ||
| "main": "./index.ts", | ||
| "dependencies": { | ||
| "@vitejs/child": "link:../child" | ||
| } | ||
| } |
This file contains hidden or 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,64 @@ | ||
| import { resolve } from 'node:path' | ||
| import { describe, expect, test } from 'vitest' | ||
| import { loadConfigFromFile } from 'vite' | ||
| import { runnerImport } from '../ssr/runnerImport' | ||
| import { slash } from '../../shared/utils' | ||
|
|
||
| describe('importing files using inlined environment', () => { | ||
| const fixture = (name: string) => | ||
| resolve(import.meta.dirname, './fixtures/runner-import', name) | ||
|
|
||
| test('importing a basic file works', async () => { | ||
| const { module } = await runnerImport< | ||
| typeof import('./fixtures/runner-import/basic') | ||
| >(fixture('basic')) | ||
| expect(module.test).toEqual({ | ||
| field: true, | ||
| }) | ||
| }) | ||
|
|
||
| test("cannot import cjs, 'runnerImport' doesn't support CJS syntax at all", async () => { | ||
| await expect(() => | ||
| runnerImport<typeof import('./fixtures/runner-import/basic')>( | ||
| fixture('cjs.js'), | ||
| ), | ||
| ).rejects.toThrow('module is not defined') | ||
| }) | ||
|
|
||
| test('can import vite config', async () => { | ||
| const { module, dependencies } = await runnerImport< | ||
| typeof import('./fixtures/runner-import/vite.config') | ||
| >(fixture('vite.config')) | ||
| expect(module.default).toEqual({ | ||
| root: './test', | ||
| plugins: [ | ||
| { | ||
| name: 'test', | ||
| }, | ||
| ], | ||
| }) | ||
| expect(dependencies).toEqual([slash(fixture('plugin.ts'))]) | ||
| }) | ||
|
|
||
| test('can import vite config that imports a TS external module', async () => { | ||
| const { module, dependencies } = await runnerImport< | ||
| typeof import('./fixtures/runner-import/vite.config.outside-pkg-import.mjs') | ||
| >(fixture('vite.config.outside-pkg-import.mts')) | ||
|
|
||
| expect(module.default.__injected).toBe(true) | ||
| expect(dependencies).toEqual([ | ||
| slash(resolve(import.meta.dirname, './packages/parent/index.ts')), | ||
| ]) | ||
|
|
||
| // confirm that it fails with a bundle approach | ||
| await expect(async () => { | ||
| const root = resolve(import.meta.dirname, './fixtures/runner-import') | ||
| await loadConfigFromFile( | ||
| { mode: 'production', command: 'serve' }, | ||
| resolve(root, './vite.config.outside-pkg-import.mts'), | ||
| root, | ||
| 'silent', | ||
| ) | ||
| }).rejects.toThrow('Unknown file extension ".ts"') | ||
| }) | ||
| }) |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to flag this experimental? I guess it's fine not to, but just to confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can mark it as experimental since the environment API is experimental 😄
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marked it like this: