diff --git a/packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.outside-pkg-import.mts b/packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.outside-pkg-import.mts deleted file mode 100644 index 401aadce8bf803..00000000000000 --- a/packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.outside-pkg-import.mts +++ /dev/null @@ -1,5 +0,0 @@ -import parent from 'parent' - -export default { - __injected: parent.child, -} diff --git a/packages/vite/src/node/__tests__/fixtures/inline-import/basic.ts b/packages/vite/src/node/__tests__/fixtures/runner-import/basic.ts similarity index 100% rename from packages/vite/src/node/__tests__/fixtures/inline-import/basic.ts rename to packages/vite/src/node/__tests__/fixtures/runner-import/basic.ts diff --git a/packages/vite/src/node/__tests__/fixtures/inline-import/cjs.js b/packages/vite/src/node/__tests__/fixtures/runner-import/cjs.js similarity index 100% rename from packages/vite/src/node/__tests__/fixtures/inline-import/cjs.js rename to packages/vite/src/node/__tests__/fixtures/runner-import/cjs.js diff --git a/packages/vite/src/node/__tests__/fixtures/inline-import/plugin.ts b/packages/vite/src/node/__tests__/fixtures/runner-import/plugin.ts similarity index 100% rename from packages/vite/src/node/__tests__/fixtures/inline-import/plugin.ts rename to packages/vite/src/node/__tests__/fixtures/runner-import/plugin.ts diff --git a/packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.outside-pkg-import.mts b/packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.outside-pkg-import.mts new file mode 100644 index 00000000000000..21bff5f0bf9a93 --- /dev/null +++ b/packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.outside-pkg-import.mts @@ -0,0 +1,6 @@ +// @ts-expect-error not typed +import parent from '@vitejs/parent' + +export default { + __injected: parent.child, +} diff --git a/packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.ts b/packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.ts similarity index 100% rename from packages/vite/src/node/__tests__/fixtures/inline-import/vite.config.ts rename to packages/vite/src/node/__tests__/fixtures/runner-import/vite.config.ts diff --git a/packages/vite/src/node/__tests__/package.json b/packages/vite/src/node/__tests__/package.json index 605363e5411c6a..4f6f029f385542 100644 --- a/packages/vite/src/node/__tests__/package.json +++ b/packages/vite/src/node/__tests__/package.json @@ -3,7 +3,7 @@ "private": true, "version": "0.0.0", "dependencies": { - "parent": "link:./packages/parent", + "@vitejs/parent": "link:./packages/parent", "@vitejs/cjs-ssr-dep": "link:./fixtures/cjs-ssr-dep", "@vitejs/test-dep-conditions": "file:./fixtures/test-dep-conditions" } diff --git a/packages/vite/src/node/__tests__/packages/child/package.json b/packages/vite/src/node/__tests__/packages/child/package.json index ea0965b5b6d53d..77e2aa64615b63 100644 --- a/packages/vite/src/node/__tests__/packages/child/package.json +++ b/packages/vite/src/node/__tests__/packages/child/package.json @@ -1,5 +1,5 @@ { - "name": "child", + "name": "@vitejs/child", "type": "module", "main": "./index.js" } diff --git a/packages/vite/src/node/__tests__/packages/parent/index.ts b/packages/vite/src/node/__tests__/packages/parent/index.ts index 0a8feb5e9b1992..747305283cadb2 100644 --- a/packages/vite/src/node/__tests__/packages/parent/index.ts +++ b/packages/vite/src/node/__tests__/packages/parent/index.ts @@ -1,5 +1,5 @@ // @ts-expect-error not typed -import child from 'child' +import child from '@vitejs/child' export default { child, diff --git a/packages/vite/src/node/__tests__/packages/parent/package.json b/packages/vite/src/node/__tests__/packages/parent/package.json index bbb7f8414e4a55..d966448a0560a8 100644 --- a/packages/vite/src/node/__tests__/packages/parent/package.json +++ b/packages/vite/src/node/__tests__/packages/parent/package.json @@ -1,8 +1,8 @@ { - "name": "parent", + "name": "@vitejs/parent", "type": "module", "main": "./index.ts", "dependencies": { - "child": "link:../child" + "@vitejs/child": "link:../child" } } diff --git a/packages/vite/src/node/__tests__/inlineImport.spec.ts b/packages/vite/src/node/__tests__/runnerImport.spec.ts similarity index 72% rename from packages/vite/src/node/__tests__/inlineImport.spec.ts rename to packages/vite/src/node/__tests__/runnerImport.spec.ts index b876c9debdda09..b847d6e2d871f2 100644 --- a/packages/vite/src/node/__tests__/inlineImport.spec.ts +++ b/packages/vite/src/node/__tests__/runnerImport.spec.ts @@ -1,16 +1,16 @@ import { resolve } from 'node:path' import { describe, expect, test } from 'vitest' import { loadConfigFromFile } from 'vite' -import { inlineImport } from '../ssr/inlineImport' +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/inline-import', name) + resolve(import.meta.dirname, './fixtures/runner-import', name) test('importing a basic file works', async () => { - const { module } = await inlineImport< - typeof import('./fixtures/inline-import/basic') + const { module } = await runnerImport< + typeof import('./fixtures/runner-import/basic') >(fixture('basic')) expect(module.test).toEqual({ field: true, @@ -19,15 +19,15 @@ describe('importing files using inlined environment', () => { test("cannot import cjs, 'inlineImport' doesn't support CJS syntax at all", async () => { await expect(() => - inlineImport( + runnerImport( fixture('cjs.js'), ), ).rejects.toThrow('module is not defined') }) test('can import vite config', async () => { - const { module, dependencies } = await inlineImport< - typeof import('./fixtures/inline-import/vite.config') + const { module, dependencies } = await runnerImport< + typeof import('./fixtures/runner-import/vite.config') >(fixture('vite.config')) expect(module.default).toEqual({ root: './test', @@ -41,8 +41,8 @@ describe('importing files using inlined environment', () => { }) test('can import vite config that imports a TS external module', async () => { - const { module, dependencies } = await inlineImport< - typeof import('./fixtures/inline-import/vite.config.outside-pkg-import.mjs') + 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) @@ -52,7 +52,7 @@ describe('importing files using inlined environment', () => { // confirm that it fails with a bundle approach await expect(async () => { - const root = resolve(import.meta.dirname, './fixtures/inline-import') + const root = resolve(import.meta.dirname, './fixtures/runner-import') await loadConfigFromFile( { mode: 'production', command: 'serve' }, resolve(root, './vite.config.outside-pkg-import.mts'), diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index ae3b2608259807..228f36b6426ab6 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -98,7 +98,7 @@ import type { ResolvedSSROptions, SSROptions } from './ssr' import { resolveSSROptions, ssrConfigDefaults } from './ssr' import { PartialEnvironment } from './baseEnvironment' import { createIdResolver } from './idResolver' -import { inlineImport } from './ssr/inlineImport' +import { runnerImport } from './ssr/runnerImport' const debug = createDebugger('vite:config', { depth: 10 }) const promisifiedRealpath = promisify(fs.realpath) @@ -1707,7 +1707,7 @@ export async function loadConfigFromFile( } async function importConfigFile(resolvedPath: string) { - const { module, dependencies } = await inlineImport<{ + const { module, dependencies } = await runnerImport<{ default: UserConfigExport }>(resolvedPath) return { diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index 6f9b7d240766db..4e74ee6ed45638 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -31,7 +31,7 @@ export { DevEnvironment, type DevEnvironmentContext, } from './server/environment' -export { inlineImport } from './ssr/inlineImport' +export { runnerImport as inlineImport } from './ssr/runnerImport' export { BuildEnvironment } from './build' export { fetchModule, type FetchModuleOptions } from './ssr/fetchModule' diff --git a/packages/vite/src/node/ssr/inlineImport.ts b/packages/vite/src/node/ssr/runnerImport.ts similarity index 97% rename from packages/vite/src/node/ssr/inlineImport.ts rename to packages/vite/src/node/ssr/runnerImport.ts index 3099c09c92dc56..a8267f6abd7655 100644 --- a/packages/vite/src/node/ssr/inlineImport.ts +++ b/packages/vite/src/node/ssr/runnerImport.ts @@ -12,7 +12,7 @@ interface InlineImportResult { * Import any file using the default Vite environment. * @experimental */ -export async function inlineImport( +export async function runnerImport( moduleId: string, inlineConfig?: InlineConfig, ): Promise> { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4258a658d38cac..683ca86bee4d62 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -417,12 +417,12 @@ importers: '@vitejs/cjs-ssr-dep': specifier: link:./fixtures/cjs-ssr-dep version: link:fixtures/cjs-ssr-dep + '@vitejs/parent': + specifier: link:./packages/parent + version: link:packages/parent '@vitejs/test-dep-conditions': specifier: file:./fixtures/test-dep-conditions version: file:packages/vite/src/node/__tests__/fixtures/test-dep-conditions - parent: - specifier: link:./packages/parent - version: link:packages/parent packages/vite/src/node/__tests__/fixtures/cjs-ssr-dep: {} @@ -440,7 +440,7 @@ importers: packages/vite/src/node/__tests__/packages/parent: dependencies: - child: + '@vitejs/child': specifier: link:../child version: link:../child