@neon-rs/cli 0.0.164 → 0.0.166

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 +202 -66
  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
- /***/ 3236:
10248
+ /***/ 1217:
10249
10249
  /***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {
10250
10250
 
10251
10251
 
@@ -10292,7 +10292,7 @@ function createInputStream(file) {
10292
10292
  return file ? (0,external_node_fs_namespaceObject.createReadStream)(file) : process.stdin;
10293
10293
  }
10294
10294
  class Dist {
10295
- static summary() { return 'Generate a .node file from a build.'; }
10295
+ static summary() { return 'Generate a binary .node file from a cargo output log.'; }
10296
10296
  static syntax() { return 'neon dist [-n <name>] [-f <dylib>|[-l <log>] [-m <path>]] [-o <dist>]'; }
10297
10297
  static options() {
10298
10298
  return [
@@ -12030,6 +12030,7 @@ const node_namespaceObject = JSON.parse('{"darwin-arm64":{"platform":"darwin","a
12030
12030
  ;// CONCATENATED MODULE: ./src/target.ts
12031
12031
 
12032
12032
 
12033
+
12033
12034
  function isRustTarget(x) {
12034
12035
  return (typeof x === 'string') && (x in rust_namespaceObject);
12035
12036
  }
@@ -12064,11 +12065,39 @@ function getTargetDescriptor(target) {
12064
12065
  llvm: nodeDescriptor.llvm
12065
12066
  };
12066
12067
  }
12068
+ function node2Rust(target) {
12069
+ return node_namespaceObject[target].llvm.map(rt => {
12070
+ assertIsRustTarget(rt);
12071
+ return rt;
12072
+ });
12073
+ }
12074
+ function rust2Node(target) {
12075
+ const nt = rust_namespaceObject[target];
12076
+ assertIsNodeTarget(nt);
12077
+ return nt;
12078
+ }
12079
+ async function getCurrentTarget(log) {
12080
+ log(`rustc -vV`);
12081
+ const result = await execa("rustc", ["-vV"], { shell: true });
12082
+ if (result.exitCode !== 0) {
12083
+ throw new Error(`Could not determine current Rust target: ${result.stderr}`);
12084
+ }
12085
+ const hostLine = result.stdout.split(/\n/).find(line => line.startsWith('host:'));
12086
+ log(`found host line: ${hostLine}`);
12087
+ if (!hostLine) {
12088
+ throw new Error("Could not determine current Rust target (unexpected rustc output)");
12089
+ }
12090
+ const target = hostLine.replace(/^host:\s+/, '');
12091
+ log(`currentTarget result: "${target}"`);
12092
+ assertIsRustTarget(target);
12093
+ return target;
12094
+ }
12067
12095
 
12068
12096
  ;// CONCATENATED MODULE: ./src/manifest.ts
12069
12097
 
12070
12098
 
12071
12099
 
12100
+
12072
12101
  function assertIsObject(json, path) {
12073
12102
  if (!json || typeof json !== 'object') {
12074
12103
  throw new TypeError(`expected "${path}" property to be an object, found ${json}`);
@@ -12091,7 +12120,7 @@ function assertIsBinaryCfg(json) {
12091
12120
  if (typeof json.rust !== 'string' || !isRustTarget(json.rust)) {
12092
12121
  throw new TypeError(`expected "neon.rust" to be a valid Rust target, found ${json.rust}`);
12093
12122
  }
12094
- if (typeof json.node !== 'string' || !isNodeTarget(json.rust)) {
12123
+ if (typeof json.node !== 'string' || !isNodeTarget(json.node)) {
12095
12124
  throw new TypeError(`expected "neon.node" to be a valid Node target, found ${json.node}`);
12096
12125
  }
12097
12126
  if (typeof json.platform !== 'string') {
@@ -12355,6 +12384,53 @@ class SourceManifest extends AbstractManifest {
12355
12384
  }
12356
12385
  return new BinaryManifest(json);
12357
12386
  }
12387
+ async addTargetPair(node, rust) {
12388
+ const targets = this.cfg().targets;
12389
+ if (targets[node] === rust) {
12390
+ return false;
12391
+ }
12392
+ targets[node] = rust;
12393
+ await this.save();
12394
+ return true;
12395
+ }
12396
+ async addNodeTarget(target) {
12397
+ const rt = node2Rust(target);
12398
+ if (rt.length > 1) {
12399
+ throw new Error(`multiple Rust targets found for Node target ${target}; please specify one of ${rt.join(', ')}`);
12400
+ }
12401
+ return await this.addTargetPair(target, rt[0]);
12402
+ }
12403
+ async addRustTarget(target) {
12404
+ return await this.addTargetPair(rust2Node(target), target);
12405
+ }
12406
+ async updateTargets(log, bundle) {
12407
+ const packages = this.packageNames();
12408
+ const specs = packages.map(name => `${name}@${this.version}`);
12409
+ log(`npm install --save-exact -O ${specs.join(' ')}`);
12410
+ const result = await execa('npm', ['install', '--save-exact', '-O', ...specs], { shell: true });
12411
+ if (result.exitCode !== 0) {
12412
+ log(`npm failed with exit code ${result.exitCode}`);
12413
+ console.error(result.stderr);
12414
+ process.exit(result.exitCode);
12415
+ }
12416
+ log(`package.json after: ${await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(process.cwd(), "package.json"))}`);
12417
+ if (!bundle) {
12418
+ return;
12419
+ }
12420
+ const PREAMBLE = `// AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
12421
+ //
12422
+ // This code is never executed but is detected by the static analysis of
12423
+ // bundlers such as \`@vercel/ncc\`. The require() expression that selects
12424
+ // the right binary module for the current platform is too dynamic to be
12425
+ // analyzable by bundler analyses, so this module provides an exhaustive
12426
+ // static list for those analyses.
12427
+
12428
+ if (0) {
12429
+ `;
12430
+ const requires = packages.map(name => ` require('${name}');`).join('\n');
12431
+ log(`generating bundler compatibility module at ${bundle}`);
12432
+ await promises_namespaceObject.writeFile(bundle, PREAMBLE + requires + '\n}\n');
12433
+ }
12358
12434
  }
12359
12435
  function upgradeSourceV1(object) {
12360
12436
  function splitSwap([key, value]) {
@@ -12392,7 +12468,7 @@ function upgradeBinaryV1(json) {
12392
12468
  };
12393
12469
  }
12394
12470
 
12395
- ;// CONCATENATED MODULE: ./src/commands/pack-build.ts
12471
+ ;// CONCATENATED MODULE: ./src/commands/tarball.ts
12396
12472
 
12397
12473
 
12398
12474
 
@@ -12401,16 +12477,16 @@ function upgradeBinaryV1(json) {
12401
12477
 
12402
12478
 
12403
12479
  const mktemp = temp.track().mkdir;
12404
- const pack_build_OPTIONS = [
12480
+ const tarball_OPTIONS = [
12405
12481
  { name: 'file', alias: 'f', type: String, defaultValue: 'index.node' },
12406
12482
  { name: 'target', alias: 't', type: String, defaultValue: null },
12407
12483
  { name: 'in-dir', alias: 'i', type: String, defaultValue: null },
12408
12484
  { name: 'out-dir', alias: 'o', type: String, defaultValue: null },
12409
12485
  { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false },
12410
12486
  ];
12411
- class PackBuild {
12412
- static summary() { return 'Create an npm tarball from a prebuild.'; }
12413
- static syntax() { return 'neon pack-build [-f <addon>] [-t <target>] [-i <dir>] [-o <dir>] [-v]'; }
12487
+ class Tarball {
12488
+ static summary() { return 'Create an npm tarball from a binary .node file.'; }
12489
+ static syntax() { return 'neon tarball [-f <addon>] [-t <target>] [-i <dir>] [-o <dir>] [-v]'; }
12414
12490
  static options() {
12415
12491
  return [
12416
12492
  { name: '-f, --file <addon>', summary: 'Prebuilt .node file to pack. (Default: index.node)' },
@@ -12433,7 +12509,7 @@ class PackBuild {
12433
12509
  _outDir;
12434
12510
  _verbose;
12435
12511
  constructor(argv) {
12436
- const options = dist_default()(pack_build_OPTIONS, { argv });
12512
+ const options = dist_default()(tarball_OPTIONS, { argv });
12437
12513
  this._target = options.target || null;
12438
12514
  this._addon = options.file;
12439
12515
  this._inDir = options['in-dir'] || null;
@@ -12442,26 +12518,11 @@ class PackBuild {
12442
12518
  }
12443
12519
  log(msg) {
12444
12520
  if (this._verbose) {
12445
- console.error("[neon pack-build] " + msg);
12521
+ console.error("[neon tarball] " + msg);
12446
12522
  }
12447
12523
  }
12448
- async currentTarget() {
12449
- this.log(`rustc -vV`);
12450
- const result = await execa("rustc", ["-vV"], { shell: true });
12451
- if (result.exitCode !== 0) {
12452
- throw new Error(`Could not determine current Rust target: ${result.stderr}`);
12453
- }
12454
- const hostLine = result.stdout.split(/\n/).find(line => line.startsWith('host:'));
12455
- this.log(`found host line: ${hostLine}`);
12456
- if (!hostLine) {
12457
- throw new Error("Could not determine current Rust target (unexpected rustc output)");
12458
- }
12459
- const target = hostLine.replace(/^host:\s+/, '');
12460
- this.log(`currentTarget result: "${target}"`);
12461
- return target;
12462
- }
12463
12524
  async createTempDir(sourceManifest) {
12464
- const target = this._target || await this.currentTarget();
12525
+ const target = this._target || await getCurrentTarget(msg => this.log(msg));
12465
12526
  if (!isRustTarget(target)) {
12466
12527
  throw new Error(`Rust target ${target} not supported.`);
12467
12528
  }
@@ -12533,19 +12594,111 @@ class PackBuild {
12533
12594
  ;
12534
12595
  }
12535
12596
 
12536
- ;// CONCATENATED MODULE: ./src/commands/install-builds.ts
12597
+ ;// CONCATENATED MODULE: ./src/commands/add-target.ts
12537
12598
 
12538
12599
 
12539
12600
 
12601
+ const add_target_OPTIONS = [
12602
+ { name: 'bundle', alias: 'b', type: String, defaultValue: null },
12603
+ { name: 'platform', alias: 'p', type: String, defaultValue: null },
12604
+ { name: 'arch', alias: 'a', type: String, defaultValue: null },
12605
+ { name: 'abi', type: String, defaultValue: null },
12606
+ { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false }
12607
+ ];
12608
+ class AddTarget {
12609
+ static summary() { return 'Add a new build target to package.json.'; }
12610
+ static syntax() { return 'neon add-target [<target> | -p <plat> -a <arch> [--abi <abi>]] [-b <file>]'; }
12611
+ static options() {
12612
+ return [
12613
+ { name: '<target>', summary: 'Full target name, in either Node or Rust convention. (Default: current target)' },
12614
+ { name: '-p, --platform <plat>', summary: 'Target platform name. (Default: current platform)' },
12615
+ { name: '-a, --arch <arch>', summary: 'Target architecture name. (Default: current arch)' },
12616
+ { name: '--abi <abi>', summary: 'Target ABI name. (Default: current ABI)' },
12617
+ { name: '-b, --bundle <file>', summary: 'File to generate bundling metadata.' },
12618
+ {
12619
+ name: '',
12620
+ summary: 'This generated file ensures support for bundlers (e.g. @vercel/ncc), which rely on static analysis to detect and enable any addons used by the library.'
12621
+ },
12622
+ { name: '-v, --verbose', summary: 'Enable verbose logging. (Default: false)' }
12623
+ ];
12624
+ }
12625
+ static seeAlso() {
12626
+ return [];
12627
+ }
12628
+ _platform;
12629
+ _arch;
12630
+ _abi;
12631
+ _target;
12632
+ _bundle;
12633
+ _verbose;
12634
+ constructor(argv) {
12635
+ const options = dist_default()(add_target_OPTIONS, { argv, partial: true });
12636
+ this._platform = options.platform || null;
12637
+ this._arch = options.arch || null;
12638
+ this._abi = options.abi || null;
12639
+ this._bundle = options.bundle || null;
12640
+ this._verbose = !!options.verbose;
12641
+ if (options.platform && !options.arch) {
12642
+ throw new Error("Option --platform requires option --arch to be specified as well.");
12643
+ }
12644
+ if (!options.platform && options.arch) {
12645
+ throw new Error("Option --arch requires option --platform to be specified as well.");
12646
+ }
12647
+ if (options.abi && (!options.platform || !options.arch)) {
12648
+ throw new Error("Option --abi requires both options --platform and --arch to be specified as well.");
12649
+ }
12650
+ if (!options.platform && !options.arch && !options.abi) {
12651
+ if (!options._unknown || options._unknown.length === 0) {
12652
+ throw new Error("No arguments found, expected <target> or -p and -a options.");
12653
+ }
12654
+ this._target = options._unknown[0];
12655
+ }
12656
+ else {
12657
+ this._target = null;
12658
+ }
12659
+ }
12660
+ log(msg) {
12661
+ if (this._verbose) {
12662
+ console.error("[neon add-target] " + msg);
12663
+ }
12664
+ }
12665
+ async addTarget(sourceManifest) {
12666
+ if (!this._target) {
12667
+ this.log('adding default system target');
12668
+ return sourceManifest.addRustTarget(await getCurrentTarget(msg => this.log(msg)));
12669
+ }
12670
+ else if (isRustTarget(this._target)) {
12671
+ this.log(`adding Rust target ${this._target}`);
12672
+ return sourceManifest.addRustTarget(this._target);
12673
+ }
12674
+ else if (isNodeTarget(this._target)) {
12675
+ this.log(`adding Node target ${this._target}`);
12676
+ return sourceManifest.addNodeTarget(this._target);
12677
+ }
12678
+ else {
12679
+ throw new Error(`unrecognized target ${this._target}`);
12680
+ }
12681
+ }
12682
+ async run() {
12683
+ this.log(`reading package.json`);
12684
+ const sourceManifest = await SourceManifest.load();
12685
+ this.log(`manifest: ${sourceManifest.stringify()}`);
12686
+ if (await this.addTarget(sourceManifest)) {
12687
+ sourceManifest.updateTargets(msg => this.log(msg), this._bundle);
12688
+ }
12689
+ }
12690
+ }
12691
+
12692
+ ;// CONCATENATED MODULE: ./src/commands/update-targets.ts
12540
12693
 
12541
12694
 
12542
- const install_builds_OPTIONS = [
12695
+ const update_targets_OPTIONS = [
12543
12696
  { name: 'bundle', alias: 'b', type: String, defaultValue: null },
12544
12697
  { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false }
12545
12698
  ];
12546
- class InstallBuilds {
12547
- static summary() { return 'Install dependencies on prebuilds in package.json.'; }
12548
- static syntax() { return 'neon install-builds [-b <file>]'; }
12699
+ class UpdateTargets {
12700
+ static summary() { return 'Update dependencies for all build targets in package.json.'; }
12701
+ static syntax() { return 'neon update-targets [-b <file>]'; }
12549
12702
  static options() {
12550
12703
  return [
12551
12704
  { name: '-b, --bundle <file>', summary: 'File to generate bundling metadata.' },
@@ -12564,13 +12717,13 @@ class InstallBuilds {
12564
12717
  _bundle;
12565
12718
  _verbose;
12566
12719
  constructor(argv) {
12567
- const options = dist_default()(install_builds_OPTIONS, { argv });
12720
+ const options = dist_default()(update_targets_OPTIONS, { argv });
12568
12721
  this._bundle = options.bundle || null;
12569
12722
  this._verbose = !!options.verbose;
12570
12723
  }
12571
12724
  log(msg) {
12572
12725
  if (this._verbose) {
12573
- console.error("[neon install-builds] " + msg);
12726
+ console.error("[neon update-targets] " + msg);
12574
12727
  }
12575
12728
  }
12576
12729
  async run() {
@@ -12579,36 +12732,11 @@ class InstallBuilds {
12579
12732
  const version = sourceManifest.version;
12580
12733
  this.log(`package.json before: ${sourceManifest.stringify()}`);
12581
12734
  this.log(`determined version: ${version}`);
12582
- const packages = sourceManifest.packageNames();
12583
- const specs = packages.map(name => `${name}@${version}`);
12584
12735
  if (sourceManifest.upgraded) {
12585
12736
  this.log(`upgrading manifest format`);
12586
12737
  await sourceManifest.save();
12587
12738
  }
12588
- this.log(`npm install --save-exact -O ${specs.join(' ')}`);
12589
- const result = await execa('npm', ['install', '--save-exact', '-O', ...specs], { shell: true });
12590
- if (result.exitCode !== 0) {
12591
- this.log(`npm failed with exit code ${result.exitCode}`);
12592
- console.error(result.stderr);
12593
- process.exit(result.exitCode);
12594
- }
12595
- this.log(`package.json after: ${await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(process.cwd(), "package.json"))}`);
12596
- if (!this._bundle) {
12597
- return;
12598
- }
12599
- const PREAMBLE = `// AUTOMATICALLY GENERATED FILE. DO NOT EDIT.
12600
- //
12601
- // This code is never executed but is detected by the static analysis of
12602
- // bundlers such as \`@vercel/ncc\`. The require() expression that selects
12603
- // the right binary module for the current platform is too dynamic to be
12604
- // analyzable by bundler analyses, so this module provides an exhaustive
12605
- // static list for those analyses.
12606
-
12607
- if (0) {
12608
- `;
12609
- const requires = packages.map(name => ` require('${name}');`).join('\n');
12610
- this.log(`generating bundler compatibility module at ${this._bundle}`);
12611
- await promises_namespaceObject.writeFile(this._bundle, PREAMBLE + requires + '\n}\n');
12739
+ sourceManifest.updateTargets(msg => this.log(msg), this._bundle);
12612
12740
  }
12613
12741
  }
12614
12742
 
@@ -12649,13 +12777,17 @@ class Help {
12649
12777
 
12650
12778
 
12651
12779
 
12780
+
12652
12781
  var CommandName;
12653
12782
  (function (CommandName) {
12654
12783
  CommandName["Help"] = "help";
12655
12784
  CommandName["Dist"] = "dist";
12656
12785
  CommandName["Bump"] = "bump";
12657
12786
  CommandName["PackBuild"] = "pack-build";
12787
+ CommandName["Tarball"] = "tarball";
12788
+ CommandName["AddTarget"] = "add-target";
12658
12789
  CommandName["InstallBuilds"] = "install-builds";
12790
+ CommandName["UpdateTargets"] = "update-targets";
12659
12791
  })(CommandName || (CommandName = {}));
12660
12792
  ;
12661
12793
  function isCommandName(s) {
@@ -12672,8 +12804,11 @@ const COMMANDS = {
12672
12804
  [CommandName.Help]: Help,
12673
12805
  [CommandName.Dist]: Dist,
12674
12806
  [CommandName.Bump]: Bump,
12675
- [CommandName.PackBuild]: PackBuild,
12676
- [CommandName.InstallBuilds]: InstallBuilds
12807
+ [CommandName.PackBuild]: Tarball,
12808
+ [CommandName.Tarball]: Tarball,
12809
+ [CommandName.AddTarget]: AddTarget,
12810
+ [CommandName.InstallBuilds]: UpdateTargets,
12811
+ [CommandName.UpdateTargets]: UpdateTargets
12677
12812
  };
12678
12813
  function commandFor(name) {
12679
12814
  return COMMANDS[name];
@@ -12683,8 +12818,9 @@ function summaries() {
12683
12818
  { name: CommandName.Help, summary: Help.summary() },
12684
12819
  { name: CommandName.Dist, summary: Dist.summary() },
12685
12820
  { name: CommandName.Bump, summary: Bump.summary() },
12686
- { name: CommandName.PackBuild, summary: PackBuild.summary() },
12687
- { name: CommandName.InstallBuilds, summary: InstallBuilds.summary() }
12821
+ { name: CommandName.Tarball, summary: Tarball.summary() },
12822
+ { name: CommandName.AddTarget, summary: AddTarget.summary() },
12823
+ { name: CommandName.UpdateTargets, summary: UpdateTargets.summary() }
12688
12824
  ];
12689
12825
  }
12690
12826
 
@@ -12698,7 +12834,7 @@ __nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __we
12698
12834
  /* harmony import */ var command_line_commands__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(5046);
