wyvrnpm 2.8.1 → 2.9.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.
@@ -1,319 +1,320 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { readConfig, writeConfig } = require('../config');
6
- const { readManifest } = require('../manifest');
7
- const { createLink, isLink, removeLink, getLinkTarget } = require('../link-utils');
8
- const { downloadDependencies } = require('../download');
9
- const { resolveDependencies } = require('../resolve');
10
- const log = require('../logger');
11
-
12
- /**
13
- * Normalizes a linked package entry to object form.
14
- * Supports both legacy string format and new object format.
15
- *
16
- * @param {string|object} entry - Either a path string or {path, subdir} object.
17
- * @returns {{path: string, subdir?: string}}
18
- */
19
- function normalizeLinkedEntry(entry) {
20
- if (typeof entry === 'string') {
21
- return { path: entry };
22
- }
23
- return entry;
24
- }
25
-
26
- /**
27
- * Gets the effective link target path (combining path + subdir).
28
- *
29
- * @param {{path: string, subdir?: string}} entry - Linked package entry.
30
- * @returns {string} The full path to link to.
31
- */
32
- function getEffectivePath(entry) {
33
- if (entry.subdir) {
34
- return path.join(entry.path, entry.subdir);
35
- }
36
- return entry.path;
37
- }
38
-
39
- /**
40
- * Register the current directory's package globally for linking.
41
- * Reads wyvrn.json to get the package name, stores {name: {path, subdir}} in config.
42
- *
43
- * @param {string} manifestPath - Path to wyvrn.json
44
- * @param {string} [subdir] - Optional subdirectory within the package to link.
45
- */
46
- function registerGlobal(manifestPath, subdir) {
47
- const manifest = readManifest(manifestPath);
48
- const packageName = manifest.name || manifest.Name;
49
-
50
- if (!packageName) {
51
- log.error('wyvrn.json must have a "name" field');
52
- process.exit(1);
53
- }
54
-
55
- const packagePath = path.dirname(path.resolve(manifestPath));
56
- const config = readConfig();
57
- config.linkedPackages = config.linkedPackages || {};
58
-
59
- const entry = { path: packagePath };
60
- if (subdir) {
61
- entry.subdir = subdir;
62
- }
63
- config.linkedPackages[packageName] = entry;
64
- writeConfig(config);
65
-
66
- const effectivePath = getEffectivePath(entry);
67
- log.info(`Registered "${packageName}" ${effectivePath}`);
68
- }
69
-
70
- /**
71
- * Link a package into the current project's wyvrn_internal directory.
72
- *
73
- * @param {string} name - Package name to link.
74
- * @param {string} sourcePath - Source directory path (absolute or relative).
75
- * @param {string} rootDir - Project root directory.
76
- */
77
- function linkToProject(name, sourcePath, rootDir) {
78
- const absoluteSource = path.resolve(sourcePath);
79
-
80
- if (!fs.existsSync(absoluteSource)) {
81
- log.error(`source path does not exist: ${absoluteSource}`);
82
- process.exit(1);
83
- }
84
-
85
- const razerDir = path.join(rootDir, 'wyvrn_internal');
86
- const linkPath = path.join(razerDir, name);
87
-
88
- // Create the link
89
- createLink(absoluteSource, linkPath);
90
-
91
- // Write a .wyvrn-version file to indicate it's linked
92
- const versionFile = path.join(linkPath, '.wyvrn-version');
93
- fs.writeFileSync(versionFile, 'linked', 'utf8');
94
-
95
- // Update the lock file to record the link
96
- const lockPath = path.join(rootDir, 'wyvrn.lock');
97
- let lockData = { packages: {} };
98
- if (fs.existsSync(lockPath)) {
99
- try {
100
- lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
101
- } catch {
102
- // Use default if parsing fails
103
- }
104
- }
105
- lockData.packages = lockData.packages || {};
106
- lockData.packages[name] = `linked:${absoluteSource}`;
107
- lockData.generatedAt = new Date().toISOString();
108
- fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
109
-
110
- log.info(`Linked: ${name} → ${absoluteSource}`);
111
- }
112
-
113
- /**
114
- * Unlink a package from the current project.
115
- *
116
- * @param {string} name - Package name to unlink.
117
- * @param {string} rootDir - Project root directory.
118
- * @param {boolean} restore - Whether to re-download from registry.
119
- * @param {object} argv - Original argv for re-download options.
120
- */
121
- async function unlinkFromProject(name, rootDir, restore, argv) {
122
- const razerDir = path.join(rootDir, 'wyvrn_internal');
123
- const linkPath = path.join(razerDir, name);
124
-
125
- if (!fs.existsSync(linkPath)) {
126
- log.error(`package "${name}" is not installed`);
127
- process.exit(1);
128
- }
129
-
130
- if (!isLink(linkPath)) {
131
- log.error(`package "${name}" is not a linked package`);
132
- process.exit(1);
133
- }
134
-
135
- // Remove the symlink
136
- removeLink(linkPath);
137
- log.info(`Unlinked: ${name}`);
138
-
139
- // Update the lock file
140
- const lockPath = path.join(rootDir, 'wyvrn.lock');
141
- if (fs.existsSync(lockPath)) {
142
- try {
143
- const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
144
- if (lockData.packages && lockData.packages[name]) {
145
- delete lockData.packages[name];
146
- lockData.generatedAt = new Date().toISOString();
147
- fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
148
- }
149
- } catch {
150
- // Ignore lock file errors
151
- }
152
- }
153
-
154
- // Re-download from registry if requested
155
- if (restore) {
156
- const manifestPath = path.resolve(argv.manifest);
157
- const manifest = readManifest(manifestPath);
158
-
159
- const rawDeps = manifest.dependencies || manifest.Dependencies || {};
160
- const deps = Array.isArray(rawDeps)
161
- ? Object.fromEntries(rawDeps.map((d) => [d.Name ?? d.name, d.Version ?? d.version]))
162
- : rawDeps;
163
-
164
- if (!deps[name]) {
165
- log.warn(`"${name}" is not in manifest dependencies, cannot restore`);
166
- return;
167
- }
168
-
169
- // Get package sources
170
- let packageSources;
171
- if (argv.source && argv.source.length > 0) {
172
- packageSources = argv.source;
173
- } else {
174
- const config = readConfig();
175
- packageSources = config.installSources.map((s) => s.url);
176
- }
177
-
178
- if (packageSources.length === 0) {
179
- log.warn('no sources configured, cannot restore package');
180
- return;
181
- }
182
-
183
- // Resolve just this one dependency
184
- const resolvedDeps = await resolveDependencies(
185
- { [name]: deps[name] },
186
- packageSources,
187
- argv.platform || 'win_x64',
188
- fetch,
189
- new Map(),
190
- );
191
-
192
- // Download it
193
- await downloadDependencies(
194
- resolvedDeps,
195
- packageSources,
196
- argv.platform || 'win_x64',
197
- razerDir,
198
- fetch,
199
- argv.timeout || 300,
200
- );
201
-
202
- // Update lock file with restored version
203
- if (fs.existsSync(lockPath)) {
204
- try {
205
- const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
206
- for (const [depName, version] of resolvedDeps) {
207
- lockData.packages[depName] = version;
208
- }
209
- lockData.generatedAt = new Date().toISOString();
210
- fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
211
- } catch {
212
- // Ignore lock file errors
213
- }
214
- }
215
- }
216
- }
217
-
218
- /**
219
- * List all globally registered packages.
220
- */
221
- function listLinked() {
222
- const config = readConfig();
223
- const linked = config.linkedPackages || {};
224
- const entries = Object.entries(linked);
225
-
226
- if (entries.length === 0) {
227
- log.info('No globally registered packages');
228
- return;
229
- }
230
-
231
- log.info('Globally registered packages:');
232
- for (const [name, rawEntry] of entries) {
233
- const entry = normalizeLinkedEntry(rawEntry);
234
- const effectivePath = getEffectivePath(entry);
235
- const exists = fs.existsSync(effectivePath);
236
- const status = exists ? '' : ' (path not found)';
237
- const subdirInfo = entry.subdir ? ` [subdir: ${entry.subdir}]` : '';
238
- console.log(` ${name} ${effectivePath}${subdirInfo}${status}`);
239
- }
240
- }
241
-
242
- /**
243
- * Main link command handler.
244
- *
245
- * @param {object} argv - Parsed yargs arguments.
246
- */
247
- async function link(argv) {
248
- const rootDir = path.resolve(argv.root);
249
- const manifestPath = path.resolve(argv.manifest);
250
-
251
- // wyvrnpm link --list
252
- if (argv.list) {
253
- listLinked();
254
- return;
255
- }
256
-
257
- // wyvrnpm link (no args) - register current package globally
258
- if (!argv.name) {
259
- if (!fs.existsSync(manifestPath)) {
260
- log.error(`no wyvrn.json found at ${manifestPath}`);
261
- process.exit(1);
262
- }
263
- registerGlobal(manifestPath, argv.subdir);
264
- return;
265
- }
266
-
267
- // wyvrnpm link <name> <path> - direct path link
268
- if (argv.name && argv.path) {
269
- let targetPath = argv.path;
270
- if (argv.subdir) {
271
- targetPath = path.join(argv.path, argv.subdir);
272
- }
273
- linkToProject(argv.name, targetPath, rootDir);
274
- return;
275
- }
276
-
277
- // wyvrnpm link <name> - link from global registry
278
- const config = readConfig();
279
- const linked = config.linkedPackages || {};
280
-
281
- if (!linked[argv.name]) {
282
- log.error(
283
- `"${argv.name}" is not registered globally\n` +
284
- `Run "wyvrnpm link" in the package directory first, or use:\n` +
285
- ` wyvrnpm link ${argv.name} <path>`,
286
- );
287
- process.exit(1);
288
- }
289
-
290
- const entry = normalizeLinkedEntry(linked[argv.name]);
291
- // Command-line --subdir overrides the registered subdir
292
- let effectivePath;
293
- if (argv.subdir) {
294
- effectivePath = path.join(entry.path, argv.subdir);
295
- } else {
296
- effectivePath = getEffectivePath(entry);
297
- }
298
-
299
- linkToProject(argv.name, effectivePath, rootDir);
300
- }
301
-
302
- /**
303
- * Unlink command handler.
304
- *
305
- * @param {object} argv - Parsed yargs arguments.
306
- */
307
- async function unlink(argv) {
308
- const rootDir = path.resolve(argv.root);
309
- await unlinkFromProject(argv.name, rootDir, argv.restore, argv);
310
- }
311
-
312
- module.exports = {
313
- link,
314
- unlink,
315
- listLinked,
316
- registerGlobal,
317
- linkToProject,
318
- unlinkFromProject,
319
- };
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { readConfig, writeConfig } = require('../config');
6
+ const { readManifest } = require('../manifest');
7
+ const { createLink, isLink, removeLink, getLinkTarget } = require('../link-utils');
8
+ const { downloadDependencies } = require('../download');
9
+ const { resolveDependencies } = require('../resolve');
10
+ const { wyvrnFetch } = require('../http-fetch');
11
+ const log = require('../logger');
12
+
13
+ /**
14
+ * Normalizes a linked package entry to object form.
15
+ * Supports both legacy string format and new object format.
16
+ *
17
+ * @param {string|object} entry - Either a path string or {path, subdir} object.
18
+ * @returns {{path: string, subdir?: string}}
19
+ */
20
+ function normalizeLinkedEntry(entry) {
21
+ if (typeof entry === 'string') {
22
+ return { path: entry };
23
+ }
24
+ return entry;
25
+ }
26
+
27
+ /**
28
+ * Gets the effective link target path (combining path + subdir).
29
+ *
30
+ * @param {{path: string, subdir?: string}} entry - Linked package entry.
31
+ * @returns {string} The full path to link to.
32
+ */
33
+ function getEffectivePath(entry) {
34
+ if (entry.subdir) {
35
+ return path.join(entry.path, entry.subdir);
36
+ }
37
+ return entry.path;
38
+ }
39
+
40
+ /**
41
+ * Register the current directory's package globally for linking.
42
+ * Reads wyvrn.json to get the package name, stores {name: {path, subdir}} in config.
43
+ *
44
+ * @param {string} manifestPath - Path to wyvrn.json
45
+ * @param {string} [subdir] - Optional subdirectory within the package to link.
46
+ */
47
+ function registerGlobal(manifestPath, subdir) {
48
+ const manifest = readManifest(manifestPath);
49
+ const packageName = manifest.name || manifest.Name;
50
+
51
+ if (!packageName) {
52
+ log.error('wyvrn.json must have a "name" field');
53
+ process.exit(1);
54
+ }
55
+
56
+ const packagePath = path.dirname(path.resolve(manifestPath));
57
+ const config = readConfig();
58
+ config.linkedPackages = config.linkedPackages || {};
59
+
60
+ const entry = { path: packagePath };
61
+ if (subdir) {
62
+ entry.subdir = subdir;
63
+ }
64
+ config.linkedPackages[packageName] = entry;
65
+ writeConfig(config);
66
+
67
+ const effectivePath = getEffectivePath(entry);
68
+ log.info(`Registered "${packageName}" → ${effectivePath}`);
69
+ }
70
+
71
+ /**
72
+ * Link a package into the current project's wyvrn_internal directory.
73
+ *
74
+ * @param {string} name - Package name to link.
75
+ * @param {string} sourcePath - Source directory path (absolute or relative).
76
+ * @param {string} rootDir - Project root directory.
77
+ */
78
+ function linkToProject(name, sourcePath, rootDir) {
79
+ const absoluteSource = path.resolve(sourcePath);
80
+
81
+ if (!fs.existsSync(absoluteSource)) {
82
+ log.error(`source path does not exist: ${absoluteSource}`);
83
+ process.exit(1);
84
+ }
85
+
86
+ const razerDir = path.join(rootDir, 'wyvrn_internal');
87
+ const linkPath = path.join(razerDir, name);
88
+
89
+ // Create the link
90
+ createLink(absoluteSource, linkPath);
91
+
92
+ // Write a .wyvrn-version file to indicate it's linked
93
+ const versionFile = path.join(linkPath, '.wyvrn-version');
94
+ fs.writeFileSync(versionFile, 'linked', 'utf8');
95
+
96
+ // Update the lock file to record the link
97
+ const lockPath = path.join(rootDir, 'wyvrn.lock');
98
+ let lockData = { packages: {} };
99
+ if (fs.existsSync(lockPath)) {
100
+ try {
101
+ lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
102
+ } catch {
103
+ // Use default if parsing fails
104
+ }
105
+ }
106
+ lockData.packages = lockData.packages || {};
107
+ lockData.packages[name] = `linked:${absoluteSource}`;
108
+ lockData.generatedAt = new Date().toISOString();
109
+ fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
110
+
111
+ log.info(`Linked: ${name} → ${absoluteSource}`);
112
+ }
113
+
114
+ /**
115
+ * Unlink a package from the current project.
116
+ *
117
+ * @param {string} name - Package name to unlink.
118
+ * @param {string} rootDir - Project root directory.
119
+ * @param {boolean} restore - Whether to re-download from registry.
120
+ * @param {object} argv - Original argv for re-download options.
121
+ */
122
+ async function unlinkFromProject(name, rootDir, restore, argv) {
123
+ const razerDir = path.join(rootDir, 'wyvrn_internal');
124
+ const linkPath = path.join(razerDir, name);
125
+
126
+ if (!fs.existsSync(linkPath)) {
127
+ log.error(`package "${name}" is not installed`);
128
+ process.exit(1);
129
+ }
130
+
131
+ if (!isLink(linkPath)) {
132
+ log.error(`package "${name}" is not a linked package`);
133
+ process.exit(1);
134
+ }
135
+
136
+ // Remove the symlink
137
+ removeLink(linkPath);
138
+ log.info(`Unlinked: ${name}`);
139
+
140
+ // Update the lock file
141
+ const lockPath = path.join(rootDir, 'wyvrn.lock');
142
+ if (fs.existsSync(lockPath)) {
143
+ try {
144
+ const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
145
+ if (lockData.packages && lockData.packages[name]) {
146
+ delete lockData.packages[name];
147
+ lockData.generatedAt = new Date().toISOString();
148
+ fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
149
+ }
150
+ } catch {
151
+ // Ignore lock file errors
152
+ }
153
+ }
154
+
155
+ // Re-download from registry if requested
156
+ if (restore) {
157
+ const manifestPath = path.resolve(argv.manifest);
158
+ const manifest = readManifest(manifestPath);
159
+
160
+ const rawDeps = manifest.dependencies || manifest.Dependencies || {};
161
+ const deps = Array.isArray(rawDeps)
162
+ ? Object.fromEntries(rawDeps.map((d) => [d.Name ?? d.name, d.Version ?? d.version]))
163
+ : rawDeps;
164
+
165
+ if (!deps[name]) {
166
+ log.warn(`"${name}" is not in manifest dependencies, cannot restore`);
167
+ return;
168
+ }
169
+
170
+ // Get package sources
171
+ let packageSources;
172
+ if (argv.source && argv.source.length > 0) {
173
+ packageSources = argv.source;
174
+ } else {
175
+ const config = readConfig();
176
+ packageSources = config.installSources.map((s) => s.url);
177
+ }
178
+
179
+ if (packageSources.length === 0) {
180
+ log.warn('no sources configured, cannot restore package');
181
+ return;
182
+ }
183
+
184
+ // Resolve just this one dependency
185
+ const resolvedDeps = await resolveDependencies(
186
+ { [name]: deps[name] },
187
+ packageSources,
188
+ argv.platform || 'win_x64',
189
+ wyvrnFetch,
190
+ new Map(),
191
+ );
192
+
193
+ // Download it
194
+ await downloadDependencies(
195
+ resolvedDeps,
196
+ packageSources,
197
+ argv.platform || 'win_x64',
198
+ razerDir,
199
+ wyvrnFetch,
200
+ argv.timeout || 300,
201
+ );
202
+
203
+ // Update lock file with restored version
204
+ if (fs.existsSync(lockPath)) {
205
+ try {
206
+ const lockData = JSON.parse(fs.readFileSync(lockPath, 'utf8'));
207
+ for (const [depName, version] of resolvedDeps) {
208
+ lockData.packages[depName] = version;
209
+ }
210
+ lockData.generatedAt = new Date().toISOString();
211
+ fs.writeFileSync(lockPath, JSON.stringify(lockData, null, 2) + '\n', 'utf8');
212
+ } catch {
213
+ // Ignore lock file errors
214
+ }
215
+ }
216
+ }
217
+ }
218
+
219
+ /**
220
+ * List all globally registered packages.
221
+ */
222
+ function listLinked() {
223
+ const config = readConfig();
224
+ const linked = config.linkedPackages || {};
225
+ const entries = Object.entries(linked);
226
+
227
+ if (entries.length === 0) {
228
+ log.info('No globally registered packages');
229
+ return;
230
+ }
231
+
232
+ log.info('Globally registered packages:');
233
+ for (const [name, rawEntry] of entries) {
234
+ const entry = normalizeLinkedEntry(rawEntry);
235
+ const effectivePath = getEffectivePath(entry);
236
+ const exists = fs.existsSync(effectivePath);
237
+ const status = exists ? '' : ' (path not found)';
238
+ const subdirInfo = entry.subdir ? ` [subdir: ${entry.subdir}]` : '';
239
+ console.log(` ${name} → ${effectivePath}${subdirInfo}${status}`);
240
+ }
241
+ }
242
+
243
+ /**
244
+ * Main link command handler.
245
+ *
246
+ * @param {object} argv - Parsed yargs arguments.
247
+ */
248
+ async function link(argv) {
249
+ const rootDir = path.resolve(argv.root);
250
+ const manifestPath = path.resolve(argv.manifest);
251
+
252
+ // wyvrnpm link --list
253
+ if (argv.list) {
254
+ listLinked();
255
+ return;
256
+ }
257
+
258
+ // wyvrnpm link (no args) - register current package globally
259
+ if (!argv.name) {
260
+ if (!fs.existsSync(manifestPath)) {
261
+ log.error(`no wyvrn.json found at ${manifestPath}`);
262
+ process.exit(1);
263
+ }
264
+ registerGlobal(manifestPath, argv.subdir);
265
+ return;
266
+ }
267
+
268
+ // wyvrnpm link <name> <path> - direct path link
269
+ if (argv.name && argv.path) {
270
+ let targetPath = argv.path;
271
+ if (argv.subdir) {
272
+ targetPath = path.join(argv.path, argv.subdir);
273
+ }
274
+ linkToProject(argv.name, targetPath, rootDir);
275
+ return;
276
+ }
277
+
278
+ // wyvrnpm link <name> - link from global registry
279
+ const config = readConfig();
280
+ const linked = config.linkedPackages || {};
281
+
282
+ if (!linked[argv.name]) {
283
+ log.error(
284
+ `"${argv.name}" is not registered globally\n` +
285
+ `Run "wyvrnpm link" in the package directory first, or use:\n` +
286
+ ` wyvrnpm link ${argv.name} <path>`,
287
+ );
288
+ process.exit(1);
289
+ }
290
+
291
+ const entry = normalizeLinkedEntry(linked[argv.name]);
292
+ // Command-line --subdir overrides the registered subdir
293
+ let effectivePath;
294
+ if (argv.subdir) {
295
+ effectivePath = path.join(entry.path, argv.subdir);
296
+ } else {
297
+ effectivePath = getEffectivePath(entry);
298
+ }
299
+
300
+ linkToProject(argv.name, effectivePath, rootDir);
301
+ }
302
+
303
+ /**
304
+ * Unlink command handler.
305
+ *
306
+ * @param {object} argv - Parsed yargs arguments.
307
+ */
308
+ async function unlink(argv) {
309
+ const rootDir = path.resolve(argv.root);
310
+ await unlinkFromProject(argv.name, rootDir, argv.restore, argv);
311
+ }
312
+
313
+ module.exports = {
314
+ link,
315
+ unlink,
316
+ listLinked,
317
+ registerGlobal,
318
+ linkToProject,
319
+ unlinkFromProject,
320
+ };