Skip to content

Commit 16c99fe

Browse files
authored
feat: support Vite 6 (#64)
1 parent a79f392 commit 16c99fe

File tree

19 files changed

+6924
-5158
lines changed

19 files changed

+6924
-5158
lines changed

.github/workflows/publish.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ on:
66

77
jobs:
88
build:
9-
runs-on: ubuntu-latest
9+
runs-on: windows-latest
1010
name: NPM Publish
1111
steps:
12-
- uses: actions/checkout@v3
12+
- uses: actions/checkout@v4
1313
- name: Setup node
14-
uses: actions/setup-node@v3
14+
uses: actions/setup-node@v4
1515
with:
16-
node-version: 18
16+
node-version: 20
1717
- name: Install dependencies
1818
run: yarn --frozen-lockfile
1919
- name: Build

.github/workflows/test.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ on:
66

77
jobs:
88
build:
9-
runs-on: ubuntu-latest
9+
runs-on: windows-latest
1010
strategy:
1111
matrix:
12-
node: ["14", "16", "18", "20"]
12+
node: ["14", "16", "18", "20", "22"]
1313
name: Test on Node.js ${{ matrix.node }}
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
- name: Setup node
17-
uses: actions/setup-node@v3
17+
uses: actions/setup-node@v4
1818
with:
1919
node-version: ${{ matrix.node }}
2020
- name: Set yarn to ignore engines version check

e2e/e2e.ts

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
/// <reference types="jest-extended" />
22
/* istanbul ignore file */
33

4+
import path from "path";
5+
import url from "url";
6+
import fs from "fs";
7+
import type { AddressInfo } from "net";
8+
49
import { jest } from "@jest/globals";
5-
import { firefox } from "playwright";
10+
import { firefox, chromium } from "playwright";
611

7-
// import type { RollupOutput } from "rollup";
8-
type RollupOutput = any;
12+
import type { RollupOutput } from "rollup";
913
import vitePluginWasm from "../src/index.js";
1014

1115
import express from "express";
1216
import waitPort from "wait-port";
1317
import mime from "mime";
14-
import path from "path";
15-
import url from "url";
16-
import type { AddressInfo } from "net";
18+
import { temporaryDirectory } from "tempy";
1719

1820
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
1921

@@ -37,9 +39,15 @@ type VitePackages =
3739
vite: typeof import("./vite5/node_modules/vite");
3840
vitePluginLegacy: (typeof import("./vite5/node_modules/@vitejs/plugin-legacy"))["default"];
3941
vitePluginTopLevelAwait: (typeof import("./vite5/node_modules/vite-plugin-top-level-await"))["default"];
42+
}
43+
| {
44+
vite: typeof import("./vite6/node_modules/vite");
45+
vitePluginLegacy: (typeof import("./vite6/node_modules/@vitejs/plugin-legacy"))["default"];
46+
vitePluginTopLevelAwait: (typeof import("./vite6/node_modules/vite-plugin-top-level-await"))["default"];
4047
};
4148

