nuxt-layerscope 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -0
- package/dist/analyze-DVzyPH7N.mjs +2 -0
- package/dist/{analyze-C78UDFtY.mjs → analyze-QaYmBXyK.mjs} +32 -6
- package/dist/api.mjs +3 -3
- package/dist/bin.mjs +3 -3
- package/dist/eslint.mjs +3 -3
- package/dist/{file-analysis-D9TGP_Nb.mjs → file-analysis-Bh7qcWUK.mjs} +3 -3
- package/dist/index.mjs +3 -3
- package/dist/{layer-factory-xZmIAPrA.mjs → layer-factory-DFh7nkFH.mjs} +15 -1
- package/dist/{unused-Cgg4-LKM.mjs → unused-BtsPSfxb.mjs} +1 -1
- package/dist/{version-D6whhsHH.mjs → version-DFWOUgi5.mjs} +1 -1
- package/package.json +1 -1
- package/dist/analyze-Du9Dkd8L.mjs +0 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
|
|
5
|
+
- A note appears when `nuxt.config` is newer than the registry, because changes to its
|
|
6
|
+
`layerscope` key only apply after `nuxi prepare`, `dev` or `build`.
|
|
7
|
+
- Layer errors caused by the `layerscope` key of `nuxt.config` name it as their source.
|
|
8
|
+
|
|
3
9
|
## 0.1.1
|
|
4
10
|
|
|
5
11
|
- Names inside type syntax are no longer reported as unresolved references: labeled tuple members
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { c as realPath, d as effectiveConfig,
|
|
1
|
+
import { c as realPath, d as effectiveConfig, f as labelConfigError, g as ruleSeverity, h as isRuleName, s as readJson, v as LayerscopeError } from "./layer-factory-DFh7nkFH.mjs";
|
|
2
2
|
import { r as pascalCase, t as compareStrings } from "./strings-CrOjNZmB.mjs";
|
|
3
3
|
import { t as globComponents } from "./component-files-DgOXNE6l.mjs";
|
|
4
|
-
import { c as createOwnerLookup, d as createAnalysisEnv, f as readRegistry, h as boundaryFindings, m as loadSymbolTable, n as analyzeFile, p as tableFromRegistry, r as collectFiles, u as resolveLayers, v as loadConfig } from "./file-analysis-
|
|
4
|
+
import { c as createOwnerLookup, d as createAnalysisEnv, f as readRegistry, h as boundaryFindings, m as loadSymbolTable, n as analyzeFile, p as tableFromRegistry, r as collectFiles, u as resolveLayers, v as loadConfig } from "./file-analysis-Bh7qcWUK.mjs";
|
|
5
5
|
import { basename, extname, join, relative, resolve } from "pathe";
|
|
6
|
-
import { existsSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { existsSync, statSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { escapePath, glob } from "tinyglobby";
|
|
8
8
|
import { spawnSync } from "node:child_process";
|
|
9
9
|
//#region src/baseline/index.ts
|
|
@@ -149,6 +149,24 @@ function runRules(input) {
|
|
|
149
149
|
};
|
|
150
150
|
}
|
|
151
151
|
//#endregion
|
|
152
|
+
//#region src/analyze/config-freshness.ts
|
|
153
|
+
const NUXT_CONFIG_FILES = [
|
|
154
|
+
"nuxt.config.ts",
|
|
155
|
+
"nuxt.config.mts",
|
|
156
|
+
"nuxt.config.js",
|
|
157
|
+
"nuxt.config.mjs"
|
|
158
|
+
];
|
|
159
|
+
/**
|
|
160
|
+
* The registry holds the `layerscope` key of `nuxt.config` as it was at the last `nuxi prepare`,
|
|
161
|
+
* `dev` or `build`, so an edit made since then does not apply yet.
|
|
162
|
+
*/
|
|
163
|
+
function staleConfigNote(rootDir, registryFile) {
|
|
164
|
+
const config = NUXT_CONFIG_FILES.map((name) => join(rootDir, name)).find((file) => existsSync(file));
|
|
165
|
+
if (config === void 0 || !existsSync(registryFile)) return null;
|
|
166
|
+
if (statSync(config).mtimeMs <= statSync(registryFile).mtimeMs) return null;
|
|
167
|
+
return "nuxt.config is newer than the layerscope registry, so changes to its \"layerscope\" key do not apply yet. Run \"nuxi prepare\" again, or pass --prepare.";
|
|
168
|
+
}
|
|
169
|
+
//#endregion
|
|
152
170
|
//#region src/analyze/freshness.ts
|
|
153
171
|
const RERUN_HINT = "Run \"nuxi prepare\" again, or pass --prepare.";
|
|
154
172
|
const COMPONENT_SUFFIX = /(?:\.(?:client|server))?(?:\.global|\.island)*$/u;
|
|
@@ -266,13 +284,21 @@ function recordedConfig(buildDir, registry) {
|
|
|
266
284
|
async function loadEnvironment(options) {
|
|
267
285
|
const { rootDir, buildDir } = options;
|
|
268
286
|
const { registry, table, ...symbols } = loadSymbols(buildDir, options.source);
|
|
269
|
-
const
|
|
270
|
-
const
|
|
287
|
+
const recorded = recordedConfig(buildDir, registry);
|
|
288
|
+
const config = effectiveConfig(options.config, recorded);
|
|
289
|
+
const { layers, ownerOf, notes } = await loadLayers(rootDir, config, registry?.layers).catch((error) => {
|
|
290
|
+
throw labelConfigError(error, recorded);
|
|
291
|
+
});
|
|
292
|
+
const stale = registry === null ? null : staleConfigNote(rootDir, symbols.sourceFile);
|
|
271
293
|
await (registry === null ? assertFresh(table, layers) : assertRegistryFresh(table, registry));
|
|
272
294
|
return {
|
|
273
295
|
...symbols,
|
|
274
296
|
config,
|
|
275
|
-
notes: [
|
|
297
|
+
notes: [
|
|
298
|
+
...symbols.notes,
|
|
299
|
+
...notes,
|
|
300
|
+
...stale === null ? [] : [stale]
|
|
301
|
+
],
|
|
276
302
|
registry,
|
|
277
303
|
layers,
|
|
278
304
|
env: createAnalysisEnv(table, ownerOf, buildDir, config)
|
package/dist/api.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as REGISTRY_FILE, u as REGISTRY_VERSION, v as LayerscopeError } from "./layer-factory-DFh7nkFH.mjs";
|
|
2
2
|
import { t as defineConfig } from "./define-l62B9fVk.mjs";
|
|
3
|
-
import { i as createBaseline, n as BASELINE_FILE, r as BASELINE_VERSION, t as analyze } from "./analyze-
|
|
3
|
+
import { i as createBaseline, n as BASELINE_FILE, r as BASELINE_VERSION, t as analyze } from "./analyze-QaYmBXyK.mjs";
|
|
4
4
|
import { i as JSON_REPORT_VERSION, n as formatResult, t as OUTPUT_FORMATS } from "./report-BNW0GCl9.mjs";
|
|
5
|
-
import { r as buildGraph, t as findUnused } from "./unused-
|
|
5
|
+
import { r as buildGraph, t as findUnused } from "./unused-BtsPSfxb.mjs";
|
|
6
6
|
export { BASELINE_FILE, BASELINE_VERSION, JSON_REPORT_VERSION, LayerscopeError, OUTPUT_FORMATS, REGISTRY_FILE, REGISTRY_VERSION, analyze, buildGraph, createBaseline, defineConfig, findUnused, formatResult };
|
package/dist/bin.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { v as LayerscopeError } from "./layer-factory-DFh7nkFH.mjs";
|
|
3
3
|
import { i as plural, r as pascalCase } from "./strings-CrOjNZmB.mjs";
|
|
4
|
-
import { a as writeBaseline, i as createBaseline, n as BASELINE_FILE, t as analyze } from "./analyze-
|
|
4
|
+
import { a as writeBaseline, i as createBaseline, n as BASELINE_FILE, t as analyze } from "./analyze-QaYmBXyK.mjs";
|
|
5
5
|
import { n as formatResult, r as isOutputFormat, t as OUTPUT_FORMATS } from "./report-BNW0GCl9.mjs";
|
|
6
|
-
import { i as edgeStatus, n as GRAPH_LEVELS, r as buildGraph, t as findUnused } from "./unused-
|
|
6
|
+
import { i as edgeStatus, n as GRAPH_LEVELS, r as buildGraph, t as findUnused } from "./unused-BtsPSfxb.mjs";
|
|
7
7
|
import { relative, resolve } from "pathe";
|
|
8
8
|
import { cac } from "cac";
|
|
9
9
|
//#region src/commands/shared.ts
|
package/dist/eslint.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { d as effectiveConfig, l as REGISTRY_FILE } from "./layer-factory-
|
|
2
|
-
import { t as packageVersion } from "./version-
|
|
3
|
-
import { _ as findConfigFile, a as lineColumn, c as createOwnerLookup, d as createAnalysisEnv, f as readRegistry, h as boundaryFindings, i as isCheckedFile, l as nameLayers, o as offsetAt, p as tableFromRegistry, s as scanFile, t as FileAnalysis, y as loadConfigSync } from "./file-analysis-
|
|
1
|
+
import { d as effectiveConfig, l as REGISTRY_FILE } from "./layer-factory-DFh7nkFH.mjs";
|
|
2
|
+
import { t as packageVersion } from "./version-DFWOUgi5.mjs";
|
|
3
|
+
import { _ as findConfigFile, a as lineColumn, c as createOwnerLookup, d as createAnalysisEnv, f as readRegistry, h as boundaryFindings, i as isCheckedFile, l as nameLayers, o as offsetAt, p as tableFromRegistry, s as scanFile, t as FileAnalysis, y as loadConfigSync } from "./file-analysis-Bh7qcWUK.mjs";
|
|
4
4
|
import { dirname, join, relative, resolve } from "pathe";
|
|
5
5
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
6
6
|
//#region src/eslint/lint-file.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as isClonedFrom, c as realPath, g as
|
|
1
|
+
import { _ as LayerConfigError, a as isClonedFrom, c as realPath, g as ruleSeverity, i as layerFromPath, l as REGISTRY_FILE, m as validateConfig, n as deriveDirectories, o as isFile, r as layerFromNuxt, s as readJson, t as ROOT_LAYER_NAME, v as LayerscopeError } from "./layer-factory-DFh7nkFH.mjs";
|
|
2
2
|
import { n as escapeRegExp, r as pascalCase, t as compareStrings } from "./strings-CrOjNZmB.mjs";
|
|
3
3
|
import { dirname, isAbsolute, join, relative, resolve } from "pathe";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -408,10 +408,10 @@ function validateLayers(layers, config) {
|
|
|
408
408
|
for (const [name, rule] of Object.entries(config.layers ?? {})) {
|
|
409
409
|
if (!names.has(name)) {
|
|
410
410
|
const known = [...names].toSorted().join(", ");
|
|
411
|
-
throw new
|
|
411
|
+
throw new LayerConfigError(`Unknown layer "${name}" in config. Known layers: ${known}`);
|
|
412
412
|
}
|
|
413
413
|
const unknown = rule.allow?.find((allowed) => !names.has(allowed));
|
|
414
|
-
if (unknown !== void 0) throw new
|
|
414
|
+
if (unknown !== void 0) throw new LayerConfigError(`layers.${name}.allow: unknown layer "${unknown}"`);
|
|
415
415
|
}
|
|
416
416
|
}
|
|
417
417
|
//#endregion
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as REGISTRY_FILE, p as pickProjectConfig, r as layerFromNuxt } from "./layer-factory-DFh7nkFH.mjs";
|
|
2
2
|
import { t as summarize } from "./summary-DiUYKMPe.mjs";
|
|
3
3
|
import { i as plural, t as compareStrings } from "./strings-CrOjNZmB.mjs";
|
|
4
|
-
import { t as packageVersion } from "./version-
|
|
4
|
+
import { t as packageVersion } from "./version-DFWOUgi5.mjs";
|
|
5
5
|
import { t as globComponents } from "./component-files-DgOXNE6l.mjs";
|
|
6
6
|
import { t as defineConfig } from "./define-l62B9fVk.mjs";
|
|
7
7
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
@@ -106,7 +106,7 @@ function renderError(message) {
|
|
|
106
106
|
//#region src/devtools/index.ts
|
|
107
107
|
const DEVTOOLS_ROUTE = "/__layerscope";
|
|
108
108
|
async function renderReport(nuxt, format) {
|
|
109
|
-
const [{ analyze }, { formatResult }] = await Promise.all([import("./analyze-
|
|
109
|
+
const [{ analyze }, { formatResult }] = await Promise.all([import("./analyze-DVzyPH7N.mjs"), import("./report-DtAi0vPb.mjs")]);
|
|
110
110
|
const { rootDir, app } = nuxt.options;
|
|
111
111
|
const result = await analyze({ rootDir });
|
|
112
112
|
if (format === "json") return formatResult(result, "json", rootDir);
|
|
@@ -9,6 +9,15 @@ var LayerscopeError = class extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
+
//#region src/layer-config-error.ts
|
|
13
|
+
/** A layer name in the config that matches no layer. */
|
|
14
|
+
var LayerConfigError = class extends LayerscopeError {
|
|
15
|
+
constructor(..._args) {
|
|
16
|
+
super(..._args);
|
|
17
|
+
this.name = "LayerConfigError";
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
12
21
|
//#region src/config/rules.ts
|
|
13
22
|
const DEFAULT_SEVERITY = {
|
|
14
23
|
"layer-boundary": "error",
|
|
@@ -70,6 +79,11 @@ function effectiveConfig(fileConfig, recorded) {
|
|
|
70
79
|
...recorded
|
|
71
80
|
};
|
|
72
81
|
}
|
|
82
|
+
/** Names the `nuxt.config` key in a layer error, when the settings that caused it came from there. */
|
|
83
|
+
function labelConfigError(error, recorded) {
|
|
84
|
+
if (error instanceof LayerConfigError && recorded !== void 0 && hasProjectConfig(recorded)) return new LayerscopeError(`${NUXT_CONFIG_LABEL}: ${error.message}`);
|
|
85
|
+
return error;
|
|
86
|
+
}
|
|
73
87
|
//#endregion
|
|
74
88
|
//#region src/registry/schema.ts
|
|
75
89
|
/** Bumped on breaking changes to `registry.json`; readers fall back to the `.d.ts` files. */
|
|
@@ -165,4 +179,4 @@ function layerFromPath(name, root) {
|
|
|
165
179
|
};
|
|
166
180
|
}
|
|
167
181
|
//#endregion
|
|
168
|
-
export { isClonedFrom as a, realPath as c, effectiveConfig as d,
|
|
182
|
+
export { LayerConfigError as _, isClonedFrom as a, realPath as c, effectiveConfig as d, labelConfigError as f, ruleSeverity as g, isRuleName as h, layerFromPath as i, REGISTRY_FILE as l, validateConfig as m, deriveDirectories as n, isFile as o, pickProjectConfig as p, layerFromNuxt as r, readJson as s, ROOT_LAYER_NAME as t, REGISTRY_VERSION as u, LayerscopeError as v };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as compareStrings } from "./strings-CrOjNZmB.mjs";
|
|
2
|
-
import { c as createOwnerLookup, g as isAllowed } from "./file-analysis-
|
|
2
|
+
import { c as createOwnerLookup, g as isAllowed } from "./file-analysis-Bh7qcWUK.mjs";
|
|
3
3
|
import { relative } from "pathe";
|
|
4
4
|
//#region src/rules/edge-status.ts
|
|
5
5
|
/** How the layer rules see one edge. */
|
package/package.json
CHANGED