wxt 0.17.4 → 0.17.5

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,18 +1,18 @@
1
1
  import {
2
2
  __require
3
- } from "./chunk-P57PW2II.js";
3
+ } from "./chunk-VBXJIVYU.js";
4
4
 
5
5
  // package.json
6
- var version = "0.17.4";
6
+ var version = "0.17.5";
7
7
 
8
8
  // src/core/utils/paths.ts
9
9
  import systemPath from "node:path";
10
10
  import normalize from "normalize-path";
11
- function normalizePath(path7) {
12
- return normalize(path7);
11
+ function normalizePath(path8) {
12
+ return normalize(path8);
13
13
  }
14
- function unnormalizePath(path7) {
15
- return systemPath.normalize(path7);
14
+ function unnormalizePath(path8) {
15
+ return systemPath.normalize(path8);
16
16
  }
17
17
  var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
18
18
  var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
@@ -733,7 +733,7 @@ async function writePathsDeclarationFile(entrypoints) {
733
733
  wxt.config.outDir,
734
734
  isHtmlEntrypoint(entry) ? ".html" : ".js"
735
735
  )
736
- ).concat(await getPublicFiles()).map(normalizePath).map((path7) => ` | "/${path7}"`).sort().join("\n");
736
+ ).concat(await getPublicFiles()).map(normalizePath).map((path8) => ` | "/${path8}"`).sort().join("\n");
737
737
  const template = `// Generated by wxt
738
738
  import "wxt/browser";
739
739
 
@@ -841,7 +841,7 @@ async function writeMainDeclarationFile(references) {
841
841
  }
842
842
  async function writeTsConfigFile(mainReference) {
843
843
  const dir = wxt.config.wxtDir;
844
- const getTsconfigPath = (path7) => normalizePath(relative3(dir, path7));
844
+ const getTsconfigPath = (path8) => normalizePath(relative3(dir, path8));
845
845
  const paths = Object.entries(wxt.config.alias).flatMap(([alias, absolutePath]) => {
846
846
  const aliasPath = getTsconfigPath(absolutePath);
847
847
  return [
@@ -886,14 +886,14 @@ function createFsCache(wxtDir) {
886
886
  const getPath = (key) => resolve5(wxtDir, "cache", encodeURIComponent(key));
887
887
  return {
888
888
  async set(key, value) {
889
- const path7 = getPath(key);
890
- await ensureDir(dirname2(path7));
891
- await writeFileIfDifferent(path7, value);
889
+ const path8 = getPath(key);
890
+ await ensureDir(dirname2(path8));
891
+ await writeFileIfDifferent(path8, value);
892
892
  },
893
893
  async get(key) {
894
- const path7 = getPath(key);
894
+ const path8 = getPath(key);
895
895
  try {
896
- return await fs5.readFile(path7, "utf-8");
896
+ return await fs5.readFile(path8, "utf-8");
897
897
  } catch {
898
898
  return void 0;
899
899
  }
@@ -1027,10 +1027,10 @@ function pointToDevServer(config, server, id, document, querySelector, attr) {
1027
1027
  relative4(config.root, resolvedAbsolutePath)
1028
1028
  );
1029
1029
  if (relativePath.startsWith(".")) {
1030
- let path7 = normalizePath(resolvedAbsolutePath);
1031
- if (!path7.startsWith("/"))
1032
- path7 = "/" + path7;
1033
- element.setAttribute(attr, `${server.origin}/@fs${path7}`);
1030
+ let path8 = normalizePath(resolvedAbsolutePath);
1031
+ if (!path8.startsWith("/"))
1032
+ path8 = "/" + path8;
1033
+ element.setAttribute(attr, `${server.origin}/@fs${path8}`);
1034
1034
  } else {
1035
1035
  const url = new URL(relativePath, server.origin);
1036
1036
  element.setAttribute(attr, url.href);
@@ -1862,6 +1862,7 @@ function mergeInlineConfig(inlineConfig, userConfig) {
1862
1862
  };
1863
1863
  }
1864
1864
  function resolveInternalZipConfig(root, mergedConfig) {
1865
+ const downloadedPackagesDir = path5.resolve(root, ".wxt/local_modules");
1865
1866
  return {
1866
1867
  name: void 0,
1867
1868
  sourcesTemplate: "{{name}}-{{version}}-sources.zip",
@@ -1880,7 +1881,9 @@ function resolveInternalZipConfig(root, mergedConfig) {
1880
1881
  "**/*.+(test|spec).?(c|m)+(j|t)s?(x)",
1881
1882
  // From user
1882
1883
  ...mergedConfig.zip?.excludeSources ?? []
1883
- ]
1884
+ ],
1885
+ downloadPackages: mergedConfig.zip?.downloadPackages ?? [],
1886
+ downloadedPackagesDir
1884
1887
  };
1885
1888
  }
1886
1889
  async function getUnimportOptions(wxtDir, logger, config) {
@@ -1991,16 +1994,16 @@ ${noImports}`;
1991
1994
  // src/core/utils/building/import-entrypoint.ts
