wyvrnpm 2.10.2 → 2.12.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.
Files changed (49) hide show
  1. package/README.md +1914 -1860
  2. package/bin/{wyvrn.js → wyvrnpm.js} +66 -0
  3. package/cmake/cpp.cmake +9 -9
  4. package/cmake/functions.cmake +224 -224
  5. package/cmake/macros.cmake +284 -284
  6. package/package.json +3 -2
  7. package/src/auth.js +66 -66
  8. package/src/binary-dir.js +95 -0
  9. package/src/bootstrap/cookbook.js +196 -196
  10. package/src/bootstrap/detect.js +150 -150
  11. package/src/bootstrap/index.js +220 -220
  12. package/src/bootstrap/version.js +72 -72
  13. package/src/build/cache.js +344 -344
  14. package/src/build/clone.js +170 -170
  15. package/src/build/cmake.js +342 -342
  16. package/src/build/index.js +299 -297
  17. package/src/build/msvc-env.js +260 -260
  18. package/src/build/recipe.js +188 -188
  19. package/src/commands/add.js +141 -141
  20. package/src/commands/bootstrap.js +96 -96
  21. package/src/commands/build.js +482 -452
  22. package/src/commands/cache.js +189 -189
  23. package/src/commands/clean.js +80 -80
  24. package/src/commands/configure.js +92 -92
  25. package/src/commands/init.js +70 -70
  26. package/src/commands/install-skill.js +115 -115
  27. package/src/commands/install.js +730 -674
  28. package/src/commands/link.js +320 -320
  29. package/src/commands/profile.js +237 -237
  30. package/src/commands/publish.js +584 -555
  31. package/src/commands/show.js +252 -252
  32. package/src/commands/version.js +187 -0
  33. package/src/compat.js +273 -273
  34. package/src/conf/index.js +415 -391
  35. package/src/conf/namespaces.js +94 -94
  36. package/src/context.js +230 -230
  37. package/src/http-fetch.js +53 -53
  38. package/src/ignore.js +118 -118
  39. package/src/logger.js +122 -122
  40. package/src/options.js +303 -303
  41. package/src/settings-overrides.js +152 -152
  42. package/src/toolchain/deps.js +164 -164
  43. package/src/toolchain/index.js +212 -212
  44. package/src/toolchain/presets.js +356 -340
  45. package/src/toolchain/template.cmake +77 -77
  46. package/src/upload-built.js +265 -265
  47. package/src/version-range.js +301 -301
  48. package/src/zip-safe.js +52 -52
  49. package/src/zip-stream.js +126 -0
