Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Dec 25, 2024
2 parents 643d152 + afff05c commit 4c777ac
Show file tree
Hide file tree
Showing 34 changed files with 761 additions and 406 deletions.
9 changes: 1 addition & 8 deletions docs/guide/api-environment-runtimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,10 @@ Module runner exposes `import` method. When Vite server triggers `full-reload` H

```js
import { ModuleRunner, ESModulesEvaluator } from 'vite/module-runner'
import { root, transport } from './rpc-implementation.js'
import { transport } from './rpc-implementation.js'

const moduleRunner = new ModuleRunner(
{
root,
transport,
},
new ESModulesEvaluator(),
Expand All @@ -180,10 +179,6 @@ type ModuleRunnerTransport = unknown

// ---cut---
interface ModuleRunnerOptions {
/**
* Root of the project
*/
root: string
/**
* A set of methods to communicate with the server.
*/
Expand Down Expand Up @@ -294,7 +289,6 @@ const transport = {

const runner = new ModuleRunner(
{
root: fileURLToPath(new URL('./', import.meta.url)),
transport,
},
new ESModulesEvaluator(),
Expand Down Expand Up @@ -362,7 +356,6 @@ import { ESModulesEvaluator, ModuleRunner } from 'vite/module-runner'

export const runner = new ModuleRunner(
{
root: fileURLToPath(new URL('./', import.meta.url)),
transport: {
async invoke(data) {
const response = await fetch(`http://my-vite-server/invoke`, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"simple-git-hooks": "^2.11.1",
"tslib": "^2.8.1",
"tsx": "^4.19.2",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"typescript-eslint": "^8.18.2",
"vite": "workspace:*",
"vitest": "^2.1.8"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-lit-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lit": "^3.2.1"
},
"devDependencies": {
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-preact-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"devDependencies": {
"@preact/preset-vite": "^2.9.3",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-qwik-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"serve": "^14.2.4",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.14.0",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"typescript-eslint": "^8.18.2",
"vite": "^6.0.5"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-solid-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"solid-js": "^1.9.3"
},
"devDependencies": {
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5",
"vite-plugin-solid": "^2.11.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/create-vite/template-svelte-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@tsconfig/svelte": "^5.0.4",
"svelte": "^5.15.0",
"svelte-check": "^4.1.1",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vanilla-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"devDependencies": {
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5"
}
}
2 changes: 1 addition & 1 deletion packages/create-vite/template-vue-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"devDependencies": {
"@vitejs/plugin-vue": "^5.2.1",
"@vue/tsconfig": "^0.7.0",
"typescript": "~5.6.2",
"typescript": "~5.7.2",
"vite": "^6.0.5",
"vue-tsc": "^2.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
},
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
"dependencies": {
"esbuild": "0.24.0",
"esbuild": "^0.24.2",
"postcss": "^8.4.49",
"rollup": "^4.23.0"
},
Expand Down
6 changes: 0 additions & 6 deletions packages/vite/src/module-runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import type {
SSRImportMetadata,
} from './types'
import {
normalizeAbsoluteUrl,
posixDirname,
posixPathToFileHref,
posixResolve,
Expand Down Expand Up @@ -52,7 +51,6 @@ export class ModuleRunner {
})
private readonly transport: NormalizedModuleRunnerTransport
private readonly resetSourceMapSupport?: () => void
private readonly root: string
private readonly concurrentModuleNodePromises = new Map<
string,
Promise<EvaluatedModuleNode>
Expand All @@ -65,8 +63,6 @@ export class ModuleRunner {
public evaluator: ModuleEvaluator = new ESModulesEvaluator(),
private debug?: ModuleRunnerDebugger,
) {
const root = this.options.root
this.root = root[root.length - 1] === '/' ? root : `${root}/`
this.evaluatedModules = options.evaluatedModules ?? new EvaluatedModules()
this.transport = normalizeModuleRunnerTransport(options.transport)
if (options.hmr !== false) {
Expand Down Expand Up @@ -237,8 +233,6 @@ export class ModuleRunner {
url: string,
importer?: string,
): Promise<EvaluatedModuleNode> {
url = normalizeAbsoluteUrl(url, this.root)

let cached = this.concurrentModuleNodePromises.get(url)
if (!cached) {
const cachedModule = this.evaluatedModules.getModuleByUrl(url)
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/module-runner/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ export interface ModuleRunnerHmr {
export interface ModuleRunnerOptions {
/**
* Root of the project
* @deprecated not used and to be removed
*/
root: string
root?: string
/**
* A set of methods to communicate with the server.
*/
Expand Down
23 changes: 1 addition & 22 deletions packages/vite/src/module-runner/utils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
import * as pathe from 'pathe'
import { isWindows, slash } from '../shared/utils'

export function normalizeAbsoluteUrl(url: string, root: string): string {
url = slash(url)

// file:///C:/root/id.js -> C:/root/id.js
if (url.startsWith('file://')) {
// 8 is the length of "file:///"
url = decodeURI(url.slice(isWindows ? 8 : 7))
}

// strip root from the URL because fetchModule prefers a public served url path
// packages/vite/src/node/server/moduleGraph.ts:17
if (url.startsWith(root)) {
// /root/id.js -> /id.js
// C:/root/id.js -> /id.js
// 1 is to keep the leading slash
url = url.slice(root.length - 1)
}

return url
}
import { isWindows } from '../shared/utils'

export const decodeBase64 =
typeof atob !== 'undefined'
Expand Down
3 changes: 2 additions & 1 deletion packages/vite/src/node/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
isInNodeModules,
normalizePath,
safeRealpathSync,
stripBomTag,
tryStatSync,
} from './utils'
import type { Plugin } from './plugin'
Expand Down Expand Up @@ -175,7 +176,7 @@ export function findNearestMainPackageData(
}

export function loadPackageData(pkgPath: string): PackageData {
const data = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
const data = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, 'utf-8')))
const pkgDir = normalizePath(path.dirname(pkgPath))
const { sideEffects } = data
let hasSideEffects: (id: string) => boolean | null
Expand Down
25 changes: 13 additions & 12 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
} from '../utils'
import type { Logger } from '../logger'
import { cleanUrl, isWindows, slash } from '../../shared/utils'
import { NULL_BYTE_PLACEHOLDER } from '../../shared/constants'
import { createBackCompatIdResolver } from '../idResolver'
import type { ResolveIdFn } from '../idResolver'
import { PartialEnvironment } from '../baseEnvironment'
Expand Down Expand Up @@ -3165,10 +3166,9 @@ async function compileLightningCSS(
): ReturnType<typeof compileCSS> {
const { config } = environment
const deps = new Set<string>()
// Relative path is needed to get stable hash when using CSS modules
const filename = cleanUrl(path.relative(config.root, id))
const toAbsolute = (filePath: string) =>
path.isAbsolute(filePath) ? filePath : path.join(config.root, filePath)
// replace null byte as lightningcss treats that as a string terminator
// https://github.com/parcel-bundler/lightningcss/issues/874
const filename = id.replace('\0', NULL_BYTE_PLACEHOLDER)

let res: LightningCssTransformAttributeResult | LightningCssTransformResult
try {
Expand All @@ -3185,16 +3185,14 @@ async function compileLightningCSS(
).bundleAsync({
...config.css.lightningcss,
filename,
// projectRoot is needed to get stable hash when using CSS modules
projectRoot: config.root,
resolver: {
read(filePath) {
if (filePath === filename) {
return src
}
// This happens with html-proxy (#13776)
if (!filePath.endsWith('.css')) {
return src
}
return fs.readFileSync(toAbsolute(filePath), 'utf-8')
return fs.readFileSync(filePath, 'utf-8')
},
async resolve(id, from) {
const publicFile = checkPublicFile(
Expand All @@ -3207,7 +3205,7 @@ async function compileLightningCSS(

const resolved = await getAtImportResolvers(
environment.getTopLevelConfig(),
).css(environment, id, toAbsolute(from))
).css(environment, id, from)

if (resolved) {
deps.add(resolved)
Expand All @@ -3229,7 +3227,7 @@ async function compileLightningCSS(
} catch (e) {
e.message = `[lightningcss] ${e.message}`
e.loc = {
file: toAbsolute(e.fileName),
file: e.fileName.replace(NULL_BYTE_PLACEHOLDER, '\0'),
line: e.loc.line,
column: e.loc.column - 1, // 1-based
}
Expand All @@ -3247,7 +3245,10 @@ async function compileLightningCSS(
if (skipUrlReplacer(dep.url)) {
replaceUrl = dep.url
} else if (urlReplacer) {
replaceUrl = await urlReplacer(dep.url, toAbsolute(dep.loc.filePath))
replaceUrl = await urlReplacer(
dep.url,
dep.loc.filePath.replace(NULL_BYTE_PLACEHOLDER, '\0'),
)
} else {
replaceUrl = dep.url
}
Expand Down
Loading

0 comments on commit 4c777ac

Please sign in to comment.