@neon-rs/cli 0.0.183 → 0.0.185

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 +87 -54
  2. package/package.json +8 -8
package/index.js CHANGED
@@ -44489,12 +44489,21 @@ const OPTIONS = [
44489
44489
  { name: 'log', alias: 'l', type: String, defaultValue: null },
44490
44490
  { name: 'mount', alias: 'm', type: String, defaultValue: null },
44491
44491
  { name: 'manifest-path', type: String, defaultValue: null },
44492
- { name: 'out', alias: 'o', type: String, defaultValue: 'index.node' },
44492
+ { name: 'out', alias: 'o', type: String, defaultValue: null },
44493
44493
  { name: 'verbose', alias: 'v', type: Boolean, defaultValue: false }
44494
44494
  ];
44495
44495
  function createInputStream(file) {
44496
44496
  return file ? (0,external_node_fs_namespaceObject.createReadStream)(file) : process.stdin;
44497
44497
  }
44498
+ function basename(crateName) {
44499
+ return crateName.replace(/^@[^/]*\//, '');
44500
+ }
44501
+ function ensureDefined(str, msg) {
44502
+ if (str === undefined) {
44503
+ throw new Error(`${msg} is not defined`);
44504
+ }
44505
+ return str;
44506
+ }
44498
44507
  class Dist {
44499
44508
  static summary() { return 'Generate a binary .node file from a cargo output log.'; }
44500
44509
  static syntax() { return 'neon dist [-n <name>] [-f <dylib>|[-l <log>] [-m <path>]] [-o <dist>]'; }
@@ -44508,7 +44517,7 @@ class Dist {
44508
44517
  summary: 'Mounted path of target directory in virtual filesystem. This is used to map paths from the log data back to their real paths, needed when tools such as cross-rs report messages from within a mounted Docker filesystem.'
44509
44518
  },
44510
44519
  { name: '--manifest-path <path>', summary: 'Real path to Cargo.toml. (Default: cargo behavior)' },
44511
- { name: '-o, --out <dist>', summary: 'Copy output to file <dist>. (Default: index.node)' },
44520
+ { name: '-o, --out <dist>', summary: 'Copy output to file <dist>. (Default: $NEON_DIST_OUTPUT or index.node)' },
44512
44521
  { name: '-v, --verbose', summary: 'Enable verbose logging. (Default: false)' }
44513
44522
  ];
44514
44523
  }
@@ -44541,9 +44550,13 @@ class Dist {
44541
44550
  this._file = options.file ?? null;
44542
44551
  this._mount = options.mount;
44543
44552
  this._manifestPath = options['manifest-path'];
44544
- this._crateName = options.name || process.env['npm_package_name'];
44545
- this._out = options.out;
44553
+ this._crateName = options.name ||
44554
+ basename(ensureDefined(process.env['npm_package_name'], '$npm_package_name'));
44555
+ this._out = options.out ||
44556
+ process.env['NEON_DIST_OUTPUT'] ||
44557
+ 'index.node';
44546
44558
  this._verbose = !!options.verbose;
44559
+ this.log(`crate name = "${this._crateName}"`);
44547
44560
  }
