@crxjs/vite-plugin 2.0.0-beta.15 → 2.0.0-beta.17
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/client.d.ts +15 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +38 -7
- package/package.json +8 -6
package/client.d.ts
CHANGED
|
@@ -57,3 +57,18 @@ declare module '*?script&module' {
|
|
|
57
57
|
const fileName: string
|
|
58
58
|
export default fileName
|
|
59
59
|
}
|
|
60
|
+
|
|
61
|
+
declare namespace ContentScriptAPI {
|
|
62
|
+
export interface ExecuteFnOptions {
|
|
63
|
+
perf: {
|
|
64
|
+
injectTime: number
|
|
65
|
+
loadTime: number
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
export interface ExecuteFn {
|
|
69
|
+
(options: ExecuteFnOptions): void
|
|
70
|
+
}
|
|
71
|
+
export interface ModuleExports {
|
|
72
|
+
onExecute?: ExecuteFn
|
|
73
|
+
}
|
|
74
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -118,12 +118,12 @@ interface ManifestV3 {
|
|
|
118
118
|
} | undefined;
|
|
119
119
|
incognito?: string | undefined;
|
|
120
120
|
input_components?: {
|
|
121
|
-
name
|
|
122
|
-
type?: string | undefined;
|
|
121
|
+
name: string;
|
|
123
122
|
id?: string | undefined;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
123
|
+
language?: string | string[] | undefined;
|
|
124
|
+
layouts?: string | string[] | undefined;
|
|
125
|
+
input_view?: string | undefined;
|
|
126
|
+
options_page?: string | undefined;
|
|
127
127
|
}[] | undefined;
|
|
128
128
|
key?: string | undefined;
|
|
129
129
|
minimum_chrome_version?: string | undefined;
|
package/dist/index.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { rollup } from 'rollup';
|
|
|
10
10
|
import * as lexer from 'es-module-lexer';
|
|
11
11
|
import { readFile as readFile$1 } from 'fs/promises';
|
|
12
12
|
import MagicString from 'magic-string';
|
|
13
|
+
import convertSourceMap from 'convert-source-map';
|
|
13
14
|
import { createLogger } from 'vite';
|
|
14
15
|
import { readFileSync, existsSync, promises } from 'fs';
|
|
15
16
|
import { createRequire } from 'module';
|
|
@@ -337,9 +338,9 @@ const pluginBackground = () => {
|
|
|
337
338
|
|
|
338
339
|
var contentHmrPort = "function isCrxHMRPayload(x) {\n return x.type === \"custom\" && x.event.startsWith(\"crx:\");\n}\nclass HMRPort {\n port;\n callbacks = /* @__PURE__ */ new Map();\n constructor() {\n setInterval(() => {\n try {\n this.port?.postMessage({ data: \"ping\" });\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"Extension context invalidated.\")) {\n location.reload();\n } else\n throw error;\n }\n }, __CRX_HMR_TIMEOUT__);\n setInterval(this.initPort, 5 * 60 * 1e3);\n this.initPort();\n }\n initPort = () => {\n this.port?.disconnect();\n this.port = chrome.runtime.connect({ name: \"@crx/client\" });\n this.port.onDisconnect.addListener(this.handleDisconnect.bind(this));\n this.port.onMessage.addListener(this.handleMessage.bind(this));\n this.port.postMessage({ type: \"connected\" });\n };\n handleDisconnect = () => {\n if (this.callbacks.has(\"close\"))\n for (const cb of this.callbacks.get(\"close\")) {\n cb({ wasClean: true });\n }\n };\n handleMessage = (message) => {\n const forward = (data) => {\n if (this.callbacks.has(\"message\"))\n for (const cb of this.callbacks.get(\"message\")) {\n cb({ data });\n }\n };\n const payload = JSON.parse(message.data);\n if (isCrxHMRPayload(payload)) {\n if (payload.event === \"crx:runtime-reload\") {\n console.log(\"[crx] runtime reload\");\n setTimeout(() => location.reload(), 500);\n } else {\n forward(JSON.stringify(payload.data));\n }\n } else {\n forward(message.data);\n }\n };\n addEventListener = (event, callback) => {\n const cbs = this.callbacks.get(event) ?? /* @__PURE__ */ new Set();\n cbs.add(callback);\n this.callbacks.set(event, cbs);\n };\n send = (data) => {\n if (this.port)\n this.port.postMessage({ data });\n else\n throw new Error(\"HMRPort is not initialized\");\n };\n}\n\nexport { HMRPort };\n";
|
|
339
340
|
|
|
340
|
-
var contentDevLoader = "(function () {\n 'use strict';\n\n (async () => {\n if (__PREAMBLE__)\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__PREAMBLE__)\n );\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__CLIENT__)\n );\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n })().catch(console.error);\n\n})();\n";
|
|
341
|
+
var contentDevLoader = "(function () {\n 'use strict';\n\n const injectTime = performance.now();\n (async () => {\n if (__PREAMBLE__)\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__PREAMBLE__)\n );\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__CLIENT__)\n );\n const { onExecute } = await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });\n })().catch(console.error);\n\n})();\n";
|
|
341
342
|
|
|
342
|
-
var contentProLoader = "(function () {\n 'use strict';\n\n (async () => {\n await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n })().catch(console.error);\n\n})();\n";
|
|
343
|
+
var contentProLoader = "(function () {\n 'use strict';\n\n const injectTime = performance.now();\n (async () => {\n const { onExecute } = await import(\n /* @vite-ignore */\n chrome.runtime.getURL(__SCRIPT__)\n );\n onExecute?.({ perf: { injectTime, loadTime: performance.now() - injectTime } });\n })().catch(console.error);\n\n})();\n";
|
|
343
344
|
|
|
344
345
|
const contentScripts = new RxMap();
|
|
345
346
|
contentScripts.change$.pipe(filter(RxMap.isChangeType.set)).subscribe(({ map, value }) => {
|
|
@@ -441,8 +442,25 @@ function prepScript(fileName, script) {
|
|
|
441
442
|
const transformResult = await server.transformRequest(viteUrl);
|
|
442
443
|
if (!transformResult)
|
|
443
444
|
throw new TypeError(`Unable to load "${script.id}" from server.`);
|
|
444
|
-
const {
|
|
445
|
-
|
|
445
|
+
const { deps = [], dynamicDeps = [], map: map2 } = transformResult;
|
|
446
|
+
let { code } = transformResult;
|
|
447
|
+
try {
|
|
448
|
+
if (map2 && server.config.build.sourcemap === "inline") {
|
|
449
|
+
code = code.replace(/\n*\/\/# sourceMappingURL=[^\n]+/g, "");
|
|
450
|
+
const sourceMap = convertSourceMap.fromObject(map2).toComment();
|
|
451
|
+
code += `
|
|
452
|
+
${sourceMap}
|
|
453
|
+
`;
|
|
454
|
+
}
|
|
455
|
+
} catch (error) {
|
|
456
|
+
console.warn("Failed to inline source map", error);
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
target,
|
|
460
|
+
code,
|
|
461
|
+
deps: [...deps, ...dynamicDeps].flat(),
|
|
462
|
+
server
|
|
463
|
+
};
|
|
446
464
|
}),
|
|
447
465
|
// retry in case of dependency rebundle
|
|
448
466
|
retry({ count: 10, delay: 100 }),
|
|
@@ -649,6 +667,19 @@ const pluginContentScripts = () => {
|
|
|
649
667
|
name: "crx:content-scripts",
|
|
650
668
|
apply: "build",
|
|
651
669
|
enforce: "pre",
|
|
670
|
+
config(config) {
|
|
671
|
+
return {
|
|
672
|
+
...config,
|
|
673
|
+
build: {
|
|
674
|
+
...config.build,
|
|
675
|
+
rollupOptions: {
|
|
676
|
+
...config.build?.rollupOptions,
|
|
677
|
+
// keep exports for content script module api
|
|
678
|
+
preserveEntrySignatures: config.build?.rollupOptions?.preserveEntrySignatures ?? "exports-only"
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
},
|
|
652
683
|
generateBundle() {
|
|
653
684
|
for (const [key, script] of contentScripts)
|
|
654
685
|
if (key === script.refId) {
|
|
@@ -1555,7 +1586,7 @@ const pluginManifest = () => {
|
|
|
1555
1586
|
}
|
|
1556
1587
|
}
|
|
1557
1588
|
const encoded = encodeManifest(manifest2);
|
|
1558
|
-
return encoded;
|
|
1589
|
+
return { code: encoded, map: null };
|
|
1559
1590
|
},
|
|
1560
1591
|
async generateBundle(options, bundle) {
|
|
1561
1592
|
const manifestName = this.getFileName(refId);
|
|
@@ -1662,10 +1693,10 @@ Public dir: "${config.publicDir}"`
|
|
|
1662
1693
|
this.emitFile({
|
|
1663
1694
|
type: "asset",
|
|
1664
1695
|
fileName: "manifest.json",
|
|
1665
|
-
source: JSON.stringify(manifest2, null, 2)
|
|
1696
|
+
source: JSON.stringify(manifest2, null, 2) + "\n"
|
|
1666
1697
|
});
|
|
1667
1698
|
} else {
|
|
1668
|
-
manifestJson.source = JSON.stringify(manifest2, null, 2);
|
|
1699
|
+
manifestJson.source = JSON.stringify(manifest2, null, 2) + "\n";
|
|
1669
1700
|
}
|
|
1670
1701
|
delete bundle[manifestName];
|
|
1671
1702
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crxjs/vite-plugin",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.17",
|
|
4
4
|
"description": "Build Chrome Extensions with this Vite plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -68,6 +68,7 @@
|
|
|
68
68
|
"acorn-walk": "^8.2.0",
|
|
69
69
|
"cheerio": "^1.0.0-rc.10",
|
|
70
70
|
"connect-injector": "^0.4.4",
|
|
71
|
+
"convert-source-map": "^1.7.0",
|
|
71
72
|
"debug": "^4.3.3",
|
|
72
73
|
"es-module-lexer": "^0.10.0",
|
|
73
74
|
"fast-glob": "^3.2.11",
|
|
@@ -89,6 +90,7 @@
|
|
|
89
90
|
"@sveltejs/vite-plugin-svelte": "1.1.0",
|
|
90
91
|
"@types/acorn": "4.0.6",
|
|
91
92
|
"@types/chrome": "0.0.209",
|
|
93
|
+
"@types/convert-source-map": "^2.0.0",
|
|
92
94
|
"@types/debug": "4.1.7",
|
|
93
95
|
"@types/fs-extra": "9.0.13",
|
|
94
96
|
"@types/jest-image-snapshot": "^5.1.0",
|
|
@@ -101,13 +103,13 @@
|
|
|
101
103
|
"@vitejs/plugin-react": "^2.1.0",
|
|
102
104
|
"@vitejs/plugin-vue": "3.2.0",
|
|
103
105
|
"chokidar": "^3.5.3",
|
|
104
|
-
"esbuild": "0.17.
|
|
106
|
+
"esbuild": "0.17.14",
|
|
105
107
|
"esbuild-runner": "2.2.2",
|
|
106
|
-
"eslint": "8.
|
|
108
|
+
"eslint": "8.39.0",
|
|
107
109
|
"eslint-plugin-react": "^7.29.4",
|
|
108
110
|
"jest-image-snapshot": "^5.2.0",
|
|
109
111
|
"npm-run-all": "^4.1.5",
|
|
110
|
-
"playwright-chromium": "1.
|
|
112
|
+
"playwright-chromium": "1.33.0",
|
|
111
113
|
"react": "17.0.2",
|
|
112
114
|
"react-dom": "17.0.2",
|
|
113
115
|
"rimraf": "3.0.2",
|
|
@@ -116,8 +118,8 @@
|
|
|
116
118
|
"svelte": "^3.48.0",
|
|
117
119
|
"typescript": "^4.6.4",
|
|
118
120
|
"vite": "^3.1.7",
|
|
119
|
-
"vite-plugin-inspect": "0.7.
|
|
121
|
+
"vite-plugin-inspect": "0.7.25",
|
|
120
122
|
"vitest": "0.28.5",
|
|
121
|
-
"vue": "3.2.
|
|
123
|
+
"vue": "3.2.47"
|
|
122
124
|
}
|
|
123
125
|
}
|