@crxjs/vite-plugin 1.0.6 → 1.0.9
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/CHANGELOG.md +18 -0
- package/dist/index.cjs +34 -13
- package/dist/index.mjs +30 -9
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @crxjs/vite-plugin
|
|
2
2
|
|
|
3
|
+
## 1.0.9
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8941353: Remove & refactor use of fs-extra
|
|
8
|
+
|
|
9
|
+
## 1.0.8
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 8a09cb9: Optimize rollup input
|
|
14
|
+
|
|
15
|
+
## 1.0.7
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- e1604d8: Strip paths from content script resource match patterns
|
|
20
|
+
|
|
3
21
|
## 1.0.6
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -8,16 +8,16 @@ var crypto = require('crypto');
|
|
|
8
8
|
var debug$5 = require('debug');
|
|
9
9
|
var fg = require('fast-glob');
|
|
10
10
|
var v8 = require('v8');
|
|
11
|
-
var
|
|
11
|
+
var fs = require('fs');
|
|
12
12
|
var MagicString = require('magic-string');
|
|
13
13
|
var path = require('path');
|
|
14
|
+
var fsExtra = require('fs-extra');
|
|
14
15
|
var perf_hooks = require('perf_hooks');
|
|
15
16
|
var colors = require('picocolors');
|
|
16
17
|
var vite = require('vite');
|
|
17
18
|
var module$1 = require('module');
|
|
18
19
|
var cheerio = require('cheerio');
|
|
19
20
|
var jsesc = require('jsesc');
|
|
20
|
-
var fs = require('fs');
|
|
21
21
|
var injector = require('connect-injector');
|
|
22
22
|
|
|
23
23
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -43,8 +43,8 @@ function _interopNamespace(e) {
|
|
|
43
43
|
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug$5);
|
|
44
44
|
var fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
45
45
|
var v8__default = /*#__PURE__*/_interopDefaultLegacy(v8);
|
|
46
|
-
var fsExtra__default = /*#__PURE__*/_interopDefaultLegacy(fsExtra);
|
|
47
46
|
var MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
47
|
+
var fsExtra__default = /*#__PURE__*/_interopDefaultLegacy(fsExtra);
|
|
48
48
|
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
49
49
|
var jsesc__default = /*#__PURE__*/_interopDefaultLegacy(jsesc);
|
|
50
50
|
var injector__default = /*#__PURE__*/_interopDefaultLegacy(injector);
|
|
@@ -132,6 +132,12 @@ function encodeManifest(manifest) {
|
|
|
132
132
|
const json = JSON.stringify(JSON.stringify(manifest));
|
|
133
133
|
return `export default ${json}`;
|
|
134
134
|
}
|
|
135
|
+
const stubMatchPattern = (pattern) => {
|
|
136
|
+
const [schema, rest] = pattern.split("://");
|
|
137
|
+
const [origin, pathname] = rest.split("/");
|
|
138
|
+
const root = `${schema}://${origin}`;
|
|
139
|
+
return pathname ? `${root}/*` : root;
|
|
140
|
+
};
|
|
135
141
|
|
|
136
142
|
const idBySource = /* @__PURE__ */ new Map();
|
|
137
143
|
const idByUrl = /* @__PURE__ */ new Map();
|
|
@@ -212,6 +218,7 @@ const preambleId = "/crx-client-preamble";
|
|
|
212
218
|
const stubId = "/crx-stub";
|
|
213
219
|
const workerClientId = "/crx-client-worker";
|
|
214
220
|
|
|
221
|
+
const { readFile: readFile$2 } = fs.promises;
|
|
215
222
|
const debug$4 = _debug("file-writer").extend("chunks");
|
|
216
223
|
for (const source of [viteClientId, customElementsId]) {
|
|
217
224
|
setUrlMeta(sourceToUrlMeta(source));
|
|
@@ -286,7 +293,7 @@ const pluginFileWriterChunks = () => {
|
|
|
286
293
|
this.emitFile({
|
|
287
294
|
type: "asset",
|
|
288
295
|
fileName: relative(server.config.root, file),
|
|
289
|
-
source: await
|
|
296
|
+
source: await readFile$2(file)
|
|
290
297
|
});
|
|
291
298
|
}
|
|
292
299
|
if (url)
|
|
@@ -2298,6 +2305,7 @@ const pluginFileWriterHtml = () => {
|
|
|
2298
2305
|
};
|
|
2299
2306
|
};
|
|
2300
2307
|
|
|
2308
|
+
const { readFile: readFile$1 } = fs.promises;
|
|
2301
2309
|
const pluginFileWriterPublic = () => {
|
|
2302
2310
|
let config;
|
|
2303
2311
|
return {
|
|
@@ -2311,7 +2319,7 @@ const pluginFileWriterPublic = () => {
|
|
|
2311
2319
|
this.addWatchFile(config.publicDir);
|
|
2312
2320
|
const publicFiles = await fg__default["default"](`${config.publicDir}/**/*`);
|
|
2313
2321
|
for (const file of publicFiles) {
|
|
2314
|
-
const source = await
|
|
2322
|
+
const source = await readFile$1(file);
|
|
2315
2323
|
const fileName = relative(config.publicDir, file);
|
|
2316
2324
|
this.emitFile({ type: "asset", fileName, source });
|
|
2317
2325
|
}
|
|
@@ -2322,8 +2330,8 @@ const pluginFileWriterPublic = () => {
|
|
|
2322
2330
|
|
|
2323
2331
|
const _require = typeof require === "undefined" ? module$1.createRequire((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))) : require;
|
|
2324
2332
|
const customElementsPath = _require.resolve(customElementsId);
|
|
2325
|
-
const customElementsCode =
|
|
2326
|
-
const customElementsMap =
|
|
2333
|
+
const customElementsCode = fs.readFileSync(customElementsPath, "utf8");
|
|
2334
|
+
const customElementsMap = fs.readFileSync(`${customElementsPath}.map`, "utf8");
|
|
2327
2335
|
const pluginFileWriterPolyfill = () => {
|
|
2328
2336
|
return {
|
|
2329
2337
|
name: "crx:file-writer-polyfill",
|
|
@@ -2766,6 +2774,7 @@ const pluginHtmlAuditor = () => {
|
|
|
2766
2774
|
};
|
|
2767
2775
|
};
|
|
2768
2776
|
|
|
2777
|
+
const { readFile } = fs.promises;
|
|
2769
2778
|
const pluginManifest = (_manifest) => () => {
|
|
2770
2779
|
let manifest;
|
|
2771
2780
|
let plugins;
|
|
@@ -2778,17 +2787,28 @@ const pluginManifest = (_manifest) => () => {
|
|
|
2778
2787
|
async config(config2, env) {
|
|
2779
2788
|
manifest = await (typeof _manifest === "function" ? _manifest(env) : _manifest);
|
|
2780
2789
|
if (manifest.manifest_version !== 3)
|
|
2781
|
-
throw new Error(`Manifest v${manifest.manifest_version}
|
|
2790
|
+
throw new Error(`CRXJS does not support Manifest v${manifest.manifest_version}, please use Manifest v3`);
|
|
2782
2791
|
if (env.command === "serve") {
|
|
2783
2792
|
const {
|
|
2784
2793
|
contentScripts: js,
|
|
2785
2794
|
background: sw,
|
|
2786
2795
|
html
|
|
2787
2796
|
} = await manifestFiles(manifest);
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2797
|
+
const { entries = [] } = config2.optimizeDeps ?? {};
|
|
2798
|
+
let { input = [] } = config2.build?.rollupOptions ?? {};
|
|
2799
|
+
if (typeof input === "string")
|
|
2800
|
+
input = [input];
|
|
2801
|
+
else
|
|
2802
|
+
input = Object.values(input);
|
|
2803
|
+
input = input.map((f) => {
|
|
2804
|
+
let result = f;
|
|
2805
|
+
if (isAbsolute(f)) {
|
|
2806
|
+
result = relative(config2.root ?? process.cwd(), f);
|
|
2807
|
+
}
|
|
2808
|
+
return result;
|
|
2809
|
+
});
|
|
2810
|
+
const set = new Set([entries, input].flat());
|
|
2811
|
+
for (const x of [js, sw, html].flat())
|
|
2792
2812
|
set.add(x);
|
|
2793
2813
|
return {
|
|
2794
2814
|
...config2,
|
|
@@ -2963,7 +2983,7 @@ Public dir: "${config.publicDir}"`);
|
|
|
2963
2983
|
this.emitFile({
|
|
2964
2984
|
type: "asset",
|
|
2965
2985
|
fileName: f,
|
|
2966
|
-
source: await
|
|
2986
|
+
source: await readFile(filename)
|
|
2967
2987
|
});
|
|
2968
2988
|
}
|
|
2969
2989
|
}));
|
|
@@ -3332,6 +3352,7 @@ const pluginResources = ({ contentScripts = {} }) => {
|
|
|
3332
3352
|
resource.resources.push(...css);
|
|
3333
3353
|
}
|
|
3334
3354
|
if (resource.resources.length) {
|
|
3355
|
+
resource.matches = resource.matches.map(stubMatchPattern);
|
|
3335
3356
|
manifest.web_accessible_resources.push(resource);
|
|
3336
3357
|
}
|
|
3337
3358
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -4,16 +4,16 @@ import { createHash as createHash$1 } from 'crypto';
|
|
|
4
4
|
import debug$5 from 'debug';
|
|
5
5
|
import fg from 'fast-glob';
|
|
6
6
|
import v8 from 'v8';
|
|
7
|
-
import
|
|
7
|
+
import { promises, readFileSync, existsSync } from 'fs';
|
|
8
8
|
import MagicString from 'magic-string';
|
|
9
9
|
import { posix } from 'path';
|
|
10
|
+
import fsExtra from 'fs-extra';
|
|
10
11
|
import { performance } from 'perf_hooks';
|
|
11
12
|
import colors from 'picocolors';
|
|
12
13
|
import { createLogger } from 'vite';
|
|
13
14
|
import { createRequire } from 'module';
|
|
14
15
|
import { load } from 'cheerio';
|
|
15
16
|
import jsesc from 'jsesc';
|
|
16
|
-
import { existsSync } from 'fs';
|
|
17
17
|
import injector from 'connect-injector';
|
|
18
18
|
|
|
19
19
|
const _debug = (id) => debug$5("crx").extend(id);
|
|
@@ -99,6 +99,12 @@ function encodeManifest(manifest) {
|
|
|
99
99
|
const json = JSON.stringify(JSON.stringify(manifest));
|
|
100
100
|
return `export default ${json}`;
|
|
101
101
|
}
|
|
102
|
+
const stubMatchPattern = (pattern) => {
|
|
103
|
+
const [schema, rest] = pattern.split("://");
|
|
104
|
+
const [origin, pathname] = rest.split("/");
|
|
105
|
+
const root = `${schema}://${origin}`;
|
|
106
|
+
return pathname ? `${root}/*` : root;
|
|
107
|
+
};
|
|
102
108
|
|
|
103
109
|
const idBySource = /* @__PURE__ */ new Map();
|
|
104
110
|
const idByUrl = /* @__PURE__ */ new Map();
|
|
@@ -179,6 +185,7 @@ const preambleId = "/crx-client-preamble";
|
|
|
179
185
|
const stubId = "/crx-stub";
|
|
180
186
|
const workerClientId = "/crx-client-worker";
|
|
181
187
|
|
|
188
|
+
const { readFile: readFile$2 } = promises;
|
|
182
189
|
const debug$4 = _debug("file-writer").extend("chunks");
|
|
183
190
|
for (const source of [viteClientId, customElementsId]) {
|
|
184
191
|
setUrlMeta(sourceToUrlMeta(source));
|
|
@@ -253,7 +260,7 @@ const pluginFileWriterChunks = () => {
|
|
|
253
260
|
this.emitFile({
|
|
254
261
|
type: "asset",
|
|
255
262
|
fileName: relative(server.config.root, file),
|
|
256
|
-
source: await readFile(file)
|
|
263
|
+
source: await readFile$2(file)
|
|
257
264
|
});
|
|
258
265
|
}
|
|
259
266
|
if (url)
|
|
@@ -2265,6 +2272,7 @@ const pluginFileWriterHtml = () => {
|
|
|
2265
2272
|
};
|
|
2266
2273
|
};
|
|
2267
2274
|
|
|
2275
|
+
const { readFile: readFile$1 } = promises;
|
|
2268
2276
|
const pluginFileWriterPublic = () => {
|
|
2269
2277
|
let config;
|
|
2270
2278
|
return {
|
|
@@ -2278,7 +2286,7 @@ const pluginFileWriterPublic = () => {
|
|
|
2278
2286
|
this.addWatchFile(config.publicDir);
|
|
2279
2287
|
const publicFiles = await fg(`${config.publicDir}/**/*`);
|
|
2280
2288
|
for (const file of publicFiles) {
|
|
2281
|
-
const source = await readFile(file);
|
|
2289
|
+
const source = await readFile$1(file);
|
|
2282
2290
|
const fileName = relative(config.publicDir, file);
|
|
2283
2291
|
this.emitFile({ type: "asset", fileName, source });
|
|
2284
2292
|
}
|
|
@@ -2733,6 +2741,7 @@ const pluginHtmlAuditor = () => {
|
|
|
2733
2741
|
};
|
|
2734
2742
|
};
|
|
2735
2743
|
|
|
2744
|
+
const { readFile } = promises;
|
|
2736
2745
|
const pluginManifest = (_manifest) => () => {
|
|
2737
2746
|
let manifest;
|
|
2738
2747
|
let plugins;
|
|
@@ -2745,17 +2754,28 @@ const pluginManifest = (_manifest) => () => {
|
|
|
2745
2754
|
async config(config2, env) {
|
|
2746
2755
|
manifest = await (typeof _manifest === "function" ? _manifest(env) : _manifest);
|
|
2747
2756
|
if (manifest.manifest_version !== 3)
|
|
2748
|
-
throw new Error(`Manifest v${manifest.manifest_version}
|
|
2757
|
+
throw new Error(`CRXJS does not support Manifest v${manifest.manifest_version}, please use Manifest v3`);
|
|
2749
2758
|
if (env.command === "serve") {
|
|
2750
2759
|
const {
|
|
2751
2760
|
contentScripts: js,
|
|
2752
2761
|
background: sw,
|
|
2753
2762
|
html
|
|
2754
2763
|
} = await manifestFiles(manifest);
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2764
|
+
const { entries = [] } = config2.optimizeDeps ?? {};
|
|
2765
|
+
let { input = [] } = config2.build?.rollupOptions ?? {};
|
|
2766
|
+
if (typeof input === "string")
|
|
2767
|
+
input = [input];
|
|
2768
|
+
else
|
|
2769
|
+
input = Object.values(input);
|
|
2770
|
+
input = input.map((f) => {
|
|
2771
|
+
let result = f;
|
|
2772
|
+
if (isAbsolute(f)) {
|
|
2773
|
+
result = relative(config2.root ?? process.cwd(), f);
|
|
2774
|
+
}
|
|
2775
|
+
return result;
|
|
2776
|
+
});
|
|
2777
|
+
const set = new Set([entries, input].flat());
|
|
2778
|
+
for (const x of [js, sw, html].flat())
|
|
2759
2779
|
set.add(x);
|
|
2760
2780
|
return {
|
|
2761
2781
|
...config2,
|
|
@@ -3299,6 +3319,7 @@ const pluginResources = ({ contentScripts = {} }) => {
|
|
|
3299
3319
|
resource.resources.push(...css);
|
|
3300
3320
|
}
|
|
3301
3321
|
if (resource.resources.length) {
|
|
3322
|
+
resource.matches = resource.matches.map(stubMatchPattern);
|
|
3302
3323
|
manifest.web_accessible_resources.push(resource);
|
|
3303
3324
|
}
|
|
3304
3325
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crxjs/vite-plugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "Build Chrome Extensions with this Vite plugin.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"rollup-plugin",
|
|
@@ -83,20 +83,20 @@
|
|
|
83
83
|
"@rollup/plugin-commonjs": "21.1.0",
|
|
84
84
|
"@rollup/plugin-node-resolve": "13.2.0",
|
|
85
85
|
"@types/acorn": "4.0.6",
|
|
86
|
-
"@types/chrome": "0.0.
|
|
86
|
+
"@types/chrome": "0.0.188",
|
|
87
87
|
"@types/debug": "4.1.7",
|
|
88
88
|
"@types/fs-extra": "9.0.13",
|
|
89
|
-
"@types/jest": "27.5.
|
|
89
|
+
"@types/jest": "27.5.1",
|
|
90
90
|
"@types/jest-image-snapshot": "4.3.1",
|
|
91
91
|
"@types/jsesc": "3.0.1",
|
|
92
92
|
"@types/node": "17.0.18",
|
|
93
93
|
"@types/react": "17.0.44",
|
|
94
|
-
"@types/react-dom": "17.0.
|
|
94
|
+
"@types/react-dom": "17.0.17",
|
|
95
95
|
"@typescript-eslint/eslint-plugin": "5.23.0",
|
|
96
96
|
"@typescript-eslint/parser": "5.23.0",
|
|
97
97
|
"@vitejs/plugin-react": "1.3.2",
|
|
98
|
-
"@vitejs/plugin-vue": "2.3.
|
|
99
|
-
"esbuild": "0.14.
|
|
98
|
+
"@vitejs/plugin-vue": "2.3.3",
|
|
99
|
+
"esbuild": "0.14.42",
|
|
100
100
|
"esbuild-runner": "2.2.1",
|
|
101
101
|
"eslint": "8.15.0",
|
|
102
102
|
"jest": "27.5.1",
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"typescript": "^4.6.4",
|
|
112
112
|
"vite": "^2.9.5",
|
|
113
113
|
"vite-plugin-inspect": "0.5.0",
|
|
114
|
-
"vue": "3.2.
|
|
114
|
+
"vue": "3.2.36"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|
|
117
117
|
"vite": "^2.9.0"
|