Skip to content

Commit

Permalink
Merge branch 'vitejs:main' into bug-fix-regex-'s'-modifier-removal-fo…
Browse files Browse the repository at this point in the history
…r-older-browsers-support
  • Loading branch information
MajedMuhammad authored Feb 14, 2024
2 parents 779885f + 63a39c2 commit a4413af
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 26 deletions.
5 changes: 5 additions & 0 deletions docs/.vitepress/theme/composables/sponsor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ const viteSponsors: Pick<Sponsors, 'special' | 'gold'> = {
url: 'https://remix.run/',
img: '/remix.svg',
},
{
name: 'Nx',
url: 'https://nx.dev/',
img: '/nx.svg',
},
{
name: 'Transloadit',
url: 'https://transloadit.com/?utm_source=vite&utm_medium=referral&utm_campaign=sponsorship&utm_content=website',
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/ssr.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ app.use('*', async (req, res, next) => {
// ESM source code to be usable in Node.js! There is no bundling
// required, and provides efficient invalidation similar to HMR.
const { render } = await vite.ssrLoadModule('/src/entry-server.js')
// 3b. Since Vite 5.1, you can use createViteRuntime API instead.
// 3b. Since Vite 5.1, you can use the experimental createViteRuntime API
// instead.
// It fully supports HMR and works in a simillar way to ssrLoadModule
// More advanced use case would be creating a runtime in a separate
// thread or even a different machine using ViteRuntime class
Expand Down
8 changes: 8 additions & 0 deletions docs/public/nx.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions packages/vite/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## <small>5.1.2 (2024-02-14)</small>

* fix: normalize import file path info (#15772) ([306df44](https://github.com/vitejs/vite/commit/306df44)), closes [#15772](https://github.com/vitejs/vite/issues/15772)
* fix(build): do not output build time when build fails (#15711) ([added3e](https://github.com/vitejs/vite/commit/added3e)), closes [#15711](https://github.com/vitejs/vite/issues/15711)
* fix(runtime): pass path instead of fileURL to `isFilePathESM` (#15908) ([7b15607](https://github.com/vitejs/vite/commit/7b15607)), closes [#15908](https://github.com/vitejs/vite/issues/15908)
* fix(worker): support UTF-8 encoding in inline workers (fixes #12117) (#15866) ([570e0f1](https://github.com/vitejs/vite/commit/570e0f1)), closes [#12117](https://github.com/vitejs/vite/issues/12117) [#15866](https://github.com/vitejs/vite/issues/15866)
* chore: update license file (#15885) ([d9adf18](https://github.com/vitejs/vite/commit/d9adf18)), closes [#15885](https://github.com/vitejs/vite/issues/15885)
* chore(deps): update all non-major dependencies (#15874) ([d16ce5d](https://github.com/vitejs/vite/commit/d16ce5d)), closes [#15874](https://github.com/vitejs/vite/issues/15874)
* chore(deps): update dependency dotenv-expand to v11 (#15875) ([642d528](https://github.com/vitejs/vite/commit/642d528)), closes [#15875](https://github.com/vitejs/vite/issues/15875)



## <small>5.1.1 (2024-02-09)</small>

* fix: empty CSS file was output when only .css?url is used (#15846) ([b2873ac](https://github.com/vitejs/vite/commit/b2873ac)), closes [#15846](https://github.com/vitejs/vite/issues/15846)
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vite",
"version": "5.1.1",
"version": "5.1.2",
"type": "module",
"license": "MIT",
"author": "Evan You",
Expand Down
14 changes: 8 additions & 6 deletions packages/vite/src/node/ssr/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function fetchModule(
throw err
}
const file = pathToFileURL(resolved.id).toString()
const type = isFilePathESM(file, server.config.packageCache)
const type = isFilePathESM(resolved.id, server.config.packageCache)
? 'module'
: 'commonjs'
return { externalize: file, type }
Expand Down Expand Up @@ -123,6 +123,11 @@ SOURCEMAPPING_URL += 'ppingURL'
const VITE_RUNTIME_SOURCEMAPPING_SOURCE = '//# sourceMappingSource=vite-runtime'
const VITE_RUNTIME_SOURCEMAPPING_URL = `${SOURCEMAPPING_URL}=data:application/json;charset=utf-8`

const OTHER_SOURCE_MAP_REGEXP = new RegExp(
`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`,
'gm',
)

function inlineSourceMap(
mod: ModuleNode,
result: TransformResult,
Expand All @@ -139,11 +144,8 @@ function inlineSourceMap(
return result

// to reduce the payload size, we only inline vite node source map, because it's also the only one we use
const OTHER_SOURCE_MAP_REGEXP = new RegExp(
`//# ${SOURCEMAPPING_URL}=data:application/json[^,]+base64,([A-Za-z0-9+/=]+)$`,
'gm',
)
while (OTHER_SOURCE_MAP_REGEXP.test(code))
OTHER_SOURCE_MAP_REGEXP.lastIndex = 0
if (OTHER_SOURCE_MAP_REGEXP.test(code))
code = code.replace(OTHER_SOURCE_MAP_REGEXP, '')

const sourceMap = Buffer.from(
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/ssr/runtime/moduleCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ModuleCacheMap extends Map<string, ModuleCache> {
update(fsPath: string, mod: ModuleCache): this {
fsPath = this.normalize(fsPath)
if (!super.has(fsPath)) this.setByModuleId(fsPath, mod)
else Object.assign(super.get(fsPath) as ModuleCache, mod)
else Object.assign(super.get(fsPath)!, mod)
return this
}

Expand All @@ -50,7 +50,7 @@ export class ModuleCacheMap extends Map<string, ModuleCache> {
importers: new Set(),
})
}
return mod as ModuleCache
return mod
}

override get(fsPath: string): ModuleCache {
Expand Down
29 changes: 14 additions & 15 deletions packages/vite/src/node/ssr/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,21 +218,20 @@ export class ViteRuntime {
return this.processImport(mod.exports, fetchedModule, metadata)
}

const getStack = () =>
`stack:\n${[...callstack, moduleId]
.reverse()
.map((p) => ` - ${p}`)
.join('\n')}`

let debugTimer: any
if (this.debug)
debugTimer = setTimeout(
() =>
this.debug!(
`[vite-runtime] module ${moduleId} takes over 2s to load.\n${getStack()}`,
),
2000,
)
if (this.debug) {
debugTimer = setTimeout(() => {
const getStack = () =>
`stack:\n${[...callstack, moduleId]
.reverse()
.map((p) => ` - ${p}`)
.join('\n')}`

this.debug!(
`[vite-runtime] module ${moduleId} takes over 2s to load.\n${getStack()}`,
)
}, 2000)
}

try {
// cached module
Expand Down Expand Up @@ -266,7 +265,7 @@ export class ViteRuntime {
this.debug?.('[vite-runtime] fetching', id)
// fast return for established externalized patterns
const fetchedModule = id.startsWith('data:')
? ({ externalize: id, type: 'builtin' } as FetchResult)
? ({ externalize: id, type: 'builtin' } satisfies FetchResult)
: await this.options.fetchModule(id, importer)
// base moduleId on "file" and not on id
// if `import(variable)` is called it's possible that it doesn't have an extension for example
Expand Down
2 changes: 1 addition & 1 deletion playground/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ export const ports = {
ssr: 9600,
'ssr-deps': 9601,
'ssr-html': 9602,
'ssr-hmr': 9609, // not imported but used in `ssr-hmr/vite.config.js`
'ssr-noexternal': 9603,
'ssr-pug': 9604,
'ssr-webworker': 9605,
'proxy-bypass': 9606, // not imported but used in `proxy-hmr/vite.config.js`
'proxy-bypass/non-existent-app': 9607, // not imported but used in `proxy-hmr/other-app/vite.config.js`
'ssr-hmr': 9609, // not imported but used in `hmr-ssr/__tests__/hmr.spec.ts`
'proxy-hmr': 9616, // not imported but used in `proxy-hmr/vite.config.js`
'proxy-hmr/other-app': 9617, // not imported but used in `proxy-hmr/other-app/vite.config.js`
'ssr-conditions': 9620,
Expand Down

0 comments on commit a4413af

Please sign in to comment.