Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
"#module-sync-enabled": {
"module-sync": "./misc/true.js",
"default": "./misc/false.js"
}
},
"#types/*": "./types/*.d.ts",
"#dep-types/*": "./src/types/*.d.ts"
},
"files": [
"bin",
Expand Down Expand Up @@ -113,7 +115,6 @@
"cors": "^2.8.5",
"cross-spawn": "^7.0.6",
"debug": "^4.4.3",
"dep-types": "link:./src/types",
"dotenv": "^17.2.3",
"dotenv-expand": "^12.0.3",
"es-module-lexer": "^1.7.0",
Expand Down Expand Up @@ -147,7 +148,6 @@
"strip-literal": "^3.1.0",
"terser": "^5.44.0",
"tsconfck": "^3.1.6",
"types": "link:./types",
"ufo": "^1.6.1",
"ws": "^8.18.3"
},
Expand Down
45 changes: 11 additions & 34 deletions packages/vite/rolldown.dts.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { builtinModules } from 'node:module'
import { defineConfig } from 'rolldown'
import type {
Expand All @@ -20,15 +19,15 @@ import type {
Statement,
} from '@oxc-project/types'

const depTypesDir = new URL('./src/types/', import.meta.url)
const pkg = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url)).toString(),
)

const external = [
/^node:*/,
/^node:/,
/^vite\//,
'rollup/parseAst',
/^#types\//,
...Object.keys(pkg.dependencies),
...Object.keys(pkg.peerDependencies),
]
Expand Down Expand Up @@ -99,14 +98,14 @@ const identifierReplacements: Record<string, Record<string, string>> = {
'vite/module-runner': {
FetchResult$1: 'moduleRunner_FetchResult',
},
'../../types/hmrPayload.js': {
'#types/hmrPayload': {
CustomPayload$1: 'hmrPayload_CustomPayload',
HotPayload$1: 'hmrPayload_HotPayload',
},
'../../types/customEvent.js': {
'#types/customEvent': {
InferCustomEventPayload$1: 'hmrPayload_InferCustomEventPayload',
},
'../../types/internal/lightningcssOptions.js': {
'#types/internal/lightningcssOptions': {
LightningCSSOptions$1: 'lightningcssOptions_LightningCSSOptions',
},
}
Expand All @@ -121,38 +120,14 @@ const ignoreConfusingTypeNames = [

/**
* Patch the types files before passing to dts plugin
* 1. Resolve `dep-types/*` and `types/*` imports
* 2. Validate unallowed dependency imports
* 3. Replace confusing type names
* 4. Strip leftover internal types
* 5. Clean unnecessary comments
* 1. Validate unallowed dependency imports
* 2. Replace confusing type names
* 3. Strip leftover internal types
* 4. Clean unnecessary comments
*/
function patchTypes(): Plugin {
return {
name: 'patch-types',
resolveId: {
order: 'pre',
filter: {
id: /^(dep-)?types\//,
},
handler(id) {
// Dep types should be bundled
if (id.startsWith('dep-types/')) {
const fileUrl = new URL(
`./${id.slice('dep-types/'.length)}.d.ts`,
depTypesDir,
)
return fileURLToPath(fileUrl)
}
// Ambient types are unbundled and externalized
if (id.startsWith('types/')) {
return {
id: '../../' + (id.endsWith('.js') ? id : id + '.js'),
external: true,
}
}
},
},
generateBundle: {
order: 'post',
handler(_opts, bundle) {
Expand Down Expand Up @@ -235,6 +210,7 @@ function validateRunnerChunk(
if (
!id.startsWith('./') &&
!id.startsWith('../') &&
!id.startsWith('#') &&
// index and moduleRunner have a common chunk "moduleRunnerTransport"
!id.startsWith('moduleRunnerTransport.d') &&
!id.startsWith('types.d')
Expand All @@ -260,6 +236,7 @@ function validateChunkImports(
if (
!id.startsWith('./') &&
!id.startsWith('../') &&
!id.startsWith('#') &&
!id.startsWith('node:') &&
!id.startsWith('types.d') &&
!id.startsWith('vite/') &&
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/client/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ErrorPayload, HotPayload } from 'types/hmrPayload'
import type { ViteHotContext } from 'types/hot'
import type { ErrorPayload, HotPayload } from '#types/hmrPayload'
import type { ViteHotContext } from '#types/hot'
import { HMRClient, HMRContext } from '../shared/hmr'
import {
createWebSocketModuleRunnerTransport,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/client/overlay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ErrorPayload } from 'types/hmrPayload'
import type { ErrorPayload } from '#types/hmrPayload'

// injected by the hmr plugin when served
declare const __BASE__: string
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/hmrHandler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { HotPayload } from 'types/hmrPayload'
import type { HotPayload } from '#types/hmrPayload'
import { slash, unwrapId } from '../shared/utils'
import { ERR_OUTDATED_OPTIMIZED_DEP } from '../shared/constants'
import { createHMRHandler } from '../shared/hmrHandler'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ViteHotContext } from 'types/hot'
import type { ViteHotContext } from '#types/hot'
import { HMRClient, HMRContext, type HMRLogger } from '../shared/hmr'
import { cleanUrl, isPrimitive } from '../shared/utils'
import { analyzeImportedModDifference } from '../shared/ssrTransform'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/module-runner/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ViteHotContext } from 'types/hot'
import type { ViteHotContext } from '#types/hot'
import type { HMRLogger } from '../shared/hmr'
import type {
DefineImportMetadata,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`fixture > transform 1`] = `
"import * as __vite_glob_3_0 from "./modules/a.ts";import * as __vite_glob_3_1 from "./modules/b.ts";import * as __vite_glob_3_2 from "./modules/index.ts";import * as __vite_glob_5_0 from "./modules/a.ts";import * as __vite_glob_5_1 from "./modules/b.ts";import * as __vite_glob_5_2 from "./modules/index.ts";import { name as __vite_glob_9_0 } from "./modules/a.ts";import { name as __vite_glob_9_1 } from "./modules/b.ts";import { name as __vite_glob_9_2 } from "./modules/index.ts";import { name as __vite_glob_11_0 } from "./modules/a.ts";import { name as __vite_glob_11_1 } from "./modules/b.ts";import { name as __vite_glob_11_2 } from "./modules/index.ts";import { default as __vite_glob_15_0 } from "./modules/a.ts?raw";import { default as __vite_glob_15_1 } from "./modules/b.ts?raw";import * as __vite_glob_28_0 from "./.foo/test.ts";import "types/importMeta";
"import * as __vite_glob_3_0 from "./modules/a.ts";import * as __vite_glob_3_1 from "./modules/b.ts";import * as __vite_glob_3_2 from "./modules/index.ts";import * as __vite_glob_5_0 from "./modules/a.ts";import * as __vite_glob_5_1 from "./modules/b.ts";import * as __vite_glob_5_2 from "./modules/index.ts";import { name as __vite_glob_9_0 } from "./modules/a.ts";import { name as __vite_glob_9_1 } from "./modules/b.ts";import { name as __vite_glob_9_2 } from "./modules/index.ts";import { name as __vite_glob_11_0 } from "./modules/a.ts";import { name as __vite_glob_11_1 } from "./modules/b.ts";import { name as __vite_glob_11_2 } from "./modules/index.ts";import { default as __vite_glob_15_0 } from "./modules/a.ts?raw";import { default as __vite_glob_15_1 } from "./modules/b.ts?raw";import * as __vite_glob_28_0 from "./.foo/test.ts";import "../../../../../../types/importMeta";
export const basic = /* #__PURE__ */ Object.assign({"./modules/a.ts": () => import("./modules/a.ts"),"./modules/b.ts": () => import("./modules/b.ts"),"./modules/index.ts": () => import("./modules/index.ts")});
export const basicWithObjectKeys = Object.keys({"./modules/a.ts": 0,"./modules/b.ts": 0,"./modules/index.ts": 0});
export const basicWithObjectValues = Object.values([() => import("./modules/a.ts"),() => import("./modules/b.ts"),() => import("./modules/index.ts")]);
Expand Down Expand Up @@ -105,7 +105,7 @@ export const dotFolder = /* #__PURE__ */ Object.assign({"./.foo/test.ts": __vite
`;

exports[`fixture > transform with restoreQueryExtension 1`] = `
"import * as __vite_glob_3_0 from "./modules/a.ts";import * as __vite_glob_3_1 from "./modules/b.ts";import * as __vite_glob_3_2 from "./modules/index.ts";import * as __vite_glob_5_0 from "./modules/a.ts";import * as __vite_glob_5_1 from "./modules/b.ts";import * as __vite_glob_5_2 from "./modules/index.ts";import { name as __vite_glob_9_0 } from "./modules/a.ts";import { name as __vite_glob_9_1 } from "./modules/b.ts";import { name as __vite_glob_9_2 } from "./modules/index.ts";import { name as __vite_glob_11_0 } from "./modules/a.ts";import { name as __vite_glob_11_1 } from "./modules/b.ts";import { name as __vite_glob_11_2 } from "./modules/index.ts";import { default as __vite_glob_15_0 } from "./modules/a.ts?raw";import { default as __vite_glob_15_1 } from "./modules/b.ts?raw";import * as __vite_glob_28_0 from "./.foo/test.ts";import "types/importMeta";
"import * as __vite_glob_3_0 from "./modules/a.ts";import * as __vite_glob_3_1 from "./modules/b.ts";import * as __vite_glob_3_2 from "./modules/index.ts";import * as __vite_glob_5_0 from "./modules/a.ts";import * as __vite_glob_5_1 from "./modules/b.ts";import * as __vite_glob_5_2 from "./modules/index.ts";import { name as __vite_glob_9_0 } from "./modules/a.ts";import { name as __vite_glob_9_1 } from "./modules/b.ts";import { name as __vite_glob_9_2 } from "./modules/index.ts";import { name as __vite_glob_11_0 } from "./modules/a.ts";import { name as __vite_glob_11_1 } from "./modules/b.ts";import { name as __vite_glob_11_2 } from "./modules/index.ts";import { default as __vite_glob_15_0 } from "./modules/a.ts?raw";import { default as __vite_glob_15_1 } from "./modules/b.ts?raw";import * as __vite_glob_28_0 from "./.foo/test.ts";import "../../../../../../types/importMeta";
export const basic = /* #__PURE__ */ Object.assign({"./modules/a.ts": () => import("./modules/a.ts"),"./modules/b.ts": () => import("./modules/b.ts"),"./modules/index.ts": () => import("./modules/index.ts")});
export const basicWithObjectKeys = Object.keys({"./modules/a.ts": 0,"./modules/b.ts": 0,"./modules/index.ts": 0});
export const basicWithObjectValues = Object.values([() => import("./modules/a.ts"),() => import("./modules/b.ts"),() => import("./modules/index.ts")]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'types/importMeta'
// NOTE: `#types/importMeta` does not work as `src/node/__tests__/package.json` shadows the root
// `package.json` and does not declare the subpath import.
import '../../../../../../types/importMeta'

export interface ModuleType {
name: string
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import type {
WatcherOptions,
} from 'rollup'
import commonjsPlugin from '@rollup/plugin-commonjs'
import type { RollupCommonJSOptions } from 'dep-types/commonjs'
import type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
import type { TransformOptions } from 'esbuild'
import type { RollupCommonJSOptions } from '#dep-types/commonjs'
import type { RollupDynamicImportVarsOptions } from '#dep-types/dynamicImportVars'
import {
DEFAULT_ASSETS_INLINE_LIMIT,
ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { performance } from 'node:perf_hooks'
import { createRequire } from 'node:module'
import crypto from 'node:crypto'
import colors from 'picocolors'
import type { Alias, AliasOptions } from 'dep-types/alias'
import type { PluginContextMeta, RollupOptions } from 'rollup'
import picomatch from 'picomatch'
import { build } from 'esbuild'
import type { Alias, AliasOptions } from '#dep-types/alias'
import type { AnymatchFn } from '../types/anymatch'
import { withTrailingSlash } from '../shared/utils'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import type { OutgoingHttpHeaders as HttpServerHeaders } from 'node:http'
import type { ServerOptions as HttpsServerOptions } from 'node:https'
import type { Connect } from 'dep-types/connect'
import colors from 'picocolors'
import type { Connect } from '#dep-types/connect'
import type { ProxyOptions } from './server/middlewares/proxy'
import type { Logger } from './logger'
import type { HttpServer } from './server'
Expand Down
26 changes: 13 additions & 13 deletions packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,19 +227,19 @@ export type {
CustomPayload,
PrunePayload,
ErrorPayload,
} from 'types/hmrPayload'
} from '#types/hmrPayload'
export type {
CustomEventMap,
InferCustomEventPayload,
InvalidatePayload,
} from 'types/customEvent'
} from '#types/customEvent'
export type {
ImportGlobFunction,
ImportGlobOptions,
GeneralImportGlobOptions,
KnownAsTypeMap,
} from 'types/importGlob'
export type { ChunkMetadata, CustomPluginOptionsVite } from 'types/metadata'
} from '#types/importGlob'
export type { ChunkMetadata, CustomPluginOptionsVite } from '#types/metadata'

// dep types
export type {
Expand All @@ -248,16 +248,16 @@ export type {
ResolverFunction,
ResolverObject,
Alias,
} from 'dep-types/alias'
export type { Connect } from 'dep-types/connect'
export type { WebSocket, WebSocketAlias } from 'dep-types/ws'
} from '#dep-types/alias'
export type { Connect } from '#dep-types/connect'
export type { WebSocket, WebSocketAlias } from '#dep-types/ws'
export type * as HttpProxy from 'http-proxy-3'
export type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
export type { Terser } from 'types/internal/terserOptions'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'
export type { LightningCSSOptions } from 'types/internal/lightningcssOptions'
export type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
export type { Terser } from '#types/internal/terserOptions'
export type { RollupCommonJSOptions } from '#dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from '#dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from '#dep-types/anymatch'
export type { LightningCSSOptions } from '#types/internal/lightningcssOptions'

// Backward compatibility
export type { ModuleGraph, ModuleNode } from './server/mixedModuleGraph'
14 changes: 7 additions & 7 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import type * as PostCSS from 'postcss'
import type Sass from 'sass'
import type Stylus from 'stylus'
import type Less from 'less'
import type { LightningCSSOptions } from 'types/internal/lightningcssOptions'
import type { TransformOptions } from 'esbuild'
import { formatMessages, transform } from 'esbuild'
import type { RawSourceMap } from '@jridgewell/remapping'
import { WorkerWithFallback } from 'artichokie'
import { globSync } from 'tinyglobby'
import type {
LessPreprocessorBaseOptions,
SassModernPreprocessBaseOptions,
StylusPreprocessorBaseOptions,
} from 'types/internal/cssPreprocessorOptions'
import type {
TransformAttributeResult as LightningCssTransformAttributeResult,
TransformResult as LightningCssTransformResult,
} from 'lightningcss'
import type { CustomPluginOptionsVite } from 'types/metadata'
import type {
LessPreprocessorBaseOptions,
SassModernPreprocessBaseOptions,
StylusPreprocessorBaseOptions,
} from '#types/internal/cssPreprocessorOptions'
import type { LightningCSSOptions } from '#types/internal/lightningcssOptions'
import type { CustomPluginOptionsVite } from '#types/metadata'
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
import type { EnvironmentModuleNode } from '../server/moduleGraph'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { RawSourceMap } from '@jridgewell/remapping'
import type { InternalModuleFormat, SourceMap } from 'rollup'
import type { TSConfckParseResult } from 'tsconfck'
import { TSConfckCache, TSConfckParseError, parse } from 'tsconfck'
import type { FSWatcher } from 'dep-types/chokidar'
import type { FSWatcher } from '#dep-types/chokidar'
import {
combineSourcemaps,
createDebugger,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import type {
import type { CustomPluginOptions, RollupAstNode, RollupError } from 'rollup'
import MagicString from 'magic-string'
import { stringifyQuery } from 'ufo'
import type { GeneralImportGlobOptions } from 'types/importGlob'
import { parseAstAsync } from 'rollup/parseAst'
import { escapePath, glob } from 'tinyglobby'
import type { GeneralImportGlobOptions } from '#types/importGlob'
import type { Plugin } from '../plugin'
import type { EnvironmentModuleNode } from '../server/moduleGraph'
import type { ResolvedConfig } from '../config'
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/plugins/terser.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { pathToFileURL } from 'node:url'
import { WorkerWithFallback } from 'artichokie'
import type {
TerserMinifyOptions,
TerserMinifyOutput,
} from 'types/internal/terserOptions'
import { WorkerWithFallback } from 'artichokie'
} from '#types/internal/terserOptions'
import type { Plugin } from '../plugin'
import type { ResolvedConfig } from '..'
import { generateCodeFrame, requireResolveFromRootWithFallback } from '../utils'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import path from 'node:path'
import sirv from 'sirv'
import compression from '@polka/compression'
import connect from 'connect'
import type { Connect } from 'dep-types/connect'
import corsMiddleware from 'cors'
import type { Connect } from '#dep-types/connect'
import type {
HttpServer,
ResolvedServerOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FSWatcher } from 'dep-types/chokidar'
import colors from 'picocolors'
import type { FSWatcher } from '#dep-types/chokidar'
import type { FetchFunctionOptions, FetchResult } from 'vite/module-runner'
import { BaseEnvironment } from '../baseEnvironment'
import type {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import fsp from 'node:fs/promises'
import path from 'node:path'
import { EventEmitter } from 'node:events'
import colors from 'picocolors'
import type { CustomPayload, HotPayload, Update } from 'types/hmrPayload'
import type { RollupError } from 'rollup'
import type { CustomPayload, HotPayload, Update } from '#types/hmrPayload'
import type {
InvokeMethods,
InvokeResponseData,
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import connect from 'connect'
import corsMiddleware from 'cors'
import colors from 'picocolors'
import chokidar from 'chokidar'
import type { FSWatcher, WatchOptions } from 'dep-types/chokidar'
import type { Connect } from 'dep-types/connect'
import launchEditorMiddleware from 'launch-editor-middleware'
import type { SourceMap } from 'rollup'
import type { FSWatcher, WatchOptions } from '#dep-types/chokidar'
import type { Connect } from '#dep-types/connect'
import type { ModuleRunner } from 'vite/module-runner'
import type { CommonServerOptions } from '../http'
import {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Connect } from 'dep-types/connect'
import type { Connect } from '#dep-types/connect'
import { joinUrlSegments, stripBase } from '../../utils'
import { cleanUrl, withTrailingSlash } from '../../../shared/utils'

Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/server/middlewares/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import path from 'node:path'
import { stripVTControlCharacters as strip } from 'node:util'
import colors from 'picocolors'
import type { RollupError } from 'rollup'
import type { Connect } from 'dep-types/connect'
import type { ErrorPayload } from 'types/hmrPayload'
import type { Connect } from '#dep-types/connect'
import type { ErrorPayload } from '#types/hmrPayload'
import { pad } from '../../utils'
import type { ViteDevServer } from '../..'
import { CLIENT_PUBLIC_PATH } from '../../constants'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/server/middlewares/hostCheck.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Connect } from 'dep-types/connect'
import { hostValidationMiddleware as originalHostValidationMiddleware } from 'host-validation-middleware'
import type { Connect } from '#dep-types/connect'
import type { ResolvedPreviewOptions, ResolvedServerOptions } from '../..'

export function getAdditionalAllowedHosts(
Expand Down
Loading
Loading