wxt 0.1.1-alpha2 → 0.1.1-alpha4
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 +107 -94
- package/dist/index.cjs +96 -83
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +101 -88
- package/dist/index.js.map +1 -1
- package/dist/virtual-modules/background-entrypoint.js.map +1 -1
- package/dist/virtual-modules/content-script-entrypoint.js.map +1 -1
- package/dist/virtual-modules/fake-browser.cjs +27 -0
- package/dist/virtual-modules/fake-browser.js +6 -0
- package/dist/virtual-modules/reload-html.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,44 +41,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
41
41
|
// src/core/utils/getInternalConfig.ts
|
|
42
42
|
var import_node_path3 = __toESM(require("path"), 1);
|
|
43
43
|
var vite2 = __toESM(require("vite"), 1);
|
|
44
|
-
var import_consola2 = require("consola");
|
|
45
|
-
|
|
46
|
-
// src/core/utils/importTsFile.ts
|
|
47
44
|
var import_consola = require("consola");
|
|
48
|
-
var import_jiti = __toESM(require("jiti"), 1);
|
|
49
|
-
var import_babel = __toESM(require("jiti/dist/babel"), 1);
|
|
50
|
-
var import_path = require("path");
|
|
51
|
-
var import_unimport = require("unimport");
|
|
52
|
-
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
53
|
-
async function importTsFile(root, path5) {
|
|
54
|
-
const unimport2 = (0, import_unimport.createUnimport)({});
|
|
55
|
-
await unimport2.scanImportsFromFile(
|
|
56
|
-
(0, import_path.resolve)(root, "node_modules/wxt/dist/client.js")
|
|
57
|
-
);
|
|
58
|
-
const text = await import_fs_extra.default.readFile(path5, "utf-8");
|
|
59
|
-
const res = await unimport2.injectImports(text, path5);
|
|
60
|
-
const transformedText = res.code;
|
|
61
|
-
const jiti = (0, import_jiti.default)(__filename, {
|
|
62
|
-
cache: false,
|
|
63
|
-
esmResolve: true,
|
|
64
|
-
interopDefault: true,
|
|
65
|
-
alias: {
|
|
66
|
-
"webextension-polyfill": "@webext-core/fake-browser"
|
|
67
|
-
},
|
|
68
|
-
transform(opts) {
|
|
69
|
-
if (opts.filename === path5)
|
|
70
|
-
opts.source = transformedText;
|
|
71
|
-
opts.source = opts.source.replace(/^import ['"].*\.css['"];?$/gm, "");
|
|
72
|
-
return (0, import_babel.default)(opts);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
try {
|
|
76
|
-
return await jiti(path5);
|
|
77
|
-
} catch (err) {
|
|
78
|
-
import_consola.consola.error(`Failed to import file: ${path5}`);
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
45
|
|
|
83
46
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
84
47
|
var vite = __toESM(require("vite"), 1);
|
|
@@ -99,7 +62,7 @@ function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
|
99
62
|
|
|
100
63
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
101
64
|
var import_linkedom = require("linkedom");
|
|
102
|
-
var
|
|
65
|
+
var import_path = require("path");
|
|
103
66
|
function devHtmlPrerender(config) {
|
|
104
67
|
return {
|
|
105
68
|
apply: "build",
|
|
@@ -109,7 +72,7 @@ function devHtmlPrerender(config) {
|
|
|
109
72
|
{
|
|
110
73
|
resolve: {
|
|
111
74
|
alias: {
|
|
112
|
-
"@wxt/reload-html": (0,
|
|
75
|
+
"@wxt/reload-html": (0, import_path.resolve)(
|
|
113
76
|
config.root,
|
|
114
77
|
"node_modules/wxt/dist/virtual-modules/reload-html.js"
|
|
115
78
|
)
|
|
@@ -137,11 +100,11 @@ function devHtmlPrerender(config) {
|
|
|
137
100
|
const src = element.getAttribute(attr);
|
|
138
101
|
if (!src)
|
|
139
102
|
return;
|
|
140
|
-
if ((0,
|
|
103
|
+
if ((0, import_path.isAbsolute)(src)) {
|
|
141
104
|
element.setAttribute(attr, server.origin + src);
|
|
142
105
|
} else if (src.startsWith(".")) {
|
|
143
|
-
const abs = (0,
|
|
144
|
-
const pathname = (0,
|
|
106
|
+
const abs = (0, import_path.resolve)((0, import_path.dirname)(id), src);
|
|
107
|
+
const pathname = (0, import_path.relative)(config.root, abs);
|
|
145
108
|
element.setAttribute(attr, `${server.origin}/${pathname}`);
|
|
146
109
|
}
|
|
147
110
|
});
|
|
@@ -251,7 +214,7 @@ function download(config) {
|
|
|
251
214
|
|
|
252
215
|
// src/core/vite-plugins/multipageMove.ts
|
|
253
216
|
var import_node_path2 = require("path");
|
|
254
|
-
var
|
|
217
|
+
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
255
218
|
function multipageMove(entrypoints, config) {
|
|
256
219
|
return {
|
|
257
220
|
name: "wxt:multipage-move",
|
|
@@ -278,8 +241,8 @@ function multipageMove(entrypoints, config) {
|
|
|
278
241
|
}
|
|
279
242
|
const oldAbsPath = (0, import_node_path2.resolve)(config.outDir, oldBundlePath);
|
|
280
243
|
const newAbsPath = (0, import_node_path2.resolve)(config.outDir, newBundlePath);
|
|
281
|
-
await (0,
|
|
282
|
-
await
|
|
244
|
+
await (0, import_fs_extra.ensureDir)((0, import_node_path2.dirname)(newAbsPath));
|
|
245
|
+
await import_fs_extra.default.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
283
246
|
const renamedChunk = {
|
|
284
247
|
...bundle[oldBundlePath],
|
|
285
248
|
fileName: newBundlePath
|
|
@@ -292,7 +255,7 @@ function multipageMove(entrypoints, config) {
|
|
|
292
255
|
}
|
|
293
256
|
|
|
294
257
|
// src/core/vite-plugins/unimport.ts
|
|
295
|
-
var
|
|
258
|
+
var import_unimport = require("unimport");
|
|
296
259
|
|
|
297
260
|
// src/core/utils/auto-imports.ts
|
|
298
261
|
var import_vite = require("vite");
|
|
@@ -316,7 +279,7 @@ function getUnimportOptions(config) {
|
|
|
316
279
|
// src/core/vite-plugins/unimport.ts
|
|
317
280
|
function unimport(config) {
|
|
318
281
|
const options = getUnimportOptions(config);
|
|
319
|
-
const unimport2 = (0,
|
|
282
|
+
const unimport2 = (0, import_unimport.createUnimport)(options);
|
|
320
283
|
return {
|
|
321
284
|
name: "wxt:unimport",
|
|
322
285
|
async config() {
|
|
@@ -329,8 +292,8 @@ function unimport(config) {
|
|
|
329
292
|
}
|
|
330
293
|
|
|
331
294
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
332
|
-
var
|
|
333
|
-
var
|
|
295
|
+
var import_fs_extra2 = __toESM(require("fs-extra"), 1);
|
|
296
|
+
var import_path2 = require("path");
|
|
334
297
|
function virtualEntrypoin(type, config) {
|
|
335
298
|
const virtualId = `virtual:wxt-${type}?`;
|
|
336
299
|
const resolvedVirtualId = `\0${virtualId}`;
|
|
@@ -347,8 +310,8 @@ function virtualEntrypoin(type, config) {
|
|
|
347
310
|
if (!id.startsWith(resolvedVirtualId))
|
|
348
311
|
return;
|
|
349
312
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
350
|
-
const template = await
|
|
351
|
-
(0,
|
|
313
|
+
const template = await import_fs_extra2.default.readFile(
|
|
314
|
+
(0, import_path2.resolve)(
|
|
352
315
|
config.root,
|
|
353
316
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
354
317
|
),
|
|
@@ -360,20 +323,20 @@ function virtualEntrypoin(type, config) {
|
|
|
360
323
|
}
|
|
361
324
|
|
|
362
325
|
// src/core/utils/createFsCache.ts
|
|
363
|
-
var
|
|
364
|
-
var
|
|
326
|
+
var import_fs_extra3 = __toESM(require("fs-extra"), 1);
|
|
327
|
+
var import_path3 = require("path");
|
|
365
328
|
function createFsCache(wxtDir) {
|
|
366
|
-
const getPath = (key) => (0,
|
|
329
|
+
const getPath = (key) => (0, import_path3.resolve)(wxtDir, "cache", encodeURIComponent(key));
|
|
367
330
|
return {
|
|
368
331
|
async set(key, value) {
|
|
369
332
|
const path5 = getPath(key);
|
|
370
|
-
await (0,
|
|
371
|
-
await
|
|
333
|
+
await (0, import_fs_extra3.ensureDir)((0, import_path3.dirname)(path5));
|
|
334
|
+
await import_fs_extra3.default.writeFile(path5, value, "utf-8");
|
|
372
335
|
},
|
|
373
336
|
async get(key) {
|
|
374
337
|
const path5 = getPath(key);
|
|
375
338
|
try {
|
|
376
|
-
return await
|
|
339
|
+
return await import_fs_extra3.default.readFile(path5, "utf-8");
|
|
377
340
|
} catch {
|
|
378
341
|
return void 0;
|
|
379
342
|
}
|
|
@@ -436,7 +399,7 @@ async function getInternalConfig(config, command) {
|
|
|
436
399
|
const manifestVersion = config.manifestVersion ?? (browser == "firefox" ? 2 : 3);
|
|
437
400
|
const outBaseDir = import_node_path3.default.resolve(root, ".output");
|
|
438
401
|
const outDir = import_node_path3.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
439
|
-
const logger = config.logger ??
|
|
402
|
+
const logger = config.logger ?? import_consola.consola;
|
|
440
403
|
const baseConfig = {
|
|
441
404
|
root,
|
|
442
405
|
outDir,
|
|
@@ -462,10 +425,12 @@ async function getInternalConfig(config, command) {
|
|
|
462
425
|
mode
|
|
463
426
|
};
|
|
464
427
|
if (config.configFile !== false) {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
428
|
+
const loaded = await (0, import_c12.loadConfig)({
|
|
429
|
+
name: "wxt",
|
|
430
|
+
cwd: root,
|
|
431
|
+
rcFile: false
|
|
432
|
+
});
|
|
433
|
+
userConfig = loaded.config ?? {};
|
|
469
434
|
}
|
|
470
435
|
const merged = vite2.mergeConfig(
|
|
471
436
|
baseConfig,
|
|
@@ -609,34 +574,34 @@ function findEffectedSteps(changedFile, currentOutput) {
|
|
|
609
574
|
|
|
610
575
|
// src/index.ts
|
|
611
576
|
var import_async_mutex = require("async-mutex");
|
|
612
|
-
var
|
|
577
|
+
var import_consola2 = require("consola");
|
|
613
578
|
var import_node_path4 = require("path");
|
|
614
579
|
|
|
615
580
|
// src/core/build/buildEntrypoints.ts
|
|
616
581
|
var vite3 = __toESM(require("vite"), 1);
|
|
617
582
|
|
|
618
583
|
// src/core/utils/removeEmptyDirs.ts
|
|
619
|
-
var
|
|
620
|
-
var
|
|
584
|
+
var import_fs_extra4 = __toESM(require("fs-extra"), 1);
|
|
585
|
+
var import_path4 = __toESM(require("path"), 1);
|
|
621
586
|
async function removeEmptyDirs(dir) {
|
|
622
|
-
const files = await
|
|
587
|
+
const files = await import_fs_extra4.default.readdir(dir);
|
|
623
588
|
for (const file of files) {
|
|
624
|
-
const filePath =
|
|
625
|
-
const stats = await
|
|
589
|
+
const filePath = import_path4.default.join(dir, file);
|
|
590
|
+
const stats = await import_fs_extra4.default.stat(filePath);
|
|
626
591
|
if (stats.isDirectory()) {
|
|
627
592
|
await removeEmptyDirs(filePath);
|
|
628
593
|
}
|
|
629
594
|
}
|
|
630
595
|
try {
|
|
631
|
-
await
|
|
596
|
+
await import_fs_extra4.default.rmdir(dir);
|
|
632
597
|
} catch {
|
|
633
598
|
}
|
|
634
599
|
}
|
|
635
600
|
|
|
636
601
|
// src/core/build/buildEntrypoints.ts
|
|
637
602
|
var import_fast_glob = __toESM(require("fast-glob"), 1);
|
|
638
|
-
var
|
|
639
|
-
var
|
|
603
|
+
var import_fs_extra5 = __toESM(require("fs-extra"), 1);
|
|
604
|
+
var import_path5 = require("path");
|
|
640
605
|
async function buildEntrypoints(groups, config) {
|
|
641
606
|
const steps = [];
|
|
642
607
|
for (const group of groups) {
|
|
@@ -724,20 +689,20 @@ function getBuildOutputChunks(result) {
|
|
|
724
689
|
}
|
|
725
690
|
async function copyPublicDirectory(config) {
|
|
726
691
|
const publicAssets = [];
|
|
727
|
-
if (!await
|
|
692
|
+
if (!await import_fs_extra5.default.exists(config.publicDir))
|
|
728
693
|
return publicAssets;
|
|
729
694
|
const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
|
|
730
695
|
for (const file of files) {
|
|
731
|
-
const srcPath = (0,
|
|
732
|
-
const outPath = (0,
|
|
733
|
-
await
|
|
734
|
-
await
|
|
696
|
+
const srcPath = (0, import_path5.resolve)(config.publicDir, file);
|
|
697
|
+
const outPath = (0, import_path5.resolve)(config.outDir, file);
|
|
698
|
+
await import_fs_extra5.default.ensureDir((0, import_path5.dirname)(outPath));
|
|
699
|
+
await import_fs_extra5.default.copyFile(srcPath, outPath);
|
|
735
700
|
publicAssets.push({
|
|
736
701
|
type: "asset",
|
|
737
702
|
fileName: file,
|
|
738
703
|
name: file,
|
|
739
704
|
needsCodeReference: false,
|
|
740
|
-
source: await
|
|
705
|
+
source: await import_fs_extra5.default.readFile(srcPath)
|
|
741
706
|
});
|
|
742
707
|
}
|
|
743
708
|
return publicAssets;
|
|
@@ -749,6 +714,54 @@ var import_fs_extra7 = __toESM(require("fs-extra"), 1);
|
|
|
749
714
|
var import_picomatch = __toESM(require("picomatch"), 1);
|
|
750
715
|
var import_linkedom2 = require("linkedom");
|
|
751
716
|
var import_json5 = __toESM(require("json5"), 1);
|
|
717
|
+
|
|
718
|
+
// src/core/utils/importTsFile.ts
|
|
719
|
+
var import_jiti = __toESM(require("jiti"), 1);
|
|
720
|
+
var import_unimport2 = require("unimport");
|
|
721
|
+
var import_fs_extra6 = __toESM(require("fs-extra"), 1);
|
|
722
|
+
var import_path6 = require("path");
|
|
723
|
+
var import_babel = __toESM(require("jiti/dist/babel"), 1);
|
|
724
|
+
async function importTsFile(path5, config) {
|
|
725
|
+
config.logger.log("Loading file metadata:", path5);
|
|
726
|
+
const unimport2 = (0, import_unimport2.createUnimport)({
|
|
727
|
+
...getUnimportOptions(config),
|
|
728
|
+
// Only allow specific imports, not all from the project
|
|
729
|
+
imports: [{ name: "*", as: "browser", from: "webextension-polyfill" }],
|
|
730
|
+
dirs: []
|
|
731
|
+
});
|
|
732
|
+
await unimport2.init();
|
|
733
|
+
const text = await import_fs_extra6.default.readFile(path5, "utf-8");
|
|
734
|
+
const textNoImports = text.replace(/import.*[\n;]/gm, "");
|
|
735
|
+
const { code } = await unimport2.injectImports(textNoImports);
|
|
736
|
+
config.logger.log(
|
|
737
|
+
["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
|
|
738
|
+
);
|
|
739
|
+
const jiti = (0, import_jiti.default)(__filename, {
|
|
740
|
+
cache: false,
|
|
741
|
+
esmResolve: true,
|
|
742
|
+
interopDefault: true,
|
|
743
|
+
alias: {
|
|
744
|
+
"webextension-polyfill": (0, import_path6.resolve)(
|
|
745
|
+
config.root,
|
|
746
|
+
"node_modules/wxt/dist/virtual-modules/fake-browser.js"
|
|
747
|
+
)
|
|
748
|
+
},
|
|
749
|
+
transform(opts) {
|
|
750
|
+
if (opts.filename === path5)
|
|
751
|
+
return (0, import_babel.default)({ ...opts, source: code });
|
|
752
|
+
else
|
|
753
|
+
return (0, import_babel.default)(opts);
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
try {
|
|
757
|
+
return await jiti(path5);
|
|
758
|
+
} catch (err) {
|
|
759
|
+
config.logger.error(err);
|
|
760
|
+
throw err;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
// src/core/build/findEntrypoints.ts
|
|
752
765
|
var import_fast_glob2 = __toESM(require("fast-glob"), 1);
|
|
753
766
|
async function findEntrypoints(config) {
|
|
754
767
|
const relativePaths = await (0, import_fast_glob2.default)("**/*", {
|
|
@@ -873,7 +886,7 @@ async function getOptionsEntrypoint(config, path5) {
|
|
|
873
886
|
};
|
|
874
887
|
}
|
|
875
888
|
async function getBackgroundEntrypoint(config, path5) {
|
|
876
|
-
const { main: _, ...options } = await importTsFile(
|
|
889
|
+
const { main: _, ...options } = await importTsFile(path5, config);
|
|
877
890
|
if (options == null) {
|
|
878
891
|
throw Error("Background script does not have a default export");
|
|
879
892
|
}
|
|
@@ -887,8 +900,8 @@ async function getBackgroundEntrypoint(config, path5) {
|
|
|
887
900
|
}
|
|
888
901
|
async function getContentScriptEntrypoint(config, name, path5) {
|
|
889
902
|
const { main: _, ...options } = await importTsFile(
|
|
890
|
-
|
|
891
|
-
|
|
903
|
+
path5,
|
|
904
|
+
config
|
|
892
905
|
);
|
|
893
906
|
if (options == null) {
|
|
894
907
|
throw Error(`Content script ${name} does not have a default export`);
|
|
@@ -1718,7 +1731,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1718
1731
|
}
|
|
1719
1732
|
|
|
1720
1733
|
// package.json
|
|
1721
|
-
var version2 = "0.1.1-
|
|
1734
|
+
var version2 = "0.1.1-alpha4";
|
|
1722
1735
|
|
|
1723
1736
|
// src/core/utils/defineConfig.ts
|
|
1724
1737
|
function defineConfig(config) {
|
|
@@ -1761,7 +1774,7 @@ async function createServer2(config) {
|
|
|
1761
1774
|
const changes = detectDevChanges(fileChanges, server.currentOutput);
|
|
1762
1775
|
if (changes.type === "no-change")
|
|
1763
1776
|
return;
|
|
1764
|
-
|
|
1777
|
+
import_consola2.consola.info(
|
|
1765
1778
|
`Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors3.default.dim((0, import_node_path4.relative)(internalConfig.root, file))).join(", ")}`
|
|
1766
1779
|
);
|
|
1767
1780
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
@@ -1789,7 +1802,7 @@ async function createServer2(config) {
|
|
|
1789
1802
|
reloadContentScripts(changes.changedSteps, internalConfig, server);
|
|
1790
1803
|
break;
|
|
1791
1804
|
}
|
|
1792
|
-
|
|
1805
|
+
import_consola2.consola.success(`Reloaded: ${rebuiltNames}`);
|
|
1793
1806
|
});
|
|
1794
1807
|
});
|
|
1795
1808
|
return server;
|