Skip to content

Commit

Permalink
feat: support Vite 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Menci committed Dec 19, 2024
1 parent a79f392 commit 98427b6
Show file tree
Hide file tree
Showing 10 changed files with 2,345 additions and 245 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ["14", "16", "18", "20"]
node: ["14", "16", "18", "20", "22"]
name: Test on Node.js ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- name: Set yarn to ignore engines version check
Expand Down
7 changes: 6 additions & 1 deletion e2e/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type VitePackages =
vite: typeof import("./vite5/node_modules/vite");
vitePluginLegacy: (typeof import("./vite5/node_modules/@vitejs/plugin-legacy"))["default"];
vitePluginTopLevelAwait: (typeof import("./vite5/node_modules/vite-plugin-top-level-await"))["default"];
}
| {
vite: typeof import("./vite6/node_modules/vite");
vitePluginLegacy: (typeof import("./vite6/node_modules/@vitejs/plugin-legacy"))["default"];
vitePluginTopLevelAwait: (typeof import("./vite6/node_modules/vite-plugin-top-level-await"))["default"];
};

async function buildAndStartProdServer(
Expand Down Expand Up @@ -80,7 +85,7 @@ async function buildAndStartProdServer(
if (filePath in bundle) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "*");
const contentType = mime.getType(filePath);
const contentType = mime.getType(filePath) || "application/octet-stream";
const contentTypeWithEncoding = contentType + (contentType.includes("text/") ? "; charset=utf-8" : "");
res.contentType(contentTypeWithEncoding);
res.send(bundle[filePath]);
Expand Down
4 changes: 2 additions & 2 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"license": "MIT",
"private": true,
"scripts": {
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5"
"install": "yarn --cwd vite2 && yarn --cwd vite3 && yarn --cwd vite4 && yarn --cwd vite5 && yarn --cwd vite6"
}
}
}
7 changes: 7 additions & 0 deletions e2e/vite6/e2e-vite6.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { runTests } from "../e2e";

runTests(6, async () => ({
vite: await import("vite"),
vitePluginLegacy: (await import("@vitejs/plugin-legacy")).default,
vitePluginTopLevelAwait: (await import("vite-plugin-top-level-await")).default
}));
16 changes: 16 additions & 0 deletions e2e/vite6/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "dependencies-vite6",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"private": true,
"devDependencies": {
"@vitejs/plugin-legacy": "^6",
"vite": "6",
"vite-plugin-top-level-await": "^1.1.1"
},
"dependencies": {
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0"
}
}
13 changes: 13 additions & 0 deletions e2e/vite6/patches/vite+6.0.4.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/vite/dist/node/chunks/dep-BZMjGe_U.js b/node_modules/vite/dist/node/chunks/dep-BZMjGe_U.js
index 8645620..820fd3e 100644
--- a/node_modules/vite/dist/node/chunks/dep-BZMjGe_U.js
+++ b/node_modules/vite/dist/node/chunks/dep-BZMjGe_U.js
@@ -10284,7 +10284,7 @@ function deepClone(value) {
return value;
}
if (value instanceof RegExp) {
- return structuredClone(value);
+ return new RegExp(value);
}
if (typeof value === "object" && value != null) {
throw new Error("Cannot deep clone non-plain object");
1,997 changes: 1,997 additions & 0 deletions e2e/vite6/yarn.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,21 @@
"@types/jest": "^29.5.11",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"esbuild": "^0.19.8",
"mime": "^4.0.0",
"express": "^4.18.2",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"mime": "^4.0.0",
"playwright": "1.23.3",
"playwright-core": "1.23.3",
"prettier": "^3.1.0",
"terser": "^5.26.0",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"vite": "5",
"vite": "6",
"wait-port": "^1.1.0"
},
"peerDependencies": {
"vite": "^2 || ^3 || ^4 || ^5"
"vite": "^2 || ^3 || ^4 || ^5 || ^6"
},
"config": {
"commitizen": {
Expand Down
7 changes: 5 additions & 2 deletions src/esbuild-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import path from "path";
import { Plugin } from "esbuild";
import type { ResolvedConfig } from "vite";
import { createRequire } from "module";

import * as wasmHelper from "./wasm-helper";
import { generateGlueCode } from "./wasm-parser";
import { createBase64UriForWasm } from "./util";

export function esbuildPlugin(): Plugin {
type ESBuildOptions = ResolvedConfig["optimizeDeps"]["esbuildOptions"];
type ESBuildPlugin = ESBuildOptions["plugins"][number];

export function esbuildPlugin(): ESBuildPlugin {
return {
name: "vite-plugin-wasm",
setup(build) {
Expand Down
Loading

0 comments on commit 98427b6

Please sign in to comment.