wxt 0.11.1 → 0.12.0

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
@@ -577,16 +577,16 @@ function npmRunPath(options = {}) {
577
577
  execPath = import_node_process.default.execPath
578
578
  } = options;
579
579
  let previous;
580
- const cwdString = cwd instanceof URL ? import_node_url.default.fileURLToPath(cwd) : cwd;
581
- let cwdPath = import_node_path10.default.resolve(cwdString);
580
+ const cwdString = cwd instanceof URL ? import_node_url2.default.fileURLToPath(cwd) : cwd;
581
+ let cwdPath = import_node_path11.default.resolve(cwdString);
582
582
  const result = [];
583
583
  while (previous !== cwdPath) {
584
- result.push(import_node_path10.default.join(cwdPath, "node_modules/.bin"));
584
+ result.push(import_node_path11.default.join(cwdPath, "node_modules/.bin"));
585
585
  previous = cwdPath;
586
- cwdPath = import_node_path10.default.resolve(cwdPath, "..");
586
+ cwdPath = import_node_path11.default.resolve(cwdPath, "..");
587
587
  }
588
- result.push(import_node_path10.default.resolve(cwdString, execPath, ".."));
589
- return [...result, path_].join(import_node_path10.default.delimiter);
588
+ result.push(import_node_path11.default.resolve(cwdString, execPath, ".."));
589
+ return [...result, path_].join(import_node_path11.default.delimiter);
590
590
  }
591
591
  function npmRunPathEnv({ env = import_node_process.default.env, ...options } = {}) {
592
592
  env = { ...env };
@@ -595,13 +595,13 @@ function npmRunPathEnv({ env = import_node_process.default.env, ...options } = {
595
595
  env[path10] = npmRunPath(options);
596
596
  return env;
597
597
  }
598
- var import_node_process, import_node_path10, import_node_url;
598
+ var import_node_process, import_node_path11, import_node_url2;
599
599
  var init_npm_run_path = __esm({
600
600
  "node_modules/.pnpm/npm-run-path@5.1.0/node_modules/npm-run-path/index.js"() {
601
601
  "use strict";
602
602
  import_node_process = __toESM(require("process"), 1);
603
- import_node_path10 = __toESM(require("path"), 1);
604
- import_node_url = __toESM(require("url"), 1);
603
+ import_node_path11 = __toESM(require("path"), 1);
604
+ import_node_url2 = __toESM(require("url"), 1);
605
605
  init_path_key();
606
606
  }
607
607
  });
@@ -2337,12 +2337,12 @@ function execaNode(scriptPath, args, options = {}) {
2337
2337
  }
2338
2338
  );
2339
2339
  }
