Skip to content

Commit 1c9ae7c

Browse files
authoredMar 11, 2023
feat!: Vite 4 Support (#81)
BREAKING CHANGE: Vite 4 plugins have different types and cannot be used with Vite 3.
1 parent 503db0f commit 1c9ae7c

File tree

22 files changed

+194
-125
lines changed

22 files changed

+194
-125
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm-lock.yaml linguist-generated

‎package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"body-parser",
1919
"download",
2020
"express",
21-
"safe-compare"
21+
"safe-compare",
22+
"@algolia/client-search"
2223
]
2324
}
2425
}

‎packages/create-vite-plugin-web-extension/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"@types/tmp": "^0.2.3",
2929
"@types/webextension-polyfill": "^0.9.0",
3030
"@vitejs/plugin-react-swc": "^3.0.1",
31-
"@vitejs/plugin-vue": "^2.1.0",
31+
"@vitejs/plugin-vue": "^4.0.0",
3232
"tsup": "^5.5.0",
3333
"tsx": "^3.12.1",
3434
"typescript": "^4.4.4",
35-
"vite": "3.1.2",
35+
"vite": "^4.1.4",
3636
"vite-plugin-web-extension": "workspace:*",
3737
"vue": "^3.2.45",
3838
"vue-tsc": "^1.0.16"

‎packages/create-vite-plugin-web-extension/templates/react-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@vitejs/plugin-react-swc": "^3.0.0",
16-
"vite": "^4.0.0",
16+
"vite": "^4.1.4",
1717
"vite-plugin-web-extension": "^1.4.9",
1818
"webextension-polyfill": "^0.10.0"
1919
}

‎packages/create-vite-plugin-web-extension/templates/react-ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@types/webextension-polyfill": "^0.9.0",
1818
"@vitejs/plugin-react-swc": "^3.0.0",
1919
"typescript": "^4.9.3",
20-
"vite": "^4.0.0",
20+
"vite": "^4.1.4",
2121
"vite-plugin-web-extension": "^1.4.9",
2222
"webextension-polyfill": "^0.10.0"
2323
}

‎packages/create-vite-plugin-web-extension/templates/vanilla-js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"build": "vite build"
99
},
1010
"devDependencies": {
11-
"vite": "^3.2.5",
11+
"vite": "^4.1.4",
1212
"vite-plugin-web-extension": "^2.0.2",
1313
"webextension-polyfill": "^0.10.0"
1414
}

‎packages/create-vite-plugin-web-extension/templates/vanilla-ts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"devDependencies": {
1212
"@types/webextension-polyfill": "^0.10.0",
1313
"typescript": "^4.9.5",
14-
"vite": "^3.2.5",
14+
"vite": "^4.1.4",
1515
"vite-plugin-web-extension": "^2.0.2",
1616
"webextension-polyfill": "^0.10.0"
1717
}

‎packages/create-vite-plugin-web-extension/templates/vue-js/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"vue": "^3.2.47"
1212
},
1313
"devDependencies": {
14-
"@vitejs/plugin-vue": "^3.2.0",
15-
"vite": "^3.2.5",
14+
"@vitejs/plugin-vue": "^4.0.0",
15+
"vite": "^4.1.4",
1616
"vite-plugin-web-extension": "^2.0.2",
1717
"webextension-polyfill": "^0.10.0"
1818
}

‎packages/create-vite-plugin-web-extension/templates/vue-ts/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
},
1313
"devDependencies": {
1414
"@types/webextension-polyfill": "^0.10.0",
15-
"@vitejs/plugin-vue": "^3.2.0",
15+
"@vitejs/plugin-vue": "^4.0.0",
1616
"typescript": "^4.9.5",
17-
"vite": "^3.2.5",
17+
"vite": "^4.1.4",
1818
"vite-plugin-web-extension": "^2.0.2",
1919
"vue-tsc": "^1.2.0",
2020
"webextension-polyfill": "^0.10.0"

‎packages/demo-localization/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"devDependencies": {
99
"typescript": "^4.4.4",
10-
"vite": "3.1.2",
10+
"vite": "^4.1.4",
1111
"vite-plugin-web-extension": "workspace:*"
1212
}
1313
}

‎packages/demo-vanilla/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@types/lodash.debounce": "^4.0.6",
1717
"sass": "^1.49.9",
1818
"typescript": "^4.4.4",
19-
"vite": "3.1.2",
19+
"vite": "^4.1.4",
2020
"vite-plugin-web-extension": "workspace:*"
2121
}
2222
}

‎packages/demo-vue/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
},
1414
"devDependencies": {
1515
"@types/lodash.debounce": "^4.0.6",
16-
"@vitejs/plugin-vue": "^3.0.0",
16+
"@vitejs/plugin-vue": "^4.0.0",
1717
"@vue/compiler-sfc": "^3.2.25",
1818
"typescript": "^4.4.4",
19-
"vite": "3.1.2",
19+
"vite": "^4.1.4",
2020
"vite-plugin-web-extension": "workspace:*",
2121
"vue": "^3.2.25"
2222
}

