wyvrnpm 1.2.0 → 1.2.1

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/bin/wyvrn.js CHANGED
@@ -86,6 +86,12 @@ yargs
86
86
  .option('token', {
87
87
  type: 'string',
88
88
  description: 'Bearer token for HTTP server authentication (HTTP only)',
89
+ })
90
+ .option('force', {
91
+ alias: 'f',
92
+ type: 'boolean',
93
+ description: 'Overwrite an existing published version',
94
+ default: false,
89
95
  });
90
96
  },
91
97
  (argv) => publish(argv),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wyvrnpm",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "A simple, static-hosting-compatible C++ package manager",
5
5
  "keywords": [
6
6
  "c++",
@@ -72,7 +72,7 @@ function addFolderFiltered(zip, dir, base, ignoreRe) {
72
72
  }
73
73
 
74
74
  async function publish(argv) {
75
- let { source, profile, platform, path: publishPath, token, manifest: manifestArg } = argv;
75
+ let { source, profile, platform, path: publishPath, token, manifest: manifestArg, force } = argv;
76
76
 
77
77
  // Resolve source + auth: CLI > config entry by name > first config entry > raw URL
78
78
  if (source) {
@@ -137,6 +137,19 @@ async function publish(argv) {
137
137
  `[wyvrn] Publishing ${name}@${version} (${targetPlatform}) via ${provider.constructor.providerName} provider`,
138
138
  );
139
139
 
140
+ // Prevent overwriting an already-published version unless --force is passed
141
+ const alreadyExists = await provider.exists({ source, platform: targetPlatform, name, version, profile, token });
142
+ if (alreadyExists) {
143
+ if (force) {
144
+ console.warn(`[wyvrn] Warning: ${name}@${version} already exists — overwriting (--force)`);
145
+ } else {
146
+ console.error(
147
+ `[wyvrn] Error: ${name}@${version} already exists. Bump the version or use --force to overwrite.`,
148
+ );
149
+ process.exit(1);
150
+ }
151
+ }
152
+
140
153
  // Load .wyvrnignore patterns from the publish directory
141
154
  const ignoreFile = path.join(srcDir, '.wyvrnignore');
142
155
  const ignorePatterns = loadIgnorePatterns(ignoreFile);
@@ -36,6 +36,17 @@ class BaseProvider {
36
36
  throw new Error(`publish() is not implemented in ${this.constructor.name}`);
37
37
  }
38
38
 
39
+ /**
40
+ * Returns true if the given package version already exists at the destination.
41
+ * Providers should override this; the default assumes it does not exist.
42
+ *
43
+ * @param {{ source: string, platform: string, name: string, version: string, profile?: string, token?: string }} _options
44
+ * @returns {Promise<boolean>}
45
+ */
46
+ async exists(_options) {
47
+ return false;
48
+ }
49
+
39
50
  /** Human-readable provider name shown in log output. */
40
51
  static get providerName() {
41
52
  return 'BaseProvider';
@@ -40,6 +40,12 @@ class FileProvider extends BaseProvider {
40
40
  return path.resolve(source);
41
41
  }
42
42
 
43
+ async exists(options) {
44
+ const { source, platform, name, version } = options;
45
+ const destDir = path.join(this._resolvePath(source), platform, name, version);
46
+ return fs.existsSync(path.join(destDir, 'wyvrn.json'));
47
+ }
48
+
43
49
  async publish(files, options) {
44
50
  const { source, platform, name, version } = options;
45
51
 
@@ -14,6 +14,22 @@ class HttpProvider extends BaseProvider {
14
14
  return 'HTTP';
15
15
  }
16
16
 
17
+ async exists(options) {
18
+ const { source, platform, name, version } = options;
19
+ const base = source.replace(/\/$/, '');
20
+ const url = `${base}/${platform}/${name}/${version}/wyvrn.json`;
21
+ return new Promise((resolve, reject) => {
22
+ const parsed = new URL(url);
23
+ const lib = parsed.protocol === 'https:' ? https : http;
24
+ const req = lib.request(
25
+ { hostname: parsed.hostname, port: parsed.port || undefined, path: parsed.pathname, method: 'HEAD' },
26
+ (res) => { res.resume(); resolve(res.statusCode >= 200 && res.statusCode < 300); },
27
+ );
28
+ req.on('error', reject);
29
+ req.end();
30
+ });
31
+ }
32
+
17
33
  async publish(files, options) {
18
34
  const { source, platform, name, version, token } = options;
19
35
  const base = source.replace(/\/$/, '');
@@ -49,6 +49,33 @@ class S3Provider extends BaseProvider {
49
49
  };
50
50
  }
51
51
 
52
+ async exists(options) {
53
+ let S3Client, HeadObjectCommand, fromSSO;
54
+ try {
55
+ ({ S3Client, HeadObjectCommand } = require('@aws-sdk/client-s3'));
56
+ ({ fromSSO } = require('@aws-sdk/credential-providers'));
57
+ } catch {
58
+ throw new Error(
59
+ 'AWS SDK packages are required for S3 publishing.\n' +
60
+ 'Run: npm install @aws-sdk/client-s3 @aws-sdk/credential-providers',
61
+ );
62
+ }
63
+
64
+ const { source, platform, name, version, profile } = options;
65
+ const { bucket, prefix } = this._parseSource(source);
66
+ const key = [prefix, platform, name, version, 'wyvrn.json'].filter(Boolean).join('/');
67
+
68
+ const clientConfig = profile ? { credentials: fromSSO({ profile }) } : {};
69
+ const client = new S3Client(clientConfig);
70
+ try {
71
+ await client.send(new HeadObjectCommand({ Bucket: bucket, Key: key }));
72
+ return true;
73
+ } catch (err) {
74
+ if (err.name === 'NotFound' || err.$metadata?.httpStatusCode === 404) return false;
75
+ throw err;
76
+ }
77
+ }
78
+
52
79
  async publish(files, options) {
53
80
  // Lazy-load AWS SDK so the tool works without it when only HTTP is used.
54
81
  let S3Client, PutObjectCommand, fromSSO;