4249
async function buildAndStartProdServer(
50+
tempDir: string,
4351
vitePackages: VitePackages,
4452
transformTopLevelAwait: boolean,
4553
modernOnly: boolean
@@ -49,8 +57,10 @@ async function buildAndStartProdServer(
4957
const result = await vite.build({
5058
root: __dirname,
5159
build: {
52-
target: "esnext"
60+
target: "esnext",
61+
outDir: path.resolve(tempDir, "dist")
5362
},
63+
cacheDir: path.resolve(tempDir, ".vite"),
5464
plugins: [
5565
...(modernOnly ? [] : [vitePluginLegacy()]),
5666
vitePluginWasm(),
@@ -80,7 +90,7 @@ async function buildAndStartProdServer(
8090
if (filePath in bundle) {
8191
res.header("Access-Control-Allow-Origin", "*");
8292
res.header("Access-Control-Allow-Methods", "*");
83-
const contentType = mime.getType(filePath);
93+
const contentType = mime.getType(filePath) || "application/octet-stream";
8494
const contentTypeWithEncoding = contentType + (contentType.includes("text/") ? "; charset=utf-8" : "");
8595
res.contentType(contentTypeWithEncoding);
8696
res.send(bundle[filePath]);
@@ -99,12 +109,13 @@ async function buildAndStartProdServer(
99109
return `http://127.0.0.1:${port}/`;
100110
}
101111

102-
async function startDevServer(vitePackages: VitePackages): Promise<string> {
112+
async function startDevServer(tempDir: string, vitePackages: VitePackages): Promise<string> {
103113
const { vite } = vitePackages;
104114

105115
const devServer = await vite.createServer({
106116
root: __dirname,
107117
plugins: [vitePluginWasm()],
118+
cacheDir: path.resolve(tempDir, ".vite"),
108119
logLevel: "error"
109120
});
110121

@@ -118,12 +129,15 @@ async function startDevServer(vitePackages: VitePackages): Promise<string> {
118129
}
119130

120131
async function createBrowser(modernBrowser: boolean) {
121-
return await firefox.launch({
122-
firefoxUserPrefs: {
123-
// Simulate a legacy browser with ES modules support disabled
124-
"dom.moduleScripts.enabled": modernBrowser
125-
}
126-
});
132+
return modernBrowser
133+
? await chromium.launch()
134+
: await firefox.launch({
135+
headless: false,
136+
firefoxUserPrefs: {
137+
// Simulate a legacy browser with ES modules support disabled
138+
"dom.moduleScripts.enabled": false
139+
}
140+
});
127141
}
128142

129143
async function runTest(
@@ -132,7 +146,15 @@ async function runTest(
132146
transformTopLevelAwait: boolean,
133147
modernBrowser: boolean
134148
) {
149+
const tempDir = temporaryDirectory();
150+
process.on("exit", () => {
151+
try {
152+
fs.rmdirSync(tempDir, { recursive: true });
153+
} catch {}
154+
});
155+
135156
const server = await (devServer ? startDevServer : buildAndStartProdServer)(
157+
tempDir,
136158
vitePackages,
137159
transformTopLevelAwait,
138160
modernBrowser
@@ -189,7 +211,7 @@ const runTestWithRetry = async (...args: Parameters<typeof runTest>) => {
189211
};
190212

191213
export function runTests(viteVersion: number, importVitePackages: () => Promise<VitePackages>) {
192-
jest.setTimeout(60000);
214+
jest.setTimeout(600000);
193215

194216
describe(`E2E test for Vite ${viteVersion}`, () => {
195217
const nodeVersion = Number(process.versions.node.split(".")[0]);

e2e/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"license": "MIT",
66
"private": true,
77
"scripts": {
8-
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5"
8+
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5 && yarn --cwd vite6"
9+
},
10+
"dependencies": {
11+
"tempy": "^3.1.0"
912
}
10-
}
13+
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
diff --git a/node_modules/vite/dist/node/chunks/dep-689425f3.js b/node_modules/vite/dist/node/chunks/dep-689425f3.js
2-
index babf8d5..019289d 100644
3-
--- a/node_modules/vite/dist/node/chunks/dep-689425f3.js
4-
+++ b/node_modules/vite/dist/node/chunks/dep-689425f3.js
1+
diff --git a/node_modules/vite/dist/node/chunks/dep-0a035c79.js b/node_modules/vite/dist/node/chunks/dep-0a035c79.js
2+
index 57ca5f3..d39bfca 100644
3+
--- a/node_modules/vite/dist/node/chunks/dep-0a035c79.js
4+
+++ b/node_modules/vite/dist/node/chunks/dep-0a035c79.js
55
@@ -38271,7 +38271,7 @@ const isModernFlag = `__VITE_IS_MODERN__`;
66
const preloadMethod = `__vitePreload`;
77
const preloadMarker = `__VITE_PRELOAD__`;

0 commit comments

Comments
 (0)