wxt 0.1.1 → 0.1.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/index.cjs CHANGED
@@ -277,6 +277,15 @@ function getUnimportOptions(config) {
277
277
  }
278
278
 
279
279
  // src/core/vite-plugins/unimport.ts
280
+ var import_path2 = require("path");
281
+ var ENABLED_EXTENSIONS = {
282
+ ".js": true,
283
+ ".jsx": true,
284
+ ".ts": true,
285
+ ".tsx": true,
286
+ ".vue": true,
287
+ ".svelte": true
288
+ };
280
289
  function unimport(config) {
281
290
  const options = getUnimportOptions(config);
282
291
  const unimport2 = (0, import_unimport.createUnimport)(options);
@@ -286,14 +295,16 @@ function unimport(config) {
286
295
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
287
296
  },
288
297
  async transform(code, id) {
289
- return unimport2.injectImports(code, id);
298
+ const ext = (0, import_path2.extname)(id);
299
+ if (ENABLED_EXTENSIONS[ext])
300
+ return unimport2.injectImports(code, id);
290
301
  }
291
302
  };
292
303
  }
293
304
 
294
305
  // src/core/vite-plugins/virtualEntrypoint.ts
295
306
  var import_fs_extra2 = __toESM(require("fs-extra"), 1);
296
- var import_path2 = require("path");
307
+ var import_path3 = require("path");
297
308
  function virtualEntrypoin(type, config) {
298
309
  const virtualId = `virtual:wxt-${type}?`;
299
310
  const resolvedVirtualId = `\0${virtualId}`;
@@ -311,7 +322,7 @@ function virtualEntrypoin(type, config) {
311
322
  return;
312
323
  const inputPath = id.replace(resolvedVirtualId, "");
313
324
  const template = await import_fs_extra2.default.readFile(
314
- (0, import_path2.resolve)(
325
+ (0, import_path3.resolve)(
315
326
  config.root,
316
327
  `node_modules/wxt/dist/virtual-modules/${type}-entrypoint.js`
317
328
  ),
@@ -324,13 +335,13 @@ function virtualEntrypoin(type, config) {
324
335
 
325
336
  // src/core/utils/createFsCache.ts
326
337
  var import_fs_extra3 = __toESM(require("fs-extra"), 1);
327
- var import_path3 = require("path");
338
+ var import_path4 = require("path");
328
339
  function createFsCache(wxtDir) {
329
- const getPath = (key) => (0, import_path3.resolve)(wxtDir, "cache", encodeURIComponent(key));
340
+ const getPath = (key) => (0, import_path4.resolve)(wxtDir, "cache", encodeURIComponent(key));
330
341
  return {
331
342
  async set(key, value) {
332
343
  const path5 = getPath(key);
333
- await (0, import_fs_extra3.ensureDir)((0, import_path3.dirname)(path5));
344
+ await (0, import_fs_extra3.ensureDir)((0, import_path4.dirname)(path5));
334
345
  await import_fs_extra3.default.writeFile(path5, value, "utf-8");
335
346
  },
336
347
  async get(key) {
@@ -411,7 +422,6 @@ async function getInternalConfig(config, command) {
411
422
  command,
412
423
  logger,
413
424
  vite: config.vite ?? {},
414
- manifest: config.manifest ?? {},
415
425
  imports: config.imports ?? {},
416
426
  runnerConfig: await (0, import_c12.loadConfig)({
417
427
  name: "web-ext",
@@ -444,6 +454,10 @@ async function getInternalConfig(config, command) {
444
454
  const publicDir = (0, import_node_path3.resolve)(srcDir, userConfig.publicDir ?? "public");
445
455
  const wxtDir = (0, import_node_path3.resolve)(srcDir, ".wxt");
446
456
  const typesDir = (0, import_node_path3.resolve)(wxtDir, "types");
457
+ const env = { mode, browser, manifestVersion, command };
458
+ const userManifest = await resolveManifestConfig(env, userConfig.manifest);
459
+ const inlineManifest = await resolveManifestConfig(env, config.manifest);
460
+ const manifest = vite2.mergeConfig(userManifest, inlineManifest);
447
461
  const finalConfig = {
448
462
  ...merged,
449
463
  srcDir,
@@ -451,7 +465,8 @@ async function getInternalConfig(config, command) {
451
465
  publicDir,
452
466
  wxtDir,
453
467
  typesDir,
454
- fsCache: createFsCache(wxtDir)
468
+ fsCache: createFsCache(wxtDir),
469
+ manifest
455
470
  };
456
471
  finalConfig.vite.root = root;
457
472
  finalConfig.vite.configFile = false;
@@ -476,6 +491,9 @@ async function getInternalConfig(config, command) {
476
491
  });
477
492
  return finalConfig;
478
493
  }
494
+ async function resolveManifestConfig(env, manifest) {
495
+ return await (typeof manifest === "function" ? manifest(env) : manifest ?? {});
496
+ }
479
497
 
480
498
  // src/index.ts
481
499
  var import_picocolors3 = __toESM(require("picocolors"), 1);
@@ -582,11 +600,11 @@ var vite3 = __toESM(require("vite"), 1);
582
600
 
583
601
  // src/core/utils/removeEmptyDirs.ts
584
602
  var import_fs_extra4 = __toESM(require("fs-extra"), 1);
585
- var import_path4 = __toESM(require("path"), 1);
603
+ var import_path5 = __toESM(require("path"), 1);
586
604
  async function removeEmptyDirs(dir) {
587
605
  const files = await import_fs_extra4.default.readdir(dir);
588
606
  for (const file of files) {
589
- const filePath = import_path4.default.join(dir, file);
607
+ const filePath = import_path5.default.join(dir, file);
590
608
  const stats = await import_fs_extra4.default.stat(filePath);
591
609
  if (stats.isDirectory()) {
592
610
  await removeEmptyDirs(filePath);
@@ -601,7 +619,7 @@ async function removeEmptyDirs(dir) {
601
619
  // src/core/build/buildEntrypoints.ts
602
620
  var import_fast_glob = __toESM(require("fast-glob"), 1);
603
621
  var import_fs_extra5 = __toESM(require("fs-extra"), 1);
604
- var import_path5 = require("path");
622
+ var import_path6 = require("path");
605
623
  async function buildEntrypoints(groups, config) {
606
624
  const steps = [];
607
625
  for (const group of groups) {
@@ -693,9 +711,9 @@ async function copyPublicDirectory(config) {
693
711
  return publicAssets;
694
712
  const files = await (0, import_fast_glob.default)("**/*", { cwd: config.publicDir });
695
713
  for (const file of files) {
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));
714
+ const srcPath = (0, import_path6.resolve)(config.publicDir, file);
715
+ const outPath = (0, import_path6.resolve)(config.outDir, file);
716
+ await import_fs_extra5.default.ensureDir((0, import_path6.dirname)(outPath));
699
717
  await import_fs_extra5.default.copyFile(srcPath, outPath);
700
718
  publicAssets.push({
701
719
  type: "asset",
@@ -709,7 +727,7 @@ async function copyPublicDirectory(config) {
709
727
  }
710
728
 
711
729
  // src/core/build/findEntrypoints.ts
712
- var import_path7 = require("path");
730
+ var import_path8 = require("path");
713
731
  var import_fs_extra7 = __toESM(require("fs-extra"), 1);
714
732
  var import_picomatch = __toESM(require("picomatch"), 1);
715
733
  var import_linkedom2 = require("linkedom");
@@ -719,7 +737,7 @@ var import_json5 = __toESM(require("json5"), 1);
719
737
  var import_jiti = __toESM(require("jiti"), 1);
720
738
  var import_unimport2 = require("unimport");
721
739
  var import_fs_extra6 = __toESM(require("fs-extra"), 1);
722
- var import_path6 = require("path");
740
+ var import_path7 = require("path");
723
741
  var import_babel = __toESM(require("jiti/dist/babel"), 1);
724
742
  async function importTsFile(path5, config) {
725
743
  config.logger.debug("Loading file metadata:", path5);
@@ -741,7 +759,7 @@ async function importTsFile(path5, config) {
741
759
  esmResolve: true,
742
760
  interopDefault: true,
743
761
  alias: {
744
- "webextension-polyfill": (0, import_path6.resolve)(
762
+ "webextension-polyfill": (0, import_path7.resolve)(
745
763
  config.root,
746
764
  "node_modules/wxt/dist/virtual-modules/fake-browser.js"
747
765
  )
@@ -773,7 +791,7 @@ async function findEntrypoints(config) {
773
791
  const entrypoints = [];
774
792
  await Promise.all(
775
793
  relativePaths.map(async (relativePath) => {
776
- const path5 = (0, import_path7.resolve)(config.entrypointsDir, relativePath);
794
+ const path5 = (0, import_path8.resolve)(config.entrypointsDir, relativePath);
777
795
  const matchingGlob = pathGlobs.find(
778
796
  (glob3) => import_picomatch.default.isMatch(relativePath, glob3)
779
797
  );
@@ -820,8 +838,8 @@ ${JSON.stringify(
820
838
  if (withSameName) {
821
839
  throw Error(
822
840
  `Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
823
- (0, import_path7.relative)(config.root, withSameName.inputPath),
824
- (0, import_path7.relative)(config.root, entrypoint.inputPath)
841
+ (0, import_path8.relative)(config.root, withSameName.inputPath),
842
+ (0, import_path8.relative)(config.root, entrypoint.inputPath)
825
843
  ].join(", ")}`
826
844
  );
827
845
  }
@@ -910,7 +928,7 @@ async function getContentScriptEntrypoint(config, name, path5) {
910
928
  type: "content-script",
911
929
  name: getEntrypointName(config.entrypointsDir, path5),
912
930
  inputPath: path5,
913
- outputDir: (0, import_path7.resolve)(config.outDir, "content-scripts"),
931
+ outputDir: (0, import_path8.resolve)(config.outDir, "content-scripts"),
914
932
  options
915
933
  };
916
934
  }
@@ -948,7 +966,7 @@ var PATH_GLOB_TO_TYPE_MAP = {
948
966
  // src/core/build/generateTypesDir.ts
949
967
  var import_unimport3 = require("unimport");
950
968
  var import_fs_extra8 = __toESM(require("fs-extra"), 1);
951
- var import_path8 = require("path");
969
+ var import_path9 = require("path");
952
970
  async function generateTypesDir(entrypoints, config) {
953
971
  await import_fs_extra8.default.ensureDir(config.typesDir);
954
972
  const references = [];
@@ -959,7 +977,7 @@ async function generateTypesDir(entrypoints, config) {
959
977
  await writeTsConfigFile(mainReference, config);
960
978
  }
961
979
  async function writeImportsDeclarationFile(config) {
962
- const filePath = (0, import_path8.resolve)(config.typesDir, "imports.d.ts");
980
+ const filePath = (0, import_path9.resolve)(config.typesDir, "imports.d.ts");
963
981
  const unimport2 = (0, import_unimport3.createUnimport)(getUnimportOptions(config));
964
982
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
965
983
  await import_fs_extra8.default.writeFile(
@@ -971,26 +989,27 @@ async function writeImportsDeclarationFile(config) {
971
989
  return filePath;
972
990
  }
973
991
  async function writePathsDeclarationFile(entrypoints, config) {
974
- const filePath = (0, import_path8.resolve)(config.typesDir, "paths.d.ts");
992
+ const filePath = (0, import_path9.resolve)(config.typesDir, "paths.d.ts");
993
+ const unions = entrypoints.map((entry) => {
994
+ const path5 = getEntrypointBundlePath(
995
+ entry,
996
+ config.outDir,
997
+ entry.inputPath.endsWith(".html") ? ".html" : ".js"
998
+ );
999
+ return ` | "/${path5}"`;
1000
+ }).sort();
975
1001
  await import_fs_extra8.default.writeFile(
976
1002
  filePath,
977
1003
  [
978
1004
  "// Generated by wxt",
979
1005
  "type EntrypointPath =",
980
- ...entrypoints.map((entry) => {
981
- const path5 = getEntrypointBundlePath(
982
- entry,
983
- config.outDir,
984
- entry.inputPath.endsWith(".html") ? ".html" : ".js"
985
- );
986
- return ` | "/${path5}"`;
987
- }).sort()
1006
+ ...unions.length === 0 ? [" never"] : unions
988
1007
  ].join("\n") + "\n"
989
1008
  );
990
1009
  return filePath;
991
1010
  }
992
1011
  async function writeGlobalsDeclarationFile(config) {
993
- const filePath = (0, import_path8.resolve)(config.typesDir, "globals.d.ts");
1012
+ const filePath = (0, import_path9.resolve)(config.typesDir, "globals.d.ts");
994
1013
  const globals = getGlobals(config);
995
1014
  await import_fs_extra8.default.writeFile(
996
1015
  filePath,
@@ -1007,13 +1026,13 @@ async function writeGlobalsDeclarationFile(config) {
1007
1026
  }
1008
1027
  async function writeMainDeclarationFile(references, config) {
1009
1028
  const dir = config.wxtDir;
1010
- const filePath = (0, import_path8.resolve)(dir, "wxt.d.ts");
1029
+ const filePath = (0, import_path9.resolve)(dir, "wxt.d.ts");
1011
1030
  await import_fs_extra8.default.writeFile(
1012
1031
  filePath,
1013
1032
  [
1014
1033
  "// Generated by wxt",
1015
1034
  ...references.map(
1016
- (ref) => `/// <reference types="./${(0, import_path8.relative)(dir, ref)}" />`
1035
+ (ref) => `/// <reference types="./${(0, import_path9.relative)(dir, ref)}" />`
1017
1036
  )
1018
1037
  ].join("\n") + "\n"
1019
1038
  );
@@ -1022,7 +1041,7 @@ async function writeMainDeclarationFile(references, config) {
1022
1041
  async function writeTsConfigFile(mainReference, config) {
1023
1042
  const dir = config.wxtDir;
1024
1043
  await import_fs_extra8.default.writeFile(
1025
- (0, import_path8.resolve)(dir, "tsconfig.json"),
1044
+ (0, import_path9.resolve)(dir, "tsconfig.json"),
1026
1045
  `{
1027
1046
  "compilerOptions": {
1028
1047
  "target": "ESNext",
@@ -1037,20 +1056,33 @@ async function writeTsConfigFile(mainReference, config) {
1037
1056
  "strict": true,
1038
1057
 
1039
1058
  /* Completeness */
1040
- "skipLibCheck": true
1059
+ "skipLibCheck": true,
1060
+
1061
+ /* Aliases */
1062
+ "baseUrl": "${(0, import_path9.relative)(dir, config.root)}",
1063
+ "paths": {
1064
+ "@@": ["."],
1065
+ "@@/*": ["./*"],
1066
+ "~~": ["."],
1067
+ "~~/*": ["./*"],
1068
+ "@": ["${(0, import_path9.relative)(config.root, config.srcDir)}"],
1069
+ "@/*": ["${(0, import_path9.relative)(config.root, config.srcDir)}/*"],
1070
+ "~": ["${(0, import_path9.relative)(config.root, config.srcDir)}"],
1071
+ "~/*": ["${(0, import_path9.relative)(config.root, config.srcDir)}/*"]
1072
+ }
1041
1073
  },
1042
1074
  "include": [
1043
- "${(0, import_path8.relative)(dir, config.root)}/**/*",
1044
- "./${(0, import_path8.relative)(dir, mainReference)}"
1075
+ "${(0, import_path9.relative)(dir, config.root)}/**/*",
1076
+ "./${(0, import_path9.relative)(dir, mainReference)}"
1045
1077
  ],
1046
- "exclude": ["${(0, import_path8.relative)(dir, config.outBaseDir)}"]
1078
+ "exclude": ["${(0, import_path9.relative)(dir, config.outBaseDir)}"]
1047
1079
  }`
1048
1080
  );
1049
1081
  }
1050
1082
 
1051
1083
  // src/core/utils/manifest.ts
1052
1084
  var import_fs_extra9 = __toESM(require("fs-extra"), 1);
1053
- var import_path9 = require("path");
1085
+ var import_path10 = require("path");
1054
1086
 
1055
1087
  // src/core/utils/ContentSecurityPolicy.ts
1056
1088
  var ContentSecurityPolicy = class _ContentSecurityPolicy {
@@ -1099,7 +1131,7 @@ var ContentSecurityPolicy = class _ContentSecurityPolicy {
1099
1131
  async function writeManifest(manifest, output, config) {
1100
1132
  const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
1101
1133
  await import_fs_extra9.default.ensureDir(config.outDir);
1102
- await import_fs_extra9.default.writeFile((0, import_path9.resolve)(config.outDir, "manifest.json"), str, "utf-8");
1134
+ await import_fs_extra9.default.writeFile((0, import_path10.resolve)(config.outDir, "manifest.json"), str, "utf-8");
1103
1135
  output.publicAssets.unshift({
1104
1136
  type: "asset",
1105
1137
  fileName: "manifest.json",
@@ -1132,7 +1164,7 @@ async function generateMainfest(entrypoints, buildOutput, config) {
1132
1164
  return manifest;
1133
1165
  }
1134
1166
  async function getPackageJson(config) {
1135
- return await import_fs_extra9.default.readJson((0, import_path9.resolve)(config.root, "package.json"));
1167
+ return await import_fs_extra9.default.readJson((0, import_path10.resolve)(config.root, "package.json"));
1136
1168
  }
1137
1169
  function simplifyVersion(versionName) {
1138
1170
  const version3 = /^((0|[1-9][0-9]{0,8})([.](0|[1-9][0-9]{0,8})){0,3}).*$/.exec(
@@ -1425,7 +1457,7 @@ function formatDuration(duration) {
1425
1457
  }
1426
1458
 
1427
1459
  // src/core/log/printBuildSummary.ts
1428
- var import_path10 = __toESM(require("path"), 1);
1460
+ var import_path11 = __toESM(require("path"), 1);
1429
1461
 
1430
1462
  // src/core/log/printTable.ts
1431
1463
  function printTable(log, rows, gap = 2) {
@@ -1462,8 +1494,8 @@ async function printBuildSummary(output, config) {
1462
1494
  ...output.steps.flatMap((step) => step.chunks),
1463
1495
  ...output.publicAssets
1464
1496
  ].sort((l, r) => {
1465
- const lWeight = CHUNK_SORT_WEIGHTS[l.fileName] ?? CHUNK_SORT_WEIGHTS[(0, import_path10.extname)(l.fileName)] ?? DEFAULT_SORT_WEIGHT;
1466
- const rWeight = CHUNK_SORT_WEIGHTS[r.fileName] ?? CHUNK_SORT_WEIGHTS[(0, import_path10.extname)(r.fileName)] ?? DEFAULT_SORT_WEIGHT;
1497
+ const lWeight = getChunkSortWeight(l.fileName);
1498
+ const rWeight = getChunkSortWeight(r.fileName);
1467
1499
  const diff = lWeight - rWeight;
1468
1500
  if (diff !== 0)
1469
1501
  return diff;
@@ -1473,13 +1505,12 @@ async function printBuildSummary(output, config) {
1473
1505
  const chunkRows = await Promise.all(
1474
1506
  chunks.map(async (chunk, i) => {
1475
1507
  const file = [
1476
- (0, import_path10.relative)(process.cwd(), config.outDir) + import_path10.default.sep,
1508
+ (0, import_path11.relative)(process.cwd(), config.outDir) + import_path11.default.sep,
1477
1509
  chunk.fileName
1478
1510
  ];
1479
- const ext = (0, import_path10.extname)(chunk.fileName);
1480
1511
  const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
1481
- const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
1482
- const stats = await import_fs_extra10.default.lstat((0, import_path10.resolve)(config.outDir, chunk.fileName));
1512
+ const color = getChunkColor(chunk.fileName);
1513
+ const stats = await import_fs_extra10.default.lstat((0, import_path11.resolve)(config.outDir, chunk.fileName));
1483
1514
  totalSize += stats.size;
1484
1515
  const size = String((0, import_filesize.filesize)(stats.size));
1485
1516
  return [
@@ -1497,15 +1528,29 @@ var DEFAULT_SORT_WEIGHT = 100;
1497
1528
  var CHUNK_SORT_WEIGHTS = {
1498
1529
  "manifest.json": 0,
1499
1530
  ".html": 1,
1531
+ ".js.map": 2,
1500
1532
  ".js": 2,
1501
1533
  ".css": 3
1502
1534
  };
1535
+ function getChunkSortWeight(filename) {
1536
+ return Object.entries(CHUNK_SORT_WEIGHTS).find(([key, value]) => {
1537
+ if (filename.endsWith(key))
1538
+ return value;
1539
+ })?.[1] ?? DEFAULT_SORT_WEIGHT;
1540
+ }
1503
1541
  var DEFAULT_COLOR = import_picocolors.default.blue;
1504
1542
  var CHUNK_COLORS = {
1543
+ ".js.map": import_picocolors.default.gray,
1505
1544
  ".html": import_picocolors.default.green,
1506
1545
  ".css": import_picocolors.default.magenta,
1507
1546
  ".js": import_picocolors.default.cyan
1508
1547
  };
1548
+ function getChunkColor(filename) {
1549
+ return Object.entries(CHUNK_COLORS).find(([key, value]) => {
1550
+ if (filename.endsWith(key))
1551
+ return value;
1552
+ })?.[1] ?? DEFAULT_COLOR;
1553
+ }
1509
1554
 
1510
1555
  // src/core/build.ts
1511
1556
  async function buildInternal(config) {
@@ -1731,7 +1776,7 @@ function reloadHtmlPages(groups, server, config) {
1731
1776
  }
1732
1777
 
1733
1778
  // package.json
1734
- var version2 = "0.1.1";
1779
+ var version2 = "0.1.3";
1735
1780
 
1736
1781
  // src/core/utils/defineConfig.ts
1737
1782
  function defineConfig(config) {