wxt 0.16.5 → 0.16.7

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.
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.16.5";
2
+ var version = "0.16.7";
3
3
 
4
4
  // src/core/utils/fs.ts
5
5
  import fs from "fs-extra";
@@ -573,29 +573,6 @@ import { createUnimport } from "unimport";
573
573
  import fs4 from "fs-extra";
574
574
  import { relative as relative3, resolve as resolve4 } from "path";
575
575
 
576
- // src/core/utils/unimport.ts
577
- import { defu } from "defu";
578
- function getUnimportOptions(config) {
579
- if (config.imports === false)
580
- return false;
581
- const defaultOptions = {
582
- debugLog: config.logger.debug,
583
- imports: [
584
- { name: "defineConfig", from: "wxt" },
585
- { name: "fakeBrowser", from: "wxt/testing" }
586
- ],
587
- presets: [
588
- { package: "wxt/client" },
589
- { package: "wxt/browser" },
590
- { package: "wxt/sandbox" },
591
- { package: "wxt/storage" }
592
- ],
593
- warn: config.logger.warn,
594
- dirs: ["components", "composables", "hooks", "utils"]
595
- };
596
- return defu(config.imports, defaultOptions);
597
- }
598
-
599
576
  // src/core/utils/globals.ts
600
577
  function getGlobals(config) {
601
578
  return [
@@ -695,9 +672,12 @@ function parseI18nMessages(messagesJson) {
695
672
  async function generateTypesDir(entrypoints) {
696
673
  await fs4.ensureDir(wxt.config.typesDir);
697
674
  const references = [];
698
- const imports = getUnimportOptions(wxt.config);
699
- if (imports !== false) {
700
- references.push(await writeImportsDeclarationFile(imports));
675
+ if (wxt.config.imports !== false) {
676
+ const unimport2 = createUnimport(wxt.config.imports);
677
+ references.push(await writeImportsDeclarationFile(unimport2));
678
+ if (wxt.config.imports.eslintrc.enabled) {
679
+ await writeImportsEslintFile(unimport2, wxt.config.imports);
680
+ }
701
681
  }
702
682
  references.push(await writePathsDeclarationFile(entrypoints));
703
683
  references.push(await writeI18nDeclarationFile());
@@ -705,9 +685,8 @@ async function generateTypesDir(entrypoints) {
705
685
  const mainReference = await writeMainDeclarationFile(references);
706
686
  await writeTsConfigFile(mainReference);
707
687
  }
708
- async function writeImportsDeclarationFile(unimportOptions) {
688
+ async function writeImportsDeclarationFile(unimport2) {
709
689
  const filePath = resolve4(wxt.config.typesDir, "imports.d.ts");
710
- const unimport2 = createUnimport(unimportOptions);
711
690
  await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
712
691
  await writeFileIfDifferent(
713
692
  filePath,
@@ -717,6 +696,14 @@ async function writeImportsDeclarationFile(unimportOptions) {
717
696
  );
718
697
  return filePath;
719
698
  }
699
+ async function writeImportsEslintFile(unimport2, options) {
700
+ const globals2 = {};
701
+ const eslintrc = { globals: globals2 };
702
+ (await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
703
+ eslintrc.globals[name] = options.eslintrc.globalsPropValue;
704
+ });
705
+ await fs4.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
706
+ }
720
707
  async function writePathsDeclarationFile(entrypoints) {
721
708
  const filePath = resolve4(wxt.config.typesDir, "paths.d.ts");
722
709
  const unions = entrypoints.map(
@@ -1206,7 +1193,7 @@ var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
1206
1193
  ".svelte"
1207
1194
  ]);
1208
1195
  function unimport(config) {
1209
- const options = getUnimportOptions(config);
1196
+ const options = config.imports;
1210
1197
  if (options === false)
1211
1198
  return [];
1212
1199
  const unimport2 = createUnimport2(options);
@@ -1324,7 +1311,10 @@ var increment = 0;
1324
1311
  function bundleAnalysis(config) {
1325
1312
  return visualizer({
1326
1313
  template: "raw-data",
1327
- filename: path3.resolve(config.outDir, `stats-${increment++}.json`)
1314
+ filename: path3.resolve(
1315
+ config.analysis.outputDir,
1316
+ `${config.analysis.outputName}-${increment++}.json`
1317
+ )
1328
1318
  });
1329
1319
  }
1330
1320
 
@@ -1641,7 +1631,27 @@ function getRollupEntry(entrypoint) {
1641
1631
  }
1642
1632
 
1643
1633
  // src/core/utils/building/resolve-config.ts
1644
- import defu2 from "defu";
1634
+ import defu from "defu";
1635
+
1636
+ // src/core/utils/package.ts
1637
+ import { resolve as resolve9 } from "node:path";
1638
+ import fs8 from "fs-extra";
1639
+ async function getPackageJson() {
1640
+ const file = resolve9(wxt.config.root, "package.json");
1641
+ try {
1642
+ return await fs8.readJson(file);
1643
+ } catch (err) {
1644
+ wxt.logger.debug(
1645
+ `Failed to read package.json at: ${file}. Returning undefined.`
1646
+ );
1647
+ return {};
1648
+ }
1649
+ }
1650
+ function isModuleInstalled(name) {
1651
+ return import(name).then(() => true).catch(() => false);
1652
+ }
1653
+
1654
+ // src/core/utils/building/resolve-config.ts
1645
1655
  async function resolveConfig(inlineConfig, command, server) {
1646
1656
  let userConfig = {};
1647
1657
  let userConfigMetadata;
@@ -1698,6 +1708,12 @@ async function resolveConfig(inlineConfig, command, server) {
1698
1708
  "~~": root
1699
1709
  }).map(([key, value]) => [key, path5.resolve(root, value)])
1700
1710
  );
1711
+ const analysisOutputFile = path5.resolve(
1712
+ root,
1713
+ mergedConfig.analysis?.outputFile ?? "stats.html"
1714
+ );
1715
+ const analysisOutputDir = path5.dirname(analysisOutputFile);
1716
+ const analysisOutputName = path5.parse(analysisOutputFile).name;
1701
1717
  const finalConfig = {
1702
1718
  browser,
1703
1719
  command,
@@ -1706,7 +1722,7 @@ async function resolveConfig(inlineConfig, command, server) {
1706
1722
  filterEntrypoints,
1707
1723
  env,
1708
1724
  fsCache: createFsCache(wxtDir),
1709
- imports: mergedConfig.imports ?? {},
1725
+ imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
1710
1726
  logger,
1711
1727
  manifest: await resolveManifestConfig(env, mergedConfig.manifest),
1712
1728
  manifestVersion,
@@ -1727,10 +1743,10 @@ async function resolveConfig(inlineConfig, command, server) {
1727
1743
  analysis: {
1728
1744
  enabled: mergedConfig.analysis?.enabled ?? false,
1729
1745
  template: mergedConfig.analysis?.template ?? "treemap",
1730
- outputFile: path5.resolve(
1731
- root,
1732
- mergedConfig.analysis?.outputFile ?? "stats.html"
1733
- )
1746
+ outputFile: analysisOutputFile,
1747
+ outputDir: analysisOutputDir,
1748
+ outputName: analysisOutputName,
1749
+ keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
1734
1750
  },
1735
1751
  userConfigMetadata: userConfigMetadata ?? {},
1736
1752
  alias,
@@ -1763,22 +1779,22 @@ function mergeInlineConfig(inlineConfig, userConfig) {
1763
1779
  } else if (userConfig.imports == null && inlineConfig.imports == null) {
1764
1780
  imports = void 0;
1765
1781
  } else {
1766
- imports = defu2(inlineConfig.imports ?? {}, userConfig.imports ?? {});
1782
+ imports = defu(inlineConfig.imports ?? {}, userConfig.imports ?? {});
1767
1783
  }
1768
1784
  const manifest = async (env) => {
1769
1785
  const user = await resolveManifestConfig(env, userConfig.manifest);
1770
1786
  const inline = await resolveManifestConfig(env, inlineConfig.manifest);
1771
- return defu2(inline, user);
1787
+ return defu(inline, user);
1772
1788
  };
1773
- const runner = defu2(
1789
+ const runner = defu(
1774
1790
  inlineConfig.runner ?? {},
1775
1791
  userConfig.runner ?? {}
1776
1792
  );
1777
- const zip = defu2(
1793
+ const zip = defu(
1778
1794
  inlineConfig.zip ?? {},
1779
1795
  userConfig.zip ?? {}
1780
1796
  );
1781
- const hooks = defu2(
1797
+ const hooks = defu(
1782
1798
  inlineConfig.hooks ?? {},
1783
1799
  userConfig.hooks ?? {}
1784
1800
  );
@@ -1842,6 +1858,44 @@ function resolveInternalZipConfig(root, mergedConfig) {
1842
1858
  ]
1843
1859
  };
1844
1860
  }
1861
+ async function getUnimportOptions(wxtDir, logger, config) {
1862
+ if (config.imports === false)
1863
+ return false;
1864
+ const enabledConfig = config.imports?.eslintrc?.enabled;
1865
+ let enabled;
1866
+ switch (enabledConfig) {
1867
+ case void 0:
1868
+ case "auto":
1869
+ enabled = await isModuleInstalled("eslint");
1870
+ break;
1871
+ default:
1872
+ enabled = enabledConfig;
1873
+ }
1874
+ const defaultOptions = {
1875
+ debugLog: logger.debug,
1876
+ imports: [
1877
+ { name: "defineConfig", from: "wxt" },
1878
+ { name: "fakeBrowser", from: "wxt/testing" }
1879
+ ],
1880
+ presets: [
1881
+ { package: "wxt/client" },
1882
+ { package: "wxt/browser" },
1883
+ { package: "wxt/sandbox" },
1884
+ { package: "wxt/storage" }
1885
+ ],
1886
+ warn: logger.warn,
1887
+ dirs: ["components", "composables", "hooks", "utils"],
1888
+ eslintrc: {
1889
+ enabled,
1890
+ filePath: path5.resolve(wxtDir, "eslintrc-auto-import.json"),
1891
+ globalsPropValue: true
1892
+ }
1893
+ };
1894
+ return defu(
1895
+ config.imports ?? {},
1896
+ defaultOptions
1897
+ );
1898
+ }
1845
1899
 
1846
1900
  // src/core/utils/building/group-entrypoints.ts
1847
1901
  function groupEntrypoints(entrypoints) {
@@ -1885,8 +1939,8 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
1885
1939
  // src/core/utils/building/import-entrypoint.ts
1886
1940
  import createJITI from "jiti";
1887
1941
  import { createUnimport as createUnimport3 } from "unimport";
1888
- import fs8 from "fs-extra";
1889
- import { relative as relative5, resolve as resolve9 } from "node:path";
1942
+ import fs9 from "fs-extra";
1943
+ import { relative as relative5, resolve as resolve10 } from "node:path";
1890
1944
 
1891
1945
  // src/core/utils/strings.ts
1892
1946
  function kebabCaseAlphanumeric(str) {
@@ -1912,12 +1966,12 @@ async function importEntrypointFile(path7) {
1912
1966
  wxt.logger.debug("Loading file metadata:", path7);
1913
1967
  const normalPath = normalizePath(path7);
1914
1968
  const unimport2 = createUnimport3({
1915
- ...getUnimportOptions(wxt.config),
1969
+ ...wxt.config.imports,
1916
1970
  // Only allow specific imports, not all from the project
1917
1971
  dirs: []
1918
1972
  });
1919
1973
  await unimport2.init();
1920
- const text = await fs8.readFile(path7, "utf-8");
1974
+ const text = await fs9.readFile(path7, "utf-8");
1921
1975
  const textNoImports = removeProjectImportStatements(text);
1922
1976
  const { code } = await unimport2.injectImports(textNoImports);
1923
1977
  wxt.logger.debug(
@@ -1930,7 +1984,7 @@ async function importEntrypointFile(path7) {
1930
1984
  debug: wxt.config.debug,
1931
1985
  esmResolve: true,
1932
1986
  alias: {
1933
- "webextension-polyfill": resolve9(
1987
+ "webextension-polyfill": resolve10(
1934
1988
  wxt.config.root,
1935
1989
  "node_modules/wxt/dist/virtual/mock-browser.js"
1936
1990
  )
@@ -1990,12 +2044,12 @@ import pc5 from "picocolors";
1990
2044
  import fs12 from "fs-extra";
1991
2045
 
1992
2046
  // src/core/utils/log/printBuildSummary.ts
1993
- import { resolve as resolve10 } from "path";
2047
+ import { resolve as resolve11 } from "path";
1994
2048
 
1995
2049
  // src/core/utils/log/printFileList.ts
1996
2050
  import path6 from "node:path";
1997
2051
  import pc3 from "picocolors";
1998
- import fs9 from "fs-extra";
2052
+ import fs10 from "fs-extra";
1999
2053
  import { filesize } from "filesize";
2000
2054
 
2001
2055
  // src/core/utils/log/printTable.ts
@@ -2036,7 +2090,7 @@ async function printFileList(log, header, baseDir, files) {
2036
2090
  ];
2037
2091
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
2038
2092
  const color = getChunkColor(file);
2039
- const stats = await fs9.lstat(file);
2093
+ const stats = await fs10.lstat(file);
2040
2094
  totalSize += stats.size;
2041
2095
  const size = String(filesize(stats.size));
2042
2096
  return [
@@ -2078,7 +2132,7 @@ async function printBuildSummary(log, header, output) {
2078
2132
  return l.fileName.localeCompare(r.fileName);
2079
2133
  });
2080
2134
  const files = chunks.map(
2081
- (chunk) => resolve10(wxt.config.outDir, chunk.fileName)
2135
+ (chunk) => resolve11(wxt.config.outDir, chunk.fileName)
2082
2136
  );
2083
2137
  await printFileList(log, header, wxt.config.outDir, files);
2084
2138
  }
@@ -2208,23 +2262,8 @@ function mapWxtOptionsToContentScript(options) {
2208
2262
  };
2209
2263
  }
2210
2264
 
2211
- // src/core/utils/package.ts
2212
- import { resolve as resolve11 } from "node:path";
2213
- import fs10 from "fs-extra";
2214
- async function getPackageJson() {
2215
- const file = resolve11(wxt.config.root, "package.json");
2216
- try {
2217
- return await fs10.readJson(file);
2218
- } catch (err) {
2219
- wxt.logger.debug(
2220
- `Failed to read package.json at: ${file}. Returning undefined.`
2221
- );
2222
- return {};
2223
- }
2224
- }
2225
-
2226
2265
  // src/core/utils/manifest.ts
2227
- import defu3 from "defu";
2266
+ import defu2 from "defu";
2228
2267
  async function writeManifest(manifest, output) {
2229
2268
  const str = wxt.config.mode === "production" ? JSON.stringify(manifest) : JSON.stringify(manifest, null, 2);
2230
2269
  await fs11.ensureDir(wxt.config.outDir);
@@ -2254,7 +2293,7 @@ async function generateManifest(entrypoints, buildOutput) {
2254
2293
  icons: discoverIcons(buildOutput)
2255
2294
  };
2256
2295
  const userManifest = wxt.config.manifest;
2257
- let manifest = defu3(
2296
+ let manifest = defu2(
2258
2297
  userManifest,
2259
2298
  baseManifest
2260
2299
  );
@@ -2833,8 +2872,8 @@ async function internalBuild() {
2833
2872
  return output;
2834
2873
  }
2835
2874
  async function combineAnalysisStats() {
2836
- const unixFiles = await glob3(`stats-*.json`, {
2837
- cwd: wxt.config.outDir,
2875
+ const unixFiles = await glob3(`${wxt.config.analysis.outputName}-*.json`, {
2876
+ cwd: wxt.config.analysis.outputDir,
2838
2877
  absolute: true
2839
2878
  });
2840
2879
  const absolutePaths = unixFiles.map(unnormalizePath);
@@ -2849,7 +2888,9 @@ async function combineAnalysisStats() {
2849
2888
  ],
2850
2889
  { cwd: wxt.config.root, stdio: "inherit" }
2851
2890
  );
2852
- await Promise.all(absolutePaths.map((statsFile) => fs12.remove(statsFile)));
2891
+ if (!wxt.config.analysis.keepArtifacts) {
2892
+ await Promise.all(absolutePaths.map((statsFile) => fs12.remove(statsFile)));
2893
+ }
2853
2894
  }
2854
2895
  function printValidationResults({
2855
2896
  errorCount,
@@ -2912,11 +2953,11 @@ export {
2912
2953
  tsconfigPaths,
2913
2954
  globals,
2914
2955
  webextensionPolyfillMock,
2956
+ getPackageJson,
2915
2957
  resolveConfig,
2916
2958
  kebabCaseAlphanumeric,
2917
2959
  printFileList,
2918
2960
  version,
2919
- getPackageJson,
2920
2961
  getContentScriptCssFiles,
2921
2962
  getContentScriptsCssMap,
2922
2963
  rebuild,