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.
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";
@@ -11035,6 +11035,9 @@ ${noImports}`;
11035
11035
  }
11036
11036
 
11037
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");
11038
11041
  async function createViteBuilder(wxtConfig, hooks, server) {
11039
11042
  const vite = await import("vite");
11040
11043
  const getBaseConfig = async () => {
@@ -11182,21 +11185,64 @@ async function createViteBuilder(wxtConfig, hooks, server) {
11182
11185
  return {
11183
11186
  name: "Vite",
11184
11187
  version: vite.version,
11185
- async importEntrypoint(url) {
11186
- const baseConfig = await getBaseConfig();
11187
- const envConfig = {
11188
- plugins: [
11189
- webextensionPolyfillMock(wxtConfig),
11190
- removeEntrypointMainFunction(wxtConfig, url)
11191
- ]
11192
- };
11193
- const config = vite.mergeConfig(baseConfig, envConfig);
11194
- const server2 = await vite.createServer(config);
11195
- await server2.listen();
11196
- const runtime = await vite.createViteRuntime(server2, { hmr: false });
11197
- const module2 = await runtime.executeUrl(url);
11198
- await server2.close();
11199
- 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
+ }
11200
11246
  },
11201
11247
  async build(group) {
11202
11248
  let entryConfig;
@@ -11462,107 +11508,15 @@ function findEffectedSteps(changedFile, currentOutput) {
11462
11508
 
11463
11509
  // src/core/utils/building/find-entrypoints.ts
11464
11510
  var import_path4 = require("path");
11465
- var import_fs_extra7 = __toESM(require("fs-extra"), 1);
11511
+ var import_fs_extra6 = __toESM(require("fs-extra"), 1);
11466
11512
  var import_minimatch = require("minimatch");
11467
11513
  var import_linkedom3 = require("linkedom");
11468
11514
  var import_json5 = __toESM(require("json5"), 1);
11469
11515
  var import_fast_glob2 = __toESM(require("fast-glob"), 1);
11470
11516
  var import_picocolors2 = __toESM(require("picocolors"), 1);
11471
-
11472
- // src/core/utils/building/import-entrypoint.ts
11473
- var import_jiti = __toESM(require("jiti"), 1);
11474
- var import_unimport2 = require("unimport");
11475
- var import_fs_extra6 = __toESM(require("fs-extra"), 1);
11476
- var import_node_path13 = require("path");
11477
- var import_esbuild = require("esbuild");
11478
- var import_node_url3 = require("url");
11479
- var import_meta = {};
11480
- async function importEntrypointFile(path12) {
11481
- wxt.logger.debug("Loading file metadata:", path12);
11482
- const normalPath = normalizePath(path12);
11483
- const unimport2 = (0, import_unimport2.createUnimport)({
11484
- ...wxt.config.imports,
11485
- // Only allow specific imports, not all from the project
11486
- dirs: []
11487
- });
11488
- await unimport2.init();
11489
- const text2 = await import_fs_extra6.default.readFile(path12, "utf-8");
11490
- const textNoImports = removeProjectImportStatements(text2);
11491
- const { code } = await unimport2.injectImports(textNoImports);
11492
- wxt.logger.debug(
11493
- ["Text:", text2, "No imports:", textNoImports, "Code:", code].join("\n")
11494
- );
11495
- const jiti = (0, import_jiti.default)(
11496
- typeof __filename !== "undefined" ? __filename : (0, import_node_url3.fileURLToPath)(import_meta.url),
11497
- {
11498
- cache: false,
11499
- debug: wxt.config.debug,
11500
- esmResolve: true,
11501
- alias: {
11502
- "webextension-polyfill": (0, import_node_path13.resolve)(
11503
- wxt.config.wxtModuleDir,
11504
- "dist/virtual/mock-browser.js"
11505
- )
11506
- },
11507
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
11508
- // respect the custom transform function when using it's native bun option.
11509
- experimentalBun: false,
11510
- // List of extensions to transform with esbuild
11511
- extensions: [
11512
- ".ts",
11513
- ".cts",
11514
- ".mts",
11515
- ".tsx",
11516
- ".js",
11517
- ".cjs",
11518
- ".mjs",
11519
- ".jsx"
11520
- ],
11521
- transform(opts) {
11522
- const isEntrypoint = opts.filename === normalPath;
11523
- return (0, import_esbuild.transformSync)(
11524
- // Use modified source code for entrypoints
11525
- isEntrypoint ? code : opts.source,
11526
- getEsbuildOptions(opts)
11527
- );
11528
- }
11529
- }
11530
- );
11531
- try {
11532
- const res = await jiti(path12);
11533
- return res.default;
11534
- } catch (err) {
11535
- const filePath = (0, import_node_path13.relative)(wxt.config.root, path12);
11536
- if (err instanceof ReferenceError) {
11537
- const variableName = err.message.replace(" is not defined", "");
11538
- throw Error(
11539
- `${filePath}: Cannot use imported variable "${variableName}" outside the main function. See https://wxt.dev/guide/go-further/entrypoint-side-effects.html`,
11540
- { cause: err }
11541
- );
11542
- } else {
11543
- wxt.logger.error(err);
11544
- throw Error(`Failed to load entrypoint: ${filePath}`, { cause: err });
11545
- }
11546
- }
11547
- }
11548
- function getEsbuildOptions(opts) {
11549
- const isJsx = opts.filename?.endsWith("x");
11550
- return {
11551
- format: "cjs",
11552
- loader: isJsx ? "tsx" : "ts",
11553
- ...isJsx ? {
11554
- // `h` and `Fragment` are undefined, but that's OK because JSX is never evaluated while
11555
- // grabbing the entrypoint's options.
11556
- jsxFactory: "h",
11557
- jsxFragment: "Fragment"
11558
- } : void 0
11559
- };
11560
- }
11561
-
11562
- // src/core/utils/building/find-entrypoints.ts
11563
11517
  async function findEntrypoints() {
11564
- await import_fs_extra7.default.mkdir(wxt.config.wxtDir, { recursive: true });
11565
- 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"), {});
11566
11520
  const relativePaths = await (0, import_fast_glob2.default)(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
11567
11521
  cwd: wxt.config.entrypointsDir
11568
11522
  });
