@neon-rs/cli 0.0.162 → 0.0.165

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 (2) hide show
  1. package/index.js +399 -113
  2. package/package.json +8 -8
package/index.js CHANGED
@@ -10245,7 +10245,7 @@ function wrappy (fn, cb) {
10245
10245
 
10246
10246
  /***/ }),
10247
10247
 
10248
- /***/ 2294:
10248
+ /***/ 3236:
10249
10249
  /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
10250
10250
 
10251
10251
 
@@ -12027,56 +12027,390 @@ var temp = __nccwpck_require__(591);
12027
12027
  const rust_namespaceObject = JSON.parse('{"aarch64-apple-darwin":"darwin-arm64","x86_64-apple-darwin":"darwin-x64","aarch64-apple-ios":"ios-arm64","x86_64-apple-ios":"ios-x64","aarch64-linux-android":"android-arm64","armv7-linux-androideabi":"android-arm-eabi","i686-linux-android":"android-ia32","x86_64-linux-android":"android-x64","aarch64-pc-windows-msvc":"win32-arm64-msvc","i686-pc-windows-gnu":"win32-ia32-gnu","i686-pc-windows-msvc":"win32-ia32-msvc","x86_64-pc-windows-gnu":"win32-x64-gnu","x86_64-pc-windows-msvc":"win32-x64-msvc","aarch64-unknown-linux-gnu":"linux-arm64-gnu","aarch64-unknown-linux-musl":"linux-arm64-musl","arm-unknown-linux-gnueabihf":"linux-arm-gnueabihf","arm-unknown-linux-musleabihf":"linux-arm-musleabihf","armv7-unknown-linux-gnueabihf":"linux-arm-gnueabihf","armv7-unknown-linux-musleabihf":"linux-arm-musleabihf","i686-unknown-linux-gnu":"linux-ia32-gnu","i686-unknown-linux-musl":"linux-ia32-musl","mips-unknown-linux-gnu":"linux-mips-gnu","mips-unknown-linux-musl":"linux-mips-musl","mips64-unknown-linux-gnuabi64":"linux-mips64-gnuabi64","mips64-unknown-linux-muslabi64":"linux-mips64-muslabi64","mips64el-unknown-linux-gnuabi64":"linux-mips64el-gnuabi64","mips64el-unknown-linux-muslabi64":"linux-mips64el-muslabi64","mipsel-unknown-linux-gnu":"linux-mipsel-gnu","mipsel-unknown-linux-musl":"linux-mipsel-musl","powerpc-unknown-linux-gnu":"linux-powerpc-gnu","powerpc64-unknown-linux-gnu":"linux-powerpc64-gnu","powerpc64le-unknown-linux-gnu":"linux-powerpc64le-gnu","riscv64gc-unknown-linux-gnu":"linux-riscv64gc-gnu","s390x-unknown-linux-gnu":"linux-s390x-gnu","sparc64-unknown-linux-gnu":"linux-sparc64-gnu","x86_64-unknown-linux-gnu":"linux-x64-gnu","x86_64-unknown-linux-gnux32":"linux-x64-gnux32","x86_64-unknown-linux-musl":"linux-x64-musl","i686-unknown-freebsd":"freebsd-ia32","x86_64-unknown-freebsd":"freebsd-x64"}');
12028
12028
  ;// CONCATENATED MODULE: ./data/node.json
