wxt 0.16.1 → 0.16.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
- import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-2QTHXYDU.cjs';
2
- export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-2QTHXYDU.cjs';
1
+ import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-wltPoSyr.cjs';
2
+ export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, D as ExtensionRunner, F as FsCache, G as GenericEntrypoint, H as HookResult, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, R as ResolvedConfig, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, V as VirtualEntrypointType, A as Wxt, x as WxtBuilder, y as WxtBuilderServer, z as WxtHooks, a as WxtViteConfig } from './index-wltPoSyr.cjs';
3
3
  import 'vite';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
8
  import 'chokidar';
9
+ import 'c12';
10
+ import 'hookable';
9
11
 
10
12
  /**
11
13
  * Bundles the extension for production. Returns a promise of the build result. Discovers the `wxt.config.ts` file in
@@ -62,6 +64,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
62
64
  */
63
65
  declare function zip(config?: InlineConfig): Promise<string[]>;
64
66
 
65
- var version = "0.16.1";
67
+ var version = "0.16.3";
66
68
 
67
69
  export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-2QTHXYDU.js';
2
- export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-2QTHXYDU.js';
1
+ import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './index-wltPoSyr.js';
2
+ export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, D as ExtensionRunner, F as FsCache, G as GenericEntrypoint, H as HookResult, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, R as ResolvedConfig, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, V as VirtualEntrypointType, A as Wxt, x as WxtBuilder, y as WxtBuilderServer, z as WxtHooks, a as WxtViteConfig } from './index-wltPoSyr.js';
3
3
  import 'vite';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
8
  import 'chokidar';
9
+ import 'c12';
10
+ import 'hookable';
9
11
 
10
12
  /**
11
13
  * Bundles the extension for production. Returns a promise of the build result. Discovers the `wxt.config.ts` file in
@@ -62,6 +64,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
62
64
  */
63
65
  declare function zip(config?: InlineConfig): Promise<string[]>;
64
66
 
65
- var version = "0.16.1";
67
+ var version = "0.16.3";
66
68
 
67
69
  export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
package/dist/index.js CHANGED
@@ -6,21 +6,22 @@ import {
6
6
  getContentScriptCssFiles,
7
7
  getContentScriptsCssMap,
8
8
  getEntrypointBundlePath,
9
- getInternalConfig,
10
9
  getPackageJson,
11
10
  internalBuild,
12
11
  kebabCaseAlphanumeric,
13
12
  printFileList,
14
13
  rebuild,
14
+ registerWxt,
15
15
  resolvePerBrowserOption,
16
- version
17
- } from "./chunk-7RB7TV6M.js";
16
+ version,
17
+ wxt
18
+ } from "./chunk-4IVGHIAG.js";
18
19
  import "./chunk-VBXJIVYU.js";
19
20
 
20
21
  // src/core/build.ts
21
22
  async function build(config) {
22
- const internalConfig = await getInternalConfig(config ?? {}, "build");
23
- return await internalBuild(internalConfig);
23
+ await registerWxt("build", config);
24
+ return await internalBuild();
24
25
  }
25
26
 
26
27
  // src/core/clean.ts