@@ -11773,7 +11727,7 @@ async function getUnlistedScriptEntrypoint({
11773
11727
  name,
11774
11728
  skipped
11775
11729
  }) {
11776
- const defaultExport = await importEntrypoint(inputPath);
11730
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
11777
11731
  if (defaultExport == null) {
11778
11732
  throw Error(
11779
11733
  `${name}: Default export not found, did you forget to call "export default defineUnlistedScript(...)"?`
@@ -11796,7 +11750,7 @@ async function getBackgroundEntrypoint({
11796
11750
  }) {
11797
11751
  let options = {};
11798
11752
  if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
11799
- const defaultExport = await importEntrypoint(inputPath);
11753
+ const defaultExport = await wxt.builder.importEntrypoint(inputPath);
11800
11754
  if (defaultExport == null) {
11801
11755
  throw Error(
11802
11756
  `${name}: Default export not found, did you forget to call "export default defineBackground(...)"?`
@@ -11822,7 +11776,13 @@ async function getContentScriptEntrypoint({
11822
11776
  name,
11823
11777
  skipped
11824
11778
  }) {
11825
- 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;
11826
11786
  if (options == null) {
11827
11787
  throw Error(
11828
11788
  `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
@@ -11865,7 +11825,7 @@ async function getSidepanelEntrypoint(info) {
11865
11825
  };
11866
11826
  }
11867
11827
  async function getHtmlEntrypointOptions(info, keyMap, queries, parsers) {
11868
- 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");
11869
11829
  const { document } = (0, import_linkedom3.parseHTML)(content);
11870
11830
  const options = {};
11871
11831
  const defaultQuery = (manifestKey) => document.querySelector(`meta[name='manifest.${manifestKey}']`)?.getAttribute("content");
@@ -11925,15 +11885,12 @@ var PATH_GLOB_TO_TYPE_MAP = {
11925
11885
  [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
11926
11886
  };
11927
11887
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
11928
- function importEntrypoint(path12) {
11929
- return wxt.config.experimental.viteRuntime ? wxt.builder.importEntrypoint(path12) : importEntrypointFile(path12);
11930
- }
11931
11888
 
11932
11889
  // src/core/utils/building/generate-wxt-dir.ts
11933
- var import_unimport3 = require("unimport");
11934
- 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);
11935
11892
  var import_path5 = require("path");
11936
- var import_node_path14 = __toESM(require("path"), 1);
11893
+ var import_node_path13 = __toESM(require("path"), 1);
11937
11894
 
11938
11895
  // src/core/utils/i18n.ts
11939
11896
  var predefinedMessages = {
@@ -11974,10 +11931,10 @@ function parseI18nMessages(messagesJson) {
11974
11931
 
11975
11932
  // src/core/utils/building/generate-wxt-dir.ts
11976
11933
  async function generateTypesDir(entrypoints) {
11977
- await import_fs_extra8.default.ensureDir(wxt.config.typesDir);
11934
+ await import_fs_extra7.default.ensureDir(wxt.config.typesDir);
11978
11935
  const references = [];
11979
11936
  if (wxt.config.imports !== false) {
11980
- const unimport2 = (0, import_unimport3.createUnimport)(wxt.config.imports);
11937
+ const unimport2 = (0, import_unimport2.createUnimport)(wxt.config.imports);
11981
11938
  references.push(await writeImportsDeclarationFile(unimport2));
11982
11939
  if (wxt.config.imports.eslintrc.enabled) {
11983
11940
  await writeImportsEslintFile(unimport2, wxt.config.imports);
@@ -12006,7 +11963,7 @@ async function writeImportsEslintFile(unimport2, options) {
12006
11963
  (await unimport2.getImports()).map((i2) => i2.as ?? i2.name).filter(Boolean).sort().forEach((name) => {
12007
11964
  eslintrc.globals[name] = options.eslintrc.globalsPropValue;
12008
11965
  });
12009
- 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 });
12010
11967
  }
12011
11968
  async function writePathsDeclarationFile(entrypoints) {
12012
11969
  const filePath = (0, import_path5.resolve)(wxt.config.typesDir, "paths.d.ts");
@@ -12060,13 +12017,13 @@ declare module "wxt/browser" {
12060
12017
  `;
12061
12018
  let messages;
12062
12019
  if (defaultLocale) {
12063
- const defaultLocalePath = import_node_path14.default.resolve(
12020
+ const defaultLocalePath = import_node_path13.default.resolve(
12064
12021
  wxt.config.publicDir,
12065
12022
  "_locales",
12066
12023
  defaultLocale,
12067
12024
  "messages.json"
12068
12025
  );
12069
- 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"));
12070
12027
  messages = parseI18nMessages(content);
12071
12028
  } else {
12072
12029
  messages = parseI18nMessages({});
@@ -12167,23 +12124,23 @@ ${paths}
12167
12124
 
12168
12125
  // src/core/utils/building/resolve-config.ts
12169
12126
  var import_c12 = require("c12");
12170
- var import_node_path19 = __toESM(require("path"), 1);
12127
+ var import_node_path18 = __toESM(require("path"), 1);
12171
12128
 
12172
12129
  // src/core/utils/cache.ts
12173
- var import_fs_extra9 = __toESM(require("fs-extra"), 1);
12130
+ var import_fs_extra8 = __toESM(require("fs-extra"), 1);
12174
12131
  var import_path6 = require("path");
12175
12132
  function createFsCache(wxtDir) {
12176
12133
  const getPath = (key) => (0, import_path6.resolve)(wxtDir, "cache", encodeURIComponent(key));
12177
12134
  return {
12178
12135
  async set(key, value) {
12179
12136
  const path12 = getPath(key);
12180
- await (0, import_fs_extra9.ensureDir)((0, import_path6.dirname)(path12));
12137
+ await (0, import_fs_extra8.ensureDir)((0, import_path6.dirname)(path12));
12181
12138
  await writeFileIfDifferent(path12, value);
12182
12139
  },
12183
12140
  async get(key) {
12184
12141
  const path12 = getPath(key);
12185
12142
  try {
12186
- return await import_fs_extra9.default.readFile(path12, "utf-8");
12143
+ return await import_fs_extra8.default.readFile(path12, "utf-8");
12187
12144
  } catch {
12188
12145
  return void 0;
12189
12146
  }
@@ -12199,18 +12156,18 @@ var import_node_process13 = require("process");
12199
12156
  init_utils2();
12200
12157
  var import_node_tty4 = require("tty");
12201
12158
  var import_node_util13 = require("util");
12202
- var import_node_path17 = require("path");
12159
+ var import_node_path16 = require("path");
12203
12160
 
12204
12161
  // src/core/utils/building/resolve-config.ts
12205
12162
  var import_defu = __toESM(require("defu"), 1);
12206
12163
 
12207
12164
  // src/core/utils/package.ts
12208
- var import_node_path18 = require("path");
12209
- 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);
12210
12167
  async function getPackageJson() {
12211
- 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");
12212
12169
  try {
12213
- return await import_fs_extra10.default.readJson(file);
12170
+ return await import_fs_extra9.default.readJson(file);
12214
12171
  } catch (err) {
12215
12172
  wxt.logger.debug(
12216
12173
  `Failed to read package.json at: ${file}. Returning undefined.`
@@ -12226,9 +12183,9 @@ function isModuleInstalled(name) {
12226
12183
  }
12227
12184
 
12228
12185
  // src/core/utils/building/resolve-config.ts
12229
- var import_fs_extra11 = __toESM(require("fs-extra"), 1);
12186
+ var import_fs_extra10 = __toESM(require("fs-extra"), 1);
12230
12187
  var import_fast_glob3 = __toESM(require("fast-glob"), 1);
12231
- var import_meta2 = {};
12188
+ var import_meta = {};
12232
12189
  async function resolveConfig(inlineConfig, command) {
12233
12190
  let userConfig = {};
12234
12191
  let userConfigMetadata;
@@ -12253,28 +12210,28 @@ async function resolveConfig(inlineConfig, command) {
12253
12210
  const manifestVersion = mergedConfig.manifestVersion ?? (browser === "firefox" || browser === "safari" ? 2 : 3);
12254
12211
  const mode = mergedConfig.mode ?? COMMAND_MODES[command];
12255
12212
  const env2 = { browser, command, manifestVersion, mode };
12256
- const root = import_node_path19.default.resolve(
12213
+ const root = import_node_path18.default.resolve(
12257
12214
  inlineConfig.root ?? userConfig.root ?? process.cwd()
12258
12215
  );
12259
- const wxtDir = import_node_path19.default.resolve(root, ".wxt");
12216
+ const wxtDir = import_node_path18.default.resolve(root, ".wxt");
12260
12217
  const wxtModuleDir = await resolveWxtModuleDir();
12261
- const srcDir = import_node_path19.default.resolve(root, mergedConfig.srcDir ?? root);
12262
- 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(
12263
12220
  srcDir,
12264
12221
  mergedConfig.entrypointsDir ?? "entrypoints"
12265
12222
  );
12266
- const modulesDir = import_node_path19.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
12223
+ const modulesDir = import_node_path18.default.resolve(srcDir, mergedConfig.modulesDir ?? "modules");
12267
12224
  if (await isDirMissing(entrypointsDir)) {
12268
12225
  logMissingDir(logger, "Entrypoints", entrypointsDir);
12269
12226
  }
12270
12227
  const filterEntrypoints = !!mergedConfig.filterEntrypoints?.length ? new Set(mergedConfig.filterEntrypoints) : void 0;
12271
- const publicDir = import_node_path19.default.resolve(srcDir, mergedConfig.publicDir ?? "public");
12228
+ const publicDir = import_node_path18.default.resolve(srcDir, mergedConfig.publicDir ?? "public");
12272
12229
  if (await isDirMissing(publicDir)) {
12273
12230
  logMissingDir(logger, "Public", publicDir);
12274
12231
  }
12275
- const typesDir = import_node_path19.default.resolve(wxtDir, "types");
12276
- const outBaseDir = import_node_path19.default.resolve(root, mergedConfig.outDir ?? ".output");
12277
- 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}`);
12278
12235
  const reloadCommand = mergedConfig.dev?.reloadCommand ?? "Alt+R";
12279
12236
  const runnerConfig = await (0, import_c12.loadConfig)({
12280
12237
  name: "web-ext",
@@ -12291,7 +12248,7 @@ async function resolveConfig(inlineConfig, command) {
12291
12248
  "~": srcDir,
12292
12249
  "@@": root,
12293
12250
  "~~": root
12294
- }).map(([key, value]) => [key, import_node_path19.default.resolve(root, value)])
12251
+ }).map(([key, value]) => [key, import_node_path18.default.resolve(root, value)])
12295
12252
  );
12296
12253
  let devServerConfig;
12297
12254
  if (command === "serve") {
@@ -12343,7 +12300,7 @@ async function resolveConfig(inlineConfig, command) {
12343
12300
  alias,
12344
12301
  experimental: (0, import_defu.default)(mergedConfig.experimental, {
12345
12302
  includeBrowserPolyfill: true,
12346
- viteRuntime: false
12303
+ entrypointImporter: "jiti"
12347
12304
  }),
12348
12305
  dev: {
12349
12306
  server: devServerConfig,
@@ -12381,7 +12338,7 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
12381
12338
  };
12382
12339
  }
12383
12340
  function resolveZipConfig(root, mergedConfig) {
12384
- const downloadedPackagesDir = import_node_path19.default.resolve(root, ".wxt/local_modules");
12341
+ const downloadedPackagesDir = import_node_path18.default.resolve(root, ".wxt/local_modules");
12385
12342
  return {
12386
12343
  name: void 0,
12387
12344
  sourcesTemplate: "{{name}}-{{version}}-sources.zip",
@@ -12407,12 +12364,12 @@ function resolveZipConfig(root, mergedConfig) {
12407
12364
  };
12408
12365
  }
12409
12366
  function resolveAnalysisConfig(root, mergedConfig) {
12410
- const analysisOutputFile = import_node_path19.default.resolve(
12367
+ const analysisOutputFile = import_node_path18.default.resolve(
12411
12368
  root,
12412
12369
  mergedConfig.analysis?.outputFile ?? "stats.html"
12413
12370
  );
12414
- const analysisOutputDir = import_node_path19.default.dirname(analysisOutputFile);
12415
- 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;
12416
12373
  return {
12417
12374
  enabled: mergedConfig.analysis?.enabled ?? false,
12418
12375
  open: mergedConfig.analysis?.open ?? false,
@@ -12451,7 +12408,7 @@ async function getUnimportOptions(wxtDir, logger, config) {
12451
12408
  dirs: ["components", "composables", "hooks", "utils"],
12452
12409
  eslintrc: {
12453
12410
  enabled,
12454
- filePath: import_node_path19.default.resolve(wxtDir, "eslintrc-auto-import.json"),
12411
+ filePath: import_node_path18.default.resolve(wxtDir, "eslintrc-auto-import.json"),
12455
12412
  globalsPropValue: true
12456
12413
  }
12457
12414
  };
@@ -12461,16 +12418,16 @@ async function getUnimportOptions(wxtDir, logger, config) {
12461
12418
  );
12462
12419
  }
12463
12420
  async function resolveWxtModuleDir() {
12464
- const requireResolve = require?.resolve ?? (await import("module")).default.createRequire(import_meta2.url).resolve;
12465
- 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"), "../..");
12466
12423
  }
12467
12424
  async function isDirMissing(dir) {
12468
- return !await import_fs_extra11.default.exists(dir);
12425
+ return !await import_fs_extra10.default.exists(dir);
12469
12426
  }
12470
12427
  function logMissingDir(logger, name, expected) {
12471
12428
  logger.warn(
12472
12429
  `${name} directory not found: ./${normalizePath(
12473
- import_node_path19.default.relative(process.cwd(), expected)
12430
+ import_node_path18.default.relative(process.cwd(), expected)
12474
12431
  )}`
12475
12432
  );
12476
12433
  }
@@ -12514,7 +12471,7 @@ async function resolveWxtModules(modulesDir, modules = []) {
12514
12471
  }).catch(() => []);
12515
12472
  const localModules = await Promise.all(
12516
12473
  localModulePaths.map(async (file) => {
12517
- const absolutePath = normalizePath(import_node_path19.default.resolve(modulesDir, file));
12474
+ const absolutePath = normalizePath(import_node_path18.default.resolve(modulesDir, file));
12518
12475
  const { config } = await (0, import_c12.loadConfig)({
12519
12476
  configFile: absolutePath,
12520
12477
  globalRc: false,
@@ -12577,6 +12534,96 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
12577
12534
  "content-script-style": "individual"
12578
12535
  };
12579
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
+
12580
12627
  // src/core/utils/building/internal-build.ts
12581
12628
  var import_picocolors5 = __toESM(require("picocolors"), 1);
12582
12629
  var import_fs_extra14 = __toESM(require("fs-extra"), 1);
@@ -12688,7 +12735,7 @@ function getChunkSortWeight(filename) {
12688
12735
  var import_picocolors4 = __toESM(require("picocolors"), 1);
12689
12736
 
12690
12737
  // package.json
12691
- var version = "0.18.7";
12738
+ var version = "0.18.8";
12692
12739
 
12693
12740
  // src/core/utils/building/internal-build.ts
12694
12741
  var import_fast_glob4 = __toESM(require("fast-glob"), 1);
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-D6lH9OkP.cjs';
2
- export { x as BackgroundDefinition, n as BackgroundEntrypoint, i as BackgroundEntrypointOptions, j as BaseContentScriptEntrypointOptions, m as BaseEntrypoint, h as BaseEntrypointOptions, e as BuildStepOutput, J as ConfigEnv, w as ContentScriptDefinition, C as ContentScriptEntrypoint, a5 as Dependency, r as Entrypoint, s as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, _ as ExtensionRunner, Z as FsCache, G as GenericEntrypoint, X as HookResult, u as IsolatedWorldContentScriptDefinition, k as IsolatedWorldContentScriptEntrypointOptions, L as Logger, v as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, t as OnContentScriptStopped, p as OptionsEntrypoint, l as OptionsEntrypointOptions, d as OutputAsset, c as OutputChunk, O as OutputFile, A as PerBrowserMap, z as PerBrowserOption, o as PopupEntrypoint, P as PopupEntrypointOptions, f as ReloadContentScriptPayload, R as ResolvedConfig, a1 as ResolvedEslintrc, D as ResolvedPerBrowserOptions, aa as ResolvedPublicFile, V as ServerInfo, q as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, g as TargetManifestVersion, y as UnlistedScriptDefinition, F as UserManifest, H as UserManifestFn, Y as Wxt, N as WxtBuilder, Q as WxtBuilderServer, K as WxtCommand, b as WxtHooks, a8 as WxtModule, a6 as WxtModuleOptions, a7 as WxtModuleSetup, a9 as WxtModuleWithMetadata, a4 as WxtPackageManager, ab as WxtPlugin, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-D6lH9OkP.cjs';
1
+ import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-B0efqfEK.cjs';
2
+ export { x as BackgroundDefinition, n as BackgroundEntrypoint, i as BackgroundEntrypointOptions, j as BaseContentScriptEntrypointOptions, m as BaseEntrypoint, h as BaseEntrypointOptions, e as BuildStepOutput, J as ConfigEnv, w as ContentScriptDefinition, C as ContentScriptEntrypoint, a5 as Dependency, r as Entrypoint, s as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, _ as ExtensionRunner, Z as FsCache, G as GenericEntrypoint, X as HookResult, u as IsolatedWorldContentScriptDefinition, k as IsolatedWorldContentScriptEntrypointOptions, L as Logger, v as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, t as OnContentScriptStopped, p as OptionsEntrypoint, l as OptionsEntrypointOptions, d as OutputAsset, c as OutputChunk, O as OutputFile, A as PerBrowserMap, z as PerBrowserOption, o as PopupEntrypoint, P as PopupEntrypointOptions, f as ReloadContentScriptPayload, R as ResolvedConfig, a1 as ResolvedEslintrc, D as ResolvedPerBrowserOptions, aa as ResolvedPublicFile, V as ServerInfo, q as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, g as TargetManifestVersion, y as UnlistedScriptDefinition, F as UserManifest, H as UserManifestFn, Y as Wxt, N as WxtBuilder, Q as WxtBuilderServer, K as WxtCommand, b as WxtHooks, a8 as WxtModule, a6 as WxtModuleOptions, a7 as WxtModuleSetup, a9 as WxtModuleWithMetadata, a4 as WxtPackageManager, ab as WxtPlugin, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-B0efqfEK.cjs';
3
3
  import 'vite';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
@@ -65,6 +65,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
65
65
  */
66
66
  declare function zip(config?: InlineConfig): Promise<string[]>;
67
67
 
68
- var version = "0.18.7";
68
+ var version = "0.18.8";
69
69
 
70
70
  export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-D6lH9OkP.js';
2
- export { x as BackgroundDefinition, n as BackgroundEntrypoint, i as BackgroundEntrypointOptions, j as BaseContentScriptEntrypointOptions, m as BaseEntrypoint, h as BaseEntrypointOptions, e as BuildStepOutput, J as ConfigEnv, w as ContentScriptDefinition, C as ContentScriptEntrypoint, a5 as Dependency, r as Entrypoint, s as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, _ as ExtensionRunner, Z as FsCache, G as GenericEntrypoint, X as HookResult, u as IsolatedWorldContentScriptDefinition, k as IsolatedWorldContentScriptEntrypointOptions, L as Logger, v as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, t as OnContentScriptStopped, p as OptionsEntrypoint, l as OptionsEntrypointOptions, d as OutputAsset, c as OutputChunk, O as OutputFile, A as PerBrowserMap, z as PerBrowserOption, o as PopupEntrypoint, P as PopupEntrypointOptions, f as ReloadContentScriptPayload, R as ResolvedConfig, a1 as ResolvedEslintrc, D as ResolvedPerBrowserOptions, aa as ResolvedPublicFile, V as ServerInfo, q as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, g as TargetManifestVersion, y as UnlistedScriptDefinition, F as UserManifest, H as UserManifestFn, Y as Wxt, N as WxtBuilder, Q as WxtBuilderServer, K as WxtCommand, b as WxtHooks, a8 as WxtModule, a6 as WxtModuleOptions, a7 as WxtModuleSetup, a9 as WxtModuleWithMetadata, a4 as WxtPackageManager, ab as WxtPlugin, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-D6lH9OkP.js';
1
+ import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-B0efqfEK.js';
2
+ export { x as BackgroundDefinition, n as BackgroundEntrypoint, i as BackgroundEntrypointOptions, j as BaseContentScriptEntrypointOptions, m as BaseEntrypoint, h as BaseEntrypointOptions, e as BuildStepOutput, J as ConfigEnv, w as ContentScriptDefinition, C as ContentScriptEntrypoint, a5 as Dependency, r as Entrypoint, s as EntrypointGroup, $ as EslintGlobalsPropValue, a0 as Eslintrc, _ as ExtensionRunner, Z as FsCache, G as GenericEntrypoint, X as HookResult, u as IsolatedWorldContentScriptDefinition, k as IsolatedWorldContentScriptEntrypointOptions, L as Logger, v as MainWorldContentScriptDefinition, M as MainWorldContentScriptEntrypointOptions, t as OnContentScriptStopped, p as OptionsEntrypoint, l as OptionsEntrypointOptions, d as OutputAsset, c as OutputChunk, O as OutputFile, A as PerBrowserMap, z as PerBrowserOption, o as PopupEntrypoint, P as PopupEntrypointOptions, f as ReloadContentScriptPayload, R as ResolvedConfig, a1 as ResolvedEslintrc, D as ResolvedPerBrowserOptions, aa as ResolvedPublicFile, V as ServerInfo, q as SidepanelEntrypoint, S as SidepanelEntrypointOptions, T as TargetBrowser, g as TargetManifestVersion, y as UnlistedScriptDefinition, F as UserManifest, H as UserManifestFn, Y as Wxt, N as WxtBuilder, Q as WxtBuilderServer, K as WxtCommand, b as WxtHooks, a8 as WxtModule, a6 as WxtModuleOptions, a7 as WxtModuleSetup, a9 as WxtModuleWithMetadata, a4 as WxtPackageManager, ab as WxtPlugin, a3 as WxtResolvedUnimportOptions, a2 as WxtUnimportOptions, a as WxtViteConfig } from './index-B0efqfEK.js';
3
3
  import 'vite';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
@@ -65,6 +65,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
65
65
  */
66
66
  declare function zip(config?: InlineConfig): Promise<string[]>;
67
67
 
68
- var version = "0.18.7";
68
+ var version = "0.18.8";
69
69
 
70
70
  export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };