wxt 0.18.9 → 0.18.11

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.
@@ -3,6 +3,10 @@ import {
3
3
  some,
4
4
  toArray
5
5
  } from "./chunk-BERPNPEZ.js";
6
+ import {
7
+ addViteConfig,
8
+ defineWxtModule
9
+ } from "./chunk-6XSIWUWF.js";
6
10
  import {
7
11
  LogLevels,
8
12
  consola
@@ -12,7 +16,7 @@ import {
12
16
  } from "./chunk-QGM4M3NI.js";
13
17
 
14
18
  // package.json
15
- var version = "0.18.8";
19
+ var version = "0.18.10";
16
20
 
17
21
  // src/core/utils/paths.ts
18
22
  import systemPath from "node:path";
@@ -128,38 +132,6 @@ function download(config) {
128
132
  };
129
133
  }
130
134
 
131
- // src/core/builders/vite/plugins/unimport.ts
132
- import { createUnimport } from "unimport";
133
- import { extname } from "path";
134
- var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
135
- ".js",
136
- ".jsx",
137
- ".ts",
138
- ".tsx",
139
- ".vue",
140
- ".svelte"
141
- ]);
142
- function unimport(config) {
143
- const options = config.imports;
144
- if (options === false) return [];
145
- const unimport2 = createUnimport(options);
146
- return {
147
- name: "wxt:unimport",
148
- async config() {
149
- await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
150
- },
151
- async transform(code, id) {
152
- if (id.includes("node_modules")) return;
153
- if (!ENABLED_EXTENSIONS.has(extname(id))) return;
154
- const injected = await unimport2.injectImports(code, id);
155
- return {
156
- code: injected.code,
157
- map: injected.s.generateMap({ hires: "boundary", source: id })
158
- };
159
- }
160
- };
161
- }
162
-
163
135
  // src/core/builders/vite/plugins/tsconfigPaths.ts
