wxt 0.2.5 → 0.3.0
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/browser.d.ts +10 -0
- package/dist/browser.js +7 -0
- package/dist/cli.cjs +141 -117
- package/dist/index.cjs +133 -109
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -3
- package/dist/index.js +110 -86
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/dist/index.d.ts
CHANGED
|
@@ -15,14 +15,14 @@ interface InlineConfig {
|
|
|
15
15
|
* directory.
|
|
16
16
|
*
|
|
17
17
|
* @default
|
|
18
|
-
* "<
|
|
18
|
+
* "<rootDir>"
|
|
19
19
|
*/
|
|
20
20
|
srcDir?: string;
|
|
21
21
|
/**
|
|
22
22
|
* Directory containing files that will be copied to the output directory as-is.
|
|
23
23
|
*
|
|
24
24
|
* @default
|
|
25
|
-
* "<
|
|
25
|
+
* "<rootDir>/publicDir"
|
|
26
26
|
*/
|
|
27
27
|
publicDir?: string;
|
|
28
28
|
/**
|
|
@@ -404,7 +404,7 @@ interface ExtensionRunnerConfig {
|
|
|
404
404
|
|
|
405
405
|
type EntrypointGroup = Entrypoint | Entrypoint[];
|
|
406
406
|
|
|
407
|
-
var version = "0.
|
|
407
|
+
var version = "0.3.0";
|
|
408
408
|
|
|
409
409
|
declare function defineConfig(config: UserConfig): UserConfig;
|
|
410
410
|
|
|
@@ -414,6 +414,10 @@ declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRun
|
|
|
414
414
|
* Bundles the extension for production. Returns a promise of the build result.
|
|
415
415
|
*/
|
|
416
416
|
declare function build(config: InlineConfig): Promise<BuildOutput>;
|
|
417
|
+
/**
|
|
418
|
+
* Creates a dev server, pre-builds all the files that need to exist to load the extension, and open
|
|
419
|
+
* the browser with the extension installed.
|
|
420
|
+
*/
|
|
417
421
|
declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
|
|
418
422
|
|
|
419
423
|
export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, build, createServer, defineConfig, defineRunnerConfig, version };
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
1
|
// src/core/utils/getInternalConfig.ts
|
|
2
2
|
import path2, { resolve as resolve6 } from "node:path";
|
|
3
|
-
import * as
|
|
3
|
+
import * as vite2 from "vite";
|
|
4
4
|
import { consola } from "consola";
|
|
5
5
|
|
|
6
6
|
// src/core/utils/entrypoints.ts
|
|
7
7
|
import path, { relative, resolve } from "node:path";
|
|
8
|
+
|
|
9
|
+
// src/core/utils/paths.ts
|
|
10
|
+
import nodePath from "node:path";
|
|
11
|
+
import * as vite from "vite";
|
|
12
|
+
function normalizePath2(path5) {
|
|
13
|
+
return vite.normalizePath(path5);
|
|
14
|
+
}
|
|
15
|
+
function unnormalizePath(path5) {
|
|
16
|
+
return nodePath.normalize(path5);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/core/utils/entrypoints.ts
|
|
8
20
|
function getEntrypointName(entrypointsDir, inputPath) {
|
|
9
21
|
const relativePath = path.relative(entrypointsDir, inputPath);
|
|
10
|
-
const name = relativePath.split(/[
|
|
22
|
+
const name = relativePath.split(/[\.\/\\]/, 2)[0];
|
|
11
23
|
return name;
|
|
12
24
|
}
|
|
13
25
|
function getEntrypointOutputFile(entrypoint, ext) {
|
|
14
26
|
return resolve(entrypoint.outputDir, `${entrypoint.name}${ext}`);
|
|
15
27
|
}
|
|
16
28
|
function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
17
|
-
return
|
|
29
|
+
return normalizePath2(
|
|
30
|
+
relative(outDir, getEntrypointOutputFile(entrypoint, ext))
|
|
31
|
+
);
|
|
18
32
|
}
|
|
19
33
|
|
|
20
34
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
@@ -176,7 +190,7 @@ function multipageMove(entrypoints, config) {
|
|
|
176
190
|
async writeBundle(_, bundle) {
|
|
177
191
|
for (const oldBundlePath in bundle) {
|
|
178
192
|
const entrypoint = entrypoints.find(
|
|
179
|
-
(entry) => !!entry.inputPath.endsWith(oldBundlePath)
|
|
193
|
+
(entry) => !!normalizePath2(entry.inputPath).endsWith(oldBundlePath)
|
|
180
194
|
);
|
|
181
195
|
if (entrypoint == null) {
|
|
182
196
|
config.logger.debug("No entrypoint found for", oldBundlePath);
|
|
@@ -217,11 +231,8 @@ import { mergeConfig } from "vite";
|
|
|
217
231
|
function getUnimportOptions(config) {
|
|
218
232
|
const defaultOptions = {
|
|
219
233
|
debugLog: config.logger.debug,
|
|
220
|
-
imports: [
|
|
221
|
-
|
|
222
|
-
{ name: "defineConfig", from: "wxt" }
|
|
223
|
-
],
|
|
224
|
-
presets: [{ package: "wxt/client" }],
|
|
234
|
+
imports: [{ name: "defineConfig", from: "wxt" }],
|
|
235
|
+
presets: [{ package: "wxt/client" }, { package: "wxt/browser" }],
|
|
225
236
|
warn: config.logger.warn,
|
|
226
237
|
dirs: ["./components/*", "./composables/*", "./hooks/*", "./utils/*"]
|
|
227
238
|
};
|
|
@@ -269,7 +280,7 @@ function virtualEntrypoin(type, config) {
|
|
|
269
280
|
const index = id.indexOf(virtualId);
|
|
270
281
|
if (index === -1)
|
|
271
282
|
return;
|
|
272
|
-
const inputPath = id.substring(index + virtualId.length);
|
|
283
|
+
const inputPath = normalizePath2(id.substring(index + virtualId.length));
|
|
273
284
|
return resolvedVirtualId + inputPath;
|
|
274
285
|
},
|
|
275
286
|
async load(id) {
|
|
@@ -350,7 +361,7 @@ function getGlobals(config) {
|
|
|
350
361
|
{
|
|
351
362
|
name: "__BROWSER__",
|
|
352
363
|
value: config.browser,
|
|
353
|
-
type: `
|
|
364
|
+
type: `string`
|
|
354
365
|
},
|
|
355
366
|
{
|
|
356
367
|
name: "__IS_CHROME__",
|
|
@@ -426,7 +437,7 @@ async function getInternalConfig(config, command) {
|
|
|
426
437
|
});
|
|
427
438
|
userConfig = loaded.config ?? {};
|
|
428
439
|
}
|
|
429
|
-
const merged =
|
|
440
|
+
const merged = vite2.mergeConfig(
|
|
430
441
|
baseConfig,
|
|
431
442
|
userConfig
|
|
432
443
|
);
|
|
@@ -435,13 +446,13 @@ async function getInternalConfig(config, command) {
|
|
|
435
446
|
srcDir,
|
|
436
447
|
userConfig.entrypointsDir ?? "entrypoints"
|
|
437
448
|
);
|
|
438
|
-
const publicDir = resolve6(
|
|
449
|
+
const publicDir = resolve6(root, userConfig.publicDir ?? "public");
|
|
439
450
|
const wxtDir = resolve6(srcDir, ".wxt");
|
|
440
451
|
const typesDir = resolve6(wxtDir, "types");
|
|
441
452
|
const env = { mode, browser, manifestVersion, command };
|
|
442
453
|
const userManifest = await resolveManifestConfig(env, userConfig.manifest);
|
|
443
454
|
const inlineManifest = await resolveManifestConfig(env, config.manifest);
|
|
444
|
-
const manifest =
|
|
455
|
+
const manifest = vite2.mergeConfig(userManifest, inlineManifest);
|
|
445
456
|
const finalConfig = {
|
|
446
457
|
...merged,
|
|
447
458
|
srcDir,
|
|
@@ -503,7 +514,7 @@ async function resolveManifestConfig(env, manifest) {
|
|
|
503
514
|
|
|
504
515
|
// src/index.ts
|
|
505
516
|
import pc3 from "picocolors";
|
|
506
|
-
import * as
|
|
517
|
+
import * as vite6 from "vite";
|
|
507
518
|
|
|
508
519
|
// src/core/utils/arrays.ts
|
|
509
520
|
function every(array, predicate) {
|
|
@@ -576,11 +587,12 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
576
587
|
}
|
|
577
588
|
function findEffectedSteps(changedFile, currentOutput) {
|
|
578
589
|
const changes = [];
|
|
579
|
-
const changedPath = changedFile[1];
|
|
590
|
+
const changedPath = normalizePath2(changedFile[1]);
|
|
580
591
|
const isChunkEffected = (chunk) => (
|
|
581
592
|
// If it's an HTML file with the same path, is is effected because HTML files need to be pre-rendered
|
|
582
|
-
//
|
|
593
|
+
// fileName is normalized, relative bundle path
|
|
583
594
|
chunk.type === "asset" && changedPath.endsWith(chunk.fileName) || // If it's a chunk that depends on the changed file, it is effected
|
|
595
|
+
// moduleIds are absolute, normalized paths
|
|
584
596
|
chunk.type === "chunk" && chunk.moduleIds.includes(changedPath)
|
|
585
597
|
);
|
|
586
598
|
for (const step of currentOutput.steps) {
|
|
@@ -602,7 +614,7 @@ import { consola as consola2 } from "consola";
|
|
|
602
614
|
import { relative as relative5 } from "node:path";
|
|
603
615
|
|
|
604
616
|
// src/core/build/buildEntrypoints.ts
|
|
605
|
-
import * as
|
|
617
|
+
import * as vite3 from "vite";
|
|
606
618
|
|
|
607
619
|
// src/core/utils/removeEmptyDirs.ts
|
|
608
620
|
import fs4 from "fs-extra";
|
|
@@ -623,9 +635,20 @@ async function removeEmptyDirs(dir) {
|
|
|
623
635
|
}
|
|
624
636
|
|
|
625
637
|
// src/core/build/buildEntrypoints.ts
|
|
626
|
-
import
|
|
627
|
-
import fs5 from "fs-extra";
|
|
638
|
+
import fs6 from "fs-extra";
|
|
628
639
|
import { dirname as dirname4, resolve as resolve7 } from "path";
|
|
640
|
+
|
|
641
|
+
// src/core/utils/public.ts
|
|
642
|
+
import fs5 from "fs-extra";
|
|
643
|
+
import glob from "fast-glob";
|
|
644
|
+
async function getPublicFiles(config) {
|
|
645
|
+
if (!await fs5.exists(config.publicDir))
|
|
646
|
+
return [];
|
|
647
|
+
const files = await glob("**/*", { cwd: config.publicDir });
|
|
648
|
+
return files.map(unnormalizePath);
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
// src/core/build/buildEntrypoints.ts
|
|
629
652
|
async function buildEntrypoints(groups, config) {
|
|
630
653
|
const steps = [];
|
|
631
654
|
for (const group of groups) {
|
|
@@ -664,11 +687,11 @@ async function buildSingleEntrypoint(entrypoint, config) {
|
|
|
664
687
|
}
|
|
665
688
|
}
|
|
666
689
|
};
|
|
667
|
-
const entryConfig =
|
|
690
|
+
const entryConfig = vite3.mergeConfig(
|
|
668
691
|
libMode,
|
|
669
692
|
config.vite
|
|
670
693
|
);
|
|
671
|
-
const result = await
|
|
694
|
+
const result = await vite3.build(entryConfig);
|
|
672
695
|
return {
|
|
673
696
|
entrypoints: entrypoint,
|
|
674
697
|
chunks: getBuildOutputChunks(result)
|
|
@@ -694,11 +717,11 @@ async function buildMultipleEntrypoints(entrypoints, config) {
|
|
|
694
717
|
}
|
|
695
718
|
}
|
|
696
719
|
};
|
|
697
|
-
const entryConfig =
|
|
720
|
+
const entryConfig = vite3.mergeConfig(
|
|
698
721
|
multiPage,
|
|
699
722
|
config.vite
|
|
700
723
|
);
|
|
701
|
-
const result = await
|
|
724
|
+
const result = await vite3.build(entryConfig);
|
|
702
725
|
return {
|
|
703
726
|
entrypoints,
|
|
704
727
|
chunks: getBuildOutputChunks(result)
|
|
@@ -712,21 +735,21 @@ function getBuildOutputChunks(result) {
|
|
|
712
735
|
return result.output;
|
|
713
736
|
}
|
|
714
737
|
async function copyPublicDirectory(config) {
|
|
738
|
+
const files = await getPublicFiles(config);
|
|
739
|
+
if (files.length === 0)
|
|
740
|
+
return [];
|
|
715
741
|
const publicAssets = [];
|
|
716
|
-
if (!await fs5.exists(config.publicDir))
|
|
717
|
-
return publicAssets;
|
|
718
|
-
const files = await glob("**/*", { cwd: config.publicDir });
|
|
719
742
|
for (const file of files) {
|
|
720
743
|
const srcPath = resolve7(config.publicDir, file);
|
|
721
744
|
const outPath = resolve7(config.outDir, file);
|
|
722
|
-
await
|
|
723
|
-
await
|
|
745
|
+
await fs6.ensureDir(dirname4(outPath));
|
|
746
|
+
await fs6.copyFile(srcPath, outPath);
|
|
724
747
|
publicAssets.push({
|
|
725
748
|
type: "asset",
|
|
726
749
|
fileName: file,
|
|
727
750
|
name: file,
|
|
728
751
|
needsCodeReference: false,
|
|
729
|
-
source: await
|
|
752
|
+
source: await fs6.readFile(srcPath)
|
|
730
753
|
});
|
|
731
754
|
}
|
|
732
755
|
return publicAssets;
|
|
@@ -734,7 +757,7 @@ async function copyPublicDirectory(config) {
|
|
|
734
757
|
|
|
735
758
|
// src/core/build/findEntrypoints.ts
|
|
736
759
|
import { relative as relative3, resolve as resolve9 } from "path";
|
|
737
|
-
import
|
|
760
|
+
import fs8 from "fs-extra";
|
|
738
761
|
import picomatch from "picomatch";
|
|
739
762
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
740
763
|
import JSON5 from "json5";
|
|
@@ -742,7 +765,7 @@ import JSON5 from "json5";
|
|
|
742
765
|
// src/core/utils/importTsFile.ts
|
|
743
766
|
import createJITI from "jiti";
|
|
744
767
|
import { createUnimport as createUnimport2 } from "unimport";
|
|
745
|
-
import
|
|
768
|
+
import fs7 from "fs-extra";
|
|
746
769
|
import { resolve as resolve8 } from "path";
|
|
747
770
|
import transform from "jiti/dist/babel";
|
|
748
771
|
|
|
@@ -757,14 +780,14 @@ function removeImportStatements(text) {
|
|
|
757
780
|
// src/core/utils/importTsFile.ts
|
|
758
781
|
async function importTsFile(path5, config) {
|
|
759
782
|
config.logger.debug("Loading file metadata:", path5);
|
|
783
|
+
const normalPath = normalizePath2(path5);
|
|
760
784
|
const unimport2 = createUnimport2({
|
|
761
785
|
...getUnimportOptions(config),
|
|
762
786
|
// Only allow specific imports, not all from the project
|
|
763
|
-
imports: [{ name: "*", as: "browser", from: "webextension-polyfill" }],
|
|
764
787
|
dirs: []
|
|
765
788
|
});
|
|
766
789
|
await unimport2.init();
|
|
767
|
-
const text = await
|
|
790
|
+
const text = await fs7.readFile(path5, "utf-8");
|
|
768
791
|
const textNoImports = removeImportStatements(text);
|
|
769
792
|
const { code } = await unimport2.injectImports(textNoImports);
|
|
770
793
|
config.logger.debug(
|
|
@@ -781,7 +804,7 @@ async function importTsFile(path5, config) {
|
|
|
781
804
|
)
|
|
782
805
|
},
|
|
783
806
|
transform(opts) {
|
|
784
|
-
if (opts.filename ===
|
|
807
|
+
if (opts.filename === normalPath)
|
|
785
808
|
return transform({ ...opts, source: code });
|
|
786
809
|
else
|
|
787
810
|
return transform(opts);
|
|
@@ -874,7 +897,7 @@ ${JSON.stringify(
|
|
|
874
897
|
}
|
|
875
898
|
async function getPopupEntrypoint(config, path5) {
|
|
876
899
|
const options = {};
|
|
877
|
-
const content = await
|
|
900
|
+
const content = await fs8.readFile(path5, "utf-8");
|
|
878
901
|
const { document } = parseHTML2(content);
|
|
879
902
|
const title = document.querySelector("title");
|
|
880
903
|
if (title != null)
|
|
@@ -904,7 +927,7 @@ async function getPopupEntrypoint(config, path5) {
|
|
|
904
927
|
}
|
|
905
928
|
async function getOptionsEntrypoint(config, path5) {
|
|
906
929
|
const options = {};
|
|
907
|
-
const content = await
|
|
930
|
+
const content = await fs8.readFile(path5, "utf-8");
|
|
908
931
|
const { document } = parseHTML2(content);
|
|
909
932
|
const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
|
|
910
933
|
if (openInTabContent) {
|
|
@@ -999,10 +1022,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
|
|
|
999
1022
|
|
|
1000
1023
|
// src/core/build/generateTypesDir.ts
|
|
1001
1024
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
1002
|
-
import
|
|
1025
|
+
import fs9 from "fs-extra";
|
|
1003
1026
|
import { relative as relative4, resolve as resolve10 } from "path";
|
|
1004
1027
|
async function generateTypesDir(entrypoints, config) {
|
|
1005
|
-
await
|
|
1028
|
+
await fs9.ensureDir(config.typesDir);
|
|
1006
1029
|
const references = [];
|
|
1007
1030
|
references.push(await writeImportsDeclarationFile(config));
|
|
1008
1031
|
references.push(await writePathsDeclarationFile(entrypoints, config));
|
|
@@ -1014,7 +1037,7 @@ async function writeImportsDeclarationFile(config) {
|
|
|
1014
1037
|
const filePath = resolve10(config.typesDir, "imports.d.ts");
|
|
1015
1038
|
const unimport2 = createUnimport3(getUnimportOptions(config));
|
|
1016
1039
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
1017
|
-
await
|
|
1040
|
+
await fs9.writeFile(
|
|
1018
1041
|
filePath,
|
|
1019
1042
|
["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
|
|
1020
1043
|
"\n"
|
|
@@ -1024,28 +1047,34 @@ async function writeImportsDeclarationFile(config) {
|
|
|
1024
1047
|
}
|
|
1025
1048
|
async function writePathsDeclarationFile(entrypoints, config) {
|
|
1026
1049
|
const filePath = resolve10(config.typesDir, "paths.d.ts");
|
|
1027
|
-
const unions = entrypoints.map(
|
|
1028
|
-
|
|
1050
|
+
const unions = entrypoints.map(
|
|
1051
|
+
(entry) => getEntrypointBundlePath(
|
|
1029
1052
|
entry,
|
|
1030
1053
|
config.outDir,
|
|
1031
1054
|
entry.inputPath.endsWith(".html") ? ".html" : ".js"
|
|
1032
|
-
)
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1055
|
+
)
|
|
1056
|
+
).concat(await getPublicFiles(config)).map(normalizePath2).map((path5) => ` | "/${path5}"`).sort().join("\n");
|
|
1057
|
+
const template = `// Generated by wxt
|
|
1058
|
+
import "wxt/browser";
|
|
1059
|
+
|
|
1060
|
+
declare module "wxt/browser" {
|
|
1061
|
+
type PublicPath =
|
|
1062
|
+
{{ union }}
|
|
1063
|
+
export interface ProjectRuntime extends Runtime.Static {
|
|
1064
|
+
getURL(path: PublicPath): string;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
`;
|
|
1068
|
+
await fs9.writeFile(
|
|
1036
1069
|
filePath,
|
|
1037
|
-
|
|
1038
|
-
"// Generated by wxt",
|
|
1039
|
-
"type EntrypointPath =",
|
|
1040
|
-
...unions.length === 0 ? [" never"] : unions
|
|
1041
|
-
].join("\n") + "\n"
|
|
1070
|
+
template.replace("{{ union }}", unions || " | never")
|
|
1042
1071
|
);
|
|
1043
1072
|
return filePath;
|
|
1044
1073
|
}
|
|
1045
1074
|
async function writeGlobalsDeclarationFile(config) {
|
|
1046
1075
|
const filePath = resolve10(config.typesDir, "globals.d.ts");
|
|
1047
1076
|
const globals = getGlobals(config);
|
|
1048
|
-
await
|
|
1077
|
+
await fs9.writeFile(
|
|
1049
1078
|
filePath,
|
|
1050
1079
|
[
|
|
1051
1080
|
"// Generated by wxt",
|
|
@@ -1061,13 +1090,13 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
1061
1090
|
async function writeMainDeclarationFile(references, config) {
|
|
1062
1091
|
const dir = config.wxtDir;
|
|
1063
1092
|
const filePath = resolve10(dir, "wxt.d.ts");
|
|
1064
|
-
await
|
|
1093
|
+
await fs9.writeFile(
|
|
1065
1094
|
filePath,
|
|
1066
1095
|
[
|
|
1067
1096
|
"// Generated by wxt",
|
|
1068
1097
|
`/// <reference types="vite/client" />`,
|
|
1069
1098
|
...references.map(
|
|
1070
|
-
(ref) => `/// <reference types="./${relative4(dir, ref)}" />`
|
|
1099
|
+
(ref) => `/// <reference types="./${normalizePath2(relative4(dir, ref))}" />`
|
|
1071
1100
|
)
|
|
1072
1101
|
].join("\n") + "\n"
|
|
1073
1102
|
);
|
|
@@ -1075,7 +1104,7 @@ async function writeMainDeclarationFile(references, config) {
|
|
|
1075
1104
|
}
|
|
1076
1105
|
async function writeTsConfigFile(mainReference, config) {
|
|
1077
1106
|
const dir = config.wxtDir;
|
|
1078
|
-
await
|
|
1107
|
+
await fs9.writeFile(
|
|
1079
1108
|
resolve10(dir, "tsconfig.json"),
|
|
1080
1109
|
`{
|
|
1081
1110
|
"compilerOptions": {
|
|
@@ -1086,37 +1115,32 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1086
1115
|
"esModuleInterop": true,
|
|
1087
1116
|
"forceConsistentCasingInFileNames": true,
|
|
1088
1117
|
"resolveJsonModule": true,
|
|
1089
|
-
|
|
1090
|
-
/* Type Checking */
|
|
1091
1118
|
"strict": true,
|
|
1092
|
-
|
|
1093
|
-
/* Completeness */
|
|
1119
|
+
"lib": ["DOM", "WebWorker"],
|
|
1094
1120
|
"skipLibCheck": true,
|
|
1095
|
-
|
|
1096
|
-
/* Aliases */
|
|
1097
|
-
"baseUrl": "${relative4(dir, config.root)}",
|
|
1121
|
+
"baseUrl": "${normalizePath2(relative4(dir, config.root))}",
|
|
1098
1122
|
"paths": {
|
|
1099
1123
|
"@@": ["."],
|
|
1100
1124
|
"@@/*": ["./*"],
|
|
1101
1125
|
"~~": ["."],
|
|
1102
1126
|
"~~/*": ["./*"],
|
|
1103
|
-
"@": ["${relative4(config.root, config.srcDir)}"],
|
|
1104
|
-
"@/*": ["${relative4(config.root, config.srcDir)}/*"],
|
|
1105
|
-
"~": ["${relative4(config.root, config.srcDir)}"],
|
|
1106
|
-
"~/*": ["${relative4(config.root, config.srcDir)}/*"]
|
|
1127
|
+
"@": ["${normalizePath2(relative4(config.root, config.srcDir))}"],
|
|
1128
|
+
"@/*": ["${normalizePath2(relative4(config.root, config.srcDir))}/*"],
|
|
1129
|
+
"~": ["${normalizePath2(relative4(config.root, config.srcDir))}"],
|
|
1130
|
+
"~/*": ["${normalizePath2(relative4(config.root, config.srcDir))}/*"]
|
|
1107
1131
|
}
|
|
1108
1132
|
},
|
|
1109
1133
|
"include": [
|
|
1110
|
-
"${relative4(dir, config.root)}/**/*",
|
|
1111
|
-
"./${relative4(dir, mainReference)}"
|
|
1134
|
+
"${normalizePath2(relative4(dir, config.root))}/**/*",
|
|
1135
|
+
"./${normalizePath2(relative4(dir, mainReference))}"
|
|
1112
1136
|
],
|
|
1113
|
-
"exclude": ["${relative4(dir, config.outBaseDir)}"]
|
|
1137
|
+
"exclude": ["${normalizePath2(relative4(dir, config.outBaseDir))}"]
|
|
1114
1138
|
}`
|
|
1115
1139
|
);
|
|
1116
1140
|
}
|
|
1117
1141
|
|
|
1118
1142
|
// src/core/utils/manifest.ts
|
|
1119
|
-
import
|
|
1143
|
+
import fs11 from "fs-extra";
|
|
1120
1144
|
import { resolve as resolve12 } from "path";
|
|
1121
1145
|
|
|
1122
1146
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
@@ -1202,11 +1226,11 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1202
1226
|
|
|
1203
1227
|
// src/core/utils/package.ts
|
|
1204
1228
|
import { resolve as resolve11 } from "node:path";
|
|
1205
|
-
import
|
|
1229
|
+
import fs10 from "fs-extra";
|
|
1206
1230
|
async function getPackageJson(config) {
|
|
1207
1231
|
const file = resolve11(config.root, "package.json");
|
|
1208
1232
|
try {
|
|
1209
|
-
return await
|
|
1233
|
+
return await fs10.readJson(file);
|
|
1210
1234
|
} catch (err) {
|
|
1211
1235
|
config.logger.debug(
|
|
1212
1236
|
`Failed to read package.json at: ${file}. Returning undefined.`
|
|
@@ -1218,8 +1242,8 @@ async function getPackageJson(config) {
|
|
|
1218
1242
|
// src/core/utils/manifest.ts
|
|
1219
1243
|
async function writeManifest(manifest, output, config) {
|
|
1220
1244
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1221
|
-
await
|
|
1222
|
-
await
|
|
1245
|
+
await fs11.ensureDir(config.outDir);
|
|
1246
|
+
await fs11.writeFile(resolve12(config.outDir, "manifest.json"), str, "utf-8");
|
|
1223
1247
|
output.publicAssets.unshift({
|
|
1224
1248
|
type: "asset",
|
|
1225
1249
|
fileName: "manifest.json",
|
|
@@ -1500,8 +1524,8 @@ function addHostPermission(manifest, hostPermission) {
|
|
|
1500
1524
|
|
|
1501
1525
|
// src/core/build.ts
|
|
1502
1526
|
import pc2 from "picocolors";
|
|
1503
|
-
import * as
|
|
1504
|
-
import
|
|
1527
|
+
import * as vite4 from "vite";
|
|
1528
|
+
import fs13 from "fs-extra";
|
|
1505
1529
|
|
|
1506
1530
|
// src/core/utils/groupEntrypoints.ts
|
|
1507
1531
|
function groupEntrypoints(entrypoints) {
|
|
@@ -1554,7 +1578,7 @@ import { resolve as resolve13 } from "path";
|
|
|
1554
1578
|
// src/core/log/printFileList.ts
|
|
1555
1579
|
import path4 from "node:path";
|
|
1556
1580
|
import pc from "picocolors";
|
|
1557
|
-
import
|
|
1581
|
+
import fs12 from "fs-extra";
|
|
1558
1582
|
import { filesize } from "filesize";
|
|
1559
1583
|
|
|
1560
1584
|
// src/core/log/printTable.ts
|
|
@@ -1594,7 +1618,7 @@ async function printFileList(log, baseDir, files) {
|
|
|
1594
1618
|
];
|
|
1595
1619
|
const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
|
|
1596
1620
|
const color = getChunkColor(file);
|
|
1597
|
-
const stats = await
|
|
1621
|
+
const stats = await fs12.lstat(file);
|
|
1598
1622
|
totalSize += stats.size;
|
|
1599
1623
|
const size = String(filesize(stats.size));
|
|
1600
1624
|
return [
|
|
@@ -1654,12 +1678,12 @@ async function buildInternal(config) {
|
|
|
1654
1678
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
1655
1679
|
config.logger.info(
|
|
1656
1680
|
`${verb} ${pc2.cyan(target)} for ${pc2.cyan(config.mode)} with ${pc2.green(
|
|
1657
|
-
`Vite ${
|
|
1681
|
+
`Vite ${vite4.version}`
|
|
1658
1682
|
)}`
|
|
1659
1683
|
);
|
|
1660
1684
|
const startTime = Date.now();
|
|
1661
|
-
await
|
|
1662
|
-
await
|
|
1685
|
+
await fs13.rm(config.outDir, { recursive: true, force: true });
|
|
1686
|
+
await fs13.ensureDir(config.outDir);
|
|
1663
1687
|
const entrypoints = await findEntrypoints(config);
|
|
1664
1688
|
const groups = groupEntrypoints(entrypoints);
|
|
1665
1689
|
const { output } = await rebuild(config, groups, void 0);
|
|
@@ -1708,7 +1732,7 @@ async function rebuild(config, entrypointGroups, existingOutput = {
|
|
|
1708
1732
|
}
|
|
1709
1733
|
|
|
1710
1734
|
// src/core/server.ts
|
|
1711
|
-
import * as
|
|
1735
|
+
import * as vite5 from "vite";
|
|
1712
1736
|
|
|
1713
1737
|
// src/core/runners/createWebExtRunner.ts
|
|
1714
1738
|
function createWebExtRunner() {
|
|
@@ -1787,8 +1811,8 @@ async function getServerInfo() {
|
|
|
1787
1811
|
}
|
|
1788
1812
|
async function setupServer(serverInfo, config) {
|
|
1789
1813
|
const runner = createWebExtRunner();
|
|
1790
|
-
const viteServer = await
|
|
1791
|
-
|
|
1814
|
+
const viteServer = await vite5.createServer(
|
|
1815
|
+
vite5.mergeConfig(serverInfo, config.vite)
|
|
1792
1816
|
);
|
|
1793
1817
|
const start = async () => {
|
|
1794
1818
|
await viteServer.listen(server.port);
|
|
@@ -1854,7 +1878,7 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
1854
1878
|
}
|
|
1855
1879
|
|
|
1856
1880
|
// package.json
|
|
1857
|
-
var version2 = "0.
|
|
1881
|
+
var version2 = "0.3.0";
|
|
1858
1882
|
|
|
1859
1883
|
// src/core/utils/defineConfig.ts
|
|
1860
1884
|
function defineConfig(config) {
|
|
@@ -1874,7 +1898,7 @@ async function build2(config) {
|
|
|
1874
1898
|
async function createServer2(config) {
|
|
1875
1899
|
const serverInfo = await getServerInfo();
|
|
1876
1900
|
const getLatestInternalConfig = () => {
|
|
1877
|
-
const viteConfig =
|
|
1901
|
+
const viteConfig = vite6.mergeConfig(
|
|
1878
1902
|
serverInfo.viteServerConfig,
|
|
1879
1903
|
config?.vite ?? {}
|
|
1880
1904
|
);
|