@neon-rs/cli 0.0.167 → 0.0.168

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 +62 -25
  2. package/package.json +8 -8
package/index.js CHANGED
@@ -12052,12 +12052,12 @@ function assertIsNodeTarget(x) {
12052
12052
  throw new RangeError(`invalid Node target: ${x}`);
12053
12053
  }
12054
12054
  }
12055
- function isTargetFamilyKey(x) {
12055
+ function isTargetPreset(x) {
12056
12056
  return (typeof x === 'string') && (x in family_namespaceObject);
12057
12057
  }
12058
- function assertIsTargetFamilyKey(x) {
12059
- if (!isTargetFamilyKey(x)) {
12060
- throw new RangeError(`invalid target family name: ${x}`);
12058
+ function assertIsTargetPreset(x) {
12059
+ if (!isTargetPreset(x)) {
12060
+ throw new RangeError(`invalid target family preset: ${x}`);
12061
12061
  }
12062
12062
  }
12063
12063
  function lookupTargetFamily(key) {
@@ -12071,7 +12071,7 @@ function merge(maps) {
12071
12071
  return merged;
12072
12072
  }
12073
12073
  function expandTargetFamily(family) {
12074
- return isTargetFamilyKey(family)
12074
+ return isTargetPreset(family)
12075
12075
  ? expandTargetFamily(lookupTargetFamily(family))
12076
12076
  : Array.isArray(family)
12077
12077
  ? merge(family.map(expandTargetFamily))
@@ -12175,6 +12175,19 @@ function assertIsTargetMap(json, path) {
12175
12175
  }
12176
12176
  }
12177
12177
  }
12178
+ function assertIsTargetFamily(json, path) {
12179
+ if (typeof json === 'string') {
12180
+ assertIsTargetPreset(json);
12181
+ return;
12182
+ }
12183
+ if (Array.isArray(json)) {
12184
+ for (const elt of json) {
12185
+ assertIsTargetPreset(elt);
12186
+ }
12187
+ return;
12188
+ }
12189
+ assertIsTargetMap(json, path);
12190
+ }
12178
12191
  function assertIsBinaryV1(json) {
12179
12192
  assertHasProps(['binary'], json, "neon");
12180
12193
  const binary = json.binary;
@@ -12218,7 +12231,7 @@ function assertIsSourceCfg(json) {
12218
12231
  if (typeof json.org !== 'string') {
12219
12232
  throw new TypeError(`expected "neon.org" to be a string, found ${json.org}`);
12220
12233
  }
12221
- assertIsTargetMap(json.targets, "neon.targets");
12234
+ assertIsTargetFamily(json.targets, "neon.targets");
12222
12235
  }
12223
12236
  function assertIsPreamble(json) {
12224
12237
  if (!json || typeof json !== 'object') {
@@ -12355,11 +12368,13 @@ function normalizeSourceCfg(json) {
12355
12368
  }
12356
12369
  class SourceManifest extends AbstractManifest {
12357
12370
  _sourceJSON;
12371
+ _expandedTargets;
12358
12372
  constructor(json) {
12359
12373
  super(json);
12360
12374
  this._upgraded = normalizeSourceCfg(this._json);
12361
12375
  assertHasSourceCfg(this._json);
12362
12376
  this._sourceJSON = this._json;
12377
+ this._expandedTargets = expandTargetFamily(this._sourceJSON.neon.targets);
12363
12378
  }
12364
12379
  static async load(dir) {
12365
12380
  return new SourceManifest(await readManifest(dir));
@@ -12369,18 +12384,21 @@ class SourceManifest extends AbstractManifest {
12369
12384
  }
12370
12385
  packageNames() {
12371
12386
  const cfg = this.cfg();
12372
- return Object.keys(cfg.targets).map(key => `${cfg.org}/${key}`);
12387
+ return Object.keys(this._expandedTargets).map(key => `${cfg.org}/${key}`);
12373
12388
  }
12374
12389
  packageFor(target) {
12375
12390
  const cfg = this.cfg();
12376
- for (const key in cfg.targets) {
12377
- const value = cfg.targets[key];
12391
+ for (const key in this._expandedTargets) {
12392
+ const value = this._expandedTargets[key];
12378
12393
  if (value === target) {
12379
12394
  return `${cfg.org}/${key}`;
12380
12395
  }
12381
12396
  }
12382
12397
  return undefined;
12383
12398
  }
12399
+ rustTargetFor(node) {
12400
+ return this._expandedTargets[node];
12401
+ }
12384
12402
  manifestFor(target) {
12385
12403
  const targetInfo = getTargetDescriptor(target);
12386
12404
  const name = this.packageFor(target);
@@ -12416,11 +12434,10 @@ class SourceManifest extends AbstractManifest {
12416
12434
  }
12417
12435
  async addTargetPair(pair) {
12418
12436
  const { node, rust } = pair;
12419
- const targets = this.cfg().targets;
12420
- if (targets[node] === rust) {
12437
+ if (this._expandedTargets[node] === rust) {
12421
12438
  return null;
12422
12439
  }
12423
- targets[node] = rust;
12440
+ this._expandedTargets[node] = rust;
12424
12441
  await this.save();
12425
12442
  return pair;
12426
12443
  }
@@ -12434,22 +12451,43 @@ class SourceManifest extends AbstractManifest {
12434
12451
  async addRustTarget(target) {
12435
12452
  return await this.addTargetPair({ node: rust2Node(target), rust: target });
12436
12453
  }
12437
- async addTargets(family) {
12438
- const targets = this.cfg().targets;
12439
- let modified = [];
12454
+ filterNewTargets(family) {
12455
+ let newTargets = [];
12440
12456
  for (const [key, value] of Object.entries(family)) {
12441
12457
  const node = key;
12442
12458
  const rust = value;
12443
- if (targets[node] === rust) {
12459
+ if (this._expandedTargets[node] === rust) {
12444
12460
  continue;
12445
12461
  }
12446
- targets[node] = rust;
12447
- modified.push({ node, rust });
12462
+ newTargets.push({ node, rust });
12448
12463
  }
12449
- if (modified.length) {
12450
- await this.save();
12464
+ return newTargets;
12465
+ }
12466
+ async addTargets(family, opts = {}) {
12467
+ let newTargets = this.filterNewTargets(family);
12468
+ if (!newTargets.length) {
12469
+ return [];
12470
+ }
12471
+ for (const { node, rust } of newTargets) {
12472
+ if (opts.targetsSrc) {
12473
+ opts.targetsSrc[node] = rust;
12474
+ }
12475
+ this._expandedTargets[node] = rust;
12476
+ }
12477
+ await this.save();
12478
+ return newTargets;
12479
+ }
12480
+ async addTargetPreset(preset) {
12481
+ const targetsSrc = this.cfg().targets;
12482
+ if (typeof targetsSrc === 'string') {
12483
+ this.cfg().targets = [targetsSrc, preset];
12484
+ return this.addTargets(expandTargetFamily(preset));
12485
+ }
12486
+ if (Array.isArray(targetsSrc)) {
12487
+ targetsSrc.push(preset);
12488
+ return this.addTargets(expandTargetFamily(preset));
12451
12489
  }
12452
- return modified;
12490
+ return this.addTargets(expandTargetFamily(preset), { targetsSrc });
12453
12491
  }
12454
12492
  async updateTargets(log, bundle) {
12455
12493
  const packages = this.packageNames();
@@ -12752,8 +12790,8 @@ class AddTarget {
12752
12790
  this.log(`adding Node target ${this._target}`);
12753
12791
  return optionArray(await sourceManifest.addNodeTarget(this._target));
12754
12792
  }
12755
- else if (isTargetFamilyKey(this._target)) {
12756
- return sourceManifest.addTargets(expandTargetFamily(this._target));
12793
+ else if (isTargetPreset(this._target)) {
12794
+ return sourceManifest.addTargetPreset(this._target);
12757
12795
  }
12758
12796
  else {
12759
12797
  throw new Error(`unrecognized target ${this._target}`);
@@ -12909,8 +12947,7 @@ class RustTarget {
12909
12947
  this.log(`reading package.json`);
12910
12948
  const sourceManifest = await SourceManifest.load();
12911
12949
  this.log(`manifest: ${sourceManifest.stringify()}`);
12912
- const targets = sourceManifest.cfg().targets;
12913
- const rust = targets[this._target];
12950
+ const rust = sourceManifest.rustTargetFor(this._target);
12914
12951
  if (!rust) {
12915
12952
  throw new Error(`no Rust target found for ${this._target}`);
12916
12953
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neon-rs/cli",
3
- "version": "0.0.167",
3
+ "version": "0.0.168",
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.167",
31
- "@cargo-messages/darwin-arm64": "0.0.167",
32
- "@cargo-messages/darwin-x64": "0.0.167",
33
- "@cargo-messages/linux-arm-gnueabihf": "0.0.167",
34
- "@cargo-messages/linux-x64-gnu": "0.0.167",
35
- "@cargo-messages/win32-arm64-msvc": "0.0.167",
36
- "@cargo-messages/win32-x64-msvc": "0.0.167"
30
+ "@cargo-messages/android-arm-eabi": "0.0.168",
31
+ "@cargo-messages/darwin-arm64": "0.0.168",
32
+ "@cargo-messages/darwin-x64": "0.0.168",
33
+ "@cargo-messages/linux-arm-gnueabihf": "0.0.168",
34
+ "@cargo-messages/linux-x64-gnu": "0.0.168",
35
+ "@cargo-messages/win32-arm64-msvc": "0.0.168",
36
+ "@cargo-messages/win32-x64-msvc": "0.0.168"
37
37
  }
38
38
  }