wxt 0.18.9 → 0.18.10

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/cli.js CHANGED
@@ -12,7 +12,7 @@ import cac from "cac";
12
12
 
13
13
  // src/core/utils/fs.ts
14
14
  import fs3 from "fs-extra";
15
- import glob from "fast-glob";
15
+ import glob2 from "fast-glob";
16
16
 
17
17
  // src/core/utils/paths.ts
18
18
  import systemPath from "node:path";
@@ -548,38 +548,6 @@ async function removeEmptyDirs(dir) {
548
548
  }
549
549
  }
550
550
 
551
- // src/core/builders/vite/plugins/unimport.ts
552
- import { createUnimport } from "unimport";
553
- import { extname as extname2 } from "path";
554
- var ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
555
- ".js",
556
- ".jsx",
557
- ".ts",
558
- ".tsx",
559
- ".vue",
560
- ".svelte"
561
- ]);
562
- function unimport(config) {
563
- const options = config.imports;
564
- if (options === false) return [];
565
- const unimport2 = createUnimport(options);
566
- return {
567
- name: "wxt:unimport",
568
- async config() {
569
- await unimport2.scanImportsFromDir(void 0, { cwd: config.srcDir });
570
- },
571
- async transform(code, id) {
572
- if (id.includes("node_modules")) return;
573
- if (!ENABLED_EXTENSIONS.has(extname2(id))) return;
574
- const injected = await unimport2.injectImports(code, id);
575
- return {
576
- code: injected.code,
577
- map: injected.s.generateMap({ hires: "boundary", source: id })
578
- };
579
- }
580
- };
581
- }
582
-
583
551
  // src/core/utils/virtual-modules.ts
