@crxjs/vite-plugin 2.0.0-beta.23 → 2.0.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.mjs +10 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const defineManifest = (manifest) => manifest;
|
|
6
6
|
const defineDynamicResource = ({
|
|
7
7
|
matches = ["http://*/*", "https://*/*"],
|
|
8
|
-
use_dynamic_url =
|
|
8
|
+
use_dynamic_url = false
|
|
9
9
|
}) => ({
|
|
10
10
|
matches,
|
|
11
11
|
resources: [DYNAMIC_RESOURCE],
|
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,12 @@ interface ManifestV3 {
|
|
|
33
33
|
description?: string | undefined;
|
|
34
34
|
icons?: chrome.runtime.ManifestIcons | undefined;
|
|
35
35
|
action?: chrome.runtime.ManifestAction | undefined;
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* @see https://developer.chrome.com/docs/extensions/reference/manifest/author
|
|
38
|
+
*/
|
|
39
|
+
author?: {
|
|
40
|
+
email: string;
|
|
41
|
+
} | undefined;
|
|
37
42
|
background?: ChromeManifestBackground | FirefoxManifestBackground | undefined;
|
|
38
43
|
chrome_settings_overrides?: {
|
|
39
44
|
homepage?: string | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -59,7 +59,7 @@ function isCrxPlugin(p) {
|
|
|
59
59
|
return !!p && typeof p === "object" && !(p instanceof Promise) && !Array.isArray(p) && p.name.startsWith("crx:");
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
var workerHmrClient = "const ownOrigin =
|
|
62
|
+
var workerHmrClient = "const ownOrigin = `chrome-extension://${chrome.runtime.id}`;\nself.addEventListener(\"fetch\", (fetchEvent) => {\n const url = new URL(fetchEvent.request.url);\n if (url.origin === ownOrigin) {\n fetchEvent.respondWith(sendToServer(url));\n }\n});\nasync function sendToServer(url) {\n url.protocol = \"http:\";\n url.host = \"localhost\";\n url.port = __SERVER_PORT__;\n url.searchParams.set(\"t\", Date.now().toString());\n const response = await fetch(url.href.replace(/=$|=(?=&)/g, \"\"));\n return new Response(response.body, {\n headers: {\n \"Content-Type\": response.headers.get(\"Content-Type\") ?? \"text/javascript\"\n }\n });\n}\nconst ports = /* @__PURE__ */ new Set();\nchrome.runtime.onConnect.addListener((port) => {\n if (port.name === \"@crx/client\") {\n ports.add(port);\n port.onDisconnect.addListener((port2) => ports.delete(port2));\n port.onMessage.addListener((message) => {\n });\n port.postMessage({ data: JSON.stringify({ type: \"connected\" }) });\n }\n});\nfunction notifyContentScripts(payload) {\n const data = JSON.stringify(payload);\n for (const port of ports)\n port.postMessage({ data });\n}\nconsole.log(\"[vite] connecting...\");\nconst socketProtocol = __HMR_PROTOCOL__ || (location.protocol === \"https:\" ? \"wss\" : \"ws\");\nconst socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${__HMR_PORT__}`;\nconst socket = new WebSocket(`${socketProtocol}://${socketHost}`, \"vite-hmr\");\nconst base = __BASE__ || \"/\";\nsocket.addEventListener(\"message\", async ({ data }) => {\n handleSocketMessage(JSON.parse(data));\n});\nfunction isCrxHmrPayload(x) {\n return x.type === \"custom\" && x.event.startsWith(\"crx:\");\n}\nfunction handleSocketMessage(payload) {\n if (isCrxHmrPayload(payload)) {\n handleCrxHmrPayload(payload);\n } else if (payload.type === \"connected\") {\n console.log(`[vite] connected.`);\n const interval = setInterval(() => socket.send(\"ping\"), __HMR_TIMEOUT__);\n socket.addEventListener(\"close\", () => clearInterval(interval));\n }\n}\nfunction handleCrxHmrPayload(payload) {\n notifyContentScripts(payload);\n switch (payload.event) {\n case \"crx:runtime-reload\":\n console.log(\"[crx] runtime reload\");\n chrome.runtime.reload();\n break;\n }\n}\nasync function waitForSuccessfulPing(ms = 1e3) {\n while (true) {\n try {\n await fetch(`${base}__vite_ping`);\n break;\n } catch (e) {\n await new Promise((resolve) => setTimeout(resolve, ms));\n }\n }\n}\nsocket.addEventListener(\"close\", async ({ wasClean }) => {\n if (wasClean)\n return;\n console.log(`[vite] server connection lost. polling for restart...`);\n await waitForSuccessfulPing();\n handleCrxHmrPayload({\n type: \"custom\",\n event: \"crx:runtime-reload\"\n });\n});\n";
|
|
63
63
|
|
|
64
64
|
const _debug = (id) => debug$3("crx").extend(id);
|
|
65
65
|
const structuredClone = (obj) => {
|
|
@@ -1229,10 +1229,15 @@ const pluginHMR = () => {
|
|
|
1229
1229
|
handleHotUpdate({ modules, server }) {
|
|
1230
1230
|
const { root } = server.config;
|
|
1231
1231
|
const relFiles = /* @__PURE__ */ new Set();
|
|
1232
|
-
|
|
1232
|
+
const fsFiles = /* @__PURE__ */ new Set();
|
|
1233
|
+
for (const m of modules) {
|
|
1233
1234
|
if (m.id?.startsWith(root)) {
|
|
1234
1235
|
relFiles.add(m.id.slice(server.config.root.length));
|
|
1236
|
+
} else if (m.url?.startsWith("/@fs")) {
|
|
1237
|
+
fsFiles.add(m.url);
|
|
1235
1238
|
}
|
|
1239
|
+
}
|
|
1240
|
+
fsFiles.forEach((file) => update(file));
|
|
1236
1241
|
if (inputManifestFiles.background.length) {
|
|
1237
1242
|
const background = prefix$1("/", inputManifestFiles.background[0]);
|
|
1238
1243
|
if (relFiles.has(background) || modules.some(isImporter(join(server.config.root, background)))) {
|
|
@@ -1800,7 +1805,7 @@ function compileFileResources(fileName, {
|
|
|
1800
1805
|
const defineManifest = (manifest) => manifest;
|
|
1801
1806
|
const defineDynamicResource = ({
|
|
1802
1807
|
matches = ["http://*/*", "https://*/*"],
|
|
1803
|
-
use_dynamic_url =
|
|
1808
|
+
use_dynamic_url = false
|
|
1804
1809
|
}) => ({
|
|
1805
1810
|
matches,
|
|
1806
1811
|
resources: [DYNAMIC_RESOURCE],
|
|
@@ -1834,7 +1839,7 @@ const pluginWebAccessibleResources = () => {
|
|
|
1834
1839
|
// all resources are web accessible
|
|
1835
1840
|
resources: ["**/*", "*"],
|
|
1836
1841
|
// change the extension origin on every reload
|
|
1837
|
-
use_dynamic_url:
|
|
1842
|
+
use_dynamic_url: false
|
|
1838
1843
|
};
|
|
1839
1844
|
if (browser === "firefox") {
|
|
1840
1845
|
delete war.use_dynamic_url;
|
|
@@ -1916,7 +1921,7 @@ const pluginWebAccessibleResources = () => {
|
|
|
1916
1921
|
const resource = {
|
|
1917
1922
|
matches: isDynamicScript ? [...dynamicScriptMatches] : matches,
|
|
1918
1923
|
resources: [...assets, ...imports],
|
|
1919
|
-
use_dynamic_url: isDynamicScript ? dynamicScriptDynamicUrl :
|
|
1924
|
+
use_dynamic_url: isDynamicScript ? dynamicScriptDynamicUrl : false
|
|
1920
1925
|
};
|
|
1921
1926
|
if (isDynamicScript || !injectCss) {
|
|
1922
1927
|
resource.resources.push(...css);
|