164
136
  function tsconfigPaths(config) {
165
137
  return {
@@ -428,7 +400,7 @@ function devServerGlobals(config, server) {
428
400
  }
429
401
 
430
402
  // src/core/builders/vite/plugins/multipageMove.ts
431
- import { dirname as dirname2, extname as extname2, resolve as resolve3, join } from "node:path";
403
+ import { dirname as dirname2, extname, resolve as resolve3, join } from "node:path";
432
404
  import fs, { ensureDir } from "fs-extra";
433
405
  function multipageMove(entrypoints, config) {
434
406
  return {
@@ -447,7 +419,7 @@ function multipageMove(entrypoints, config) {
447
419
  const newBundlePath = getEntrypointBundlePath(
448
420
  entrypoint,
449
421
  config.outDir,
450
- extname2(oldBundlePath)
422
+ extname(oldBundlePath)
451
423
  );
452
424
  if (newBundlePath === oldBundlePath) {
453
425
  config.logger.debug(
@@ -751,6 +723,105 @@ function removeProjectImportStatements(text) {
751
723
  ${noImports}`;
752
724
  }
753
725
 
726
+ // src/builtin-modules/unimport.ts
727
+ import { createUnimport } from "unimport";
728
+ import { extname as extname2 } from "node:path";
729
+ var unimport_default = defineWxtModule({
730
+ name: "wxt:built-in:unimport",
731
+ setup(wxt2) {
732
+ const options = wxt2.config.imports;
733
+ if (options === false) return;
734
+ let unimport;
735
+ wxt2.hooks.hook("ready", () => {
736
+ const addModuleImports = (module) => {
737
+ if (!module.imports) return;
738
+ options.imports ??= [];
739
+ options.imports.push(...module.imports);
740
+ };
741
+ wxt2.config.builtinModules.forEach(addModuleImports);
742
+ wxt2.config.userModules.forEach(addModuleImports);
743
+ });
744
+ wxt2.hooks.afterEach((event) => {
745
+ if (event.name === "ready") {
746
+ unimport = createUnimport(options);
747
+ }
748
+ });
749
+ wxt2.hooks.hook("prepare:types", async (_, entries) => {
750
+ await unimport.init();
751
+ entries.push(await getImportsDeclarationEntry(unimport));
752
+ if (options.eslintrc.enabled === false) return;
753
+ entries.push(
754
+ await getEslintConfigEntry(unimport, options.eslintrc.enabled, options)
755
+ );
756
+ });
757
+ addViteConfig(wxt2, () => ({
758
+ plugins: [vitePlugin(unimport)]
759
+ }));
760
+ }
761
+ });
762
+ function vitePlugin(unimport) {
763
+ const ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
764
+ ".js",
765
+ ".jsx",
766
+ ".ts",
767
+ ".tsx",
768
+ ".vue",
769
+ ".svelte"
770
+ ]);
771
+ return {
772
+ name: "wxt:unimport",
773
+ async transform(code, id) {
774
+ if (id.includes("node_modules")) return;
775
+ if (!ENABLED_EXTENSIONS.has(extname2(id))) return;
776
+ const injected = await unimport.injectImports(code, id);
777
+ return {
778
+ code: injected.code,
779
+ map: injected.s.generateMap({ hires: "boundary", source: id })
780
+ };
781
+ }
782
+ };
783
+ }
784
+ async function getImportsDeclarationEntry(unimport) {
785
+ await unimport.init();
786
+ return {
787
+ path: "types/imports.d.ts",
788
+ text: [
789
+ "// Generated by wxt",
790
+ await unimport.generateTypeDeclarations(),
791
+ ""
792
+ ].join("\n"),
793
+ tsReference: true
794
+ };
795
+ }
796
+ async function getEslintConfigEntry(unimport, version2, options) {
797
+ const globals2 = (await unimport.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().reduce((globals3, name) => {
798
+ globals3[name] = options.eslintrc.globalsPropValue;
799
+ return globals3;
800
+ }, {});
801
+ if (version2 <= 8) return getEslint8ConfigEntry(options, globals2);
802
+ else return getEslint9ConfigEntry(options, globals2);
803
+ }
804
+ function getEslint8ConfigEntry(options, globals2) {
805
+ return {
806
+ path: options.eslintrc.filePath,
807
+ text: JSON.stringify({ globals: globals2 }, null, 2) + "\n"
808
+ };
809
+ }
810
+ function getEslint9ConfigEntry(options, globals2) {
811
+ return {
812
+ path: options.eslintrc.filePath,
813
+ text: `const globals = ${JSON.stringify(globals2, null, 2)}
814
+
815
+ export default {
816
+ languageOptions: {
817
+ globals,
818
+ sourceType: "module",
819
+ },
820
+ };
821
+ `
822
+ };
823
+ }
824
+
754
825
  // src/core/utils/fs.ts
755
826
  import fs3 from "fs-extra";
756
827
  import glob from "fast-glob";
@@ -796,13 +867,17 @@ async function copyPublicDirectory() {
796
867
  await wxt.hooks.callHook("build:publicAssets", wxt, files);
797
868
  if (files.length === 0) return [];
798
869
  const publicAssets = [];
799
- for (const { absoluteSrc, relativeDest } of files) {
800
- const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
870
+ for (const file of files) {
871
+ const absoluteDest = resolve6(wxt.config.outDir, file.relativeDest);
801
872
  await fs4.ensureDir(dirname3(absoluteDest));
802
- await fs4.copyFile(absoluteSrc, absoluteDest);
873
+ if ("absoluteSrc" in file) {
874
+ await fs4.copyFile(file.absoluteSrc, absoluteDest);
875
+ } else {
876
+ await fs4.writeFile(absoluteDest, file.contents, "utf8");
877
+ }
803
878
  publicAssets.push({
804
879
  type: "asset",
805
- fileName: relativeDest
880
+ fileName: file.relativeDest
806
881
  });
807
882
  }
808
883
  return publicAssets;
@@ -1281,9 +1356,8 @@ var PATH_GLOB_TO_TYPE_MAP = {
1281
1356
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1282
1357
 
1283
1358
  // src/core/utils/building/generate-wxt-dir.ts
1284
- import { createUnimport as createUnimport2 } from "unimport";
1285
1359
  import fs6 from "fs-extra";
1286
- import { relative as relative4, resolve as resolve8 } from "path";
1360
+ import { dirname as dirname4, relative as relative4, resolve as resolve8 } from "node:path";
1287
1361
  import path4 from "node:path";
1288
1362
 
1289
1363
  // src/core/utils/i18n.ts
@@ -1326,41 +1400,32 @@ function parseI18nMessages(messagesJson) {
1326
1400
  // src/core/utils/building/generate-wxt-dir.ts
1327
1401
  async function generateTypesDir(entrypoints) {
1328
1402
  await fs6.ensureDir(wxt.config.typesDir);
1329
- const references = [];
1330
- if (wxt.config.imports !== false) {
1331
- const unimport2 = createUnimport2(wxt.config.imports);
1332
- references.push(await writeImportsDeclarationFile(unimport2));
1333
- if (wxt.config.imports.eslintrc.enabled) {
1334
- await writeImportsEslintFile(unimport2, wxt.config.imports);
1335
- }
1336
- }
1337
- references.push(await writePathsDeclarationFile(entrypoints));
1338
- references.push(await writeI18nDeclarationFile());
1339
- references.push(await writeGlobalsDeclarationFile());
1340
- const mainReference = await writeMainDeclarationFile(references);
1341
- await writeTsConfigFile(mainReference);
1342
- }
1343
- async function writeImportsDeclarationFile(unimport2) {
1344
- const filePath = resolve8(wxt.config.typesDir, "imports.d.ts");
1345
- await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
1346
- await writeFileIfDifferent(
1347
- filePath,
1348
- ["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
1349
- "\n"
1350
- ) + "\n"
1351
- );
1352
- return filePath;
1353
- }
1354
- async function writeImportsEslintFile(unimport2, options) {
1355
- const globals2 = {};
1356
- const eslintrc = { globals: globals2 };
1357
- (await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
1358
- eslintrc.globals[name] = options.eslintrc.globalsPropValue;
1403
+ const entries = [
1404
+ // Hard-coded entries
1405
+ { module: "wxt/vite-builder-env" }
1406
+ ];
1407
+ wxt.config.userModules.forEach((module) => {
1408
+ if (module.type === "node_module" && module.configKey != null)
1409
+ entries.push({ module: module.id });
1359
1410
  });
1360
- await fs6.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1411
+ entries.push(await getPathsDeclarationEntry(entrypoints));
1412
+ entries.push(await getI18nDeclarationEntry());
1413
+ entries.push(await getGlobalsDeclarationEntry());
1414
+ entries.push(await getTsConfigEntry());
1415
+ await wxt.hooks.callHook("prepare:types", wxt, entries);
1416
+ entries.push(getMainDeclarationEntry(entries));
1417
+ const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
1418
+ ...entry,
1419
+ path: resolve8(wxt.config.wxtDir, entry.path)
1420
+ }));
1421
+ await Promise.all(
1422
+ absoluteFileEntries.map(async (file) => {
1423
+ await fs6.ensureDir(dirname4(file.path));
1424
+ await writeFileIfDifferent(file.path, file.text);
1425
+ })
1426
+ );
1361
1427
  }
1362
- async function writePathsDeclarationFile(entrypoints) {
1363
- const filePath = resolve8(wxt.config.typesDir, "paths.d.ts");
1428
+ async function getPathsDeclarationEntry(entrypoints) {
1364
1429
  const unions = entrypoints.map(
1365
1430
  (entry) => getEntrypointBundlePath(
1366
1431
  entry,
@@ -1381,14 +1446,13 @@ declare module "wxt/browser" {
1381
1446
  }
1382
1447
  }
1383
1448
  `;
1384
- await writeFileIfDifferent(
1385
- filePath,
1386
- template.replace("{{ union }}", unions || " | never")
1387
- );
1388
- return filePath;
1449
+ return {
1450
+ path: "types/paths.d.ts",
1451
+ text: template.replace("{{ union }}", unions || " | never"),
1452
+ tsReference: true
1453
+ };
1389
1454
  }
1390
- async function writeI18nDeclarationFile() {
1391
- const filePath = resolve8(wxt.config.typesDir, "i18n.d.ts");
1455
+ async function getI18nDeclarationEntry() {
1392
1456
  const defaultLocale = wxt.config.manifest.default_locale;
1393
1457
  const template = `// Generated by wxt
1394
1458
  import "wxt/browser";
@@ -1434,18 +1498,17 @@ declare module "wxt/browser" {
1434
1498
  options?: GetMessageOptions,
1435
1499
  ): string;`;
1436
1500
  });
1437
- await writeFileIfDifferent(
1438
- filePath,
1439
- template.replace("{{ overrides }}", overrides.join("\n"))
1440
- );
1441
- return filePath;
1501
+ return {
1502
+ path: "types/i18n.d.ts",
1503
+ text: template.replace("{{ overrides }}", overrides.join("\n")),
1504
+ tsReference: true
1505
+ };
1442
1506
  }
1443
- async function writeGlobalsDeclarationFile() {
1444
- const filePath = resolve8(wxt.config.typesDir, "globals.d.ts");
1507
+ async function getGlobalsDeclarationEntry() {
1445
1508
  const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
1446
- await writeFileIfDifferent(
1447
- filePath,
1448
- [
1509
+ return {
1510
+ path: "types/globals.d.ts",
1511
+ text: [
1449
1512
  "// Generated by wxt",
1450
1513
  "export {}",
1451
1514
  "interface ImportMetaEnv {",
@@ -1453,34 +1516,29 @@ async function writeGlobalsDeclarationFile() {
1453
1516
  "}",
1454
1517
  "interface ImportMeta {",
1455
1518
  " readonly env: ImportMetaEnv",
1456
- "}"
1457
- ].join("\n") + "\n"
1458
- );
1459
- return filePath;
1519
+ "}",
1520
+ ""
1521
+ ].join("\n"),
1522
+ tsReference: true
1523
+ };
1460
1524
  }
1461
- async function writeMainDeclarationFile(references) {
1462
- const dir = wxt.config.wxtDir;
1463
- const filePath = resolve8(dir, "wxt.d.ts");
1464
- await writeFileIfDifferent(
1465
- filePath,
1466
- [
1467
- "// Generated by wxt",
1468
- `/// <reference types="wxt/vite-builder-env" />`,
1469
- ...references.map(
1470
- (ref) => `/// <reference types="./${normalizePath(relative4(dir, ref))}" />`
1471
- ),
1472
- // Add references to modules installed from NPM to the TS project so
1473
- // their type augmentation can update InlineConfig correctly. Local
1474
- // modules defined in <root>/modules are already apart of the project, so
1475
- // we don't need to add them.
1476
- ...wxt.config.modules.filter(
1477
- (module) => module.type === "node_module" && module.configKey != null
1478
- ).map((module) => `/// <reference types="${module.id}" />`)
1479
- ].join("\n") + "\n"
1480
- );
1481
- return filePath;
1525
+ function getMainDeclarationEntry(references) {
1526
+ const lines = ["// Generated by wxt"];
1527
+ references.forEach((ref) => {
1528
+ if ("module" in ref) {
1529
+ return lines.push(`/// <reference types="${ref.module}" />`);
1530
+ } else if (ref.tsReference) {
1531
+ const absolutePath = resolve8(wxt.config.wxtDir, ref.path);
1532
+ const relativePath = relative4(wxt.config.wxtDir, absolutePath);
1533
+ lines.push(`/// <reference types="./${normalizePath(relativePath)}" />`);
1534
+ }
1535
+ });
1536
+ return {
1537
+ path: "wxt.d.ts",
1538
+ text: lines.join("\n") + "\n"
1539
+ };
1482
1540
  }
1483
- async function writeTsConfigFile(mainReference) {
1541
+ async function getTsConfigEntry() {
1484
1542
  const dir = wxt.config.wxtDir;
1485
1543
  const getTsconfigPath = (path8) => normalizePath(relative4(dir, path8));
1486
1544
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
@@ -1490,9 +1548,7 @@ async function writeTsConfigFile(mainReference) {
1490
1548
  ` "${alias}/*": ["${aliasPath}/*"]`
1491
1549
  ];
1492
1550
  }).join(",\n");
1493
- await writeFileIfDifferent(
1494
- resolve8(dir, "tsconfig.json"),
1495
- `{
1551
+ const text = `{
1496
1552
  "compilerOptions": {
1497
1553
  "target": "ESNext",
1498
1554
  "module": "ESNext",
@@ -1509,11 +1565,14 @@ ${paths}
1509
1565
  },
1510
1566
  "include": [
1511
1567
  "${getTsconfigPath(wxt.config.root)}/**/*",
1512
- "./${getTsconfigPath(mainReference)}"
1568
+ "./wxt.d.ts"
1513
1569
  ],
1514
1570
  "exclude": ["${getTsconfigPath(wxt.config.outBaseDir)}"]
1515
- }`
1516
- );
1571
+ }`;
1572
+ return {
1573
+ path: "tsconfig.json",
1574
+ text
1575
+ };
1517
1576
  }
1518
1577
 
1519
1578
  // src/core/utils/building/resolve-config.ts
@@ -1522,13 +1581,13 @@ import path5 from "node:path";
1522
1581
 
1523
1582
  // src/core/utils/cache.ts
1524
1583
  import fs7, { ensureDir as ensureDir2 } from "fs-extra";
1525
- import { dirname as dirname4, resolve as resolve9 } from "path";
1584
+ import { dirname as dirname5, resolve as resolve9 } from "path";
1526
1585
  function createFsCache(wxtDir) {
1527
1586
  const getPath = (key) => resolve9(wxtDir, "cache", encodeURIComponent(key));
1528
1587
  return {
1529
1588
  async set(key, value) {
1530
1589
  const path8 = getPath(key);
1531
- await ensureDir2(dirname4(path8));
1590
+ await ensureDir2(dirname5(path8));
1532
1591
  await writeFileIfDifferent(path8, value);
1533
1592
  },
1534
1593
  async get(key) {
@@ -1544,31 +1603,26 @@ function createFsCache(wxtDir) {
1544
1603
 
1545
1604
  // src/core/utils/building/resolve-config.ts
1546
1605
  import defu from "defu";
1547
-
1548
- // src/core/utils/package.ts
1549
- import { resolve as resolve10 } from "node:path";
1550
1606
  import fs8 from "fs-extra";
1551
- async function getPackageJson() {
1552
- const file = resolve10(wxt.config.root, "package.json");
1607
+ import glob3 from "fast-glob";
1608
+
1609
+ // src/builtin-modules/index.ts
1610
+ var builtinModules = [unimport_default];
1611
+
1612
+ // src/core/utils/eslint.ts
1613
+ async function getEslintVersion() {
1553
1614
  try {
1554
- return await fs8.readJson(file);
1555
- } catch (err) {
1556
- wxt.logger.debug(
1557
- `Failed to read package.json at: ${file}. Returning undefined.`
1615
+ const require2 = (await import("node:module")).default.createRequire(
1616
+ import.meta.url
1558
1617
  );
1559
- return {};
1618
+ const { ESLint } = require2("eslint");
1619
+ return ESLint.version?.split(".") ?? [];
1620
+ } catch (error) {
1621
+ return [];
1560
1622
  }
1561
1623
  }
1562
- function isModuleInstalled(name) {
1563
- return import(
1564
- /* @vite-ignore */
1565
- name
1566
- ).then(() => true).catch(() => false);
1567
- }
1568
1624
 
1569
1625
  // src/core/utils/building/resolve-config.ts
1570
- import fs9 from "fs-extra";
1571
- import glob3 from "fast-glob";
1572
1626
  async function resolveConfig(inlineConfig, command) {
1573
1627
  let userConfig = {};
1574
1628
  let userConfigMetadata;
@@ -1645,14 +1699,20 @@ async function resolveConfig(inlineConfig, command) {
1645
1699
  hostname: "localhost"
1646
1700
  };
1647
1701
  }
1648
- const modules = await resolveWxtModules(modulesDir, mergedConfig.modules);
1649
- const moduleOptions = modules.reduce((map, module) => {
1650
- if (module.configKey) {
1651
- map[module.configKey] = // @ts-expect-error
1652
- mergedConfig[module.configKey];
1653
- }
1654
- return map;
1655
- }, {});
1702
+ const userModules = await resolveWxtUserModules(
1703
+ modulesDir,
1704
+ mergedConfig.modules
1705
+ );
1706
+ const moduleOptions = userModules.reduce(
1707
+ (map, module) => {
1708
+ if (module.configKey) {
1709
+ map[module.configKey] = // @ts-expect-error
1710
+ mergedConfig[module.configKey];
1711
+ }
1712
+ return map;
1713
+ },
1714
+ {}
1715
+ );
1656
1716
  return {
1657
1717
  browser,
1658
1718
  command,
@@ -1662,7 +1722,7 @@ async function resolveConfig(inlineConfig, command) {
1662
1722
  filterEntrypoints,
1663
1723
  env,
1664
1724
  fsCache: createFsCache(wxtDir),
1665
- imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
1725
+ imports: await getUnimportOptions(wxtDir, srcDir, logger, mergedConfig),
1666
1726
  logger,
1667
1727
  manifest: await resolveManifestConfig(env, mergedConfig.manifest),
1668
1728
  manifestVersion,
@@ -1676,7 +1736,7 @@ async function resolveConfig(inlineConfig, command) {
1676
1736
  srcDir,
1677
1737
  typesDir,
1678
1738
  wxtDir,
1679
- zip: resolveZipConfig(root, mergedConfig),
1739
+ zip: resolveZipConfig(root, outBaseDir, mergedConfig),
1680
1740
  transformManifest: mergedConfig.transformManifest,
1681
1741
  analysis: resolveAnalysisConfig(root, mergedConfig),
1682
1742
  userConfigMetadata: userConfigMetadata ?? {},
@@ -1691,7 +1751,8 @@ async function resolveConfig(inlineConfig, command) {
1691
1751
  },
1692
1752
  hooks: mergedConfig.hooks ?? {},
1693
1753
  vite: mergedConfig.vite ?? (() => ({})),
1694
- modules,
1754
+ builtinModules,
1755
+ userModules,
1695
1756
  plugins: [],
1696
1757
  ...moduleOptions
1697
1758
  };
@@ -1720,7 +1781,7 @@ async function mergeInlineConfig(inlineConfig, userConfig) {
1720
1781
  ...builderConfig
1721
1782
  };
1722
1783
  }
1723
- function resolveZipConfig(root, mergedConfig) {
1784
+ function resolveZipConfig(root, outBaseDir, mergedConfig) {
1724
1785
  const downloadedPackagesDir = path5.resolve(root, ".wxt/local_modules");
1725
1786
  return {
1726
1787
  name: void 0,
@@ -1739,6 +1800,8 @@ function resolveZipConfig(root, mergedConfig) {
1739
1800
  // Tests
1740
1801
  "**/__tests__/**",
1741
1802
  "**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
1803
+ // Output directory
1804
+ `${path5.relative(root, outBaseDir)}/**`,
1742
1805
  // From user
1743
1806
  ...mergedConfig.zip?.excludeSources ?? []
1744
1807
  ],
@@ -1763,18 +1826,8 @@ function resolveAnalysisConfig(root, mergedConfig) {
1763
1826
  keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
1764
1827
  };
1765
1828
  }
1766
- async function getUnimportOptions(wxtDir, logger, config) {
1829
+ async function getUnimportOptions(wxtDir, srcDir, logger, config) {
1767
1830
  if (config.imports === false) return false;
1768
- const enabledConfig = config.imports?.eslintrc?.enabled;
1769
- let enabled;
1770
- switch (enabledConfig) {
1771
- case void 0:
1772
- case "auto":
1773
- enabled = await isModuleInstalled("eslint");
1774
- break;
1775
- default:
1776
- enabled = enabledConfig;
1777
- }
1778
1831
  const defaultOptions = {
1779
1832
  debugLog: logger.debug,
1780
1833
  imports: [
@@ -1789,23 +1842,48 @@ async function getUnimportOptions(wxtDir, logger, config) {
1789
1842
  ],
1790
1843
  warn: logger.warn,
1791
1844
  dirs: ["components", "composables", "hooks", "utils"],
1792
- eslintrc: {
1793
- enabled,
1794
- filePath: path5.resolve(wxtDir, "eslintrc-auto-import.json"),
1795
- globalsPropValue: true
1796
- }
1845
+ dirsScanOptions: {
1846
+ cwd: srcDir
1847
+ },
1848
+ eslintrc: await getUnimportEslintOptions(wxtDir, config.imports?.eslintrc)
1797
1849
  };
1798
1850
  return defu(
1799
1851
  config.imports ?? {},
1800
1852
  defaultOptions
1801
1853
  );
1802
1854
  }
1855
+ async function getUnimportEslintOptions(wxtDir, options) {
1856
+ const rawEslintEnabled = options?.enabled ?? "auto";
1857
+ let eslintEnabled;
1858
+ switch (rawEslintEnabled) {
1859
+ case "auto":
1860
+ const version2 = await getEslintVersion();
1861
+ let major = parseInt(version2[0]);
1862
+ if (major <= 8) eslintEnabled = 8;
1863
+ else if (major >= 9) eslintEnabled = 9;
1864
+ else eslintEnabled = 8;
1865
+ break;
1866
+ case true:
1867
+ eslintEnabled = 8;
1868
+ break;
1869
+ default:
1870
+ eslintEnabled = rawEslintEnabled;
1871
+ }
1872
+ return {
1873
+ enabled: eslintEnabled,
1874
+ filePath: path5.resolve(
1875
+ wxtDir,
1876
+ eslintEnabled === 9 ? "eslint-auto-imports.mjs" : "eslintrc-auto-import.json"
1877
+ ),
1878
+ globalsPropValue: true
1879
+ };
1880
+ }
1803
1881
  async function resolveWxtModuleDir() {
1804
1882
  const requireResolve = __require?.resolve ?? (await import("node:module")).default.createRequire(import.meta.url).resolve;
1805
1883
  return path5.resolve(requireResolve("wxt"), "../..");
1806
1884
  }
1807
1885
  async function isDirMissing(dir) {
1808
- return !await fs9.exists(dir);
1886
+ return !await fs8.exists(dir);
1809
1887
  }
1810
1888
  function logMissingDir(logger, name, expected) {
1811
1889
  logger.warn(
@@ -1831,7 +1909,7 @@ async function mergeBuilderConfig(inlineConfig, userConfig) {
1831
1909
  }
1832
1910
  throw Error("Builder not found. Make sure vite is installed.");
1833
1911
  }
1834
- async function resolveWxtModules(modulesDir, modules = []) {
1912
+ async function resolveWxtUserModules(modulesDir, modules = []) {
1835
1913
  const npmModules = await Promise.all(
1836
1914
  modules.map(async (moduleId) => {
1837
1915
  const mod = await import(
@@ -1919,23 +1997,23 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
1919
1997
 
1920
1998
  // src/core/utils/building/import-entrypoint.ts
1921
1999
  import createJITI from "jiti";
1922
- import { createUnimport as createUnimport3 } from "unimport";
1923
- import fs10 from "fs-extra";
1924
- import { relative as relative5, resolve as resolve11 } from "node:path";
2000
+ import { createUnimport as createUnimport2 } from "unimport";
2001
+ import fs9 from "fs-extra";
2002
+ import { relative as relative5, resolve as resolve10 } from "node:path";
1925
2003
  import { transformSync } from "esbuild";
1926
2004
  import { fileURLToPath } from "node:url";
1927
2005
  async function importEntrypointFile(path8) {
1928
2006
  wxt.logger.debug("Loading file metadata:", path8);
1929
2007
  const normalPath = normalizePath(path8);
1930
- const unimport2 = createUnimport3({
2008
+ const unimport = createUnimport2({
1931
2009
  ...wxt.config.imports,
1932
2010
  // Only allow specific imports, not all from the project
1933
2011
  dirs: []
1934
2012
  });
1935
- await unimport2.init();
1936
- const text = await fs10.readFile(path8, "utf-8");
2013
+ await unimport.init();
2014
+ const text = await fs9.readFile(path8, "utf-8");
1937
2015
  const textNoImports = removeProjectImportStatements(text);
1938
- const { code } = await unimport2.injectImports(textNoImports);
2016
+ const { code } = await unimport.injectImports(textNoImports);
1939
2017
  wxt.logger.debug(
1940
2018
  ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
1941
2019
  );
@@ -1946,7 +2024,7 @@ async function importEntrypointFile(path8) {
1946
2024
  debug: wxt.config.debug,
1947
2025
  esmResolve: true,
1948
2026
  alias: {
1949
- "webextension-polyfill": resolve11(
2027
+ "webextension-polyfill": resolve10(
1950
2028
  wxt.config.wxtModuleDir,
1951
2029
  "dist/virtual/mock-browser.js"
1952
2030
  )
@@ -2011,12 +2089,12 @@ import pc5 from "picocolors";
2011
2089
  import fs13 from "fs-extra";
2012
2090
 
2013
2091
  // src/core/utils/log/printBuildSummary.ts
2014
- import { resolve as resolve12 } from "path";
2092
+ import { resolve as resolve11 } from "path";
2015
2093
 
2016
2094
  // src/core/utils/log/printFileList.ts
2017
2095
  import path6 from "node:path";
2018
2096
  import pc3 from "picocolors";
2019
- import fs11 from "fs-extra";
2097
+ import fs10 from "fs-extra";
2020
2098
  import { filesize } from "filesize";
2021
2099
 
2022
2100
  // src/core/utils/log/printTable.ts
@@ -2054,7 +2132,7 @@ async function printFileList(log, header, baseDir, files) {
2054
2132
  ];
2055
2133
  const prefix = i === files.length - 1 ? " \u2514\u2500" : " \u251C\u2500";
2056
2134
  const color = getChunkColor(file);
2057
- const stats = await fs11.lstat(file);
2135
+ const stats = await fs10.lstat(file);
2058
2136
  totalSize += stats.size;
2059
2137
  const size = String(filesize(stats.size));
2060
2138
  return [
@@ -2095,7 +2173,7 @@ async function printBuildSummary(log, header, output) {
2095
2173
  return l.fileName.localeCompare(r.fileName);
2096
2174
  });
2097
2175
  const files = chunks.map(
2098
- (chunk) => resolve12(wxt.config.outDir, chunk.fileName)
2176
+ (chunk) => resolve11(wxt.config.outDir, chunk.fileName)
2099
2177
  );
2100
2178
  await printFileList(log, header, wxt.config.outDir, files);
2101
2179
  }
@@ -2225,6 +2303,21 @@ function getContentScriptJs(config, entrypoint) {
2225
2303
  return [getEntrypointBundlePath(entrypoint, config.outDir, ".js")];
2226
2304
  }
2227
2305
 
2306
+ // src/core/utils/package.ts
2307
+ import { resolve as resolve12 } from "node:path";
2308
+ import fs11 from "fs-extra";
2309
+ async function getPackageJson() {
2310
+ const file = resolve12(wxt.config.root, "package.json");
2311
+ try {
2312
+ return await fs11.readJson(file);
2313
+ } catch (err) {
2314
+ wxt.logger.debug(
2315
+ `Failed to read package.json at: ${file}. Returning undefined.`
2316
+ );
2317
+ return {};
2318
+ }
2319
+ }
2320
+
2228
2321
  // src/core/utils/manifest.ts
2229
2322
  import defu2 from "defu";
2230
2323
  async function writeManifest(manifest, output) {
@@ -2912,12 +3005,12 @@ function printValidationResults({
2912
3005
  return map;
2913
3006
  }, /* @__PURE__ */ new Map());
2914
3007
  Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
2915
- consola.log(relative6(cwd, entrypoint.inputPath));
3008
+ wxt.logger.log(relative6(cwd, entrypoint.inputPath));
2916
3009
  console.log();
2917
3010
  errors2.forEach((err) => {
2918
3011
  const type = err.type === "error" ? pc5.red("ERROR") : pc5.yellow("WARN");
2919
3012
  const recieved = pc5.dim(`(recieved: ${JSON.stringify(err.value)})`);
2920
- consola.log(` - ${type} ${err.message} ${recieved}`);
3013
+ wxt.logger.log(` - ${type} ${err.message} ${recieved}`);
2921
3014
  });
2922
3015
  console.log();
2923
3016
  });
@@ -2943,7 +3036,7 @@ var npm = {
2943
3036
  overridesKey: "overrides",
2944
3037
  async downloadDependency(id, downloadDir) {
2945
3038
  await ensureDir3(downloadDir);
2946
- const { execa } = await import("./execa-D7CMCKO2.js");
3039
+ const { execa } = await import("./execa-4UBDUBJZ.js");
2947
3040
  const res = await execa("npm", ["pack", id, "--json"], {
2948
3041
  cwd: downloadDir
2949
3042
  });
@@ -2955,7 +3048,7 @@ var npm = {
2955
3048
  if (options?.all) {
2956
3049
  args.push("--depth", "Infinity");
2957
3050
  }
2958
- const { execa } = await import("./execa-D7CMCKO2.js");
3051
+ const { execa } = await import("./execa-4UBDUBJZ.js");
2959
3052
  const res = await execa("npm", args, { cwd: options?.cwd });
2960
3053
  const project = JSON.parse(res.stdout);
2961
3054
  return flattenNpmListOutput([project]);
@@ -3008,7 +3101,7 @@ var bun = {
3008
3101
  if (options?.all) {
3009
3102
  args.push("--all");
3010
3103
  }
3011
- const { execa } = await import("./execa-D7CMCKO2.js");
3104
+ const { execa } = await import("./execa-4UBDUBJZ.js");
3012
3105
  const res = await execa("bun", args, { cwd: options?.cwd });
3013
3106
  return dedupeDependencies(
3014
3107
  res.stdout.split("\n").slice(1).map((line) => line.trim()).map((line) => /.* (@?\S+)@(\S+)$/.exec(line)).filter((match) => !!match).map(([_, name, version2]) => ({ name, version: version2 }))
@@ -3027,7 +3120,7 @@ var yarn = {
3027
3120
  if (options?.all) {
3028
3121
  args.push("--depth", "Infinity");
3029
3122
  }
3030
- const { execa } = await import("./execa-D7CMCKO2.js");
3123
+ const { execa } = await import("./execa-4UBDUBJZ.js");
3031
3124
  const res = await execa("yarn", args, { cwd: options?.cwd });
3032
3125
  const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
3033
3126
  if (tree == null) throw Error("'yarn list --json' did not output a tree");
@@ -3063,7 +3156,7 @@ var pnpm = {
3063
3156
  if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
3064
3157
  args.push("--ignore-workspace");
3065
3158
  }
3066
- const { execa } = await import("./execa-D7CMCKO2.js");
3159
+ const { execa } = await import("./execa-4UBDUBJZ.js");
3067
3160
  const res = await execa("pnpm", args, { cwd: options?.cwd });
3068
3161
  const projects = JSON.parse(res.stdout);
3069
3162
  return flattenNpmListOutput(projects);
@@ -3152,7 +3245,6 @@ async function createViteBuilder(wxtConfig, hooks, server) {
3152
3245
  config.plugins.push(
3153
3246
  download(wxtConfig),
3154
3247
  devHtmlPrerender(wxtConfig, server),
3155
- unimport(wxtConfig),
3156
3248
  resolveVirtualModules(wxtConfig),
3157
3249
  devServerGlobals(wxtConfig, server),
3158
3250
  tsconfigPaths(wxtConfig),
@@ -3312,7 +3404,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
3312
3404
  const config = vite.mergeConfig(baseConfig, envConfig);
3313
3405
  const server2 = await vite.createServer(config);
3314
3406
  await server2.pluginContainer.buildStart({});
3315
- const node = new ViteNodeServer(server2);
3407
+ const node = new ViteNodeServer(
3408
+ // @ts-ignore: Some weird type error...
3409
+ server2
3410
+ );
3316
3411
  installSourcemapsSupport({
3317
3412
  getSourceMap: (source) => node.getSourceMap(source)
3318
3413
  });
@@ -3434,18 +3529,16 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
3434
3529
  builder,
3435
3530
  server
3436
3531
  };
3437
- for (const module of config.modules) {
3532
+ const initModule = async (module) => {
3438
3533
  if (module.hooks) wxt.hooks.addHooks(module.hooks);
3439
- if (wxt.config.imports !== false && module.imports) {
3440
- wxt.config.imports.imports ??= [];
3441
- wxt.config.imports.imports.push(...module.imports);
3442
- }
3443
3534
  await module.setup?.(
3444
3535
  wxt,
3445
3536
  // @ts-expect-error: Untyped configKey field
3446
3537
  module.configKey ? config[module.configKey] : void 0
3447
3538
  );
3448
- }
3539
+ };
3540
+ for (const builtinModule of builtinModules) await initModule(builtinModule);
3541
+ for (const userModule of config.userModules) await initModule(userModule);
3449
3542
  wxt.hooks.addHooks(config.hooks);
3450
3543
  await wxt.hooks.callHook("ready", wxt);
3451
3544
  }
@@ -3457,22 +3550,22 @@ export {
3457
3550
  isHtmlEntrypoint,
3458
3551
  formatDuration,
3459
3552
  download,
3460
- unimport,
3461
3553
  tsconfigPaths,
3462
3554
  globals,
3463
3555
  webextensionPolyfillMock,
3464
3556
  kebabCaseAlphanumeric,
3557
+ vitePlugin,
3465
3558
  wxt,
3466
3559
  registerWxt,
3467
3560
  detectDevChanges,
3468
3561
  findEntrypoints,
3469
3562
  generateTypesDir,
3470
- getPackageJson,
3471
3563
  resolveConfig,
3472
3564
  printFileList,
3473
3565
  version,
3474
3566
  mapWxtOptionsToRegisteredContentScript,
3475
3567
  getContentScriptJs,
3568
+ getPackageJson,
3476
3569
  getContentScriptCssFiles,
3477
3570
  getContentScriptsCssMap,
3478
3571
  rebuild,