12029
12029
  const node_namespaceObject = JSON.parse('{"darwin-arm64":{"platform":"darwin","arch":"arm64","abi":null,"llvm":["aarch64-apple-darwin"]},"darwin-x64":{"platform":"darwin","arch":"x64","abi":null,"llvm":["x86_64-apple-darwin"]},"ios-arm64":{"platform":"ios","arch":"arm64","abi":null,"llvm":["aarch64-apple-ios"]},"ios-x64":{"platform":"ios","arch":"x64","abi":null,"llvm":["x86_64-apple-ios"]},"android-arm64":{"platform":"android","arch":"arm64","abi":null,"llvm":["aarch64-linux-android"]},"android-arm-eabi":{"platform":"android","arch":"arm","abi":"eabi","llvm":["armv7-linux-androideabi"]},"android-ia32":{"platform":"android","arch":"ia32","abi":null,"llvm":["i686-linux-android"]},"android-x64":{"platform":"android","arch":"x64","abi":null,"llvm":["x86_64-linux-android"]},"win32-arm64-msvc":{"platform":"win32","arch":"arm64","abi":"msvc","llvm":["aarch64-pc-windows-msvc"]},"win32-ia32-gnu":{"platform":"win32","arch":"ia32","abi":"gnu","llvm":["i686-pc-windows-gnu"]},"win32-ia32-msvc":{"platform":"win32","arch":"ia32","abi":"msvc","llvm":["i686-pc-windows-msvc"]},"win32-x64-gnu":{"platform":"win32","arch":"x64","abi":"gnu","llvm":["x86_64-pc-windows-gnu"]},"win32-x64-msvc":{"platform":"win32","arch":"x64","abi":"msvc","llvm":["x86_64-pc-windows-msvc"]},"linux-arm64-gnu":{"platform":"linux","arch":"arm64","abi":"gnu","llvm":["aarch64-unknown-linux-gnu"]},"linux-arm64-musl":{"platform":"linux","arch":"arm64","abi":"musl","llvm":["aarch64-unknown-linux-musl"]},"linux-arm-gnueabihf":{"platform":"linux","arch":"arm","abi":"gnueabihf","llvm":["arm-unknown-linux-gnueabihf","armv7-unknown-linux-gnueabihf"]},"linux-arm-musleabihf":{"platform":"linux","arch":"arm","abi":"musleabihf","llvm":["arm-unknown-linux-musleabihf","armv7-unknown-linux-musleabihf"]},"linux-ia32-gnu":{"platform":"linux","arch":"ia32","abi":"gnu","llvm":["i686-unknown-linux-gnu"]},"linux-ia32-musl":{"platform":"linux","arch":"ia32","abi":"musl","llvm":["i686-unknown-linux-musl"]},"linux-mips-gnu":{"platform":"linux","arch":"mips","abi":"gnu","llvm":["mips-unknown-linux-gnu"]},"linux-mips-musl":{"platform":"linux","arch":"mips","abi":"musl","llvm":["mips-unknown-linux-musl"]},"linux-mips64-gnuabi64":{"platform":"linux","arch":"mips64","abi":"gnuabi64","llvm":["mips64-unknown-linux-gnuabi64"]},"linux-mips64-muslabi64":{"platform":"linux","arch":"mips64","abi":"muslabi64","llvm":["mips64-unknown-linux-muslabi64"]},"linux-mips64el-gnuabi64":{"platform":"linux","arch":"mips64el","abi":"gnuabi64","llvm":["mips64el-unknown-linux-gnuabi64"]},"linux-mips64el-muslabi64":{"platform":"linux","arch":"mips64el","abi":"muslabi64","llvm":["mips64el-unknown-linux-muslabi64"]},"linux-mipsel-gnu":{"platform":"linux","arch":"mipsel","abi":"gnu","llvm":["mipsel-unknown-linux-gnu"]},"linux-mipsel-musl":{"platform":"linux","arch":"mipsel","abi":"musl","llvm":["mipsel-unknown-linux-musl"]},"linux-powerpc-gnu":{"platform":"linux","arch":"powerpc","abi":"gnu","llvm":["powerpc-unknown-linux-gnu"]},"linux-powerpc64-gnu":{"platform":"linux","arch":"powerpc64","abi":"gnu","llvm":["powerpc64-unknown-linux-gnu"]},"linux-powerpc64le-gnu":{"platform":"linux","arch":"powerpc64le","abi":"gnu","llvm":["powerpc64le-unknown-linux-gnu"]},"linux-riscv64gc-gnu":{"platform":"linux","arch":"riscv64gc","abi":"gnu","llvm":["riscv64gc-unknown-linux-gnu"]},"linux-s390x-gnu":{"platform":"linux","arch":"s390x","abi":"gnu","llvm":["s390x-unknown-linux-gnu"]},"linux-sparc64-gnu":{"platform":"linux","arch":"sparc64","abi":"gnu","llvm":["sparc64-unknown-linux-gnu"]},"linux-x64-gnu":{"platform":"linux","arch":"x64","abi":"gnu","llvm":["x86_64-unknown-linux-gnu"]},"linux-x64-gnux32":{"platform":"linux","arch":"x64","abi":"gnux32","llvm":["x86_64-unknown-linux-gnux32"]},"linux-x64-musl":{"platform":"linux","arch":"x64","abi":"musl","llvm":["x86_64-unknown-linux-musl"]},"freebsd-ia32":{"platform":"freebsd","arch":"ia32","abi":null,"llvm":["i686-unknown-freebsd"]},"freebsd-x64":{"platform":"freebsd","arch":"x64","abi":null,"llvm":["x86_64-unknown-freebsd"]}}');
12030
- ;// CONCATENATED MODULE: ./src/commands/pack-build.ts
12031
-
12032
-
12033
-
12034
-
12030
+ ;// CONCATENATED MODULE: ./src/target.ts
12035
12031
 
12036
- const mktemp = temp.track().mkdir;
12037
- const pack_build_OPTIONS = [
12038
- { name: 'file', alias: 'f', type: String, defaultValue: 'index.node' },
12039
- { name: 'target', alias: 't', type: String, defaultValue: null },
12040
- { name: 'in-dir', alias: 'i', type: String, defaultValue: null },
12041
- { name: 'out-dir', alias: 'o', type: String, defaultValue: null },
12042
- { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false },
12043
- ];
12044
12032
 