584
552
  var virtualEntrypointTypes = [
585
553
  "content-script-main-world",
@@ -978,7 +946,7 @@ import { ViteNodeServer } from "vite-node/server";
978
946
  import { ViteNodeRunner } from "vite-node/client";
979
947
  import { installSourcemapsSupport } from "vite-node/source-map";
980
948
  async function createViteBuilder(wxtConfig, hooks, server) {
981
- const vite = await import("vite");
949
+ const vite2 = await import("vite");
982
950
  const getBaseConfig = async () => {
983
951
  const config = await wxtConfig.vite(wxtConfig.env);
984
952
  config.root = wxtConfig.root;
@@ -1000,7 +968,6 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1000
968
  config.plugins.push(
1001
969
  download(wxtConfig),
1002
970
  devHtmlPrerender(wxtConfig, server),
1003
- unimport(wxtConfig),
1004
971
  resolveVirtualModules(wxtConfig),
1005
972
  devServerGlobals(wxtConfig, server),
1006
973
  tsconfigPaths(wxtConfig),
@@ -1123,7 +1090,7 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1123
1090
  };
1124
1091
  return {
1125
1092
  name: "Vite",
1126
- version: vite.version,
1093
+ version: vite2.version,
1127
1094
  async importEntrypoint(path11) {
1128
1095
  switch (wxtConfig.experimental.entrypointImporter) {
1129
1096
  default:
@@ -1138,10 +1105,10 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1138
1105
  removeEntrypointMainFunction(wxtConfig, path11)
1139
1106
  ]
1140
1107
  };
1141
- const config = vite.mergeConfig(baseConfig, envConfig);
1142
- const server2 = await vite.createServer(config);
1108
+ const config = vite2.mergeConfig(baseConfig, envConfig);
1109
+ const server2 = await vite2.createServer(config);
1143
1110
  await server2.listen();
1144
- const runtime = await vite.createViteRuntime(server2, { hmr: false });
1111
+ const runtime = await vite2.createViteRuntime(server2, { hmr: false });
1145
1112
  const module = await runtime.executeUrl(path11);
1146
1113
  await server2.close();
1147
1114
  return module.default;
@@ -1157,8 +1124,8 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1157
1124
  removeEntrypointMainFunction(wxtConfig, path11)
1158
1125
  ]
1159
1126
  };
1160
- const config = vite.mergeConfig(baseConfig, envConfig);
1161
- const server2 = await vite.createServer(config);
1127
+ const config = vite2.mergeConfig(baseConfig, envConfig);
1128
+ const server2 = await vite2.createServer(config);
1162
1129
  await server2.pluginContainer.buildStart({});
1163
1130
  const node = new ViteNodeServer(server2);
1164
1131
  installSourcemapsSupport({
@@ -1189,13 +1156,13 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1189
1156
  else if (group.inputPath.endsWith(".css"))
1190
1157
  entryConfig = getCssConfig(group);
1191
1158
  else entryConfig = getLibModeConfig(group);
1192
- const buildConfig = vite.mergeConfig(await getBaseConfig(), entryConfig);
1159
+ const buildConfig = vite2.mergeConfig(await getBaseConfig(), entryConfig);
1193
1160
  await hooks.callHook(
1194
1161
  "vite:build:extendConfig",
1195
1162
  toArray(group),
1196
1163
  buildConfig
1197
1164
  );
1198
- const result = await vite.build(buildConfig);
1165
+ const result = await vite2.build(buildConfig);
1199
1166
  return {
1200
1167
  entrypoints: group,
1201
1168
  chunks: getBuildOutputChunks(result)
@@ -1211,9 +1178,9 @@ async function createViteBuilder(wxtConfig, hooks, server) {
1211
1178
  }
1212
1179
  };
1213
1180
  const baseConfig = await getBaseConfig();
1214
- const finalConfig = vite.mergeConfig(baseConfig, serverConfig);
1181
+ const finalConfig = vite2.mergeConfig(baseConfig, serverConfig);
1215
1182
  await hooks.callHook("vite:devServer:extendConfig", finalConfig);
1216
- const viteServer = await vite.createServer(finalConfig);
1183
+ const viteServer = await vite2.createServer(finalConfig);
1217
1184
  const server2 = {
1218
1185
  async listen() {
1219
1186
  await viteServer.listen(info.port);
@@ -1261,6 +1228,107 @@ function getRollupEntry(entrypoint) {
1261
1228
  return entrypoint.inputPath;
1262
1229
  }
1263
1230
 
1231
+ // src/modules.ts
1232
+ import * as vite from "vite";
1233
+ import glob from "fast-glob";
1234
+ function defineWxtModule(module) {
1235
+ if (typeof module === "function") return { setup: module };
1236
+ return module;
1237
+ }
1238
+ function addViteConfig(wxt2, viteConfig) {
1239
+ wxt2.hooks.hook("ready", (wxt3) => {
1240
+ const userVite = wxt3.config.vite;
1241
+ wxt3.config.vite = async (env) => {
1242
+ const fromUser = await userVite(env);
1243
+ const fromModule = viteConfig(env) ?? {};
1244
+ return vite.mergeConfig(fromModule, fromUser);
1245
+ };
1246
+ });
1247
+ }
1248
+
1249
+ // src/builtin-modules/unimport.ts
1250
+ import { createUnimport } from "unimport";
1251
+ import { extname as extname2 } from "node:path";
1252
+ var unimport_default = defineWxtModule({
1253
+ name: "wxt:built-in:unimport",
1254
+ setup(wxt2) {
1255
+ const options = wxt2.config.imports;
1256
+ if (options === false) return;
1257
+ let unimport;
1258
+ wxt2.hooks.hook("ready", () => {
1259
+ const addModuleImports = (module) => {
1260
+ if (!module.imports) return;
1261
+ options.imports ??= [];
1262
+ options.imports.push(...module.imports);
1263
+ };
1264
+ wxt2.config.builtinModules.forEach(addModuleImports);
1265
+ wxt2.config.userModules.forEach(addModuleImports);
1266
+ });
1267
+ wxt2.hooks.afterEach((event) => {
1268
+ if (event.name === "ready") {
1269
+ unimport = createUnimport(options);
1270
+ }
1271
+ });
1272
+ wxt2.hooks.hook("prepare:types", async (_, entries) => {
1273
+ await unimport.init();
1274
+ entries.push(await getImportsDeclarationEntry(unimport));
1275
+ if (!options.eslintrc.enabled) return;
1276
+ entries.push(await getImportsEslintEntry(unimport, options));
1277
+ });
1278
+ addViteConfig(wxt2, () => ({
1279
+ plugins: [vitePlugin(unimport)]
1280
+ }));
1281
+ }
1282
+ });
1283
+ function vitePlugin(unimport) {
1284
+ const ENABLED_EXTENSIONS = /* @__PURE__ */ new Set([
1285
+ ".js",
1286
+ ".jsx",
1287
+ ".ts",
1288
+ ".tsx",
1289
+ ".vue",
1290
+ ".svelte"
1291
+ ]);
1292
+ return {
1293
+ name: "wxt:unimport",
1294
+ async transform(code, id) {
1295
+ if (id.includes("node_modules")) return;
1296
+ if (!ENABLED_EXTENSIONS.has(extname2(id))) return;
1297
+ const injected = await unimport.injectImports(code, id);
1298
+ return {
1299
+ code: injected.code,
1300
+ map: injected.s.generateMap({ hires: "boundary", source: id })
1301
+ };
1302
+ }
1303
+ };
1304
+ }
1305
+ async function getImportsDeclarationEntry(unimport) {
1306
+ await unimport.init();
1307
+ return {
1308
+ path: "types/imports.d.ts",
1309
+ text: [
1310
+ "// Generated by wxt",
1311
+ await unimport.generateTypeDeclarations(),
1312
+ ""
1313
+ ].join("\n"),
1314
+ tsReference: true
1315
+ };
1316
+ }
1317
+ async function getImportsEslintEntry(unimport, options) {
1318
+ const globals2 = {};
1319
+ const eslintrc = { globals: globals2 };
1320
+ (await unimport.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
1321
+ eslintrc.globals[name] = options.eslintrc.globalsPropValue;
1322
+ });
1323
+ return {
1324
+ path: options.eslintrc.filePath,
1325
+ text: JSON.stringify(eslintrc, null, 2) + "\n"
1326
+ };
1327
+ }
1328
+
1329
+ // src/builtin-modules/index.ts
1330
+ var builtinModules = [unimport_default];
1331
+
1264
1332
  // src/core/wxt.ts
1265
1333
  var wxt;
1266
1334
  async function registerWxt(command, inlineConfig = {}, getServer) {
@@ -1282,18 +1350,16 @@ async function registerWxt(command, inlineConfig = {}, getServer) {
1282
1350
  builder,
1283
1351
  server
1284
1352
  };
1285
- for (const module of config.modules) {
1353
+ const initModule = async (module) => {
1286
1354
  if (module.hooks) wxt.hooks.addHooks(module.hooks);
1287
- if (wxt.config.imports !== false && module.imports) {
1288
- wxt.config.imports.imports ??= [];
1289
- wxt.config.imports.imports.push(...module.imports);
1290
- }
1291
1355
  await module.setup?.(
1292
1356
  wxt,
1293
1357
  // @ts-expect-error: Untyped configKey field
1294
1358
  module.configKey ? config[module.configKey] : void 0
1295
1359
  );
1296
- }
1360
+ };
1361
+ for (const builtinModule of builtinModules) await initModule(builtinModule);
1362
+ for (const userModule of config.userModules) await initModule(userModule);
1297
1363
  wxt.hooks.addHooks(config.hooks);
1298
1364
  await wxt.hooks.callHook("ready", wxt);
1299
1365
  }
@@ -1307,7 +1373,7 @@ async function writeFileIfDifferent(file, newContents) {
1307
1373
  }
1308
1374
  async function getPublicFiles() {
1309
1375
  if (!await fs3.exists(wxt.config.publicDir)) return [];
1310
- const files = await glob("**/*", { cwd: wxt.config.publicDir });
1376
+ const files = await glob2("**/*", { cwd: wxt.config.publicDir });
1311
1377
  return files.map(unnormalizePath);
1312
1378
  }
1313
1379
 
@@ -1341,13 +1407,17 @@ async function copyPublicDirectory() {
1341
1407
  await wxt.hooks.callHook("build:publicAssets", wxt, files);
1342
1408
  if (files.length === 0) return [];
1343
1409
  const publicAssets = [];
1344
- for (const { absoluteSrc, relativeDest } of files) {
1345
- const absoluteDest = resolve6(wxt.config.outDir, relativeDest);
1410
+ for (const file of files) {
1411
+ const absoluteDest = resolve6(wxt.config.outDir, file.relativeDest);
1346
1412
  await fs4.ensureDir(dirname3(absoluteDest));
1347
- await fs4.copyFile(absoluteSrc, absoluteDest);
1413
+ if ("absoluteSrc" in file) {
1414
+ await fs4.copyFile(file.absoluteSrc, absoluteDest);
1415
+ } else {
1416
+ await fs4.writeFile(absoluteDest, file.contents, "utf8");
1417
+ }
1348
1418
  publicAssets.push({
1349
1419
  type: "asset",
1350
- fileName: relativeDest
1420
+ fileName: file.relativeDest
1351
1421
  });
1352
1422
  }
1353
1423
  return publicAssets;
@@ -1451,12 +1521,12 @@ import fs5 from "fs-extra";
1451
1521
  import { minimatch } from "minimatch";
1452
1522
  import { parseHTML as parseHTML3 } from "linkedom";
1453
1523
  import JSON5 from "json5";
1454
- import glob2 from "fast-glob";
1524
+ import glob3 from "fast-glob";
1455
1525
  import pc2 from "picocolors";
1456
1526
  async function findEntrypoints() {
1457
1527
  await fs5.mkdir(wxt.config.wxtDir, { recursive: true });
1458
1528
  await fs5.writeJson(resolve7(wxt.config.wxtDir, "tsconfig.json"), {});
1459
- const relativePaths = await glob2(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
1529
+ const relativePaths = await glob3(Object.keys(PATH_GLOB_TO_TYPE_MAP), {
1460
1530
  cwd: wxt.config.entrypointsDir
1461
1531
  });
1462
1532
  relativePaths.sort();
@@ -1465,7 +1535,7 @@ async function findEntrypoints() {
1465
1535
  const inputPath = resolve7(wxt.config.entrypointsDir, relativePath);
1466
1536
  const name = getEntrypointName(wxt.config.entrypointsDir, inputPath);
1467
1537
  const matchingGlob = pathGlobs.find(
1468
- (glob7) => minimatch(relativePath, glob7)
1538
+ (glob8) => minimatch(relativePath, glob8)
1469
1539
  );
1470
1540
  if (matchingGlob) {
1471
1541
  const type = PATH_GLOB_TO_TYPE_MAP[matchingGlob];
@@ -1826,9 +1896,8 @@ var PATH_GLOB_TO_TYPE_MAP = {
1826
1896
  var CONTENT_SCRIPT_OUT_DIR = "content-scripts";
1827
1897
 
1828
1898
  // src/core/utils/building/generate-wxt-dir.ts
1829
- import { createUnimport as createUnimport2 } from "unimport";
1830
1899
  import fs6 from "fs-extra";
1831
- import { relative as relative4, resolve as resolve8 } from "path";
1900
+ import { dirname as dirname4, relative as relative4, resolve as resolve8 } from "node:path";
1832
1901
  import path5 from "node:path";
1833
1902
 
1834
1903
  // src/core/utils/i18n.ts
@@ -1871,41 +1940,32 @@ function parseI18nMessages(messagesJson) {
1871
1940
  // src/core/utils/building/generate-wxt-dir.ts
1872
1941
  async function generateTypesDir(entrypoints) {
1873
1942
  await fs6.ensureDir(wxt.config.typesDir);
1874
- const references = [];
1875
- if (wxt.config.imports !== false) {
1876
- const unimport2 = createUnimport2(wxt.config.imports);
1877
- references.push(await writeImportsDeclarationFile(unimport2));
1878
- if (wxt.config.imports.eslintrc.enabled) {
1879
- await writeImportsEslintFile(unimport2, wxt.config.imports);
1880
- }
1881
- }
1882
- references.push(await writePathsDeclarationFile(entrypoints));
1883
- references.push(await writeI18nDeclarationFile());
1884
- references.push(await writeGlobalsDeclarationFile());
1885
- const mainReference = await writeMainDeclarationFile(references);
1886
- await writeTsConfigFile(mainReference);
1887
- }
1888
- async function writeImportsDeclarationFile(unimport2) {
1889
- const filePath = resolve8(wxt.config.typesDir, "imports.d.ts");
1890
- await unimport2.scanImportsFromDir(void 0, { cwd: wxt.config.srcDir });
1891
- await writeFileIfDifferent(
1892
- filePath,
1893
- ["// Generated by wxt", await unimport2.generateTypeDeclarations()].join(
1894
- "\n"
1895
- ) + "\n"
1896
- );
1897
- return filePath;
1898
- }
1899
- async function writeImportsEslintFile(unimport2, options) {
1900
- const globals2 = {};
1901
- const eslintrc = { globals: globals2 };
1902
- (await unimport2.getImports()).map((i) => i.as ?? i.name).filter(Boolean).sort().forEach((name) => {
1903
- eslintrc.globals[name] = options.eslintrc.globalsPropValue;
1943
+ const entries = [
1944
+ // Hard-coded entries
1945
+ { module: "wxt/vite-builder-env" }
1946
+ ];
1947
+ wxt.config.userModules.forEach((module) => {
1948
+ if (module.type === "node_module" && module.configKey != null)
1949
+ entries.push({ module: module.id });
1904
1950
  });
1905
- await fs6.writeJson(options.eslintrc.filePath, eslintrc, { spaces: 2 });
1951
+ entries.push(await getPathsDeclarationEntry(entrypoints));
1952
+ entries.push(await getI18nDeclarationEntry());
1953
+ entries.push(await getGlobalsDeclarationEntry());
1954
+ entries.push(await getTsConfigEntry());
1955
+ await wxt.hooks.callHook("prepare:types", wxt, entries);
1956
+ entries.push(getMainDeclarationEntry(entries));
1957
+ const absoluteFileEntries = entries.filter((entry) => "path" in entry).map((entry) => ({
1958
+ ...entry,
1959
+ path: resolve8(wxt.config.wxtDir, entry.path)
1960
+ }));
1961
+ await Promise.all(
1962
+ absoluteFileEntries.map(async (file) => {
1963
+ await fs6.ensureDir(dirname4(file.path));
1964
+ await writeFileIfDifferent(file.path, file.text);
1965
+ })
1966
+ );
1906
1967
  }
1907
- async function writePathsDeclarationFile(entrypoints) {
1908
- const filePath = resolve8(wxt.config.typesDir, "paths.d.ts");
1968
+ async function getPathsDeclarationEntry(entrypoints) {
1909
1969
  const unions = entrypoints.map(
1910
1970
  (entry) => getEntrypointBundlePath(
1911
1971
  entry,
@@ -1926,14 +1986,13 @@ declare module "wxt/browser" {
1926
1986
  }
1927
1987
  }
1928
1988
  `;
1929
- await writeFileIfDifferent(
1930
- filePath,
1931
- template.replace("{{ union }}", unions || " | never")
1932
- );
1933
- return filePath;
1989
+ return {
1990
+ path: "types/paths.d.ts",
1991
+ text: template.replace("{{ union }}", unions || " | never"),
1992
+ tsReference: true
1993
+ };
1934
1994
  }
1935
- async function writeI18nDeclarationFile() {
1936
- const filePath = resolve8(wxt.config.typesDir, "i18n.d.ts");
1995
+ async function getI18nDeclarationEntry() {
1937
1996
  const defaultLocale = wxt.config.manifest.default_locale;
1938
1997
  const template = `// Generated by wxt
1939
1998
  import "wxt/browser";
@@ -1979,18 +2038,17 @@ declare module "wxt/browser" {
1979
2038
  options?: GetMessageOptions,
1980
2039
  ): string;`;
1981
2040
  });
1982
- await writeFileIfDifferent(
1983
- filePath,
1984
- template.replace("{{ overrides }}", overrides.join("\n"))
1985
- );
1986
- return filePath;
2041
+ return {
2042
+ path: "types/i18n.d.ts",
2043
+ text: template.replace("{{ overrides }}", overrides.join("\n")),
2044
+ tsReference: true
2045
+ };
1987
2046
  }
1988
- async function writeGlobalsDeclarationFile() {
1989
- const filePath = resolve8(wxt.config.typesDir, "globals.d.ts");
2047
+ async function getGlobalsDeclarationEntry() {
1990
2048
  const globals2 = [...getGlobals(wxt.config), ...getEntrypointGlobals("")];
1991
- await writeFileIfDifferent(
1992
- filePath,
1993
- [
2049
+ return {
2050
+ path: "types/globals.d.ts",
2051
+ text: [
1994
2052
  "// Generated by wxt",
1995
2053
  "export {}",
1996
2054
  "interface ImportMetaEnv {",
@@ -1998,34 +2056,29 @@ async function writeGlobalsDeclarationFile() {
1998
2056
  "}",
1999
2057
  "interface ImportMeta {",
2000
2058
  " readonly env: ImportMetaEnv",
2001
- "}"
2002
- ].join("\n") + "\n"
2003
- );
2004
- return filePath;
2059
+ "}",
2060
+ ""
2061
+ ].join("\n"),
2062
+ tsReference: true
2063
+ };
2005
2064
  }
2006
- async function writeMainDeclarationFile(references) {
2007
- const dir = wxt.config.wxtDir;
2008
- const filePath = resolve8(dir, "wxt.d.ts");
2009
- await writeFileIfDifferent(
2010
- filePath,
2011
- [
2012
- "// Generated by wxt",
2013
- `/// <reference types="wxt/vite-builder-env" />`,
2014
- ...references.map(
2015
- (ref) => `/// <reference types="./${normalizePath(relative4(dir, ref))}" />`
2016
- ),
2017
- // Add references to modules installed from NPM to the TS project so
2018
- // their type augmentation can update InlineConfig correctly. Local
2019
- // modules defined in <root>/modules are already apart of the project, so
2020
- // we don't need to add them.
2021
- ...wxt.config.modules.filter(
2022
- (module) => module.type === "node_module" && module.configKey != null
2023
- ).map((module) => `/// <reference types="${module.id}" />`)
2024
- ].join("\n") + "\n"
2025
- );
2026
- return filePath;
2065
+ function getMainDeclarationEntry(references) {
2066
+ const lines = ["// Generated by wxt"];
2067
+ references.forEach((ref) => {
2068
+ if ("module" in ref) {
2069
+ return lines.push(`/// <reference types="${ref.module}" />`);
2070
+ } else if (ref.tsReference) {
2071
+ const absolutePath = resolve8(wxt.config.wxtDir, ref.path);
2072
+ const relativePath = relative4(wxt.config.wxtDir, absolutePath);
2073
+ lines.push(`/// <reference types="./${normalizePath(relativePath)}" />`);
2074
+ }
2075
+ });
2076
+ return {
2077
+ path: "wxt.d.ts",
2078
+ text: lines.join("\n") + "\n"
2079
+ };
2027
2080
  }
2028
- async function writeTsConfigFile(mainReference) {
2081
+ async function getTsConfigEntry() {
2029
2082
  const dir = wxt.config.wxtDir;
2030
2083
  const getTsconfigPath = (path11) => normalizePath(relative4(dir, path11));
2031
2084
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
@@ -2035,9 +2088,7 @@ async function writeTsConfigFile(mainReference) {
2035
2088
  ` "${alias}/*": ["${aliasPath}/*"]`
2036
2089
  ];
2037
2090
  }).join(",\n");
2038
- await writeFileIfDifferent(
2039
- resolve8(dir, "tsconfig.json"),
2040
- `{
2091
+ const text = `{
2041
2092
  "compilerOptions": {
2042
2093
  "target": "ESNext",
2043
2094
  "module": "ESNext",
@@ -2054,11 +2105,14 @@ ${paths}
2054
2105
  },
2055
2106
  "include": [
2056
2107
  "${getTsconfigPath(wxt.config.root)}/**/*",
2057
- "./${getTsconfigPath(mainReference)}"
2108
+ "./wxt.d.ts"
2058
2109
  ],
2059
2110
  "exclude": ["${getTsconfigPath(wxt.config.outBaseDir)}"]
2060
- }`
2061
- );
2111
+ }`;
2112
+ return {
2113
+ path: "tsconfig.json",
2114
+ text
2115
+ };
2062
2116
  }
2063
2117
 
2064
2118
  // src/core/utils/building/resolve-config.ts
@@ -2067,13 +2121,13 @@ import path6 from "node:path";
2067
2121
 
2068
2122
  // src/core/utils/cache.ts
2069
2123
  import fs7, { ensureDir as ensureDir3 } from "fs-extra";
2070
- import { dirname as dirname4, resolve as resolve9 } from "path";
2124
+ import { dirname as dirname5, resolve as resolve9 } from "path";
2071
2125
  function createFsCache(wxtDir) {
2072
2126
  const getPath = (key) => resolve9(wxtDir, "cache", encodeURIComponent(key));
2073
2127
  return {
2074
2128
  async set(key, value) {
2075
2129
  const path11 = getPath(key);
2076
- await ensureDir3(dirname4(path11));
2130
+ await ensureDir3(dirname5(path11));
2077
2131
  await writeFileIfDifferent(path11, value);
2078
2132
  },
2079
2133
  async get(key) {
@@ -2113,7 +2167,7 @@ function isModuleInstalled(name) {
2113
2167
 
2114
2168
  // src/core/utils/building/resolve-config.ts
2115
2169
  import fs9 from "fs-extra";
2116
- import glob3 from "fast-glob";
2170
+ import glob4 from "fast-glob";
2117
2171
  async function resolveConfig(inlineConfig, command) {
2118
2172
  let userConfig = {};
2119
2173
  let userConfigMetadata;
@@ -2190,14 +2244,20 @@ async function resolveConfig(inlineConfig, command) {
2190
2244
  hostname: "localhost"
2191
2245
  };
2192
2246
  }
2193
- const modules = await resolveWxtModules(modulesDir, mergedConfig.modules);
2194
- const moduleOptions = modules.reduce((map, module) => {
2195
- if (module.configKey) {
2196
- map[module.configKey] = // @ts-expect-error
2197
- mergedConfig[module.configKey];
2198
- }
2199
- return map;
2200
- }, {});
2247
+ const userModules = await resolveWxtUserModules(
2248
+ modulesDir,
2249
+ mergedConfig.modules
2250
+ );
2251
+ const moduleOptions = userModules.reduce(
2252
+ (map, module) => {
2253
+ if (module.configKey) {
2254
+ map[module.configKey] = // @ts-expect-error
2255
+ mergedConfig[module.configKey];
2256
+ }
2257
+ return map;
2258
+ },
2259
+ {}
2260
+ );
2201
2261
  return {
2202
2262
  browser,
2203
2263
  command,
@@ -2207,7 +2267,7 @@ async function resolveConfig(inlineConfig, command) {
2207
2267
  filterEntrypoints,
2208
2268
  env,
2209
2269
  fsCache: createFsCache(wxtDir),
2210
- imports: await getUnimportOptions(wxtDir, logger, mergedConfig),
2270
+ imports: await getUnimportOptions(wxtDir, srcDir, logger, mergedConfig),
2211
2271
  logger,
2212
2272
  manifest: await resolveManifestConfig(env, mergedConfig.manifest),
2213
2273
  manifestVersion,
@@ -2236,7 +2296,8 @@ async function resolveConfig(inlineConfig, command) {
2236
2296
  },
2237
2297
  hooks: mergedConfig.hooks ?? {},
2238
2298
  vite: mergedConfig.vite ?? (() => ({})),
2239
- modules,
2299
+ builtinModules,
2300
+ userModules,
2240
2301
  plugins: [],
2241
2302
  ...moduleOptions
2242
2303
  };
@@ -2308,17 +2369,17 @@ function resolveAnalysisConfig(root, mergedConfig) {
2308
2369
  keepArtifacts: mergedConfig.analysis?.keepArtifacts ?? false
2309
2370
  };
2310
2371
  }
2311
- async function getUnimportOptions(wxtDir, logger, config) {
2372
+ async function getUnimportOptions(wxtDir, srcDir, logger, config) {
2312
2373
  if (config.imports === false) return false;
2313
- const enabledConfig = config.imports?.eslintrc?.enabled;
2314
- let enabled;
2315
- switch (enabledConfig) {
2374
+ const rawEslintEnabled = config.imports?.eslintrc?.enabled;
2375
+ let eslintEnabled;
2376
+ switch (rawEslintEnabled) {
2316
2377
  case void 0:
2317
2378
  case "auto":
2318
- enabled = await isModuleInstalled("eslint");
2379
+ eslintEnabled = await isModuleInstalled("eslint");
2319
2380
  break;
2320
2381
  default:
2321
- enabled = enabledConfig;
2382
+ eslintEnabled = rawEslintEnabled;
2322
2383
  }
2323
2384
  const defaultOptions = {
2324
2385
  debugLog: logger.debug,
@@ -2334,8 +2395,11 @@ async function getUnimportOptions(wxtDir, logger, config) {
2334
2395
  ],
2335
2396
  warn: logger.warn,
2336
2397
  dirs: ["components", "composables", "hooks", "utils"],
2398
+ dirsScanOptions: {
2399
+ cwd: srcDir
2400
+ },
2337
2401
  eslintrc: {
2338
- enabled,
2402
+ enabled: eslintEnabled,
2339
2403
  filePath: path6.resolve(wxtDir, "eslintrc-auto-import.json"),
2340
2404
  globalsPropValue: true
2341
2405
  }
@@ -2364,19 +2428,19 @@ var COMMAND_MODES = {
2364
2428
  serve: "development"
2365
2429
  };
2366
2430
  async function mergeBuilderConfig(inlineConfig, userConfig) {
2367
- const vite = await import("vite").catch(() => void 0);
2368
- if (vite) {
2431
+ const vite2 = await import("vite").catch(() => void 0);
2432
+ if (vite2) {
2369
2433
  return {
2370
2434
  vite: async (env) => {
2371
2435
  const resolvedInlineConfig = await inlineConfig.vite?.(env) ?? {};
2372
2436
  const resolvedUserConfig = await userConfig.vite?.(env) ?? {};
2373
- return vite.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
2437
+ return vite2.mergeConfig(resolvedUserConfig, resolvedInlineConfig);
2374
2438
  }
2375
2439
  };
2376
2440
  }
2377
2441
  throw Error("Builder not found. Make sure vite is installed.");
2378
2442
  }
2379
- async function resolveWxtModules(modulesDir, modules = []) {
2443
+ async function resolveWxtUserModules(modulesDir, modules = []) {
2380
2444
  const npmModules = await Promise.all(
2381
2445
  modules.map(async (moduleId) => {
2382
2446
  const mod = await import(
@@ -2393,7 +2457,7 @@ async function resolveWxtModules(modulesDir, modules = []) {
2393
2457
  };
2394
2458
  })
2395
2459
  );
2396
- const localModulePaths = await glob3(["*.[tj]s", "*/index.[tj]s"], {
2460
+ const localModulePaths = await glob4(["*.[tj]s", "*/index.[tj]s"], {
2397
2461
  cwd: modulesDir,
2398
2462
  onlyFiles: true
2399
2463
  }).catch(() => []);
@@ -2464,7 +2528,7 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
2464
2528
 
2465
2529
  // src/core/utils/building/import-entrypoint.ts
2466
2530
  import createJITI from "jiti";
2467
- import { createUnimport as createUnimport3 } from "unimport";
2531
+ import { createUnimport as createUnimport2 } from "unimport";
2468
2532
  import fs10 from "fs-extra";
2469
2533
  import { relative as relative5, resolve as resolve11 } from "node:path";
2470
2534
  import { transformSync } from "esbuild";
@@ -2472,15 +2536,15 @@ import { fileURLToPath } from "node:url";
2472
2536
  async function importEntrypointFile(path11) {
2473
2537
  wxt.logger.debug("Loading file metadata:", path11);
2474
2538
  const normalPath = normalizePath(path11);
2475
- const unimport2 = createUnimport3({
2539
+ const unimport = createUnimport2({
2476
2540
  ...wxt.config.imports,
2477
2541
  // Only allow specific imports, not all from the project
2478
2542
  dirs: []
2479
2543
  });
2480
- await unimport2.init();
2544
+ await unimport.init();
2481
2545
  const text = await fs10.readFile(path11, "utf-8");
2482
2546
  const textNoImports = removeProjectImportStatements(text);
2483
- const { code } = await unimport2.injectImports(textNoImports);
2547
+ const { code } = await unimport.injectImports(textNoImports);
2484
2548
  wxt.logger.debug(
2485
2549
  ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
2486
2550
  );
@@ -2662,7 +2726,7 @@ function getChunkSortWeight(filename) {
2662
2726
  import pc4 from "picocolors";
2663
2727
 
2664
2728
  // package.json
2665
- var version = "0.18.8";
2729
+ var version = "0.18.9";
2666
2730
 
2667
2731
  // src/core/utils/log/printHeader.ts
2668
2732
  function printHeader() {
@@ -2671,7 +2735,7 @@ function printHeader() {
2671
2735
  }
2672
2736
 
2673
2737
  // src/core/utils/building/internal-build.ts
2674
- import glob4 from "fast-glob";
2738
+ import glob5 from "fast-glob";
2675
2739
 
2676
2740
  // src/core/utils/manifest.ts
2677
2741
  import fs12 from "fs-extra";
@@ -3436,7 +3500,7 @@ async function internalBuild() {
3436
3500
  return output;
3437
3501
  }
3438
3502
  async function combineAnalysisStats() {
3439
- const unixFiles = await glob4(`${wxt.config.analysis.outputName}-*.json`, {
3503
+ const unixFiles = await glob5(`${wxt.config.analysis.outputName}-*.json`, {
3440
3504
  cwd: wxt.config.analysis.outputDir,
3441
3505
  absolute: true
3442
3506
  });
@@ -3485,7 +3549,7 @@ async function build(config) {
3485
3549
 
3486
3550
  // src/core/clean.ts
3487
3551
  import path8 from "node:path";
3488
- import glob5 from "fast-glob";
3552
+ import glob6 from "fast-glob";
3489
3553
  import fs14 from "fs-extra";
3490
3554
  import pc6 from "picocolors";
3491
3555
  async function clean(root = process.cwd()) {
@@ -3497,7 +3561,7 @@ async function clean(root = process.cwd()) {
3497
3561
  ".output/*"
3498
3562
  ];
3499
3563
  consola.debug("Looking for:", tempDirs.map(pc6.cyan).join(", "));
3500
- const directories = await glob5(tempDirs, {
3564
+ const directories = await glob6(tempDirs, {
3501
3565
  cwd: path8.resolve(root),
3502
3566
  absolute: true,
3503
3567
  onlyDirectories: true,
@@ -3989,7 +4053,7 @@ import path10 from "node:path";
3989
4053
  import fs16 from "fs-extra";
3990
4054
  import { minimatch as minimatch2 } from "minimatch";
3991
4055
  import JSZip from "jszip";
3992
- import glob6 from "fast-glob";
4056
+ import glob7 from "fast-glob";
3993
4057
  async function zip(config) {
3994
4058
  await registerWxt("build", config);
3995
4059
  const output = await internalBuild();
@@ -4037,7 +4101,7 @@ async function zip(config) {
4037
4101
  }
4038
4102
  async function zipDir(directory, outputPath, options) {
4039
4103
  const archive = new JSZip();
4040
- const files = (await glob6("**/*", {
4104
+ const files = (await glob7("**/*", {
4041
4105
  cwd: directory,
4042
4106
  // Ignore node_modules, otherwise this glob step takes forever
4043
4107
  ignore: ["**/node_modules"],