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