@crxjs/vite-plugin 2.0.0-beta.25 → 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.mjs +4 -4
- 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.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) => {
|
|
@@ -1805,7 +1805,7 @@ function compileFileResources(fileName, {
|
|
|
1805
1805
|
const defineManifest = (manifest) => manifest;
|
|
1806
1806
|
const defineDynamicResource = ({
|
|
1807
1807
|
matches = ["http://*/*", "https://*/*"],
|
|
1808
|
-
use_dynamic_url =
|
|
1808
|
+
use_dynamic_url = false
|
|
1809
1809
|
}) => ({
|
|
1810
1810
|
matches,
|
|
1811
1811
|
resources: [DYNAMIC_RESOURCE],
|
|
@@ -1839,7 +1839,7 @@ const pluginWebAccessibleResources = () => {
|
|
|
1839
1839
|
// all resources are web accessible
|
|
1840
1840
|
resources: ["**/*", "*"],
|
|
1841
1841
|
// change the extension origin on every reload
|
|
1842
|
-
use_dynamic_url:
|
|
1842
|
+
use_dynamic_url: false
|
|
1843
1843
|
};
|
|
1844
1844
|
if (browser === "firefox") {
|
|
1845
1845
|
delete war.use_dynamic_url;
|
|
@@ -1921,7 +1921,7 @@ const pluginWebAccessibleResources = () => {
|
|
|
1921
1921
|
const resource = {
|
|
1922
1922
|
matches: isDynamicScript ? [...dynamicScriptMatches] : matches,
|
|
1923
1923
|
resources: [...assets, ...imports],
|
|
1924
|
-
use_dynamic_url: isDynamicScript ? dynamicScriptDynamicUrl :
|
|
1924
|
+
use_dynamic_url: isDynamicScript ? dynamicScriptDynamicUrl : false
|
|
1925
1925
|
};
|
|
1926
1926
|
if (isDynamicScript || !injectCss) {
|
|
1927
1927
|
resource.resources.push(...css);
|