@@ -72,11 +73,11 @@ function defineRunnerConfig(config) {
72
73
  import { relative } from "node:path";
73
74
  function createWslRunner() {
74
75
  return {
75
- async openBrowser(config) {
76
- config.logger.warn(
76
+ async openBrowser() {
77
+ wxt.logger.warn(
77
78
  `Cannot open browser when using WSL. Load "${relative(
78
79
  process.cwd(),
79
- config.outDir
80
+ wxt.config.outDir
80
81
  )}" as an unpacked extension manually`
81
82
  );
82
83
  },
@@ -90,9 +91,9 @@ import defu from "defu";
90
91
  function createWebExtRunner() {
91
92
  let runner;
92
93
  return {
93
- async openBrowser(config) {
94
+ async openBrowser() {
94
95
  const startTime = Date.now();
95
- if (config.browser === "firefox" && config.manifestVersion === 3) {
96
+ if (wxt.config.browser === "firefox" && wxt.config.manifestVersion === 3) {
96
97
  throw Error(
97
98
  "Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653"
98
99
  );
@@ -100,22 +101,22 @@ function createWebExtRunner() {
100
101
  const webExtLogger = await import("web-ext-run/util/logger");
101
102
  webExtLogger.consoleStream.write = ({ level, msg, name }) => {
102
103
  if (level >= ERROR_LOG_LEVEL)
103
- config.logger.error(name, msg);
104
+ wxt.logger.error(name, msg);
104
105
  if (level >= WARN_LOG_LEVEL)
105
- config.logger.warn(msg);
106
+ wxt.logger.warn(msg);
106
107
  };
107
- const wxtUserConfig = config.runnerConfig.config;
108
+ const wxtUserConfig = wxt.config.runnerConfig.config;
108
109
  const userConfig = {
109
110
  console: wxtUserConfig?.openConsole,
110
111
  devtools: wxtUserConfig?.openDevtools,
111
112
  startUrl: wxtUserConfig?.startUrls,
112
- ...config.browser === "firefox" ? {
113
+ ...wxt.config.browser === "firefox" ? {
113
114
  firefox: wxtUserConfig?.binaries?.firefox,
114
115
  firefoxProfile: wxtUserConfig?.firefoxProfile,
115
116
  prefs: wxtUserConfig?.firefoxPrefs,
116
117
  args: wxtUserConfig?.firefoxArgs
117
118
  } : {
118
- chromiumBinary: wxtUserConfig?.binaries?.[config.browser],
119
+ chromiumBinary: wxtUserConfig?.binaries?.[wxt.config.browser],
119
120
  chromiumProfile: wxtUserConfig?.chromiumProfile,
120
121
  chromiumPref: defu(
121
122
  wxtUserConfig?.chromiumPref,
@@ -126,8 +127,8 @@ function createWebExtRunner() {
126
127
  };
127
128
  const finalConfig = {
128
129
  ...userConfig,
129
- target: config.browser === "firefox" ? "firefox-desktop" : "chromium",
130
- sourceDir: config.outDir,
130
+ target: wxt.config.browser === "firefox" ? "firefox-desktop" : "chromium",
131
+ sourceDir: wxt.config.outDir,
131
132
  // WXT handles reloads, so disable auto-reload behaviors in web-ext
132
133
  noReload: true,
133
134
  noInput: true
@@ -136,12 +137,12 @@ function createWebExtRunner() {
136
137
  // Don't call `process.exit(0)` after starting web-ext
137
138
  shouldExitProgram: false
138
139
  };
139
- config.logger.debug("web-ext config:", finalConfig);
140
- config.logger.debug("web-ext options:", options);
140
+ wxt.logger.debug("web-ext config:", finalConfig);
141
+ wxt.logger.debug("web-ext options:", options);
141
142
  const webExt = await import("web-ext-run");
142
143
  runner = await webExt.default.cmd.run(finalConfig, options);
143
144
  const duration = Date.now() - startTime;
144
- config.logger.success(`Opened browser in ${formatDuration(duration)}`);
145
+ wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
145
146
  },
146
147
  async closeBrowser() {
147
148
  return await runner?.exit();
@@ -165,11 +166,11 @@ var DEFAULT_CHROMIUM_PREFS = {
165
166
  import { relative as relative2 } from "node:path";
166
167
  function createSafariRunner() {
167
168
  return {
168
- async openBrowser(config) {
169
- config.logger.warn(
169
+ async openBrowser() {
170
+ wxt.logger.warn(
170
171
  `Cannot Safari using web-ext. Load "${relative2(
171
172
  process.cwd(),
172
- config.outDir
173
+ wxt.config.outDir
173
174
  )}" as an unpacked extension manually`
174
175
  );
175
176
  },
@@ -182,11 +183,11 @@ function createSafariRunner() {
182
183
  import { relative as relative3 } from "node:path";
183
184
  function createManualRunner() {
184
185
  return {
185
- async openBrowser(config) {
186
- config.logger.info(
186
+ async openBrowser() {
187
+ wxt.logger.info(
187
188
  `Load "${relative3(
188
189
  process.cwd(),
189
- config.outDir
190
+ wxt.config.outDir
190
191
  )}" as an unpacked extension manually`
191
192
  );
192
193
  },
@@ -202,12 +203,12 @@ async function isWsl() {
202
203
  }
203
204
 
204
205
  // src/core/runners/index.ts
205
- async function createExtensionRunner(config) {
206
- if (config.browser === "safari")
206
+ async function createExtensionRunner() {
207
+ if (wxt.config.browser === "safari")
207
208
  return createSafariRunner();
208
209
  if (await isWsl())
209
210
  return createWslRunner();
210
- if (config.runnerConfig.config?.disabled)
211
+ if (wxt.config.runnerConfig.config?.disabled)
211
212
  return createManualRunner();
212
213
  return createWebExtRunner();
213
214
  }
@@ -227,13 +228,13 @@ async function createServer(inlineConfig) {
227
228
  origin
228
229
  };
229
230
  const buildAndOpenBrowser = async () => {
230
- server.currentOutput = await internalBuild(config);
231
- await runner.openBrowser(config);
231
+ server.currentOutput = await internalBuild();
232
+ await runner.openBrowser();
232
233
  };
233
234
  const closeAndRecreateRunner = async () => {
234
235
  await runner.closeBrowser();
235
- config = await getLatestConfig();
236
- runner = await createExtensionRunner(config);
236
+ await wxt.reloadConfig();
237
+ runner = await createExtensionRunner();
237
238
  };
238
239
  const server = {
239
240
  ...serverInfo,
@@ -246,7 +247,7 @@ async function createServer(inlineConfig) {
246
247
  currentOutput: void 0,
247
248
  async start() {
248
249
  await builderServer.listen();
249
- config.logger.success(`Started dev server @ ${serverInfo.origin}`);
250
+ wxt.logger.success(`Started dev server @ ${serverInfo.origin}`);
250
251
  await buildAndOpenBrowser();
251
252
  },
252
253
  async stop() {
@@ -271,27 +272,20 @@ async function createServer(inlineConfig) {
271
272
  },
272
273
  async restartBrowser() {
273
274
  await closeAndRecreateRunner();
274
- await runner.openBrowser(config);
275
+ await runner.openBrowser();
275
276
  }
276
277
  };
277
- const getLatestConfig = () => getInternalConfig(inlineConfig ?? {}, "serve", server);
278
- let config = await getLatestConfig();
278
+ await registerWxt("serve", inlineConfig, server);
279
279
  let [runner, builderServer] = await Promise.all([
280
- createExtensionRunner(config),
281
- config.builder.createServer(server)
280
+ createExtensionRunner(),
281
+ wxt.config.builder.createServer(server)
282
282
  ]);
283
283
  server.ws.on("wxt:background-initialized", () => {
284
284
  if (server.currentOutput == null)
285
285
  return;
286
- reloadContentScripts(server.currentOutput.steps, config, server);
287
- });
288
- const reloadOnChange = createFileReloader({
289
- server,
290
- getLatestConfig,
291
- updateConfig(newConfig) {
292
- config = newConfig;
293
- }
286
+ reloadContentScripts(server.currentOutput.steps, server);
294
287
  });
288
+ const reloadOnChange = createFileReloader(server);
295
289
  server.watcher.on("all", reloadOnChange);
296
290
  return server;
297
291
  }
@@ -299,14 +293,12 @@ async function getPort() {
299
293
  const { default: getPort2, portNumbers } = await import("get-port");
300
294
  return await getPort2({ port: portNumbers(3e3, 3010) });
301
295
  }
302
- function createFileReloader(options) {
303
- const { server, getLatestConfig, updateConfig } = options;
296
+ function createFileReloader(server) {
304
297
  const fileChangedMutex = new Mutex();
305
298
  const changeQueue = [];
306
299
  return async (event, path3) => {
307
- const config = await getLatestConfig();
308
- updateConfig(config);
309
- if (path3.startsWith(config.outBaseDir))
300
+ await wxt.reloadConfig();
301
+ if (path3.startsWith(wxt.config.outBaseDir))
310
302
  return;
311
303
  changeQueue.push([event, path3]);
312
304
  await fileChangedMutex.runExclusive(async () => {
@@ -315,29 +307,24 @@ function createFileReloader(options) {
315
307
  const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
316
308
  if (fileChanges.length === 0)
317
309
  return;
318
- const changes = detectDevChanges(
319
- config,
320
- fileChanges,
321
- server.currentOutput
322
- );
310
+ const changes = detectDevChanges(fileChanges, server.currentOutput);
323
311
  if (changes.type === "no-change")
324
312
  return;
325
313
  if (changes.type === "full-restart") {
326
- config.logger.info("Config changed, restarting server...");
314
+ wxt.logger.info("Config changed, restarting server...");
327
315
  server.restart();
328
316
  return;
329
317
  }
330
318
  if (changes.type === "browser-restart") {
331
- config.logger.info("Runner config changed, restarting browser...");
319
+ wxt.logger.info("Runner config changed, restarting browser...");
332
320
  server.restartBrowser();
333
321
  return;
334
322
  }
335
- config.logger.info(
336
- `Changed: ${Array.from(new Set(fileChanges)).map((file) => pc2.dim(relative4(config.root, file))).join(", ")}`
323
+ wxt.logger.info(
324
+ `Changed: ${Array.from(new Set(fileChanges)).map((file) => pc2.dim(relative4(wxt.config.root, file))).join(", ")}`
337
325
  );
338
- const allEntrypoints = await findEntrypoints(config);
326
+ const allEntrypoints = await findEntrypoints();
339
327
  const { output: newOutput } = await rebuild(
340
- config,
341
328
  allEntrypoints,
342
329
  // TODO: this excludes new entrypoints, so they're not built until the dev command is restarted
343
330
  changes.rebuildGroups,
@@ -352,13 +339,12 @@ function createFileReloader(options) {
352
339
  case "html-reload":
353
340
  const { reloadedNames } = reloadHtmlPages(
354
341
  changes.rebuildGroups,
355
- server,
356
- config
342
+ server
357
343
  );
358
344
  consola2.success(`Reloaded: ${getFilenameList(reloadedNames)}`);
359
345
  break;
360
346
  case "content-script-reload":
361
- reloadContentScripts(changes.changedSteps, config, server);
347
+ reloadContentScripts(changes.changedSteps, server);
362
348
  const rebuiltNames = changes.rebuildGroups.flat().map((entry) => entry.name);
363
349
  consola2.success(`Reloaded: ${getFilenameList(rebuiltNames)}`);
364
350
  break;
@@ -366,30 +352,33 @@ function createFileReloader(options) {
366
352
  });
367
353
  };
368
354
  }
369
- function reloadContentScripts(steps, config, server) {
370
- if (config.manifestVersion === 3) {
355
+ function reloadContentScripts(steps, server) {
356
+ if (wxt.config.manifestVersion === 3) {
371
357
  steps.forEach((step) => {
372
358
  if (server.currentOutput == null)
373
359
  return;
374
360
  const entry = step.entrypoints;
375
361
  if (Array.isArray(entry) || entry.type !== "content-script")
376
362
  return;
377
- const js = [getEntrypointBundlePath(entry, config.outDir, ".js")];
363
+ const js = [getEntrypointBundlePath(entry, wxt.config.outDir, ".js")];
378
364
  const cssMap = getContentScriptsCssMap(server.currentOutput, [entry]);
379
365
  const css = getContentScriptCssFiles([entry], cssMap);
380
366
  server.reloadContentScript({
381
367
  allFrames: resolvePerBrowserOption(
382
368
  entry.options.allFrames,
383
- config.browser
369
+ wxt.config.browser
384
370
  ),
385
371
  excludeMatches: resolvePerBrowserOption(
386
372
  entry.options.excludeMatches,
387
- config.browser
373
+ wxt.config.browser
374
+ ),
375
+ matches: resolvePerBrowserOption(
376
+ entry.options.matches,
377
+ wxt.config.browser
388
378
  ),
389
- matches: resolvePerBrowserOption(entry.options.matches, config.browser),
390
- runAt: resolvePerBrowserOption(entry.options.runAt, config.browser),
379
+ runAt: resolvePerBrowserOption(entry.options.runAt, wxt.config.browser),
391
380
  // @ts-expect-error: Chrome accepts this, not typed in webextension-polyfill (https://developer.chrome.com/docs/extensions/reference/scripting/#type-RegisteredContentScript)
392
- world: resolvePerBrowserOption(entry.options.world, config.browser),
381
+ world: resolvePerBrowserOption(entry.options.world, wxt.config.browser),
393
382
  js,
394
383
  css
395
384
  });
@@ -398,10 +387,10 @@ function reloadContentScripts(steps, config, server) {
398
387
  server.reloadExtension();
399
388
  }
400
389
  }
401
- function reloadHtmlPages(groups, server, config) {
390
+ function reloadHtmlPages(groups, server) {
402
391
  const htmlEntries = groups.flat().filter((entry) => entry.inputPath.endsWith(".html"));
403
392
  htmlEntries.forEach((entry) => {
404
- const path3 = getEntrypointBundlePath(entry, config.outDir, ".html");
393
+ const path3 = getEntrypointBundlePath(entry, wxt.config.outDir, ".html");
405
394
  server.reloadPage(path3);
406
395
  });
407
396
  return {
@@ -482,19 +471,11 @@ async function initialize(options) {
482
471
  }
483
472
  async function listTemplates() {
484
473
  try {
485
- const res = await fetch(
486
- "https://api.github.com/repos/wxt-dev/wxt/contents/templates",
487
- {
488
- headers: {
489
- Accept: "application/vnd.github+json",
490
- "X-GitHub-Api-Version": "2022-11-28"
491
- }
492
- }
493
- );
474
+ const res = await fetch("https://ungh.cc/repos/wxt-dev/wxt/files/main");
494
475
  if (res.status >= 300)
495
476
  throw Error(`Request failed with status ${res.status} ${res.statusText}`);
496
477
  const data = await res.json();
497
- return data.filter((item) => item.type === "dir").map((item) => ({ name: item.name, path: item.path })).sort((l, r) => {
478
+ return data.files.map((item) => item.path.match(/templates\/(.+)\/package\.json/)?.[1]).filter((name) => name != null).map((name) => ({ name, path: `templates/${name}` })).sort((l, r) => {
498
479
  const lWeight = TEMPLATE_SORT_WEIGHT[l.name] ?? Number.MAX_SAFE_INTEGER;
499
480
  const rWeight = TEMPLATE_SORT_WEIGHT[r.name] ?? Number.MAX_SAFE_INTEGER;
500
481
  const diff = lWeight - rWeight;
@@ -545,10 +526,10 @@ var TEMPLATE_SORT_WEIGHT = {
545
526
 
546
527
  // src/core/prepare.ts
547
528
  async function prepare(config) {
548
- const internalConfig = await getInternalConfig(config, "build");
549
- internalConfig.logger.info("Generating types...");
550
- const entrypoints = await findEntrypoints(internalConfig);
551
- await generateTypesDir(entrypoints, internalConfig);
529
+ await registerWxt("build", config);
530
+ wxt.logger.info("Generating types...");
531
+ const entrypoints = await findEntrypoints();
532
+ await generateTypesDir(entrypoints);
552
533
  }
553
534
 
554
535
  // src/core/zip.ts
@@ -557,40 +538,35 @@ import { dirname, relative as relative5, resolve } from "node:path";
557
538
  import fs3 from "fs-extra";
558
539
  import { minimatch } from "minimatch";
559
540
  async function zip(config) {
560
- const internalConfig = await getInternalConfig(config ?? {}, "build");
561
- const output = await internalBuild(internalConfig);
541
+ await registerWxt("build", config);
542
+ const output = await internalBuild();
562
543
  const start = Date.now();
563
- internalConfig.logger.info("Zipping extension...");
544
+ wxt.logger.info("Zipping extension...");
564
545
  const zipFiles = [];
565
- const projectName = internalConfig.zip.name ?? kebabCaseAlphanumeric(
566
- (await getPackageJson(internalConfig))?.name || dirname(process.cwd())
546
+ const projectName = wxt.config.zip.name ?? kebabCaseAlphanumeric(
547
+ (await getPackageJson())?.name || dirname(process.cwd())
567
548
  );
568
- const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", internalConfig.browser).replaceAll(
549
+ const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", wxt.config.browser).replaceAll(
569
550
  "{{version}}",
570
551
  output.manifest.version_name ?? output.manifest.version
571
- ).replaceAll("{{manifestVersion}}", `mv${internalConfig.manifestVersion}`);
572
- await fs3.ensureDir(internalConfig.outBaseDir);
573
- const outZipFilename = applyTemplate(internalConfig.zip.artifactTemplate);
574
- const outZipPath = resolve(internalConfig.outBaseDir, outZipFilename);
575
- await zipdir(internalConfig.outDir, {
552
+ ).replaceAll("{{manifestVersion}}", `mv${wxt.config.manifestVersion}`);
553
+ await fs3.ensureDir(wxt.config.outBaseDir);
554
+ const outZipFilename = applyTemplate(wxt.config.zip.artifactTemplate);
555
+ const outZipPath = resolve(wxt.config.outBaseDir, outZipFilename);
556
+ await zipdir(wxt.config.outDir, {
576
557
  saveTo: outZipPath
577
558
  });
578
559
  zipFiles.push(outZipPath);
579
- if (internalConfig.browser === "firefox") {
580
- const sourcesZipFilename = applyTemplate(
581
- internalConfig.zip.sourcesTemplate
582
- );
583
- const sourcesZipPath = resolve(
584
- internalConfig.outBaseDir,
585
- sourcesZipFilename
586
- );
587
- await zipdir(internalConfig.zip.sourcesRoot, {
560
+ if (wxt.config.browser === "firefox") {
561
+ const sourcesZipFilename = applyTemplate(wxt.config.zip.sourcesTemplate);
562
+ const sourcesZipPath = resolve(wxt.config.outBaseDir, sourcesZipFilename);
563
+ await zipdir(wxt.config.zip.sourcesRoot, {
588
564
  saveTo: sourcesZipPath,
589
565
  filter(path3) {
590
- const relativePath = relative5(internalConfig.zip.sourcesRoot, path3);
591
- return internalConfig.zip.includeSources.some(
566
+ const relativePath = relative5(wxt.config.zip.sourcesRoot, path3);
567
+ return wxt.config.zip.includeSources.some(
592
568
  (pattern) => minimatch(relativePath, pattern)
593
- ) || !internalConfig.zip.excludeSources.some(
569
+ ) || !wxt.config.zip.excludeSources.some(
594
570
  (pattern) => minimatch(relativePath, pattern)
595
571
  );
596
572
  }
@@ -598,9 +574,9 @@ async function zip(config) {
598
574
  zipFiles.push(sourcesZipPath);
599
575
  }
600
576
  await printFileList(
601
- internalConfig.logger.success,
577
+ wxt.logger.success,
602
578
  `Zipped extension in ${formatDuration(Date.now() - start)}`,
603
- internalConfig.outBaseDir,
579
+ wxt.config.outBaseDir,
604
580
  zipFiles
605
581
  );
606
582
  return zipFiles;
package/dist/sandbox.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { U as UnlistedScriptDefinition, B as BackgroundDefinition, C as ContentScriptDefinition } from './external-TYmXqKVq.js';
1
+ import { U as UnlistedScriptDefinition, B as BackgroundDefinition, C as ContentScriptDefinition } from './index-TYmXqKVq.js';
2
2
  export * from '@webext-core/match-patterns';
3
3
  import 'webextension-polyfill';
4
4
 
package/dist/testing.cjs CHANGED
@@ -653,9 +653,29 @@ function entrypointGroupGlobals(entrypointGroup) {
653
653
  };
654
654
  }
655
655
 
656
+ // src/core/builders/vite/plugins/defineImportMeta.ts
657
+ function defineImportMeta() {
658
+ return {
659
+ name: "wxt:define",
660
+ config() {
661
+ return {
662
+ define: {
663
+ // This works for all extension contexts, including background service worker
664
+ "import.meta.url": "self.location.href"
665
+ }
666
+ };
667
+ }
668
+ };
669
+ }
670
+
656
671
  // src/core/utils/fs.ts
657
672
  var import_fs_extra3 = __toESM(require("fs-extra"), 1);
658
673
  var import_fast_glob = __toESM(require("fast-glob"), 1);
674
+
675
+ // src/core/wxt.ts
676
+ var import_hookable = require("hookable");
677
+
678
+ // src/core/utils/fs.ts
659
679
  async function writeFileIfDifferent(file, newContents) {
660
680
  const existingContents = await import_fs_extra3.default.readFile(file, "utf-8").catch(() => void 0);
661
681
  if (existingContents !== newContents) {
@@ -719,7 +739,7 @@ var import_unimport3 = require("unimport");
719
739
  var import_fs_extra6 = __toESM(require("fs-extra"), 1);
720
740
  var import_node_path6 = __toESM(require("path"), 1);
721
741
 
722
- // src/core/utils/building/get-internal-config.ts
742
+ // src/core/utils/building/resolve-config.ts
723
743
  var import_c12 = require("c12");
724
744
  var import_node_path7 = __toESM(require("path"), 1);
725
745
 
@@ -745,7 +765,7 @@ function createFsCache(wxtDir) {
745
765
  };
746
766
  }
747
767
 
748
- // src/core/utils/building/get-internal-config.ts
768
+ // src/core/utils/building/resolve-config.ts
749
769
  var import_consola = __toESM(require("consola"), 1);
750
770
 
751
771
  // src/core/builders/vite/index.ts
@@ -784,7 +804,8 @@ async function createViteBuilder(inlineConfig, userConfig, wxtConfig) {
784
804
  tsconfigPaths(wxtConfig),
785
805
  noopBackground(),
786
806
  globals(wxtConfig),
787
- excludeBrowserPolyfill(wxtConfig)
807
+ excludeBrowserPolyfill(wxtConfig),
808
+ defineImportMeta()
788
809
  );
789
810
  if (wxtConfig.analysis.enabled) {
790
811
  config.plugins.push(bundleAnalysis());
@@ -962,9 +983,9 @@ function getRollupEntry(entrypoint) {
962
983
  return virtualEntrypointType ? `virtual:wxt-${virtualEntrypointType}?${entrypoint.inputPath}` : entrypoint.inputPath;
963
984
  }
964
985
 
965
- // src/core/utils/building/get-internal-config.ts
986
+ // src/core/utils/building/resolve-config.ts
966
987
  var import_defu2 = __toESM(require("defu"), 1);
967
- async function getInternalConfig(inlineConfig, command, server) {
988
+ async function resolveConfig(inlineConfig, command, server) {
968
989
  let userConfig = {};
969
990
  let userConfigMetadata;
970
991
  if (inlineConfig.configFile !== false) {
@@ -1058,7 +1079,8 @@ async function getInternalConfig(inlineConfig, command, server) {
1058
1079
  server,
1059
1080
  dev: {
1060
1081
  reloadCommand
1061
- }
1082
+ },
1083
+ hooks: mergedConfig.hooks ?? {}
1062
1084
  };
1063
1085
  const builder = await createViteBuilder(
1064
1086
  inlineConfig,
@@ -1095,6 +1117,10 @@ function mergeInlineConfig(inlineConfig, userConfig) {
1095
1117
  inlineConfig.zip ?? {},
1096
1118
  userConfig.zip ?? {}
1097
1119
  );
1120
+ const hooks = (0, import_defu2.default)(
1121
+ inlineConfig.hooks ?? {},
1122
+ userConfig.hooks ?? {}
1123
+ );
1098
1124
  return {
1099
1125
  root: inlineConfig.root ?? userConfig.root,
1100
1126
  browser: inlineConfig.browser ?? userConfig.browser,
@@ -1129,7 +1155,8 @@ function mergeInlineConfig(inlineConfig, userConfig) {
1129
1155
  dev: {
1130
1156
  ...userConfig.dev,
1131
1157
  ...inlineConfig.dev
1132
- }
1158
+ },
1159
+ hooks
1133
1160
  };
1134
1161
  }
1135
1162
  function resolveInternalZipConfig(root, mergedConfig) {
@@ -1214,7 +1241,7 @@ var managedPath = (0, import_manage_path.default)(process.env);
1214
1241
 
1215
1242
  // src/testing/wxt-vitest-plugin.ts
1216
1243
  function WxtVitest(inlineConfig) {
1217
- return getInternalConfig(inlineConfig ?? {}, "serve").then((config) => [
1244
+ return resolveConfig(inlineConfig ?? {}, "serve").then((config) => [
1218
1245
  webextensionPolyfillMock(config),
1219
1246
  unimport(config),
1220
1247
  globals(config),
@@ -1,11 +1,13 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './external-2QTHXYDU.cjs';
3
+ import { I as InlineConfig } from './index-wltPoSyr.cjs';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
8
  import 'chokidar';
9
+ import 'c12';
10
+ import 'hookable';
9
11
 
10
12
  /**
11
13
  * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
package/dist/testing.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { FakeBrowser, fakeBrowser } from '@webext-core/fake-browser';
2
2
  import * as vite from 'vite';
3
- import { I as InlineConfig } from './external-2QTHXYDU.js';
3
+ import { I as InlineConfig } from './index-wltPoSyr.js';
4
4
  import 'webextension-polyfill';
5
5
  import 'unimport';
6
6
  import 'consola';
7
7
  import 'rollup-plugin-visualizer';
8
8
  import 'chokidar';
9
+ import 'c12';
10
+ import 'hookable';
9
11
 
10
12
  /**
11
13
  * Vite plugin that configures Vitest with everything required to test a WXT extension, based on the `<root>/wxt.config.ts`
package/dist/testing.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  download,
3
- getInternalConfig,
4
3
  globals,
4
+ resolveConfig,
5
5
  tsconfigPaths,
6
6
  unimport,
7
7
  webextensionPolyfillMock
8
- } from "./chunk-7RB7TV6M.js";
8
+ } from "./chunk-4IVGHIAG.js";
9
9
  import "./chunk-VBXJIVYU.js";
10
10
 
11
11
  // src/testing/fake-browser.ts
@@ -13,7 +13,7 @@ import { fakeBrowser } from "@webext-core/fake-browser";
13
13
 
14
14
  // src/testing/wxt-vitest-plugin.ts
15
15
  function WxtVitest(inlineConfig) {
16
- return getInternalConfig(inlineConfig ?? {}, "serve").then((config) => [
16
+ return resolveConfig(inlineConfig ?? {}, "serve").then((config) => [
17
17
  webextensionPolyfillMock(config),
18
18
  unimport(config),
19
19
  globals(config),