wyvrnpm 1.3.2 → 2.0.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.
@@ -1,33 +1,33 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { defaultManifest, writeManifest } = require('../manifest');
6
-
7
- /**
8
- * Initialises a new wyvrn.json manifest in the project root.
9
- * If a manifest already exists the command exits early without overwriting it.
10
- *
11
- * @param {object} argv - Parsed yargs arguments.
12
- * @param {string} argv.manifest - Path to the manifest file.
13
- * @param {string} argv.root - Project root directory.
14
- * @returns {Promise<void>}
15
- */
16
- async function init(argv) {
17
- const manifestPath = path.resolve(argv.manifest);
18
- const rootDir = path.resolve(argv.root);
19
-
20
- if (fs.existsSync(manifestPath)) {
21
- console.log(`[wyvrn] Manifest already exists at ${manifestPath}`);
22
- return;
23
- }
24
-
25
- const projectName = path.basename(rootDir);
26
- const manifest = defaultManifest(projectName);
27
-
28
- writeManifest(manifestPath, manifest);
29
-
30
- console.log(`[wyvrn] Created manifest at ${manifestPath}`);
31
- }
32
-
33
- module.exports = init;
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { defaultManifest, writeManifest } = require('../manifest');
6
+
7
+ /**
8
+ * Initialises a new wyvrn.json manifest in the project root.
9
+ * If a manifest already exists the command exits early without overwriting it.
10
+ *
11
+ * @param {object} argv - Parsed yargs arguments.
12
+ * @param {string} argv.manifest - Path to the manifest file.
13
+ * @param {string} argv.root - Project root directory.
14
+ * @returns {Promise<void>}
15
+ */
16
+ async function init(argv) {
17
+ const manifestPath = path.resolve(argv.manifest);
18
+ const rootDir = path.resolve(argv.root);
19
+
20
+ if (fs.existsSync(manifestPath)) {
21
+ console.log(`[wyvrn] Manifest already exists at ${manifestPath}`);
22
+ return;
23
+ }
24
+
25
+ const projectName = path.basename(rootDir);
26
+ const manifest = defaultManifest(projectName);
27
+
28
+ writeManifest(manifestPath, manifest);
29
+
30
+ console.log(`[wyvrn] Created manifest at ${manifestPath}`);
31
+ }
32
+
33
+ module.exports = init;
@@ -1,34 +1,35 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
3
+ const fs = require('fs');
4
4
  const path = require('path');
5
- const { readManifest } = require('../manifest');
6
- const { resolveDependencies } = require('../resolve');
7
- const { downloadDependencies } = require('../download');
8
- const { readConfig } = require('../config');
5
+
6
+ const { readManifest, normalizeDependencies } = require('../manifest');
7
+ const { resolveDependencies } = require('../resolve');
8
+ const { downloadDependencies } = require('../download');
9
+ const { readConfig } = require('../config');
10
+ const { loadProfile, hashProfile, formatProfile, mergeProfile } = require('../profile');
9
11
 
10
12
  /**
11
13
  * Resolves and downloads all dependencies declared in the manifest, then writes
12
14
  * a wyvrn.lock file recording exactly what was installed.
13
15
  *
14
- * @param {object} argv - Parsed yargs arguments.
15
- * @param {string} argv.manifest - Path to wyvrn.json.
16
- * @param {string} argv.root - Project root directory.
17
- * @param {string[]} [argv.source] - One or more base URLs for package sources.
18
- * @param {string} argv.platform - Target platform string.
19
- * @param {number} argv.timeout - HTTP timeout in seconds.
20
- * @returns {Promise<void>}
16
+ * v2 behaviour:
17
+ * - Loads the named build profile (--profile flag → config.defaultProfile → "default")
18
+ * - Each dependency can override individual profile settings via its `settings` field
19
+ * - Lock file records the full profile + per-package SHA256, profileHash, and git metadata
20
+ *
21
+ * @param {object} argv
21
22
  */
