@crxjs/vite-plugin 2.0.0-beta.11 → 2.0.0-beta.12
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.mjs +27 -0
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -24,8 +24,10 @@ const pluginOptionsProvider = (options) => {
|
|
|
24
24
|
name: pluginName$1,
|
|
25
25
|
api: {
|
|
26
26
|
crx: {
|
|
27
|
+
// during testing this can be null, we don't provide options through the test config
|
|
27
28
|
options
|
|
28
29
|
}
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
31
|
}
|
|
30
32
|
};
|
|
31
33
|
};
|
|
@@ -292,6 +294,7 @@ const pluginBackground = () => {
|
|
|
292
294
|
},
|
|
293
295
|
{
|
|
294
296
|
name: "crx:background-loader-file",
|
|
297
|
+
// this should happen after other plugins; the loader file is an implementation detail
|
|
295
298
|
enforce: "post",
|
|
296
299
|
configResolved(_config) {
|
|
297
300
|
config = _config;
|
|
@@ -318,6 +321,7 @@ const pluginBackground = () => {
|
|
|
318
321
|
}
|
|
319
322
|
const refId = this.emitFile({
|
|
320
323
|
type: "asset",
|
|
324
|
+
// fileName b/c service worker must be at root of crx
|
|
321
325
|
fileName: getFileName({ type: "loader", id: "service-worker" }),
|
|
322
326
|
source: loader
|
|
323
327
|
});
|
|
@@ -426,6 +430,7 @@ function prepAsset(fileName, { id, source }) {
|
|
|
426
430
|
}
|
|
427
431
|
function prepScript(fileName, script) {
|
|
428
432
|
return ($) => $.pipe(
|
|
433
|
+
// get script contents from dev server
|
|
429
434
|
mergeMap(async ({ server }) => {
|
|
430
435
|
const target = getOutputPath(server, fileName);
|
|
431
436
|
const viteUrl = getViteUrl(script);
|
|
@@ -435,7 +440,9 @@ function prepScript(fileName, script) {
|
|
|
435
440
|
const { code, deps = [], dynamicDeps = [] } = transformResult;
|
|
436
441
|
return { target, code, deps: [...deps, ...dynamicDeps].flat(), server };
|
|
437
442
|
}),
|
|
443
|
+
// retry in case of dependency rebundle
|
|
438
444
|
retry({ count: 10, delay: 100 }),
|
|
445
|
+
// patch content scripts
|
|
439
446
|
mergeMap(async ({ target, server, ...rest }) => {
|
|
440
447
|
const plugins = server.config.plugins;
|
|
441
448
|
let { code, deps } = rest;
|
|
@@ -527,8 +534,11 @@ function update(_id) {
|
|
|
527
534
|
async function write(fileId) {
|
|
528
535
|
const start2 = performance.now();
|
|
529
536
|
const deps = await firstValueFrom(
|
|
537
|
+
// wait for start event
|
|
530
538
|
start$.pipe(
|
|
539
|
+
// prepare either asset or script contents
|
|
531
540
|
prepFileData(fileId),
|
|
541
|
+
// output file and add dependencies to file writer
|
|
532
542
|
mergeMap(async ({ target, source, deps: deps2 }) => {
|
|
533
543
|
const files = deps2.map((id) => {
|
|
534
544
|
const r = [add({ id, type: "module" })];
|
|
@@ -544,6 +554,7 @@ async function write(fileId) {
|
|
|
544
554
|
await outputFile(target, source, { encoding: "utf8" });
|
|
545
555
|
return files;
|
|
546
556
|
}),
|
|
557
|
+
// abort write operation on close event
|
|
547
558
|
takeUntil(close$),
|
|
548
559
|
concatWith(of([]))
|
|
549
560
|
)
|
|
@@ -816,6 +827,12 @@ const pluginDynamicContentScripts = () => {
|
|
|
816
827
|
{
|
|
817
828
|
name: "crx:dynamic-content-scripts-build",
|
|
818
829
|
apply: "build",
|
|
830
|
+
/**
|
|
831
|
+
* Replace dynamic script placeholders during build.
|
|
832
|
+
*
|
|
833
|
+
* Can't use `renderChunk` b/c pre plugin crx:content-scripts uses
|
|
834
|
+
* `generateBundle` to emit loaders. Must come after "enforce: pre".
|
|
835
|
+
*/
|
|
819
836
|
generateBundle(options, bundle) {
|
|
820
837
|
for (const chunk of Object.values(bundle))
|
|
821
838
|
if (chunk.type === "chunk") {
|
|
@@ -1084,6 +1101,7 @@ const pluginHMR = () => {
|
|
|
1084
1101
|
name: "crx:hmr",
|
|
1085
1102
|
apply: "serve",
|
|
1086
1103
|
enforce: "pre",
|
|
1104
|
+
// server hmr host should be localhost
|
|
1087
1105
|
async config({ server = {}, ...config2 }) {
|
|
1088
1106
|
if (server.hmr === false)
|
|
1089
1107
|
return;
|
|
@@ -1093,6 +1111,7 @@ const pluginHMR = () => {
|
|
|
1093
1111
|
server.hmr.host = "localhost";
|
|
1094
1112
|
return { server, ...config2 };
|
|
1095
1113
|
},
|
|
1114
|
+
// server should ignore outdir
|
|
1096
1115
|
configResolved(_config) {
|
|
1097
1116
|
config = _config;
|
|
1098
1117
|
const { watch = {} } = config.server;
|
|
@@ -1130,6 +1149,7 @@ const pluginHMR = () => {
|
|
|
1130
1149
|
closeBundle() {
|
|
1131
1150
|
subs.unsubscribe();
|
|
1132
1151
|
},
|
|
1152
|
+
// background changes require a full extension reload
|
|
1133
1153
|
handleHotUpdate({ modules, server }) {
|
|
1134
1154
|
const { root } = server.config;
|
|
1135
1155
|
const relFiles = /* @__PURE__ */ new Set();
|
|
@@ -1157,6 +1177,7 @@ const pluginHMR = () => {
|
|
|
1157
1177
|
name: "crx:hmr",
|
|
1158
1178
|
apply: "serve",
|
|
1159
1179
|
enforce: "post",
|
|
1180
|
+
// get final output manifest for handleHotUpdate 👆
|
|
1160
1181
|
async transformCrxManifest(manifest) {
|
|
1161
1182
|
inputManifestFiles = await manifestFiles(manifest, { cwd: config.root });
|
|
1162
1183
|
return null;
|
|
@@ -1247,6 +1268,7 @@ const pluginHtmlInlineScripts = () => {
|
|
|
1247
1268
|
};
|
|
1248
1269
|
const postPlugin = {
|
|
1249
1270
|
name: "crx:html-auditor-post",
|
|
1271
|
+
// this hook isn't audited b/c we add it after we set up the auditors
|
|
1250
1272
|
transformIndexHtml(html, ctx) {
|
|
1251
1273
|
const key = toKey(ctx);
|
|
1252
1274
|
const p = pages.get(key);
|
|
@@ -1591,6 +1613,7 @@ Public dir: "${config.publicDir}"`
|
|
|
1591
1613
|
this.emitFile({
|
|
1592
1614
|
type: "asset",
|
|
1593
1615
|
fileName: f,
|
|
1616
|
+
// TODO: cache source buffer
|
|
1594
1617
|
source: await readFile(filename)
|
|
1595
1618
|
});
|
|
1596
1619
|
}
|
|
@@ -1703,8 +1726,11 @@ const pluginWebAccessibleResources = () => {
|
|
|
1703
1726
|
...rest
|
|
1704
1727
|
})).filter(({ resources }) => resources.length);
|
|
1705
1728
|
manifest.web_accessible_resources.push({
|
|
1729
|
+
// change the extension origin on every reload
|
|
1706
1730
|
use_dynamic_url: true,
|
|
1731
|
+
// all web origins can access
|
|
1707
1732
|
matches: ["<all_urls>"],
|
|
1733
|
+
// all resources are web accessible
|
|
1708
1734
|
resources: ["**/*", "*"]
|
|
1709
1735
|
});
|
|
1710
1736
|
return manifest;
|
|
@@ -1834,6 +1860,7 @@ const pluginWebAccessibleResources = () => {
|
|
|
1834
1860
|
};
|
|
1835
1861
|
|
|
1836
1862
|
const crx = (options) => {
|
|
1863
|
+
contentScripts.clear();
|
|
1837
1864
|
return [
|
|
1838
1865
|
pluginOptionsProvider(options),
|
|
1839
1866
|
pluginBackground(),
|
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.12",
|
|
4
4
|
"description": "Build Chrome Extensions with this Vite plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"@vitejs/plugin-react": "^2.1.0",
|
|
102
102
|
"@vitejs/plugin-vue": "3.2.0",
|
|
103
103
|
"chokidar": "^3.5.3",
|
|
104
|
-
"esbuild": "0.
|
|
104
|
+
"esbuild": "0.17.4",
|
|
105
105
|
"esbuild-runner": "2.2.2",
|
|
106
106
|
"eslint": "8.26.0",
|
|
107
107
|
"eslint-plugin-react": "^7.29.4",
|
|
@@ -116,7 +116,7 @@
|
|
|
116
116
|
"svelte": "^3.48.0",
|
|
117
117
|
"typescript": "^4.6.4",
|
|
118
118
|
"vite": "^3.1.7",
|
|
119
|
-
"vite-plugin-inspect": "0.7.
|
|
119
|
+
"vite-plugin-inspect": "0.7.14",
|
|
120
120
|
"vitest": "0.24.3",
|
|
121
121
|
"vue": "3.2.41"
|
|
122
122
|
}
|