2340
- var import_node_buffer2, import_node_path11, import_node_child_process3, import_node_process4, import_cross_spawn, DEFAULT_MAX_BUFFER, getEnv, handleArguments, handleOutput, normalizeScriptStdin, normalizeScriptOptions, $;
2340
+ var import_node_buffer2, import_node_path12, import_node_child_process3, import_node_process4, import_cross_spawn, DEFAULT_MAX_BUFFER, getEnv, handleArguments, handleOutput, normalizeScriptStdin, normalizeScriptOptions, $;
2341
2341
  var init_execa = __esm({
2342
2342
  "node_modules/.pnpm/execa@8.0.1/node_modules/execa/index.js"() {
2343
2343
  "use strict";
2344
2344
  import_node_buffer2 = require("buffer");
2345
- import_node_path11 = __toESM(require("path"), 1);
2345
+ import_node_path12 = __toESM(require("path"), 1);
2346
2346
  import_node_child_process3 = __toESM(require("child_process"), 1);
2347
2347
  import_node_process4 = __toESM(require("process"), 1);
2348
2348
  import_cross_spawn = __toESM(require_cross_spawn(), 1);
@@ -2388,7 +2388,7 @@ var init_execa = __esm({
2388
2388
  };
2389
2389
  options.env = getEnv(options);
2390
2390
  options.stdio = normalizeStdio(options);
2391
- if (import_node_process4.default.platform === "win32" && import_node_path11.default.basename(file, ".exe") === "cmd") {
2391
+ if (import_node_process4.default.platform === "win32" && import_node_path12.default.basename(file, ".exe") === "cmd") {
2392
2392
  args.unshift("/q");
2393
2393
  }
2394
2394
  return { file, args, options, parsed };
@@ -2616,51 +2616,47 @@ var VIRTUAL_NOOP_BACKGROUND_MODULE_ID = "virtual:user-background";
2616
2616
 
2617
2617
  // src/core/utils/building/find-entrypoints.ts
2618
2618
  async function findEntrypoints(config) {
2619
- const relativePaths = await (0, import_fast_glob2.default)("**/*", {
2619
+ const relativePaths = await (0, import_fast_glob2.default)(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
2620
2620
  cwd: config.entrypointsDir
2621
2621
  });
2622
2622
  relativePaths.sort();
2623
2623
  const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
2624
- let hasBackground = false;
2625
- const possibleEntrypoints = await Promise.all(
2626
- relativePaths.map(async (relativePath) => {
2627
- const path10 = (0, import_path2.resolve)(config.entrypointsDir, relativePath);
2628
- const matchingGlob = pathGlobs.find(
2629
- (glob5) => (0, import_minimatch.minimatch)(relativePath, glob5)
2630
- );
2631
- if (matchingGlob == null) {
2632
- config.logger.warn(
2633
- `${relativePath} does not match any known entrypoint. Known entrypoints:
2634
- ${JSON.stringify(
2635
- PATH_GLOB_TO_TYPE_MAP,
2636
- null,
2637
- 2
2638
- )}`
2639
- );
2640
- return;
2641
- }
2624
+ const entrypointInfos = relativePaths.reduce((results, relativePath) => {
2625
+ const inputPath = (0, import_path2.resolve)(config.entrypointsDir, relativePath);
2626
+ const name = getEntrypointName(config.entrypointsDir, inputPath);
2627
+ const matchingGlob = pathGlobs.find(
2628
+ (glob5) => (0, import_minimatch.minimatch)(relativePath, glob5)
2629
+ );
2630
+ if (matchingGlob) {
2642
2631
  const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
2643
- if (type === "ignored")
2644
- return;
2632
+ results.push({ name, inputPath, type });
2633
+ }
2634
+ return results;
2635
+ }, []);
2636
+ preventNoEntrypoints(config, entrypointInfos);
2637
+ preventDuplicateEntrypointNames(config, entrypointInfos);
2638
+ let hasBackground = false;
2639
+ const entrypoints = await Promise.all(
2640
+ entrypointInfos.map(async (info) => {
2641
+ const { type } = info;
2645
2642
  switch (type) {
2646
2643
  case "popup":
2647
- return await getPopupEntrypoint(config, path10);
2644
+ return await getPopupEntrypoint(config, info);
2648
2645
  case "options":
2649
- return await getOptionsEntrypoint(config, path10);
2646
+ return await getOptionsEntrypoint(config, info);
2650
2647
  case "background":
2651
2648
  hasBackground = true;
2652
- return await getBackgroundEntrypoint(config, path10);
2649
+ return await getBackgroundEntrypoint(config, info);
2653
2650
  case "content-script":
2654
- return await getContentScriptEntrypoint(config, path10);
2651
+ return await getContentScriptEntrypoint(config, info);
2655
2652
  case "unlisted-page":
2656
- return await getUnlistedPageEntrypoint(config, path10);
2653
+ return await getUnlistedPageEntrypoint(config, info);
2657
2654
  case "unlisted-script":
2658
- return await getUnlistedScriptEntrypoint(config, path10);
2655
+ return await getUnlistedScriptEntrypoint(config, info);
2659
2656
  case "content-script-style":
2660
2657
  return {
2658
+ ...info,
2661
2659
  type,
2662
- name: getEntrypointName(config.entrypointsDir, path10),
2663
- inputPath: path10,
2664
2660
  outputDir: (0, import_path2.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
2665
2661
  options: {
2666
2662
  include: void 0,
@@ -2669,9 +2665,8 @@ ${JSON.stringify(
2669
2665
  };
2670
2666
  default:
2671
2667
  return {
2668
+ ...info,
2672
2669
  type,
2673
- name: getEntrypointName(config.entrypointsDir, path10),
2674
- inputPath: path10,
2675
2670
  outputDir: config.outDir,
2676
2671
  options: {
2677
2672
  include: void 0,
@@ -2681,25 +2676,13 @@ ${JSON.stringify(
2681
2676
  }
2682
2677
  })
2683
2678
  );
2684
- const entrypoints = possibleEntrypoints.filter(
2685
- (entry) => !!entry
2686
- );
2687
- const existingNames = {};
2688
- entrypoints.forEach((entrypoint) => {
2689
- const withSameName = existingNames[entrypoint.name];
2690
- if (withSameName) {
2691
- throw Error(
2692
- `Multiple entrypoints with the name "${entrypoint.name}" detected, but only one is allowed: ${[
2693
- (0, import_path2.relative)(config.root, withSameName.inputPath),
2694
- (0, import_path2.relative)(config.root, entrypoint.inputPath)
2695
- ].join(", ")}`
2696
- );
2697
- }
2698
- existingNames[entrypoint.name] = entrypoint;
2699
- });
2700
2679
  if (config.command === "serve" && !hasBackground) {
2701
2680
  entrypoints.push(
2702
- await getBackgroundEntrypoint(config, VIRTUAL_NOOP_BACKGROUND_MODULE_ID)
2681
+ await getBackgroundEntrypoint(config, {
2682
+ inputPath: VIRTUAL_NOOP_BACKGROUND_MODULE_ID,
2683
+ name: "background",
2684
+ type: "background"
2685
+ })
2703
2686
  );
2704
2687
  }
2705
2688
  config.logger.debug("All entrypoints:", entrypoints);
@@ -2722,6 +2705,41 @@ ${JSON.stringify(
2722
2705
  config.logger.debug(`${config.browser} entrypoints:`, targetEntrypoints);
2723
2706
  return targetEntrypoints;
2724
2707
  }
2708
+ function preventDuplicateEntrypointNames(config, files) {
2709
+ const namesToPaths = files.reduce(
2710
+ (map, { name, inputPath }) => {
2711
+ map[name] ??= [];
2712
+ map[name].push(inputPath);
2713
+ return map;
2714
+ },
2715
+ {}
2716
+ );
2717
+ const errorLines = Object.entries(namesToPaths).reduce(
2718
+ (lines, [name, absolutePaths]) => {
2719
+ if (absolutePaths.length > 1) {
2720
+ lines.push(`- ${name}`);
2721
+ absolutePaths.forEach((absolutePath) => {
2722
+ lines.push(` - ${(0, import_path2.relative)(config.root, absolutePath)}`);
2723
+ });
2724
+ }
2725
+ return lines;
2726
+ },
2727
+ []
2728
+ );
2729
+ if (errorLines.length > 0) {
2730
+ const errorContent = errorLines.join("\n");
2731
+ throw Error(
2732
+ `Multiple entrypoints with the same name detected, only one entrypoint for each name is allowed.
2733
+
2734
+ ${errorContent}`
2735
+ );
2736
+ }
2737
+ }
2738
+ function preventNoEntrypoints(config, files) {
2739
+ if (files.length === 0) {
2740
+ throw Error(`No entrypoints found in ${config.entrypointsDir}`);
2741
+ }
2742
+ }
2725
2743
  function getHtmlBaseOptions(document) {
2726
2744
  const options = {};
2727
2745
  const includeContent = document.querySelector("meta[name='manifest.include']")?.getAttribute("content");
@@ -2734,8 +2752,8 @@ function getHtmlBaseOptions(document) {
2734
2752
  }
2735
2753
  return options;
2736
2754
  }
2737
- async function getPopupEntrypoint(config, path10) {
2738
- const content = await import_fs_extra3.default.readFile(path10, "utf-8");
2755
+ async function getPopupEntrypoint(config, { inputPath, name }) {
2756
+ const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
2739
2757
  const { document } = (0, import_linkedom.parseHTML)(content);
2740
2758
  const options = getHtmlBaseOptions(document);
2741
2759
  const title = document.querySelector("title");
@@ -2764,12 +2782,12 @@ async function getPopupEntrypoint(config, path10) {
2764
2782
  type: "popup",
2765
2783
  name: "popup",
2766
2784
  options,
2767
- inputPath: path10,
2785
+ inputPath,
2768
2786
  outputDir: config.outDir
2769
2787
  };
2770
2788
  }
2771
- async function getOptionsEntrypoint(config, path10) {
2772
- const content = await import_fs_extra3.default.readFile(path10, "utf-8");
2789
+ async function getOptionsEntrypoint(config, { inputPath, name }) {
2790
+ const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
2773
2791
  const { document } = (0, import_linkedom.parseHTML)(content);
2774
2792
  const options = getHtmlBaseOptions(document);
2775
2793
  const openInTabContent = document.querySelector("meta[name='manifest.open_in_tab']")?.getAttribute("content");
@@ -2788,25 +2806,24 @@ async function getOptionsEntrypoint(config, path10) {
2788
2806
  type: "options",
2789
2807
  name: "options",
2790
2808
  options,
2791
- inputPath: path10,
2809
+ inputPath,
2792
2810
  outputDir: config.outDir
2793
2811
  };
2794
2812
  }
2795
- async function getUnlistedPageEntrypoint(config, path10) {
2796
- const content = await import_fs_extra3.default.readFile(path10, "utf-8");
2813
+ async function getUnlistedPageEntrypoint(config, { inputPath, name }) {
2814
+ const content = await import_fs_extra3.default.readFile(inputPath, "utf-8");
2797
2815
  const { document } = (0, import_linkedom.parseHTML)(content);
2798
2816
  return {
2799
2817
  type: "unlisted-page",
2800
- name: getEntrypointName(config.entrypointsDir, path10),
2801
- inputPath: path10,
2818
+ name: getEntrypointName(config.entrypointsDir, inputPath),
2819
+ inputPath,
2802
2820
  outputDir: config.outDir,
2803
2821
  options: getHtmlBaseOptions(document)
2804
2822
  };
2805
2823
  }
2806
- async function getUnlistedScriptEntrypoint(config, path10) {
2807
- const name = getEntrypointName(config.entrypointsDir, path10);
2824
+ async function getUnlistedScriptEntrypoint(config, { inputPath, name }) {
2808
2825
  const defaultExport = await importEntrypointFile(
2809
- path10,
2826
+ inputPath,
2810
2827
  config
2811
2828
  );
2812
2829
  if (defaultExport == null) {
@@ -2819,17 +2836,16 @@ async function getUnlistedScriptEntrypoint(config, path10) {
2819
2836
  return {
2820
2837
  type: "unlisted-script",
2821
2838
  name,
2822
- inputPath: path10,
2839
+ inputPath,
2823
2840
  outputDir: config.outDir,
2824
2841
  options
2825
2842
  };
2826
2843
  }
2827
- async function getBackgroundEntrypoint(config, path10) {
2828
- const name = "background";
2844
+ async function getBackgroundEntrypoint(config, { inputPath, name }) {
2829
2845
  let options = {};
2830
- if (path10 !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
2846
+ if (inputPath !== VIRTUAL_NOOP_BACKGROUND_MODULE_ID) {
2831
2847
  const defaultExport = await importEntrypointFile(
2832
- path10,
2848
+ inputPath,
2833
2849
  config
2834
2850
  );
2835
2851
  if (defaultExport == null) {
@@ -2843,7 +2859,7 @@ async function getBackgroundEntrypoint(config, path10) {
2843
2859
  return {
2844
2860
  type: "background",
2845
2861
  name,
2846
- inputPath: path10,
2862
+ inputPath,
2847
2863
  outputDir: config.outDir,
2848
2864
  options: {
2849
2865
  ...options,
@@ -2852,9 +2868,8 @@ async function getBackgroundEntrypoint(config, path10) {
2852
2868
  }
2853
2869
  };
2854
2870
  }
2855
- async function getContentScriptEntrypoint(config, path10) {
2856
- const name = getEntrypointName(config.entrypointsDir, path10);
2857
- const { main: _, ...options } = await importEntrypointFile(path10, config);
2871
+ async function getContentScriptEntrypoint(config, { inputPath, name }) {
2872
+ const { main: _, ...options } = await importEntrypointFile(inputPath, config);
2858
2873
  if (options == null) {
2859
2874
  throw Error(
2860
2875
  `${name}: Default export not found, did you forget to call "export default defineContentScript(...)"?`
@@ -2863,7 +2878,7 @@ async function getContentScriptEntrypoint(config, path10) {
2863
2878
  return {
2864
2879
  type: "content-script",
2865
2880
  name,
2866
- inputPath: path10,
2881
+ inputPath,
2867
2882
  outputDir: (0, import_path2.resolve)(config.outDir, CONTENT_SCRIPT_OUT_DIR),
2868
2883
  options
2869
2884
  };
@@ -2902,12 +2917,10 @@ var PATH_GLOB_TO_TYPE_MAP = {
2902
2917
  "options/index.html": "options",
2903
2918
  "*.html": "unlisted-page",
2904
2919
  "*/index.html": "unlisted-page",
2905
- "*.[jt]s": "unlisted-script",
2906
- "*/index.ts": "unlisted-script",
2920
+ "*.[jt]s?(x)": "unlisted-script",
2921
+ "*/index.[jt]s?(x)": "unlisted-script",
2907
2922
  [`*.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
2908
- [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style",
2909
- // Don't warn about any files in subdirectories, like CSS or JS entrypoints for HTML files or tests
2910
- "*/**": "ignored"
2923
+ [`*/index.${CSS_EXTENSIONS_PATTERN}`]: "unlisted-style"
2911
2924
  };
2912
2925
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
2913
2926
 
@@ -3719,7 +3732,8 @@ async function craeteViteBuilder(inlineConfig, userConfig, wxtConfig) {
3719
3732
  devHtmlPrerender(wxtConfig),
3720
3733
  unimport(wxtConfig),
3721
3734
  virtualEntrypoint("background", wxtConfig),
3722
- virtualEntrypoint("content-script", wxtConfig),
3735
+ virtualEntrypoint("content-script-isolated-world", wxtConfig),
3736
+ virtualEntrypoint("content-script-main-world", wxtConfig),
3723
3737
  virtualEntrypoint("unlisted-script", wxtConfig),
3724
3738
  devServerGlobals(wxtConfig),
3725
3739
  tsconfigPaths(wxtConfig),
@@ -3733,12 +3747,17 @@ async function craeteViteBuilder(inlineConfig, userConfig, wxtConfig) {
3733
3747
  return config;
3734
3748
  };
3735
3749
  const getLibModeConfig = (entrypoint) => {
3736
- const isVirtual = [
3737
- "background",
3738
- "content-script",
3739
- "unlisted-script"
3740
- ].includes(entrypoint.type);
3741
- const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
3750
+ let virtualEntrypointType;
3751
+ switch (entrypoint.type) {
3752
+ case "background":
3753
+ case "unlisted-script":
3754
+ virtualEntrypointType = entrypoint.type;
3755
+ break;
3756
+ case "content-script":
3757
+ virtualEntrypointType = entrypoint.options.world === "MAIN" ? "content-script-main-world" : "content-script-isolated-world";
3758
+ break;
3759
+ }
3760
+ const entry = virtualEntrypointType ? `virtual:wxt-${virtualEntrypointType}?${entrypoint.inputPath}` : entrypoint.inputPath;
3742
3761
  const plugins = [
3743
3762
  entrypointGroupGlobals(entrypoint)
3744
3763
  ];
@@ -3899,7 +3918,10 @@ async function getInternalConfig(inlineConfig, command, server) {
3899
3918
  const { config: loadedConfig, ...metadata } = await (0, import_c12.loadConfig)({
3900
3919
  name: "wxt",
3901
3920
  cwd: inlineConfig.root ?? process.cwd(),
3902
- rcFile: false
3921
+ rcFile: false,
3922
+ jitiOptions: {
3923
+ esmResolve: true
3924
+ }
3903
3925
  });
3904
3926
  userConfig = loadedConfig ?? {};
3905
3927
  userConfigMetadata = metadata;
@@ -4108,7 +4130,7 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
4108
4130
  var import_jiti = __toESM(require("jiti"), 1);
4109
4131
  var import_unimport5 = require("unimport");
4110
4132
  var import_fs_extra8 = __toESM(require("fs-extra"), 1);
4111
- var import_path7 = require("path");
4133
+ var import_node_path8 = require("path");
4112
4134
 
4113
4135
  // src/core/utils/strings.ts
4114
4136
  function kebabCaseAlphanumeric(str) {
@@ -4122,14 +4144,15 @@ function removeImportStatements(text) {
4122
4144
  }
4123
4145
  function removeProjectImportStatements(text) {
4124
4146
  const noImports = removeImportStatements(text);
4125
- return `import { defineContentScript, defineBackground } from 'wxt/client';
4126
- import { defineUnlistedScript } from 'wxt/sandbox';
4147
+ return `import { defineUnlistedScript, defineContentScript, defineBackground } from 'wxt/sandbox';
4127
4148
 
4128
4149
  ${noImports}`;
4129
4150
  }
4130
4151
 
4131
4152
  // src/core/utils/building/import-entrypoint.ts
4132
4153
  var import_esbuild = require("esbuild");
4154
+ var import_node_url = require("url");
4155
+ var import_meta = {};
4133
4156
  async function importEntrypointFile(path10, config) {
4134
4157
  config.logger.debug("Loading file metadata:", path10);
4135
4158
  const normalPath = normalizePath(path10);
@@ -4145,30 +4168,42 @@ async function importEntrypointFile(path10, config) {
4145
4168
  config.logger.debug(
4146
4169
  ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
4147
4170
  );
4148
- const jiti = (0, import_jiti.default)(__filename, {
4149
- cache: false,
4150
- debug: config.debug,
4151
- esmResolve: true,
4152
- alias: {
4153
- "webextension-polyfill": (0, import_path7.resolve)(
4154
- config.root,
4155
- "node_modules/wxt/dist/virtual/mock-browser.js"
4156
- )
4157
- },
4158
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
4159
- // respect the custom transform function when using it's native bun option.
4160
- experimentalBun: false,
4161
- // List of extensions to transform with esbuild
4162
- extensions: [".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"],
4163
- transform(opts) {
4164
- const isEntrypoint = opts.filename === normalPath;
4165
- return (0, import_esbuild.transformSync)(
4166
- // Use modified source code for entrypoints
4167
- isEntrypoint ? code : opts.source,
4168
- getEsbuildOptions(opts)
4169
- );
4171
+ const jiti = (0, import_jiti.default)(
4172
+ typeof __filename !== "undefined" ? __filename : (0, import_node_url.fileURLToPath)(import_meta.url),
4173
+ {
4174
+ cache: false,
4175
+ debug: config.debug,
4176
+ esmResolve: true,
4177
+ alias: {
4178
+ "webextension-polyfill": (0, import_node_path8.resolve)(
4179
+ config.root,
4180
+ "node_modules/wxt/dist/virtual/mock-browser.js"
4181
+ )
4182
+ },
4183
+ // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
4184
+ // respect the custom transform function when using it's native bun option.
4185
+ experimentalBun: false,
4186
+ // List of extensions to transform with esbuild
4187
+ extensions: [
4188
+ ".ts",
4189
+ ".cts",
4190
+ ".mts",
4191
+ ".tsx",
4192
+ ".js",
4193
+ ".cjs",
4194
+ ".mjs",
4195
+ ".jsx"
4196
+ ],
4197
+ transform(opts) {
4198
+ const isEntrypoint = opts.filename === normalPath;
4199
+ return (0, import_esbuild.transformSync)(
4200
+ // Use modified source code for entrypoints
4201
+ isEntrypoint ? code : opts.source,
4202
+ getEsbuildOptions(opts)
4203
+ );
4204
+ }
4170
4205
  }
4171
- });
4206
+ );
4172
4207
  try {
4173
4208
  const res = await jiti(path10);
4174
4209
  return res.default;
@@ -4191,10 +4226,10 @@ var import_picocolors4 = __toESM(require("picocolors"), 1);
4191
4226
  var import_fs_extra12 = __toESM(require("fs-extra"), 1);
4192
4227
 
4193
4228
  // src/core/utils/log/printBuildSummary.ts
4194
- var import_path8 = require("path");
4229
+ var import_path7 = require("path");
4195
4230
 
4196
4231
  // src/core/utils/log/printFileList.ts
4197
- var import_node_path8 = __toESM(require("path"), 1);
4232
+ var import_node_path9 = __toESM(require("path"), 1);
4198
4233
  var import_picocolors2 = __toESM(require("picocolors"), 1);
4199
4234
  var import_fs_extra9 = __toESM(require("fs-extra"), 1);
4200
4235
  var import_filesize = require("filesize");
@@ -4232,8 +4267,8 @@ async function printFileList(log, header, baseDir, files) {
4232
4267
  const fileRows = await Promise.all(
4233
4268
  files.map(async (file, i) => {
4234
4269
  const parts = [
4235
- import_node_path8.default.relative(process.cwd(), baseDir) + import_node_path8.default.sep,
4236
- import_node_path8.default.relative(baseDir, file)
4270
+ import_node_path9.default.relative(process.cwd(), baseDir) + import_node_path9.default.sep,
4271
+ import_node_path9.default.relative(baseDir, file)
4237
4272
  ];
4238
4273
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
4239
4274
  const color = getChunkColor(file);
@@ -4278,7 +4313,7 @@ async function printBuildSummary(log, header, output, config) {
4278
4313
  return diff;
4279
4314
  return l.fileName.localeCompare(r.fileName);
4280
4315
  });
4281
- const files = chunks.map((chunk) => (0, import_path8.resolve)(config.outDir, chunk.fileName));
4316
+ const files = chunks.map((chunk) => (0, import_path7.resolve)(config.outDir, chunk.fileName));
4282
4317
  await printFileList(log, header, config.outDir, files);
4283
4318
  }
4284
4319
  var DEFAULT_SORT_WEIGHT = 100;
@@ -4299,7 +4334,7 @@ function getChunkSortWeight(filename) {
4299
4334
  var import_picocolors3 = __toESM(require("picocolors"), 1);
4300
4335
 
4301
4336
  // package.json
4302
- var version = "0.11.1";
4337
+ var version = "0.12.0";
4303
4338
 
4304
4339
  // src/core/utils/log/printHeader.ts
4305
4340
  var import_consola2 = require("consola");
@@ -4309,7 +4344,7 @@ var import_fast_glob3 = __toESM(require("fast-glob"), 1);
4309
4344
 
4310
4345
  // src/core/utils/manifest.ts
4311
4346
  var import_fs_extra11 = __toESM(require("fs-extra"), 1);
4312
- var import_path9 = require("path");
4347
+ var import_path8 = require("path");
4313
4348
 
4314
4349
  // src/core/utils/content-security-policy.ts
4315
4350
  var ContentSecurityPolicy = class _ContentSecurityPolicy {
@@ -4413,10 +4448,10 @@ function mapWxtOptionsToContentScript(options, config) {
4413
4448
  }
4414
4449
 
4415
4450
  // src/core/utils/package.ts
4416
- var import_node_path9 = require("path");
4451
+ var import_node_path10 = require("path");
4417
4452
  var import_fs_extra10 = __toESM(require("fs-extra"), 1);
4418
4453
  async function getPackageJson(config) {
4419
- const file = (0, import_node_path9.resolve)(config.root, "package.json");
4454
+ const file = (0, import_node_path10.resolve)(config.root, "package.json");
4420
4455
  try {
4421
4456
  return await import_fs_extra10.default.readJson(file);
4422
4457
  } catch (err) {
@@ -4433,7 +4468,7 @@ var import_defu3 = __toESM(require("defu"), 1);
4433
4468
  async function writeManifest(manifest, output, config) {
4434
4469
  const str = config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
4435
4470
  await import_fs_extra11.default.ensureDir(config.outDir);
4436
- await writeFileIfDifferent((0, import_path9.resolve)(config.outDir, "manifest.json"), str);
4471
+ await writeFileIfDifferent((0, import_path8.resolve)(config.outDir, "manifest.json"), str);
4437
4472
  output.publicAssets.unshift({
4438
4473
  type: "asset",
4439
4474
  fileName: "manifest.json"
@@ -4902,7 +4937,7 @@ async function build(config) {
4902
4937
  }
4903
4938
 
4904
4939
  // src/core/clean.ts
4905
- var import_node_path12 = __toESM(require("path"), 1);
4940
+ var import_node_path13 = __toESM(require("path"), 1);
4906
4941
  var import_fast_glob4 = __toESM(require("fast-glob"), 1);
4907
4942
  var import_fs_extra13 = __toESM(require("fs-extra"), 1);
4908
4943
  var import_consola3 = require("consola");
@@ -4917,7 +4952,7 @@ async function clean(root = process.cwd()) {
4917
4952
  ];
4918
4953
  import_consola3.consola.debug("Looking for:", tempDirs.map(import_picocolors5.default.cyan).join(", "));
4919
4954
  const directories = await (0, import_fast_glob4.default)(tempDirs, {
4920
- cwd: import_node_path12.default.resolve(root),
4955
+ cwd: import_node_path13.default.resolve(root),
4921
4956
  absolute: true,
4922
4957
  onlyDirectories: true,
4923
4958
  deep: 2
@@ -4928,11 +4963,11 @@ async function clean(root = process.cwd()) {
4928
4963
  }
4929
4964
  import_consola3.consola.debug(
4930
4965
  "Found:",
4931
- directories.map((dir) => import_picocolors5.default.cyan(import_node_path12.default.relative(root, dir))).join(", ")
4966
+ directories.map((dir) => import_picocolors5.default.cyan(import_node_path13.default.relative(root, dir))).join(", ")
4932
4967
  );
4933
4968
  for (const directory of directories) {
4934
4969
  await import_fs_extra13.default.rm(directory, { force: true, recursive: true });
4935
- import_consola3.consola.debug("Deleted " + import_picocolors5.default.cyan(import_node_path12.default.relative(root, directory)));
4970
+ import_consola3.consola.debug("Deleted " + import_picocolors5.default.cyan(import_node_path13.default.relative(root, directory)));
4936
4971
  }
4937
4972
  }
4938
4973
 
@@ -4947,12 +4982,12 @@ function defineRunnerConfig(config) {
4947
4982
  }
4948
4983
 
4949
4984
  // src/core/runners/wsl.ts
4950
- var import_node_path13 = require("path");
4985
+ var import_node_path14 = require("path");
4951
4986
  function createWslRunner() {
4952
4987
  return {
4953
4988
  async openBrowser(config) {
4954
4989
  config.logger.warn(
4955
- `Cannot open browser when using WSL. Load "${(0, import_node_path13.relative)(
4990
+ `Cannot open browser when using WSL. Load "${(0, import_node_path14.relative)(
4956
4991
  process.cwd(),
4957
4992
  config.outDir
4958
4993
  )}" as an unpacked extension manually`
@@ -5024,12 +5059,12 @@ var WARN_LOG_LEVEL = 40;
5024
5059
  var ERROR_LOG_LEVEL = 50;
5025
5060
 
5026
5061
  // src/core/runners/safari.ts
5027
- var import_node_path14 = require("path");
5062
+ var import_node_path15 = require("path");
5028
5063
  function createSafariRunner() {
5029
5064
  return {
5030
5065
  async openBrowser(config) {
5031
5066
  config.logger.warn(
5032
- `Cannot Safari using web-ext. Load "${(0, import_node_path14.relative)(
5067
+ `Cannot Safari using web-ext. Load "${(0, import_node_path15.relative)(
5033
5068
  process.cwd(),
5034
5069
  config.outDir
5035
5070
  )}" as an unpacked extension manually`
@@ -5041,12 +5076,12 @@ function createSafariRunner() {
5041
5076
  }
5042
5077
 
5043
5078
  // src/core/runners/manual.ts
5044
- var import_node_path15 = require("path");
5079
+ var import_node_path16 = require("path");
5045
5080
  function createManualRunner() {
5046
5081
  return {
5047
5082
  async openBrowser(config) {
5048
5083
  config.logger.info(
5049
- `Load "${(0, import_node_path15.relative)(
5084
+ `Load "${(0, import_node_path16.relative)(
5050
5085
  process.cwd(),
5051
5086
  config.outDir
5052
5087
  )}" as an unpacked extension manually`
@@ -5078,7 +5113,7 @@ async function createExtensionRunner(config) {
5078
5113
  var import_consola4 = require("consola");
5079
5114
  var import_async_mutex = require("async-mutex");
5080
5115
  var import_picocolors6 = __toESM(require("picocolors"), 1);
5081
- var import_node_path16 = require("path");
5116
+ var import_node_path17 = require("path");
5082
5117
  async function createServer(inlineConfig) {
5083
5118
  const port = await getPort();
5084
5119
  const hostname = "localhost";
@@ -5158,11 +5193,11 @@ function createFileReloader(options) {
5158
5193
  if (changes.type === "no-change")
5159
5194
  return;
5160
5195
  config.logger.info(
5161
- `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors6.default.dim((0, import_node_path16.relative)(config.root, file))).join(", ")}`
5196
+ `Changed: ${Array.from(new Set(fileChanges.map((change) => change[1]))).map((file) => import_picocolors6.default.dim((0, import_node_path17.relative)(config.root, file))).join(", ")}`
5162
5197
  );
5163
5198
  const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
5164
5199
  return import_picocolors6.default.cyan(
5165
- (0, import_node_path16.relative)(config.outDir, getEntrypointOutputFile(entry, ""))
5200
+ (0, import_node_path17.relative)(config.outDir, getEntrypointOutputFile(entry, ""))
5166
5201
  );
5167
5202
  }).join(import_picocolors6.default.dim(", "));
5168
5203
  const { output: newOutput } = await rebuild(
@@ -5229,7 +5264,7 @@ var import_prompts = __toESM(require("prompts"), 1);
5229
5264
  var import_consola5 = require("consola");
5230
5265
  var import_giget = require("giget");
5231
5266
  var import_fs_extra14 = __toESM(require("fs-extra"), 1);
5232
- var import_node_path17 = __toESM(require("path"), 1);
5267
+ var import_node_path18 = __toESM(require("path"), 1);
5233
5268
  var import_picocolors7 = __toESM(require("picocolors"), 1);
5234
5269
  async function initialize(options) {
5235
5270
  import_consola5.consola.info("Initalizing new project");
@@ -5277,7 +5312,7 @@ async function initialize(options) {
5277
5312
  input.template ??= defaultTemplate;
5278
5313
  input.packageManager ??= options.packageManager;
5279
5314
  await cloneProject(input);
5280
- const cdPath = import_node_path17.default.relative(process.cwd(), import_node_path17.default.resolve(input.directory));
5315
+ const cdPath = import_node_path18.default.relative(process.cwd(), import_node_path18.default.resolve(input.directory));
5281
5316
  console.log();
5282
5317
  import_consola5.consola.log(
5283
5318
  `\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
@@ -5329,14 +5364,14 @@ async function cloneProject({
5329
5364
  force: true
5330
5365
  });
5331
5366
  await import_fs_extra14.default.move(
5332
- import_node_path17.default.join(directory, "_gitignore"),
5333
- import_node_path17.default.join(directory, ".gitignore")
5367
+ import_node_path18.default.join(directory, "_gitignore"),
5368
+ import_node_path18.default.join(directory, ".gitignore")
5334
5369
  ).catch(
5335
5370
  (err) => import_consola5.consola.warn("Failed to move _gitignore to .gitignore:", err)
5336
5371
  );
5337
5372
  if (packageManager === "pnpm") {
5338
5373
  await import_fs_extra14.default.writeFile(
5339
- import_node_path17.default.join(directory, ".npmrc"),
5374
+ import_node_path18.default.join(directory, ".npmrc"),
5340
5375
  "shamefully-hoist=true\n"
5341
5376
  );
5342
5377
  }
@@ -5369,7 +5404,7 @@ async function prepare(config) {
5369
5404
 
5370
5405
  // src/core/zip.ts
5371
5406
  var import_zip_dir = __toESM(require("zip-dir"), 1);
5372
- var import_node_path18 = require("path");
5407
+ var import_node_path19 = require("path");
5373
5408
  var import_fs_extra15 = __toESM(require("fs-extra"), 1);
5374
5409
  var import_minimatch2 = require("minimatch");
5375
5410
  async function zip(config) {
@@ -5379,7 +5414,7 @@ async function zip(config) {
5379
5414
  internalConfig.logger.info("Zipping extension...");
5380
5415
  const zipFiles = [];
5381
5416
  const projectName = internalConfig.zip.name ?? kebabCaseAlphanumeric(
5382
- (await getPackageJson(internalConfig))?.name || (0, import_node_path18.dirname)(process.cwd())
5417
+ (await getPackageJson(internalConfig))?.name || (0, import_node_path19.dirname)(process.cwd())
5383
5418
  );
5384
5419
  const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", internalConfig.browser).replaceAll(
5385
5420
  "{{version}}",
@@ -5387,7 +5422,7 @@ async function zip(config) {
5387
5422
  ).replaceAll("{{manifestVersion}}", `mv${internalConfig.manifestVersion}`);
5388
5423
  await import_fs_extra15.default.ensureDir(internalConfig.outBaseDir);
5389
5424
  const outZipFilename = applyTemplate(internalConfig.zip.artifactTemplate);
5390
- const outZipPath = (0, import_node_path18.resolve)(internalConfig.outBaseDir, outZipFilename);
5425
+ const outZipPath = (0, import_node_path19.resolve)(internalConfig.outBaseDir, outZipFilename);
5391
5426
  await (0, import_zip_dir.default)(internalConfig.outDir, {
5392
5427
  saveTo: outZipPath
5393
5428
  });
@@ -5396,14 +5431,14 @@ async function zip(config) {
5396
5431
  const sourcesZipFilename = applyTemplate(
5397
5432
  internalConfig.zip.sourcesTemplate
5398
5433
  );
5399
- const sourcesZipPath = (0, import_node_path18.resolve)(
5434
+ const sourcesZipPath = (0, import_node_path19.resolve)(
5400
5435
  internalConfig.outBaseDir,
5401
5436
  sourcesZipFilename
5402
5437
  );
5403
5438
  await (0, import_zip_dir.default)(internalConfig.zip.sourcesRoot, {
5404
5439
  saveTo: sourcesZipPath,
5405
5440
  filter(path10) {
5406
- const relativePath = (0, import_node_path18.relative)(internalConfig.zip.sourcesRoot, path10);
5441
+ const relativePath = (0, import_node_path19.relative)(internalConfig.zip.sourcesRoot, path10);
5407
5442
  const matchedPattern = internalConfig.zip.ignoredSources.find(
5408
5443
  (pattern) => (0, import_minimatch2.minimatch)(relativePath, pattern)
5409
5444
  );