‎packages/e2e/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"cross-env": "^7.0.3",
1212
"sass": "^1.49.9",
1313
"typescript": "^4.4.4",
14-
"vite": "3.1.2",
14+
"vite": "^4.1.4",
1515
"vite-plugin-web-extension": "workspace:*",
1616
"vitest": "^0.23.2"
1717
}

‎packages/vite-plugin-web-extension/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"lodash.uniq": "^4.5.0",
4646
"lodash.uniqby": "^4.7.0",
4747
"md5": "^2.3.0",
48+
"vite": "^4.1.4",
4849
"web-ext": "^7.2.0",
4950
"webextension-polyfill": "^0.10.0",
5051
"yaml": "^2.2.1"
@@ -57,13 +58,12 @@
5758
"@types/md5": "^2.3.1",
5859
"@types/node": "^16.11.6",
5960
"@types/webextension-polyfill": "^0.9.0",
60-
"rollup": "2.78.1",
61+
"rollup": "3.15.0",
6162
"tsup": "^6.5.0",
6263
"typescript": "^4.4.4",
63-
"vite": "3.1.2",
6464
"vitest": "^0.28.4"
6565
},
6666
"peerDependencies": {
67-
"vite": "^3"
67+
"vite": "^4"
6868
}
69-
}
69+
}

‎packages/vite-plugin-web-extension/src/build/build-context.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export function createBuildContext({
144144

145145
function waitForWatchBuildComplete(watcher: rollup.RollupWatcher) {
146146
return new Promise<void>((res, rej) => {
147-
watcher.addListener("event", async (e) => {
147+
watcher.on("event", async (e) => {
148148
switch (e.code) {
149149
case "END":
150150
res();
@@ -174,7 +174,7 @@ export function createBuildContext({
174174
(config.plugins ??= []).push(bundleTracker);
175175

176176
const output = await vite.build(config);
177-
if ("addListener" in output) {
177+
if ("on" in output) {
178178
activeWatchers.push(output);
179179
// In watch mode, wait until it's built once
180180
await waitForWatchBuildComplete(output);

‎packages/vite-plugin-web-extension/src/build/getViteConfigsForInputs.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import path from "node:path";
22
import * as vite from "vite";
3-
import { V } from "vitest/dist/global-fe52f84b";
43
import type browser from "webextension-polyfill";
54
import { Logger } from "../logger";
65
import { ProjectPaths, Manifest } from "../options";

‎packages/vite-plugin-web-extension/src/build/renderManifest.test.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { describe, expect, it } from "vitest";
2-
import { Manifest } from "webextension-polyfill";
32
import { renderManifest, BundleMap } from "./renderManifest";
43

54
describe("renderManifest", () => {

‎packages/vite-plugin-web-extension/src/plugins/bundle-tracker-plugin.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as rollup from "rollup";
21
import * as vite from "vite";
32
import { BUNDLE_TRACKER_PLUGIN_NAME } from "../constants";
43

‎packages/vite-plugin-web-extension/src/plugins/manifest-loader-plugin.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
import path from "node:path";
1616
import fs from "fs-extra";
1717
import { inspect } from "node:util";
18-
import * as rollup from "rollup";
19-
import type browser from "webextension-polyfill";
2018
import { createWebExtRunner, ExtensionRunner } from "../extension-runner";
2119
import { createManifestValidator } from "../manifest-validation";
2220
import { ContentSecurityPolicy } from "../csp";
@@ -223,12 +221,17 @@ export function manifestLoaderPlugin(options: ResolvedOptions): vite.Plugin {
223221
isError = err != null;
224222
},
225223

226-
// Runs during: build, watch
224+
// Runs during: build, watch, dev (only when pressing ctrl+C to stop server)
227225
async closeBundle() {
228226
if (isError || mode === BuildMode.BUILD || options.disableAutoLaunch) {
229227
return;
230228
}
231229

230+
// Vite4 handles SIGINT (ctrl+C) in dev mode and calls closeBundle after stopping the server.
231+
// So we need to manually close the open browser.
232+
if (mode === BuildMode.DEV) return await extensionRunner.exit();
233+
234+
// This is where we open the browser in watch mode.
232235
await openBrowser();
233236
},
234237

‎packages/vite-plugin-web-extension/src/utils.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,10 @@ describe("Utils", () => {
257257
});
258258

259259
it("should work with Vite library options", () => {
260-
const inputRecord: vite.LibraryOptions = { entry: "src/test.ts" };
261-
const expected = [inputRecord.entry];
260+
const inputRecord: vite.LibraryOptions = {
261+
entry: ["src/test.ts", "test2.ts"],
262+
};
263+
const expected = inputRecord.entry;
262264

263265
const actual = getInputPaths(paths, inputRecord);
264266

‎packages/vite-plugin-web-extension/src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ export function getInputPaths(
131131
let inputs: string[];
132132
if (typeof input === "string") inputs = [input];
133133
else if (Array.isArray(input)) inputs = input;
134-
else if ("entry" in input) inputs = [input.entry];
134+
else if ("entry" in input)
135+
inputs = getInputPaths(paths, (input as vite.LibraryOptions).entry);
135136
else inputs = Object.values(input);
136137

137138
return inputs.map((file) => {

‎pnpm-lock.yaml

+158-94
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.