wxt 0.14.5 → 0.14.6
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/{chunk-YECUTQH3.js → chunk-XDRW7AKZ.js} +127 -11
- package/dist/cli.js +212 -53
- package/dist/{external-biT0d3qK.d.cts → external-mJ1bW7iy.d.cts} +18 -2
- package/dist/{external-biT0d3qK.d.ts → external-mJ1bW7iy.d.ts} +18 -2
- package/dist/index.cjs +224 -68
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +56 -16
- package/dist/testing.cjs +8 -0
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -130,12 +130,12 @@ var require_isexe = __commonJS({
|
|
|
130
130
|
if (typeof Promise !== "function") {
|
|
131
131
|
throw new TypeError("callback not provided");
|
|
132
132
|
}
|
|
133
|
-
return new Promise(function(
|
|
133
|
+
return new Promise(function(resolve15, reject) {
|
|
134
134
|
isexe(path10, options || {}, function(er, is) {
|
|
135
135
|
if (er) {
|
|
136
136
|
reject(er);
|
|
137
137
|
} else {
|
|
138
|
-
|
|
138
|
+
resolve15(is);
|
|
139
139
|
}
|
|
140
140
|
});
|
|
141
141
|
});
|
|
@@ -202,27 +202,27 @@ var require_which = __commonJS({
|
|
|
202
202
|
opt = {};
|
|
203
203
|
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
|
|
204
204
|
const found = [];
|
|
205
|
-
const step = (i) => new Promise((
|
|
205
|
+
const step = (i) => new Promise((resolve15, reject) => {
|
|
206
206
|
if (i === pathEnv.length)
|
|
207
|
-
return opt.all && found.length ?
|
|
207
|
+
return opt.all && found.length ? resolve15(found) : reject(getNotFoundError(cmd));
|
|
208
208
|
const ppRaw = pathEnv[i];
|
|
209
209
|
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
|
|
210
210
|
const pCmd = path10.join(pathPart, cmd);
|
|
211
211
|
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
|
|
212
|
-
|
|
212
|
+
resolve15(subStep(p, i, 0));
|
|
213
213
|
});
|
|
214
|
-
const subStep = (p, i, ii) => new Promise((
|
|
214
|
+
const subStep = (p, i, ii) => new Promise((resolve15, reject) => {
|
|
215
215
|
if (ii === pathExt.length)
|
|
216
|
-
return
|
|
216
|
+
return resolve15(step(i + 1));
|
|
217
217
|
const ext = pathExt[ii];
|
|
218
218
|
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
|
|
219
219
|
if (!er && is) {
|
|
220
220
|
if (opt.all)
|
|
221
221
|
found.push(p + ext);
|
|
222
222
|
else
|
|
223
|
-
return
|
|
223
|
+
return resolve15(p + ext);
|
|
224
224
|
}
|
|
225
|
-
return
|
|
225
|
+
return resolve15(subStep(p, i, ii + 1));
|
|
226
226
|
});
|
|
227
227
|
});
|
|
228
228
|
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
|
|
@@ -1529,7 +1529,7 @@ var init_kill = __esm({
|
|
|
1529
1529
|
return spawnedPromise;
|
|
1530
1530
|
}
|
|
1531
1531
|
let timeoutId;
|
|
1532
|
-
const timeoutPromise = new Promise((
|
|
1532
|
+
const timeoutPromise = new Promise((resolve15, reject) => {
|
|
1533
1533
|
timeoutId = setTimeout(() => {
|
|
1534
1534
|
timeoutKill(spawned, killSignal, reject);
|
|
1535
1535
|
}, timeout);
|
|
@@ -2013,9 +2013,9 @@ var init_promise = __esm({
|
|
|
2013
2013
|
Reflect.defineProperty(spawned, property, { ...descriptor, value });
|
|
2014
2014
|
}
|
|
2015
2015
|
};
|
|
2016
|
-
getSpawnedPromise = (spawned) => new Promise((
|
|
2016
|
+
getSpawnedPromise = (spawned) => new Promise((resolve15, reject) => {
|
|
2017
2017
|
spawned.on("exit", (exitCode, signal) => {
|
|
2018
|
-
|
|
2018
|
+
resolve15({ exitCode, signal });
|
|
2019
2019
|
});
|
|
2020
2020
|
spawned.on("error", (error) => {
|
|
2021
2021
|
reject(error);
|
|
@@ -2497,11 +2497,27 @@ function every(array, predicate) {
|
|
|
2497
2497
|
return false;
|
|
2498
2498
|
return true;
|
|
2499
2499
|
}
|
|
2500
|
+
function some(array, predicate) {
|
|
2501
|
+
for (let i = 0; i < array.length; i++)
|
|
2502
|
+
if (predicate(array[i], i))
|
|
2503
|
+
return true;
|
|
2504
|
+
return false;
|
|
2505
|
+
}
|
|
2500
2506
|
|
|
2501
2507
|
// src/core/utils/building/detect-dev-changes.ts
|
|
2502
|
-
function detectDevChanges(changedFiles, currentOutput) {
|
|
2503
|
-
|
|
2504
|
-
|
|
2508
|
+
function detectDevChanges(config, changedFiles, currentOutput) {
|
|
2509
|
+
const isConfigChange = some(
|
|
2510
|
+
changedFiles,
|
|
2511
|
+
(file) => file === config.userConfigMetadata.configFile
|
|
2512
|
+
);
|
|
2513
|
+
if (isConfigChange)
|
|
2514
|
+
return { type: "full-restart" };
|
|
2515
|
+
const isRunnerChange = some(
|
|
2516
|
+
changedFiles,
|
|
2517
|
+
(file) => file === config.runnerConfig.configFile
|
|
2518
|
+
);
|
|
2519
|
+
if (isRunnerChange)
|
|
2520
|
+
return { type: "browser-restart" };
|
|
2505
2521
|
const changedSteps = new Set(
|
|
2506
2522
|
changedFiles.flatMap(
|
|
2507
2523
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
@@ -2533,7 +2549,7 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
2533
2549
|
unchangedOutput.publicAssets.push(asset);
|
|
2534
2550
|
}
|
|
2535
2551
|
}
|
|
2536
|
-
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (
|
|
2552
|
+
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
2537
2553
|
if (isOnlyHtmlChanges) {
|
|
2538
2554
|
return {
|
|
2539
2555
|
type: "html-reload",
|
|
@@ -2561,7 +2577,7 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
2561
2577
|
}
|
|
2562
2578
|
function findEffectedSteps(changedFile, currentOutput) {
|
|
2563
2579
|
const changes = [];
|
|
2564
|
-
const changedPath = normalizePath(changedFile
|
|
2580
|
+
const changedPath = normalizePath(changedFile);
|
|
2565
2581
|
const isChunkEffected = (chunk) => (
|
|
2566
2582
|
// If it's an HTML file with the same path, is is effected because HTML files need to be pre-rendered
|
|
2567
2583
|
// fileName is normalized, relative bundle path
|
|
@@ -3912,6 +3928,9 @@ async function createViteBuilder(inlineConfig, userConfig, wxtConfig) {
|
|
|
3912
3928
|
async listen() {
|
|
3913
3929
|
await viteServer.listen(info.port);
|
|
3914
3930
|
},
|
|
3931
|
+
async close() {
|
|
3932
|
+
await viteServer.close();
|
|
3933
|
+
},
|
|
3915
3934
|
transformHtml(...args) {
|
|
3916
3935
|
return viteServer.transformIndexHtml(...args);
|
|
3917
3936
|
},
|
|
@@ -4381,7 +4400,7 @@ function getChunkSortWeight(filename) {
|
|
|
4381
4400
|
var import_picocolors4 = __toESM(require("picocolors"), 1);
|
|
4382
4401
|
|
|
4383
4402
|
// package.json
|
|
4384
|
-
var version = "0.14.
|
|
4403
|
+
var version = "0.14.6";
|
|
4385
4404
|
|
|
4386
4405
|
// src/core/utils/log/printHeader.ts
|
|
4387
4406
|
var import_consola2 = require("consola");
|
|
@@ -4964,6 +4983,70 @@ async function rebuild(config, allEntrypoints, entrypointGroups, existingOutput
|
|
|
4964
4983
|
}
|
|
4965
4984
|
|
|
4966
4985
|
// src/core/utils/building/internal-build.ts
|
|
4986
|
+
var import_manage_path = __toESM(require("manage-path"), 1);
|
|
4987
|
+
var import_node_path13 = require("path");
|
|
4988
|
+
|
|
4989
|
+
// src/core/utils/validation.ts
|
|
4990
|
+
function validateEntrypoints(entrypoints) {
|
|
4991
|
+
const errors = entrypoints.flatMap((entrypoint) => {
|
|
4992
|
+
switch (entrypoint.type) {
|
|
4993
|
+
case "content-script":
|
|
4994
|
+
return validateContentScriptEntrypoint(entrypoint);
|
|
4995
|
+
default:
|
|
4996
|
+
return validateBaseEntrypoint(entrypoint);
|
|
4997
|
+
}
|
|
4998
|
+
});
|
|
4999
|
+
let errorCount = 0;
|
|
5000
|
+
let warningCount = 0;
|
|
5001
|
+
for (const err of errors) {
|
|
5002
|
+
if (err.type === "warning")
|
|
5003
|
+
warningCount++;
|
|
5004
|
+
else
|
|
5005
|
+
errorCount++;
|
|
5006
|
+
}
|
|
5007
|
+
return {
|
|
5008
|
+
errors,
|
|
5009
|
+
errorCount,
|
|
5010
|
+
warningCount
|
|
5011
|
+
};
|
|
5012
|
+
}
|
|
5013
|
+
function validateContentScriptEntrypoint(definition) {
|
|
5014
|
+
const errors = validateBaseEntrypoint(definition);
|
|
5015
|
+
if (definition.options.matches == null) {
|
|
5016
|
+
errors.push({
|
|
5017
|
+
type: "error",
|
|
5018
|
+
message: "`matches` is required",
|
|
5019
|
+
value: definition.options.matches,
|
|
5020
|
+
entrypoint: definition
|
|
5021
|
+
});
|
|
5022
|
+
}
|
|
5023
|
+
return errors;
|
|
5024
|
+
}
|
|
5025
|
+
function validateBaseEntrypoint(definition) {
|
|
5026
|
+
const errors = [];
|
|
5027
|
+
if (definition.options.exclude != null && !Array.isArray(definition.options.exclude)) {
|
|
5028
|
+
errors.push({
|
|
5029
|
+
type: "error",
|
|
5030
|
+
message: "`exclude` must be an array of browser names",
|
|
5031
|
+
value: definition.options.exclude,
|
|
5032
|
+
entrypoint: definition
|
|
5033
|
+
});
|
|
5034
|
+
}
|
|
5035
|
+
if (definition.options.include != null && !Array.isArray(definition.options.include)) {
|
|
5036
|
+
errors.push({
|
|
5037
|
+
type: "error",
|
|
5038
|
+
message: "`include` must be an array of browser names",
|
|
5039
|
+
value: definition.options.include,
|
|
5040
|
+
entrypoint: definition
|
|
5041
|
+
});
|
|
5042
|
+
}
|
|
5043
|
+
return errors;
|
|
5044
|
+
}
|
|
5045
|
+
var ValidationError = class extends Error {
|
|
5046
|
+
};
|
|
5047
|
+
|
|
5048
|
+
// src/core/utils/building/internal-build.ts
|
|
5049
|
+
var import_consola3 = __toESM(require("consola"), 1);
|
|
4967
5050
|
async function internalBuild(config) {
|
|
4968
5051
|
const verb = config.command === "serve" ? "Pre-rendering" : "Building";
|
|
4969
5052
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
@@ -4977,6 +5060,15 @@ async function internalBuild(config) {
|
|
|
4977
5060
|
await import_fs_extra12.default.ensureDir(config.outDir);
|
|
4978
5061
|
const entrypoints = await findEntrypoints(config);
|
|
4979
5062
|
config.logger.debug("Detected entrypoints:", entrypoints);
|
|
5063
|
+
const validationResults = validateEntrypoints(entrypoints);
|
|
5064
|
+
if (validationResults.errorCount + validationResults.warningCount > 0) {
|
|
5065
|
+
printValidationResults(config, validationResults);
|
|
5066
|
+
}
|
|
5067
|
+
if (validationResults.errorCount > 0) {
|
|
5068
|
+
throw new ValidationError(`Entrypoint validation failed`, {
|
|
5069
|
+
cause: validationResults
|
|
5070
|
+
});
|
|
5071
|
+
}
|
|
4980
5072
|
const groups = groupEntrypoints(entrypoints);
|
|
4981
5073
|
const { output, warnings } = await rebuild(
|
|
4982
5074
|
config,
|
|
@@ -5009,11 +5101,35 @@ async function combineAnalysisStats(config) {
|
|
|
5009
5101
|
absolute: true
|
|
5010
5102
|
});
|
|
5011
5103
|
const absolutePaths = unixFiles.map(unnormalizePath);
|
|
5104
|
+
const alterPath = (0, import_manage_path.default)(process.env);
|
|
5105
|
+
alterPath.push((0, import_node_path13.resolve)(config.root, "node_modules/wxt/node_modules/.bin"));
|
|
5012
5106
|
await execaCommand2(
|
|
5013
5107
|
`rollup-plugin-visualizer ${absolutePaths.join(" ")} --template ${config.analysis.template}`,
|
|
5014
5108
|
{ cwd: config.root, stdio: "inherit" }
|
|
5015
5109
|
);
|
|
5016
5110
|
}
|
|
5111
|
+
function printValidationResults(config, { errorCount, errors, warningCount }) {
|
|
5112
|
+
(errorCount > 0 ? config.logger.error : config.logger.warn)(
|
|
5113
|
+
`Entrypoint validation failed: ${errorCount} error${errorCount === 1 ? "" : "s"}, ${warningCount} warning${warningCount === 1 ? "" : "s"}`
|
|
5114
|
+
);
|
|
5115
|
+
const cwd = process.cwd();
|
|
5116
|
+
const entrypointErrors = errors.reduce((map, error) => {
|
|
5117
|
+
const entryErrors = map.get(error.entrypoint) ?? [];
|
|
5118
|
+
entryErrors.push(error);
|
|
5119
|
+
map.set(error.entrypoint, entryErrors);
|
|
5120
|
+
return map;
|
|
5121
|
+
}, /* @__PURE__ */ new Map());
|
|
5122
|
+
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
|
|
5123
|
+
import_consola3.default.log((0, import_node_path13.relative)(cwd, entrypoint.inputPath));
|
|
5124
|
+
console.log();
|
|
5125
|
+
errors2.forEach((err) => {
|
|
5126
|
+
const type = err.type === "error" ? import_picocolors5.default.red("ERROR") : import_picocolors5.default.yellow("WARN");
|
|
5127
|
+
const recieved = import_picocolors5.default.dim(`(recieved: ${JSON.stringify(err.value)})`);
|
|
5128
|
+
import_consola3.default.log(` - ${type} ${err.message} ${recieved}`);
|
|
5129
|
+
});
|
|
5130
|
+
console.log();
|
|
5131
|
+
});
|
|
5132
|
+
}
|
|
5017
5133
|
|
|
5018
5134
|
// src/core/build.ts
|
|
5019
5135
|
async function build(config) {
|
|
@@ -5022,37 +5138,37 @@ async function build(config) {
|
|
|
5022
5138
|
}
|
|
5023
5139
|
|
|
5024
5140
|
// src/core/clean.ts
|
|
5025
|
-
var
|
|
5141
|
+
var import_node_path14 = __toESM(require("path"), 1);
|
|
5026
5142
|
var import_fast_glob4 = __toESM(require("fast-glob"), 1);
|
|
5027
5143
|
var import_fs_extra13 = __toESM(require("fs-extra"), 1);
|
|
5028
|
-
var
|
|
5144
|
+
var import_consola4 = require("consola");
|
|
5029
5145
|
var import_picocolors6 = __toESM(require("picocolors"), 1);
|
|
5030
5146
|
async function clean(root = process.cwd()) {
|
|
5031
|
-
|
|
5147
|
+
import_consola4.consola.info("Cleaning Project");
|
|
5032
5148
|
const tempDirs = [
|
|
5033
5149
|
"node_modules/.vite",
|
|
5034
5150
|
"node_modules/.cache",
|
|
5035
5151
|
"**/.wxt",
|
|
5036
5152
|
".output/*"
|
|
5037
5153
|
];
|
|
5038
|
-
|
|
5154
|
+
import_consola4.consola.debug("Looking for:", tempDirs.map(import_picocolors6.default.cyan).join(", "));
|
|
5039
5155
|
const directories = await (0, import_fast_glob4.default)(tempDirs, {
|
|
5040
|
-
cwd:
|
|
5156
|
+
cwd: import_node_path14.default.resolve(root),
|
|
5041
5157
|
absolute: true,
|
|
5042
5158
|
onlyDirectories: true,
|
|
5043
5159
|
deep: 2
|
|
5044
5160
|
});
|
|
5045
5161
|
if (directories.length === 0) {
|
|
5046
|
-
|
|
5162
|
+
import_consola4.consola.debug("No generated files found.");
|
|
5047
5163
|
return;
|
|
5048
5164
|
}
|
|
5049
|
-
|
|
5165
|
+
import_consola4.consola.debug(
|
|
5050
5166
|
"Found:",
|
|
5051
|
-
directories.map((dir) => import_picocolors6.default.cyan(
|
|
5167
|
+
directories.map((dir) => import_picocolors6.default.cyan(import_node_path14.default.relative(root, dir))).join(", ")
|
|
5052
5168
|
);
|
|
5053
5169
|
for (const directory of directories) {
|
|
5054
5170
|
await import_fs_extra13.default.rm(directory, { force: true, recursive: true });
|
|
5055
|
-
|
|
5171
|
+
import_consola4.consola.debug("Deleted " + import_picocolors6.default.cyan(import_node_path14.default.relative(root, directory)));
|
|
5056
5172
|
}
|
|
5057
5173
|
}
|
|
5058
5174
|
|
|
@@ -5067,12 +5183,12 @@ function defineRunnerConfig(config) {
|
|
|
5067
5183
|
}
|
|
5068
5184
|
|
|
5069
5185
|
// src/core/runners/wsl.ts
|
|
5070
|
-
var
|
|
5186
|
+
var import_node_path15 = require("path");
|
|
5071
5187
|
function createWslRunner() {
|
|
5072
5188
|
return {
|
|
5073
5189
|
async openBrowser(config) {
|
|
5074
5190
|
config.logger.warn(
|
|
5075
|
-
`Cannot open browser when using WSL. Load "${(0,
|
|
5191
|
+
`Cannot open browser when using WSL. Load "${(0, import_node_path15.relative)(
|
|
5076
5192
|
process.cwd(),
|
|
5077
5193
|
config.outDir
|
|
5078
5194
|
)}" as an unpacked extension manually`
|
|
@@ -5088,7 +5204,7 @@ function createWebExtRunner() {
|
|
|
5088
5204
|
let runner;
|
|
5089
5205
|
return {
|
|
5090
5206
|
async openBrowser(config) {
|
|
5091
|
-
|
|
5207
|
+
const startTime = Date.now();
|
|
5092
5208
|
if (config.browser === "firefox" && config.manifestVersion === 3) {
|
|
5093
5209
|
throw Error(
|
|
5094
5210
|
"Dev mode does not support Firefox MV3. For alternatives, see https://github.com/wxt-dev/wxt/issues/230#issuecomment-1806881653"
|
|
@@ -5133,7 +5249,8 @@ function createWebExtRunner() {
|
|
|
5133
5249
|
config.logger.debug("web-ext options:", options);
|
|
5134
5250
|
const webExt = await import("web-ext-run");
|
|
5135
5251
|
runner = await webExt.default.cmd.run(finalConfig, options);
|
|
5136
|
-
|
|
5252
|
+
const duration = Date.now() - startTime;
|
|
5253
|
+
config.logger.success(`Opened browser in ${formatDuration(duration)}`);
|
|
5137
5254
|
},
|
|
5138
5255
|
async closeBrowser() {
|
|
5139
5256
|
return await runner?.exit();
|
|
@@ -5144,12 +5261,12 @@ var WARN_LOG_LEVEL = 40;
|
|
|
5144
5261
|
var ERROR_LOG_LEVEL = 50;
|
|
5145
5262
|
|
|
5146
5263
|
// src/core/runners/safari.ts
|
|
5147
|
-
var
|
|
5264
|
+
var import_node_path16 = require("path");
|
|
5148
5265
|
function createSafariRunner() {
|
|
5149
5266
|
return {
|
|
5150
5267
|
async openBrowser(config) {
|
|
5151
5268
|
config.logger.warn(
|
|
5152
|
-
`Cannot Safari using web-ext. Load "${(0,
|
|
5269
|
+
`Cannot Safari using web-ext. Load "${(0, import_node_path16.relative)(
|
|
5153
5270
|
process.cwd(),
|
|
5154
5271
|
config.outDir
|
|
5155
5272
|
)}" as an unpacked extension manually`
|
|
@@ -5161,12 +5278,12 @@ function createSafariRunner() {
|
|
|
5161
5278
|
}
|
|
5162
5279
|
|
|
5163
5280
|
// src/core/runners/manual.ts
|
|
5164
|
-
var
|
|
5281
|
+
var import_node_path17 = require("path");
|
|
5165
5282
|
function createManualRunner() {
|
|
5166
5283
|
return {
|
|
5167
5284
|
async openBrowser(config) {
|
|
5168
5285
|
config.logger.info(
|
|
5169
|
-
`Load "${(0,
|
|
5286
|
+
`Load "${(0, import_node_path17.relative)(
|
|
5170
5287
|
process.cwd(),
|
|
5171
5288
|
config.outDir
|
|
5172
5289
|
)}" as an unpacked extension manually`
|
|
@@ -5195,10 +5312,10 @@ async function createExtensionRunner(config) {
|
|
|
5195
5312
|
}
|
|
5196
5313
|
|
|
5197
5314
|
// src/core/create-server.ts
|
|
5198
|
-
var
|
|
5315
|
+
var import_consola5 = require("consola");
|
|
5199
5316
|
var import_async_mutex = require("async-mutex");
|
|
5200
5317
|
var import_picocolors7 = __toESM(require("picocolors"), 1);
|
|
5201
|
-
var
|
|
5318
|
+
var import_node_path18 = require("path");
|
|
5202
5319
|
async function createServer(inlineConfig) {
|
|
5203
5320
|
const port = await getPort();
|
|
5204
5321
|
const hostname = "localhost";
|
|
@@ -5208,19 +5325,36 @@ async function createServer(inlineConfig) {
|
|
|
5208
5325
|
hostname,
|
|
5209
5326
|
origin
|
|
5210
5327
|
};
|
|
5328
|
+
const buildAndOpenBrowser = async () => {
|
|
5329
|
+
server.currentOutput = await internalBuild(config);
|
|
5330
|
+
await runner.openBrowser(config);
|
|
5331
|
+
};
|
|
5332
|
+
const closeAndRecreateRunner = async () => {
|
|
5333
|
+
await runner.closeBrowser();
|
|
5334
|
+
config = await getLatestConfig();
|
|
5335
|
+
runner = await createExtensionRunner(config);
|
|
5336
|
+
};
|
|
5211
5337
|
const server = {
|
|
5212
5338
|
...serverInfo,
|
|
5213
|
-
watcher
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
|
|
5339
|
+
get watcher() {
|
|
5340
|
+
return builderServer.watcher;
|
|
5341
|
+
},
|
|
5342
|
+
get ws() {
|
|
5343
|
+
return builderServer.ws;
|
|
5344
|
+
},
|
|
5217
5345
|
currentOutput: void 0,
|
|
5218
|
-
// Filled out later down below
|
|
5219
5346
|
async start() {
|
|
5220
5347
|
await builderServer.listen();
|
|
5221
5348
|
config.logger.success(`Started dev server @ ${serverInfo.origin}`);
|
|
5222
|
-
|
|
5223
|
-
|
|
5349
|
+
await buildAndOpenBrowser();
|
|
5350
|
+
},
|
|
5351
|
+
async stop() {
|
|
5352
|
+
await runner.closeBrowser();
|
|
5353
|
+
await builderServer.close();
|
|
5354
|
+
},
|
|
5355
|
+
async restart() {
|
|
5356
|
+
await closeAndRecreateRunner();
|
|
5357
|
+
await buildAndOpenBrowser();
|
|
5224
5358
|
},
|
|
5225
5359
|
transformHtml(url2, html, originalUrl) {
|
|
5226
5360
|
return builderServer.transformHtml(url2, html, originalUrl);
|
|
@@ -5233,17 +5367,21 @@ async function createServer(inlineConfig) {
|
|
|
5233
5367
|
},
|
|
5234
5368
|
reloadExtension() {
|
|
5235
5369
|
server.ws.send("wxt:reload-extension");
|
|
5370
|
+
},
|
|
5371
|
+
async restartBrowser() {
|
|
5372
|
+
await closeAndRecreateRunner();
|
|
5373
|
+
await runner.openBrowser(config);
|
|
5236
5374
|
}
|
|
5237
5375
|
};
|
|
5238
5376
|
const getLatestConfig = () => getInternalConfig(inlineConfig ?? {}, "serve", server);
|
|
5239
5377
|
let config = await getLatestConfig();
|
|
5240
|
-
|
|
5378
|
+
let [runner, builderServer] = await Promise.all([
|
|
5241
5379
|
createExtensionRunner(config),
|
|
5242
5380
|
config.builder.createServer(server)
|
|
5243
5381
|
]);
|
|
5244
|
-
server.watcher = builderServer.watcher;
|
|
5245
|
-
server.ws = builderServer.ws;
|
|
5246
5382
|
server.ws.on("wxt:background-initialized", () => {
|
|
5383
|
+
if (server.currentOutput == null)
|
|
5384
|
+
return;
|
|
5247
5385
|
reloadContentScripts(server.currentOutput.steps, config, server);
|
|
5248
5386
|
});
|
|
5249
5387
|
const reloadOnChange = createFileReloader({
|
|
@@ -5271,18 +5409,34 @@ function createFileReloader(options) {
|
|
|
5271
5409
|
return;
|
|
5272
5410
|
changeQueue.push([event, path10]);
|
|
5273
5411
|
await fileChangedMutex.runExclusive(async () => {
|
|
5274
|
-
|
|
5412
|
+
if (server.currentOutput == null)
|
|
5413
|
+
return;
|
|
5414
|
+
const fileChanges = changeQueue.splice(0, changeQueue.length).map(([_, file]) => file);
|
|
5275
5415
|
if (fileChanges.length === 0)
|
|
5276
5416
|
return;
|
|
5277
|
-
const changes = detectDevChanges(
|
|
5417
|
+
const changes = detectDevChanges(
|
|
5418
|
+
config,
|
|
5419
|
+
fileChanges,
|
|
5420
|
+
server.currentOutput
|
|
5421
|
+
);
|
|
5278
5422
|
if (changes.type === "no-change")
|
|
5279
5423
|
return;
|
|
5424
|
+
if (changes.type === "full-restart") {
|
|
5425
|
+
config.logger.info("Config changed, restarting server...");
|
|
5426
|
+
server.restart();
|
|
5427
|
+
return;
|
|
5428
|
+
}
|
|
5429
|
+
if (changes.type === "browser-restart") {
|
|
5430
|
+
config.logger.info("Runner config changed, restarting browser...");
|
|
5431
|
+
server.restartBrowser();
|
|
5432
|
+
return;
|
|
5433
|
+
}
|
|
5280
5434
|
config.logger.info(
|
|
5281
|
-
`Changed: ${Array.from(new Set(fileChanges
|
|
5435
|
+
`Changed: ${Array.from(new Set(fileChanges)).map((file) => import_picocolors7.default.dim((0, import_node_path18.relative)(config.root, file))).join(", ")}`
|
|
5282
5436
|
);
|
|
5283
5437
|
const rebuiltNames = changes.rebuildGroups.flat().map((entry) => {
|
|
5284
5438
|
return import_picocolors7.default.cyan(
|
|
5285
|
-
(0,
|
|
5439
|
+
(0, import_node_path18.relative)(config.outDir, getEntrypointOutputFile(entry, ""))
|
|
5286
5440
|
);
|
|
5287
5441
|
}).join(import_picocolors7.default.dim(", "));
|
|
5288
5442
|
const allEntrypoints = await findEntrypoints(config);
|
|
@@ -5305,13 +5459,15 @@ function createFileReloader(options) {
|
|
|
5305
5459
|
reloadContentScripts(changes.changedSteps, config, server);
|
|
5306
5460
|
break;
|
|
5307
5461
|
}
|
|
5308
|
-
|
|
5462
|
+
import_consola5.consola.success(`Reloaded: ${rebuiltNames}`);
|
|
5309
5463
|
});
|
|
5310
5464
|
};
|
|
5311
5465
|
}
|
|
5312
5466
|
function reloadContentScripts(steps, config, server) {
|
|
5313
5467
|
if (config.manifestVersion === 3) {
|
|
5314
5468
|
steps.forEach((step) => {
|
|
5469
|
+
if (server.currentOutput == null)
|
|
5470
|
+
return;
|
|
5315
5471
|
const entry = step.entrypoints;
|
|
5316
5472
|
if (Array.isArray(entry) || entry.type !== "content-script")
|
|
5317
5473
|
return;
|
|
@@ -5348,13 +5504,13 @@ function reloadHtmlPages(groups, server, config) {
|
|
|
5348
5504
|
|
|
5349
5505
|
// src/core/initialize.ts
|
|
5350
5506
|
var import_prompts = __toESM(require("prompts"), 1);
|
|
5351
|
-
var
|
|
5507
|
+
var import_consola6 = require("consola");
|
|
5352
5508
|
var import_giget = require("giget");
|
|
5353
5509
|
var import_fs_extra14 = __toESM(require("fs-extra"), 1);
|
|
5354
|
-
var
|
|
5510
|
+
var import_node_path19 = __toESM(require("path"), 1);
|
|
5355
5511
|
var import_picocolors8 = __toESM(require("picocolors"), 1);
|
|
5356
5512
|
async function initialize(options) {
|
|
5357
|
-
|
|
5513
|
+
import_consola6.consola.info("Initalizing new project");
|
|
5358
5514
|
const templates = await listTemplates();
|
|
5359
5515
|
const defaultTemplate = templates.find(
|
|
5360
5516
|
(template) => template.name === options.template?.toLowerCase().trim()
|
|
@@ -5399,17 +5555,17 @@ async function initialize(options) {
|
|
|
5399
5555
|
input.template ??= defaultTemplate;
|
|
5400
5556
|
input.packageManager ??= options.packageManager;
|
|
5401
5557
|
await cloneProject(input);
|
|
5402
|
-
const cdPath =
|
|
5558
|
+
const cdPath = import_node_path19.default.relative(process.cwd(), import_node_path19.default.resolve(input.directory));
|
|
5403
5559
|
console.log();
|
|
5404
|
-
|
|
5560
|
+
import_consola6.consola.log(
|
|
5405
5561
|
`\u2728 WXT project created with the ${TEMPLATE_COLORS[input.template.name]?.(input.template.name) ?? input.template.name} template.`
|
|
5406
5562
|
);
|
|
5407
5563
|
console.log();
|
|
5408
|
-
|
|
5564
|
+
import_consola6.consola.log("Next steps:");
|
|
5409
5565
|
let step = 0;
|
|
5410
5566
|
if (cdPath !== "")
|
|
5411
|
-
|
|
5412
|
-
|
|
5567
|
+
import_consola6.consola.log(` ${++step}.`, import_picocolors8.default.cyan(`cd ${cdPath}`));
|
|
5568
|
+
import_consola6.consola.log(` ${++step}.`, import_picocolors8.default.cyan(`${input.packageManager} install`));
|
|
5413
5569
|
console.log();
|
|
5414
5570
|
}
|
|
5415
5571
|
async function listTemplates() {
|
|
@@ -5451,10 +5607,10 @@ async function cloneProject({
|
|
|
5451
5607
|
force: true
|
|
5452
5608
|
});
|
|
5453
5609
|
await import_fs_extra14.default.move(
|
|
5454
|
-
|
|
5455
|
-
|
|
5610
|
+
import_node_path19.default.join(directory, "_gitignore"),
|
|
5611
|
+
import_node_path19.default.join(directory, ".gitignore")
|
|
5456
5612
|
).catch(
|
|
5457
|
-
(err) =>
|
|
5613
|
+
(err) => import_consola6.consola.warn("Failed to move _gitignore to .gitignore:", err)
|
|
5458
5614
|
);
|
|
5459
5615
|
spinner.succeed();
|
|
5460
5616
|
} catch (err) {
|
|
@@ -5485,7 +5641,7 @@ async function prepare(config) {
|
|
|
5485
5641
|
|
|
5486
5642
|
// src/core/zip.ts
|
|
5487
5643
|
var import_zip_dir = __toESM(require("zip-dir"), 1);
|
|
5488
|
-
var
|
|
5644
|
+
var import_node_path20 = require("path");
|
|
5489
5645
|
var import_fs_extra15 = __toESM(require("fs-extra"), 1);
|
|
5490
5646
|
var import_minimatch2 = require("minimatch");
|
|
5491
5647
|
async function zip(config) {
|
|
@@ -5495,7 +5651,7 @@ async function zip(config) {
|
|
|
5495
5651
|
internalConfig.logger.info("Zipping extension...");
|
|
5496
5652
|
const zipFiles = [];
|
|
5497
5653
|
const projectName = internalConfig.zip.name ?? kebabCaseAlphanumeric(
|
|
5498
|
-
(await getPackageJson(internalConfig))?.name || (0,
|
|
5654
|
+
(await getPackageJson(internalConfig))?.name || (0, import_node_path20.dirname)(process.cwd())
|
|
5499
5655
|
);
|
|
5500
5656
|
const applyTemplate = (template) => template.replaceAll("{{name}}", projectName).replaceAll("{{browser}}", internalConfig.browser).replaceAll(
|
|
5501
5657
|
"{{version}}",
|
|
@@ -5503,7 +5659,7 @@ async function zip(config) {
|
|
|
5503
5659
|
).replaceAll("{{manifestVersion}}", `mv${internalConfig.manifestVersion}`);
|
|
5504
5660
|
await import_fs_extra15.default.ensureDir(internalConfig.outBaseDir);
|
|
5505
5661
|
const outZipFilename = applyTemplate(internalConfig.zip.artifactTemplate);
|
|
5506
|
-
const outZipPath = (0,
|
|
5662
|
+
const outZipPath = (0, import_node_path20.resolve)(internalConfig.outBaseDir, outZipFilename);
|
|
5507
5663
|
await (0, import_zip_dir.default)(internalConfig.outDir, {
|
|
5508
5664
|
saveTo: outZipPath
|
|
5509
5665
|
});
|
|
@@ -5512,14 +5668,14 @@ async function zip(config) {
|
|
|
5512
5668
|
const sourcesZipFilename = applyTemplate(
|
|
5513
5669
|
internalConfig.zip.sourcesTemplate
|
|
5514
5670
|
);
|
|
5515
|
-
const sourcesZipPath = (0,
|
|
5671
|
+
const sourcesZipPath = (0, import_node_path20.resolve)(
|
|
5516
5672
|
internalConfig.outBaseDir,
|
|
5517
5673
|
sourcesZipFilename
|
|
5518
5674
|
);
|
|
5519
5675
|
await (0, import_zip_dir.default)(internalConfig.zip.sourcesRoot, {
|
|
5520
5676
|
saveTo: sourcesZipPath,
|
|
5521
5677
|
filter(path10) {
|
|
5522
|
-
const relativePath = (0,
|
|
5678
|
+
const relativePath = (0, import_node_path20.relative)(internalConfig.zip.sourcesRoot, path10);
|
|
5523
5679
|
const matchedPattern = internalConfig.zip.ignoredSources.find(
|
|
5524
5680
|
(pattern) => (0, import_minimatch2.minimatch)(relativePath, pattern)
|
|
5525
5681
|
);
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-
|
|
2
|
-
export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-
|
|
1
|
+
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-mJ1bW7iy.cjs';
|
|
2
|
+
export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-mJ1bW7iy.cjs';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
@@ -62,6 +62,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
62
62
|
*/
|
|
63
63
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
64
64
|
|
|
65
|
-
var version = "0.14.
|
|
65
|
+
var version = "0.14.6";
|
|
66
66
|
|
|
67
67
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-
|
|
2
|
-
export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-
|
|
1
|
+
import { I as InlineConfig, B as BuildOutput, U as UserConfig, E as ExtensionRunnerConfig, W as WxtDevServer } from './external-mJ1bW7iy.js';
|
|
2
|
+
export { q as BackgroundDefinition, h as BackgroundEntrypoint, g as BaseEntrypoint, f as BaseEntrypointOptions, d as BuildStepOutput, w as ConfigEnv, p as ContentScriptBaseDefinition, m as ContentScriptDefinition, C as ContentScriptEntrypoint, n as ContentScriptIsolatedWorldDefinition, o as ContentScriptMainWorldDefinition, j as Entrypoint, k as EntrypointGroup, t as ExcludableEntrypoint, G as GenericEntrypoint, L as Logger, l as OnContentScriptStopped, i as OptionsEntrypoint, c as OutputAsset, b as OutputChunk, O as OutputFile, s as PerBrowserOption, P as PopupEntrypoint, S as ServerInfo, T as TargetBrowser, e as TargetManifestVersion, r as UnlistedScriptDefinition, u as UserManifest, v as UserManifestFn, x as WxtBuilder, y as WxtBuilderServer, a as WxtViteConfig } from './external-mJ1bW7iy.js';
|
|
3
3
|
import 'vite';
|
|
4
4
|
import 'webextension-polyfill';
|
|
5
5
|
import 'unimport';
|
|
@@ -62,6 +62,6 @@ declare function prepare(config: InlineConfig): Promise<void>;
|
|
|
62
62
|
*/
|
|
63
63
|
declare function zip(config?: InlineConfig): Promise<string[]>;
|
|
64
64
|
|
|
65
|
-
var version = "0.14.
|
|
65
|
+
var version = "0.14.6";
|
|
66
66
|
|
|
67
67
|
export { BuildOutput, ExtensionRunnerConfig, InlineConfig, UserConfig, WxtDevServer, build, clean, createServer, defineConfig, defineRunnerConfig, initialize, prepare, version, zip };
|