@napi-rs/cli 3.0.0-alpha.77 → 3.0.0-alpha.79

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/dist/index.cjs CHANGED
@@ -412,16 +412,29 @@ function parseMetadata(manifestPath) {
412
412
  if (!import_node_fs2.default.existsSync(manifestPath)) {
413
413
  throw new Error(`No crate found in manifest: ${manifestPath}`);
414
414
  }
415
- const cmd = `cargo metadata --manifest-path ${manifestPath} --format-version 1 --no-deps`;
416
- try {
417
- const output = (0, import_node_child_process2.execSync)(cmd, {
418
- encoding: "utf-8"
415
+ const { stdout, stderr, status, error } = (0, import_node_child_process2.spawnSync)("cargo", [
416
+ "metadata",
417
+ "--manifest-path",
418
+ manifestPath,
419
+ "--format-version",
420
+ "1",
421
+ "--no-deps"
422
+ ], { encoding: "utf-8" });
423
+ if (error) {
424
+ throw new Error("cargo metadata failed to run", { cause: error });
425
+ }
426
+ if (status !== 0) {
427
+ const simpleMessage = `cargo metadata exited with code ${status}`;
428
+ throw new Error(`${simpleMessage} and error message:
429
+
430
+ ${stderr}`, {
431
+ cause: new Error(simpleMessage)
419
432
  });
420
- return JSON.parse(output);
433
+ }
434
+ try {
435
+ return JSON.parse(stdout);
421
436
  } catch (e) {
422
- throw new Error(`Failed to parse cargo metadata output by command: ${cmd}`, {
423
- cause: e
424
- });
437
+ throw new Error("Failed to parse cargo metadata JSON", { cause: e });
425
438
  }
426
439
  }
427
440
 
@@ -662,6 +675,11 @@ function apply(func, thisArg, args) {
662
675
  }
663
676
  var apply_default = apply;
664
677
 
678
+ // ../node_modules/lodash-es/noop.js
679
+ function noop() {
680
+ }
681
+ var noop_default = noop;
682
+
665
683
  // ../node_modules/lodash-es/_copyArray.js
666
684
  function copyArray(source, array) {
667
685
  var index = -1, length = source.length;
@@ -740,6 +758,49 @@ function arrayEach(array, iteratee) {
740
758
  }
741
759
  var arrayEach_default = arrayEach;
742
760
 
761
+ // ../node_modules/lodash-es/_baseFindIndex.js
762
+ function baseFindIndex(array, predicate, fromIndex, fromRight) {
763
+ var length = array.length, index = fromIndex + (fromRight ? 1 : -1);
764
+ while (fromRight ? index-- : ++index < length) {
765
+ if (predicate(array[index], index, array)) {
766
+ return index;
767
+ }
768
+ }
769
+ return -1;
770
+ }
771
+ var baseFindIndex_default = baseFindIndex;
772
+
773
+ // ../node_modules/lodash-es/_baseIsNaN.js
774
+ function baseIsNaN(value) {
775
+ return value !== value;
776
+ }
777
+ var baseIsNaN_default = baseIsNaN;
778
+
779
+ // ../node_modules/lodash-es/_strictIndexOf.js
780
+ function strictIndexOf(array, value, fromIndex) {
781
+ var index = fromIndex - 1, length = array.length;
782
+ while (++index < length) {
783
+ if (array[index] === value) {
784
+ return index;
785
+ }
786
+ }
787
+ return -1;
788
+ }
789
+ var strictIndexOf_default = strictIndexOf;
790
+
791
+ // ../node_modules/lodash-es/_baseIndexOf.js
792
+ function baseIndexOf(array, value, fromIndex) {
793
+ return value === value ? strictIndexOf_default(array, value, fromIndex) : baseFindIndex_default(array, baseIsNaN_default, fromIndex);
794
+ }
795
+ var baseIndexOf_default = baseIndexOf;
796
+
797
+ // ../node_modules/lodash-es/_arrayIncludes.js
798
+ function arrayIncludes(array, value) {
799
+ var length = array == null ? 0 : array.length;
800
+ return !!length && baseIndexOf_default(array, value, 0) > -1;
801
+ }
802
+ var arrayIncludes_default = arrayIncludes;
803
+
743
804
  // ../node_modules/lodash-es/_isIndex.js
744
805
  var MAX_SAFE_INTEGER = 9007199254740991;
745
806
  var reIsUint = /^(?:0|[1-9]\d*)$/;
@@ -1504,6 +1565,66 @@ function baseSlice(array, start, end) {
1504
1565
  }
1505
1566
  var baseSlice_default = baseSlice;
1506
1567
 
1568
+ // ../node_modules/lodash-es/_castSlice.js
1569
+ function castSlice(array, start, end) {
1570
+ var length = array.length;
1571
+ end = end === void 0 ? length : end;
1572
+ return !start && end >= length ? array : baseSlice_default(array, start, end);
1573
+ }
1574
+ var castSlice_default = castSlice;
1575
+
1576
+ // ../node_modules/lodash-es/_hasUnicode.js
1577
+ var rsAstralRange = "\\ud800-\\udfff";
1578
+ var rsComboMarksRange = "\\u0300-\\u036f";
1579
+ var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
1580
+ var rsComboSymbolsRange = "\\u20d0-\\u20ff";
1581
+ var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
1582
+ var rsVarRange = "\\ufe0e\\ufe0f";
1583
+ var rsZWJ = "\\u200d";
1584
+ var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + "]");
1585
+ function hasUnicode(string) {
1586
+ return reHasUnicode.test(string);
1587
+ }
1588
+ var hasUnicode_default = hasUnicode;
1589
+
1590
+ // ../node_modules/lodash-es/_asciiToArray.js
1591
+ function asciiToArray(string) {
1592
+ return string.split("");
1593
+ }
1594
+ var asciiToArray_default = asciiToArray;
1595
+
1596
+ // ../node_modules/lodash-es/_unicodeToArray.js
1597
+ var rsAstralRange2 = "\\ud800-\\udfff";
1598
+ var rsComboMarksRange2 = "\\u0300-\\u036f";
1599
+ var reComboHalfMarksRange2 = "\\ufe20-\\ufe2f";
1600
+ var rsComboSymbolsRange2 = "\\u20d0-\\u20ff";
1601
+ var rsComboRange2 = rsComboMarksRange2 + reComboHalfMarksRange2 + rsComboSymbolsRange2;
1602
+ var rsVarRange2 = "\\ufe0e\\ufe0f";
1603
+ var rsAstral = "[" + rsAstralRange2 + "]";
1604
+ var rsCombo = "[" + rsComboRange2 + "]";
1605
+ var rsFitz = "\\ud83c[\\udffb-\\udfff]";
1606
+ var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
1607
+ var rsNonAstral = "[^" + rsAstralRange2 + "]";
1608
+ var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
1609
+ var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
1610
+ var rsZWJ2 = "\\u200d";
1611
+ var reOptMod = rsModifier + "?";
1612
+ var rsOptVar = "[" + rsVarRange2 + "]?";
1613
+ var rsOptJoin = "(?:" + rsZWJ2 + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
1614
+ var rsSeq = rsOptVar + reOptMod + rsOptJoin;
1615
+ var rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
1616
+ var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
1617
+ function unicodeToArray(string) {
1618
+ return string.match(reUnicode) || [];
1619
+ }
1620
+ var unicodeToArray_default = unicodeToArray;
1621
+
1622
+ // ../node_modules/lodash-es/_stringToArray.js
1623
+ function stringToArray(string) {
1624
+ return hasUnicode_default(string) ? unicodeToArray_default(string) : asciiToArray_default(string);
1625
+ }
1626
+ var stringToArray_default = stringToArray;
1627
+
1507
1628
  // ../node_modules/lodash-es/_stackClear.js
1508
1629
  function stackClear() {
1509
1630
  this.__data__ = new ListCache_default();
@@ -2384,6 +2505,17 @@ function baseIteratee(value) {
2384
2505
  }
2385
2506
  var baseIteratee_default = baseIteratee;
2386
2507
 
2508
+ // ../node_modules/lodash-es/_arrayAggregator.js
2509
+ function arrayAggregator(array, setter, iteratee, accumulator) {
2510
+ var index = -1, length = array == null ? 0 : array.length;
2511
+ while (++index < length) {
2512
+ var value = array[index];
2513
+ setter(accumulator, value, iteratee(value), array);
2514
+ }
2515
+ return accumulator;
2516
+ }
2517
+ var arrayAggregator_default = arrayAggregator;
2518
+
2387
2519
  // ../node_modules/lodash-es/_createBaseFor.js
2388
2520
  function createBaseFor(fromRight) {
2389
2521
  return function(object, iteratee, keysFunc) {
@@ -2433,6 +2565,24 @@ var createBaseEach_default = createBaseEach;
2433
2565
  var baseEach = createBaseEach_default(baseForOwn_default);
2434
2566
  var baseEach_default = baseEach;
2435
2567
 
2568
+ // ../node_modules/lodash-es/_baseAggregator.js
2569
+ function baseAggregator(collection, setter, iteratee, accumulator) {
2570
+ baseEach_default(collection, function(value, key, collection2) {
2571
+ setter(accumulator, value, iteratee(value), collection2);
2572
+ });
2573
+ return accumulator;
2574
+ }
2575
+ var baseAggregator_default = baseAggregator;
2576
+
2577
+ // ../node_modules/lodash-es/_createAggregator.js
2578
+ function createAggregator(setter, initializer) {
2579
+ return function(collection, iteratee) {
2580
+ var func = isArray_default(collection) ? arrayAggregator_default : baseAggregator_default, accumulator = initializer ? initializer() : {};
2581
+ return func(collection, setter, baseIteratee_default(iteratee, 2), accumulator);
2582
+ };
2583
+ }
2584
+ var createAggregator_default = createAggregator;
2585
+
2436
2586
  // ../node_modules/lodash-es/_assignMergeValue.js
2437
2587
  function assignMergeValue(object, key, value) {
2438
2588
  if (value !== void 0 && !eq_default(object[key], value) || value === void 0 && !(key in object)) {
@@ -2531,6 +2681,18 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
2531
2681
  }
2532
2682
  var baseMerge_default = baseMerge;
2533
2683
 
2684
+ // ../node_modules/lodash-es/_arrayIncludesWith.js
2685
+ function arrayIncludesWith(array, value, comparator) {
2686
+ var index = -1, length = array == null ? 0 : array.length;
2687
+ while (++index < length) {
2688
+ if (comparator(value, array[index])) {
2689
+ return true;
2690
+ }
2691
+ }
2692
+ return false;
2693
+ }
2694
+ var arrayIncludesWith_default = arrayIncludesWith;
2695
+
2534
2696
  // ../node_modules/lodash-es/last.js
2535
2697
  function last(array) {
2536
2698
  var length = array == null ? 0 : array.length;
@@ -2548,18 +2710,48 @@ function baseMap(collection, iteratee) {
2548
2710
  }
2549
2711
  var baseMap_default = baseMap;
2550
2712
 
2713
+ // ../node_modules/lodash-es/groupBy.js
2714
+ var objectProto17 = Object.prototype;
2715
+ var hasOwnProperty14 = objectProto17.hasOwnProperty;
2716
+ var groupBy = createAggregator_default(function(result, value, key) {
2717
+ if (hasOwnProperty14.call(result, key)) {
2718
+ result[key].push(value);
2719
+ } else {
2720
+ baseAssignValue_default(result, key, [value]);
2721
+ }
2722
+ });
2723
+ var groupBy_default = groupBy;
2724
+
2551
2725
  // ../node_modules/lodash-es/_parent.js
2552
2726
  function parent(object, path2) {
2553
2727
  return path2.length < 2 ? object : baseGet_default(object, baseSlice_default(path2, 0, -1));
2554
2728
  }
2555
2729
  var parent_default = parent;
2556
2730
 
2731
+ // ../node_modules/lodash-es/isEqual.js
2732
+ function isEqual(value, other) {
2733
+ return baseIsEqual_default(value, other);
2734
+ }
2735
+ var isEqual_default = isEqual;
2736
+
2557
2737
  // ../node_modules/lodash-es/isNil.js
2558
2738
  function isNil(value) {
2559
2739
  return value == null;
2560
2740
  }
2561
2741
  var isNil_default = isNil;
2562
2742
 
2743
+ // ../node_modules/lodash-es/_baseIsRegExp.js
2744
+ var regexpTag5 = "[object RegExp]";
2745
+ function baseIsRegExp(value) {
2746
+ return isObjectLike_default(value) && baseGetTag_default(value) == regexpTag5;
2747
+ }
2748
+ var baseIsRegExp_default = baseIsRegExp;
2749
+
2750
+ // ../node_modules/lodash-es/isRegExp.js
2751
+ var nodeIsRegExp = nodeUtil_default && nodeUtil_default.isRegExp;
2752
+ var isRegExp = nodeIsRegExp ? baseUnary_default(nodeIsRegExp) : baseIsRegExp_default;
2753
+ var isRegExp_default = isRegExp;
2754
+
2563
2755
  // ../node_modules/lodash-es/merge.js
2564
2756
  var merge = createAssigner_default(function(object, source, srcIndex) {
2565
2757
  baseMerge_default(object, source, srcIndex);
@@ -2791,6 +2983,86 @@ var sortBy = baseRest_default(function(collection, iteratees) {
2791
2983
  });
2792
2984
  var sortBy_default = sortBy;
2793
2985
 
2986
+ // ../node_modules/lodash-es/split.js
2987
+ var MAX_ARRAY_LENGTH = 4294967295;
2988
+ function split(string, separator, limit) {
2989
+ if (limit && typeof limit != "number" && isIterateeCall_default(string, separator, limit)) {
2990
+ separator = limit = void 0;
2991
+ }
2992
+ limit = limit === void 0 ? MAX_ARRAY_LENGTH : limit >>> 0;
2993
+ if (!limit) {
2994
+ return [];
2995
+ }
2996
+ string = toString_default(string);
2997
+ if (string && (typeof separator == "string" || separator != null && !isRegExp_default(separator))) {
2998
+ separator = baseToString_default(separator);
2999
+ if (!separator && hasUnicode_default(string)) {
3000
+ return castSlice_default(stringToArray_default(string), 0, limit);
3001
+ }
3002
+ }
3003
+ return string.split(separator, limit);
3004
+ }
3005
+ var split_default = split;
3006
+
3007
+ // ../node_modules/lodash-es/_createSet.js
3008
+ var INFINITY3 = 1 / 0;
3009
+ var createSet = !(Set_default && 1 / setToArray_default(new Set_default([, -0]))[1] == INFINITY3) ? noop_default : function(values) {
3010
+ return new Set_default(values);
3011
+ };
3012
+ var createSet_default = createSet;
3013
+
3014
+ // ../node_modules/lodash-es/_baseUniq.js
3015
+ var LARGE_ARRAY_SIZE2 = 200;
3016
+ function baseUniq(array, iteratee, comparator) {
3017
+ var index = -1, includes = arrayIncludes_default, length = array.length, isCommon = true, result = [], seen = result;
3018
+ if (comparator) {
3019
+ isCommon = false;
3020
+ includes = arrayIncludesWith_default;
3021
+ } else if (length >= LARGE_ARRAY_SIZE2) {
3022
+ var set = iteratee ? null : createSet_default(array);
3023
+ if (set) {
3024
+ return setToArray_default(set);
3025
+ }
3026
+ isCommon = false;
3027
+ includes = cacheHas_default;
3028
+ seen = new SetCache_default();
3029
+ } else {
3030
+ seen = iteratee ? [] : result;
3031
+ }
3032
+ outer:
3033
+ while (++index < length) {
3034
+ var value = array[index], computed = iteratee ? iteratee(value) : value;
3035
+ value = comparator || value !== 0 ? value : 0;
3036
+ if (isCommon && computed === computed) {
3037
+ var seenIndex = seen.length;
3038
+ while (seenIndex--) {
3039
+ if (seen[seenIndex] === computed) {
3040
+ continue outer;
3041
+ }
3042
+ }
3043
+ if (iteratee) {
3044
+ seen.push(computed);
3045
+ }
3046
+ result.push(value);
3047
+ } else if (!includes(seen, computed, comparator)) {
3048
+ if (seen !== result) {
3049
+ seen.push(computed);
3050
+ }
3051
+ result.push(value);
3052
+ }
3053
+ }
3054
+ return result;
3055
+ }
3056
+ var baseUniq_default = baseUniq;
3057
+
3058
+ // ../node_modules/lodash-es/unionWith.js
3059
+ var unionWith = baseRest_default(function(arrays) {
3060
+ var comparator = last_default(arrays);
3061
+ comparator = typeof comparator == "function" ? comparator : void 0;
3062
+ return baseUniq_default(baseFlatten_default(arrays, 1, isArrayLikeObject_default, true), void 0, comparator);
3063
+ });
3064
+ var unionWith_default = unionWith;
3065
+
2794
3066
  // dist/utils/config.js
2795
3067
  async function readNapiConfig(path2, configPath) {
2796
3068
  if (configPath && !await fileExists(configPath)) {
@@ -3009,14 +3281,14 @@ export declare class ExternalObject<T> {
3009
3281
  }
3010
3282
  async function readIntermediateTypeFile(file) {
3011
3283
  const content = await readFileAsync(file, "utf8");
3012
- const defs = content.split("\n").filter(Boolean).map((line) => {
3284
+ const defs = unionWith_default(content.split("\n").filter(Boolean).map((line) => {
3013
3285
  line = line.trim();
3014
3286
  if (!line.startsWith("{")) {
3015
3287
  const start = line.indexOf(":") + 1;
3016
3288
  line = line.slice(start);
3017
3289
  }
3018
3290
  return JSON.parse(line);
3019
- });
3291
+ }).filter((def) => !!def.kind), (a, b) => isEqual_default(a, b));
3020
3292
  return defs.sort((a, b) => {
3021
3293
  if (a.kind === TypeDefKind.Struct) {
3022
3294
  if (b.kind === TypeDefKind.Struct) {
@@ -4178,6 +4450,7 @@ const { createRequire } = require('node:module')
4178
4450
  require = createRequire(__filename)
4179
4451
 
4180
4452
  ${createCommonBinding(localName, pkgName)}
4453
+ module.exports = nativeBinding
4181
4454
  ${idents.map((ident) => `module.exports.${ident} = nativeBinding.${ident}`).join("\n")}
4182
4455
  `;
4183
4456
  }
@@ -4273,7 +4546,7 @@ function requireNative() {
4273
4546
  try {
4274
4547
  nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
4275
4548
  } catch (err) {
4276
- loadErrors.push(err);
4549
+ loadErrors.push(err)
4277
4550
  }
4278
4551
  } else if (process.platform === 'android') {
4279
4552
  if (process.arch === 'arm64') {
@@ -4402,10 +4675,10 @@ const __wasi = new __WASI({
4402
4675
  const emnapiInstantiateImport = asyncInit ? `instantiateNapiModule as __emnapiInstantiateNapiModule` : `instantiateNapiModuleSync as __emnapiInstantiateNapiModuleSync`;
4403
4676
  const emnapiInstantiateCall = asyncInit ? `await __emnapiInstantiateNapiModule` : `__emnapiInstantiateNapiModuleSync`;
4404
4677
  return `import {
4405
- ${emnapiInstantiateImport},
4678
+ createOnMessage as __wasmCreateOnMessageForFsProxy,
4406
4679
  getDefaultContext as __emnapiGetDefaultContext,
4680
+ ${emnapiInstantiateImport},
4407
4681
  WASI as __WASI,
4408
- createOnMessage as __wasmCreateOnMessageForFsProxy,
4409
4682
  } from '@napi-rs/wasm-runtime'
4410
4683
  ${fsImport}
4411
4684
  import __wasmUrl from './${wasiFilename}.wasm?url'
@@ -4466,9 +4739,9 @@ const { WASI: __nodeWASI } = require('node:wasi')
4466
4739
  const { Worker } = require('node:worker_threads')
4467
4740
 
4468
4741
  const {
4469
- instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
4470
- getDefaultContext: __emnapiGetDefaultContext,
4471
4742
  createOnMessage: __wasmCreateOnMessageForFsProxy,
4743
+ getDefaultContext: __emnapiGetDefaultContext,
4744
+ instantiateNapiModuleSync: __emnapiInstantiateNapiModuleSync,
4472
4745
  } = require('@napi-rs/wasm-runtime')
4473
4746
 
4474
4747
  const __rootDir = __nodePath.parse(process.cwd()).root
@@ -4541,7 +4814,6 @@ const { instance: __napiInstance, module: __wasiModule, napiModule: __napiModule
4541
4814
  }
4542
4815
  },
4543
4816
  })
4544
-
4545
4817
  `;
4546
4818
 
4547
4819
  // dist/api/templates/wasi-worker-template.js
@@ -4686,8 +4958,9 @@ async function buildProject(options) {
4686
4958
  if (!pkg) {
4687
4959
  throw new Error("Unable to find crate to build. It seems you are trying to build a crate in a workspace, try using `--package` option to specify the package to build.");
4688
4960
  }
4961
+ const depsNapiPackages = pkg.dependencies.map((p) => metadata.packages.find((c) => c.name === p.name)).filter((c) => c != null && c.dependencies.some((d) => d.name == "napi-derive"));
4689
4962
  const crateDir = (0, import_node_path2.parse)(pkg.manifest_path).dir;
4690
- const builder = new Builder(options, pkg, cwd, options.target ? parseTriple(options.target) : process.env.CARGO_BUILD_TARGET ? parseTriple(process.env.CARGO_BUILD_TARGET) : getSystemDefaultTarget(), crateDir, resolvePath(options.outputDir ?? crateDir), options.targetDir ?? process.env.CARGO_BUILD_TARGET_DIR ?? metadata.target_directory, await readNapiConfig(resolvePath(options.configPath ?? options.packageJsonPath ?? "package.json"), options.configPath ? resolvePath(options.configPath) : void 0));
4963
+ const builder = new Builder(options, pkg, cwd, options.target ? parseTriple(options.target) : process.env.CARGO_BUILD_TARGET ? parseTriple(process.env.CARGO_BUILD_TARGET) : getSystemDefaultTarget(), crateDir, resolvePath(options.outputDir ?? crateDir), options.targetDir ?? process.env.CARGO_BUILD_TARGET_DIR ?? metadata.target_directory, await readNapiConfig(resolvePath(options.configPath ?? options.packageJsonPath ?? "package.json"), options.configPath ? resolvePath(options.configPath) : void 0), depsNapiPackages);
4691
4964
  return builder.build();
4692
4965
  }
4693
4966
  var Builder = class {
@@ -4699,10 +4972,11 @@ var Builder = class {
4699
4972
  outputDir;
4700
4973
  targetDir;
4701
4974
  config;
4975
+ depsNapiPackages;
4702
4976
  args = [];
4703
4977
  envs = {};
4704
4978
  outputs = [];
4705
- constructor(options, crate, cwd, target, crateDir, outputDir, targetDir, config) {
4979
+ constructor(options, crate, cwd, target, crateDir, outputDir, targetDir, config, depsNapiPackages) {
4706
4980
  this.options = options;
4707
4981
  this.crate = crate;
4708
4982
  this.cwd = cwd;
@@ -4711,6 +4985,7 @@ var Builder = class {
4711
4985
  this.outputDir = outputDir;
4712
4986
  this.targetDir = targetDir;
4713
4987
  this.config = config;
4988
+ this.depsNapiPackages = depsNapiPackages;
4714
4989
  }
4715
4990
  get cdyLibName() {
4716
4991
  return this.crate.targets.find((t) => t.crate_types.includes("cdylib"))?.name;
@@ -4913,8 +5188,57 @@ var Builder = class {
4913
5188
  }
4914
5189
  setEnvs() {
4915
5190
  this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile();
4916
- this.envs.WASI_REGISTER_TMP_PATH = this.getIntermediateWasiRegisterFile();
4917
- this.envs.CARGO_CFG_NAPI_RS_CLI_VERSION = CLI_VERSION;
5191
+ if ((0, import_node_fs3.existsSync)(this.envs.TYPE_DEF_TMP_PATH)) {
5192
+ const { depsNapiPackages, crate } = this;
5193
+ let shouldInvalidateSelf = false;
5194
+ const content = (0, import_node_fs3.readFileSync)(this.envs.TYPE_DEF_TMP_PATH, "utf-8");
5195
+ const typedefRaw = content.split("\n").filter((line) => line.trim().length).map((line) => {
5196
+ const [pkgName, ...jsonContents] = split_default(line, ":");
5197
+ return {
5198
+ pkgName,
5199
+ jsonContent: jsonContents.join(":")
5200
+ };
5201
+ });
5202
+ const groupedTypedefRaw = groupBy_default(typedefRaw, ({ pkgName }) => pkgName);
5203
+ const invalidPackages = /* @__PURE__ */ new Set();
5204
+ for (const [pkgName, value] of Object.entries(groupedTypedefRaw)) {
5205
+ const packageInvalidKey = `NAPI_PACKAGE_${pkgName.toUpperCase().replaceAll("-", "_")}_INVALID`;
5206
+ let done = false;
5207
+ for (const { jsonContent } of value) {
5208
+ try {
5209
+ const json = JSON.parse(jsonContent);
5210
+ if (json.done === true) {
5211
+ done = true;
5212
+ break;
5213
+ }
5214
+ } catch {
5215
+ done = false;
5216
+ break;
5217
+ }
5218
+ }
5219
+ if (!done) {
5220
+ process.env[packageInvalidKey] = `${Date.now()}`;
5221
+ shouldInvalidateSelf = true;
5222
+ invalidPackages.add(pkgName);
5223
+ }
5224
+ }
5225
+ const typedefPackages = new Set(Object.keys(groupedTypedefRaw));
5226
+ for (const crate2 of depsNapiPackages) {
5227
+ if (!typedefPackages.has(crate2.name)) {
5228
+ debug3("Set invalid package typedef: %i", crate2.name);
5229
+ shouldInvalidateSelf = true;
5230
+ process.env[`NAPI_PACKAGE_${crate2.name.toUpperCase().replaceAll("-", "_")}_INVALID`] = `${Date.now()}`;
5231
+ }
5232
+ }
5233
+ if (shouldInvalidateSelf) {
5234
+ debug3("Set invalid package typedef: %i", crate.name);
5235
+ process.env[`NAPI_PACKAGE_${crate.name.toUpperCase().replaceAll("-", "_")}_INVALID`] = `${Date.now()}`;
5236
+ }
5237
+ if (invalidPackages.size) {
5238
+ debug3("Clean invalid packages typedef: %O", invalidPackages);
5239
+ (0, import_node_fs3.writeFileSync)(this.envs.TYPE_DEF_TMP_PATH, typedefRaw.filter(({ pkgName }) => !invalidPackages.has(pkgName)).map(({ pkgName, jsonContent }) => `${pkgName}:${jsonContent}`).join("\n"));
5240
+ }
5241
+ }
4918
5242
  let rustflags = process.env.RUSTFLAGS ?? process.env.CARGO_BUILD_RUSTFLAGS ?? "";
4919
5243
  if (this.target.abi?.includes("musl") && !rustflags.includes("target-feature=-crt-static")) {
4920
5244
  rustflags += " -C target-feature=-crt-static";
@@ -5024,9 +5348,6 @@ var Builder = class {
5024
5348
  }
5025
5349
  return `${dtsPath}.tmp`;
5026
5350
  }
5027
- getIntermediateWasiRegisterFile() {
5028
- return (0, import_node_path2.join)((0, import_node_os.tmpdir)(), `${this.crate.name}-${(0, import_node_crypto.createHash)("sha256").update(this.crate.manifest_path).update(CLI_VERSION).digest("hex").substring(0, 8)}.napi_wasi_register.tmp`);
5029
- }
5030
5351
  async postBuild() {
5031
5352
  try {
5032
5353
  debug3(`Try to create output directory:`);
@@ -5041,19 +5362,8 @@ var Builder = class {
5041
5362
  const wasmBinaryName = await this.copyArtifact();
5042
5363
  if (this.cdyLibName) {
5043
5364
  const idents = await this.generateTypeDef();
5044
- const intermediateWasiRegisterFile = this.envs.WASI_REGISTER_TMP_PATH;
5045
- const wasiRegisterFunctions = this.config.targets.some((t) => t.platform === "wasi") ? await async function readIntermediateWasiRegisterFile() {
5046
- const fileContent = await readFileAsync(intermediateWasiRegisterFile, "utf8").catch((err) => {
5047
- console.warn(`Read ${colors3.yellowBright(intermediateWasiRegisterFile)} failed, reason: ${err.message}`);
5048
- return ``;
5049
- });
5050
- return fileContent.split("\n").map((l) => l.trim()).filter((l) => l.length).map((line) => {
5051
- const [_, fn] = line.split(":");
5052
- return fn?.trim();
5053
- }).filter((fn) => !!fn);
5054
- }() : [];
5055
5365
  const jsOutput = await this.writeJsBinding(idents);
5056
- const wasmBindingsOutput = await this.writeWasiBinding(wasiRegisterFunctions, wasmBinaryName ?? "index.wasm", idents);
5366
+ const wasmBindingsOutput = await this.writeWasiBinding(wasmBinaryName ?? "index.wasm", idents);
5057
5367
  if (jsOutput) {
5058
5368
  this.outputs.push(jsOutput);
5059
5369
  }
@@ -5086,7 +5396,7 @@ var Builder = class {
5086
5396
  try {
5087
5397
  const debugWasmModule = new ModuleConfig().generateDwarf(true).generateNameSection(true).generateProducersSection(true).preserveCodeTransform(true).strictValidate(false).parse(await readFileAsync(src));
5088
5398
  const debugWasmBinary = debugWasmModule.emitWasm(true);
5089
- await writeFileAsync(dest.replace(".wasm", ".debug.wasm"), debugWasmBinary);
5399
+ await writeFileAsync(dest.replace(/\.wasm$/, ".debug.wasm"), debugWasmBinary);
5090
5400
  debug3("Generate release wasm module");
5091
5401
  const releaseWasmModule = new ModuleConfig().generateDwarf(false).generateNameSection(false).generateProducersSection(false).preserveCodeTransform(false).strictValidate(false).onlyStableFeatures(false).parse(debugWasmBinary);
5092
5402
  const releaseWasmBinary = releaseWasmModule.emitWasm(false);
@@ -5178,17 +5488,19 @@ var Builder = class {
5178
5488
  throw new Error("Failed to write js binding file", { cause: e });
5179
5489
  }
5180
5490
  }
5181
- async writeWasiBinding(wasiRegisterFunctions, distFileName, idents) {
5182
- if (distFileName && wasiRegisterFunctions.length) {
5491
+ async writeWasiBinding(distFileName, idents) {
5492
+ if (distFileName) {
5183
5493
  const { name, dir } = (0, import_node_path2.parse)(distFileName);
5184
5494
  const bindingPath = (0, import_node_path2.join)(dir, `${this.config.binaryName}.wasi.cjs`);
5185
5495
  const browserBindingPath = (0, import_node_path2.join)(dir, `${this.config.binaryName}.wasi-browser.js`);
5186
5496
  const workerPath = (0, import_node_path2.join)(dir, "wasi-worker.mjs");
5187
5497
  const browserWorkerPath = (0, import_node_path2.join)(dir, "wasi-worker-browser.mjs");
5188
5498
  const browserEntryPath = (0, import_node_path2.join)(dir, "browser.js");
5189
- const exportsCode = idents.map((ident) => `module.exports.${ident} = __napiModule.exports.${ident}`).join("\n");
5499
+ const exportsCode = `module.exports = __napiModule.exports
5500
+ ` + idents.map((ident) => `module.exports.${ident} = __napiModule.exports.${ident}`).join("\n");
5190
5501
  await writeFileAsync(bindingPath, createWasiBinding(name, this.config.packageName, this.config.wasm?.initialMemory, this.config.wasm?.maximumMemory) + exportsCode + "\n", "utf8");
5191
- await writeFileAsync(browserBindingPath, createWasiBrowserBinding(name, this.config.wasm?.initialMemory, this.config.wasm?.maximumMemory, this.config.wasm?.browser?.fs, this.config.wasm?.browser?.asyncInit) + idents.map((ident) => `export const ${ident} = __napiModule.exports.${ident}`).join("\n") + "\n", "utf8");
5502
+ await writeFileAsync(browserBindingPath, createWasiBrowserBinding(name, this.config.wasm?.initialMemory, this.config.wasm?.maximumMemory, this.config.wasm?.browser?.fs, this.config.wasm?.browser?.asyncInit) + `export default __napiModule.exports
5503
+ ` + idents.map((ident) => `export const ${ident} = __napiModule.exports.${ident}`).join("\n") + "\n", "utf8");
5192
5504
  await writeFileAsync(workerPath, WASI_WORKER_TEMPLATE, "utf8");
5193
5505
  await writeFileAsync(browserWorkerPath, createWasiBrowserWorkerBinding(this.config.wasm?.browser?.fs ?? false), "utf8");
5194
5506
  await writeFileAsync(browserEntryPath, `export * from '${this.config.packageName}-wasm32-wasi'
@@ -6421,10 +6733,10 @@ var createTokenAuth = function createTokenAuth2(token) {
6421
6733
  };
6422
6734
 
6423
6735
  // ../node_modules/@octokit/rest/node_modules/@octokit/core/dist-src/version.js
6424
- var VERSION4 = "6.1.4";
6736
+ var VERSION4 = "6.1.5";
6425
6737
 
6426
6738
  // ../node_modules/@octokit/rest/node_modules/@octokit/core/dist-src/index.js
6427
- var noop = () => {
6739
+ var noop2 = () => {
6428
6740
  };
6429
6741
  var consoleWarn = console.warn.bind(console);
6430
6742
  var consoleError = console.error.bind(console);
@@ -6497,8 +6809,8 @@ var Octokit = class {
6497
6809
  this.graphql = withCustomRequest(this.request).defaults(requestDefaults);
6498
6810
  this.log = Object.assign(
6499
6811
  {
6500
- debug: noop,
6501
- info: noop,
6812
+ debug: noop2,
6813
+ info: noop2,
6502
6814
  warn: consoleWarn,
6503
6815
  error: consoleError
6504
6816
  },
@@ -13,6 +13,18 @@ export interface Crate {
13
13
  targets: CrateTarget[];
14
14
  features: Record<string, string[]>;
15
15
  manifest_path: string;
16
+ dependencies: Array<{
17
+ name: string;
18
+ source: string;
19
+ req: string;
20
+ kind: string | null;
21
+ rename: string | null;
22
+ optional: boolean;
23
+ uses_default_features: boolean;
24
+ features: string[];
25
+ target: string | null;
26
+ registry: string | null;
27
+ }>;
16
28
  }
17
29
  export interface CargoWorkspaceMetadata {
18
30
  version: number;
@@ -1,20 +1,31 @@
1
- import { execSync } from 'node:child_process';
1
+ import { spawnSync } from 'node:child_process';
2
2
  import fs from 'node:fs';
3
3
  export function parseMetadata(manifestPath) {
4
4
  if (!fs.existsSync(manifestPath)) {
5
5
  throw new Error(`No crate found in manifest: ${manifestPath}`);
6
6
  }
7
- const cmd = `cargo metadata --manifest-path ${manifestPath} --format-version 1 --no-deps`;
8
- try {
9
- const output = execSync(cmd, {
10
- encoding: 'utf-8',
7
+ const { stdout, stderr, status, error } = spawnSync('cargo', [
8
+ 'metadata',
9
+ '--manifest-path',
10
+ manifestPath,
11
+ '--format-version',
12
+ '1',
13
+ '--no-deps',
14
+ ], { encoding: 'utf-8' });
15
+ if (error) {
16
+ throw new Error('cargo metadata failed to run', { cause: error });
17
+ }
18
+ if (status !== 0) {
19
+ const simpleMessage = `cargo metadata exited with code ${status}`;
20
+ throw new Error(`${simpleMessage} and error message:\n\n${stderr}`, {
21
+ cause: new Error(simpleMessage),
11
22
  });
12
- return JSON.parse(output);
23
+ }
24
+ try {
25
+ return JSON.parse(stdout);
13
26
  }
14
27
  catch (e) {
15
- throw new Error(`Failed to parse cargo metadata output by command: ${cmd}`, {
16
- cause: e,
17
- });
28
+ throw new Error('Failed to parse cargo metadata JSON', { cause: e });
18
29
  }
19
30
  }
20
31
  //# sourceMappingURL=metadata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/utils/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,MAAM,SAAS,CAAA;AAqCxB,MAAM,UAAU,aAAa,CAAC,YAAoB;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,+BAA+B,YAAY,EAAE,CAAC,CAAA;IAChE,CAAC;IAED,MAAM,GAAG,GAAG,kCAAkC,YAAY,+BAA+B,CAAA;IAEzF,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE;YAC3B,QAAQ,EAAE,OAAO;SAClB,CAAC,CAAA;QACF,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAA2B,CAAA;IACrD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,qDAAqD,GAAG,EAAE,EAC1D;YACE,KAAK,EAAE,CAAC;SACT,CACF,CAAA;IACH,CAAC;AACH,CAAC"}
1
+ {"version":3,"file":"metadata.js","sourceRoot":"","sources":["../../src/utils/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAA;AAiDxB,MAAM,UAAU,aAAa,CAAC,YAAoB;IAChD,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,+BAA+B,YAAY,EAAE,CAAC,CAAA;IAChE,CAAC;IAED,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,SAAS,CACjD,OAAO,EACP;QACE,UAAU;QACV,iBAAiB;QACjB,YAAY;QACZ,kBAAkB;QAClB,GAAG;QACH,WAAW;KACZ,EACD,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtB,CAAA;IAED,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;IACnE,CAAC;IACD,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,MAAM,aAAa,GAAG,mCAAmC,MAAM,EAAE,CAAA;QACjE,MAAM,IAAI,KAAK,CAAC,GAAG,aAAa,0BAA0B,MAAM,EAAE,EAAE;YAClE,KAAK,EAAE,IAAI,KAAK,CAAC,aAAa,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;IAED,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAA2B,CAAA;IACrD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,qCAAqC,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAA;IACtE,CAAC;AACH,CAAC"}