wxt 0.1.1 → 0.1.2

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.ts CHANGED
@@ -18,8 +18,8 @@ interface InlineConfig {
18
18
  browser?: TargetBrowser;
19
19
  manifestVersion?: TargetManifestVersion;
20
20
  logger?: Logger;
21
- vite?: Omit<vite.InlineConfig, 'root' | 'configFile' | 'mode'>;
22
- manifest?: UserManifest;
21
+ vite?: Omit<vite.UserConfig, 'root' | 'configFile' | 'mode'>;
22
+ manifest?: UserManifest | Promise<UserManifest> | UserManifestFn;
23
23
  server?: WxtDevServer;
24
24
  runner?: ExtensionRunnerConfig;
25
25
  }
@@ -171,6 +171,19 @@ interface BackgroundScriptDefintition {
171
171
  * and "version" are managed automatically, and don't need to be listed here.
172
172
  */
173
173
  type UserManifest = Omit<Manifest.WebExtensionManifest, 'action' | 'background' | 'browser_action' | 'chrome_url_overrides' | 'content_scripts' | 'description' | 'devtools_page' | 'manifest_version' | 'name' | 'options_page' | 'options_ui' | 'sandbox' | 'page_action' | 'popup' | 'short_name' | 'sidepanel' | 'sidebar_action' | 'version' | 'version_name'>;
174
+ type UserManifestFn = (env: ConfigEnv) => UserManifest | Promise<UserManifest>;
175
+ interface ConfigEnv {
176
+ mode: string;
177
+ command: 'build' | 'serve';
178
+ /**
179
+ * Browser passed in from the CLI
180
+ */
181
+ browser: TargetBrowser;
182
+ /**
183
+ * Manifest version passed in from the CLI
184
+ */
185
+ manifestVersion: 2 | 3;
186
+ }
174
187
  /**
175
188
  * Configure how the browser starts up.
176
189
  */
@@ -232,7 +245,7 @@ interface ExtensionRunnerConfig {
232
245
 
233
246
  type EntrypointGroup = Entrypoint | Entrypoint[];
234
247
 
235
- var version = "0.1.1";
248
+ var version = "0.1.2";
236
249
 
237
250
  declare function defineConfig(config: UserConfig): UserConfig;
238
251
 
@@ -244,4 +257,4 @@ declare function defineRunnerConfig(config: ExtensionRunnerConfig): ExtensionRun
244
257
  declare function build(config: InlineConfig): Promise<BuildOutput>;
245
258
  declare function createServer(config?: InlineConfig): Promise<WxtDevServer>;
246
259
 
247
- export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BuildOutput, BuildStepOutput, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, WxtDevServer, WxtInlineViteConfig, build, createServer, defineConfig, defineRunnerConfig, version };
260
+ export { BackgroundEntrypoint, BackgroundScriptDefintition, BaseEntrypoint, BuildOutput, BuildStepOutput, ConfigEnv, ContentScriptDefinition, ContentScriptEntrypoint, Entrypoint, ExtensionRunnerConfig, GenericEntrypoint, InlineConfig, Logger, OnContentScriptStopped, OptionsEntrypoint, PopupEntrypoint, TargetBrowser, TargetManifestVersion, UserConfig, UserManifest, UserManifestFn, WxtDevServer, WxtInlineViteConfig, build, createServer, defineConfig, defineRunnerConfig, version };
package/dist/index.js CHANGED
@@ -237,6 +237,15 @@ function getUnimportOptions(config) {
237
237
  }
238
238
 
239
239
  // src/core/vite-plugins/unimport.ts
240
+ import { extname as extname2 } from "path";
241
+ var ENABLED_EXTENSIONS = {
242
+ ".js": true,
243
+ ".jsx": true,
244
+ ".ts": true,
245
+ ".tsx": true,
246
+ ".vue": true,
247
+ ".svelte": true
248
+ };
240
249
  function unimport(config) {
241
250
  const options = getUnimportOptions(config);
242
251
  const unimport2 = createUnimport(options);
@@ -246,7 +255,9 @@ function unimport(config) {
246
255
  await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
247
256
  },
248
257
  async transform(code, id) {
249
- return unimport2.injectImports(code, id);
258
+ const ext = extname2(id);
259
+ if (ENABLED_EXTENSIONS[ext])
260
+ return unimport2.injectImports(code, id);
250
261
  }
251
262
  };
252
263
  }
