wxt 0.5.2 → 0.5.3
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 +237 -181
- package/dist/index.cjs +212 -153
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -11
- package/dist/index.d.ts +4 -11
- package/dist/index.js +236 -177
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
1
|
// src/core/utils/getInternalConfig.ts
|
|
2
|
-
import
|
|
2
|
+
import { loadConfig } from "c12";
|
|
3
|
+
import path2 from "node:path";
|
|
3
4
|
import * as vite2 from "vite";
|
|
4
|
-
|
|
5
|
+
|
|
6
|
+
// src/core/utils/createFsCache.ts
|
|
7
|
+
import fs2, { ensureDir } from "fs-extra";
|
|
8
|
+
import { dirname, resolve } from "path";
|
|
9
|
+
|
|
10
|
+
// src/core/utils/fs.ts
|
|
11
|
+
import fs from "fs-extra";
|
|
12
|
+
async function writeFileIfDifferent(file, newContents) {
|
|
13
|
+
const existingContents = await fs.readFile(file, "utf-8").catch(() => void 0);
|
|
14
|
+
if (existingContents !== newContents) {
|
|
15
|
+
await fs.writeFile(file, newContents);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// src/core/utils/createFsCache.ts
|
|
20
|
+
function createFsCache(wxtDir) {
|
|
21
|
+
const getPath = (key) => resolve(wxtDir, "cache", encodeURIComponent(key));
|
|
22
|
+
return {
|
|
23
|
+
async set(key, value) {
|
|
24
|
+
const path7 = getPath(key);
|
|
25
|
+
await ensureDir(dirname(path7));
|
|
26
|
+
await writeFileIfDifferent(path7, value);
|
|
27
|
+
},
|
|
28
|
+
async get(key) {
|
|
29
|
+
const path7 = getPath(key);
|
|
30
|
+
try {
|
|
31
|
+
return await fs2.readFile(path7, "utf-8");
|
|
32
|
+
} catch {
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/core/utils/getInternalConfig.ts
|
|
40
|
+
import consola, { LogLevels } from "consola";
|
|
5
41
|
|
|
6
42
|
// src/core/utils/entrypoints.ts
|
|
7
|
-
import path, { relative, resolve } from "node:path";
|
|
43
|
+
import path, { relative, resolve as resolve2 } from "node:path";
|
|
8
44
|
|
|
9
45
|
// src/core/utils/paths.ts
|
|
10
46
|
import nodePath from "node:path";
|
|
@@ -25,7 +61,7 @@ function getEntrypointName(entrypointsDir, inputPath) {
|
|
|
25
61
|
return name;
|
|
26
62
|
}
|
|
27
63
|
function getEntrypointOutputFile(entrypoint, ext) {
|
|
28
|
-
return
|
|
64
|
+
return resolve2(entrypoint.outputDir, `${entrypoint.name}${ext}`);
|
|
29
65
|
}
|
|
30
66
|
function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
31
67
|
return normalizePath2(
|
|
@@ -35,7 +71,7 @@ function getEntrypointBundlePath(entrypoint, outDir, ext) {
|
|
|
35
71
|
|
|
36
72
|
// src/core/vite-plugins/devHtmlPrerender.ts
|
|
37
73
|
import { parseHTML } from "linkedom";
|
|
38
|
-
import { dirname, isAbsolute, relative as relative2, resolve as
|
|
74
|
+
import { dirname as dirname2, isAbsolute, relative as relative2, resolve as resolve3 } from "path";
|
|
39
75
|
function devHtmlPrerender(config) {
|
|
40
76
|
return {
|
|
41
77
|
apply: "build",
|
|
@@ -44,7 +80,7 @@ function devHtmlPrerender(config) {
|
|
|
44
80
|
return {
|
|
45
81
|
resolve: {
|
|
46
82
|
alias: {
|
|
47
|
-
"@wxt/reload-html":
|
|
83
|
+
"@wxt/reload-html": resolve3(
|
|
48
84
|
config.root,
|
|
49
85
|
"node_modules/wxt/dist/virtual-modules/reload-html.js"
|
|
50
86
|
)
|
|
@@ -73,7 +109,7 @@ function devHtmlPrerender(config) {
|
|
|
73
109
|
if (isAbsolute(src)) {
|
|
74
110
|
element.setAttribute(attr, server.origin + src);
|
|
75
111
|
} else if (src.startsWith(".")) {
|
|
76
|
-
const abs =
|
|
112
|
+
const abs = resolve3(dirname2(id), src);
|
|
77
113
|
const pathname = relative2(config.root, abs);
|
|
78
114
|
element.setAttribute(attr, `${server.origin}/${pathname}`);
|
|
79
115
|
}
|
|
@@ -184,8 +220,8 @@ function download(config) {
|
|
|
184
220
|
}
|
|
185
221
|
|
|
186
222
|
// src/core/vite-plugins/multipageMove.ts
|
|
187
|
-
import { dirname as
|
|
188
|
-
import
|
|
223
|
+
import { dirname as dirname3, extname, resolve as resolve4 } from "node:path";
|
|
224
|
+
import fs3, { ensureDir as ensureDir2 } from "fs-extra";
|
|
189
225
|
function multipageMove(entrypoints, config) {
|
|
190
226
|
return {
|
|
191
227
|
name: "wxt:multipage-move",
|
|
@@ -212,10 +248,10 @@ function multipageMove(entrypoints, config) {
|
|
|
212
248
|
);
|
|
213
249
|
continue;
|
|
214
250
|
}
|
|
215
|
-
const oldAbsPath =
|
|
216
|
-
const newAbsPath =
|
|
217
|
-
await
|
|
218
|
-
await
|
|
251
|
+
const oldAbsPath = resolve4(config.outDir, oldBundlePath);
|
|
252
|
+
const newAbsPath = resolve4(config.outDir, newBundlePath);
|
|
253
|
+
await ensureDir2(dirname3(newAbsPath));
|
|
254
|
+
await fs3.move(oldAbsPath, newAbsPath, { overwrite: true });
|
|
219
255
|
const renamedChunk = {
|
|
220
256
|
...bundle[oldBundlePath],
|
|
221
257
|
fileName: newBundlePath
|
|
@@ -277,8 +313,8 @@ function unimport(config) {
|
|
|
277
313
|
}
|
|
278
314
|
|
|
279
315
|
// src/core/vite-plugins/virtualEntrypoint.ts
|
|
280
|
-
import
|
|
281
|
-
import { resolve as
|
|
316
|
+
import fs4 from "fs-extra";
|
|
317
|
+
import { resolve as resolve5 } from "path";
|
|
282
318
|
function virtualEntrypoin(type, config) {
|
|
283
319
|
const virtualId = `virtual:wxt-${type}?`;
|
|
284
320
|
const resolvedVirtualId = `\0${virtualId}`;
|
|
@@ -295,8 +331,8 @@ function virtualEntrypoin(type, config) {
|
|
|
295
331
|
if (!id.startsWith(resolvedVirtualId))
|
|
296
332
|
return;
|
|
297
333
|
const inputPath = id.replace(resolvedVirtualId, "");
|
|
298
|
-
const template = await
|
|
299
|
-
|
|
334
|
+
const template = await fs4.readFile(
|
|
335
|
+
resolve5(
|
|
300
336
|
config.root,
|
|
301
337
|
`node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
|
|
302
338
|
),
|
|
@@ -370,39 +406,6 @@ function cssEntrypoints(entrypoint, config) {
|
|
|
370
406
|
};
|
|
371
407
|
}
|
|
372
408
|
|
|
373
|
-
// src/core/utils/createFsCache.ts
|
|
374
|
-
import fs4, { ensureDir as ensureDir2 } from "fs-extra";
|
|
375
|
-
import { dirname as dirname3, resolve as resolve5 } from "path";
|
|
376
|
-
|
|
377
|
-
// src/core/utils/fs.ts
|
|
378
|
-
import fs3 from "fs-extra";
|
|
379
|
-
async function writeFileIfDifferent(file, newContents) {
|
|
380
|
-
const existingContents = await fs3.readFile(file, "utf-8").catch(() => void 0);
|
|
381
|
-
if (existingContents !== newContents) {
|
|
382
|
-
await fs3.writeFile(file, newContents);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// src/core/utils/createFsCache.ts
|
|
387
|
-
function createFsCache(wxtDir) {
|
|
388
|
-
const getPath = (key) => resolve5(wxtDir, "cache", encodeURIComponent(key));
|
|
389
|
-
return {
|
|
390
|
-
async set(key, value) {
|
|
391
|
-
const path7 = getPath(key);
|
|
392
|
-
await ensureDir2(dirname3(path7));
|
|
393
|
-
await writeFileIfDifferent(path7, value);
|
|
394
|
-
},
|
|
395
|
-
async get(key) {
|
|
396
|
-
const path7 = getPath(key);
|
|
397
|
-
try {
|
|
398
|
-
return await fs4.readFile(path7, "utf-8");
|
|
399
|
-
} catch {
|
|
400
|
-
return void 0;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
|
|
406
409
|
// src/core/utils/globals.ts
|
|
407
410
|
function getGlobals(config) {
|
|
408
411
|
return [
|
|
@@ -450,128 +453,182 @@ function getGlobals(config) {
|
|
|
450
453
|
}
|
|
451
454
|
|
|
452
455
|
// src/core/utils/getInternalConfig.ts
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const mode = config.mode ?? (command === "build" ? "production" : "development");
|
|
457
|
-
const browser = config.browser ?? "chrome";
|
|
458
|
-
const manifestVersion = config.manifestVersion ?? (browser == "firefox" ? 2 : 3);
|
|
459
|
-
const outBaseDir = path2.resolve(root, ".output");
|
|
460
|
-
const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
461
|
-
const logger = config.logger ?? consola;
|
|
462
|
-
const debug = !!config.debug;
|
|
463
|
-
if (debug)
|
|
464
|
-
logger.level = LogLevels.debug;
|
|
465
|
-
const baseConfig = {
|
|
466
|
-
root,
|
|
467
|
-
outDir,
|
|
468
|
-
outBaseDir,
|
|
469
|
-
storeIds: config.storeIds ?? {},
|
|
470
|
-
browser,
|
|
471
|
-
manifestVersion,
|
|
472
|
-
mode,
|
|
473
|
-
command,
|
|
474
|
-
debug,
|
|
475
|
-
logger,
|
|
476
|
-
vite: config.vite ?? {},
|
|
477
|
-
imports: config.imports ?? {},
|
|
478
|
-
runnerConfig: await loadConfig({
|
|
479
|
-
name: "web-ext",
|
|
480
|
-
cwd: root,
|
|
481
|
-
globalRc: true,
|
|
482
|
-
rcFile: ".webextrc",
|
|
483
|
-
overrides: config.runner
|
|
484
|
-
})
|
|
485
|
-
};
|
|
486
|
-
let userConfig = {
|
|
487
|
-
mode
|
|
488
|
-
};
|
|
489
|
-
if (config.configFile !== false) {
|
|
456
|
+
async function getInternalConfig(inlineConfig, command) {
|
|
457
|
+
let userConfig = {};
|
|
458
|
+
if (inlineConfig.configFile !== false) {
|
|
490
459
|
const loaded = await loadConfig({
|
|
491
460
|
name: "wxt",
|
|
492
|
-
cwd: root,
|
|
461
|
+
cwd: inlineConfig.root ?? process.cwd(),
|
|
493
462
|
rcFile: false
|
|
494
463
|
});
|
|
495
464
|
userConfig = loaded.config ?? {};
|
|
496
465
|
}
|
|
497
|
-
const
|
|
498
|
-
|
|
499
|
-
|
|
466
|
+
const mergedConfig = mergeInlineConfig(inlineConfig, userConfig);
|
|
467
|
+
const debug = mergedConfig.debug ?? false;
|
|
468
|
+
const logger = mergedConfig.logger ?? consola;
|
|
469
|
+
if (debug)
|
|
470
|
+
logger.level = LogLevels.debug;
|
|
471
|
+
const browser = mergedConfig.browser ?? "chrome";
|
|
472
|
+
const manifestVersion = mergedConfig.manifestVersion ?? (browser == "firefox" ? 2 : 3);
|
|
473
|
+
const mode = mergedConfig.mode ?? (command === "build" ? "production" : "development");
|
|
474
|
+
const env = { browser, command, manifestVersion, mode };
|
|
475
|
+
const root = path2.resolve(
|
|
476
|
+
inlineConfig.root ?? userConfig.root ?? process.cwd()
|
|
500
477
|
);
|
|
501
|
-
const
|
|
502
|
-
const
|
|
478
|
+
const wxtDir = path2.resolve(root, ".wxt");
|
|
479
|
+
const srcDir = path2.resolve(root, mergedConfig.srcDir ?? root);
|
|
480
|
+
const entrypointsDir = path2.resolve(
|
|
503
481
|
srcDir,
|
|
504
|
-
|
|
482
|
+
mergedConfig.entrypointsDir ?? "entrypoints"
|
|
505
483
|
);
|
|
506
|
-
const publicDir =
|
|
507
|
-
const
|
|
508
|
-
const
|
|
509
|
-
const
|
|
510
|
-
const
|
|
511
|
-
|
|
512
|
-
|
|
484
|
+
const publicDir = path2.resolve(srcDir, mergedConfig.publicDir ?? "public");
|
|
485
|
+
const typesDir = path2.resolve(wxtDir, "types");
|
|
486
|
+
const outBaseDir = path2.resolve(root, ".output");
|
|
487
|
+
const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
|
|
488
|
+
const runnerConfig = await loadConfig({
|
|
489
|
+
name: "web-ext",
|
|
490
|
+
cwd: root,
|
|
491
|
+
globalRc: true,
|
|
492
|
+
rcFile: ".webextrc",
|
|
493
|
+
overrides: mergedConfig.runner
|
|
494
|
+
});
|
|
513
495
|
const finalConfig = {
|
|
514
|
-
|
|
515
|
-
|
|
496
|
+
browser,
|
|
497
|
+
command,
|
|
498
|
+
debug,
|
|
516
499
|
entrypointsDir,
|
|
500
|
+
fsCache: createFsCache(wxtDir),
|
|
501
|
+
imports: mergedConfig.imports ?? {},
|
|
502
|
+
logger,
|
|
503
|
+
manifest: await resolveManifestConfig(env, mergedConfig.manifest),
|
|
504
|
+
manifestVersion,
|
|
505
|
+
mode,
|
|
506
|
+
outBaseDir,
|
|
507
|
+
outDir,
|
|
517
508
|
publicDir,
|
|
518
|
-
|
|
509
|
+
root,
|
|
510
|
+
runnerConfig,
|
|
511
|
+
srcDir,
|
|
519
512
|
typesDir,
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
525
|
-
sourcesRoot: root,
|
|
526
|
-
...userConfig.zip,
|
|
527
|
-
...config.zip,
|
|
528
|
-
ignoredSources: [
|
|
529
|
-
"**/node_modules",
|
|
530
|
-
// WXT files
|
|
531
|
-
"**/web-ext.config.ts",
|
|
532
|
-
// Hidden files
|
|
533
|
-
"**/.*",
|
|
534
|
-
// Tests
|
|
535
|
-
"**/__tests__/**",
|
|
536
|
-
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
537
|
-
// User config
|
|
538
|
-
...userConfig.zip?.ignoredSources ?? [],
|
|
539
|
-
...config.zip?.ignoredSources ?? []
|
|
540
|
-
]
|
|
541
|
-
}
|
|
513
|
+
vite: {},
|
|
514
|
+
// Real value added after this object is initialized.
|
|
515
|
+
wxtDir,
|
|
516
|
+
zip: resolveInternalZipConfig(root, mergedConfig)
|
|
542
517
|
};
|
|
543
|
-
finalConfig.vite
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
finalConfig.vite.build.outDir = outDir;
|
|
548
|
-
finalConfig.vite.build.emptyOutDir = false;
|
|
549
|
-
finalConfig.vite.plugins ??= [];
|
|
550
|
-
finalConfig.vite.plugins.push(download(finalConfig));
|
|
551
|
-
finalConfig.vite.plugins.push(devHtmlPrerender(finalConfig));
|
|
552
|
-
finalConfig.vite.plugins.push(unimport(finalConfig));
|
|
553
|
-
finalConfig.vite.plugins.push(
|
|
554
|
-
virtualEntrypoin("background", finalConfig)
|
|
555
|
-
);
|
|
556
|
-
finalConfig.vite.plugins.push(
|
|
557
|
-
virtualEntrypoin("content-script", finalConfig)
|
|
518
|
+
finalConfig.vite = await resolveInternalViteConfig(
|
|
519
|
+
env,
|
|
520
|
+
mergedConfig,
|
|
521
|
+
finalConfig
|
|
558
522
|
);
|
|
559
|
-
finalConfig.vite.plugins.push(devServerGlobals(finalConfig));
|
|
560
|
-
finalConfig.vite.plugins.push(tsconfigPaths(finalConfig));
|
|
561
|
-
finalConfig.vite.plugins.push(noopBackground());
|
|
562
|
-
finalConfig.vite.define ??= {};
|
|
563
|
-
getGlobals(finalConfig).forEach((global) => {
|
|
564
|
-
finalConfig.vite.define[global.name] = JSON.stringify(global.value);
|
|
565
|
-
});
|
|
566
523
|
return finalConfig;
|
|
567
524
|
}
|
|
568
525
|
async function resolveManifestConfig(env, manifest) {
|
|
569
526
|
return await (typeof manifest === "function" ? manifest(env) : manifest ?? {});
|
|
570
527
|
}
|
|
528
|
+
function mergeInlineConfig(inlineConfig, userConfig) {
|
|
529
|
+
let imports;
|
|
530
|
+
if (inlineConfig.imports === false || userConfig.imports === false) {
|
|
531
|
+
imports = false;
|
|
532
|
+
} else if (userConfig.imports == null && inlineConfig.imports == null) {
|
|
533
|
+
imports = void 0;
|
|
534
|
+
} else {
|
|
535
|
+
imports = vite2.mergeConfig(
|
|
536
|
+
userConfig.imports ?? {},
|
|
537
|
+
inlineConfig.imports ?? {}
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
const manifest = async (env) => {
|
|
541
|
+
const user = await resolveManifestConfig(env, userConfig.manifest);
|
|
542
|
+
const inline = await resolveManifestConfig(env, inlineConfig.manifest);
|
|
543
|
+
return vite2.mergeConfig(user, inline);
|
|
544
|
+
};
|
|
545
|
+
const viteConfig = async (env) => {
|
|
546
|
+
const user = await resolveViteConfig(env, userConfig.vite);
|
|
547
|
+
const inline = await resolveViteConfig(env, inlineConfig.vite);
|
|
548
|
+
return vite2.mergeConfig(user, inline);
|
|
549
|
+
};
|
|
550
|
+
const runner = vite2.mergeConfig(
|
|
551
|
+
userConfig.runner ?? {},
|
|
552
|
+
inlineConfig.runner ?? {}
|
|
553
|
+
);
|
|
554
|
+
const zip = vite2.mergeConfig(
|
|
555
|
+
userConfig.zip ?? {},
|
|
556
|
+
inlineConfig.zip ?? {}
|
|
557
|
+
);
|
|
558
|
+
return {
|
|
559
|
+
root: inlineConfig.root ?? userConfig.root,
|
|
560
|
+
browser: inlineConfig.browser ?? userConfig.browser,
|
|
561
|
+
manifestVersion: inlineConfig.manifestVersion ?? userConfig.manifestVersion,
|
|
562
|
+
configFile: inlineConfig.configFile,
|
|
563
|
+
debug: inlineConfig.debug ?? userConfig.debug,
|
|
564
|
+
entrypointsDir: inlineConfig.entrypointsDir ?? userConfig.entrypointsDir,
|
|
565
|
+
imports,
|
|
566
|
+
logger: inlineConfig.logger ?? userConfig.logger,
|
|
567
|
+
manifest,
|
|
568
|
+
mode: inlineConfig.mode ?? userConfig.mode,
|
|
569
|
+
publicDir: inlineConfig.publicDir ?? userConfig.publicDir,
|
|
570
|
+
runner,
|
|
571
|
+
srcDir: inlineConfig.srcDir ?? userConfig.srcDir,
|
|
572
|
+
vite: viteConfig,
|
|
573
|
+
zip
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
async function resolveViteConfig(env, vite6) {
|
|
577
|
+
return await (typeof vite6 === "function" ? vite6(env) : vite6 ?? {});
|
|
578
|
+
}
|
|
579
|
+
function resolveInternalZipConfig(root, mergedConfig) {
|
|
580
|
+
return {
|
|
581
|
+
sourcesTemplate: "{{name}}-{{version}}-sources.zip",
|
|
582
|
+
artifactTemplate: "{{name}}-{{version}}-{{browser}}.zip",
|
|
583
|
+
sourcesRoot: root,
|
|
584
|
+
...mergedConfig.zip,
|
|
585
|
+
ignoredSources: [
|
|
586
|
+
"**/node_modules",
|
|
587
|
+
// WXT files
|
|
588
|
+
"**/web-ext.config.ts",
|
|
589
|
+
// Hidden files
|
|
590
|
+
"**/.*",
|
|
591
|
+
// Tests
|
|
592
|
+
"**/__tests__/**",
|
|
593
|
+
"**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
|
|
594
|
+
// From user
|
|
595
|
+
...mergedConfig.zip?.ignoredSources ?? []
|
|
596
|
+
]
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
async function resolveInternalViteConfig(env, mergedConfig, finalConfig) {
|
|
600
|
+
const internalVite = await resolveViteConfig(
|
|
601
|
+
env,
|
|
602
|
+
mergedConfig.vite
|
|
603
|
+
);
|
|
604
|
+
internalVite.root = finalConfig.root;
|
|
605
|
+
internalVite.configFile = false;
|
|
606
|
+
internalVite.logLevel = "warn";
|
|
607
|
+
internalVite.build ??= {};
|
|
608
|
+
internalVite.build.outDir = finalConfig.outDir;
|
|
609
|
+
internalVite.build.emptyOutDir = false;
|
|
610
|
+
internalVite.plugins ??= [];
|
|
611
|
+
internalVite.plugins.push(download(finalConfig));
|
|
612
|
+
internalVite.plugins.push(devHtmlPrerender(finalConfig));
|
|
613
|
+
internalVite.plugins.push(unimport(finalConfig));
|
|
614
|
+
internalVite.plugins.push(
|
|
615
|
+
virtualEntrypoin("background", finalConfig)
|
|
616
|
+
);
|
|
617
|
+
internalVite.plugins.push(
|
|
618
|
+
virtualEntrypoin("content-script", finalConfig)
|
|
619
|
+
);
|
|
620
|
+
internalVite.plugins.push(devServerGlobals(finalConfig));
|
|
621
|
+
internalVite.plugins.push(tsconfigPaths(finalConfig));
|
|
622
|
+
internalVite.plugins.push(noopBackground());
|
|
623
|
+
internalVite.define ??= {};
|
|
624
|
+
for (const global of getGlobals(finalConfig)) {
|
|
625
|
+
internalVite.define[global.name] = JSON.stringify(global.value);
|
|
626
|
+
}
|
|
627
|
+
return internalVite;
|
|
628
|
+
}
|
|
571
629
|
|
|
572
630
|
// src/index.ts
|
|
573
631
|
import pc4 from "picocolors";
|
|
574
|
-
import * as vite6 from "vite";
|
|
575
632
|
|
|
576
633
|
// src/core/utils/arrays.ts
|
|
577
634
|
function every(array, predicate) {
|
|
@@ -693,7 +750,7 @@ async function removeEmptyDirs(dir) {
|
|
|
693
750
|
|
|
694
751
|
// src/core/build/buildEntrypoints.ts
|
|
695
752
|
import fs7 from "fs-extra";
|
|
696
|
-
import { dirname as dirname4, resolve as
|
|
753
|
+
import { dirname as dirname4, resolve as resolve6 } from "path";
|
|
697
754
|
|
|
698
755
|
// src/core/utils/public.ts
|
|
699
756
|
import fs6 from "fs-extra";
|
|
@@ -802,8 +859,8 @@ async function copyPublicDirectory(config) {
|
|
|
802
859
|
return [];
|
|
803
860
|
const publicAssets = [];
|
|
804
861
|
for (const file of files) {
|
|
805
|
-
const srcPath =
|
|
806
|
-
const outPath =
|
|
862
|
+
const srcPath = resolve6(config.publicDir, file);
|
|
863
|
+
const outPath = resolve6(config.outDir, file);
|
|
807
864
|
await fs7.ensureDir(dirname4(outPath));
|
|
808
865
|
await fs7.copyFile(srcPath, outPath);
|
|
809
866
|
publicAssets.push({
|
|
@@ -818,7 +875,7 @@ async function copyPublicDirectory(config) {
|
|
|
818
875
|
}
|
|
819
876
|
|
|
820
877
|
// src/core/build/findEntrypoints.ts
|
|
821
|
-
import { relative as relative3, resolve as
|
|
878
|
+
import { relative as relative3, resolve as resolve8 } from "path";
|
|
822
879
|
import fs9 from "fs-extra";
|
|
823
880
|
import { minimatch } from "minimatch";
|
|
824
881
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -828,7 +885,7 @@ import JSON5 from "json5";
|
|
|
828
885
|
import createJITI from "jiti";
|
|
829
886
|
import { createUnimport as createUnimport2 } from "unimport";
|
|
830
887
|
import fs8 from "fs-extra";
|
|
831
|
-
import { resolve as
|
|
888
|
+
import { resolve as resolve7 } from "path";
|
|
832
889
|
import transform from "jiti/dist/babel";
|
|
833
890
|
|
|
834
891
|
// src/core/utils/strings.ts
|
|
@@ -866,7 +923,7 @@ async function importEntrypointFile(path7, config) {
|
|
|
866
923
|
esmResolve: true,
|
|
867
924
|
interopDefault: true,
|
|
868
925
|
alias: {
|
|
869
|
-
"webextension-polyfill":
|
|
926
|
+
"webextension-polyfill": resolve7(
|
|
870
927
|
config.root,
|
|
871
928
|
"node_modules/wxt/dist/virtual-modules/fake-browser.js"
|
|
872
929
|
)
|
|
@@ -899,7 +956,7 @@ async function findEntrypoints(config) {
|
|
|
899
956
|
let hasBackground = false;
|
|
900
957
|
await Promise.all(
|
|
901
958
|
relativePaths.map(async (relativePath) => {
|
|
902
|
-
const path7 =
|
|
959
|
+
const path7 = resolve8(config.entrypointsDir, relativePath);
|
|
903
960
|
const matchingGlob = pathGlobs.find(
|
|
904
961
|
(glob4) => minimatch(relativePath, glob4)
|
|
905
962
|
);
|
|
@@ -943,7 +1000,7 @@ ${JSON.stringify(
|
|
|
943
1000
|
type,
|
|
944
1001
|
name: getEntrypointName(config.entrypointsDir, path7),
|
|
945
1002
|
inputPath: path7,
|
|
946
|
-
outputDir:
|
|
1003
|
+
outputDir: resolve8(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
947
1004
|
options: {
|
|
948
1005
|
include: void 0,
|
|
949
1006
|
exclude: void 0
|
|
@@ -1104,7 +1161,7 @@ async function getContentScriptEntrypoint(config, name, path7) {
|
|
|
1104
1161
|
type: "content-script",
|
|
1105
1162
|
name: getEntrypointName(config.entrypointsDir, path7),
|
|
1106
1163
|
inputPath: path7,
|
|
1107
|
-
outputDir:
|
|
1164
|
+
outputDir: resolve8(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
1108
1165
|
options
|
|
1109
1166
|
};
|
|
1110
1167
|
}
|
|
@@ -1153,7 +1210,7 @@ var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
|
|
|
1153
1210
|
// src/core/build/generateTypesDir.ts
|
|
1154
1211
|
import { createUnimport as createUnimport3 } from "unimport";
|
|
1155
1212
|
import fs10 from "fs-extra";
|
|
1156
|
-
import { relative as relative4, resolve as
|
|
1213
|
+
import { relative as relative4, resolve as resolve9 } from "path";
|
|
1157
1214
|
import path4 from "node:path";
|
|
1158
1215
|
|
|
1159
1216
|
// src/core/utils/i18n.ts
|
|
@@ -1208,7 +1265,7 @@ async function generateTypesDir(entrypoints, config) {
|
|
|
1208
1265
|
await writeTsConfigFile(mainReference, config);
|
|
1209
1266
|
}
|
|
1210
1267
|
async function writeImportsDeclarationFile(config, unimportOptions) {
|
|
1211
|
-
const filePath =
|
|
1268
|
+
const filePath = resolve9(config.typesDir, "imports.d.ts");
|
|
1212
1269
|
const unimport2 = createUnimport3(unimportOptions);
|
|
1213
1270
|
await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
|
|
1214
1271
|
await writeFileIfDifferent(
|
|
@@ -1220,7 +1277,7 @@ async function writeImportsDeclarationFile(config, unimportOptions) {
|
|
|
1220
1277
|
return filePath;
|
|
1221
1278
|
}
|
|
1222
1279
|
async function writePathsDeclarationFile(entrypoints, config) {
|
|
1223
|
-
const filePath =
|
|
1280
|
+
const filePath = resolve9(config.typesDir, "paths.d.ts");
|
|
1224
1281
|
const unions = entrypoints.map(
|
|
1225
1282
|
(entry) => getEntrypointBundlePath(
|
|
1226
1283
|
entry,
|
|
@@ -1246,7 +1303,7 @@ declare module "wxt/browser" {
|
|
|
1246
1303
|
return filePath;
|
|
1247
1304
|
}
|
|
1248
1305
|
async function writeI18nDeclarationFile(config) {
|
|
1249
|
-
const filePath =
|
|
1306
|
+
const filePath = resolve9(config.typesDir, "i18n.d.ts");
|
|
1250
1307
|
const defaultLocale = config.manifest.default_locale;
|
|
1251
1308
|
const template = `// Generated by wxt
|
|
1252
1309
|
import "wxt/browser";
|
|
@@ -1299,7 +1356,7 @@ declare module "wxt/browser" {
|
|
|
1299
1356
|
return filePath;
|
|
1300
1357
|
}
|
|
1301
1358
|
async function writeGlobalsDeclarationFile(config) {
|
|
1302
|
-
const filePath =
|
|
1359
|
+
const filePath = resolve9(config.typesDir, "globals.d.ts");
|
|
1303
1360
|
const globals = getGlobals(config);
|
|
1304
1361
|
await writeFileIfDifferent(
|
|
1305
1362
|
filePath,
|
|
@@ -1315,7 +1372,7 @@ async function writeGlobalsDeclarationFile(config) {
|
|
|
1315
1372
|
}
|
|
1316
1373
|
async function writeMainDeclarationFile(references, config) {
|
|
1317
1374
|
const dir = config.wxtDir;
|
|
1318
|
-
const filePath =
|
|
1375
|
+
const filePath = resolve9(dir, "wxt.d.ts");
|
|
1319
1376
|
await writeFileIfDifferent(
|
|
1320
1377
|
filePath,
|
|
1321
1378
|
[
|
|
@@ -1333,7 +1390,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1333
1390
|
const rootPath = normalizePath2(relative4(dir, config.root));
|
|
1334
1391
|
const srcPath = normalizePath2(relative4(dir, config.srcDir));
|
|
1335
1392
|
await writeFileIfDifferent(
|
|
1336
|
-
|
|
1393
|
+
resolve9(dir, "tsconfig.json"),
|
|
1337
1394
|
`{
|
|
1338
1395
|
"compilerOptions": {
|
|
1339
1396
|
"target": "ESNext",
|
|
@@ -1368,7 +1425,7 @@ async function writeTsConfigFile(mainReference, config) {
|
|
|
1368
1425
|
|
|
1369
1426
|
// src/core/utils/manifest.ts
|
|
1370
1427
|
import fs12 from "fs-extra";
|
|
1371
|
-
import { resolve as
|
|
1428
|
+
import { resolve as resolve11 } from "path";
|
|
1372
1429
|
|
|
1373
1430
|
// src/core/utils/ContentSecurityPolicy.ts
|
|
1374
1431
|
var ContentSecurityPolicy = class _ContentSecurityPolicy {
|
|
@@ -1452,10 +1509,10 @@ function mapWxtOptionsToContentScript(options) {
|
|
|
1452
1509
|
}
|
|
1453
1510
|
|
|
1454
1511
|
// src/core/utils/package.ts
|
|
1455
|
-
import { resolve as
|
|
1512
|
+
import { resolve as resolve10 } from "node:path";
|
|
1456
1513
|
import fs11 from "fs-extra";
|
|
1457
1514
|
async function getPackageJson(config) {
|
|
1458
|
-
const file =
|
|
1515
|
+
const file = resolve10(config.root, "package.json");
|
|
1459
1516
|
try {
|
|
1460
1517
|
return await fs11.readJson(file);
|
|
1461
1518
|
} catch (err) {
|
|
@@ -1470,7 +1527,7 @@ async function getPackageJson(config) {
|
|
|
1470
1527
|
async function writeManifest(manifest, output, config) {
|
|
1471
1528
|
const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
|
|
1472
1529
|
await fs12.ensureDir(config.outDir);
|
|
1473
|
-
await writeFileIfDifferent(
|
|
1530
|
+
await writeFileIfDifferent(resolve11(config.outDir, "manifest.json"), str);
|
|
1474
1531
|
output.publicAssets.unshift({
|
|
1475
1532
|
type: "asset",
|
|
1476
1533
|
fileName: "manifest.json",
|
|
@@ -1840,7 +1897,7 @@ function formatDuration(duration) {
|
|
|
1840
1897
|
}
|
|
1841
1898
|
|
|
1842
1899
|
// src/core/log/printBuildSummary.ts
|
|
1843
|
-
import { resolve as
|
|
1900
|
+
import { resolve as resolve12 } from "path";
|
|
1844
1901
|
|
|
1845
1902
|
// src/core/log/printFileList.ts
|
|
1846
1903
|
import path5 from "node:path";
|
|
@@ -1923,7 +1980,7 @@ async function printBuildSummary(log, header, output, config) {
|
|
|
1923
1980
|
return diff;
|
|
1924
1981
|
return l.fileName.localeCompare(r.fileName);
|
|
1925
1982
|
});
|
|
1926
|
-
const files = chunks.map((chunk) =>
|
|
1983
|
+
const files = chunks.map((chunk) => resolve12(config.outDir, chunk.fileName));
|
|
1927
1984
|
await printFileList(log, header, config.outDir, files);
|
|
1928
1985
|
}
|
|
1929
1986
|
var DEFAULT_SORT_WEIGHT = 100;
|
|
@@ -2184,7 +2241,7 @@ async function clean(root = process.cwd()) {
|
|
|
2184
2241
|
}
|
|
2185
2242
|
|
|
2186
2243
|
// package.json
|
|
2187
|
-
var version2 = "0.5.
|
|
2244
|
+
var version2 = "0.5.3";
|
|
2188
2245
|
|
|
2189
2246
|
// src/core/utils/defineConfig.ts
|
|
2190
2247
|
function defineConfig(config) {
|
|
@@ -2203,12 +2260,14 @@ async function build2(config) {
|
|
|
2203
2260
|
}
|
|
2204
2261
|
async function createServer2(config) {
|
|
2205
2262
|
const serverInfo = await getServerInfo();
|
|
2206
|
-
const getLatestInternalConfig = () => {
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2263
|
+
const getLatestInternalConfig = async () => {
|
|
2264
|
+
return getInternalConfig(
|
|
2265
|
+
{
|
|
2266
|
+
...config,
|
|
2267
|
+
vite: serverInfo.viteServerConfig
|
|
2268
|
+
},
|
|
2269
|
+
"serve"
|
|
2210
2270
|
);
|
|
2211
|
-
return getInternalConfig({ ...config, vite: viteConfig }, "serve");
|
|
2212
2271
|
};
|
|
2213
2272
|
let internalConfig = await getLatestInternalConfig();
|
|
2214
2273
|
const server = await setupServer(serverInfo, internalConfig);
|