@@ -1,212 +1,212 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- const { generateDepsCmake } = require('./deps');
7
- const { generateCMakePresets } = require('./presets');
8
-
9
- /**
10
- * Absolute path to the bundled `cmake/` directory shipped inside the
11
- * wyvrnpm npm package. Returned in CMake-friendly form (forward slashes).
12
- *
13
- * @returns {string}
14
- */
15
- function getBundledCmakeDir() {
16
- const dir = path.resolve(__dirname, '..', '..', 'cmake');
17
- return dir.replace(/\\/g, '/');
18
- }
19
-
20
- // Arch bit-width mapping. Kept exhaustive against `ARCH_MAP` in profile.js
21
- // so any arch a profile can hold has a deterministic "32"/"64" suffix.
22
- // Unknown arch strings fall back to an empty suffix — the consumer's
23
- // CMakeLists should then use another discriminator (e.g. profile hash).
24
- const ARCH_BIT_SUFFIX = {
25
- x86_64: '64',
26
- x86: '32',
27
- armv8: '64',
28
- armv7: '32',
29
- ppc64le: '64',
30
- s390x: '64',
31
- mips: '32',
32
- mipsel: '32',
33
- };
34
-
35
- /**
36
- * Map a profile `arch` value to the canonical "64" / "32" suffix that
37
- * `WYVRN_ARCH_SUFFIX` exposes to consumer CMakeLists. Empty string for
38
- * unknown arches — callers can pattern-match on that to fall back.
39
- *
40
- * @param {string|null|undefined} arch
41
- * @returns {string}
42
- */
43
- function archToBitSuffix(arch) {
44
- if (!arch) return '';
45
- return ARCH_BIT_SUFFIX[arch] ?? '';
46
- }
47
-
48
- // Visual Studio generator `-A <platform>` mapping. VS defaults to x64
49
- // when `-A` is unspecified — which silently wins against a 32-bit profile
50
- // and causes consumer-side `find_package()` to reject 32-bit artefacts
51
- // with "The version found is not compatible" (a CMake pointer-size check,
52
- // not a version-number check). Auto-emitting `-A` keeps VS + x86 honest.
53
- const ARCH_VS_PLATFORM = {
54
- x86_64: 'x64',
55
- x86: 'Win32',
56
- armv8: 'ARM64',
57
- armv7: 'ARM',
58
- };
59
-
60
- /**
61
- * Map a profile arch to the Visual Studio generator's `-A <platform>` value.
62
- * Returns null for arches that don't map to a known VS platform — callers
63
- * should skip `-A` in that case and let the user pass one explicitly.
64
- *
65
- * @param {string|null|undefined} arch
66
- * @returns {string|null}
67
- */
68
- function archToVsPlatform(arch) {
69
- if (!arch) return null;
70
- return ARCH_VS_PLATFORM[arch] ?? null;
71
- }
72
-
73
- /**
74
- * True when the generator name identifies a Visual Studio generator (e.g.
75
- * "Visual Studio 17 2022"). VS generators require `-A <platform>` /
76
- * `architecture` in the preset; everyone else (Ninja, Make, Xcode, …)
77
- * ignores it.
78
- *
79
- * @param {string|null|undefined} name
80
- * @returns {boolean}
81
- */
82
- function isVisualStudioGenerator(name) {
83
- if (!name) return false;
84
- return /^Visual Studio \d/.test(name);
85
- }
86
-
87
- /**
88
- * Substitute `{{KEY}}` placeholders in a template string.
89
- *
90
- * @param {string} template
91
- * @param {Record<string, string>} values
92
- * @returns {string}
93
- */
94
- function renderTemplate(template, values) {
95
- return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
96
- if (Object.prototype.hasOwnProperty.call(values, key)) {
97
- return values[key];
98
- }
99
- throw new Error(`Toolchain template has no value for placeholder {{${key}}}`);
100
- });
101
- }
102
-
103
- /**
104
- * Produce the toolchain template's placeholder substitutions.
105
- *
106
- * @param {object} args
107
- * @param {import('../profile').WyvrnProfile} args.profile
108
- * @param {string} args.profileName
109
- * @param {string} args.profileHash
110
- * @param {string[]} args.packageNames
111
- * @returns {Record<string, string>}
112
- */
113
- function buildPlaceholders({ profile, profileName, profileHash, packageNames }) {
114
- const prefixPathEntries = packageNames
115
- .map((name) => ` "\${CMAKE_CURRENT_LIST_DIR}/${name}"`)
116
- .join('\n');
117
-
118
- return {
119
- GENERATED_AT: new Date().toISOString(),
120
- PROFILE_NAME: profileName,
121
- PROFILE_HASH: profileHash,
122
- PROFILE_OS: profile.os ?? '',
123
- PROFILE_ARCH: profile.arch ?? '',
124
- PROFILE_ARCH_SUFFIX: archToBitSuffix(profile.arch),
125
- PROFILE_COMPILER: profile.compiler ?? '',
126
- PROFILE_COMPILER_VERSION: profile['compiler.version'] ?? '',
127
- PROFILE_CPPSTD: profile['compiler.cppstd'] ?? '20',
128
- PROFILE_RUNTIME: profile['compiler.runtime'] ?? '',
129
- WYVRNPM_CMAKE_DIR: getBundledCmakeDir(),
130
- PREFIX_PATH_ENTRIES: prefixPathEntries || ' # (no dependencies)',
131
- };
132
- }
133
-
134
- /**
135
- * Generate the three toolchain artefacts under `destDir`:
136
- * - wyvrn_toolchain.cmake
137
- * - wyvrn_deps.cmake
138
- * - wyvrn_profile.json
139
- *
140
- * ───────────────────────────────────────────────────────────────────────────
141
- * CONTRACT (PLAN-CMAKE-TOOLCHAIN Phase F ↔ PLAN-BUILD-MISSING Phase 3)
142
- * ───────────────────────────────────────────────────────────────────────────
143
- * This function is the **single source of truth** for translating a build
144
- * profile into a CMake configuration. Two callers exist:
145
- *
146
- * 1. `install` — writes the toolchain into a consumer project's
147
- * `wyvrn_internal/`, so `cmake --preset` picks it
148
- * up at configure time.
149
- * 2. `buildFromSource` — (not yet implemented; PLAN-BUILD-MISSING §3)
150
- * writes the toolchain into a scratch build dir
151
- * when we source-build a package via
152
- * `--build=missing`. The package is compiled
153
- * with THIS function's output, guaranteeing the
154
- * resulting binary's profile → flag mapping is
155
- * bit-for-bit identical to what a consumer sees.
156
- *
157
- * Do NOT replicate this mapping elsewhere. If PLAN-BUILD-MISSING §3 finds it
158
- * needs additional behaviour (e.g. extra CMake cache variables), extend this
159
- * function — do not branch.
160
- *
161
- * Callers choose `destDir` and `packageNames`:
162
- * - `destDir` — any directory; in source-build, points at the scratch
163
- * `wyvrn_internal/` co-located with the cloned source.
164
- * - `packageNames` — in `install`, the consumer's resolved deps; in
165
- * source-build, the *package's own* resolved deps.
166
- *
167
- * Profile arguments (`profile`, `profileName`, `profileHash`) are always the
168
- * active consumer profile — source-build still uses the consumer's profile,
169
- * not the package's. That is the whole point of the source-build path.
170
- * ───────────────────────────────────────────────────────────────────────────
171
- *
172
- * @param {object} args
173
- * @param {string} args.destDir Where to write the three files.
174
- * @param {import('../profile').WyvrnProfile} args.profile
175
- * @param {string} args.profileName
176
- * @param {string} args.profileHash
177
- * @param {string[]} args.packageNames Resolved dep names in topological order.
178
- * @returns {{ toolchain: string, deps: string, profile: string }}
179
- * Absolute paths of the three files written.
180
- */
181
- function generateToolchain({ destDir, profile, profileName, profileHash, packageNames }) {
182
- fs.mkdirSync(destDir, { recursive: true });
183
-
184
- const templatePath = path.join(__dirname, 'template.cmake');
185
- const template = fs.readFileSync(templatePath, 'utf8');
186
- const placeholders = buildPlaceholders({ profile, profileName, profileHash, packageNames });
187
- const toolchainContent = renderTemplate(template, placeholders);
188
- const depsContent = generateDepsCmake({ packageNames, profileHash });
189
- const profileContent = JSON.stringify({ name: profileName, hash: profileHash, ...profile }, null, 2) + '\n';
190
-
191
- const toolchainPath = path.join(destDir, 'wyvrn_toolchain.cmake');
192
- const depsPath = path.join(destDir, 'wyvrn_deps.cmake');
193
- const profilePath = path.join(destDir, 'wyvrn_profile.json');
194
-
195
- fs.writeFileSync(toolchainPath, toolchainContent, 'utf8');
196
- fs.writeFileSync(depsPath, depsContent, 'utf8');
197
- fs.writeFileSync(profilePath, profileContent, 'utf8');
198
-
199
- return { toolchain: toolchainPath, deps: depsPath, profile: profilePath };
200
- }
201
-
202
- module.exports = {
203
- generateToolchain,
204
- generateCMakePresets,
205
- getBundledCmakeDir,
206
- archToVsPlatform,
207
- isVisualStudioGenerator,
208
- // Exported for tests
209
- archToBitSuffix,
210
- buildPlaceholders,
211
- renderTemplate,
212
- };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const { generateDepsCmake } = require('./deps');
7
+ const { generateCMakePresets } = require('./presets');
8
+
9
+ /**
10
+ * Absolute path to the bundled `cmake/` directory shipped inside the
11
+ * wyvrnpm npm package. Returned in CMake-friendly form (forward slashes).
12
+ *
13
+ * @returns {string}
14
+ */
15
+ function getBundledCmakeDir() {
16
+ const dir = path.resolve(__dirname, '..', '..', 'cmake');
17
+ return dir.replace(/\\/g, '/');
18
+ }
19
+
20
+ // Arch bit-width mapping. Kept exhaustive against `ARCH_MAP` in profile.js
21
+ // so any arch a profile can hold has a deterministic "32"/"64" suffix.
22
+ // Unknown arch strings fall back to an empty suffix — the consumer's
23
+ // CMakeLists should then use another discriminator (e.g. profile hash).
24
+ const ARCH_BIT_SUFFIX = {
25
+ x86_64: '64',
26
+ x86: '32',
27
+ armv8: '64',
28
+ armv7: '32',
29
+ ppc64le: '64',
30
+ s390x: '64',
31
+ mips: '32',
32
+ mipsel: '32',
33
+ };
34
+
35
+ /**
36
+ * Map a profile `arch` value to the canonical "64" / "32" suffix that
37
+ * `WYVRN_ARCH_SUFFIX` exposes to consumer CMakeLists. Empty string for
38
+ * unknown arches — callers can pattern-match on that to fall back.
39
+ *
40
+ * @param {string|null|undefined} arch
41
+ * @returns {string}
42
+ */
43
+ function archToBitSuffix(arch) {
44
+ if (!arch) return '';
45
+ return ARCH_BIT_SUFFIX[arch] ?? '';
46
+ }
47
+
48
+ // Visual Studio generator `-A <platform>` mapping. VS defaults to x64
49
+ // when `-A` is unspecified — which silently wins against a 32-bit profile
50
+ // and causes consumer-side `find_package()` to reject 32-bit artefacts
51
+ // with "The version found is not compatible" (a CMake pointer-size check,
52
+ // not a version-number check). Auto-emitting `-A` keeps VS + x86 honest.
53
+ const ARCH_VS_PLATFORM = {
54
+ x86_64: 'x64',
55
+ x86: 'Win32',
56
+ armv8: 'ARM64',
57
+ armv7: 'ARM',
58
+ };
59
+
60
+ /**
61
+ * Map a profile arch to the Visual Studio generator's `-A <platform>` value.
62
+ * Returns null for arches that don't map to a known VS platform — callers
63
+ * should skip `-A` in that case and let the user pass one explicitly.
64
+ *
65
+ * @param {string|null|undefined} arch
66
+ * @returns {string|null}
67
+ */
68
+ function archToVsPlatform(arch) {
69
+ if (!arch) return null;
70
+ return ARCH_VS_PLATFORM[arch] ?? null;
71
+ }
72
+
73
+ /**
74
+ * True when the generator name identifies a Visual Studio generator (e.g.
75
+ * "Visual Studio 17 2022"). VS generators require `-A <platform>` /
76
+ * `architecture` in the preset; everyone else (Ninja, Make, Xcode, …)
77
+ * ignores it.
78
+ *
79
+ * @param {string|null|undefined} name
80
+ * @returns {boolean}
81
+ */
82
+ function isVisualStudioGenerator(name) {
83
+ if (!name) return false;
84
+ return /^Visual Studio \d/.test(name);
85
+ }
86
+
87
+ /**
88
+ * Substitute `{{KEY}}` placeholders in a template string.
89
+ *
90
+ * @param {string} template
91
+ * @param {Record<string, string>} values
92
+ * @returns {string}
93
+ */
94
+ function renderTemplate(template, values) {
95
+ return template.replace(/\{\{(\w+)\}\}/g, (match, key) => {
96
+ if (Object.prototype.hasOwnProperty.call(values, key)) {
97
+ return values[key];
98
+ }
99
+ throw new Error(`Toolchain template has no value for placeholder {{${key}}}`);
100
+ });
101
+ }
102
+
103
+ /**
104
+ * Produce the toolchain template's placeholder substitutions.
105
+ *
106
+ * @param {object} args
107
+ * @param {import('../profile').WyvrnProfile} args.profile
108
+ * @param {string} args.profileName
109
+ * @param {string} args.profileHash
110
+ * @param {string[]} args.packageNames
111
+ * @returns {Record<string, string>}
112
+ */
113
+ function buildPlaceholders({ profile, profileName, profileHash, packageNames }) {
114
+ const prefixPathEntries = packageNames
115
+ .map((name) => ` "\${CMAKE_CURRENT_LIST_DIR}/${name}"`)
116
+ .join('\n');
117
+
118
+ return {
119
+ GENERATED_AT: new Date().toISOString(),
120
+ PROFILE_NAME: profileName,
121
+ PROFILE_HASH: profileHash,
122
+ PROFILE_OS: profile.os ?? '',
123
+ PROFILE_ARCH: profile.arch ?? '',
124
+ PROFILE_ARCH_SUFFIX: archToBitSuffix(profile.arch),
125
+ PROFILE_COMPILER: profile.compiler ?? '',
126
+ PROFILE_COMPILER_VERSION: profile['compiler.version'] ?? '',
127
+ PROFILE_CPPSTD: profile['compiler.cppstd'] ?? '20',
128
+ PROFILE_RUNTIME: profile['compiler.runtime'] ?? '',
129
+ WYVRNPM_CMAKE_DIR: getBundledCmakeDir(),
130
+ PREFIX_PATH_ENTRIES: prefixPathEntries || ' # (no dependencies)',
131
+ };
132
+ }
133
+
134
+ /**
135
+ * Generate the three toolchain artefacts under `destDir`:
136
+ * - wyvrn_toolchain.cmake
137
+ * - wyvrn_deps.cmake
138
+ * - wyvrn_profile.json
139
+ *
140
+ * ───────────────────────────────────────────────────────────────────────────
141
+ * CONTRACT (PLAN-CMAKE-TOOLCHAIN Phase F ↔ PLAN-BUILD-MISSING Phase 3)
142
+ * ───────────────────────────────────────────────────────────────────────────
143
+ * This function is the **single source of truth** for translating a build
144
+ * profile into a CMake configuration. Two callers exist:
145
+ *
146
+ * 1. `install` — writes the toolchain into a consumer project's
147
+ * `wyvrn_internal/`, so `cmake --preset` picks it
148
+ * up at configure time.
149
+ * 2. `buildFromSource` — (not yet implemented; PLAN-BUILD-MISSING §3)
150
+ * writes the toolchain into a scratch build dir
151
+ * when we source-build a package via
152
+ * `--build=missing`. The package is compiled
153
+ * with THIS function's output, guaranteeing the
154
+ * resulting binary's profile → flag mapping is
155
+ * bit-for-bit identical to what a consumer sees.
156
+ *
157
+ * Do NOT replicate this mapping elsewhere. If PLAN-BUILD-MISSING §3 finds it
158
+ * needs additional behaviour (e.g. extra CMake cache variables), extend this
159
+ * function — do not branch.
160
+ *
161
+ * Callers choose `destDir` and `packageNames`:
162
+ * - `destDir` — any directory; in source-build, points at the scratch
163
+ * `wyvrn_internal/` co-located with the cloned source.
164
+ * - `packageNames` — in `install`, the consumer's resolved deps; in
165
+ * source-build, the *package's own* resolved deps.
166
+ *
167
+ * Profile arguments (`profile`, `profileName`, `profileHash`) are always the
168
+ * active consumer profile — source-build still uses the consumer's profile,
169
+ * not the package's. That is the whole point of the source-build path.
170
+ * ───────────────────────────────────────────────────────────────────────────
171
+ *
172
+ * @param {object} args
173
+ * @param {string} args.destDir Where to write the three files.
174
+ * @param {import('../profile').WyvrnProfile} args.profile
175
+ * @param {string} args.profileName
176
+ * @param {string} args.profileHash
177
+ * @param {string[]} args.packageNames Resolved dep names in topological order.
178
+ * @returns {{ toolchain: string, deps: string, profile: string }}
179
+ * Absolute paths of the three files written.
180
+ */
181
+ function generateToolchain({ destDir, profile, profileName, profileHash, packageNames }) {
182
+ fs.mkdirSync(destDir, { recursive: true });
183
+
184
+ const templatePath = path.join(__dirname, 'template.cmake');
185
+ const template = fs.readFileSync(templatePath, 'utf8');
186
+ const placeholders = buildPlaceholders({ profile, profileName, profileHash, packageNames });
187
+ const toolchainContent = renderTemplate(template, placeholders);
188
+ const depsContent = generateDepsCmake({ packageNames, profileHash });
189
+ const profileContent = JSON.stringify({ name: profileName, hash: profileHash, ...profile }, null, 2) + '\n';
190
+
191
+ const toolchainPath = path.join(destDir, 'wyvrn_toolchain.cmake');
192
+ const depsPath = path.join(destDir, 'wyvrn_deps.cmake');
193
+ const profilePath = path.join(destDir, 'wyvrn_profile.json');
194
+
195
+ fs.writeFileSync(toolchainPath, toolchainContent, 'utf8');
196
+ fs.writeFileSync(depsPath, depsContent, 'utf8');
197
+ fs.writeFileSync(profilePath, profileContent, 'utf8');
198
+
199
+ return { toolchain: toolchainPath, deps: depsPath, profile: profilePath };
200
+ }
201
+
202
+ module.exports = {
203
+ generateToolchain,
204
+ generateCMakePresets,
205
+ getBundledCmakeDir,
206
+ archToVsPlatform,
207
+ isVisualStudioGenerator,
208
+ // Exported for tests
209
+ archToBitSuffix,
210
+ buildPlaceholders,
211
+ renderTemplate,
212
+ };