wyvrnpm 2.14.1 → 2.15.0
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 +1 -1
- package/bin/wyvrnpm.js +1 -1
- package/claude/skills/wyvrnpm.skill +0 -0
- package/package.json +1 -1
- package/src/build/index.js +51 -4
- package/src/commands/install.js +90 -15
- package/src/commands/show.js +26 -0
- package/src/manifest.js +142 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A simple, private C++ package manager that works with any static file hosting pr
|
|
|
4
4
|
|
|
5
5
|
There is no central registry. You control where packages are hosted.
|
|
6
6
|
|
|
7
|
-
> **README version: 2.
|
|
7
|
+
> **README version: 2.15.0** — **New:** `buildDependencies` block + `whenOption` gating — closes EVALUATION.md **F3** (`tool_requires` + `test_requires`). Recipes can now declare author-private deps (the asio / websocketpp / boost-internals case — header-only libs that compile into a `StaticLib` and aren't exposed by its public API; the protoc / flex / bison case — executables the build invokes at configure time) in a sibling block to `dependencies`. Buildable at the author's root and at source-build of a transitive, but **never walked transitively when a downstream consumer pulls the prebuilt binary** — they just get the lean runtime closure. `whenOption: "websocket"` (or `"api=legacy"`) gates a dep on a recipe-declared option value, evaluated at the seam where the package's effective options are known (root install + source-build). The combination also subsumes Conan's `test_requires`: declare `options.tests` and list gtest in `buildDependencies` with `whenOption: "tests"` — default `tests=false` skips it, `-o MyPkg:tests=true` opts in for that build, consumers of the prebuilt binary never see it either way. Mirrors Conan 2.0's `requires` / `tool_requires` split. Backward compat is automatic — old wyvrnpm clients ignore the unknown top-level field. `wyvrnpm show` surfaces both blocks per-profile so a publisher can verify what shipped. (Cross-compilation case — tool requires resolved under a *build* profile distinct from the *host* profile — stays open as F4, deferred pending a concrete cross-compilation user.) **New:** npm self-update notifier — when a newer `wyvrnpm` is on the npm registry, the next interactive run prints a one-line `[wyvrn] warn wyvrnpm <old> → <new> available` banner on stderr. The fetch happens in a detached background process so the user's command never blocks on the network; the banner appears on the *following* invocation after the cache (`%LOCALAPPDATA%\wyvrnpm\update-check.json`) is populated. Auto-suppressed in CI (`$CI`), non-TTY runs, and `--format json` mode; opt out via `WYVRNPM_NO_UPDATE_CHECK=1` or `--no-update-check`. Hand-rolled (~120 lines, zero new deps) instead of pulling in `update-notifier` and its 10+ transitives. Closes the gap where users on stale CLIs silently missed bug fixes (the `2.8.4` CloudFront cache-split fix and the `2.12.2` install-failure exit code, in particular). **Resolver caches `@latest` lookups** within a single `wyvrnpm install` — when a package is referenced as `@latest` from multiple parents in the dep graph (or already resolved earlier via a range), the registry round-trip is reused instead of re-probing `latest.json` per encounter. Eliminates ~12 redundant HTTPS round-trips on a typical 16-dep graph; visible win on resolution wall-time when the registry sits behind CloudFront. Closes the parallel gap to `manifestCache` / `publishedCache` — all three S3-backed helpers in `resolve.js` now memoise per-name within one install. **Per-config artefact slicing.** Recipes opt in via `build.publishPerConfig: true`; `wyvrnpm publish` then emits one `wyvrn-<Config>.zip` per declared CMake config under one `profileHash` URL instead of a single fat zip. Consumers fetch only the configs they need: `wyvrnpm install --request-configs Release` on a CI runner pulls 1.93 GB of gRPC instead of 14.96 GB across all four configs (~87% saving). Driven by CMake's own `*Targets-<config>.cmake` exports (`IMPORTED_LOCATION_<CONFIG>`) so both the MSVC convention (`lib/<Config>/foo.lib`) and the postfix convention (`lib/foo.lib` Release vs `lib/food.lib` Debug, via `CMAKE_DEBUG_POSTFIX`) classify correctly. `wyvrn.local.json` gains `requestConfigs` (global) + `depRequestConfigs` (per-dep override — "all four configs of fmt, but MinSizeRel of grpc"). Attestation v2 binds an `artefactSha256: { config → sha }` map; one signature covers every slice. `wyvrnpm publish --dry-run` materialises the would-be-uploaded artefacts to `<build>/dry-run-publish/` for inspection (override with `--dry-run-out`), and tolerates expired AWS credentials (the existence check degrades to `wouldOverwrite: null` instead of crashing). Highlights since 2.8.3: S1 artefact signing — Ed25519 detached signatures over a canonical attestation, verified against a per-registry `.trust/keys.json`; `wyvrnpm key gen / show-pub`, `wyvrnpm trust list / refresh`, `wyvrnpm configure signing set-default / show / unset`; `--require-signatures` on install, `--no-sign` / `--signing-key-env` / `--signing-key-file` on publish; pure-Node `crypto` (no external tooling, identical on Windows / Linux / macOS). Closes S1 + S3. Profile's `compiler.cppstd` is now authoritative for the toolchain — `CMAKE_CXX_STANDARD` is set unconditionally before `project()` and `cpp.cmake` no longer touches it post-`project()`, so a `-DCMAKE_CXX_STANDARD=23` on the cmake CLI cannot defeat a `cppstd=20` profile; `wyvrnpm install` exits non-zero on partial failure (sha256-mismatch, extract-failed, no-exact-match, source-build-failed, not-found) and prints a per-dep failure summary instead of misreporting "Done — N installed"; streaming publish via `archiver` (handles >2 GiB artefacts that `adm-zip` choked on — e.g. gRPC's `RelWithDebInfo` static libs); `--build-dir <path>` + `wyvrn.local.json:binaryDirRoot` to sidestep `build/` case-insensitive-FS collisions on repos with a Bazel/Buck `BUILD` file at the root (gRPC, …); `wyvrnpm version` to read / set / partially update the top-level `version` field from CI pipelines (`wyvrnpm version --build "$BUILD_ID"`); `wyvrnpm bootstrap <git-url>` to scaffold a first-draft `wyvrn.json` for OSS C++ libraries (fmt, spdlog, zlib, …) with cookbook-driven defaults; `wyvrnpm publish --dry-run` (npm-style preview of the upload plan, plus `wouldOverwrite` flag in `--format json`); `wyvrnpm build --config Debug,Release` / `--all-configs` to build multiple configurations from a single configure; resolver hardened against the CloudFront brotli-vs-identity cache split (resolved a class of bugs where `show` listed a freshly-published version that `install` claimed didn't exist). Full list in `claude/EVALUATION.md`.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
package/bin/wyvrnpm.js
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/build/index.js
CHANGED
|
@@ -9,7 +9,12 @@ const { normalizeRecipe, hasBuildRecipe } = require('./recipe');
|
|
|
9
9
|
const { configureBuildInstall } = require('./cmake');
|
|
10
10
|
const { getBuildPaths, hasValidArtefact } = require('./cache');
|
|
11
11
|
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
normalizeDependencies,
|
|
14
|
+
normalizeManifestDeps,
|
|
15
|
+
validateWhenOption,
|
|
16
|
+
evaluateWhenOption,
|
|
17
|
+
} = require('../manifest');
|
|
13
18
|
const { resolveDependencies } = require('../resolve');
|
|
14
19
|
const { hashProfile, mergeProfile, sha256Of } = require('../profile');
|
|
15
20
|
const { generateToolchain } = require('../toolchain');
|
|
@@ -188,9 +193,51 @@ async function buildFromSource(args) {
|
|
|
188
193
|
// eslint-disable-next-line global-require
|
|
189
194
|
const { downloadDependencies } = require('../download');
|
|
190
195
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
);
|
|
196
|
+
// Read both runtime and author-private buildDependencies from the cloned
|
|
197
|
+
// source. The source-build sandbox needs both to compile (e.g. asio +
|
|
198
|
+
// websocketpp headers when building WyvrnIPC); the fetched buildDeps
|
|
199
|
+
// stay scoped to this sandbox's `wyvrn_internal/` and never propagate
|
|
200
|
+
// up to the outer install's lockfile or wyvrn_deps.cmake.
|
|
201
|
+
let depsByKind;
|
|
202
|
+
try {
|
|
203
|
+
depsByKind = normalizeManifestDeps(clonedManifest);
|
|
204
|
+
} catch (err) {
|
|
205
|
+
throw new Error(
|
|
206
|
+
`${name}@${version}: ${err.message} (in cloned wyvrn.json at ${gitSha.slice(0, 12)})`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
const { runtime: runtimeDeps, build: buildDeps } = depsByKind;
|
|
210
|
+
|
|
211
|
+
// Validate + filter whenOption against the source-build's effective
|
|
212
|
+
// options (passed in from the consumer's resolution as `args.options`).
|
|
213
|
+
const declarationForFilter = clonedManifest.options
|
|
214
|
+
? normalizeOptionsDeclaration(clonedManifest.options, `${name}@${version}`)
|
|
215
|
+
: null;
|
|
216
|
+
for (const [depName, d] of Object.entries(runtimeDeps)) {
|
|
217
|
+
if (d.whenOption) {
|
|
218
|
+
validateWhenOption(d.whenOption, declarationForFilter, `${name}.dependencies.${depName}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
for (const [depName, d] of Object.entries(buildDeps)) {
|
|
222
|
+
if (d.whenOption) {
|
|
223
|
+
validateWhenOption(d.whenOption, declarationForFilter, `${name}.buildDependencies.${depName}`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
const filterByWhenOption = (deps) => {
|
|
227
|
+
const out = {};
|
|
228
|
+
for (const [depName, d] of Object.entries(deps)) {
|
|
229
|
+
if (!d.whenOption || evaluateWhenOption(d.whenOption, options)) {
|
|
230
|
+
out[depName] = d;
|
|
231
|
+
} else {
|
|
232
|
+
log.info(` ${depName}: skipped (whenOption "${d.whenOption}" not satisfied)`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
};
|
|
237
|
+
const rawPackageDeps = {
|
|
238
|
+
...filterByWhenOption(runtimeDeps),
|
|
239
|
+
...filterByWhenOption(buildDeps),
|
|
240
|
+
};
|
|
194
241
|
const depsForResolution = Object.fromEntries(
|
|
195
242
|
Object.entries(rawPackageDeps).map(([n, d]) => [n, d.version]),
|
|
196
243
|
);
|
package/src/commands/install.js
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
const fs = require('fs');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
const {
|
|
6
|
+
const {
|
|
7
|
+
normalizeDependencies,
|
|
8
|
+
normalizeManifestDeps,
|
|
9
|
+
validateWhenOption,
|
|
10
|
+
evaluateWhenOption,
|
|
11
|
+
} = require('../manifest');
|
|
7
12
|
const { resolveDependencies } = require('../resolve');
|
|
8
13
|
const { downloadDependencies } = require('../download');
|
|
9
14
|
const { resolveSigningContext } = require('../signing/resolve-context');
|
|
@@ -134,8 +139,76 @@ async function install(argv) {
|
|
|
134
139
|
// and caches the result for the rest of this invocation.
|
|
135
140
|
const manifest = ctx.manifest;
|
|
136
141
|
|
|
137
|
-
//
|
|
138
|
-
|
|
142
|
+
// Pull both runtime `dependencies` and author-private `buildDependencies`.
|
|
143
|
+
// The latter feeds the root install (the author needs them to compile)
|
|
144
|
+
// and source-builds of this package as a transitive, but is never walked
|
|
145
|
+
// when a downstream consumer pulls the prebuilt binary — see resolve.js.
|
|
146
|
+
let depsByKind;
|
|
147
|
+
try {
|
|
148
|
+
depsByKind = normalizeManifestDeps(manifest);
|
|
149
|
+
} catch (err) {
|
|
150
|
+
log.error(err.message);
|
|
151
|
+
process.exit(1);
|
|
152
|
+
}
|
|
153
|
+
const { runtime: runtimeDeps, build: buildDeps } = depsByKind;
|
|
154
|
+
|
|
155
|
+
// Resolve the project's own effective options early. Needed for
|
|
156
|
+
// `whenOption` filtering of root deps, then reused below for the
|
|
157
|
+
// CMake preset's `${options.*}` substitution.
|
|
158
|
+
let projectDeclaration = null;
|
|
159
|
+
let projectEffectiveOptions = null;
|
|
160
|
+
try {
|
|
161
|
+
projectDeclaration = manifest.options
|
|
162
|
+
? normalizeOptionsDeclaration(manifest.options, manifest.name)
|
|
163
|
+
: null;
|
|
164
|
+
projectEffectiveOptions = resolveEffectiveOptions(
|
|
165
|
+
projectDeclaration, {}, cliOptionsByPkg[manifest.name] ?? {}, manifest.name,
|
|
166
|
+
);
|
|
167
|
+
} catch (err) {
|
|
168
|
+
log.error(err.message);
|
|
169
|
+
process.exit(1);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Validate every `whenOption` against the project's declared options
|
|
173
|
+
// before resolving anything — surface authoring errors fast.
|
|
174
|
+
try {
|
|
175
|
+
for (const [name, d] of Object.entries(runtimeDeps)) {
|
|
176
|
+
if (d.whenOption) {
|
|
177
|
+
validateWhenOption(d.whenOption, projectDeclaration, `${manifest.name}.dependencies.${name}`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
for (const [name, d] of Object.entries(buildDeps)) {
|
|
181
|
+
if (d.whenOption) {
|
|
182
|
+
validateWhenOption(d.whenOption, projectDeclaration, `${manifest.name}.buildDependencies.${name}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
} catch (err) {
|
|
186
|
+
log.error(err.message);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Filter both blocks by whenOption. A dep whose condition is false is
|
|
191
|
+
// omitted from the resolver's queue — the consumer never pays the
|
|
192
|
+
// download / find_package cost, and the entry stays out of wyvrn.lock.
|
|
193
|
+
const filterByWhenOption = (deps, label) => {
|
|
194
|
+
const out = {};
|
|
195
|
+
for (const [name, d] of Object.entries(deps)) {
|
|
196
|
+
if (!d.whenOption || evaluateWhenOption(d.whenOption, projectEffectiveOptions)) {
|
|
197
|
+
out[name] = d;
|
|
198
|
+
} else {
|
|
199
|
+
log.info(`${name}: ${label} skipped (whenOption "${d.whenOption}" not satisfied)`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
};
|
|
204
|
+
const activeRuntimeDeps = filterByWhenOption(runtimeDeps, 'runtime');
|
|
205
|
+
const activeBuildDeps = filterByWhenOption(buildDeps, 'buildDep');
|
|
206
|
+
|
|
207
|
+
// Combined view for resolver + downstream lookups. `buildDepNames`
|
|
208
|
+
// is the only side-channel — used to annotate lockfile entries with
|
|
209
|
+
// `kind: "build"` and to label log lines.
|
|
210
|
+
const normalizedDeps = { ...activeRuntimeDeps, ...activeBuildDeps };
|
|
211
|
+
const buildDepNames = new Set(Object.keys(activeBuildDeps));
|
|
139
212
|
|
|
140
213
|
// For resolution, only pass name → version (settings don't affect resolution)
|
|
141
214
|
const depsForResolution = Object.fromEntries(
|
|
@@ -484,7 +557,15 @@ async function install(argv) {
|
|
|
484
557
|
// ── Write v2 lock file ────────────────────────────────────────────────────
|
|
485
558
|
const sortedPackages = {};
|
|
486
559
|
for (const key of [...resolvedDeps.keys()].sort()) {
|
|
487
|
-
|
|
560
|
+
const entry = lockEntries?.get(key) ?? { version: resolvedDeps.get(key) };
|
|
561
|
+
// Annotate root-level buildDependencies so `wyvrnpm show` / audits
|
|
562
|
+
// can distinguish runtime deps from author-private build deps.
|
|
563
|
+
// Runtime deps stay un-annotated so pre-feature lockfiles round-trip
|
|
564
|
+
// byte-identically.
|
|
565
|
+
if (buildDepNames.has(key) && entry && typeof entry === 'object' && !entry.kind) {
|
|
566
|
+
entry.kind = 'build';
|
|
567
|
+
}
|
|
568
|
+
sortedPackages[key] = entry;
|
|
488
569
|
}
|
|
489
570
|
|
|
490
571
|
const lockData = {
|
|
@@ -533,17 +614,11 @@ async function install(argv) {
|
|
|
533
614
|
let presetConfigs = null;
|
|
534
615
|
if (hasBuildRecipe(manifest)) {
|
|
535
616
|
try {
|
|
536
|
-
//
|
|
537
|
-
//
|
|
538
|
-
//
|
|
539
|
-
//
|
|
540
|
-
|
|
541
|
-
? normalizeOptionsDeclaration(manifest.options, manifest.name)
|
|
542
|
-
: null;
|
|
543
|
-
const projectCliOverrides = cliOptionsByPkg[manifest.name] ?? {};
|
|
544
|
-
const projectEffectiveOptions = resolveEffectiveOptions(
|
|
545
|
-
projectDeclaration, {}, projectCliOverrides, manifest.name,
|
|
546
|
-
);
|
|
617
|
+
// `projectEffectiveOptions` was already resolved at the top of the
|
|
618
|
+
// function (needed for whenOption filtering). Reuse it here for
|
|
619
|
+
// `${options.*}` substitution in `build.configure` / `build.buildArgs`
|
|
620
|
+
// — normalizeRecipe enforces that template references must match a
|
|
621
|
+
// declared option.
|
|
547
622
|
const recipe = normalizeRecipe(manifest.build, projectEffectiveOptions, manifest);
|
|
548
623
|
|
|
549
624
|
if (recipe.generators.length > 0) {
|
package/src/commands/show.js
CHANGED
|
@@ -170,6 +170,17 @@ async function show(argv) {
|
|
|
170
170
|
if (meta?.options && Object.keys(meta.options).length > 0) {
|
|
171
171
|
console.log(` declared: ${formatDeclaredOptions(meta.options)}`);
|
|
172
172
|
}
|
|
173
|
+
// Author-private buildDependencies (F-buildDeps). Surface both
|
|
174
|
+
// blocks so a publisher can confirm what shipped — runtime
|
|
175
|
+
// deps propagate to consumers, buildDeps don't. `whenOption`
|
|
176
|
+
// entries are annotated inline so it's obvious which deps are
|
|
177
|
+
// gated on an option value.
|
|
178
|
+
if (meta?.dependencies && Object.keys(meta.dependencies).length > 0) {
|
|
179
|
+
console.log(` deps : ${formatDeps(meta.dependencies)}`);
|
|
180
|
+
}
|
|
181
|
+
if (meta?.buildDependencies && Object.keys(meta.buildDependencies).length > 0) {
|
|
182
|
+
console.log(` buildDeps: ${formatDeps(meta.buildDependencies)}`);
|
|
183
|
+
}
|
|
173
184
|
// PLAN-CONF.md §4.6 — surface publisher's publishedConf.
|
|
174
185
|
// Informational only; absent for pre-2.6.0 author publishes.
|
|
175
186
|
if (meta?.publishedConf && Object.keys(meta.publishedConf).length > 0) {
|
|
@@ -193,6 +204,8 @@ async function show(argv) {
|
|
|
193
204
|
uploadedBy: meta?.uploadedBy ?? null,
|
|
194
205
|
compatibility: meta?.compatibility ?? null,
|
|
195
206
|
declaredOptions: meta?.options ?? null,
|
|
207
|
+
dependencies: meta?.dependencies ?? null,
|
|
208
|
+
buildDependencies: meta?.buildDependencies ?? null,
|
|
196
209
|
publishedConf: meta?.publishedConf ?? null,
|
|
197
210
|
signing,
|
|
198
211
|
});
|
|
@@ -271,5 +284,18 @@ function formatDeclaredOptions(declared) {
|
|
|
271
284
|
.join('; ');
|
|
272
285
|
}
|
|
273
286
|
|
|
287
|
+
function formatDeps(deps) {
|
|
288
|
+
return Object.entries(deps)
|
|
289
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
290
|
+
.map(([name, value]) => {
|
|
291
|
+
const ver = typeof value === 'string' ? value : (value?.version ?? '?');
|
|
292
|
+
const when = (typeof value === 'object' && value?.whenOption)
|
|
293
|
+
? ` [when ${value.whenOption}]`
|
|
294
|
+
: '';
|
|
295
|
+
return `${name}@${ver}${when}`;
|
|
296
|
+
})
|
|
297
|
+
.join(', ');
|
|
298
|
+
}
|
|
299
|
+
|
|
274
300
|
module.exports = show;
|
|
275
301
|
module.exports.parseSpec = parseSpec;
|
package/src/manifest.js
CHANGED
|
@@ -54,21 +54,24 @@ function defaultManifest(name) {
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Normalise the raw `dependencies` field from a manifest into a consistent
|
|
57
|
-
* `{ name → { version, settings, options, source? } }` map,
|
|
58
|
-
* input format:
|
|
57
|
+
* `{ name → { version, settings, options, source?, whenOption? } }` map,
|
|
58
|
+
* regardless of input format:
|
|
59
59
|
*
|
|
60
|
-
* • String value : "1.0.0"
|
|
61
|
-
* • Object value : { version, settings?, options?, source? } → kept (missing keys default to {})
|
|
62
|
-
* • Array format : [{ Name, Version }]
|
|
60
|
+
* • String value : "1.0.0" → { version: "1.0.0", settings: {}, options: {} }
|
|
61
|
+
* • Object value : { version, settings?, options?, source?, whenOption? } → kept (missing keys default to {})
|
|
62
|
+
* • Array format : [{ Name, Version }] → converted (no settings/options)
|
|
63
63
|
*
|
|
64
64
|
* `settings` merges on top of the active profile for this dep only.
|
|
65
65
|
* `options` maps to the recipe's declared options; validated against
|
|
66
66
|
* the recipe's `allowed` list at resolve time (see src/options.js).
|
|
67
67
|
* `source` (EVALUATION.md S4) pins the dep to a named install source
|
|
68
68
|
* (e.g. `"primary-s3"`); absent = fan out across all configured sources.
|
|
69
|
+
* `whenOption` (`"name"` or `"name=value"`) gates the dep on a recipe-
|
|
70
|
+
* declared option — see `evaluateWhenOption`. Validated against the
|
|
71
|
+
* package's `options` block by `validateWhenOption` at install time.
|
|
69
72
|
*
|
|
70
73
|
* @param {object|Array|undefined} rawDeps
|
|
71
|
-
* @returns {Record<string, { version: string, settings: object, options: object, source?: string }>}
|
|
74
|
+
* @returns {Record<string, { version: string, settings: object, options: object, source?: string, whenOption?: string }>}
|
|
72
75
|
*/
|
|
73
76
|
function normalizeDependencies(rawDeps) {
|
|
74
77
|
if (!rawDeps || typeof rawDeps !== 'object') return {};
|
|
@@ -98,12 +101,141 @@ function normalizeDependencies(rawDeps) {
|
|
|
98
101
|
if (typeof value.source === 'string' && value.source.length > 0) {
|
|
99
102
|
entry.source = value.source;
|
|
100
103
|
}
|
|
104
|
+
// Option-gated dep (F-buildDeps). Preserved verbatim here; structural
|
|
105
|
+
// validation lives in `validateWhenOption` because that's where we
|
|
106
|
+
// also know the package's declared options.
|
|
107
|
+
if (typeof value.whenOption === 'string' && value.whenOption.length > 0) {
|
|
108
|
+
entry.whenOption = value.whenOption;
|
|
109
|
+
}
|
|
101
110
|
result[n] = entry;
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
return result;
|
|
105
114
|
}
|
|
106
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Pull both runtime `dependencies` and author-private `buildDependencies`
|
|
118
|
+
* out of a manifest, normalised through `normalizeDependencies`. A package
|
|
119
|
+
* name MUST NOT appear in both blocks — that's a hard authoring error
|
|
120
|
+
* (no sensible meaning for "both runtime and build-only").
|
|
121
|
+
*
|
|
122
|
+
* `buildDependencies` are deps the package needs to compile itself but
|
|
123
|
+
* that consumers of the prebuilt binary do not need transitively. The
|
|
124
|
+
* resolver walks them at the root (and at source-build of a transitive
|
|
125
|
+
* dep) but never when reading an upstream manifest's transitive graph
|
|
126
|
+
* — see [src/resolve.js](resolve.js). Backward compat with old wyvrnpm
|
|
127
|
+
* clients is automatic: they only read `dependencies`.
|
|
128
|
+
*
|
|
129
|
+
* @param {object} manifest - parsed wyvrn.json
|
|
130
|
+
* @returns {{
|
|
131
|
+
* runtime: Record<string, object>,
|
|
132
|
+
* build: Record<string, object>,
|
|
133
|
+
* }}
|
|
134
|
+
*/
|
|
135
|
+
function normalizeManifestDeps(manifest) {
|
|
136
|
+
const runtime = normalizeDependencies(
|
|
137
|
+
manifest?.dependencies ?? manifest?.Dependencies,
|
|
138
|
+
);
|
|
139
|
+
const build = normalizeDependencies(manifest?.buildDependencies);
|
|
140
|
+
for (const name of Object.keys(build)) {
|
|
141
|
+
if (name in runtime) {
|
|
142
|
+
throw new Error(
|
|
143
|
+
`"${name}" appears in both \`dependencies\` and \`buildDependencies\` — ` +
|
|
144
|
+
`pick one. Runtime deps propagate to consumers; buildDependencies do not.`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { runtime, build };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Parse a `whenOption` spec into `{ name, value }`. Bare `"foo"` is
|
|
153
|
+
* sugar for `"foo=true"`. Throws on malformed input. Pure structural
|
|
154
|
+
* parser — does not validate against a package's option declaration;
|
|
155
|
+
* use `validateWhenOption` for that.
|
|
156
|
+
*
|
|
157
|
+
* @param {string} spec
|
|
158
|
+
* @returns {{ name: string, value: string|boolean }}
|
|
159
|
+
*/
|
|
160
|
+
function parseWhenOption(spec) {
|
|
161
|
+
if (typeof spec !== 'string' || spec.length === 0) {
|
|
162
|
+
throw new Error('whenOption must be a non-empty string');
|
|
163
|
+
}
|
|
164
|
+
const eqIdx = spec.indexOf('=');
|
|
165
|
+
if (eqIdx === -1) {
|
|
166
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(spec)) {
|
|
167
|
+
throw new Error(
|
|
168
|
+
`whenOption "${spec}" is malformed — option name must match /^[a-z][a-z0-9_-]*$/`,
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return { name: spec, value: true };
|
|
172
|
+
}
|
|
173
|
+
const name = spec.slice(0, eqIdx);
|
|
174
|
+
const raw = spec.slice(eqIdx + 1);
|
|
175
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(name)) {
|
|
176
|
+
throw new Error(
|
|
177
|
+
`whenOption "${spec}" is malformed — option name must match /^[a-z][a-z0-9_-]*$/`,
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (raw.length === 0) {
|
|
181
|
+
throw new Error(`whenOption "${spec}" has empty value after "="`);
|
|
182
|
+
}
|
|
183
|
+
const lc = raw.toLowerCase();
|
|
184
|
+
if (lc === 'true') return { name, value: true };
|
|
185
|
+
if (lc === 'false') return { name, value: false };
|
|
186
|
+
return { name, value: raw };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Validate a dep's `whenOption` against the owning package's normalised
|
|
191
|
+
* options declaration. Throws on:
|
|
192
|
+
* - structural error in the spec,
|
|
193
|
+
* - referenced option name not in the declaration,
|
|
194
|
+
* - compared value not in the option's `allowed` list.
|
|
195
|
+
*
|
|
196
|
+
* @param {string} spec - the whenOption string
|
|
197
|
+
* @param {object|null} optionsDecl - normalised options (from src/options.js)
|
|
198
|
+
* @param {string} where - context for error messages ("WyvrnIPC.dependencies.websocketpp")
|
|
199
|
+
* @returns {{ name: string, value: any }}
|
|
200
|
+
*/
|
|
201
|
+
function validateWhenOption(spec, optionsDecl, where) {
|
|
202
|
+
const parsed = parseWhenOption(spec);
|
|
203
|
+
if (!optionsDecl || !(parsed.name in optionsDecl)) {
|
|
204
|
+
const declared = optionsDecl ? Object.keys(optionsDecl).join(', ') : '(none)';
|
|
205
|
+
throw new Error(
|
|
206
|
+
`whenOption on ${where} references option "${parsed.name}" which is not declared.\n` +
|
|
207
|
+
` declared options: ${declared}`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const allowed = optionsDecl[parsed.name].allowed;
|
|
211
|
+
if (!allowed.includes(parsed.value)) {
|
|
212
|
+
throw new Error(
|
|
213
|
+
`whenOption on ${where} compares ${parsed.name} = ${JSON.stringify(parsed.value)}, ` +
|
|
214
|
+
`which is not in allowed: ${JSON.stringify(allowed)}`,
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
return parsed;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Evaluate a `whenOption` spec against a resolved options map.
|
|
222
|
+
* Returns true (include the dep) when the option's resolved value
|
|
223
|
+
* matches the spec's compared value.
|
|
224
|
+
*
|
|
225
|
+
* Pre-validated: callers should run `validateWhenOption` once to
|
|
226
|
+
* surface authoring errors — `evaluateWhenOption` is the per-install
|
|
227
|
+
* runtime decision and assumes structurally valid input.
|
|
228
|
+
*
|
|
229
|
+
* @param {string} spec
|
|
230
|
+
* @param {Record<string, any>|null} effectiveOptions
|
|
231
|
+
* @returns {boolean}
|
|
232
|
+
*/
|
|
233
|
+
function evaluateWhenOption(spec, effectiveOptions) {
|
|
234
|
+
const parsed = parseWhenOption(spec);
|
|
235
|
+
const actual = effectiveOptions?.[parsed.name];
|
|
236
|
+
return actual === parsed.value;
|
|
237
|
+
}
|
|
238
|
+
|
|
107
239
|
/**
|
|
108
240
|
* Reads and parses a wyvrn.json manifest from disk.
|
|
109
241
|
*
|
|
@@ -160,6 +292,10 @@ module.exports = {
|
|
|
160
292
|
VALID_KINDS,
|
|
161
293
|
defaultManifest,
|
|
162
294
|
normalizeDependencies,
|
|
295
|
+
normalizeManifestDeps,
|
|
296
|
+
parseWhenOption,
|
|
297
|
+
validateWhenOption,
|
|
298
|
+
evaluateWhenOption,
|
|
163
299
|
readManifest,
|
|
164
300
|
writeManifest,
|
|
165
301
|
};
|