1992
1995
  import { transformSync } from "esbuild";
1993
1996
  import { fileURLToPath } from "node:url";
1994
- async function importEntrypointFile(path7) {
1995
- wxt.logger.debug("Loading file metadata:", path7);
1996
- const normalPath = normalizePath(path7);
1997
+ async function importEntrypointFile(path8) {
1998
+ wxt.logger.debug("Loading file metadata:", path8);
1999
+ const normalPath = normalizePath(path8);
1997
2000
  const unimport2 = createUnimport3({
1998
2001
  ...wxt.config.imports,
1999
2002
  // Only allow specific imports, not all from the project
2000
2003
  dirs: []
2001
2004
  });
2002
2005
  await unimport2.init();
2003
- const text = await fs9.readFile(path7, "utf-8");
2006
+ const text = await fs9.readFile(path8, "utf-8");
2004
2007
  const textNoImports = removeProjectImportStatements(text);
2005
2008
  const { code } = await unimport2.injectImports(textNoImports);
2006
2009
  wxt.logger.debug(
@@ -2043,10 +2046,10 @@ async function importEntrypointFile(path7) {
2043
2046
  }
2044
2047
  );
2045
2048
  try {
2046
- const res = await jiti(path7);
2049
+ const res = await jiti(path8);
2047
2050
  return res.default;
2048
2051
  } catch (err) {
2049
- const filePath = relative5(wxt.config.root, path7);
2052
+ const filePath = relative5(wxt.config.root, path8);
2050
2053
  if (err instanceof ReferenceError) {
2051
2054
  const variableName = err.message.replace(" is not defined", "");
2052
2055
  throw Error(
@@ -2946,10 +2949,218 @@ function printValidationResults({
2946
2949
 
2947
2950
  // src/core/wxt.ts
2948
2951
  import { createHooks } from "hookable";
2952
+
2953
+ // src/core/package-managers/index.ts
2954
+ import {
2955
+ detectPackageManager,
2956
+ addDependency,
2957
+ addDevDependency,
2958
+ ensureDependencyInstalled,
2959
+ installDependencies,
2960
+ removeDependency
2961
+ } from "nypm";
2962
+
2963
+ // src/core/package-managers/npm.ts
2964
+ import path7 from "node:path";
2965
+ import { ensureDir as ensureDir3 } from "fs-extra";
2966
+ var npm = {
2967
+ overridesKey: "overrides",
2968
+ async downloadDependency(id, downloadDir) {
2969
+ await ensureDir3(downloadDir);
2970
+ const { execa } = await import("./execa-4F7CCWCA.js");
2971
+ const res = await execa("npm", ["pack", id, "--json"], {
2972
+ cwd: downloadDir
2973
+ });
2974
+ const packed = JSON.parse(res.stdout);
2975
+ return path7.resolve(downloadDir, packed[0].filename);
2976
+ },
2977
+ async listDependencies(options) {
2978
+ const args = ["ls", "--json"];
2979
+ if (options?.all) {
2980
+ args.push("--depth", "Infinity");
2981
+ }
2982
+ const { execa } = await import("./execa-4F7CCWCA.js");
2983
+ const res = await execa("npm", args, { cwd: options?.cwd });
2984
+ const project = JSON.parse(res.stdout);
2985
+ return flattenNpmListOutput([project]);
2986
+ }
2987
+ };
2988
+ function flattenNpmListOutput(projects) {
2989
+ const queue = projects.flatMap(
2990
+ (project) => {
2991
+ const acc = [];
2992
+ if (project.dependencies)
2993
+ acc.push(project.dependencies);
2994
+ if (project.devDependencies)
2995
+ acc.push(project.devDependencies);
2996
+ return acc;
2997
+ }
2998
+ );
2999
+ const dependencies = [];
3000
+ while (queue.length > 0) {
3001
+ Object.entries(queue.pop()).forEach(([name, meta]) => {
3002
+ dependencies.push({
3003
+ name,
3004
+ version: meta.version
3005
+ });
3006
+ if (meta.dependencies)
3007
+ queue.push(meta.dependencies);
3008
+ if (meta.devDependencies)
3009
+ queue.push(meta.devDependencies);
3010
+ });
3011
+ }
3012
+ return dedupeDependencies(dependencies);
3013
+ }
3014
+ function dedupeDependencies(dependencies) {
3015
+ const hashes = /* @__PURE__ */ new Set();
3016
+ return dependencies.filter((dep) => {
3017
+ const hash = `${dep.name}@${dep.version}`;
3018
+ if (hashes.has(hash)) {
3019
+ return false;
3020
+ } else {
3021
+ hashes.add(hash);
3022
+ return true;
3023
+ }
3024
+ });
3025
+ }
3026
+
3027
+ // src/core/package-managers/bun.ts
3028
+ var bun = {
3029
+ overridesKey: "overrides",
3030
+ // But also supports "resolutions"
3031
+ downloadDependency(...args) {
3032
+ return npm.downloadDependency(...args);
3033
+ },
3034
+ async listDependencies(options) {
3035
+ const args = ["pm", "ls"];
3036
+ if (options?.all) {
3037
+ args.push("--all");
3038
+ }
3039
+ const { execa } = await import("./execa-4F7CCWCA.js");
3040
+ const res = await execa("bun", args, { cwd: options?.cwd });
3041
+ return dedupeDependencies(
3042
+ 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 }))
3043
+ );
3044
+ }
3045
+ };
3046
+
3047
+ // src/core/package-managers/yarn.ts
3048
+ var yarn = {
3049
+ overridesKey: "resolutions",
3050
+ downloadDependency(...args) {
3051
+ return npm.downloadDependency(...args);
3052
+ },
3053
+ async listDependencies(options) {
3054
+ const args = ["list", "--json"];
3055
+ if (options?.all) {
3056
+ args.push("--depth", "Infinity");
3057
+ }
3058
+ const { execa } = await import("./execa-4F7CCWCA.js");
3059
+ const res = await execa("yarn", args, { cwd: options?.cwd });
3060
+ const tree = res.stdout.split("\n").map((line) => JSON.parse(line)).find((line) => line.type === "tree")?.data;
3061
+ if (tree == null)
3062
+ throw Error("'yarn list --json' did not output a tree");
3063
+ const queue = [...tree.trees];
3064
+ const dependencies = [];
3065
+ while (queue.length > 0) {
3066
+ const { name: treeName, children } = queue.pop();
3067
+ const match = /(@?\S+)@(\S+)$/.exec(treeName);
3068
+ if (match) {
3069
+ const [_, name, version2] = match;
3070
+ dependencies.push({ name, version: version2 });
3071
+ }
3072
+ if (children != null) {
3073
+ queue.push(...children);
3074
+ }
3075
+ }
3076
+ return dedupeDependencies(dependencies);
3077
+ }
3078
+ };
3079
+
3080
+ // src/core/package-managers/pnpm.ts
3081
+ var pnpm = {
3082
+ overridesKey: "resolutions",
3083
+ // "pnpm.overrides" has a higher priority, but I don't want to deal with nesting
3084
+ downloadDependency(...args) {
3085
+ return npm.downloadDependency(...args);
3086
+ },
3087
+ async listDependencies(options) {
3088
+ const args = ["ls", "--json"];
3089
+ if (options?.all) {
3090
+ args.push("--depth", "Infinity");
3091
+ }
3092
+ if (typeof process !== "undefined" && process.env.WXT_PNPM_IGNORE_WORKSPACE === "true") {
3093
+ args.push("--ignore-workspace");
3094
+ }
3095
+ const { execa } = await import("./execa-4F7CCWCA.js");
3096
+ const res = await execa("pnpm", args, { cwd: options?.cwd });
3097
+ const projects = JSON.parse(res.stdout);
3098
+ return flattenNpmListOutput(projects);
3099
+ }
3100
+ };
3101
+
3102
+ // src/core/package-managers/index.ts
3103
+ async function createWxtPackageManager(root) {
3104
+ const pm = await detectPackageManager(root, {
3105
+ includeParentDirs: true
3106
+ });
3107
+ const requirePm = (cb) => {
3108
+ if (pm == null)
3109
+ throw Error("Could not detect package manager");
3110
+ return cb(pm);
3111
+ };
3112
+ return {
3113
+ get name() {
3114
+ return requirePm((pm2) => pm2.name);
3115
+ },
3116
+ get command() {
3117
+ return requirePm((pm2) => pm2.command);
3118
+ },
3119
+ get version() {
3120
+ return requirePm((pm2) => pm2.version);
3121
+ },
3122
+ get majorVersion() {
3123
+ return requirePm((pm2) => pm2.majorVersion);
3124
+ },
3125
+ get lockFile() {
3126
+ return requirePm((pm2) => pm2.lockFile);
3127
+ },
3128
+ get files() {
3129
+ return requirePm((pm2) => pm2.files);
3130
+ },
3131
+ addDependency,
3132
+ addDevDependency,
3133
+ ensureDependencyInstalled,
3134
+ installDependencies,
3135
+ removeDependency,
3136
+ get overridesKey() {
3137
+ return requirePm((pm2) => packageManagers[pm2.name].overridesKey);
3138
+ },
3139
+ downloadDependency(...args) {
3140
+ return requirePm(
3141
+ (pm2) => packageManagers[pm2.name].downloadDependency(...args)
3142
+ );
3143
+ },
3144
+ listDependencies(...args) {
3145
+ return requirePm(
3146
+ (pm2) => packageManagers[pm2.name].listDependencies(...args)
3147
+ );
3148
+ }
3149
+ };
3150
+ }
3151
+ var packageManagers = {
3152
+ npm,
3153
+ pnpm,
3154
+ bun,
3155
+ yarn
3156
+ };
3157
+
3158
+ // src/core/wxt.ts
2949
3159
  var wxt;
2950
3160
  async function registerWxt(command, inlineConfig = {}, server) {
2951
3161
  const config = await resolveConfig(inlineConfig, command, server);
2952
3162
  const hooks = createHooks();
3163
+ const pm = await createWxtPackageManager(config.root);
2953
3164
  wxt = {
2954
3165
  config,
2955
3166
  hooks,
@@ -2958,13 +3169,15 @@ async function registerWxt(command, inlineConfig = {}, server) {
2958
3169
  },
2959
3170
  async reloadConfig() {
2960
3171
  wxt.config = await resolveConfig(inlineConfig, command, server);
2961
- }
3172
+ },
3173
+ pm
2962
3174
  };
2963
3175
  wxt.hooks.addHooks(config.hooks);
2964
3176
  await wxt.hooks.callHook("ready", wxt);
2965
3177
  }
2966
3178
 
2967
3179
  export {
3180
+ normalizePath,
2968
3181
  unnormalizePath,
2969
3182
  wxt,
2970
3183
  registerWxt,
@@ -0,0 +1,38 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ export {
35
+ __require,
36
+ __commonJS,
37
+ __toESM
38
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+
2
+ export { }