22
23
  async function install(argv) {
23
24
  const manifestPath = path.resolve(argv.manifest);
24
- const rootDir = path.resolve(argv.root);
25
+ const rootDir = path.resolve(argv.root);
25
26
 
26
- // CLI --source takes priority; fall back to config installSources.
27
+ // ── Auth / sources ────────────────────────────────────────────────────────
27
28
  let packageSources;
28
29
  if (argv.source && argv.source.length > 0) {
29
30
  packageSources = argv.source;
30
31
  } else {
31
- const config = readConfig();
32
+ const config = readConfig();
32
33
  packageSources = config.installSources.map((s) => s.url);
33
34
  if (packageSources.length > 0) {
34
35
  console.log(`[wyvrn] Using ${packageSources.length} source(s) from config`);
@@ -42,13 +43,25 @@ async function install(argv) {
42
43
  );
43
44
  }
44
45
 
45
- const lockPath = path.join(path.dirname(manifestPath), 'wyvrn.lock');
46
+ // ── Active build profile ──────────────────────────────────────────────────
47
+ const config = readConfig();
48
+ const profileName = argv.profile ?? config.defaultProfile ?? 'default';
49
+ const { profile: baseProfile, fromFile } = loadProfile(profileName);
50
+
51
+ console.log(`[wyvrn] Profile: "${profileName}"${fromFile ? '' : ' (auto-detected)'}`);
52
+ console.log(formatProfile(baseProfile).split('\n').map((l) => ` ${l}`).join('\n'));
53
+ console.log(` Profile hash : ${hashProfile(baseProfile)}`);
54
+
55
+ // ── Lock file ─────────────────────────────────────────────────────────────
56
+ const lockPath = path.join(path.dirname(manifestPath), 'wyvrn.lock');
46
57
  const lockedVersions = new Map();
58
+
47
59
  if (fs.existsSync(lockPath)) {
48
60
  try {
49
61
  const lock = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
50
- for (const [name, version] of Object.entries(lock.packages || {})) {
51
- lockedVersions.set(name, version);
62
+ for (const [name, entry] of Object.entries(lock.packages ?? {})) {
63
+ const ver = typeof entry === 'string' ? entry : entry.version;
64
+ if (ver) lockedVersions.set(name, ver);
52
65
  }
53
66
  console.log(`[wyvrn] Lock file found — ${lockedVersions.size} pinned package(s)`);
54
67
  } catch {
@@ -56,47 +69,81 @@ async function install(argv) {
56
69
  }
57
70
  }
58
71
 
72
+ // ── Read manifest ─────────────────────────────────────────────────────────
59
73
  const manifest = readManifest(manifestPath);
60
74
 
61
- // Normalize dependencies: support both array [{ Name, Version }] and object { name: version }.
62
- const rawDeps = manifest.dependencies || manifest.Dependencies || {};
63
- const rootDeps = Array.isArray(rawDeps)
64
- ? Object.fromEntries(rawDeps.map((d) => [d.Name ?? d.name, d.Version ?? d.version]))
65
- : rawDeps;
75
+ // Normalize to { name: { version, settings } }
76
+ const normalizedDeps = normalizeDependencies(manifest.dependencies ?? manifest.Dependencies);
77
+
78
+ // For resolution, only pass name version (settings don't affect resolution)
79
+ const depsForResolution = Object.fromEntries(
80
+ Object.entries(normalizedDeps).map(([name, d]) => [name, d.version]),
81
+ );
66
82
 
67
83
  console.log(
68
84
  `[wyvrn] Installing dependencies for "${manifest.name}" (platform: ${argv.platform})`,
69
85
  );
70
86
 
71
87
  const resolvedDeps = await resolveDependencies(
72
- rootDeps,
88
+ depsForResolution,
73
89
  packageSources,
74
90
  argv.platform,
75
91
  fetch,
76
92
  lockedVersions,
77
93
  );
78
94
 
95
+ // ── Build per-dependency enriched map ─────────────────────────────────────
96
+ // Each dep gets a profileHash based on base profile + any settings overrides
97
+ // declared in wyvrn.json under that dependency's "settings" key.
98
+ const enrichedDeps = new Map();
99
+ for (const [name, version] of resolvedDeps) {
100
+ const depOverrides = normalizedDeps[name]?.settings ?? {};
101
+ const effectiveProfile = mergeProfile(baseProfile, depOverrides);
102
+ const profileHash = hashProfile(effectiveProfile);
103
+
104
+ if (Object.keys(depOverrides).length > 0) {
105
+ console.log(
106
+ `[wyvrn] ${name}: settings override → profileHash ${profileHash}` +
107
+ ` (${JSON.stringify(depOverrides)})`,
108
+ );
109
+ }
110
+
111
+ enrichedDeps.set(name, { version, profileHash, profile: effectiveProfile });
112
+ }
113
+
79
114
  const razerDir = path.join(rootDir, 'wyvrn_internal');
80
115
 
81
- await downloadDependencies(
82
- resolvedDeps,
116
+ // Extract auth from the first install source (if any)
117
+ const firstInstallSrc = config.installSources?.[0];
118
+ const authOptions = {
119
+ awsProfile: firstInstallSrc?.profile ?? undefined,
120
+ token: firstInstallSrc?.token ?? undefined,
121
+ };
122
+
123
+ const lockEntries = await downloadDependencies(
124
+ enrichedDeps,
83
125
  packageSources,
84
126
  argv.platform,
85
127
  razerDir,
86
128
  fetch,
87
129
  argv.timeout,
130
+ authOptions,
88
131
  );
89
132
 
90
- // Build lock file — packages sorted alphabetically for deterministic diffs.
133
+ // ── Write v2 lock file ────────────────────────────────────────────────────
91
134
  const sortedPackages = {};
92
135
  for (const key of [...resolvedDeps.keys()].sort()) {
93
- sortedPackages[key] = resolvedDeps.get(key);
136
+ sortedPackages[key] = lockEntries?.get(key) ?? { version: resolvedDeps.get(key) };
94
137
  }
95
138
 
96
139
  const lockData = {
97
- generatedAt: new Date().toISOString(),
98
- platform: argv.platform,
99
- packages: sortedPackages,
140
+ wyvrnVersion: 2,
141
+ generatedAt: new Date().toISOString(),
142
+ platform: argv.platform,
143
+ profileName,
144
+ profile: baseProfile,
145
+ profileHash: hashProfile(baseProfile),
146
+ packages: sortedPackages,
100
147
  };
101
148
 
102
149
  fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');