12045
12033
  function isRustTarget(x) {
12046
- return (x in rust_namespaceObject);
12034
+ return (typeof x === 'string') && (x in rust_namespaceObject);
12035
+ }
12036
+ function assertIsRustTarget(x) {
12037
+ if (!isRustTarget(x)) {
12038
+ throw new RangeError(`invalid Rust target: ${x}`);
12039
+ }
12047
12040
  }
12048
-
12049
12041
  function isNodeTarget(x) {
12050
12042
  return (typeof x === 'string') && (x in node_namespaceObject);
12051
12043
  }
12052
- function lookup(target) {
12044
+ function assertIsNodeTarget(x) {
12045
+ if (!isNodeTarget(x)) {
12046
+ throw new RangeError(`invalid Node target: ${x}`);
12047
+ }
12048
+ }
12049
+ function getTargetDescriptor(target) {
12053
12050
  const node = rust_namespaceObject[target];
12054
12051
  if (!isNodeTarget(node)) {
12055
12052
  throw new Error(`Rust target ${target} not supported`);
12056
12053
  }
12057
- return { node, ...node_namespaceObject[node] };
12054
+ const nodeDescriptor = node_namespaceObject[node];
12055
+ const badTarget = nodeDescriptor.llvm.find(t => !isRustTarget(t));
12056
+ if (badTarget) {
12057
+ throw new Error(`Rust target ${badTarget} not supported`);
12058
+ }
12059
+ return {
12060
+ node,
12061
+ platform: nodeDescriptor.platform,
12062
+ arch: nodeDescriptor.arch,
12063
+ abi: nodeDescriptor.abi,
12064
+ llvm: nodeDescriptor.llvm
12065
+ };
12066
+ }
12067
+
12068
+ ;// CONCATENATED MODULE: ./src/manifest.ts
12069
+
12070
+
12071
+
12072
+ function assertIsObject(json, path) {
12073
+ if (!json || typeof json !== 'object') {
12074
+ throw new TypeError(`expected "${path}" property to be an object, found ${json}`);
12075
+ }
12076
+ }
12077
+ // Idea thanks to https://www.lucaspaganini.com/academy/assertion-functions-typescript-narrowing-5
12078
+ function assertHasProps(keys, json, path) {
12079
+ assertIsObject(json, path);
12080
+ for (const key of keys) {
12081
+ if (!(key in json)) {
12082
+ throw new TypeError(`property "${path}.${key}" not found`);
12083
+ }
12084
+ }
12085
+ }
12086
+ function assertIsBinaryCfg(json) {
12087
+ assertHasProps(['type', 'rust', 'node', 'platform', 'arch', 'abi'], json, "neon");
12088
+ if (json.type !== 'binary') {
12089
+ throw new TypeError(`expected "neon.type" property to be "binary", found ${json.type}`);
12090
+ }
12091
+ if (typeof json.rust !== 'string' || !isRustTarget(json.rust)) {
12092
+ throw new TypeError(`expected "neon.rust" to be a valid Rust target, found ${json.rust}`);
12093
+ }
12094
+ if (typeof json.node !== 'string' || !isNodeTarget(json.node)) {
12095
+ throw new TypeError(`expected "neon.node" to be a valid Node target, found ${json.node}`);
12096
+ }
12097
+ if (typeof json.platform !== 'string') {
12098
+ throw new TypeError(`expected "neon.platform" to be a string, found ${json.platform}`);
12099
+ }
12100
+ if (typeof json.arch !== 'string') {
12101
+ throw new TypeError(`expected "neon.arch" to be a string, found ${json.arch}`);
12102
+ }
12103
+ if (json.abi !== null && typeof json.abi !== 'string') {
12104
+ throw new TypeError(`expected "neon.abi" to be a string or null, found ${json.abi}`);
12105
+ }
12058
12106
  }
12059
- function extractPackageNameV1(targets, target) {
12060
- return targets[target];
12107
+ function assertIsTargetMap(json, path) {
12108
+ assertIsObject(json, path);
12109
+ for (const key in json) {
12110
+ const value = json[key];
12111
+ if (!isNodeTarget(key)) {
12112
+ throw new TypeError(`target table key ${key} is not a valid Node target`);
12113
+ }
12114
+ if (typeof value !== 'string' || !isRustTarget(value)) {
12115
+ throw new TypeError(`target table value ${value} is not a valid Rust target`);
12116
+ }
12117
+ }
12118
+ }
12119
+ function assertIsBinaryV1(json) {
12120
+ assertHasProps(['binary'], json, "neon");
12121
+ const binary = json.binary;
12122
+ if (!binary || typeof binary !== 'object') {
12123
+ throw new TypeError(`expected "neon.binary" to be an object, found ${binary}`);
12124
+ }
12125
+ assertHasProps(['rust', 'node', 'platform', 'arch', 'abi'], binary, "neon.binary");
12126
+ if (typeof binary.rust !== 'string' || !isRustTarget(binary.rust)) {
12127
+ throw new TypeError(`expected "neon.binary.rust" to be a valid Rust target, found ${binary.rust}`);
12128
+ }
12129
+ if (!isNodeTarget(binary.node)) {
12130
+ throw new TypeError(`expected "neon.binary.node" to be a valid Node target, found ${binary.node}`);
12131
+ }
12132
+ if (typeof binary.platform !== 'string') {
12133
+ throw new TypeError(`expected "neon.binary.platform" to be a string, found ${binary.platform}`);
12134
+ }
12135
+ if (typeof binary.arch !== 'string') {
12136
+ throw new TypeError(`expected "neon.binary.arch" to be a string, found ${binary.arch}`);
12137
+ }
12138
+ if (binary.abi !== null && typeof binary.abi !== 'string') {
12139
+ throw new TypeError(`expected "neon.binary.abi" to be a string or null, found ${binary.abi}`);
12140
+ }
12061
12141
  }
12062
- function extractPackageNameV2(manifest, target) {
12063
- for (const key in manifest.neon.targets) {
12064
- const value = manifest.neon.targets[key];
12065
- if (value === target) {
12066
- return `${manifest.neon.org}/${key}`;
12142
+ function assertIsSourceV1(json) {
12143
+ assertIsObject(json, "neon");
12144
+ for (const key in json) {
12145
+ const value = json[key];
12146
+ if (!isRustTarget(key)) {
12147
+ throw new TypeError(`target table key ${key} is not a valid Rust target`);
12148
+ }
12149
+ if (typeof value !== 'string') {
12150
+ throw new TypeError(`target table value ${value} is not a string`);
12067
12151
  }
12068
12152
  }
12069
- return undefined;
12070
12153
  }
12071
- function extractPackageName(manifest, target) {
12072
- if (manifest.neon.org) {
12073
- return extractPackageNameV2(manifest, target);
12154
+ function assertIsSourceCfg(json) {
12155
+ assertHasProps(['type', 'org', 'targets'], json, "neon");
12156
+ if (json.type !== 'source') {
12157
+ throw new TypeError(`expected "neon.type" property to be "source", found ${json.type}`);
12158
+ }
12159
+ if (typeof json.org !== 'string') {
12160
+ throw new TypeError(`expected "neon.org" to be a string, found ${json.org}`);
12074
12161
  }
12075
- return extractPackageNameV1(manifest.neon.targets, target);
12162
+ assertIsTargetMap(json.targets, "neon.targets");
12076
12163
  }
12164
+ function assertIsPreamble(json) {
12165
+ if (!json || typeof json !== 'object') {
12166
+ throw new TypeError(`expected binary Neon package manifest, found ${json}`);
12167
+ }
12168
+ if (!('version' in json) || typeof json.version !== 'string') {
12169
+ throw new TypeError('valid "version" string not found in Neon package manifest');
12170
+ }
12171
+ if (!('name' in json) || typeof json.name !== 'string') {
12172
+ throw new TypeError('valid "name" string not found in Neon package manifest');
12173
+ }
12174
+ }
12175
+ class AbstractManifest {
12176
+ _json;
12177
+ _upgraded;
12178
+ constructor(json) {
12179
+ assertIsPreamble(json);
12180
+ this._json = json;
12181
+ this._upgraded = false;
12182
+ }
12183
+ get name() { return this._json.name; }
12184
+ set name(value) { this._json.name = value; }
12185
+ get version() { return this._json.version; }
12186
+ set version(value) { this._json.version = value; }
12187
+ get description() { return this._json.description ?? ""; }
12188
+ get upgraded() { return this._upgraded; }
12189
+ async save(dir) {
12190
+ dir = dir ?? process.cwd();
12191
+ await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(dir, "package.json"), JSON.stringify(this._json, null, 2), { encoding: 'utf8' });
12192
+ }
12193
+ stringify() {
12194
+ return JSON.stringify(this._json);
12195
+ }
12196
+ }
12197
+ function assertHasCfg(json) {
12198
+ if (!('neon' in json)) {
12199
+ throw new TypeError('property "neon" not found');
12200
+ }
12201
+ assertIsObject(json.neon, "neon");
12202
+ }
12203
+ function assertHasBinaryCfg(json) {
12204
+ assertHasCfg(json);
12205
+ assertIsBinaryCfg(json.neon);
12206
+ }
12207
+ function assertHasSourceCfg(json) {
12208
+ assertHasCfg(json);
12209
+ assertIsSourceCfg(json.neon);
12210
+ }
12211
+ async function readManifest(dir) {
12212
+ dir = dir ?? process.cwd();
12213
+ return JSON.parse(await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(dir, "package.json"), { encoding: 'utf8' }));
12214
+ }
12215
+ class BinaryManifest extends AbstractManifest {
12216
+ _binaryJSON;
12217
+ constructor(json) {
12218
+ super(json);
12219
+ this._upgraded = normalizeBinaryCfg(this._json);
12220
+ assertHasBinaryCfg(this._json);
12221
+ this._binaryJSON = this._json;
12222
+ }
12223
+ cfg() {
12224
+ return this._binaryJSON.neon;
12225
+ }
12226
+ static async load(dir) {
12227
+ return new BinaryManifest(await readManifest(dir));
12228
+ }
12229
+ }
12230
+ function normalizeBinaryCfg(json) {
12231
+ assertHasCfg(json);
12232
+ // V2 format: {
12233
+ // neon: {
12234
+ // type: 'binary',
12235
+ // rust: RustTarget,
12236
+ // node: NodeTarget,
12237
+ // platform: string,
12238
+ // arch: string,
12239
+ // abi: string | null
12240
+ // }
12241
+ // }
12242
+ if ('type' in json.neon) {
12243
+ return false;
12244
+ }
12245
+ // V1 format: {
12246
+ // neon: {
12247
+ // binary: {
12248
+ // rust: RustTarget,
12249
+ // node: NodeTarget,
12250
+ // platform: string,
12251
+ // arch: string,
12252
+ // abi: string | null
12253
+ // }
12254
+ // }
12255
+ // }
12256
+ json.neon = upgradeBinaryV1(json.neon);
12257
+ return true;
12258
+ }
12259
+ function normalizeSourceCfg(json) {
12260
+ assertHasCfg(json);
12261
+ // V3 format: {
12262
+ // neon: {
12263
+ // type: 'source',
12264
+ // org: string,
12265
+ // targets: { Node => Rust }
12266
+ // }
12267
+ // }
12268
+ if ('type' in json.neon) {
12269
+ return false;
12270
+ }
12271
+ // V2 format: {
12272
+ // neon: {
12273
+ // org: string,
12274
+ // targets: { Node => Rust }
12275
+ // }
12276
+ // }
12277
+ if ('org' in json.neon) {
12278
+ const targets = json.neon['targets'];
12279
+ assertIsTargetMap(targets, "neon.targets");
12280
+ json.neon = {
12281
+ type: 'source',
12282
+ org: json.neon.org,
12283
+ targets
12284
+ };
12285
+ return true;
12286
+ }
12287
+ // V1 format: {
12288
+ // neon: {
12289
+ // targets: { Rust => fully-qualified package name }
12290
+ // }
12291
+ // }
12292
+ const targets = json.neon['targets'];
12293
+ assertIsSourceV1(targets);
12294
+ json.neon = upgradeSourceV1(targets);
12295
+ return true;
12296
+ }
12297
+ class SourceManifest extends AbstractManifest {
12298
+ _sourceJSON;
12299
+ constructor(json) {
12300
+ super(json);
12301
+ this._upgraded = normalizeSourceCfg(this._json);
12302
+ assertHasSourceCfg(this._json);
12303
+ this._sourceJSON = this._json;
12304
+ }
12305
+ static async load(dir) {
12306
+ return new SourceManifest(await readManifest(dir));
12307
+ }
12308
+ cfg() {
12309
+ return this._sourceJSON.neon;
12310
+ }
12311
+ packageNames() {
12312
+ const cfg = this.cfg();
12313
+ return Object.keys(cfg.targets).map(key => `${cfg.org}/${key}`);
12314
+ }
12315
+ packageFor(target) {
12316
+ const cfg = this.cfg();
12317
+ for (const key in cfg.targets) {
12318
+ const value = cfg.targets[key];
12319
+ if (value === target) {
12320
+ return `${cfg.org}/${key}`;
12321
+ }
12322
+ }
12323
+ return undefined;
12324
+ }
12325
+ manifestFor(target) {
12326
+ const targetInfo = getTargetDescriptor(target);
12327
+ const name = this.packageFor(target);
12328
+ if (!name) {
12329
+ throw new Error(`Rust target ${target} not found in "neon.targets" table.`);
12330
+ }
12331
+ const json = {
12332
+ name,
12333
+ description: `Prebuilt binary package for \`${this.name}\` on \`${targetInfo.node}\`.`,
12334
+ version: this.version,
12335
+ os: [targetInfo.platform],
12336
+ cpu: [targetInfo.arch],
12337
+ main: "index.node",
12338
+ files: ["index.node"],
12339
+ neon: {
12340
+ type: "binary",
12341
+ rust: target,
12342
+ node: targetInfo.node,
12343
+ platform: targetInfo.platform,
12344
+ arch: targetInfo.arch,
12345
+ abi: targetInfo.abi
12346
+ }
12347
+ };
12348
+ const OPTIONAL_KEYS = [
12349
+ 'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
12350
+ ];
12351
+ for (const key of OPTIONAL_KEYS) {
12352
+ if (key in this._json) {
12353
+ json[key] = this._json[key];
12354
+ }
12355
+ }
12356
+ return new BinaryManifest(json);
12357
+ }
12358
+ }
12359
+ function upgradeSourceV1(object) {
12360
+ function splitSwap([key, value]) {
12361
+ if (!/^@.*\//.test(value)) {
12362
+ throw new TypeError(`expected namespaced npm package name, found ${value}`);
12363
+ }
12364
+ const pkg = value.split('/')[1];
12365
+ assertIsNodeTarget(pkg);
12366
+ assertIsRustTarget(key);
12367
+ return [pkg, key];
12368
+ }
12369
+ const entries = Object.entries(object).map(splitSwap);
12370
+ const orgs = new Set(Object.values(object).map(v => v.split('/')[0]));
12371
+ if (orgs.size === 0) {
12372
+ throw new Error("empty target table");
12373
+ }
12374
+ else if (orgs.size > 1) {
12375
+ throw new Error(`multiple npm orgs found: ${orgs}`);
12376
+ }
12377
+ return {
12378
+ type: 'source',
12379
+ org: [...orgs][0],
12380
+ targets: Object.fromEntries(entries)
12381
+ };
12382
+ }
12383
+ function upgradeBinaryV1(json) {
12384
+ assertIsBinaryV1(json);
12385
+ return {
12386
+ type: 'binary',
12387
+ rust: json.binary.rust,
12388
+ node: json.binary.node,
12389
+ platform: json.binary.platform,
12390
+ arch: json.binary.arch,
12391
+ abi: json.binary.abi
12392
+ };
12393
+ }
12394
+
12395
+ ;// CONCATENATED MODULE: ./src/commands/pack-build.ts
12396
+
12397
+
12398
+
12399
+
12400
+
12401
+
12402
+
12403
+ const mktemp = temp.track().mkdir;
12404
+ const pack_build_OPTIONS = [
12405
+ { name: 'file', alias: 'f', type: String, defaultValue: 'index.node' },
12406
+ { name: 'target', alias: 't', type: String, defaultValue: null },
12407
+ { name: 'in-dir', alias: 'i', type: String, defaultValue: null },
12408
+ { name: 'out-dir', alias: 'o', type: String, defaultValue: null },
12409
+ { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false },
12410
+ ];
12077
12411
  class PackBuild {
12078
12412
  static summary() { return 'Create an npm tarball from a prebuild.'; }
12079
- static syntax() { return 'neon pack-build [-f <addon>] [-t <target>] [-d <dir>]'; }
12413
+ static syntax() { return 'neon pack-build [-f <addon>] [-t <target>] [-i <dir>] [-o <dir>] [-v]'; }
12080
12414
  static options() {
12081
12415
  return [
12082
12416
  { name: '-f, --file <addon>', summary: 'Prebuilt .node file to pack. (Default: index.node)' },
@@ -12126,85 +12460,44 @@ class PackBuild {
12126
12460
  this.log(`currentTarget result: "${target}"`);
12127
12461
  return target;
12128
12462
  }
12129
- async createTempDir(manifest) {
12130
- const version = manifest.version;
12131
- const targets = manifest.neon.targets;
12463
+ async createTempDir(sourceManifest) {
12132
12464
  const target = this._target || await this.currentTarget();
12133
12465
  if (!isRustTarget(target)) {
12134
12466
  throw new Error(`Rust target ${target} not supported.`);
12135
12467
  }
12136
- const name = extractPackageName(manifest, target);
12137
- if (!name) {
12138
- throw new Error(`Rust target ${target} not found in package.json.`);
12139
- }
12140
- const targetInfo = lookup(target);
12141
- const description = `Prebuilt binary package for \`${manifest.name}\` on \`${targetInfo.node}\`.`;
12142
- let prebuildManifest = {
12143
- name,
12144
- description,
12145
- version,
12146
- os: [targetInfo.platform],
12147
- cpu: [targetInfo.arch],
12148
- main: "index.node",
12149
- files: ["index.node"],
12150
- neon: {
12151
- binary: {
12152
- rust: target,
12153
- node: targetInfo.node,
12154
- platform: targetInfo.platform,
12155
- arch: targetInfo.arch,
12156
- abi: targetInfo.abi
12157
- }
12158
- }
12159
- };
12160
- const OPTIONAL_KEYS = [
12161
- 'author', 'repository', 'keywords', 'bugs', 'homepage', 'license', 'engines'
12162
- ];
12163
- for (const key of OPTIONAL_KEYS) {
12164
- if (manifest[key]) {
12165
- prebuildManifest[key] = manifest[key];
12166
- }
12167
- }
12168
- this.log(`prebuild manifest: ${JSON.stringify(prebuildManifest)}`);
12468
+ const binaryManifest = sourceManifest.manifestFor(target);
12469
+ this.log(`prebuild manifest: ${binaryManifest.stringify()}`);
12169
12470
  this.log("creating temp dir");
12170
12471
  const tmpdir = await mktemp('neon-');
12171
12472
  this.log(`created temp dir ${tmpdir}`);
12172
12473
  this.log(`creating ${tmpdir}/package.json`);
12173
- await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "package.json"), JSON.stringify(prebuildManifest, null, 2));
12474
+ await binaryManifest.save(tmpdir);
12174
12475
  this.log(`copying ${this._addon} to ${tmpdir}/index.node`);
12175
12476
  await promises_namespaceObject.copyFile(this._addon, external_node_path_namespaceObject.join(tmpdir, "index.node"));
12176
12477
  this.log(`creating ${tmpdir}/README.md`);
12177
- await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "README.md"), `# \`${name}\`\n\n${description}\n`);
12478
+ await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "README.md"), `# \`${binaryManifest.name}\`\n\n${binaryManifest.description}\n`);
12178
12479
  return tmpdir;
12179
12480
  }
12180
- async prepareInDir(manifest) {
12481
+ async prepareInDir(sourceManifest) {
12181
12482
  if (!this._inDir) {
12182
- return await this.createTempDir(manifest);
12483
+ return await this.createTempDir(sourceManifest);
12183
12484
  }
12184
- const version = manifest.version;
12185
- const binaryManifest = JSON.parse(await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(this._inDir, 'package.json'), { encoding: 'utf8' }));
12186
- const binaryTarget = binaryManifest.neon.binary.rust || null;
12187
- if (binaryTarget && this._target && (binaryTarget !== this._target)) {
12188
- throw new Error(`Specified target ${this._target} does not match target ${binaryTarget} in ${this._inDir}`);
12485
+ const version = sourceManifest.version;
12486
+ const binaryManifest = await BinaryManifest.load(this._inDir);
12487
+ const cfg = binaryManifest.cfg();
12488
+ if (this._target && (cfg.rust !== this._target)) {
12489
+ throw new Error(`Specified target ${this._target} does not match target ${cfg.rust} in ${this._inDir}`);
12189
12490
  }
12190
- const target = binaryTarget || this._target || await this.currentTarget();
12191
- if (!isRustTarget(target)) {
12192
- throw new Error(`Rust target ${target} not supported.`);
12193
- }
12194
- const descriptor = lookup(target);
12195
- binaryManifest.neon = binaryManifest.neon || {};
12196
- binaryManifest.neon.binary = {
12197
- rust: target,
12198
- node: descriptor.node,
12199
- platform: descriptor.platform,
12200
- arch: descriptor.arch,
12201
- abi: descriptor.abi
12202
- };
12491
+ const targetInfo = getTargetDescriptor(cfg.rust);
12492
+ cfg.node = targetInfo.node;
12493
+ cfg.platform = targetInfo.platform;
12494
+ cfg.arch = targetInfo.arch;
12495
+ cfg.abi = targetInfo.abi;
12203
12496
  // FIXME: make it possible to disable this
12204
12497
  binaryManifest.version = version;
12205
- this.log(`binary manifest: ${JSON.stringify(binaryManifest)}`);
12498
+ this.log(`binary manifest: ${binaryManifest.stringify()}`);
12206
12499
  this.log(`creating ${this._inDir}/package.json`);
12207
- await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(this._inDir, 'package.json'), JSON.stringify(binaryManifest, null, 2), { encoding: 'utf8' });
12500
+ await binaryManifest.save(this._inDir);
12208
12501
  // FIXME: make this path configurable
12209
12502
  this.log(`copying ${this._addon} to ${this._inDir}/index.node`);
12210
12503
  await promises_namespaceObject.copyFile(this._addon, external_node_path_namespaceObject.join(this._inDir, "index.node"));
@@ -12214,9 +12507,9 @@ class PackBuild {
12214
12507
  this.log(`creating directory ${this._outDir}`);
12215
12508
  await promises_namespaceObject.mkdir(this._outDir, { recursive: true });
12216
12509
  this.log(`reading package.json`);
12217
- const manifest = JSON.parse(await promises_namespaceObject.readFile('package.json', { encoding: 'utf8' }));
12218
- this.log(`manifest: ${JSON.stringify(manifest)}`);
12219
- const inDir = await this.prepareInDir(manifest);
12510
+ const sourceManifest = await SourceManifest.load();
12511
+ this.log(`manifest: ${sourceManifest.stringify()}`);
12512
+ const inDir = await this.prepareInDir(sourceManifest);
12220
12513
  this.log(`npm pack --json`);
12221
12514
  const result = await execa("npm", ["pack", "--json"], {
12222
12515
  shell: true,
@@ -12245,22 +12538,11 @@ class PackBuild {
12245
12538
 
12246
12539
 
12247
12540
 
12541
+
12248
12542
  const install_builds_OPTIONS = [
12249
12543
  { name: 'bundle', alias: 'b', type: String, defaultValue: null },
12250
12544
  { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false }
12251
12545
  ];
12252
- function lookupBinaryPackagesV1(targets) {
12253
- return Object.values(targets);
12254
- }
12255
- function lookupBinaryPackagesV2(org, targets) {
12256
- return Object.keys(targets).map(key => `${org}/${key}`);
12257
- }
12258
- function lookupBinaryPackages(manifest) {
12259
- if (manifest.neon.org) {
12260
- return lookupBinaryPackagesV2(manifest.neon.org, manifest.neon.targets);
12261
- }
12262
- return lookupBinaryPackagesV1(manifest.neon.targets);
12263
- }
12264
12546
  class InstallBuilds {
12265
12547
  static summary() { return 'Install dependencies on prebuilds in package.json.'; }
12266
12548
  static syntax() { return 'neon install-builds [-b <file>]'; }
@@ -12293,12 +12575,16 @@ class InstallBuilds {
12293
12575
  }
12294
12576
  async run() {
12295
12577
  this.log(`reading package.json (CWD=${process.cwd()})`);
12296
- const manifest = JSON.parse(await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(process.cwd(), 'package.json'), { encoding: 'utf8' }));
12297
- const version = manifest.version;
12298
- this.log(`package.json before: ${JSON.stringify(manifest)}`);
12578
+ const sourceManifest = await SourceManifest.load();
12579
+ const version = sourceManifest.version;
12580
+ this.log(`package.json before: ${sourceManifest.stringify()}`);
12299
12581
  this.log(`determined version: ${version}`);
12300
- const packages = lookupBinaryPackages(manifest);
12582
+ const packages = sourceManifest.packageNames();
12301
12583
  const specs = packages.map(name => `${name}@${version}`);
12584
+ if (sourceManifest.upgraded) {
12585
+ this.log(`upgrading manifest format`);
12586
+ await sourceManifest.save();
12587
+ }
12302
12588
  this.log(`npm install --save-exact -O ${specs.join(' ')}`);
12303
12589
  const result = await execa('npm', ['install', '--save-exact', '-O', ...specs], { shell: true });
12304
12590
  if (result.exitCode !== 0) {
@@ -12412,7 +12698,7 @@ __nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __we
12412
12698
  /* harmony import */ var command_line_commands__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(5046);
12413
12699
  /* harmony import */ var command_line_commands__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(command_line_commands__WEBPACK_IMPORTED_MODULE_0__);
12414
12700
  /* harmony import */ var _print_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(9050);
12415
- /* harmony import */ var _command_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(2294);
12701
+ /* harmony import */ var _command_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(3236);
12416
12702
  /* harmony import */ var node_module__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(2033);
12417
12703
  /* harmony import */ var node_module__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__nccwpck_require__.n(node_module__WEBPACK_IMPORTED_MODULE_3__);
12418
12704
 
@@ -15435,8 +15721,8 @@ const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
15435
15721
 
15436
15722
  /* harmony default export */ const chalk_source = (chalk);
15437
15723
 
15438
- // EXTERNAL MODULE: ./src/command.ts + 34 modules
15439
- var command = __nccwpck_require__(2294);
15724
+ // EXTERNAL MODULE: ./src/command.ts + 36 modules
15725
+ var command = __nccwpck_require__(3236);
15440
15726
  ;// CONCATENATED MODULE: ./src/print.ts
15441
15727
 
15442
15728
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/cli",
3
- "version": "0.0.162",
3
+ "version": "0.0.165",
4
4
  "description": "Command-line build tool for Neon modules.",
5
5
  "type": "module",
6
6
  "exports": "./index.js",
@@ -27,12 +27,12 @@
27
27
  },
28
28
  "homepage": "https://github.com/dherman/neon-rs#readme",
29
29
  "optionalDependencies": {
30
- "@cargo-messages/android-arm-eabi": "0.0.162",
31
- "@cargo-messages/darwin-arm64": "0.0.162",
32
- "@cargo-messages/darwin-x64": "0.0.162",
33
- "@cargo-messages/linux-arm-gnueabihf": "0.0.162",
34
- "@cargo-messages/linux-x64-gnu": "0.0.162",
35
- "@cargo-messages/win32-arm64-msvc": "0.0.162",
36
- "@cargo-messages/win32-x64-msvc": "0.0.162"
30
+ "@cargo-messages/android-arm-eabi": "0.0.165",
31
+ "@cargo-messages/darwin-arm64": "0.0.165",
32
+ "@cargo-messages/darwin-x64": "0.0.165",
33
+ "@cargo-messages/linux-arm-gnueabihf": "0.0.165",
34
+ "@cargo-messages/linux-x64-gnu": "0.0.165",
35
+ "@cargo-messages/win32-arm64-msvc": "0.0.165",
36
+ "@cargo-messages/win32-x64-msvc": "0.0.165"
37
37
  }
38
38
  }