wxt 0.11.2 → 0.12.1

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/bin/wxt.mjs ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import '../dist/cli.js';
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "0.11.2";
2
+ var version = "0.12.1";
3
3
 
4
4
  // src/core/utils/arrays.ts
5
5
  function every(array, predicate) {
@@ -1029,7 +1029,8 @@ async function craeteViteBuilder(inlineConfig, userConfig, wxtConfig) {
1029
1029
  devHtmlPrerender(wxtConfig),
1030
1030
  unimport(wxtConfig),
1031
1031
  virtualEntrypoint("background", wxtConfig),
1032
- virtualEntrypoint("content-script", wxtConfig),
1032
+ virtualEntrypoint("content-script-isolated-world", wxtConfig),
1033
+ virtualEntrypoint("content-script-main-world", wxtConfig),
1033
1034
  virtualEntrypoint("unlisted-script", wxtConfig),
1034
1035
  devServerGlobals(wxtConfig),
1035
1036
  tsconfigPaths(wxtConfig),
@@ -1043,12 +1044,17 @@ async function craeteViteBuilder(inlineConfig, userConfig, wxtConfig) {
1043
1044
  return config;
1044
1045
  };
1045
1046
  const getLibModeConfig = (entrypoint) => {
1046
- const isVirtual = [
1047
- "background",
1048
- "content-script",
1049
- "unlisted-script"
1050
- ].includes(entrypoint.type);
1051
- const entry = isVirtual ? `virtual:wxt-${entrypoint.type}?${entrypoint.inputPath}` : entrypoint.inputPath;
1047
+ let virtualEntrypointType;
1048
+ switch (entrypoint.type) {
1049
+ case "background":
1050
+ case "unlisted-script":
1051
+ virtualEntrypointType = entrypoint.type;
1052
+ break;
1053
+ case "content-script":
1054
+ virtualEntrypointType = entrypoint.options.world === "MAIN" ? "content-script-main-world" : "content-script-isolated-world";
1055
+ break;
1056
+ }
1057
+ const entry = virtualEntrypointType ? `virtual:wxt-${virtualEntrypointType}?${entrypoint.inputPath}` : entrypoint.inputPath;
1052
1058
  const plugins = [
1053
1059
  entrypointGroupGlobals(entrypoint)
1054
1060
  ];
@@ -1209,7 +1215,10 @@ async function getInternalConfig(inlineConfig, command, server) {
1209
1215
  const { config: loadedConfig, ...metadata } = await loadConfig({
1210
1216
  name: "wxt",
1211
1217
  cwd: inlineConfig.root ?? process.cwd(),
1212
- rcFile: false
1218
+ rcFile: false,
1219
+ jitiOptions: {
1220
+ esmResolve: true
1221
+ }
1213
1222
  });
1214
1223
  userConfig = loadedConfig ?? {};
1215
1224
  userConfigMetadata = metadata;
@@ -1418,7 +1427,7 @@ var ENTRY_TYPE_TO_GROUP_MAP = {
1418
1427
  import createJITI from "jiti";
1419
1428
  import { createUnimport as createUnimport3 } from "unimport";
1420
1429
  import fs7 from "fs-extra";
1421
- import { resolve as resolve8 } from "path";
1430
+ import { resolve as resolve8 } from "node:path";
1422
1431
 
1423
1432
  // src/core/utils/strings.ts
1424
1433
  function kebabCaseAlphanumeric(str) {
@@ -1432,14 +1441,14 @@ function removeImportStatements(text) {
1432
1441
  }
1433
1442
  function removeProjectImportStatements(text) {
1434
1443
  const noImports = removeImportStatements(text);
1435
- return `import { defineContentScript, defineBackground } from 'wxt/client';
1436
- import { defineUnlistedScript } from 'wxt/sandbox';
1444
+ return `import { defineUnlistedScript, defineContentScript, defineBackground } from 'wxt/sandbox';
1437
1445
 
1438
1446
  ${noImports}`;
1439
1447
  }
1440
1448
 
1441
1449
  // src/core/utils/building/import-entrypoint.ts
1442
1450
  import { transformSync } from "esbuild";
1451
+ import { fileURLToPath } from "node:url";
1443
1452
  async function importEntrypointFile(path6, config) {
1444
1453
  config.logger.debug("Loading file metadata:", path6);
1445
1454
  const normalPath = normalizePath(path6);
@@ -1455,30 +1464,42 @@ async function importEntrypointFile(path6, config) {
1455
1464
  config.logger.debug(
1456
1465
  ["Text:", text, "No imports:", textNoImports, "Code:", code].join("\n")
1457
1466
  );
1458
- const jiti = createJITI(__filename, {
1459
- cache: false,
1460
- debug: config.debug,
1461
- esmResolve: true,
1462
- alias: {
1463
- "webextension-polyfill": resolve8(
1464
- config.root,
1465
- "node_modules/wxt/dist/virtual/mock-browser.js"
1466
- )
1467
- },
1468
- // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
1469
- // respect the custom transform function when using it's native bun option.
1470
- experimentalBun: false,
1471
- // List of extensions to transform with esbuild
1472
- extensions: [".ts", ".cts", ".mts", ".tsx", ".js", ".cjs", ".mjs", ".jsx"],
1473
- transform(opts) {
1474
- const isEntrypoint = opts.filename === normalPath;
1475
- return transformSync(
1476
- // Use modified source code for entrypoints
1477
- isEntrypoint ? code : opts.source,
1478
- getEsbuildOptions(opts)
1479
- );
1467
+ const jiti = createJITI(
1468
+ typeof __filename !== "undefined" ? __filename : fileURLToPath(import.meta.url),
1469
+ {
1470
+ cache: false,
1471
+ debug: config.debug,
1472
+ esmResolve: true,
1473
+ alias: {
1474
+ "webextension-polyfill": resolve8(
1475
+ config.root,
1476
+ "node_modules/wxt/dist/virtual/mock-browser.js"
1477
+ )
1478
+ },
1479
+ // Continue using node to load TS files even if `bun run --bun` is detected. Jiti does not
1480
+ // respect the custom transform function when using it's native bun option.
1481
+ experimentalBun: false,
1482
+ // List of extensions to transform with esbuild
1483
+ extensions: [
1484
+ ".ts",
1485
+ ".cts",
1486
+ ".mts",
1487
+ ".tsx",
1488
+ ".js",
1489
+ ".cjs",
1490
+ ".mjs",
1491
+ ".jsx"
1492
+ ],
1493
+ transform(opts) {
1494
+ const isEntrypoint = opts.filename === normalPath;
1495
+ return transformSync(
1496
+ // Use modified source code for entrypoints
1497
+ isEntrypoint ? code : opts.source,
1498
+ getEsbuildOptions(opts)
1499
+ );
1500
+ }
1480
1501
  }
1481
- });
1502
+ );
1482
1503
  try {
1483
1504
  const res = await jiti(path6);
1484
1505
  return res.default;
@@ -2220,6 +2241,7 @@ async function findEntrypoints(config) {
2220
2241
  }
2221
2242
  return results;
2222
2243
  }, []);
2244
+ preventNoEntrypoints(config, entrypointInfos);
2223
2245
  preventDuplicateEntrypointNames(config, entrypointInfos);
2224
2246
  let hasBackground = false;
2225
2247
  const entrypoints = await Promise.all(
@@ -2321,6 +2343,11 @@ ${errorContent}`
2321
2343
  );
2322
2344
  }
2323
2345
  }
2346
+ function preventNoEntrypoints(config, files) {
2347
+ if (files.length === 0) {
2348
+ throw Error(`No entrypoints found in ${config.entrypointsDir}`);
2349
+ }
2350
+ }
2324
2351
  function getHtmlBaseOptions(document) {
2325
2352
  const options = {};
2326
2353
  const includeContent = document.querySelector("meta[name='manifest.include']")?.getAttribute("content");