wxt 0.18.8 → 0.18.9

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.
@@ -12,7 +12,7 @@ import {
12
12
  } from "./chunk-QGM4M3NI.js";
13
13
 
14
14
  // package.json
15
- var version = "0.18.7";
15
+ var version = "0.18.8";
16
16
 
17
17
  // src/core/utils/paths.ts
18
18
  import systemPath from "node:path";
@@ -901,114 +901,23 @@ function findEffectedSteps(changedFile, currentOutput) {
901
901
  }
902
902
 
903
903
  // src/core/utils/building/find-entrypoints.ts
904
- import { relative as relative4, resolve as resolve8 } from "path";
905
- import fs6 from "fs-extra";
904
+ import { relative as relative3, resolve as resolve7 } from "path";
905
+ import fs5 from "fs-extra";
906
906
  import { minimatch } from "minimatch";
907
907
  import { parseHTML as parseHTML3 } from "linkedom";
908
908
  import JSON5 from "json5";
909
909
  import glob2 from "fast-glob";
910
910
  import pc2 from "picocolors";
911
-
912
- // src/core/utils/building/import-entrypoint.ts
913
- import createJITI from "jiti";
914
- import { createUnimport as createUnimport2 } from "unimport";
915
- import fs5 from "fs-extra";
916
- import { relative as relative3, resolve as resolve7 } from "node:path";
917
- import { transformSync } from "esbuild";
918
- import { fileURLToPath } from "node:url";
919
- async function importEntrypointFile(path8) {
920
- wxt.logger.debug("Loading file metadata:", path8);
921
- const normalPath = normalizePath(path8);
922
- const unimport2 = createUnimport2({
923
- ...wxt.config.imports,
924
- // Only allow specific imports, not all from the project
925
- dirs: []
926
- });
927
- await unimport2.init();
928
- const text = await fs5.readFile(path8, "utf-8");
929
- const textNoImports = removeProjectImportStatements(text);
930
- const { code } = await unimport2.injectImports(textNoImports);
931
- wxt.logger.debug(
932
- ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
933
- );
934
- const jiti = createJITI(
935
- typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
936
- {
937
- cache: false,
938
- debug: wxt.config.debug,
939
- esmResolve: true,
940
- alias: {
941
- "webextension-polyfill": resolve7(
942
- wxt.config.wxtModuleDir,
943
- "dist/virtual/mock-browser.js"
944
- )
945
- },
946
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
947
- // respect the custom transform function when using it's native bun option.
948
- experimentalBun: false,
949
- // List of extensions to transform with esbuild
950
- extensions: [
951
- ".ts",
952
- ".cts",
953
- ".mts",
954
- ".tsx",
955
- ".js",
956
- ".cjs",
957
- ".mjs",
958
- ".jsx"
959
- ],
960
- transform(opts) {
961
- const isEntrypoint = opts.filename === normalPath;
962
- return transformSync(
963
- // Use modified source code for entrypoints
964
- isEntrypoint ? code : opts.source,
965
- getEsbuildOptions(opts)
966
- );
967
- }
968
- }
969
- );
970
- try {
971
- const res = await jiti(path8);
972
- return res.default;
973
- } catch (err) {
974
- const filePath = relative3(wxt.config.root, path8);
975
- if (err instanceof ReferenceError) {
976
- const variableName = err.message.replace(" is not defined", "");
977
- throw Error(
978
- `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
979
- { cause: err }
980
- );
981
- } else {
982
- wxt.logger.error(err);
983
- throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
984
- }
985
- }
986
- }
987
- function getEsbuildOptions(opts) {
988
- const isJsx = opts.filename?.endsWith("x");
989
- return {
990
- format: "cjs",
991
- loader: isJsx ? "tsx" : "ts",
992
- ...isJsx ? {
993
- // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
994
- // grabbing the entrypoint's options.
995
- jsxFactory: "h",
996
- jsxFragment: "Fragment"
997
- } : void 0
998
- };
999
- }
1000
-
1001
- // src/core/utils/building/find-entrypoints.ts
1002
911
  async function findEntrypoints() {
1003
- await fs6.mkdir(wxt.config.wxtDir, { recursive: true });
1004
- await fs6.writeJson(resolve8(wxt.config.wxtDir, "tsconfig.json"), {});
912
+ await fs5.mkdir(wxt.config.wxtDir, { recursive: true });
913
+ await fs5.writeJson(resolve7(wxt.config.wxtDir, "tsconfig.json"), {});
1005
914
  const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
1006
915
  cwd: wxt.config.entrypointsDir
1007
916
  });
1008
917
  relativePaths.sort();
1009
918
  const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
1010
919
  const entrypointInfos = relativePaths.reduce((results, relativePath) => {
1011
- const inputPath = resolve8(wxt.config.entrypointsDir, relativePath);
920
+ const inputPath = resolve7(wxt.config.entrypointsDir, relativePath);
1012
921
  const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
1013
922
  const matchingGlob = pathGlobs.find(
1014
923
  (glob5) => minimatch(relativePath, glob5)
@@ -1050,7 +959,7 @@ async function findEntrypoints() {
1050
959
  return {
1051
960
  ...info,
1052
961
  type,
1053
- outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
962
+ outputDir: resolve7(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1054
963
  options: {
1055
964
  include: void 0,
1056
965
  exclude: void 0
@@ -1124,7 +1033,7 @@ function preventDuplicateEntrypointNames(files) {
1124
1033
  if (absolutePaths.length > 1) {
1125
1034
  lines.push(`- ${name}`);
1126
1035
  absolutePaths.forEach((absolutePath) => {
1127
- lines.push(` - ${relative4(wxt.config.root, absolutePath)}`);
1036
+ lines.push(` - ${relative3(wxt.config.root, absolutePath)}`);
1128
1037
  });
1129
1038
  }
1130
1039
  return lines;
@@ -1212,7 +1121,7 @@ async function getUnlistedScriptEntrypoint({
1212
1121
  name,
1213
1122
  skipped
1214
1123
  }) {
1215
- const defaultExport = await importEntrypoint(inputPath);
1124
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
1216
1125
  if (defaultExport == null) {
1217
1126
  throw Error(
1218
1127
  `${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
@@ -1235,7 +1144,7 @@ async function getBackgroundEntrypoint({
1235
1144
  }) {
1236
1145
  let options = {};
1237
1146
  if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
1238
- const defaultExport = await importEntrypoint(inputPath);
1147
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
1239
1148
  if (defaultExport == null) {
1240
1149
  throw Error(
1241
1150
  `${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
@@ -1261,7 +1170,13 @@ async function getContentScriptEntrypoint({
1261
1170
  name,
1262
1171
  skipped
1263
1172
  }) {
1264
- const { main: _, ...options } = await importEntrypoint(inputPath);
1173
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
1174
+ if (defaultExport == null) {
1175
+ throw Error(
1176
+ `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
1177
+ );
1178
+ }
1179
+ const { main: _, ...options } = defaultExport;
1265
1180
  if (options == null) {
1266
1181
  throw Error(
1267
1182
  `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
@@ -1271,7 +1186,7 @@ async function getContentScriptEntrypoint({
1271
1186
  type: "content-script",
1272
1187
  name,
1273
1188
  inputPath,
1274
- outputDir: resolve8(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1189
+ outputDir: resolve7(wxt.config.outDir, CONTENT_SCRIPT_OUT_DIR),
1275
1190
  options: resolvePerBrowserOptions(options, wxt.config.browser),
1276
1191
  skipped
1277
1192
  };
@@ -1304,7 +1219,7 @@ async function getSidepanelEntrypoint(info) {
1304
1219
  };
1305
1220
  }
1306
1221
  async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
1307
- const content = await fs6.readFile(info.inputPath, "utf-8");
1222
+ const content = await fs5.readFile(info.inputPath, "utf-8");
1308
1223
  const { document } = parseHTML3(content);
1309
1224
  const options = {};
1310
1225
  const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
@@ -1364,14 +1279,11 @@ var PATH_GLOB_TO_TYPE_MAP = {
1364
1279
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
1365
1280
  };
1366
1281
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1367
- function importEntrypoint(path8) {
1368
- return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path8) : importEntrypointFile(path8);
1369
- }
1370
1282
 
1371
1283
  // src/core/utils/building/generate-wxt-dir.ts
1372
- import { createUnimport as createUnimport3 } from "unimport";
1373
- import fs7 from "fs-extra";
1374
- import { relative as relative5, resolve as resolve9 } from "path";
1284
+ import { createUnimport as createUnimport2 } from "unimport";
1285
+ import fs6 from "fs-extra";
1286
+ import { relative as relative4, resolve as resolve8 } from "path";
1375
1287
  import path4 from "node:path";
1376
1288
 
1377
1289
  // src/core/utils/i18n.ts
@@ -1413,10 +1325,10 @@ function parseI18nMessages(messagesJson) {
1413
1325
 
1414
1326
  // src/core/utils/building/generate-wxt-dir.ts
1415
1327
  async function generateTypesDir(entrypoints) {
1416
- await fs7.ensureDir(wxt.config.typesDir);
1328
+ await fs6.ensureDir(wxt.config.typesDir);
1417
1329
  const references = [];
1418
1330
  if (wxt.config.imports !== false) {
1419
- const unimport2 = createUnimport3(wxt.config.imports);
1331
+ const unimport2 = createUnimport2(wxt.config.imports);
1420
1332
  references.push(await writeImportsDeclarationFile(unimport2));
1421
1333
  if (wxt.config.imports.eslintrc.enabled) {
1422
1334
  await writeImportsEslintFile(unimport2, wxt.config.imports);
@@ -1429,7 +1341,7 @@ async function generateTypesDir(entrypoints) {
1429
1341
  await writeTsConfigFile(mainReference);
1430
1342
  }
1431
1343
  async function writeImportsDeclarationFile(unimport2) {
1432
- const filePath = resolve9(wxt.config.typesDir, "imports.d.ts");
1344
+ const filePath = resolve8(wxt.config.typesDir, "imports.d.ts");
1433
1345
  await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
1434
1346
  await writeFileIfDifferent(
1435
1347
  filePath,
@@ -1445,10 +1357,10 @@ async function writeImportsEslintFile(unimport2, options) {
1445
1357
  (await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
1446
1358
  eslintrc.globals[name] = options.eslintrc.globalsPropValue;
1447
1359
  });
1448
- await fs7.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1360
+ await fs6.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1449
1361
  }
1450
1362
  async function writePathsDeclarationFile(entrypoints) {
1451
- const filePath = resolve9(wxt.config.typesDir, "paths.d.ts");
1363
+ const filePath = resolve8(wxt.config.typesDir, "paths.d.ts");
1452
1364
  const unions = entrypoints.map(
1453
1365
  (entry) => getEntrypointBundlePath(
1454
1366
  entry,
@@ -1476,7 +1388,7 @@ declare module "wxt/browser" {
1476
1388
  return filePath;
1477
1389
  }
1478
1390
  async function writeI18nDeclarationFile() {
1479
- const filePath = resolve9(wxt.config.typesDir, "i18n.d.ts");
1391
+ const filePath = resolve8(wxt.config.typesDir, "i18n.d.ts");
1480
1392
  const defaultLocale = wxt.config.manifest.default_locale;
1481
1393
  const template = `// Generated by wxt
1482
1394
  import "wxt/browser";
@@ -1505,7 +1417,7 @@ declare module "wxt/browser" {
1505
1417
  defaultLocale,
1506
1418
  "messages.json"
1507
1419
  );
1508
- const content = JSON.parse(await fs7.readFile(defaultLocalePath, "utf-8"));
1420
+ const content = JSON.parse(await fs6.readFile(defaultLocalePath, "utf-8"));
1509
1421
  messages = parseI18nMessages(content);
1510
1422
  } else {
1511
1423
  messages = parseI18nMessages({});
@@ -1529,7 +1441,7 @@ declare module "wxt/browser" {
1529
1441
  return filePath;
1530
1442
  }
1531
1443
  async function writeGlobalsDeclarationFile() {
1532
- const filePath = resolve9(wxt.config.typesDir, "globals.d.ts");
1444
+ const filePath = resolve8(wxt.config.typesDir, "globals.d.ts");
1533
1445
  const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
1534
1446
  await writeFileIfDifferent(
1535
1447
  filePath,
@@ -1548,14 +1460,14 @@ async function writeGlobalsDeclarationFile() {
1548
1460
  }
1549
1461
  async function writeMainDeclarationFile(references) {
1550
1462
  const dir = wxt.config.wxtDir;
1551
- const filePath = resolve9(dir, "wxt.d.ts");
1463
+ const filePath = resolve8(dir, "wxt.d.ts");
1552
1464
  await writeFileIfDifferent(
1553
1465
  filePath,
1554
1466
  [
1555
1467
  "// Generated by wxt",
1556
1468
  `/// <reference types="wxt/vite-builder-env" />`,
1557
1469
  ...references.map(
1558
- (ref) => `/// <reference types="./${normalizePath(relative5(dir, ref))}" />`
1470
+ (ref) => `/// <reference types="./${normalizePath(relative4(dir, ref))}" />`
1559
1471
  ),
1560
1472
  // Add references to modules installed from NPM to the TS project so
1561
1473
  // their type augmentation can update InlineConfig correctly. Local
@@ -1570,7 +1482,7 @@ async function writeMainDeclarationFile(references) {
1570
1482
  }
1571
1483
  async function writeTsConfigFile(mainReference) {
1572
1484
  const dir = wxt.config.wxtDir;
1573
- const getTsconfigPath = (path8) => normalizePath(relative5(dir, path8));
1485
+ const getTsconfigPath = (path8) => normalizePath(relative4(dir, path8));
1574
1486
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
1575
1487
  const aliasPath = getTsconfigPath(absolutePath);
1576
1488
  return [
@@ -1579,7 +1491,7 @@ async function writeTsConfigFile(mainReference) {
1579
1491
  ];
1580
1492
  }).join(",\n");
1581
1493
  await writeFileIfDifferent(
1582
- resolve9(dir, "tsconfig.json"),
1494
+ resolve8(dir, "tsconfig.json"),
1583
1495
  `{
1584
1496
  "compilerOptions": {
1585
1497
  "target": "ESNext",
@@ -1609,10 +1521,10 @@ import { loadConfig } from "c12";
1609
1521
  import path5 from "node:path";
1610
1522
 
1611
1523
  // src/core/utils/cache.ts
1612
- import fs8, { ensureDir as ensureDir2 } from "fs-extra";
1613
- import { dirname as dirname4, resolve as resolve10 } from "path";
1524
+ import fs7, { ensureDir as ensureDir2 } from "fs-extra";
1525
+ import { dirname as dirname4, resolve as resolve9 } from "path";
1614
1526
  function createFsCache(wxtDir) {
1615
- const getPath = (key) => resolve10(wxtDir, "cache", encodeURIComponent(key));
1527
+ const getPath = (key) => resolve9(wxtDir, "cache", encodeURIComponent(key));
1616
1528
  return {
1617
1529
  async set(key, value) {
1618
1530
  const path8 = getPath(key);
@@ -1622,7 +1534,7 @@ function createFsCache(wxtDir) {
1622
1534
  async get(key) {
1623
1535
  const path8 = getPath(key);
1624
1536
  try {
1625
- return await fs8.readFile(path8, "utf-8");
1537
+ return await fs7.readFile(path8, "utf-8");
1626
1538
  } catch {
1627
1539
  return void 0;
1628
1540
  }
@@ -1634,12 +1546,12 @@ function createFsCache(wxtDir) {
1634
1546
  import defu from "defu";
1635
1547
 
1636
1548
  // src/core/utils/package.ts
1637
- import { resolve as resolve11 } from "node:path";
1638
- import fs9 from "fs-extra";
1549
+ import { resolve as resolve10 } from "node:path";
1550
+ import fs8 from "fs-extra";
1639
1551
  async function getPackageJson() {
1640
- const file = resolve11(wxt.config.root, "package.json");
1552
+ const file = resolve10(wxt.config.root, "package.json");
1641
1553
  try {
1642
- return await fs9.readJson(file);
1554
+ return await fs8.readJson(file);
1643
1555
  } catch (err) {
1644
1556
  wxt.logger.debug(
1645
1557
  `Failed to read package.json at: ${file}. Returning undefined.`
@@ -1655,7 +1567,7 @@ function isModuleInstalled(name) {
1655
1567
  }
1656
1568
 
1657
1569
  // src/core/utils/building/resolve-config.ts
1658
- import fs10 from "fs-extra";
1570
+ import fs9 from "fs-extra";
1659
1571
  import glob3 from "fast-glob";
1660
1572
  async function resolveConfig(inlineConfig, command) {
1661
1573
  let userConfig = {};
@@ -1771,7 +1683,7 @@ async function resolveConfig(inlineConfig, command) {
1771
1683
  alias,
1772
1684
  experimental: defu(mergedConfig.experimental, {
1773
1685
  includeBrowserPolyfill: true,
1774
- viteRuntime: false
1686
+ entrypointImporter: "jiti"
1775
1687
  }),
1776
1688
  dev: {
1777
1689
  server: devServerConfig,
@@ -1893,7 +1805,7 @@ async function resolveWxtModuleDir() {
1893
1805
  return path5.resolve(requireResolve("wxt"), "../..");
1894
1806
  }
1895
1807
  async function isDirMissing(dir) {
1896
- return !await fs10.exists(dir);
1808
+ return !await fs9.exists(dir);
1897
1809
  }
1898
1810
  function logMissingDir(logger, name, expected) {
1899
1811
  logger.warn(
@@ -2005,6 +1917,95 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
2005
1917
  "content-script-style": "individual"
2006
1918
  };
2007
1919
 
1920
+ // src/core/utils/building/import-entrypoint.ts
1921
+ import createJITI from "jiti";
1922
+ import { createUnimport as createUnimport3 } from "unimport";
1923
+ import fs10 from "fs-extra";
1924
+ import { relative as relative5, resolve as resolve11 } from "node:path";
1925
+ import { transformSync } from "esbuild";
1926
+ import { fileURLToPath } from "node:url";
1927
+ async function importEntrypointFile(path8) {
1928
+ wxt.logger.debug("Loading file metadata:", path8);
1929
+ const normalPath = normalizePath(path8);
1930
+ const unimport2 = createUnimport3({
1931
+ ...wxt.config.imports,
1932
+ // Only allow specific imports, not all from the project
1933
+ dirs: []
1934
+ });
1935
+ await unimport2.init();
1936
+ const text = await fs10.readFile(path8, "utf-8");
1937
+ const textNoImports = removeProjectImportStatements(text);
1938
+ const { code } = await unimport2.injectImports(textNoImports);
1939
+ wxt.logger.debug(
1940
+ ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
1941
+ );
1942
+ const jiti = createJITI(
1943
+ typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
1944
+ {
1945
+ cache: false,
1946
+ debug: wxt.config.debug,
1947
+ esmResolve: true,
1948
+ alias: {
1949
+ "webextension-polyfill": resolve11(
1950
+ wxt.config.wxtModuleDir,
1951
+ "dist/virtual/mock-browser.js"
1952
+ )
1953
+ },
1954
+ // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
1955
+ // respect the custom transform function when using it's native bun option.
1956
+ experimentalBun: false,
1957
+ // List of extensions to transform with esbuild
1958
+ extensions: [
1959
+ ".ts",
1960
+ ".cts",
1961
+ ".mts",
1962
+ ".tsx",
1963
+ ".js",
1964
+ ".cjs",
1965
+ ".mjs",
1966
+ ".jsx"
1967
+ ],
1968
+ transform(opts) {
1969
+ const isEntrypoint = opts.filename === normalPath;
1970
+ return transformSync(
1971
+ // Use modified source code for entrypoints
1972
+ isEntrypoint ? code : opts.source,
1973
+ getEsbuildOptions(opts)
1974
+ );
1975
+ }
1976
+ }
1977
+ );
1978
+ try {
1979
+ const res = await jiti(path8);
1980
+ return res.default;
1981
+ } catch (err) {
1982
+ const filePath = relative5(wxt.config.root, path8);
1983
+ if (err instanceof ReferenceError) {
1984
+ const variableName = err.message.replace(" is not defined", "");
1985
+ throw Error(
1986
+ `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
1987
+ { cause: err }
1988
+ );
1989
+ } else {
1990
+ wxt.logger.error(err);
1991
+ throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
1992
+ }
1993
+ }
1994
+ }
1995
+ function getEsbuildOptions(opts) {
1996
+ const isJsx = opts.filename?.endsWith("x");
1997
+ return {
1998
+ format: "cjs",
1999
+ loader: isJsx ? "tsx" : "ts",
2000
+ ...isJsx ? {
2001
+ // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
2002
+ // grabbing the entrypoint's options.
2003
+ jsxFactory: "h",
2004
+ jsxFragment: "Fragment"
2005
+ } : void 0
2006
+ };
2007
+ }
2008
+
2008
2009
  // src/core/utils/building/internal-build.ts
2009
2010
  import pc5 from "picocolors";
2010
2011
  import fs13 from "fs-extra";
@@ -3125,6 +3126,9 @@ var packageManagers = {
3125
3126
  };
3126
3127
 
3127
3128
  // src/core/builders/vite/index.ts
3129
+ import { ViteNodeServer } from "vite-node/server";
3130
+ import { ViteNodeRunner } from "vite-node/client";
3131
+ import { installSourcemapsSupport } from "vite-node/source-map";
3128
3132
  async function createViteBuilder(wxtConfig, hooks, server) {
3129
3133
  const vite = await import("vite");
3130
3134
  const getBaseConfig = async () => {
@@ -3272,21 +3276,64 @@ async function createViteBuilder(wxtConfig, hooks, server) {
3272
3276
  return {
3273
3277
  name: "Vite",
3274
3278
  version: vite.version,
3275
- async importEntrypoint(url) {
3276
- const baseConfig = await getBaseConfig();
3277
- const envConfig = {
3278
- plugins: [
3279
- webextensionPolyfillMock(wxtConfig),
3280
- removeEntrypointMainFunction(wxtConfig, url)
3281
- ]
3282
- };
3283
- const config = vite.mergeConfig(baseConfig, envConfig);
3284
- const server2 = await vite.createServer(config);
3285
- await server2.listen();
3286
- const runtime = await vite.createViteRuntime(server2, { hmr: false });
3287
- const module = await runtime.executeUrl(url);
3288
- await server2.close();
3289
- return module.default;
3279
+ async importEntrypoint(path8) {
3280
+ switch (wxtConfig.experimental.entrypointImporter) {
3281
+ default:
3282
+ case "jiti": {
3283
+ return await importEntrypointFile(path8);
3284
+ }
3285
+ case "vite-runtime": {
3286
+ const baseConfig = await getBaseConfig();
3287
+ const envConfig = {
3288
+ plugins: [
3289
+ webextensionPolyfillMock(wxtConfig),
3290
+ removeEntrypointMainFunction(wxtConfig, path8)
3291
+ ]
3292
+ };
3293
+ const config = vite.mergeConfig(baseConfig, envConfig);
3294
+ const server2 = await vite.createServer(config);
3295
+ await server2.listen();
3296
+ const runtime = await vite.createViteRuntime(server2, { hmr: false });
3297
+ const module = await runtime.executeUrl(path8);
3298
+ await server2.close();
3299
+ return module.default;
3300
+ }
3301
+ case "vite-node": {
3302
+ const baseConfig = await getBaseConfig();
3303
+ baseConfig.optimizeDeps ??= {};
3304
+ baseConfig.optimizeDeps.noDiscovery = true;
3305
+ baseConfig.optimizeDeps.include = [];
3306
+ const envConfig = {
3307
+ plugins: [
3308
+ webextensionPolyfillMock(wxtConfig),
3309
+ removeEntrypointMainFunction(wxtConfig, path8)
3310
+ ]
3311
+ };
3312
+ const config = vite.mergeConfig(baseConfig, envConfig);
3313
+ const server2 = await vite.createServer(config);
3314
+ await server2.pluginContainer.buildStart({});
3315
+ const node = new ViteNodeServer(server2);
3316
+ installSourcemapsSupport({
3317
+ getSourceMap: (source) => node.getSourceMap(source)
3318
+ });
3319
+ const runner = new ViteNodeRunner({
3320
+ root: server2.config.root,
3321
+ base: server2.config.base,
3322
+ // when having the server and runner in a different context,
3323
+ // you will need to handle the communication between them
3324
+ // and pass to this function
3325
+ fetchModule(id) {
3326
+ return node.fetchModule(id);
3327
+ },
3328
+ resolveId(id, importer) {
3329
+ return node.resolveId(id, importer);
3330
+ }
3331
+ });
3332
+ const res = await runner.executeFile(path8);
3333
+ await server2.close();
3334
+ return res.default;
3335
+ }
3336
+ }
3290
3337
  },
3291
3338
  async build(group) {
3292
3339
  let entryConfig;