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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// package.json
|
|
2
|
-
var version = "0.14.
|
|
2
|
+
var version = "0.14.6";
|
|
3
3
|
|
|
4
4
|
// src/core/utils/arrays.ts
|
|
5
5
|
function every(array, predicate) {
|
|
@@ -8,6 +8,12 @@ function every(array, predicate) {
|
|
|
8
8
|
return false;
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
|
+
function some(array, predicate) {
|
|
12
|
+
for (let i = 0; i < array.length; i++)
|
|
13
|
+
if (predicate(array[i], i))
|
|
14
|
+
return true;
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
11
17
|
|
|
12
18
|
// src/core/utils/paths.ts
|
|
13
19
|
import systemPath from "node:path";
|
|
@@ -22,9 +28,19 @@ var CSS_EXTENSIONS = ["css", "scss", "sass", "less", "styl", "stylus"];
|
|
|
22
28
|
var CSS_EXTENSIONS_PATTERN = `+(${CSS_EXTENSIONS.join("|")})`;
|
|
23
29
|
|
|
24
30
|
// src/core/utils/building/detect-dev-changes.ts
|
|
25
|
-
function detectDevChanges(changedFiles, currentOutput) {
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
function detectDevChanges(config, changedFiles, currentOutput) {
|
|
32
|
+
const isConfigChange = some(
|
|
33
|
+
changedFiles,
|
|
34
|
+
(file) => file === config.userConfigMetadata.configFile
|
|
35
|
+
);
|
|
36
|
+
if (isConfigChange)
|
|
37
|
+
return { type: "full-restart" };
|
|
38
|
+
const isRunnerChange = some(
|
|
39
|
+
changedFiles,
|
|
40
|
+
(file) => file === config.runnerConfig.configFile
|
|
41
|
+
);
|
|
42
|
+
if (isRunnerChange)
|
|
43
|
+
return { type: "browser-restart" };
|
|
28
44
|
const changedSteps = new Set(
|
|
29
45
|
changedFiles.flatMap(
|
|
30
46
|
(changedFile) => findEffectedSteps(changedFile, currentOutput)
|
|
@@ -56,7 +72,7 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
56
72
|
unchangedOutput.publicAssets.push(asset);
|
|
57
73
|
}
|
|
58
74
|
}
|
|
59
|
-
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (
|
|
75
|
+
const isOnlyHtmlChanges = changedFiles.length > 0 && every(changedFiles, (file) => file.endsWith(".html"));
|
|
60
76
|
if (isOnlyHtmlChanges) {
|
|
61
77
|
return {
|
|
62
78
|
type: "html-reload",
|
|
@@ -84,7 +100,7 @@ function detectDevChanges(changedFiles, currentOutput) {
|
|
|
84
100
|
}
|
|
85
101
|
function findEffectedSteps(changedFile, currentOutput) {
|
|
86
102
|
const changes = [];
|
|
87
|
-
const changedPath = normalizePath(changedFile
|
|
103
|
+
const changedPath = normalizePath(changedFile);
|
|
88
104
|
const isChunkEffected = (chunk) => (
|
|
89
105
|
// If it's an HTML file with the same path, is is effected because HTML files need to be pre-rendered
|
|
90
106
|
// fileName is normalized, relative bundle path
|
|
@@ -127,7 +143,7 @@ function resolvePerBrowserOption(option, browser) {
|
|
|
127
143
|
}
|
|
128
144
|
|
|
129
145
|
// src/core/utils/building/find-entrypoints.ts
|
|
130
|
-
import { relative as
|
|
146
|
+
import { relative as relative6, resolve as resolve13 } from "path";
|
|
131
147
|
import fs12 from "fs-extra";
|
|
132
148
|
import { minimatch } from "minimatch";
|
|
133
149
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -1172,6 +1188,9 @@ async function createViteBuilder(inlineConfig, userConfig, wxtConfig) {
|
|
|
1172
1188
|
async listen() {
|
|
1173
1189
|
await viteServer.listen(info.port);
|
|
1174
1190
|
},
|
|
1191
|
+
async close() {
|
|
1192
|
+
await viteServer.close();
|
|
1193
|
+
},
|
|
1175
1194
|
transformHtml(...args) {
|
|
1176
1195
|
return viteServer.transformIndexHtml(...args);
|
|
1177
1196
|
},
|
|
@@ -2218,6 +2237,70 @@ async function rebuild(config, allEntrypoints, entrypointGroups, existingOutput
|
|
|
2218
2237
|
}
|
|
2219
2238
|
|
|
2220
2239
|
// src/core/utils/building/internal-build.ts
|
|
2240
|
+
import managePath from "manage-path";
|
|
2241
|
+
import { resolve as resolve12, relative as relative5 } from "node:path";
|
|
2242
|
+
|
|
2243
|
+
// src/core/utils/validation.ts
|
|
2244
|
+
function validateEntrypoints(entrypoints) {
|
|
2245
|
+
const errors = entrypoints.flatMap((entrypoint) => {
|
|
2246
|
+
switch (entrypoint.type) {
|
|
2247
|
+
case "content-script":
|
|
2248
|
+
return validateContentScriptEntrypoint(entrypoint);
|
|
2249
|
+
default:
|
|
2250
|
+
return validateBaseEntrypoint(entrypoint);
|
|
2251
|
+
}
|
|
2252
|
+
});
|
|
2253
|
+
let errorCount = 0;
|
|
2254
|
+
let warningCount = 0;
|
|
2255
|
+
for (const err of errors) {
|
|
2256
|
+
if (err.type === "warning")
|
|
2257
|
+
warningCount++;
|
|
2258
|
+
else
|
|
2259
|
+
errorCount++;
|
|
2260
|
+
}
|
|
2261
|
+
return {
|
|
2262
|
+
errors,
|
|
2263
|
+
errorCount,
|
|
2264
|
+
warningCount
|
|
2265
|
+
};
|
|
2266
|
+
}
|
|
2267
|
+
function validateContentScriptEntrypoint(definition) {
|
|
2268
|
+
const errors = validateBaseEntrypoint(definition);
|
|
2269
|
+
if (definition.options.matches == null) {
|
|
2270
|
+
errors.push({
|
|
2271
|
+
type: "error",
|
|
2272
|
+
message: "`matches` is required",
|
|
2273
|
+
value: definition.options.matches,
|
|
2274
|
+
entrypoint: definition
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
return errors;
|
|
2278
|
+
}
|
|
2279
|
+
function validateBaseEntrypoint(definition) {
|
|
2280
|
+
const errors = [];
|
|
2281
|
+
if (definition.options.exclude != null && !Array.isArray(definition.options.exclude)) {
|
|
2282
|
+
errors.push({
|
|
2283
|
+
type: "error",
|
|
2284
|
+
message: "`exclude` must be an array of browser names",
|
|
2285
|
+
value: definition.options.exclude,
|
|
2286
|
+
entrypoint: definition
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
if (definition.options.include != null && !Array.isArray(definition.options.include)) {
|
|
2290
|
+
errors.push({
|
|
2291
|
+
type: "error",
|
|
2292
|
+
message: "`include` must be an array of browser names",
|
|
2293
|
+
value: definition.options.include,
|
|
2294
|
+
entrypoint: definition
|
|
2295
|
+
});
|
|
2296
|
+
}
|
|
2297
|
+
return errors;
|
|
2298
|
+
}
|
|
2299
|
+
var ValidationError = class extends Error {
|
|
2300
|
+
};
|
|
2301
|
+
|
|
2302
|
+
// src/core/utils/building/internal-build.ts
|
|
2303
|
+
import consola3 from "consola";
|
|
2221
2304
|
async function internalBuild(config) {
|
|
2222
2305
|
const verb = config.command === "serve" ? "Pre-rendering" : "Building";
|
|
2223
2306
|
const target = `${config.browser}-mv${config.manifestVersion}`;
|
|
@@ -2231,6 +2314,15 @@ async function internalBuild(config) {
|
|
|
2231
2314
|
await fs11.ensureDir(config.outDir);
|
|
2232
2315
|
const entrypoints = await findEntrypoints(config);
|
|
2233
2316
|
config.logger.debug("Detected entrypoints:", entrypoints);
|
|
2317
|
+
const validationResults = validateEntrypoints(entrypoints);
|
|
2318
|
+
if (validationResults.errorCount + validationResults.warningCount > 0) {
|
|
2319
|
+
printValidationResults(config, validationResults);
|
|
2320
|
+
}
|
|
2321
|
+
if (validationResults.errorCount > 0) {
|
|
2322
|
+
throw new ValidationError(`Entrypoint validation failed`, {
|
|
2323
|
+
cause: validationResults
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2234
2326
|
const groups = groupEntrypoints(entrypoints);
|
|
2235
2327
|
const { output, warnings } = await rebuild(
|
|
2236
2328
|
config,
|
|
@@ -2263,11 +2355,35 @@ async function combineAnalysisStats(config) {
|
|
|
2263
2355
|
absolute: true
|
|
2264
2356
|
});
|
|
2265
2357
|
const absolutePaths = unixFiles.map(unnormalizePath);
|
|
2358
|
+
const alterPath = managePath(process.env);
|
|
2359
|
+
alterPath.push(resolve12(config.root, "node_modules/wxt/node_modules/.bin"));
|
|
2266
2360
|
await execaCommand(
|
|
2267
2361
|
`rollup-plugin-visualizer ${absolutePaths.join(" ")} --template ${config.analysis.template}`,
|
|
2268
2362
|
{ cwd: config.root, stdio: "inherit" }
|
|
2269
2363
|
);
|
|
2270
2364
|
}
|
|
2365
|
+
function printValidationResults(config, { errorCount, errors, warningCount }) {
|
|
2366
|
+
(errorCount > 0 ? config.logger.error : config.logger.warn)(
|
|
2367
|
+
`Entrypoint validation failed: ${errorCount} error${errorCount === 1 ? "" : "s"}, ${warningCount} warning${warningCount === 1 ? "" : "s"}`
|
|
2368
|
+
);
|
|
2369
|
+
const cwd = process.cwd();
|
|
2370
|
+
const entrypointErrors = errors.reduce((map, error) => {
|
|
2371
|
+
const entryErrors = map.get(error.entrypoint) ?? [];
|
|
2372
|
+
entryErrors.push(error);
|
|
2373
|
+
map.set(error.entrypoint, entryErrors);
|
|
2374
|
+
return map;
|
|
2375
|
+
}, /* @__PURE__ */ new Map());
|
|
2376
|
+
Array.from(entrypointErrors.entries()).forEach(([entrypoint, errors2]) => {
|
|
2377
|
+
consola3.log(relative5(cwd, entrypoint.inputPath));
|
|
2378
|
+
console.log();
|
|
2379
|
+
errors2.forEach((err) => {
|
|
2380
|
+
const type = err.type === "error" ? pc4.red("ERROR") : pc4.yellow("WARN");
|
|
2381
|
+
const recieved = pc4.dim(`(recieved: ${JSON.stringify(err.value)})`);
|
|
2382
|
+
consola3.log(` - ${type} ${err.message} ${recieved}`);
|
|
2383
|
+
});
|
|
2384
|
+
console.log();
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2271
2387
|
|
|
2272
2388
|
// src/core/utils/building/find-entrypoints.ts
|
|
2273
2389
|
import glob3 from "fast-glob";
|
|
@@ -2279,7 +2395,7 @@ async function findEntrypoints(config) {
|
|
|
2279
2395
|
relativePaths.sort();
|
|
2280
2396
|
const pathGlobs = Object.keys(PATH_GLOB_TO_TYPE_MAP);
|
|
2281
2397
|
const entrypointInfos = relativePaths.reduce((results, relativePath) => {
|
|
2282
|
-
const inputPath =
|
|
2398
|
+
const inputPath = resolve13(config.entrypointsDir, relativePath);
|
|
2283
2399
|
const name = getEntrypointName(config.entrypointsDir, inputPath);
|
|
2284
2400
|
const matchingGlob = pathGlobs.find(
|
|
2285
2401
|
(glob4) => minimatch(relativePath, glob4)
|
|
@@ -2319,7 +2435,7 @@ async function findEntrypoints(config) {
|
|
|
2319
2435
|
return {
|
|
2320
2436
|
...info,
|
|
2321
2437
|
type,
|
|
2322
|
-
outputDir:
|
|
2438
|
+
outputDir: resolve13(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2323
2439
|
options: {
|
|
2324
2440
|
include: void 0,
|
|
2325
2441
|
exclude: void 0
|
|
@@ -2392,7 +2508,7 @@ function preventDuplicateEntrypointNames(config, files) {
|
|
|
2392
2508
|
if (absolutePaths.length > 1) {
|
|
2393
2509
|
lines.push(`- ${name}`);
|
|
2394
2510
|
absolutePaths.forEach((absolutePath) => {
|
|
2395
|
-
lines.push(` - ${
|
|
2511
|
+
lines.push(` - ${relative6(config.root, absolutePath)}`);
|
|
2396
2512
|
});
|
|
2397
2513
|
}
|
|
2398
2514
|
return lines;
|
|
@@ -2557,7 +2673,7 @@ async function getContentScriptEntrypoint(config, { inputPath, name, skipped })
|
|
|
2557
2673
|
type: "content-script",
|
|
2558
2674
|
name,
|
|
2559
2675
|
inputPath,
|
|
2560
|
-
outputDir:
|
|
2676
|
+
outputDir: resolve13(config.outDir, CONTENT_SCRIPT_OUT_DIR),
|
|
2561
2677
|
options,
|
|
2562
2678
|
skipped
|
|
2563
2679
|
};
|