Skip to content

Commit

Permalink
chore: rename to runnerImport, rename test packages
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed Dec 4, 2024
1 parent d847961 commit 07867ae
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 28 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @ts-expect-error not typed
import parent from '@vitejs/parent'

export default {
__injected: parent.child,
}
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "child",
"name": "@vitejs/child",
"type": "module",
"main": "./index.js"
}
2 changes: 1 addition & 1 deletion packages/vite/src/node/__tests__/packages/parent/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// @ts-expect-error not typed
import child from 'child'
import child from '@vitejs/child'

export default {
child,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/__tests__/packages/parent/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "parent",
"name": "@vitejs/parent",
"type": "module",
"main": "./index.ts",
"dependencies": {
"child": "link:../child"
"@vitejs/child": "link:../child"
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<typeof import('./fixtures/inline-import/basic')>(
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 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',
Expand All @@ -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)
Expand All @@ -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'),
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface InlineImportResult<T> {
* Import any file using the default Vite environment.
* @experimental
*/
export async function inlineImport<T>(
export async function runnerImport<T>(
moduleId: string,
inlineConfig?: InlineConfig,
): Promise<InlineImportResult<T>> {
Expand Down
8 changes: 4 additions & 4 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 07867ae

Please sign in to comment.