@@ -360,6 +371,12 @@ async function getInternalConfig(config, command) {
360
371
  const outBaseDir = path2.resolve(root, ".output");
361
372
  const outDir = path2.resolve(outBaseDir, `${browser}-mv${manifestVersion}`);
362
373
  const logger = config.logger ?? consola;
374
+ const manifest = await (typeof config.manifest === "function" ? config.manifest({
375
+ browser,
376
+ command,
377
+ manifestVersion,
378
+ mode
379
+ }) : config.manifest ?? {});
363
380
  const baseConfig = {
364
381
  root,
365
382
  outDir,
@@ -371,7 +388,7 @@ async function getInternalConfig(config, command) {
371
388
  command,
372
389
  logger,
373
390
  vite: config.vite ?? {},
374
- manifest: config.manifest ?? {},
391
+ manifest,
375
392
  imports: config.imports ?? {},
376
393
  runnerConfig: await loadConfig({
377
394
  name: "web-ext",
@@ -932,19 +949,20 @@ async function writeImportsDeclarationFile(config) {
932
949
  }
933
950
  async function writePathsDeclarationFile(entrypoints, config) {
934
951
  const filePath = resolve10(config.typesDir, "paths.d.ts");
952
+ const unions = entrypoints.map((entry) => {
953
+ const path5 = getEntrypointBundlePath(
954
+ entry,
955
+ config.outDir,
956
+ entry.inputPath.endsWith(".html") ? ".html" : ".js"
957
+ );
958
+ return ` | "/${path5}"`;
959
+ }).sort();
935
960
  await fs8.writeFile(
936
961
  filePath,
937
962
  [
938
963
  "// Generated by wxt",
939
964
  "type EntrypointPath =",
940
- ...entrypoints.map((entry) => {
941
- const path5 = getEntrypointBundlePath(
942
- entry,
943
- config.outDir,
944
- entry.inputPath.endsWith(".html") ? ".html" : ".js"
945
- );
946
- return ` | "/${path5}"`;
947
- }).sort()
965
+ ...unions.length === 0 ? [" never"] : unions
948
966
  ].join("\n") + "\n"
949
967
  );
950
968
  return filePath;
@@ -1385,7 +1403,7 @@ function formatDuration(duration) {
1385
1403
  }
1386
1404
 
1387
1405
  // src/core/log/printBuildSummary.ts
1388
- import path4, { extname as extname2, relative as relative5, resolve as resolve12 } from "path";
1406
+ import path4, { extname as extname3, relative as relative5, resolve as resolve12 } from "path";
1389
1407
 
1390
1408
  // src/core/log/printTable.ts
1391
1409
  function printTable(log, rows, gap = 2) {
@@ -1422,8 +1440,8 @@ async function printBuildSummary(output, config) {
1422
1440
  ...output.steps.flatMap((step) => step.chunks),
1423
1441
  ...output.publicAssets
1424
1442
  ].sort((l, r) => {
1425
- const lWeight = CHUNK_SORT_WEIGHTS[l.fileName] ?? CHUNK_SORT_WEIGHTS[extname2(l.fileName)] ?? DEFAULT_SORT_WEIGHT;
1426
- const rWeight = CHUNK_SORT_WEIGHTS[r.fileName] ?? CHUNK_SORT_WEIGHTS[extname2(r.fileName)] ?? DEFAULT_SORT_WEIGHT;
1443
+ const lWeight = CHUNK_SORT_WEIGHTS[l.fileName] ?? CHUNK_SORT_WEIGHTS[extname3(l.fileName)] ?? DEFAULT_SORT_WEIGHT;
1444
+ const rWeight = CHUNK_SORT_WEIGHTS[r.fileName] ?? CHUNK_SORT_WEIGHTS[extname3(r.fileName)] ?? DEFAULT_SORT_WEIGHT;
1427
1445
  const diff = lWeight - rWeight;
1428
1446
  if (diff !== 0)
1429
1447
  return diff;
@@ -1436,7 +1454,7 @@ async function printBuildSummary(output, config) {
1436
1454
  relative5(process.cwd(), config.outDir) + path4.sep,
1437
1455
  chunk.fileName
1438
1456
  ];
1439
- const ext = extname2(chunk.fileName);
1457
+ const ext = extname3(chunk.fileName);
1440
1458
  const prefix = i === chunks.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
1441
1459
  const color = CHUNK_COLORS[ext] ?? DEFAULT_COLOR;
1442
1460
  const stats = await fs10.lstat(resolve12(config.outDir, chunk.fileName));
@@ -1691,7 +1709,7 @@ function reloadHtmlPages(groups, server, config) {
1691
1709
  }
1692
1710
 
1693
1711
  // package.json
1694
- var version2 = "0.1.1";
1712
+ var version2 = "0.1.2";
1695
1713
 
1696
1714
  // src/core/utils/defineConfig.ts
1697
1715
  function defineConfig(config) {