Skip to content

Commit f670af3

Browse files
committed
chore: use oxc module runner transform
wip: workaround double createRequire chore: enable back pnpm override fix: fix duplicate createRequire chore: fix overrides ci: trigger preview Revert "ci: trigger preview" This reverts commit 6fb3890. chore: oxc-transform 0.57.0 test: update test and note vitejs#19627 test: test ssrTransform deps
1 parent 7912459 commit f670af3

File tree

5 files changed

+70
-2
lines changed

5 files changed

+70
-2
lines changed

packages/vite/src/node/ssr/__tests__/ssrLoadModule.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ test('json', async () => {
238238
null,
239239
'/test.json',
240240
)
241-
expect(json?.code.length).toMatchInlineSnapshot(`61`)
241+
expect(json?.code.length).toMatchInlineSnapshot(`60`)
242242
})
243243

244244
test('file url', async () => {

packages/vite/src/node/ssr/__tests__/ssrTransform.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -1523,3 +1523,29 @@ test('combine mappings', async () => {
15231523
`)
15241524
}
15251525
})
1526+
1527+
test.skip('deps', async () => {
1528+
const result = await ssrTransformSimple(`\
1529+
import a from "a";
1530+
export { b } from "b";
1531+
export * from "c";
1532+
export * as d from "d";
1533+
import("e");
1534+
`)
1535+
expect({
1536+
deps: result?.deps,
1537+
dynamicDeps: result?.dynamicDeps,
1538+
}).toMatchInlineSnapshot(`
1539+
{
1540+
"deps": [
1541+
"a",
1542+
"b",
1543+
"c",
1544+
"d",
1545+
],
1546+
"dynamicDeps": [
1547+
"e",
1548+
],
1549+
}
1550+
`)
1551+
})
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// comment
1+
{}; // comment only on the 1st line breaks due to https://github.com/vitejs/vite/issues/19627
22
throw new Error('module error')

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

+3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ describe('module runner initialization', async () => {
6363
expect(serializeStack(server, methodErrorNew)).toBe(
6464
' at Module.throwError (<root>/fixtures/throws-error-method.ts:11:9)',
6565
)
66+
67+
// TODO: test stacktrace on first line
68+
// https://github.com/vitejs/vite/issues/19627
6669
})
6770

6871
it('deep stacktrace', async ({ runner, server }) => {

packages/vite/src/node/ssr/ssrTransform.ts

+39
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { extract_names as extractNames } from 'periscopic'
1818
import { walk as eswalk } from 'estree-walker'
1919
import type { RawSourceMap } from '@ampproject/remapping'
2020
import { parseAstAsync as rolldownParseAstAsync } from 'rolldown/parseAst'
21+
import { moduleRunnerTransform } from 'oxc-transform'
2122
import type { TransformResult } from '../server/transformRequest'
2223
import {
2324
combineSourcemaps,
@@ -84,6 +85,44 @@ async function ssrTransformScript(
8485
url: string,
8586
originalCode: string,
8687
): Promise<TransformResult | null> {
88+
if (!process.env['DISABLE_OXC_MODULE_TRANSFORM']) {
89+
const result = moduleRunnerTransform('test.js', code, { sourcemap: true })
90+
if (result.errors.length) {
91+
// eslint-disable-next-line no-console
92+
console.log(JSON.stringify(result.errors, null, 2), '\n', code)
93+
throw new AggregateError(result.errors)
94+
}
95+
let map: TransformResult['map'] = inMap
96+
if (inMap?.mappings === '') {
97+
map = inMap
98+
} else if (result.map) {
99+
map = result.map as SourceMap
100+
map.sources = [path.basename(url)]
101+
// needs to use originalCode instead of code
102+
// because code might be already transformed even if map is null
103+
map.sourcesContent = [originalCode]
104+
if (
105+
inMap &&
106+
inMap.mappings &&
107+
'sources' in inMap &&
108+
inMap.sources.length > 0
109+
) {
110+
map = combineSourcemaps(url, [
111+
map as RawSourceMap,
112+
inMap as RawSourceMap,
113+
]) as SourceMap
114+
}
115+
}
116+
117+
return {
118+
code: result.code,
119+
map,
120+
ssr: true,
121+
deps: [...result.deps],
122+
dynamicDeps: [...result.dynamicDeps],
123+
}
124+
}
125+
87126
const s = new MagicString(code)
88127

89128
let ast: any

0 commit comments

Comments
 (0)