wxt 0.18.7 → 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.
package/dist/index.cjs CHANGED
@@ -8637,7 +8637,7 @@ var init_core2 = __esm({
8637
8637
 
8638
8638
  // ../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/shared/consola.06ad8a64.mjs
8639
8639
  function parseStack(stack) {
8640
- const cwd = process.cwd() + import_node_path15.sep;
8640
+ const cwd = process.cwd() + import_node_path14.sep;
8641
8641
  const lines = stack.split("\n").splice(1).map((l2) => l2.trim().replace("file://", "").replace(cwd, ""));
8642
8642
  return lines;
8643
8643
  }
@@ -8645,12 +8645,12 @@ function writeStream(data, stream) {
8645
8645
  const write = stream.__write || stream.write;
8646
8646
  return write.call(stream, data);
8647
8647
  }
8648
- var import_node_util11, import_node_path15, bracket, BasicReporter;
8648
+ var import_node_util11, import_node_path14, bracket, BasicReporter;
8649
8649
  var init_consola_06ad8a64 = __esm({
8650
8650
  "../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/shared/consola.06ad8a64.mjs"() {
8651
8651
  "use strict";
8652
8652
  import_node_util11 = require("util");
8653
- import_node_path15 = require("path");
8653
+ import_node_path14 = require("path");
8654
8654
  bracket = (x) => x ? `[${x}]` : "";
8655
8655
  BasicReporter = class {
8656
8656
  formatStack(stack, opts) {
@@ -9053,7 +9053,7 @@ async function prompt(message, opts = {}) {
9053
9053
  }
9054
9054
  throw new Error(`Unknown prompt type: ${opts.type}`);
9055
9055
  }
9056
- var import_node_process11, import_node_readline, import_node_tty3, import_tty, import_node_util12, import_node_path16, ESC, CSI, beep, cursor, scroll, erase, src, picocolors, tty4, isColorSupported2, formatter, replaceClose2, createColors2, picocolorsExports, l, m, G, K, Y, v, L, M, T, r, Z, H, q, p, J, b, W, Q, I, w, N, j, X, _, DD, uD, R, V, tD, h2, sD, iD, ED, oD, unicode, s, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_BAR, S_BAR_END, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_CHECKBOX_ACTIVE, S_CHECKBOX_SELECTED, S_CHECKBOX_INACTIVE, symbol, text, confirm, select, multiselect;
9056
+ var import_node_process11, import_node_readline, import_node_tty3, import_tty, import_node_util12, import_node_path15, ESC, CSI, beep, cursor, scroll, erase, src, picocolors, tty4, isColorSupported2, formatter, replaceClose2, createColors2, picocolorsExports, l, m, G, K, Y, v, L, M, T, r, Z, H, q, p, J, b, W, Q, I, w, N, j, X, _, DD, uD, R, V, tD, h2, sD, iD, ED, oD, unicode, s, S_STEP_ACTIVE, S_STEP_CANCEL, S_STEP_ERROR, S_STEP_SUBMIT, S_BAR, S_BAR_END, S_RADIO_ACTIVE, S_RADIO_INACTIVE, S_CHECKBOX_ACTIVE, S_CHECKBOX_SELECTED, S_CHECKBOX_INACTIVE, symbol, text, confirm, select, multiselect;
9057
9057
  var init_prompt = __esm({
9058
9058
  "../../node_modules/.pnpm/consola@3.2.3/node_modules/consola/dist/chunks/prompt.mjs"() {
9059
9059
  "use strict";
@@ -9066,7 +9066,7 @@ var init_prompt = __esm({
9066
9066
  init_core2();
9067
9067
  init_consola_06ad8a64();
9068
9068
  import_node_util12 = require("util");
9069
- import_node_path16 = require("path");
9069
+ import_node_path15 = require("path");
9070
9070
  ESC = "\x1B";
9071
9071
  CSI = `${ESC}[`;
9072
9072
  beep = "\x07";
@@ -10981,10 +10981,13 @@ try {
10981
10981
  // Use "pre" so the new script is added before vite bundles all the scripts
10982
10982
  order: "pre",
10983
10983
  handler(html, _ctx) {
10984
+ const src2 = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
10984
10985
  const { document } = (0, import_linkedom2.parseHTML)(html);
10986
+ const existing = document.querySelector(`script[src='${src2}']`);
10987
+ if (existing) return;
10985
10988
  const script = document.createElement("script");
10986
10989
  script.type = "module";
10987
- script.src = config.command === "serve" ? `http://${config.dev.server?.hostname}:${config.dev.server?.port}/@id/${virtualHtmlModuleId}` : virtualHtmlModuleId;
10990
+ script.src = src2;
10988
10991
  if (document.head == null) {
10989
10992
  const newHead = document.createElement("head");
10990
10993
  document.documentElement.prepend(newHead);
@@ -11032,6 +11035,9 @@ ${noImports}`;
11032
11035
  }
11033
11036
 
11034
11037
  // src/core/builders/vite/index.ts
11038
+ var import_server = require("vite-node/server");
11039
+ var import_client = require("vite-node/client");
11040
+ var import_source_map = require("vite-node/source-map");
11035
11041
  async function createViteBuilder(wxtConfig, hooks, server) {
11036
11042
  const vite = await import("vite");
11037
11043
  const getBaseConfig = async () => {
@@ -11179,21 +11185,64 @@ async function createViteBuilder(wxtConfig, hooks, server) {
11179
11185
  return {
11180
11186
  name: "Vite",
11181
11187
  version: vite.version,
11182
- async importEntrypoint(url) {
11183
- const baseConfig = await getBaseConfig();
11184
- const envConfig = {
11185
- plugins: [
11186
- webextensionPolyfillMock(wxtConfig),
11187
- removeEntrypointMainFunction(wxtConfig, url)
11188
- ]
11189
- };
11190
- const config = vite.mergeConfig(baseConfig, envConfig);
11191
- const server2 = await vite.createServer(config);
11192
- await server2.listen();
11193
- const runtime = await vite.createViteRuntime(server2, { hmr: false });
11194
- const module2 = await runtime.executeUrl(url);
11195
- await server2.close();
11196
- return module2.default;
11188
+ async importEntrypoint(path12) {
11189
+ switch (wxtConfig.experimental.entrypointImporter) {
11190
+ default:
11191
+ case "jiti": {
11192
+ return await importEntrypointFile(path12);
11193
+ }
11194
+ case "vite-runtime": {
11195
+ const baseConfig = await getBaseConfig();
11196
+ const envConfig = {
11197
+ plugins: [
11198
+ webextensionPolyfillMock(wxtConfig),
11199
+ removeEntrypointMainFunction(wxtConfig, path12)
11200
+ ]
11201
+ };
11202
+ const config = vite.mergeConfig(baseConfig, envConfig);
11203
+ const server2 = await vite.createServer(config);
11204
+ await server2.listen();
11205
+ const runtime = await vite.createViteRuntime(server2, { hmr: false });
11206
+ const module2 = await runtime.executeUrl(path12);
11207
+ await server2.close();
11208
+ return module2.default;
11209
+ }
11210
+ case "vite-node": {
11211
+ const baseConfig = await getBaseConfig();
11212
+ baseConfig.optimizeDeps ??= {};
11213
+ baseConfig.optimizeDeps.noDiscovery = true;
11214
+ baseConfig.optimizeDeps.include = [];
11215
+ const envConfig = {
11216
+ plugins: [
11217
+ webextensionPolyfillMock(wxtConfig),
11218
+ removeEntrypointMainFunction(wxtConfig, path12)
11219
+ ]
11220
+ };
11221
+ const config = vite.mergeConfig(baseConfig, envConfig);
11222
+ const server2 = await vite.createServer(config);
11223
+ await server2.pluginContainer.buildStart({});
11224
+ const node = new import_server.ViteNodeServer(server2);
11225
+ (0, import_source_map.installSourcemapsSupport)({
11226
+ getSourceMap: (source) => node.getSourceMap(source)
11227
+ });
11228
+ const runner = new import_client.ViteNodeRunner({
11229
+ root: server2.config.root,
11230
+ base: server2.config.base,
11231
+ // when having the server and runner in a different context,
11232
+ // you will need to handle the communication between them
11233
+ // and pass to this function
11234
+ fetchModule(id) {
11235
+ return node.fetchModule(id);
11236
+ },
11237
+ resolveId(id, importer) {
11238
+ return node.resolveId(id, importer);
11239
+ }
11240
+ });
11241
+ const res = await runner.executeFile(path12);
11242
+ await server2.close();
11243
+ return res.default;
11244
+ }
11245
+ }
11197
11246
  },
11198
11247
  async build(group) {
11199
11248
  let entryConfig;
@@ -11382,11 +11431,25 @@ function detectDevChanges(changedFiles, currentOutput) {
11382
11431
  (changedFile) => findEffectedSteps(changedFile, currentOutput)
11383
11432
  )
11384
11433
  );
11385
- if (changedSteps.size === 0) return { type: "no-change" };
11434
+ if (changedSteps.size === 0) {
11435
+ const hasPublicChange = some(
11436
+ changedFiles,
11437
+ (file) => file.startsWith(wxt.config.publicDir)
11438
+ );
11439
+ if (hasPublicChange) {
11440
+ return {
11441
+ type: "extension-reload",
11442
+ rebuildGroups: [],
11443
+ cachedOutput: currentOutput
11444
+ };
11445
+ } else {
11446
+ return { type: "no-change" };
11447
+ }
11448
+ }
11386
11449
  const unchangedOutput = {
11387
11450
  manifest: currentOutput.manifest,
11388
11451
  steps: [],
11389
- publicAssets: []
11452
+ publicAssets: [...currentOutput.publicAssets]
11390
11453
  };
11391
11454
  const changedOutput = {
11392
11455
  manifest: currentOutput.manifest,
@@ -11400,13 +11463,6 @@ function detectDevChanges(changedFiles, currentOutput) {
11400
11463
  unchangedOutput.steps.push(step);
11401
11464
  }
11402
11465
  }
11403
- for (const asset of currentOutput.publicAssets) {
11404
- if (changedSteps.has(asset)) {
11405
- changedOutput.publicAssets.push(asset);
11406
- } else {
11407
- unchangedOutput.publicAssets.push(asset);
11408
- }
11409
- }
11410
11466
  const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
11411
11467
  if (isOnlyHtmlChanges) {
11412
11468
  return {
@@ -11447,116 +11503,20 @@ function findEffectedSteps(changedFile, currentOutput) {
11447
11503
  const effectedChunk = step.chunks.find((chunk) => isChunkEffected(chunk));
11448
11504
  if (effectedChunk) changes.push(step);
11449
11505
  }
11450
- const effectedAsset = currentOutput.publicAssets.find(
11451
- (chunk) => isChunkEffected(chunk)
11452
- );
11453
- if (effectedAsset) changes.push(effectedAsset);
11454
11506
  return changes;
11455
11507
  }
11456
11508
 
11457
11509
  // src/core/utils/building/find-entrypoints.ts
11458
11510
  var import_path4 = require("path");
11459
- var import_fs_extra7 = __toESM(require("fs-extra"), 1);
11511
+ var import_fs_extra6 = __toESM(require("fs-extra"), 1);
11460
11512
  var import_minimatch = require("minimatch");
11461
11513
  var import_linkedom3 = require("linkedom");
11462
11514
  var import_json5 = __toESM(require("json5"), 1);
11463
11515
  var import_fast_glob2 = __toESM(require("fast-glob"), 1);
11464
11516
  var import_picocolors2 = __toESM(require("picocolors"), 1);
11465
-
11466
- // src/core/utils/building/import-entrypoint.ts
11467
- var import_jiti = __toESM(require("jiti"), 1);
11468
- var import_unimport2 = require("unimport");
11469
- var import_fs_extra6 = __toESM(require("fs-extra"), 1);
11470
- var import_node_path13 = require("path");
11471
- var import_esbuild = require("esbuild");
11472
- var import_node_url3 = require("url");
11473
- var import_meta = {};
11474
- async function importEntrypointFile(path12) {
11475
- wxt.logger.debug("Loading file metadata:", path12);
11476
- const normalPath = normalizePath(path12);
11477
- const unimport2 = (0, import_unimport2.createUnimport)({
11478
- ...wxt.config.imports,
11479
- // Only allow specific imports, not all from the project
11480
- dirs: []
11481
- });
11482
- await unimport2.init();
11483
- const text2 = await import_fs_extra6.default.readFile(path12, "utf-8");
11484
- const textNoImports = removeProjectImportStatements(text2);
11485
- const { code } = await unimport2.injectImports(textNoImports);
11486
- wxt.logger.debug(
11487
- ["Text:", text2, "No imports:", textNoImports, "Code:", code].join("\n")
11488
- );
11489
- const jiti = (0, import_jiti.default)(
11490
- typeof __filename !== "undefined" ? __filename : (0, import_node_url3.fileURLToPath)(import_meta.url),
11491
- {
11492
- cache: false,
11493
- debug: wxt.config.debug,
11494
- esmResolve: true,
11495
- alias: {
11496
- "webextension-polyfill": (0, import_node_path13.resolve)(
11497
- wxt.config.wxtModuleDir,
11498
- "dist/virtual/mock-browser.js"
11499
- )
11500
- },
11501
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
11502
- // respect the custom transform function when using it's native bun option.
11503
- experimentalBun: false,
11504
- // List of extensions to transform with esbuild
11505
- extensions: [
11506
- ".ts",
11507
- ".cts",
11508
- ".mts",
11509
- ".tsx",
11510
- ".js",
11511
- ".cjs",
11512
- ".mjs",
11513
- ".jsx"
11514
- ],
11515
- transform(opts) {
11516
- const isEntrypoint = opts.filename === normalPath;
11517
- return (0, import_esbuild.transformSync)(
11518
- // Use modified source code for entrypoints
11519
- isEntrypoint ? code : opts.source,
11520
- getEsbuildOptions(opts)
11521
- );
11522
- }
11523
- }
11524
- );
11525
- try {
11526
- const res = await jiti(path12);
11527
- return res.default;
11528
- } catch (err) {
11529
- const filePath = (0, import_node_path13.relative)(wxt.config.root, path12);
11530
- if (err instanceof ReferenceError) {
11531
- const variableName = err.message.replace(" is not defined", "");
11532
- throw Error(
11533
- `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
11534
- { cause: err }
11535
- );
11536
- } else {
11537
- wxt.logger.error(err);
11538
- throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
11539
- }
11540
- }
11541
- }
11542
- function getEsbuildOptions(opts) {
11543
- const isJsx = opts.filename?.endsWith("x");
11544
- return {
11545
- format: "cjs",
11546
- loader: isJsx ? "tsx" : "ts",
11547
- ...isJsx ? {
11548
- // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
11549
- // grabbing the entrypoint's options.
11550
- jsxFactory: "h",
11551
- jsxFragment: "Fragment"
11552
- } : void 0
11553
- };
11554
- }
11555
-
11556
- // src/core/utils/building/find-entrypoints.ts
11557
11517
  async function findEntrypoints() {
11558
- await import_fs_extra7.default.mkdir(wxt.config.wxtDir, { recursive: true });
11559
- await import_fs_extra7.default.writeJson((0, import_path4.resolve)(wxt.config.wxtDir, "tsconfig.json"), {});
11518
+ await import_fs_extra6.default.mkdir(wxt.config.wxtDir, { recursive: true });
11519
+ await import_fs_extra6.default.writeJson((0, import_path4.resolve)(wxt.config.wxtDir, "tsconfig.json"), {});
11560
11520
  const relativePaths = await (0, import_fast_glob2.default)(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
11561
11521
  cwd: wxt.config.entrypointsDir
11562
11522
  });
@@ -11767,7 +11727,7 @@ async function getUnlistedScriptEntrypoint({
11767
11727
  name,
11768
11728
  skipped
11769
11729
  }) {
11770
- const defaultExport = await importEntrypoint(inputPath);
11730
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
11771
11731
  if (defaultExport == null) {
11772
11732
  throw Error(
11773
11733
  `${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
@@ -11790,7 +11750,7 @@ async function getBackgroundEntrypoint({
11790
11750
  }) {
11791
11751
  let options = {};
11792
11752
  if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
11793
- const defaultExport = await importEntrypoint(inputPath);
11753
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
11794
11754
  if (defaultExport == null) {
11795
11755
  throw Error(
11796
11756
  `${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
@@ -11816,7 +11776,13 @@ async function getContentScriptEntrypoint({
11816
11776
  name,
11817
11777
  skipped
11818
11778
  }) {
11819
- const { main: _2, ...options } = await importEntrypoint(inputPath);
11779
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
11780
+ if (defaultExport == null) {
11781
+ throw Error(
11782
+ `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
11783
+ );
11784
+ }
11785
+ const { main: _2, ...options } = defaultExport;
11820
11786
  if (options == null) {
11821
11787
  throw Error(
11822
11788
  `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
@@ -11859,7 +11825,7 @@ async function getSidepanelEntrypoint(info) {
11859
11825
  };
11860
11826
  }
11861
11827
  async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
11862
- const content = await import_fs_extra7.default.readFile(info.inputPath, "utf-8");
11828
+ const content = await import_fs_extra6.default.readFile(info.inputPath, "utf-8");
11863
11829
  const { document } = (0, import_linkedom3.parseHTML)(content);
11864
11830
  const options = {};
11865
11831
  const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
@@ -11919,15 +11885,12 @@ var PATH_GLOB_TO_TYPE_MAP = {
11919
11885
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
11920
11886
  };
11921
11887
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
11922
- function importEntrypoint(path12) {
11923
- return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path12) : importEntrypointFile(path12);
11924
- }
11925
11888
 
11926
11889
  // src/core/utils/building/generate-wxt-dir.ts
11927
- var import_unimport3 = require("unimport");
11928
- var import_fs_extra8 = __toESM(require("fs-extra"), 1);
11890
+ var import_unimport2 = require("unimport");
11891
+ var import_fs_extra7 = __toESM(require("fs-extra"), 1);
11929
11892
  var import_path5 = require("path");
11930
- var import_node_path14 = __toESM(require("path"), 1);
11893
+ var import_node_path13 = __toESM(require("path"), 1);
11931
11894
 
11932
11895
  // src/core/utils/i18n.ts
11933
11896
  var predefinedMessages = {
@@ -11968,10 +11931,10 @@ function parseI18nMessages(messagesJson) {
11968
11931
 
11969
11932
  // src/core/utils/building/generate-wxt-dir.ts
11970
11933
  async function generateTypesDir(entrypoints) {
11971
- await import_fs_extra8.default.ensureDir(wxt.config.typesDir);
11934
+ await import_fs_extra7.default.ensureDir(wxt.config.typesDir);
11972
11935
  const references = [];
11973
11936
  if (wxt.config.imports !== false) {
11974
- const unimport2 = (0, import_unimport3.createUnimport)(wxt.config.imports);
11937
+ const unimport2 = (0, import_unimport2.createUnimport)(wxt.config.imports);
11975
11938
  references.push(await writeImportsDeclarationFile(unimport2));
11976
11939
  if (wxt.config.imports.eslintrc.enabled) {
11977
11940
  await writeImportsEslintFile(unimport2, wxt.config.imports);
@@ -12000,7 +11963,7 @@ async function writeImportsEslintFile(unimport2, options) {
12000
11963
  (await unimport2.getImports()).map((i2) => i2.as ?? i2.name).filter(Boolean).sort().forEach((name) => {
12001
11964
  eslintrc.globals[name] = options.eslintrc.globalsPropValue;
12002
11965
  });
12003
- await import_fs_extra8.default.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
11966
+ await import_fs_extra7.default.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
12004
11967
  }
12005
11968
  async function writePathsDeclarationFile(entrypoints) {
12006
11969
  const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "paths.d.ts");
@@ -12054,13 +12017,13 @@ declare module "wxt/browser" {
12054
12017
  `;
12055
12018
  let messages;
12056
12019
  if (defaultLocale) {
12057
- const defaultLocalePath = import_node_path14.default.resolve(
12020
+ const defaultLocalePath = import_node_path13.default.resolve(
12058
12021
  wxt.config.publicDir,
12059
12022
  "_locales",
12060
12023
  defaultLocale,
12061
12024
  "messages.json"
12062
12025
  );
12063
- const content = JSON.parse(await import_fs_extra8.default.readFile(defaultLocalePath, "utf-8"));
12026
+ const content = JSON.parse(await import_fs_extra7.default.readFile(defaultLocalePath, "utf-8"));
12064
12027
  messages = parseI18nMessages(content);
12065
12028
  } else {
12066
12029
  messages = parseI18nMessages({});
@@ -12161,23 +12124,23 @@ ${paths}
12161
12124
 
12162
12125
  // src/core/utils/building/resolve-config.ts
12163
12126
  var import_c12 = require("c12");
12164
- var import_node_path19 = __toESM(require("path"), 1);
12127
+ var import_node_path18 = __toESM(require("path"), 1);
12165
12128
 
12166
12129
  // src/core/utils/cache.ts
12167
- var import_fs_extra9 = __toESM(require("fs-extra"), 1);
12130
+ var import_fs_extra8 = __toESM(require("fs-extra"), 1);
12168
12131
  var import_path6 = require("path");
12169
12132
  function createFsCache(wxtDir) {
12170
12133
  const getPath = (key) => (0, import_path6.resolve)(wxtDir, "cache", encodeURIComponent(key));
12171
12134
  return {
12172
12135
  async set(key, value) {
12173
12136
  const path12 = getPath(key);
12174
- await (0, import_fs_extra9.ensureDir)((0, import_path6.dirname)(path12));
12137
+ await (0, import_fs_extra8.ensureDir)((0, import_path6.dirname)(path12));
12175
12138
  await writeFileIfDifferent(path12, value);
12176
12139
  },
12177
12140
  async get(key) {
12178
12141
  const path12 = getPath(key);
12179
12142
  try {
12180
- return await import_fs_extra9.default.readFile(path12, "utf-8");
12143
+ return await import_fs_extra8.default.readFile(path12, "utf-8");
12181
12144
  } catch {
12182
12145
  return void 0;
12183
12146
  }
@@ -12193,18 +12156,18 @@ var import_node_process13 = require("process");
12193
12156
  init_utils2();
12194
12157
  var import_node_tty4 = require("tty");
12195
12158
  var import_node_util13 = require("util");
12196
- var import_node_path17 = require("path");
12159
+ var import_node_path16 = require("path");
12197
12160
 
12198
12161
  // src/core/utils/building/resolve-config.ts
12199
12162
  var import_defu = __toESM(require("defu"), 1);
12200
12163
 
12201
12164
  // src/core/utils/package.ts
12202
- var import_node_path18 = require("path");
12203
- var import_fs_extra10 = __toESM(require("fs-extra"), 1);
12165
+ var import_node_path17 = require("path");
12166
+ var import_fs_extra9 = __toESM(require("fs-extra"), 1);
12204
12167
  async function getPackageJson() {
12205
- const file = (0, import_node_path18.resolve)(wxt.config.root, "package.json");
12168
+ const file = (0, import_node_path17.resolve)(wxt.config.root, "package.json");
12206
12169
  try {
12207
- return await import_fs_extra10.default.readJson(file);
12170
+ return await import_fs_extra9.default.readJson(file);
12208
12171
  } catch (err) {
12209
12172
  wxt.logger.debug(
12210
12173
  `Failed to read package.json at: ${file}. Returning undefined.`
@@ -12220,9 +12183,9 @@ function isModuleInstalled(name) {
12220
12183
  }
12221
12184
 
12222
12185
  // src/core/utils/building/resolve-config.ts
12223
- var import_fs_extra11 = __toESM(require("fs-extra"), 1);
12186
+ var import_fs_extra10 = __toESM(require("fs-extra"), 1);
12224
12187
  var import_fast_glob3 = __toESM(require("fast-glob"), 1);
12225
- var import_meta2 = {};
12188
+ var import_meta = {};
12226
12189
  async function resolveConfig(inlineConfig, command) {
12227
12190
  let userConfig = {};
12228
12191
  let userConfigMetadata;
@@ -12247,28 +12210,28 @@ async function resolveConfig(inlineConfig, command) {
12247
12210
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
12248
12211
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
12249
12212
  const env2 = { browser, command, manifestVersion, mode };
12250
- const root = import_node_path19.default.resolve(
12213
+ const root = import_node_path18.default.resolve(
12251
12214
  inlineConfig.root ?? userConfig.root ?? process.cwd()
12252
12215
  );
12253
- const wxtDir = import_node_path19.default.resolve(root, ".wxt");
12216
+ const wxtDir = import_node_path18.default.resolve(root, ".wxt");
12254
12217
  const wxtModuleDir = await resolveWxtModuleDir();
12255
- const srcDir = import_node_path19.default.resolve(root, mergedConfig.srcDir ?? root);
12256
- const entrypointsDir = import_node_path19.default.resolve(
12218
+ const srcDir = import_node_path18.default.resolve(root, mergedConfig.srcDir ?? root);
12219
+ const entrypointsDir = import_node_path18.default.resolve(
12257
12220
  srcDir,
12258
12221
  mergedConfig.entrypointsDir ?? "entrypoints"
12259
12222
  );
12260
- const modulesDir = import_node_path19.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
12223
+ const modulesDir = import_node_path18.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
12261
12224
  if (await isDirMissing(entrypointsDir)) {
12262
12225
  logMissingDir(logger, "Entrypoints", entrypointsDir);
12263
12226
  }
12264
12227
  const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
12265
- const publicDir = import_node_path19.default.resolve(srcDir, mergedConfig.publicDir ?? "public");
12228
+ const publicDir = import_node_path18.default.resolve(srcDir, mergedConfig.publicDir ?? "public");
12266
12229
  if (await isDirMissing(publicDir)) {
12267
12230
  logMissingDir(logger, "Public", publicDir);
12268
12231
  }
12269
- const typesDir = import_node_path19.default.resolve(wxtDir, "types");
12270
- const outBaseDir = import_node_path19.default.resolve(root, mergedConfig.outDir ?? ".output");
12271
- const outDir = import_node_path19.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
12232
+ const typesDir = import_node_path18.default.resolve(wxtDir, "types");
12233
+ const outBaseDir = import_node_path18.default.resolve(root, mergedConfig.outDir ?? ".output");
12234
+ const outDir = import_node_path18.default.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
12272
12235
  const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
12273
12236
  const runnerConfig = await (0, import_c12.loadConfig)({
12274
12237
  name: "web-ext",
@@ -12285,7 +12248,7 @@ async function resolveConfig(inlineConfig, command) {
12285
12248
  "~": srcDir,
12286
12249
  "@@": root,
12287
12250
  "~~": root
12288
- }).map(([key, value]) => [key, import_node_path19.default.resolve(root, value)])
12251
+ }).map(([key, value]) => [key, import_node_path18.default.resolve(root, value)])
12289
12252
  );
12290
12253
  let devServerConfig;
12291
12254
  if (command === "serve") {
@@ -12337,7 +12300,7 @@ async function resolveConfig(inlineConfig, command) {
12337
12300
  alias,
12338
12301
  experimental: (0, import_defu.default)(mergedConfig.experimental, {
12339
12302
  includeBrowserPolyfill: true,
12340
- viteRuntime: false
12303
+ entrypointImporter: "jiti"
12341
12304
  }),
12342
12305
  dev: {
12343
12306
  server: devServerConfig,
@@ -12375,7 +12338,7 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
12375
12338
  };
12376
12339
  }
12377
12340
  function resolveZipConfig(root, mergedConfig) {
12378
- const downloadedPackagesDir = import_node_path19.default.resolve(root, ".wxt/local_modules");
12341
+ const downloadedPackagesDir = import_node_path18.default.resolve(root, ".wxt/local_modules");
12379
12342
  return {
12380
12343
  name: void 0,
12381
12344
  sourcesTemplate: "{{name}}-{{version}}-sources.zip",
@@ -12401,12 +12364,12 @@ function resolveZipConfig(root, mergedConfig) {
12401
12364
  };
12402
12365
  }
12403
12366
  function resolveAnalysisConfig(root, mergedConfig) {
12404
- const analysisOutputFile = import_node_path19.default.resolve(
12367
+ const analysisOutputFile = import_node_path18.default.resolve(
12405
12368
  root,
12406
12369
  mergedConfig.analysis?.outputFile ?? "stats.html"
12407
12370
  );
12408
- const analysisOutputDir = import_node_path19.default.dirname(analysisOutputFile);
12409
- const analysisOutputName = import_node_path19.default.parse(analysisOutputFile).name;
12371
+ const analysisOutputDir = import_node_path18.default.dirname(analysisOutputFile);
12372
+ const analysisOutputName = import_node_path18.default.parse(analysisOutputFile).name;
12410
12373
  return {
12411
12374
  enabled: mergedConfig.analysis?.enabled ?? false,
12412
12375
  open: mergedConfig.analysis?.open ?? false,
@@ -12445,7 +12408,7 @@ async function getUnimportOptions(wxtDir, logger, config) {
12445
12408
  dirs: ["components", "composables", "hooks", "utils"],
12446
12409
  eslintrc: {
12447
12410
  enabled,
12448
- filePath: import_node_path19.default.resolve(wxtDir, "eslintrc-auto-import.json"),
12411
+ filePath: import_node_path18.default.resolve(wxtDir, "eslintrc-auto-import.json"),
12449
12412
  globalsPropValue: true
12450
12413
  }
12451
12414
  };
@@ -12455,16 +12418,16 @@ async function getUnimportOptions(wxtDir, logger, config) {
12455
12418
  );
12456
12419
  }
12457
12420
  async function resolveWxtModuleDir() {
12458
- const requireResolve = require?.resolve ?? (await import("module")).default.createRequire(import_meta2.url).resolve;
12459
- return import_node_path19.default.resolve(requireResolve("wxt"), "../..");
12421
+ const requireResolve = require?.resolve ?? (await import("module")).default.createRequire(import_meta.url).resolve;
12422
+ return import_node_path18.default.resolve(requireResolve("wxt"), "../..");
12460
12423
  }
12461
12424
  async function isDirMissing(dir) {
12462
- return !await import_fs_extra11.default.exists(dir);
12425
+ return !await import_fs_extra10.default.exists(dir);
12463
12426
  }
12464
12427
  function logMissingDir(logger, name, expected) {
12465
12428
  logger.warn(
12466
12429
  `${name} directory not found: ./${normalizePath(
12467
- import_node_path19.default.relative(process.cwd(), expected)
12430
+ import_node_path18.default.relative(process.cwd(), expected)
12468
12431
  )}`
12469
12432
  );
12470
12433
  }
@@ -12508,7 +12471,7 @@ async function resolveWxtModules(modulesDir, modules = []) {
12508
12471
  }).catch(() => []);
12509
12472
  const localModules = await Promise.all(
12510
12473
  localModulePaths.map(async (file) => {
12511
- const absolutePath = normalizePath(import_node_path19.default.resolve(modulesDir, file));
12474
+ const absolutePath = normalizePath(import_node_path18.default.resolve(modulesDir, file));
12512
12475
  const { config } = await (0, import_c12.loadConfig)({
12513
12476
  configFile: absolutePath,
12514
12477
  globalRc: false,
@@ -12571,6 +12534,96 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
12571
12534
  "content-script-style": "individual"
12572
12535
  };
12573
12536
 
12537
+ // src/core/utils/building/import-entrypoint.ts
12538
+ var import_jiti = __toESM(require("jiti"), 1);
12539
+ var import_unimport3 = require("unimport");
12540
+ var import_fs_extra11 = __toESM(require("fs-extra"), 1);
12541
+ var import_node_path19 = require("path");
12542
+ var import_esbuild = require("esbuild");
12543
+ var import_node_url3 = require("url");
12544
+ var import_meta2 = {};
12545
+ async function importEntrypointFile(path12) {
12546
+ wxt.logger.debug("Loading file metadata:", path12);
12547
+ const normalPath = normalizePath(path12);
12548
+ const unimport2 = (0, import_unimport3.createUnimport)({
12549
+ ...wxt.config.imports,
12550
+ // Only allow specific imports, not all from the project
12551
+ dirs: []
12552
+ });
12553
+ await unimport2.init();
12554
+ const text2 = await import_fs_extra11.default.readFile(path12, "utf-8");
12555
+ const textNoImports = removeProjectImportStatements(text2);
12556
+ const { code } = await unimport2.injectImports(textNoImports);
12557
+ wxt.logger.debug(
12558
+ ["Text:", text2, "No imports:", textNoImports, "Code:", code].join("\n")
12559
+ );
12560
+ const jiti = (0, import_jiti.default)(
12561
+ typeof __filename !== "undefined" ? __filename : (0, import_node_url3.fileURLToPath)(import_meta2.url),
12562
+ {
12563
+ cache: false,
12564
+ debug: wxt.config.debug,
12565
+ esmResolve: true,
12566
+ alias: {
12567
+ "webextension-polyfill": (0, import_node_path19.resolve)(
12568
+ wxt.config.wxtModuleDir,
12569
+ "dist/virtual/mock-browser.js"
12570
+ )
12571
+ },
12572
+ // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
12573
+ // respect the custom transform function when using it's native bun option.
12574
+ experimentalBun: false,
12575
+ // List of extensions to transform with esbuild
12576
+ extensions: [
12577
+ ".ts",
12578
+ ".cts",
12579
+ ".mts",
12580
+ ".tsx",
12581
+ ".js",
12582
+ ".cjs",
12583
+ ".mjs",
12584
+ ".jsx"
12585
+ ],
12586
+ transform(opts) {
12587
+ const isEntrypoint = opts.filename === normalPath;
12588
+ return (0, import_esbuild.transformSync)(
12589
+ // Use modified source code for entrypoints
12590
+ isEntrypoint ? code : opts.source,
12591
+ getEsbuildOptions(opts)
12592
+ );
12593
+ }
12594
+ }
12595
+ );
12596
+ try {
12597
+ const res = await jiti(path12);
12598
+ return res.default;
12599
+ } catch (err) {
12600
+ const filePath = (0, import_node_path19.relative)(wxt.config.root, path12);
12601
+ if (err instanceof ReferenceError) {
12602
+ const variableName = err.message.replace(" is not defined", "");
12603
+ throw Error(
12604
+ `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
12605
+ { cause: err }
12606
+ );
12607
+ } else {
12608
+ wxt.logger.error(err);
12609
+ throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
12610
+ }
12611
+ }
12612
+ }
12613
+ function getEsbuildOptions(opts) {
12614
+ const isJsx = opts.filename?.endsWith("x");
12615
+ return {
12616
+ format: "cjs",
12617
+ loader: isJsx ? "tsx" : "ts",
12618
+ ...isJsx ? {
12619
+ // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
12620
+ // grabbing the entrypoint's options.
12621
+ jsxFactory: "h",
12622
+ jsxFragment: "Fragment"
12623
+ } : void 0
12624
+ };
12625
+ }
12626
+
12574
12627
  // src/core/utils/building/internal-build.ts
12575
12628
  var import_picocolors5 = __toESM(require("picocolors"), 1);
12576
12629
  var import_fs_extra14 = __toESM(require("fs-extra"), 1);
@@ -12682,7 +12735,7 @@ function getChunkSortWeight(filename) {
12682
12735
  var import_picocolors4 = __toESM(require("picocolors"), 1);
12683
12736
 
12684
12737
  // package.json
12685
- var version = "0.18.6";
12738
+ var version = "0.18.8";
12686
12739
 
12687
12740
  // src/core/utils/building/internal-build.ts
12688
12741
  var import_fast_glob4 = __toESM(require("fast-glob"), 1);
@@ -13767,6 +13820,7 @@ function createFileReloader(server) {
13767
13820
  return async (event, path12) => {
13768
13821
  await wxt.reloadConfig();
13769
13822
  if (path12.startsWith(wxt.config.outBaseDir)) return;
13823
+ if (path12.startsWith(wxt.config.wxtDir)) return;
13770
13824
  changeQueue.push([event, path12]);
13771
13825
  await fileChangedMutex.runExclusive(async () => {
13772
13826
  if (server.currentOutput == null) return;