Skip to content

Commit d323ed7

Browse files
authored
fix(dev): always use ESM Oxc runtime (#21829)
1 parent 5ba688b commit d323ed7

6 files changed

Lines changed: 24 additions & 36 deletions

File tree

packages/vite/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
},
7474
"//": "READ CONTRIBUTING.md to understand what to put under deps vs. devDeps!",
7575
"dependencies": {
76-
"@oxc-project/runtime": "0.120.0",
7776
"lightningcss": "^1.32.0",
7877
"picomatch": "^4.0.3",
7978
"postcss": "^8.5.8",

packages/vite/src/node/plugins/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
viteAliasPlugin as nativeAliasPlugin,
55
viteJsonPlugin as nativeJsonPlugin,
66
viteWasmFallbackPlugin as nativeWasmFallbackPlugin,
7+
oxcRuntimePlugin,
78
} from 'rolldown/experimental'
89
import type { PluginHookUtils, ResolvedConfig } from '../config'
910
import {
@@ -94,6 +95,8 @@ export async function resolvePlugins(
9495
htmlInlineProxyPlugin(config),
9596
cssPlugin(config),
9697
esbuildBannerFooterCompatPlugin(config),
98+
// @oxc-project/runtime resolution is handled by rolldown in build
99+
config.oxc !== false && !isBundled ? oxcRuntimePlugin() : null,
97100
config.oxc !== false ? oxcPlugin(config) : null,
98101
nativeJsonPlugin({ ...config.json, minify: isBuild }),
99102
wasmHelperPlugin(),

packages/vite/src/node/plugins/oxc.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import { transformSync } from 'rolldown/utils'
77
import { viteTransformPlugin as nativeTransformPlugin } from 'rolldown/experimental'
88
import type { RolldownError, RolldownLog, SourceMap } from 'rolldown'
99
import colors from 'picocolors'
10-
import { prefixRegex } from 'rolldown/filter'
1110
import type { FSWatcher } from '#dep-types/chokidar'
1211
import { createFilter, ensureWatchedFile, normalizePath } from '../utils'
1312
import type { ResolvedConfig } from '../config'
1413
import type { Plugin } from '../plugin'
1514
import { cleanUrl } from '../../shared/utils'
1615
import { type Environment, perEnvironmentPlugin } from '..'
1716
import type { ViteDevServer } from '../server'
18-
import { JS_TYPES_RE, VITE_PACKAGE_DIR } from '../constants'
17+
import { JS_TYPES_RE } from '../constants'
1918
import type { Logger } from '../logger'
2019
import { type ESBuildOptions, getTSConfigResolutionCache } from './esbuild'
2120

@@ -299,9 +298,6 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
299298

300299
return result
301300
}
302-
const runtimeResolveBase = normalizePath(
303-
path.join(VITE_PACKAGE_DIR, 'package.json'),
304-
)
305301

306302
let server: ViteDevServer
307303

@@ -310,23 +306,6 @@ export function oxcPlugin(config: ResolvedConfig): Plugin {
310306
configureServer(_server) {
311307
server = _server
312308
},
313-
// @oxc-project/runtime resolution is handled by rolldown in build
314-
...(config.command === 'serve'
315-
? {
316-
resolveId: {
317-
filter: {
318-
id: prefixRegex('@oxc-project/runtime/'),
319-
},
320-
async handler(id, _importer, opts) {
321-
// @oxc-project/runtime imports will be injected by Oxc transform
322-
// since it's injected by the transform, @oxc-project/runtime should be resolved to the one Vite depends on
323-
const resolved = await this.resolve(id, runtimeResolveBase, opts)
324-
return resolved
325-
},
326-
order: 'pre',
327-
},
328-
}
329-
: {}),
330309
async transform(code, id) {
331310
if (filter(id) || filter(cleanUrl(id)) || jsxRefreshFilter?.(id)) {
332311
const modifiedOxcTransformOptions = getModifiedOxcTransformOptions(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function html(strings: TemplateStringsArray, ...values: unknown[]) {
2+
return strings.join('')
3+
}
4+
export const result = html`<script>
5+
console.log('hi')
6+
</script>`

packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('module runner initialization', async () => {
1212
const it = await createModuleRunnerTester({
1313
resolve: {
1414
external: ['tinyglobby'],
15+
noExternal: ['@oxc-project/runtime'],
1516
},
1617
})
1718

@@ -396,6 +397,15 @@ describe('module runner initialization', async () => {
396397
)
397398
})
398399

400+
it('oxc runtime helpers are loadable', async ({ runner }) => {
401+
const mod = await runner.import('/fixtures/oxc-runtime-helper.ts')
402+
expect(mod.result).toMatchInlineSnapshot(`
403+
"<script>
404+
console.log('hi')
405+
</script>"
406+
`)
407+
})
408+
399409
it(`handle Object variable`, async ({ runner }) => {
400410
const mod = await runner.import('/fixtures/top-level-object.js')
401411
expect(mod).toMatchInlineSnapshot(`

pnpm-lock.yaml

Lines changed: 4 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)