wxt 0.1.1-alpha2 → 0.1.1-alpha3
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/cli.cjs +94 -81
- package/dist/index.cjs +93 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -85
- package/dist/index.js.map +1 -1
- package/dist/virtual-modules/fake-browser.cjs +27 -0
- package/dist/virtual-modules/fake-browser.js +6 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,57 +1,20 @@
|
|
|
1
1
|
// src/core/utils/getInternalConfig.ts
|
|
2
|
-
import path2, { resolve as
|
|
2
|
+
import path2, { resolve as resolve6 } from "node:path";
|
|
3
3
|
import * as vite2 from "vite";
|
|
4
|
-
import { consola as consola2 } from "consola";
|
|
5
|
-
|
|
6
|
-
// src/core/utils/importTsFile.ts
|
|
7
4
|
import { consola } from "consola";
|
|
8
|
-
import createJITI from "jiti";
|
|
9
|
-
import transform from "jiti/dist/babel";
|
|
10
|
-
import { resolve } from "path";
|
|
11
|
-
import { createUnimport } from "unimport";
|
|
12
|
-
import fs from "fs-extra";
|
|
13
|
-
async function importTsFile(root, path5) {
|
|
14
|
-
const unimport2 = createUnimport({});
|
|
15
|
-
await unimport2.scanImportsFromFile(
|
|
16
|
-
resolve(root, "node_modules/wxt/dist/client.js")
|
|
17
|
-
);
|
|
18
|
-
const text = await fs.readFile(path5, "utf-8");
|
|
19
|
-
const res = await unimport2.injectImports(text, path5);
|
|
20
|
-
const transformedText = res.code;
|
|
21
|
-
const jiti = createJITI(__filename, {
|
|
22
|
-
cache: false,
|
|
23
|
-
esmResolve: true,
|
|
24
|
-
interopDefault: true,
|
|
25
|
-
alias: {
|
|
26
|
-
"webextension-polyfill": "@webext-core/fake-browser"
|
|
27
|
-
},
|
|
28
|
-
transform(opts) {
|
|
29
|
-
if (opts.filename === path5)
|
|
30
|
-
opts.source = transformedText;
|
|
31
|
-
opts.source = opts.source.replace(/^import ['"].*\.css['"];?$/gm, "");
|
|
32
|
-
return transform(opts);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
try {
|
|
36
|
-
return await jiti(path5);
|
|
37
|
-
} catch (err) {
|
|
38
|
-
consola.error(`Failed to import file: ${path5}`);
|
|
39
|
-
throw err;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
5
|
|
|
43
6
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
44
7
|
import * as vite from "vite";
|
|
45
8
|
|
|
46
9
|
// src/core/utils/entrypoints.ts
|
|
47
|
-
import path, { relative, resolve
|
|
10
|
+
import path, { relative, resolve } from "node:path";
|
|
48
11
|
function getEntrypointName(entrypointsDir, inputPath) {
|
|
49
12
|
const relativePath = path.relative(entrypointsDir, inputPath);
|
|
50
13
|
const name = relativePath.split(/[\.\/]/, 2)[0];
|
|
51
14
|
return name;
|
|
52
15
|
}
|
|
53
16
|
function getEntrypointOutputFile(entrypoint, ext) {
|
|
54
|
-
return
|
|
17
|
+
return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
|
|
55
18
|
}
|
|
56
19
|
function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
57
20
|
return relative(outDir, getEntrypointOutputFile(entrypoint, ext));
|
|
@@ -59,7 +22,7 @@ function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
|
59
22
|
|
|
60
23
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
61
24
|
import { parseHTML } from "linkedom";
|
|
62
|
-
import { dirname, isAbsolute, relative as relative2, resolve as
|
|
25
|
+
import { dirname, isAbsolute, relative as relative2, resolve as resolve2 } from "path";
|
|
63
26
|
function devHtmlPrerender(config) {
|
|
64
27
|
return {
|
|
65
28
|
apply: "build",
|
|
@@ -69,7 +32,7 @@ function devHtmlPrerender(config) {
|
|
|
69
32
|
{
|
|
70
33
|
resolve: {
|
|
71
34
|
alias: {
|
|
72
|
-
"@wxt/reload-html":
|
|
35
|
+
"@wxt/reload-html": resolve2(
|
|
73
36
|
config.root,
|
|
74
37
|
"node_modules/wxt/dist/virtual-modules/reload-html.js"
|
|
75
38
|
)
|
|
@@ -100,7 +63,7 @@ function devHtmlPrerender(config) {
|
|
|
100
63
|
if (isAbsolute(src)) {
|
|
101
64
|
element.setAttribute(attr, server.origin + src);
|
|
102
65
|
} else if (src.startsWith(".")) {
|
|
103
|
-
const abs =
|
|
66
|
+
const abs = resolve2(dirname(id), src);
|
|
104
67
|
const pathname = relative2(config.root, abs);
|
|
105
68
|
element.setAttribute(attr, `${server.origin}/${pathname}`);
|
|
106
69
|
}
|
|
@@ -210,8 +173,8 @@ function download(config) {
|
|
|
210
173
|
}
|
|
211
174
|
|
|
212
175
|
// src/core/vite-plugins/multipageMove.ts
|
|
213
|
-
import { dirname as dirname2, extname, resolve as
|
|
214
|
-
import
|
|
176
|
+
import { dirname as dirname2, extname, resolve as resolve3 } from "node:path";
|
|
177
|
+
import fs, { ensureDir } from "fs-extra";
|
|
215
178
|
function multipageMove(entrypoints, config) {
|
|
216
179
|
return {
|
|
217
180
|
name: "wxt:multipage-move",
|
|
@@ -236,10 +199,10 @@ function multipageMove(entrypoints, config) {
|
|
|
236
199
|
);
|
|
237
200
|
continue;
|
|
238
201
|
}
|
|
239
|
-
const oldAbsPath =
|
|
240
|
-
const newAbsPath =
|
|
202
|
+
const oldAbsPath = resolve3(config.outDir, oldBundlePath);
|
|
203
|
+
const newAbsPath = resolve3(config.outDir, newBundlePath);
|
|
241
204
|
await ensureDir(dirname2(newAbsPath));
|
|
242
|
-
await
|
|
205
|
+
await fs.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
243
206
|
const renamedChunk = {
|
|
244
207
|
...bundle[oldBundlePath],
|
|
245
208
|
fileName: newBundlePath
|
|
@@ -252,7 +215,7 @@ function multipageMove(entrypoints, config) {
|
|
|
252
215
|
}
|
|
253
216
|
|
|
254
217
|
// src/core/vite-plugins/unimport.ts
|
|
255
|
-
import { createUnimport
|
|
218
|
+
import { createUnimport } from "unimport";
|
|
256
219
|
|
|
257
220
|
// src/core/utils/auto-imports.ts
|
|
258
221
|
import { mergeConfig as mergeConfig2 } from "vite";
|
|
@@ -276,7 +239,7 @@ function getUnimportOptions(config) {
|
|
|
276
239
|
// src/core/vite-plugins/unimport.ts
|
|
277
240
|
function unimport(config) {
|
|
278
241
|
const options = getUnimportOptions(config);
|
|
279
|
-
const unimport2 =
|
|
242
|
+
const unimport2 = createUnimport(options);
|
|
280
243
|
return {
|
|
281
244
|
name: "wxt:unimport",
|
|
282
245
|
async config() {
|
|
@@ -289,8 +252,8 @@ function unimport(config) {
|
|
|
289
252
|
}
|
|
290
253
|
|
|
291
254
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
292
|
-
import
|
|
293
|
-
import { resolve as
|
|
255
|
+
import fs2 from "fs-extra";
|
|
256
|
+
import { resolve as resolve4 } from "path";
|
|
294
257
|
function virtualEntrypoin(type, config) {
|
|
295
258
|
const virtualId = `virtual:wxt-${type}?`;
|
|
296
259
|
const resolvedVirtualId = `\0${virtualId}`;
|
|
@@ -307,8 +270,8 @@ function virtualEntrypoin(type, config) {
|
|
|
307
270
|
if (!id.startsWith(resolvedVirtualId))
|
|
308
271
|
return;
|
|
309
272
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
310
|
-
const template = await
|
|
311
|
-
|
|
273
|
+
const template = await fs2.readFile(
|
|
274
|
+
resolve4(
|
|
312
275
|
config.root,
|
|
313
276
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
314
277
|
),
|
|
@@ -320,20 +283,20 @@ function virtualEntrypoin(type, config) {
|
|
|
320
283
|
}
|
|
321
284
|
|
|
322
285
|
// src/core/utils/createFsCache.ts
|
|
323
|
-
import
|
|
324
|
-
import { dirname as dirname3, resolve as
|
|
286
|
+
import fs3, { ensureDir as ensureDir2 } from "fs-extra";
|
|
287
|
+
import { dirname as dirname3, resolve as resolve5 } from "path";
|
|
325
288
|
function createFsCache(wxtDir) {
|
|
326
|
-
const getPath = (key) =>
|
|
289
|
+
const getPath = (key) => resolve5(wxtDir, "cache", encodeURIComponent(key));
|
|
327
290
|
return {
|
|
328
291
|
async set(key, value) {
|
|
329
292
|
const path5 = getPath(key);
|
|
330
293
|
await ensureDir2(dirname3(path5));
|
|
331
|
-
await
|
|
294
|
+
await fs3.writeFile(path5, value, "utf-8");
|
|
332
295
|
},
|
|
333
296
|
async get(key) {
|
|
334
297
|
const path5 = getPath(key);
|
|
335
298
|
try {
|
|
336
|
-
return await
|
|
299
|
+
return await fs3.readFile(path5, "utf-8");
|
|
337
300
|
} catch {
|
|
338
301
|
return void 0;
|
|
339
302
|
}
|
|
@@ -396,7 +359,7 @@ async function getInternalConfig(config, command) {
|
|
|
396
359
|
const manifestVersion = config.manifestVersion ?? (browser == "firefox" ? 2 : 3);
|
|
397
360
|
const outBaseDir = path2.resolve(root, ".output");
|
|
398
361
|
const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
399
|
-
const logger = config.logger ??
|
|
362
|
+
const logger = config.logger ?? consola;
|
|
400
363
|
const baseConfig = {
|
|
401
364
|
root,
|
|
402
365
|
outDir,
|
|
@@ -422,23 +385,25 @@ async function getInternalConfig(config, command) {
|
|
|
422
385
|
mode
|
|
423
386
|
};
|
|
424
387
|
if (config.configFile !== false) {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
388
|
+
const loaded = await loadConfig({
|
|
389
|
+
name: "wxt",
|
|
390
|
+
cwd: root,
|
|
391
|
+
rcFile: false
|
|
392
|
+
});
|
|
393
|
+
userConfig = loaded.config ?? {};
|
|
429
394
|
}
|
|
430
395
|
const merged = vite2.mergeConfig(
|
|
431
396
|
baseConfig,
|
|
432
397
|
userConfig
|
|
433
398
|
);
|
|
434
|
-
const srcDir = userConfig.srcDir ?
|
|
435
|
-
const entrypointsDir =
|
|
399
|
+
const srcDir = userConfig.srcDir ? resolve6(root, userConfig.srcDir) : root;
|
|
400
|
+
const entrypointsDir = resolve6(
|
|
436
401
|
srcDir,
|
|
437
402
|
userConfig.entrypointsDir ?? "entrypoints"
|
|
438
403
|
);
|
|
439
|
-
const publicDir =
|
|
440
|
-
const wxtDir =
|
|
441
|
-
const typesDir =
|
|
404
|
+
const publicDir = resolve6(srcDir, userConfig.publicDir ?? "public");
|
|
405
|
+
const wxtDir = resolve6(srcDir, ".wxt");
|
|
406
|
+
const typesDir = resolve6(wxtDir, "types");
|
|
442
407
|
const finalConfig = {
|
|
443
408
|
...merged,
|
|
444
409
|
srcDir,
|
|
@@ -576,27 +541,27 @@ import { relative as relative6 } from "node:path";
|
|
|
576
541
|
import * as vite3 from "vite";
|
|
577
542
|
|
|
578
543
|
// src/core/utils/removeEmptyDirs.ts
|
|
579
|
-
import
|
|
544
|
+
import fs4 from "fs-extra";
|
|
580
545
|
import path3 from "path";
|
|
581
546
|
async function removeEmptyDirs(dir) {
|
|
582
|
-
const files = await
|
|
547
|
+
const files = await fs4.readdir(dir);
|
|
583
548
|
for (const file of files) {
|
|
584
549
|
const filePath = path3.join(dir, file);
|
|
585
|
-
const stats = await
|
|
550
|
+
const stats = await fs4.stat(filePath);
|
|
586
551
|
if (stats.isDirectory()) {
|
|
587
552
|
await removeEmptyDirs(filePath);
|
|
588
553
|
}
|
|
589
554
|
}
|
|
590
555
|
try {
|
|
591
|
-
await
|
|
556
|
+
await fs4.rmdir(dir);
|
|
592
557
|
} catch {
|
|
593
558
|
}
|
|
594
559
|
}
|
|
595
560
|
|
|
596
561
|
// src/core/build/buildEntrypoints.ts
|
|
597
562
|
import glob from "fast-glob";
|
|
598
|
-
import
|
|
599
|
-
import { dirname as dirname4, resolve as
|
|
563
|
+
import fs5 from "fs-extra";
|
|
564
|
+
import { dirname as dirname4, resolve as resolve7 } from "path";
|
|
600
565
|
async function buildEntrypoints(groups, config) {
|
|
601
566
|
const steps = [];
|
|
602
567
|
for (const group of groups) {
|
|
@@ -684,20 +649,20 @@ function getBuildOutputChunks(result) {
|
|
|
684
649
|
}
|
|
685
650
|
async function copyPublicDirectory(config) {
|
|
686
651
|
const publicAssets = [];
|
|
687
|
-
if (!await
|
|
652
|
+
if (!await fs5.exists(config.publicDir))
|
|
688
653
|
return publicAssets;
|
|
689
654
|
const files = await glob("**/*", { cwd: config.publicDir });
|
|
690
655
|
for (const file of files) {
|
|
691
|
-
const srcPath =
|
|
692
|
-
const outPath =
|
|
693
|
-
await
|
|
694
|
-
await
|
|
656
|
+
const srcPath = resolve7(config.publicDir, file);
|
|
657
|
+
const outPath = resolve7(config.outDir, file);
|
|
658
|
+
await fs5.ensureDir(dirname4(outPath));
|
|
659
|
+
await fs5.copyFile(srcPath, outPath);
|
|
695
660
|
publicAssets.push({
|
|
696
661
|
type: "asset",
|
|
697
662
|
fileName: file,
|
|
698
663
|
name: file,
|
|
699
664
|
needsCodeReference: false,
|
|
700
|
-
source: await
|
|
665
|
+
source: await fs5.readFile(srcPath)
|
|
701
666
|
});
|
|
702
667
|
}
|
|
703
668
|
return publicAssets;
|
|
@@ -709,6 +674,54 @@ import fs7 from "fs-extra";
|
|
|
709
674
|
import picomatch from "picomatch";
|
|
710
675
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
711
676
|
import JSON5 from "json5";
|
|
677
|
+
|
|
678
|
+
// src/core/utils/importTsFile.ts
|
|
679
|
+
import { consola as consola2 } from "consola";
|
|
680
|
+
import transform from "jiti/dist/babel";
|
|
681
|
+
import { createUnimport as createUnimport2 } from "unimport";
|
|
682
|
+
import fs6 from "fs-extra";
|
|
683
|
+
import { loadConfig as loadConfig2 } from "c12";
|
|
684
|
+
import { resolve as resolve8 } from "path";
|
|
685
|
+
async function importTsFile(path5, config) {
|
|
686
|
+
const options = getUnimportOptions(config);
|
|
687
|
+
const unimport2 = createUnimport2(options);
|
|
688
|
+
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
689
|
+
const text = await fs6.readFile(path5, "utf-8");
|
|
690
|
+
const res = await unimport2.injectImports(text, path5);
|
|
691
|
+
const transformedText = res.code;
|
|
692
|
+
try {
|
|
693
|
+
const loaded = await loadConfig2({
|
|
694
|
+
configFile: path5,
|
|
695
|
+
rcFile: false,
|
|
696
|
+
jitiOptions: {
|
|
697
|
+
cache: false,
|
|
698
|
+
// esmResolve: true,
|
|
699
|
+
// interopDefault: true,
|
|
700
|
+
alias: {
|
|
701
|
+
"webextension-polyfill": resolve8(
|
|
702
|
+
config.root,
|
|
703
|
+
"node_modules/wxt/dist/virtual-modules/fake-browser.js"
|
|
704
|
+
)
|
|
705
|
+
},
|
|
706
|
+
transform(opts) {
|
|
707
|
+
if (opts.filename === path5)
|
|
708
|
+
opts.source = transformedText;
|
|
709
|
+
opts.source = opts.source.replace(
|
|
710
|
+
/^import.*['"].*\.css['"];?$/gm,
|
|
711
|
+
""
|
|
712
|
+
);
|
|
713
|
+
return transform(opts);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
});
|
|
717
|
+
return loaded.config;
|
|
718
|
+
} catch (err) {
|
|
719
|
+
consola2.error(`Failed to import file: ${path5}`);
|
|
720
|
+
throw err;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// src/core/build/findEntrypoints.ts
|
|
712
725
|
import glob2 from "fast-glob";
|
|
713
726
|
async function findEntrypoints(config) {
|
|
714
727
|
const relativePaths = await glob2("**/*", {
|
|
@@ -833,7 +846,7 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
833
846
|
};
|
|
834
847
|
}
|
|
835
848
|
async function getBackgroundEntrypoint(config, path5) {
|
|
836
|
-
const { main: _, ...options } = await importTsFile(
|
|
849
|
+
const { main: _, ...options } = await importTsFile(path5, config);
|
|
837
850
|
if (options == null) {
|
|
838
851
|
throw Error("Background script does not have a default export");
|
|
839
852
|
}
|
|
@@ -847,8 +860,8 @@ async function getBackgroundEntrypoint(config, path5) {
|
|
|
847
860
|
}
|
|
848
861
|
async function getContentScriptEntrypoint(config, name, path5) {
|
|
849
862
|
const { main: _, ...options } = await importTsFile(
|
|
850
|
-
|
|
851
|
-
|
|
863
|
+
path5,
|
|
864
|
+
config
|
|
852
865
|
);
|
|
853
866
|
if (options == null) {
|
|
854
867
|
throw Error(`Content script ${name} does not have a default export`);
|
|
@@ -1678,7 +1691,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1678
1691
|
}
|
|
1679
1692
|
|
|
1680
1693
|
// package.json
|
|
1681
|
-
var version2 = "0.1.1-
|
|
1694
|
+
var version2 = "0.1.1-alpha3";
|
|
1682
1695
|
|
|
1683
1696
|
// src/core/utils/defineConfig.ts
|
|
1684
1697
|
function defineConfig(config) {
|