44548
44561
  async findArtifact() {
44549
44562
  const reader = new lib.CargoReader(createInputStream(this._log), {
@@ -44580,6 +44593,11 @@ class Dist {
44580
44593
  // }
44581
44594
  // return file;
44582
44595
  }
44596
+ log(msg) {
44597
+ if (this._verbose) {
44598
+ console.error("[neon dist] " + msg);
44599
+ }
44600
+ }
44583
44601
  async run() {
44584
44602
  const file = this._file || (await this.findArtifact());
44585
44603
  // FIXME: needs all the logic of cargo-cp-artifact (timestamp check, M1 workaround, async, errors)
@@ -46443,7 +46461,7 @@ function assertIsBinaryV1(json) {
46443
46461
  throw new TypeError(`expected "neon.binary.abi" to be a string or null, found ${binary.abi}`);
46444
46462
  }
46445
46463
  }
46446
- function assertIsSourceV1(json) {
46464
+ function assertIsLibraryV1(json) {
46447
46465
  assertIsObject(json, "neon");
46448
46466
  for (const key in json) {
46449
46467
  const value = json[key];
@@ -46455,10 +46473,10 @@ function assertIsSourceV1(json) {
46455
46473
  }
46456
46474
  }
46457
46475
  }
46458
- function assertIsSourceCfg(json) {
46476
+ function assertIsLibraryCfg(json) {
46459
46477
  assertHasProps(['type', 'org', 'platforms'], json, "neon");
46460
- if (json.type !== 'source') {
46461
- throw new TypeError(`expected "neon.type" property to be "source", found ${json.type}`);
46478
+ if (json.type !== 'library') {
46479
+ throw new TypeError(`expected "neon.type" property to be "library", found ${json.type}`);
46462
46480
  }
46463
46481
  if (typeof json.org !== 'string') {
46464
46482
  throw new TypeError(`expected "neon.org" to be a string, found ${json.org}`);
@@ -46513,9 +46531,9 @@ function assertHasBinaryCfg(json) {
46513
46531
  assertHasCfg(json);
46514
46532
  assertIsBinaryCfg(json.neon);
46515
46533
  }
46516
- function assertHasSourceCfg(json) {
46534
+ function assertHasLibraryCfg(json) {
46517
46535
  assertHasCfg(json);
46518
- assertIsSourceCfg(json.neon);
46536
+ assertIsLibraryCfg(json.neon);
46519
46537
  }
46520
46538
  async function readManifest(dir) {
46521
46539
  dir = dir ?? process.cwd();
@@ -46579,8 +46597,17 @@ function normalizeBinaryCfg(json) {
46579
46597
  json.neon = upgradeBinaryV1(json.neon);
46580
46598
  return true;
46581
46599
  }
46582
- function normalizeSourceCfg(json) {
46600
+ function normalizeLibraryCfg(json) {
46583
46601
  assertHasCfg(json);
46602
+ // V5 format: {
46603
+ // type: 'library',
46604
+ // org: string,
46605
+ // platforms: PlatformFamily,
46606
+ // load?: string | undefined
46607
+ // }
46608
+ if ('type' in json.neon && json.neon.type === 'library') {
46609
+ return false;
46610
+ }
46584
46611
  // V4 format: {
46585
46612
  // neon: {
46586
46613
  // type: 'source',
@@ -46590,7 +46617,8 @@ function normalizeSourceCfg(json) {
46590
46617
  // }
46591
46618
  // }
46592
46619
  if ('type' in json.neon && 'platforms' in json.neon) {
46593
- return false;
46620
+ json.neon.type = 'library';
46621
+ return true;
46594
46622
  }
46595
46623
  // V3 format: {
46596
46624
  // neon: {
@@ -46604,7 +46632,7 @@ function normalizeSourceCfg(json) {
46604
46632
  const targets = json.neon['targets'];
46605
46633
  assertIsPlatformFamily(targets, "neon.targets");
46606
46634
  json.neon = {
46607
- type: 'source',
46635
+ type: 'library',
46608
46636
  org,
46609
46637
  platforms: targets
46610
46638
  };
@@ -46620,7 +46648,7 @@ function normalizeSourceCfg(json) {
46620
46648
  const platforms = json.neon['targets'];
46621
46649
  assertIsPlatformMap(platforms, "neon.targets");
46622
46650
  json.neon = {
46623
- type: 'source',
46651
+ type: 'library',
46624
46652
  org: json.neon.org,
46625
46653
  platforms
46626
46654
  };
@@ -46632,8 +46660,8 @@ function normalizeSourceCfg(json) {
46632
46660
  // }
46633
46661
  // }
46634
46662
  const targets = json.neon['targets'];
46635
- assertIsSourceV1(targets);
46636
- json.neon = upgradeSourceV1(targets);
46663
+ assertIsLibraryV1(targets);
46664
+ json.neon = upgradeLibraryV1(targets);
46637
46665
  return true;
46638
46666
  }
46639
46667
  // The source manifest is the source of truth for all Neon
@@ -46641,18 +46669,18 @@ function normalizeSourceCfg(json) {
46641
46669
  // for any other files to query the Neon project's metadata.
46642
46670
  // (Some data is replicated in the binary manifests, however,
46643
46671
  // since they are independently published in npm.)
46644
- class SourceManifest extends AbstractManifest {
46672
+ class LibraryManifest extends AbstractManifest {
46645
46673
  _sourceJSON;
46646
46674
  _expandedPlatforms;
46647
46675
  constructor(json) {
46648
46676
  super(json);
46649
- this._upgraded = normalizeSourceCfg(this._json);
46650
- assertHasSourceCfg(this._json);
46677
+ this._upgraded = normalizeLibraryCfg(this._json);
46678
+ assertHasLibraryCfg(this._json);
46651
46679
  this._sourceJSON = this._json;
46652
46680
  this._expandedPlatforms = expandPlatformFamily(this._sourceJSON.neon.platforms);
46653
46681
  }
46654
46682
  static async load(dir) {
46655
- return new SourceManifest(await readManifest(dir));
46683
+ return new LibraryManifest(await readManifest(dir));
46656
46684
  }
46657
46685
  cfg() {
46658
46686
  return this._sourceJSON.neon;
@@ -46792,6 +46820,11 @@ class SourceManifest extends AbstractManifest {
46792
46820
  platformsSrc.push(preset);
46793
46821
  return this.addPlatforms(expandPlatformFamily(preset));
46794
46822
  }
46823
+ // Edge case: an empty object can be treated like an empty array
46824
+ if (Object.keys(platformsSrc).length === 0) {
46825
+ this.cfg().platforms = [];
46826
+ return await this.addPlatformPreset(preset);
46827
+ }
46795
46828
  return this.addPlatforms(expandPlatformFamily(preset), { platformsSrc });
46796
46829
  }
46797
46830
  async updateTargets(log, bundle) {
@@ -46824,7 +46857,7 @@ if (0) {
46824
46857
  await promises_namespaceObject.writeFile(bundle, PREAMBLE + requires + '\n}\n');
46825
46858
  }
46826
46859
  }
46827
- function upgradeSourceV1(object) {
46860
+ function upgradeLibraryV1(object) {
46828
46861
  function splitSwap([key, value]) {
46829
46862
  if (!/^@.*\//.test(value)) {
46830
46863
  throw new TypeError(`expected namespaced npm package name, found ${value}`);
@@ -46843,7 +46876,7 @@ function upgradeSourceV1(object) {
46843
46876
  throw new Error(`multiple npm orgs found: ${orgs}`);
46844
46877
  }
46845
46878
  return {
46846
- type: 'source',
46879
+ type: 'library',
46847
46880
  org: [...orgs][0],
46848
46881
  platforms: Object.fromEntries(entries)
46849
46882
  };
@@ -46925,12 +46958,12 @@ class Tarball {
46925
46958
  console.error("[neon tarball] " + msg);
46926
46959
  }
46927
46960
  }
46928
- async createTempDir(sourceManifest) {
46961
+ async createTempDir(libManifest) {
46929
46962
  const target = this._target || await getCurrentTarget(msg => this.log(msg));
46930
46963
  if (!isRustTarget(target)) {
46931
46964
  throw new Error(`Rust target ${target} not supported.`);
46932
46965
  }
46933
- const binaryManifest = sourceManifest.manifestFor(target);
46966
+ const binaryManifest = libManifest.manifestFor(target);
46934
46967
  this.log(`prebuild manifest: ${binaryManifest.stringify()}`);
46935
46968
  this.log("creating temp dir");
46936
46969
  const tmpdir = await mktemp('neon-');
@@ -46943,11 +46976,11 @@ class Tarball {
46943
46976
  await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(tmpdir, "README.md"), `# \`${binaryManifest.name}\`\n\n${binaryManifest.description}\n`);
46944
46977
  return tmpdir;
46945
46978
  }
46946
- async prepareInDir(sourceManifest) {
46979
+ async prepareInDir(libManifest) {
46947
46980
  if (!this._inDir) {
46948
- return await this.createTempDir(sourceManifest);
46981
+ return await this.createTempDir(libManifest);
46949
46982
  }
46950
- const version = sourceManifest.version;
46983
+ const version = libManifest.version;
46951
46984
  const binaryManifest = await BinaryManifest.load(this._inDir);
46952
46985
  const cfg = binaryManifest.cfg();
46953
46986
  // Since the source manifest is the source of truth, any time there's a
@@ -46974,9 +47007,9 @@ class Tarball {
46974
47007
  this.log(`creating directory ${this._outDir}`);
46975
47008
  await promises_namespaceObject.mkdir(this._outDir, { recursive: true });
46976
47009
  this.log(`reading package.json`);
46977
- const sourceManifest = await SourceManifest.load();
46978
- this.log(`manifest: ${sourceManifest.stringify()}`);
46979
- const inDir = await this.prepareInDir(sourceManifest);
47010
+ const libManifest = await LibraryManifest.load();
47011
+ this.log(`manifest: ${libManifest.stringify()}`);
47012
+ const inDir = await this.prepareInDir(libManifest);
46980
47013
  this.log(`npm pack --json`);
46981
47014
  const result = await execa("npm", ["pack", "--json"], {
46982
47015
  shell: true,
@@ -47096,29 +47129,29 @@ class AddPlatform {
47096
47129
  console.error("[neon add-platform] " + msg);
47097
47130
  }
47098
47131
  }
47099
- async addPlatform(sourceManifest) {
47132
+ async addPlatform(libManifest) {
47100
47133
  if (!this._platform) {
47101
47134
  this.log('adding default system platform');
47102
- return optionArray(await sourceManifest.addRustTarget(await getCurrentTarget(msg => this.log(msg))));
47135
+ return optionArray(await libManifest.addRustTarget(await getCurrentTarget(msg => this.log(msg))));
47103
47136
  }
47104
47137
  else if (isRustTarget(this._platform)) {
47105
47138
  this.log(`adding Rust target ${this._platform}`);
47106
- return optionArray(await sourceManifest.addRustTarget(this._platform));
47139
+ return optionArray(await libManifest.addRustTarget(this._platform));
47107
47140
  }
47108
47141
  else if (isNodePlatform(this._platform)) {
47109
47142
  this.log(`adding Node platform ${this._platform}`);
47110
- return optionArray(await sourceManifest.addNodePlatform(this._platform));
47143
+ return optionArray(await libManifest.addNodePlatform(this._platform));
47111
47144
  }
47112
47145
  else if (isPlatformPreset(this._platform)) {
47113
- return sourceManifest.addPlatformPreset(this._platform);
47146
+ return libManifest.addPlatformPreset(this._platform);
47114
47147
  }
47115
47148
  else {
47116
47149
  throw new Error(`unrecognized platform or preset ${this._platform}`);
47117
47150
  }
47118
47151
  }
47119
- async createTemplateTree(sourceManifest, pair) {
47152
+ async createTemplateTree(libManifest, pair) {
47120
47153
  const { node, rust } = pair;
47121
- const binaryManifest = sourceManifest.manifestFor(rust);
47154
+ const binaryManifest = libManifest.manifestFor(rust);
47122
47155
  this.log(`prebuild manifest: ${binaryManifest.stringify()}`);
47123
47156
  const treeDir = external_node_path_namespaceObject.join(this._outDir, node);
47124
47157
  this.log(`creating ${treeDir}`);
@@ -47131,13 +47164,13 @@ class AddPlatform {
47131
47164
  }
47132
47165
  async run() {
47133
47166
  this.log(`reading package.json`);
47134
- const sourceManifest = await SourceManifest.load();
47135
- this.log(`manifest: ${sourceManifest.stringify()}`);
47136
- const modified = await this.addPlatform(sourceManifest);
47167
+ const libManifest = await LibraryManifest.load();
47168
+ this.log(`manifest: ${libManifest.stringify()}`);
47169
+ const modified = await this.addPlatform(libManifest);
47137
47170
  if (modified.length) {
47138
- sourceManifest.updateTargets(msg => this.log(msg), this._bundle);
47171
+ libManifest.updateTargets(msg => this.log(msg), this._bundle);
47139
47172
  for (const pair of modified) {
47140
- await this.createTemplateTree(sourceManifest, pair);
47173
+ await this.createTemplateTree(libManifest, pair);
47141
47174
  }
47142
47175
  }
47143
47176
  }
@@ -47183,15 +47216,15 @@ class UpdatePlatforms {
47183
47216
  }
47184
47217
  async run() {
47185
47218
  this.log(`reading package.json (CWD=${process.cwd()})`);
47186
- const sourceManifest = await SourceManifest.load();
47187
- const version = sourceManifest.version;
47188
- this.log(`package.json before: ${sourceManifest.stringify()}`);
47219
+ const libManifest = await LibraryManifest.load();
47220
+ const version = libManifest.version;
47221
+ this.log(`package.json before: ${libManifest.stringify()}`);
47189
47222
  this.log(`determined version: ${version}`);
47190
- if (sourceManifest.upgraded) {
47223
+ if (libManifest.upgraded) {
47191
47224
  this.log(`upgrading manifest format`);
47192
- await sourceManifest.save();
47225
+ await libManifest.save();
47193
47226
  }
47194
- sourceManifest.updateTargets(msg => this.log(msg), this._bundle);
47227
+ libManifest.updateTargets(msg => this.log(msg), this._bundle);
47195
47228
  }
47196
47229
  }
47197
47230
 
@@ -47223,9 +47256,9 @@ class ListPlatforms {
47223
47256
  }
47224
47257
  async run() {
47225
47258
  this.log(`reading package.json`);
47226
- const sourceManifest = await SourceManifest.load();
47227
- this.log(`manifest: ${sourceManifest.stringify()}`);
47228
- const platforms = sourceManifest.allPlatforms();
47259
+ const libManifest = await LibraryManifest.load();
47260
+ this.log(`manifest: ${libManifest.stringify()}`);
47261
+ const platforms = libManifest.allPlatforms();
47229
47262
  console.log(JSON.stringify(platforms, null, 2));
47230
47263
  }
47231
47264
  }
@@ -47347,9 +47380,9 @@ class RustTarget {
47347
47380
  }
47348
47381
  async run() {
47349
47382
  this.log(`reading package.json`);
47350
- const sourceManifest = await SourceManifest.load();
47351
- this.log(`manifest: ${sourceManifest.stringify()}`);
47352
- const rust = sourceManifest.rustTargetFor(this._platform);
47383
+ const libManifest = await LibraryManifest.load();
47384
+ this.log(`manifest: ${libManifest.stringify()}`);
47385
+ const rust = libManifest.rustTargetFor(this._platform);
47353
47386
  if (!rust) {
47354
47387
  throw new Error(`no Rust target found for ${this._platform}`);
47355
47388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/cli",
3
- "version": "0.0.183",
3
+ "version": "0.0.185",
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.183",
31
- "@cargo-messages/darwin-arm64": "0.0.183",
32
- "@cargo-messages/darwin-x64": "0.0.183",
33
- "@cargo-messages/linux-arm-gnueabihf": "0.0.183",
34
- "@cargo-messages/linux-x64-gnu": "0.0.183",
35
- "@cargo-messages/win32-arm64-msvc": "0.0.183",
36
- "@cargo-messages/win32-x64-msvc": "0.0.183"
30
+ "@cargo-messages/android-arm-eabi": "0.0.185",
31
+ "@cargo-messages/darwin-arm64": "0.0.185",
32
+ "@cargo-messages/darwin-x64": "0.0.185",
33
+ "@cargo-messages/linux-arm-gnueabihf": "0.0.185",
34
+ "@cargo-messages/linux-x64-gnu": "0.0.185",
35
+ "@cargo-messages/win32-arm64-msvc": "0.0.185",
36
+ "@cargo-messages/win32-x64-msvc": "0.0.185"
37
37
  }
38
38
  }