vite-doctor 0.1.2 → 0.1.4
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/README.md +38 -0
- package/dist/artifacts-BKM8gbLj.mjs +1 -0
- package/dist/{artifacts-Bg8btSBB.mjs → artifacts-CYHDkARd.mjs} +212 -34
- package/dist/bin.d.mts +1 -0
- package/dist/bin.mjs +7 -0
- package/dist/{cache-store-9oluC2IE.mjs → cache-store-CXsq5Lie.mjs} +3 -5
- package/dist/{cli-main-CyF0P2ec.mjs → cli-main-CVmikUmV.mjs} +308 -34
- package/dist/{cli-DAyaFyYp.mjs → cli-run-V69_YrCa.mjs} +5 -12
- package/dist/cli.d.mts +2 -6
- package/dist/cli.mjs +18 -1
- package/dist/{client-C28bTBLq.mjs → client-CuOaE-c8.mjs} +13 -9
- package/dist/{config-CaJ0DqB3.mjs → config-D3G1qfMX.mjs} +1 -2
- package/dist/{config-Vi7rSzhn.d.mts → config-wwwLWUby.d.mts} +4 -4
- package/dist/config.d.mts +3 -2
- package/dist/config.mjs +1 -2
- package/dist/{core-CaB3tfE8.mjs → core-k04MFI77.mjs} +2008 -880
- package/dist/doctor-CBWn_Vgu.mjs +1 -0
- package/dist/{doctor-B_MuQCG9.mjs → doctor-Dat88WI7.mjs} +18 -14
- package/dist/doctor-process.mjs +2 -3
- package/dist/{engine-B7-vSbel.mjs → engine-D-b1VHkw.mjs} +2 -3
- package/dist/extension-RRySKeJC.d.mts +3 -0
- package/dist/extension.d.mts +2 -2
- package/dist/extension.mjs +1 -2
- package/dist/index-5_HywaHt.d.mts +29 -0
- package/dist/index-CPCGMb1S.d.mts +31 -0
- package/dist/index-DMP86a-Y.d.mts +2 -0
- package/dist/index-DW8TxFWt.d.mts +1 -0
- package/dist/index-DiMFm6OS.d.mts +17 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/{internal-diagnostic-handles-R_2cBQaP.mjs → internal-diagnostic-handles-CWwk7gkR.mjs} +22 -6
- package/dist/local-evidence-BSSVSBNP.mjs +542 -0
- package/dist/mcp-Du691Vuz.mjs +613 -0
- package/dist/{migration-BKDeSg5K.mjs → migration-C2WAlVSQ.mjs} +4 -5
- package/dist/{module-Dkz3TqoG.mjs → module-ClC_V7Ia.mjs} +9 -5
- package/dist/{module-BYcUuLDi.d.mts → module-Dc65Bhlf.d.mts} +3 -5
- package/dist/nitro-_dKoORqg.mjs +2 -0
- package/dist/{no-route-middleware-api-security-D8_B1fZx.mjs → no-route-middleware-api-security-CqHF0v_t.mjs} +82 -35
- package/dist/nuxt-cli.mjs +2 -3
- package/dist/nuxt.d.mts +1 -1
- package/dist/nuxt.mjs +1 -2
- package/dist/package-Brn7sEJH.mjs +912 -0
- package/dist/{pinia-BOSWuj_L.mjs → pinia-BfDvlwmh.mjs} +13 -18
- package/dist/plugin-D-VCE4Ui.d.mts +37 -0
- package/dist/{plugin-Dd5QxPcQ.mjs → plugin-rcjM0QLO.mjs} +25 -14
- package/dist/plugin-run-BRyXDOf8.mjs +1 -0
- package/dist/{plugin-run-DVWUGgM8.mjs → plugin-run-CyukQCSU.mjs} +3 -4
- package/dist/plugin-worker.mjs +2 -3
- package/dist/plugin.d.mts +1 -1
- package/dist/plugin.mjs +1 -2
- package/dist/{primitives-nC-P1qet.d.mts → primitives-6q3JlxZh.d.mts} +69 -20
- package/dist/{primitives-QDMBsnjd.mjs → primitives-D-MFha3v.mjs} +5 -7
- package/dist/{protocol-CcLGBETF.mjs → protocol-DN_Gt9Xk.mjs} +2 -2
- package/dist/{rule-authoring-BdNe410l.mjs → rule-authoring-CqCjCYqv.mjs} +3 -4
- package/dist/{rule-inputs-GzH5Uyjz.mjs → rule-inputs-BFfaSgdT.mjs} +1 -2
- package/dist/rule-packs/mcp/index.d.mts +14 -0
- package/dist/rule-packs/mcp/index.mjs +1 -0
- package/dist/rule-packs/nitro/index.d.mts +3 -3
- package/dist/rule-packs/nitro/index.mjs +2 -3
- package/dist/rule-packs/nitro/rules.d.mts +2 -2
- package/dist/rule-packs/nitro/rules.mjs +1 -2
- package/dist/rule-packs/nuxt/index.d.mts +10 -12
- package/dist/rule-packs/nuxt/index.mjs +8 -9
- package/dist/rule-packs/nuxt/module.d.mts +2 -2
- package/dist/rule-packs/nuxt/module.mjs +1 -2
- package/dist/rule-packs/nuxt/rules/index.d.mts +16 -36
- package/dist/rule-packs/nuxt/rules/index.mjs +558 -200
- package/dist/rule-packs/package/index.d.mts +8 -11
- package/dist/rule-packs/package/index.mjs +1 -2
- package/dist/rule-packs/pinia/index.d.mts +9 -19
- package/dist/rule-packs/pinia/index.mjs +1 -2
- package/dist/rule-packs/shadcn/index.d.mts +12 -18
- package/dist/rule-packs/shadcn/index.mjs +1 -2
- package/dist/rule-packs/typescript/index.d.mts +2 -2
- package/dist/rule-packs/typescript/index.mjs +2 -3
- package/dist/rule-packs/typescript/rules/index.d.mts +2 -2
- package/dist/rule-packs/typescript/rules/index.mjs +1 -2
- package/dist/rule-packs/vite/index.d.mts +2 -2
- package/dist/rule-packs/vite/index.mjs +1 -2
- package/dist/rule-packs/vite/rules/index.d.mts +2 -2
- package/dist/rule-packs/vite/rules/index.mjs +1 -2
- package/dist/rule-packs/vue/index.d.mts +2 -2
- package/dist/rule-packs/vue/index.mjs +1 -2
- package/dist/rule-packs/vue/rules.d.mts +2 -2
- package/dist/rule-packs/vue/rules.mjs +1 -2
- package/dist/rules-BQGzDQOv.mjs +2 -0
- package/dist/{rules-DYeVClNx.mjs → rules-DElocQuj.mjs} +1024 -121
- package/dist/rules-DyA0lBFx.d.mts +63 -0
- package/dist/rules-G-cC1C4H.mjs +2940 -0
- package/dist/{rules-DTXdi7Ka.mjs → rules-hQeW5xVi.mjs} +1333 -127
- package/dist/rules-oE64PfR7.mjs +10269 -0
- package/dist/rules.d.mts +2 -2
- package/dist/rules.mjs +2 -3
- package/dist/{runtime-graph-DB9xVYJ4.mjs → runtime-graph-DiifZUjG.mjs} +7 -5
- package/dist/{script-scope-KkOa4q8R.mjs → script-scope-CSSBC2kH.mjs} +8 -6
- package/dist/{server-Ds24tvve.mjs → server-Bnmw4bS-.mjs} +5 -6
- package/dist/{shadcn-CpFqGWl3.mjs → shadcn-jB2qos8b.mjs} +14 -11
- package/dist/testkit.d.mts +7 -9
- package/dist/testkit.mjs +3 -4
- package/dist/typescript-6stxdyep.mjs +2 -0
- package/dist/{version-Qod0rU4x.mjs → version-CDs548Rs.mjs} +1 -2
- package/dist/vite-config-file-BS9cPEGU.mjs +15 -0
- package/dist/{watch-DMUy9-YX.mjs → watch-BcIJ9Qv8.mjs} +2 -3
- package/docs/skills/doctor/SKILL.md +5 -4
- package/package.json +13 -11
- package/dist/doctor-keXSmA0d.mjs +0 -2
- package/dist/extension-BWauKIzu.d.mts +0 -5
- package/dist/index-B8J7duVA.d.mts +0 -44
- package/dist/index-C-XOuvIV.d.mts +0 -2
- package/dist/index-CWqoD7Dt.d.mts +0 -1
- package/dist/index-DEy2t14t.d.mts +0 -72
- package/dist/index-vyjK90RR.d.mts +0 -58
- package/dist/nitro-CPo75d0U.mjs +0 -2
- package/dist/package-C6h9Qtda.mjs +0 -155
- package/dist/plugin-NkM7-RMx.d.mts +0 -24
- package/dist/plugin-run-CzodTs31.mjs +0 -2
- package/dist/rules-BEz9as7i.mjs +0 -1641
- package/dist/rules-CW8Ec0h7.mjs +0 -2
- package/dist/rules-Dg84VwNY.mjs +0 -5297
- package/dist/rules-NQvZWSQD.d.mts +0 -125
- package/dist/typescript-DP3Wc7UQ.mjs +0 -2
package/README.md
CHANGED
|
@@ -88,6 +88,8 @@ The migration report stages source changes that are safe on the installed runtim
|
|
|
88
88
|
|
|
89
89
|
## Configuration
|
|
90
90
|
|
|
91
|
+
Doctor needs no config file: it activates Rule Packs from the project's dependencies. Add config only to change rules, per-path overrides, suppressions, include or exclude globs, or presets. Doctor reports an info-level `DOC0038` Diagnostic for an automatically discovered `doctor.config.json` that only repeats the defaults and can be deleted without changing the run.
|
|
92
|
+
|
|
91
93
|
Doctor automatically loads declarative `doctor.config.json` without executing project code:
|
|
92
94
|
|
|
93
95
|
```json
|
|
@@ -98,6 +100,32 @@ Doctor automatically loads declarative `doctor.config.json` without executing pr
|
|
|
98
100
|
}
|
|
99
101
|
```
|
|
100
102
|
|
|
103
|
+
Or put the same config under the `doctor` key of a statically readable `vite.config.ts`. Doctor parses the file without running it, so the value must be a literal:
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
// vite.config.ts
|
|
107
|
+
import { defineConfig } from "vite-plus";
|
|
108
|
+
import { defineDoctorConfig } from "vite-doctor";
|
|
109
|
+
|
|
110
|
+
export default defineConfig({
|
|
111
|
+
doctor: defineDoctorConfig({
|
|
112
|
+
rules: {
|
|
113
|
+
"vite/define/no-secret-define": "error",
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
// Vite+ has no check hook for other tools; a task makes `vp run check:doctor` run Doctor.
|
|
117
|
+
run: {
|
|
118
|
+
tasks: {
|
|
119
|
+
"check:doctor": { command: "vite-doctor . --max-warnings 0", cache: false },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
See [Run Doctor with Vite+](https://vite-doctor.onmax.me/vite#run-doctor-with-vite) for Nuxt module repositories.
|
|
126
|
+
|
|
127
|
+
If Doctor can't determine whether a dynamic Vite config contains a `doctor` key, select your Doctor config explicitly with `--config doctor.config.json` (use `{}` for defaults).
|
|
128
|
+
|
|
101
129
|
Executable config remains explicit because loading it runs project code:
|
|
102
130
|
|
|
103
131
|
```ts
|
|
@@ -170,6 +198,16 @@ export default defineNuxtConfig({
|
|
|
170
198
|
});
|
|
171
199
|
```
|
|
172
200
|
|
|
201
|
+
### Strict mode
|
|
202
|
+
|
|
203
|
+
By default Doctor runs the recommended preset of every Rule Pack the project activates (`extends: "auto"`). Strict mode runs each activated Rule Pack's strict preset instead, which adds noisier, opinionated, and migration-oriented Rules. Rule Packs without a strict preset keep their recommended preset:
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
pnpm dlx vite-doctor . --strict
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`--strict` is short for `--extends strict`. Set `extends: "strict"` in `doctor.config.json`, `doctor.config.ts`, `doctor({ config })` in Vite config, or the Nuxt `doctor` key to make it the default. In an `extends` list, `"strict"` works like `"auto"` and combines with explicit presets: `["strict", "comark/recommended"]`.
|
|
210
|
+
|
|
173
211
|
### Removed run options
|
|
174
212
|
|
|
175
213
|
Remove `coverage`, `runtimeEvidence`, `emitGraph`, `confidenceMin`, and `scoreOnly` from `DoctorRunOptions` objects. These options had no effect on Doctor Runs; their removal is a breaking TypeScript API change. Runtime Evidence contributors, graph reports, diagnostic confidence, and scoring remain supported.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { t as chainLabeler, n as defaultEntry, r as describeChain, a as installedPackageArtifacts, o as installedWith, c as matchExportKey, l as optionalPeer, u as packageArtifacts } from "./artifacts-CYHDkARd.mjs";
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
-
import { t as RuleInputs } from "./rule-inputs-
|
|
1
|
+
import { t as RuleInputs } from "./rule-inputs-BFfaSgdT.mjs";
|
|
2
2
|
import { isBuiltin } from "node:module";
|
|
3
3
|
import { dirname, isAbsolute, relative, resolve } from "pathe";
|
|
4
4
|
import { parseSync } from "oxc-parser";
|
|
5
5
|
import { basename as basename$1 } from "node:path";
|
|
6
|
-
|
|
6
|
+
// src/rule-packs/package/artifacts.ts
|
|
7
|
+
const defaultEntry = ".";
|
|
8
|
+
function importChain(hop) {
|
|
9
|
+
const chain = [];
|
|
10
|
+
for (let current = hop; current; current = current.previous) chain.unshift(current);
|
|
11
|
+
return chain;
|
|
12
|
+
}
|
|
13
|
+
function mergeReaches(left, right) {
|
|
14
|
+
const merged = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const reach of [...left, ...right]) {
|
|
16
|
+
const key = `${reach.entry}\0${reach.branch}\0${reach.mode}\0${reach.executionRequired}\0${reach.required}`;
|
|
17
|
+
if (!merged.has(key)) merged.set(key, reach);
|
|
18
|
+
}
|
|
19
|
+
return [...merged.values()];
|
|
20
|
+
}
|
|
7
21
|
const scriptExtension = /\.(?:[cm]?js|jsx|[cm]?ts|tsx)$/;
|
|
8
22
|
const declarationExtension = /\.d\.[cm]?ts$/;
|
|
9
23
|
function isRecord(value) {
|
|
@@ -58,19 +72,64 @@ function packageArtifacts(ctx) {
|
|
|
58
72
|
}];
|
|
59
73
|
return inventory;
|
|
60
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Artifacts of the package that Node resolves for `name` from `fromFile`, read once per Doctor Run.
|
|
77
|
+
* Undefined when the package is not installed, is private, or has no package.json.
|
|
78
|
+
*/
|
|
79
|
+
function installedPackageArtifacts(ctx, name, fromFile) {
|
|
80
|
+
let packageRoot;
|
|
81
|
+
for (let directory = dirname(fromFile);; directory = dirname(directory)) {
|
|
82
|
+
const candidate = resolve(directory, "node_modules", name);
|
|
83
|
+
if (ctx.fs.exists(resolve(candidate, "package.json"))) {
|
|
84
|
+
packageRoot = ctx.fs.realpath(candidate) ?? candidate;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (dirname(directory) === directory) return void 0;
|
|
88
|
+
}
|
|
89
|
+
const key = `package:installed:${packageRoot}`;
|
|
90
|
+
const cached = ctx.cache.get(key);
|
|
91
|
+
if (cached !== void 0) return cached ?? void 0;
|
|
92
|
+
const artifacts = packageArtifacts(ctx).find((item) => item.root === packageRoot) ?? readPackageArtifacts(packageRoot, ctx.fs);
|
|
93
|
+
ctx.cache.set(key, artifacts);
|
|
94
|
+
return artifacts ?? void 0;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The entry that a package subpath such as "./kv" selects: the subpath itself when an exact key or
|
|
98
|
+
* a pattern key such as "./drivers/*" exports it, matching the entries artifacts record.
|
|
99
|
+
*/
|
|
100
|
+
function winningExportKey(exports, subpath) {
|
|
101
|
+
if (Object.hasOwn(exports, subpath)) return subpath;
|
|
102
|
+
return Object.keys(exports).filter((key) => {
|
|
103
|
+
const star = key.indexOf("*");
|
|
104
|
+
return star >= 0 && star === key.lastIndexOf("*") && subpath.length >= key.length && subpath.startsWith(key.slice(0, star)) && subpath.endsWith(key.slice(star + 1));
|
|
105
|
+
}).sort((a, b) => b.indexOf("*") - a.indexOf("*") || b.length - a.length)[0];
|
|
106
|
+
}
|
|
107
|
+
function matchExportKey(manifest, subpath) {
|
|
108
|
+
const exports = manifest.exports;
|
|
109
|
+
if (!isRecord(exports) || !Object.keys(exports).some((key) => key.startsWith("."))) return;
|
|
110
|
+
if (subpath.includes("*")) return;
|
|
111
|
+
const key = winningExportKey(exports, subpath);
|
|
112
|
+
return key && exports[key] !== null ? subpath : void 0;
|
|
113
|
+
}
|
|
61
114
|
function readPackageArtifacts(root, fs = new RuleInputs(root).frame().fs) {
|
|
62
115
|
const active = readPackageArtifactsForMode(fs, root, true);
|
|
63
116
|
if (!active) return null;
|
|
64
117
|
const inactive = readPackageArtifactsForMode(fs, root, false);
|
|
65
|
-
const
|
|
66
|
-
const
|
|
118
|
+
const requiredKeys = (artifacts) => new Set(artifacts.references.flatMap((reference) => reference.reaches.filter((reach) => reach.required).map((reach) => `${reach.entry}\0${reference.packageName}`)));
|
|
119
|
+
const requiredInActive = requiredKeys(active);
|
|
120
|
+
const requiredInBoth = new Set([...requiredKeys(inactive)].filter((key) => requiredInActive.has(key)));
|
|
67
121
|
const references = /* @__PURE__ */ new Map();
|
|
68
122
|
for (const reference of [...active.references, ...inactive.references]) {
|
|
69
123
|
const key = `${reference.file}:${reference.range.start}:${reference.specifier}:${reference.kind}`;
|
|
70
124
|
const previous = references.get(key);
|
|
125
|
+
const reaches = reference.reaches.map((reach) => ({
|
|
126
|
+
...reach,
|
|
127
|
+
required: reach.required && requiredInBoth.has(`${reach.entry}\0${reference.packageName}`)
|
|
128
|
+
}));
|
|
71
129
|
references.set(key, {
|
|
72
130
|
...reference,
|
|
73
|
-
required: (reference.required || previous?.required === true) && requiredInBoth.has(reference.packageName)
|
|
131
|
+
required: (reference.required || previous?.required === true) && requiredInBoth.has(`.\0${reference.packageName}`),
|
|
132
|
+
reaches: mergeReaches(previous?.reaches ?? [], reaches)
|
|
74
133
|
});
|
|
75
134
|
}
|
|
76
135
|
return {
|
|
@@ -91,6 +150,8 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
91
150
|
const missing = /* @__PURE__ */ new Set();
|
|
92
151
|
const visited = /* @__PURE__ */ new Set();
|
|
93
152
|
const queue = [];
|
|
153
|
+
const parsedFiles = /* @__PURE__ */ new Map();
|
|
154
|
+
const edgesByFile = /* @__PURE__ */ new Map();
|
|
94
155
|
const rootPath = fs.realpath(root) ?? root;
|
|
95
156
|
function inside(path) {
|
|
96
157
|
const rel = relative(rootPath, path);
|
|
@@ -152,13 +213,28 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
152
213
|
}
|
|
153
214
|
return findFile(suffixes.slice(1).map((suffix) => resolve(path, "index" + suffix)));
|
|
154
215
|
}
|
|
155
|
-
function enqueue(target, kind, required, from = root, probe = true, adjacentDeclaration = false, sourceResolution = false, declarationBacked = false) {
|
|
216
|
+
function enqueue(target, kind, required, from = root, probe = true, adjacentDeclaration = false, sourceResolution = false, declarationBacked = false, origin = {}) {
|
|
156
217
|
const path = resolve(from, target);
|
|
157
218
|
if (!inside(path)) return;
|
|
158
219
|
if (target.includes("*")) {
|
|
159
220
|
const matches = fs.glob(path.replace("*", "**/*")).filter((match) => fs.stat(match)?.isFile() === true);
|
|
160
221
|
if (!matches.length) missing.add(relative(root, path));
|
|
161
|
-
|
|
222
|
+
const star = path.indexOf("*");
|
|
223
|
+
for (const match of matches) {
|
|
224
|
+
let matchOrigin = origin;
|
|
225
|
+
if (origin.entry?.includes("*")) {
|
|
226
|
+
const suffix = path.slice(star + 1);
|
|
227
|
+
if (!match.startsWith(path.slice(0, star)) || !match.endsWith(suffix)) continue;
|
|
228
|
+
const entry = origin.entry.replace("*", match.slice(star, match.length - suffix.length));
|
|
229
|
+
if (isRecord(manifest.exports) && winningExportKey(manifest.exports, entry) !== origin.entry) continue;
|
|
230
|
+
matchOrigin = {
|
|
231
|
+
...origin,
|
|
232
|
+
entry,
|
|
233
|
+
branch: `${origin.branch}\0${entry}`
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
enqueue(match, kind, required, from, false, adjacentDeclaration, sourceResolution, declarationBacked, matchOrigin);
|
|
237
|
+
}
|
|
162
238
|
return;
|
|
163
239
|
}
|
|
164
240
|
const file = (probe ? kind === "types" ? typeCandidates(path) : probe === "main" || probe === "commonjs" && !sourceResolution ? [commonjsFile(path), ...probe === "main" && manifest.exports == null ? [
|
|
@@ -192,7 +268,11 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
192
268
|
path: file,
|
|
193
269
|
kind: resolvedKind,
|
|
194
270
|
required: required && resolvedKind === "runtime",
|
|
195
|
-
declarationBacked: resolvedKind === "runtime" && (declarationBacked || Boolean(adjacentDeclaration && declaration))
|
|
271
|
+
declarationBacked: resolvedKind === "runtime" && (declarationBacked || Boolean(adjacentDeclaration && declaration)),
|
|
272
|
+
...resolvedKind === "runtime" ? {
|
|
273
|
+
...origin,
|
|
274
|
+
branch: origin.branch ?? `${origin.entry}\0${file}`
|
|
275
|
+
} : {}
|
|
196
276
|
});
|
|
197
277
|
if (resolvedKind === "runtime" && adjacentDeclaration && declaration) queue.push({
|
|
198
278
|
path: declaration,
|
|
@@ -233,10 +313,14 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
233
313
|
}
|
|
234
314
|
}
|
|
235
315
|
let typedTargets = false;
|
|
236
|
-
function addTargets(value,
|
|
316
|
+
function addTargets(value, entry, mode) {
|
|
237
317
|
typedTargets = false;
|
|
238
318
|
const selected = targets(value, "runtime", mode, addons);
|
|
239
|
-
if (Array.isArray(selected)) for (const target of selected) enqueue(target, "runtime",
|
|
319
|
+
if (Array.isArray(selected)) for (const target of selected) enqueue(target, "runtime", true, root, false, true, false, typedTargets, {
|
|
320
|
+
entry,
|
|
321
|
+
branch: `${entry}\0${target}\0${mode}`,
|
|
322
|
+
mode
|
|
323
|
+
});
|
|
240
324
|
}
|
|
241
325
|
const typed = (path) => {
|
|
242
326
|
const resolved = resolve(root, path);
|
|
@@ -246,19 +330,19 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
246
330
|
if (manifest.exports != null) {
|
|
247
331
|
const exports = manifest.exports;
|
|
248
332
|
if (exports && typeof exports === "object" && !Array.isArray(exports) && Object.keys(exports).some((key) => key.startsWith("."))) for (const [subpath, value] of Object.entries(exports)) {
|
|
249
|
-
addTargets(value, subpath
|
|
250
|
-
addTargets(value, subpath
|
|
333
|
+
addTargets(value, subpath, "import");
|
|
334
|
+
addTargets(value, subpath, "require");
|
|
251
335
|
}
|
|
252
336
|
else {
|
|
253
|
-
addTargets(exports,
|
|
254
|
-
addTargets(exports,
|
|
337
|
+
addTargets(exports, ".", "import");
|
|
338
|
+
addTargets(exports, ".", "require");
|
|
255
339
|
}
|
|
256
340
|
} else if (!manifest.main && !manifest.module) {
|
|
257
|
-
if (fs.exists(resolve(root, "index.js"))) enqueue("index.js", "runtime", true, root, true, true, false, rootTyped);
|
|
341
|
+
if (fs.exists(resolve(root, "index.js"))) enqueue("index.js", "runtime", true, root, true, true, false, rootTyped, { entry: "." });
|
|
258
342
|
}
|
|
259
|
-
if (manifest.main) enqueue(manifest.main, "runtime", true, root, "main", true, false, rootTyped);
|
|
260
|
-
if (manifest.module) enqueue(manifest.module, "runtime", true, root, true, true, false, rootTyped);
|
|
261
|
-
if (typeof manifest.browser === "string") enqueue(manifest.browser, "runtime", true, root, false, true, false, rootTyped);
|
|
343
|
+
if (manifest.main) enqueue(manifest.main, "runtime", true, root, "main", true, false, rootTyped, { entry: "." });
|
|
344
|
+
if (manifest.module) enqueue(manifest.module, "runtime", true, root, true, true, false, rootTyped, { entry: "." });
|
|
345
|
+
if (typeof manifest.browser === "string") enqueue(manifest.browser, "runtime", true, root, false, true, false, rootTyped, { entry: "." });
|
|
262
346
|
else if (manifest.browser) {
|
|
263
347
|
for (const [original, entry] of Object.entries(manifest.browser)) if (entry && entry.startsWith(".")) enqueue(entry, "runtime", false, root, false, true, false, rootTyped || typed(original));
|
|
264
348
|
}
|
|
@@ -269,13 +353,18 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
269
353
|
for (const version of Object.values(manifest.typesVersions ?? {})) for (const entries of Object.values(version)) for (const entry of entries) enqueue(entry, "types", false, root, false);
|
|
270
354
|
for (let i = 0; i < queue.length; i++) {
|
|
271
355
|
const current = queue[i];
|
|
272
|
-
const key = `${current.path}:${current.kind}:${current.required}:${current.declarationBacked ?? false}`;
|
|
356
|
+
const key = `${current.path}:${current.kind}:${current.required}:${current.declarationBacked ?? false}:${current.entry ?? ""}:${current.branch ?? ""}`;
|
|
273
357
|
if (visited.has(key)) continue;
|
|
274
358
|
visited.add(key);
|
|
275
359
|
if (current.required && manifest.browser && typeof manifest.browser === "object") for (const [original, replacement] of Object.entries(manifest.browser)) {
|
|
276
360
|
if (!replacement || resolve(root, original) !== current.path) continue;
|
|
277
361
|
if (replacement.startsWith(".")) {
|
|
278
|
-
enqueue(replacement, "runtime", true, root, false, true, false, current.declarationBacked
|
|
362
|
+
enqueue(replacement, "runtime", true, root, false, true, false, current.declarationBacked, {
|
|
363
|
+
entry: current.entry,
|
|
364
|
+
branch: current.branch,
|
|
365
|
+
mode: current.mode,
|
|
366
|
+
via: current.via
|
|
367
|
+
});
|
|
279
368
|
continue;
|
|
280
369
|
}
|
|
281
370
|
const packageName = externalPackageName(replacement);
|
|
@@ -284,31 +373,62 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
284
373
|
const offset = manifestText.indexOf(JSON.stringify(replacement), keyOffset);
|
|
285
374
|
const start = offset < 0 ? 0 : offset;
|
|
286
375
|
const before = manifestText.slice(0, start);
|
|
376
|
+
const line = before.split("\n").length;
|
|
287
377
|
references.push({
|
|
288
378
|
specifier: replacement,
|
|
289
379
|
packageName,
|
|
290
380
|
typeReference: false,
|
|
291
381
|
kind: "runtime",
|
|
292
|
-
required:
|
|
382
|
+
required: current.entry === ".",
|
|
383
|
+
reaches: current.entry ? [{
|
|
384
|
+
entry: current.entry,
|
|
385
|
+
branch: current.branch,
|
|
386
|
+
mode: current.mode,
|
|
387
|
+
executionRequired: true,
|
|
388
|
+
required: true,
|
|
389
|
+
via: {
|
|
390
|
+
file: manifestPath,
|
|
391
|
+
line,
|
|
392
|
+
specifier: replacement,
|
|
393
|
+
previous: current.via
|
|
394
|
+
}
|
|
395
|
+
}] : [],
|
|
293
396
|
file: manifestPath,
|
|
294
397
|
range: {
|
|
295
398
|
start,
|
|
296
399
|
end: start + JSON.stringify(replacement).length,
|
|
297
|
-
line
|
|
400
|
+
line,
|
|
298
401
|
column: start - before.lastIndexOf("\n")
|
|
299
402
|
}
|
|
300
403
|
});
|
|
301
404
|
}
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
const commonjs = commonjsModule(current.path) && (explicitCommonjsModule(current.path) || !hasRuntimeModuleSyntax(parsed.program));
|
|
405
|
+
const parsed = parsedFiles.get(current.path) ?? parseModule(current.path, fs.readText(current.path) ?? "");
|
|
406
|
+
parsedFiles.set(current.path, parsed);
|
|
305
407
|
const scope = packageScope(current.path);
|
|
306
|
-
|
|
408
|
+
const edgesKey = `${current.path}:${current.kind}:${current.declarationBacked ?? false}`;
|
|
409
|
+
let edges = edgesByFile.get(edgesKey);
|
|
410
|
+
if (!edges) {
|
|
411
|
+
const commonjs = commonjsModule(current.path) && (explicitCommonjsModule(current.path) || !hasRuntimeModuleSyntax(parsed.program));
|
|
412
|
+
edges = importEdges(parsed, current.kind, commonjs, explicitCommonjsModule(current.path), !current.declarationBacked && !/\.(?:[cm]?ts|tsx)$/.test(current.path));
|
|
413
|
+
edgesByFile.set(edgesKey, edges);
|
|
414
|
+
}
|
|
415
|
+
for (const edge of edges) {
|
|
307
416
|
const required = current.required && edge.required;
|
|
308
417
|
const executionRequired = required && !edge.resolutionOnly;
|
|
418
|
+
const hop = (specifier) => current.entry ? {
|
|
419
|
+
entry: current.entry,
|
|
420
|
+
branch: current.branch,
|
|
421
|
+
mode: current.mode,
|
|
422
|
+
via: {
|
|
423
|
+
file: current.path,
|
|
424
|
+
line: positionOf(parsed, edge.start).line + 1,
|
|
425
|
+
specifier,
|
|
426
|
+
previous: current.via
|
|
427
|
+
}
|
|
428
|
+
} : {};
|
|
309
429
|
for (const { specifier, kind, required: selectedRequired } of resolvePackageImport(edge.specifier, scope.manifest.imports, edge.kind, edge.probe === "commonjs" ? "require" : "import", /* @__PURE__ */ new Set(), void 0, scope.directory, addons)) {
|
|
310
430
|
if (specifier.startsWith(".")) {
|
|
311
|
-
enqueue(specifier, kind, executionRequired && selectedRequired && kind === "runtime", edge.specifier.startsWith("#") ? scope.directory : dirname(current.path), edge.specifier.startsWith("#") ? false : edge.probe || kind === "types" || /\.(?:[cm]?ts|tsx|jsx)$/.test(current.path), false, /\.(?:[cm]?ts|tsx)$/.test(current.path), current.declarationBacked);
|
|
431
|
+
enqueue(specifier, kind, executionRequired && selectedRequired && kind === "runtime", edge.specifier.startsWith("#") ? scope.directory : dirname(current.path), edge.specifier.startsWith("#") ? false : edge.probe || kind === "types" || /\.(?:[cm]?ts|tsx|jsx)$/.test(current.path), false, /\.(?:[cm]?ts|tsx)$/.test(current.path), current.declarationBacked, hop(edge.specifier));
|
|
312
432
|
continue;
|
|
313
433
|
}
|
|
314
434
|
const packageName = edge.typeReference ? specifier : externalPackageName(specifier);
|
|
@@ -317,16 +437,28 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
317
437
|
const exports = scope.manifest.exports;
|
|
318
438
|
const entries = exports && typeof exports === "object" && !Array.isArray(exports) && Object.keys(exports).some((key) => key.startsWith(".")) ? exports : { ".": exports ?? scope.manifest.main };
|
|
319
439
|
const aliases = Object.fromEntries(Object.entries(entries).map(([key, value]) => [`#self${key.slice(1)}`, value]));
|
|
320
|
-
for (const target of resolvePackageImport(`#self${specifier.slice(packageName.length)}`, aliases, kind, edge.probe === "commonjs" ? "require" : "import", /* @__PURE__ */ new Set(), scope.directory, void 0, addons)) if (target.specifier.startsWith(".")) enqueue(target.specifier, target.kind, executionRequired && selectedRequired && target.required && target.kind === "runtime", scope.directory, exports === void 0 ? "main" : false, true, false, current.declarationBacked);
|
|
440
|
+
for (const target of resolvePackageImport(`#self${specifier.slice(packageName.length)}`, aliases, kind, edge.probe === "commonjs" ? "require" : "import", /* @__PURE__ */ new Set(), scope.directory, void 0, addons)) if (target.specifier.startsWith(".")) enqueue(target.specifier, target.kind, executionRequired && selectedRequired && target.required && target.kind === "runtime", scope.directory, exports === void 0 ? "main" : false, true, false, current.declarationBacked, hop(edge.specifier));
|
|
321
441
|
continue;
|
|
322
442
|
}
|
|
323
443
|
const position = positionOf(parsed, edge.start);
|
|
444
|
+
const referenceRequired = required && selectedRequired && kind === "runtime";
|
|
445
|
+
const reach = hop(edge.specifier);
|
|
324
446
|
references.push({
|
|
325
447
|
specifier,
|
|
448
|
+
loadMode: edge.probe === "commonjs" ? "require" : "import",
|
|
326
449
|
packageName,
|
|
327
450
|
typeReference: edge.typeReference ?? false,
|
|
328
451
|
kind,
|
|
329
|
-
required:
|
|
452
|
+
required: referenceRequired && current.entry === ".",
|
|
453
|
+
...edge.dynamic ? { dynamic: edge.dynamic } : {},
|
|
454
|
+
reaches: kind === "runtime" && reach.entry && reach.via ? [{
|
|
455
|
+
entry: reach.entry,
|
|
456
|
+
branch: reach.branch,
|
|
457
|
+
mode: reach.mode,
|
|
458
|
+
executionRequired: executionRequired && selectedRequired && kind === "runtime",
|
|
459
|
+
required: referenceRequired,
|
|
460
|
+
via: reach.via
|
|
461
|
+
}] : [],
|
|
330
462
|
file: current.path,
|
|
331
463
|
range: {
|
|
332
464
|
start: edge.start,
|
|
@@ -344,7 +476,8 @@ function readPackageArtifactsForMode(fs, root, addons) {
|
|
|
344
476
|
const previous = unique.get(key);
|
|
345
477
|
unique.set(key, {
|
|
346
478
|
...reference,
|
|
347
|
-
required: reference.required || Boolean(previous?.required)
|
|
479
|
+
required: reference.required || Boolean(previous?.required),
|
|
480
|
+
reaches: mergeReaches(previous?.reaches ?? [], reference.reaches)
|
|
348
481
|
});
|
|
349
482
|
}
|
|
350
483
|
return {
|
|
@@ -653,6 +786,29 @@ function hasRuntimeModuleSyntax(program) {
|
|
|
653
786
|
}
|
|
654
787
|
});
|
|
655
788
|
}
|
|
789
|
+
function handlesAbsence(node) {
|
|
790
|
+
let target = node;
|
|
791
|
+
while (true) {
|
|
792
|
+
while (target.parent?.type === "ParenthesizedExpression") target = target.parent;
|
|
793
|
+
const member = target.parent;
|
|
794
|
+
const name = accessName(member);
|
|
795
|
+
let callee = member;
|
|
796
|
+
while (callee?.parent?.type === "ParenthesizedExpression") callee = callee.parent;
|
|
797
|
+
const call = callee?.parent;
|
|
798
|
+
if (member?.object !== target || call?.type !== "CallExpression" || call.callee !== callee) break;
|
|
799
|
+
if (name === "catch" || name === "then" && call.arguments.length > 1) return true;
|
|
800
|
+
if (name !== "then") break;
|
|
801
|
+
target = call;
|
|
802
|
+
}
|
|
803
|
+
let awaited = node;
|
|
804
|
+
while (awaited.parent?.type === "ParenthesizedExpression") awaited = awaited.parent;
|
|
805
|
+
if (awaited.parent?.type !== "AwaitExpression") return false;
|
|
806
|
+
for (let child = awaited, parent = awaited.parent; parent; child = parent, parent = parent.parent) {
|
|
807
|
+
if (isFunctionLike(parent) || parent.type === "StaticBlock") return false;
|
|
808
|
+
if (parent.type === "TryStatement" && parent.block === child) return true;
|
|
809
|
+
}
|
|
810
|
+
return false;
|
|
811
|
+
}
|
|
656
812
|
function hasAncestor(node, predicate) {
|
|
657
813
|
for (let current = node; current; current = current.parent) if (predicate(current)) return true;
|
|
658
814
|
return false;
|
|
@@ -683,8 +839,10 @@ function importEdges(parsed, kind, commonjs, explicitCommonjs, jsdocTypes) {
|
|
|
683
839
|
if (typeOnly || supportsStaticImports) add(node.source, typeOnly, true);
|
|
684
840
|
} else if (node.type === "TSImportEqualsDeclaration" && node.moduleReference.type === "TSExternalModuleReference") add(node.moduleReference.expression, node.importKind === "type", true, "commonjs");
|
|
685
841
|
else if (node.type === "TSImportType") add(node.source, true, false);
|
|
686
|
-
else if (node.type === "ImportExpression")
|
|
687
|
-
|
|
842
|
+
else if (node.type === "ImportExpression") {
|
|
843
|
+
add(node.source, false, isUnconditional(node, true));
|
|
844
|
+
if (edges.at(-1)?.start === unwrapParens(node.source).start) edges.at(-1).dynamic = { handlesAbsence: handlesAbsence(node) };
|
|
845
|
+
} else if (node.type === "CallExpression") {
|
|
688
846
|
const member = node.callee;
|
|
689
847
|
const memberName = accessName(member) ?? (member.type === "MemberExpression" && member.property.type === "Literal" && typeof member.property.value === "string" ? member.property.value : void 0);
|
|
690
848
|
const receiver = member.type === "MemberExpression" ? member.object : void 0;
|
|
@@ -1205,5 +1363,25 @@ function shadowsName(node, identifier) {
|
|
|
1205
1363
|
}
|
|
1206
1364
|
return false;
|
|
1207
1365
|
}
|
|
1208
|
-
|
|
1209
|
-
|
|
1366
|
+
/** An optional peer that the package does not also install as a dependency. */
|
|
1367
|
+
function optionalPeer(manifest, name) {
|
|
1368
|
+
return Boolean(manifest.peerDependencies?.[name] && manifest.peerDependenciesMeta?.[name]?.optional === true && !manifest.dependencies?.[name]);
|
|
1369
|
+
}
|
|
1370
|
+
/**
|
|
1371
|
+
* Labels files in this package relative to the project root, and files in an installed package
|
|
1372
|
+
* as `<name>/<path>`, so an import chain reads the same in every package manager layout.
|
|
1373
|
+
*/
|
|
1374
|
+
function chainLabeler(ctx, artifacts) {
|
|
1375
|
+
const projectRoot = ctx.fs.realpath(ctx.project.root) ?? ctx.project.root;
|
|
1376
|
+
const own = relative(projectRoot, artifacts.root);
|
|
1377
|
+
const installed = own.startsWith("..") || own.split("/").includes("node_modules");
|
|
1378
|
+
return (file) => installed ? `${artifacts.manifest.name ?? basename$1(artifacts.root)}/${relative(artifacts.root, file)}` : relative(projectRoot, file);
|
|
1379
|
+
}
|
|
1380
|
+
function describeChain(hop, label) {
|
|
1381
|
+
return importChain(hop).map((item) => `${label(item.file)}:${item.line} "${item.specifier}"`).join(" → ");
|
|
1382
|
+
}
|
|
1383
|
+
/** Installing a package with this manifest also installs `name`, or makes its absence a peer warning. */
|
|
1384
|
+
function installedWith(manifest, name) {
|
|
1385
|
+
return Boolean(manifest.dependencies?.[name] || manifest.optionalDependencies?.[name] || manifest.peerDependencies?.[name] && !optionalPeer(manifest, name));
|
|
1386
|
+
}
|
|
1387
|
+
export { installedPackageArtifacts as a, matchExportKey as c, parsePackageManifest as d, readPackageArtifacts as f, importChain as i, optionalPeer as l, defaultEntry as n, installedWith as o, describeChain as r, isRecord as s, chainLabeler as t, packageArtifacts as u };
|
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {}
|
package/dist/bin.mjs
ADDED
|
@@ -2,10 +2,10 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { closeSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
3
3
|
import { resolve } from "pathe";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
-
import { Diagnostic } from "nostics";
|
|
6
5
|
import { dirname as dirname$1, isAbsolute as isAbsolute$1, matchesGlob, relative as relative$1, sep } from "node:path";
|
|
6
|
+
import { Diagnostic } from "nostics";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
|
|
8
|
+
// src/core/internal/utils.ts
|
|
9
9
|
const VERSION = "0.0.0";
|
|
10
10
|
const DEFAULT_WEIGHTS = {
|
|
11
11
|
blocker: 15,
|
|
@@ -33,8 +33,7 @@ function nodeOffsets(node) {
|
|
|
33
33
|
function shellArgument(value) {
|
|
34
34
|
return /^[a-zA-Z0-9_./:@,+-]+$/.test(value) ? value : `'${value.replaceAll("'", "'\\''")}'`;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
//#region src/core/internal/cache-store.ts
|
|
36
|
+
// src/core/internal/cache-store.ts
|
|
38
37
|
const CACHE_STORE_FILE = "store.json";
|
|
39
38
|
const CACHE_STORE_VERSION = 2;
|
|
40
39
|
const COARSE_RACY_SIGNATURE_MS = 2e3;
|
|
@@ -896,5 +895,4 @@ function assertCachePath(root, path) {
|
|
|
896
895
|
current = parent;
|
|
897
896
|
}
|
|
898
897
|
}
|
|
899
|
-
//#endregion
|
|
900
898
|
export { retainCacheStores as a, nativeMatch as c, shellArgument as d, readCacheStatus as i, nodeOffsets as l, cleanCacheDirectory as n, DEFAULT_WEIGHTS as o, flushStoreWrites as r, VERSION as s, DoctorCache as t, sha256 as u };
|