12699
12835
  /* harmony import */ var command_line_commands__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(command_line_commands__WEBPACK_IMPORTED_MODULE_0__);
12700
12836
  /* harmony import */ var _print_js__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(9050);
12701
- /* harmony import */ var _command_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(3236);
12837
+ /* harmony import */ var _command_js__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(1217);
12702
12838
  /* harmony import */ var node_module__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(2033);
12703
12839
  /* harmony import */ var node_module__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__nccwpck_require__.n(node_module__WEBPACK_IMPORTED_MODULE_3__);
12704
12840
 
@@ -15721,8 +15857,8 @@ const chalkStderr = createChalk({level: stderrColor ? stderrColor.level : 0});
15721
15857
 
15722
15858
  /* harmony default export */ const chalk_source = (chalk);
15723
15859
 
15724
- // EXTERNAL MODULE: ./src/command.ts + 36 modules
15725
- var command = __nccwpck_require__(3236);
15860
+ // EXTERNAL MODULE: ./src/command.ts + 37 modules
15861
+ var command = __nccwpck_require__(1217);
15726
15862
  ;// CONCATENATED MODULE: ./src/print.ts
15727
15863
 
15728
15864
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/cli",
3
- "version": "0.0.164",
3
+ "version": "0.0.166",
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.164",
31
- "@cargo-messages/darwin-arm64": "0.0.164",
32
- "@cargo-messages/darwin-x64": "0.0.164",
33
- "@cargo-messages/linux-arm-gnueabihf": "0.0.164",
34
- "@cargo-messages/linux-x64-gnu": "0.0.164",
35
- "@cargo-messages/win32-arm64-msvc": "0.0.164",
36
- "@cargo-messages/win32-x64-msvc": "0.0.164"
30
+ "@cargo-messages/android-arm-eabi": "0.0.166",
31
+ "@cargo-messages/darwin-arm64": "0.0.166",
32
+ "@cargo-messages/darwin-x64": "0.0.166",
33
+ "@cargo-messages/linux-arm-gnueabihf": "0.0.166",
34
+ "@cargo-messages/linux-x64-gnu": "0.0.166",
35
+ "@cargo-messages/win32-arm64-msvc": "0.0.166",
36
+ "@cargo-messages/win32-x64-msvc": "0.0.166"
37
37
  }
38
38
  }