@napi-rs/cli 3.0.0-alpha.81 → 3.0.0-alpha.83

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
@@ -201,10 +201,144 @@ var debug = debugFactory("utils");
201
201
 
202
202
  // dist/utils/misc.js
203
203
  var import_node_fs = require("node:fs");
204
- var import_node_module = require("node:module");
205
204
  var import_node_util = require("node:util");
206
- var require2 = (0, import_node_module.createRequire)(__filename);
207
- var pkgJson = require2("@napi-rs/cli/package.json");
205
+
206
+ // package.json
207
+ var package_default = {
208
+ name: "@napi-rs/cli",
209
+ version: "3.0.0-alpha.83",
210
+ description: "Cli tools for napi-rs",
211
+ author: "LongYinan <lynweklm@gmail.com>",
212
+ homepage: "https://github.com/napi-rs/napi-rs",
213
+ license: "MIT",
214
+ type: "module",
215
+ engines: {
216
+ node: ">= 16"
217
+ },
218
+ bin: {
219
+ napi: "./dist/cli.js",
220
+ "napi-raw": "./cli.mjs"
221
+ },
222
+ main: "./dist/index.cjs",
223
+ module: "./dist/index.js",
224
+ exports: {
225
+ ".": {
226
+ import: {
227
+ default: "./dist/index.js",
228
+ types: "./dist/index.d.ts"
229
+ },
230
+ require: {
231
+ default: "./dist/index.cjs",
232
+ types: "./dist/index.d.ts"
233
+ }
234
+ },
235
+ "./package.json": {
236
+ import: "./package.json",
237
+ require: "./package.json"
238
+ }
239
+ },
240
+ files: [
241
+ "dist",
242
+ "src"
243
+ ],
244
+ keywords: [
245
+ "cli",
246
+ "rust",
247
+ "napi",
248
+ "n-api",
249
+ "node-api",
250
+ "node-addon",
251
+ "neon"
252
+ ],
253
+ maintainers: [
254
+ {
255
+ name: "LongYinan",
256
+ email: "lynweklm@gmail.com",
257
+ homepage: "https://github.com/Brooooooklyn"
258
+ },
259
+ {
260
+ name: "forehalo",
261
+ homepage: "https://github.com/forehalo"
262
+ }
263
+ ],
264
+ repository: {
265
+ type: "git",
266
+ url: "git+https://github.com/napi-rs/napi-rs.git"
267
+ },
268
+ publishConfig: {
269
+ registry: "https://registry.npmjs.org/",
270
+ access: "public"
271
+ },
272
+ bugs: {
273
+ url: "https://github.com/napi-rs/napi-rs/issues"
274
+ },
275
+ dependencies: {
276
+ "@inquirer/prompts": "^7.4.0",
277
+ "@napi-rs/cross-toolchain": "^0.0.19",
278
+ "@napi-rs/wasm-tools": "^0.0.3",
279
+ "@octokit/rest": "^22.0.0",
280
+ clipanion: "^4.0.0-rc.4",
281
+ colorette: "^2.0.20",
282
+ debug: "^4.4.0",
283
+ emnapi: "^1.4.0",
284
+ "js-yaml": "^4.1.0",
285
+ "lodash-es": "^4.17.21",
286
+ semver: "^7.7.1",
287
+ toml: "^3.0.0",
288
+ typanion: "^3.14.0",
289
+ "wasm-sjlj": "^1.0.6"
290
+ },
291
+ devDependencies: {
292
+ "@emnapi/core": "^1.4.0",
293
+ "@emnapi/runtime": "^1.4.0",
294
+ "@oxc-node/core": "^0.0.27",
295
+ "@types/debug": "^4.1.12",
296
+ "@types/inquirer": "^9.0.7",
297
+ "@types/js-yaml": "^4.0.9",
298
+ "@types/lodash-es": "^4.17.12",
299
+ "@types/node": "^22.13.16",
300
+ "@types/semver": "^7.7.0",
301
+ ava: "^6.2.0",
302
+ "env-paths": "^3.0.0",
303
+ esbuild: "^0.25.2",
304
+ prettier: "^3.5.3",
305
+ tslib: "^2.8.1",
306
+ typescript: "^5.8.2"
307
+ },
308
+ peerDependencies: {
309
+ "@emnapi/runtime": "^1.1.0",
310
+ emnapi: "^1.1.0"
311
+ },
312
+ peerDependenciesMeta: {
313
+ "@emnapi/runtime": {
314
+ optional: true
315
+ },
316
+ emnapi: {
317
+ optional: true
318
+ }
319
+ },
320
+ funding: {
321
+ type: "github",
322
+ url: "https://github.com/sponsors/Brooooooklyn"
323
+ },
324
+ scripts: {
325
+ codegen: "node --import @oxc-node/core/register ./codegen/index.ts",
326
+ build: "tsc && yarn build:cjs",
327
+ "build:cjs": "node ./esbuild.mjs",
328
+ test: "node --import @oxc-node/core/register ../node_modules/ava/entrypoints/cli.mjs"
329
+ },
330
+ ava: {
331
+ extensions: {
332
+ ts: "module"
333
+ },
334
+ files: [
335
+ "**/__tests__/**/*.spec.ts"
336
+ ]
337
+ },
338
+ gitHead: "fc62b69abca1d6ef609855d6464d1cfa322d94cf"
339
+ };
340
+
341
+ // dist/utils/misc.js
208
342
  var readFileAsync = (0, import_node_util.promisify)(import_node_fs.readFile);
209
343
  var writeFileAsync = (0, import_node_util.promisify)(import_node_fs.writeFile);
210
344
  var unlinkAsync = (0, import_node_util.promisify)(import_node_fs.unlink);
@@ -216,6 +350,14 @@ async function fileExists(path2) {
216
350
  const exists = await statAsync(path2).then(() => true).catch(() => false);
217
351
  return exists;
218
352
  }
353
+ async function dirExistsAsync(path2) {
354
+ try {
355
+ const stats = await statAsync(path2);
356
+ return stats.isDirectory();
357
+ } catch {
358
+ return false;
359
+ }
360
+ }
219
361
  function pick(o, ...keys2) {
220
362
  return keys2.reduce((acc, key) => {
221
363
  acc[key] = o[key];
@@ -228,10 +370,10 @@ async function updatePackageJson(path2, partial) {
228
370
  debug(`File not exists ${path2}`);
229
371
  return;
230
372
  }
231
- const old = require2(path2);
373
+ const old = require(path2);
232
374
  await writeFileAsync(path2, JSON.stringify({ ...old, ...partial }, null, 2));
233
375
  }
234
- var CLI_VERSION = pkgJson.version;
376
+ var CLI_VERSION = package_default.version;
235
377
 
236
378
  // dist/utils/target.js
237
379
  var import_node_child_process = require("node:child_process");
@@ -684,11 +826,6 @@ function apply(func, thisArg, args) {
684
826
  }
685
827
  var apply_default = apply;
686
828
 
687
- // ../node_modules/lodash-es/noop.js
688
- function noop() {
689
- }
690
- var noop_default = noop;
691
-
692
829
  // ../node_modules/lodash-es/_copyArray.js
693
830
  function copyArray(source, array) {
694
831
  var index = -1, length = source.length;
@@ -767,49 +904,6 @@ function arrayEach(array, iteratee) {
767
904
  }
768
905
  var arrayEach_default = arrayEach;
769
906
 
770
- // ../node_modules/lodash-es/_baseFindIndex.js
771
- function baseFindIndex(array, predicate, fromIndex, fromRight) {
772
- var length = array.length, index = fromIndex + (fromRight ? 1 : -1);
773
- while (fromRight ? index-- : ++index < length) {
774
- if (predicate(array[index], index, array)) {
775
- return index;
776
- }
777
- }
778
- return -1;
779
- }
780
- var baseFindIndex_default = baseFindIndex;
781
-
782
- // ../node_modules/lodash-es/_baseIsNaN.js
783
- function baseIsNaN(value) {
784
- return value !== value;
785
- }
786
- var baseIsNaN_default = baseIsNaN;
787
-
788
- // ../node_modules/lodash-es/_strictIndexOf.js
789
- function strictIndexOf(array, value, fromIndex) {
790
- var index = fromIndex - 1, length = array.length;
791
- while (++index < length) {
792
- if (array[index] === value) {
793
- return index;
794
- }
795
- }
796
- return -1;
797
- }
798
- var strictIndexOf_default = strictIndexOf;
799
-
800
- // ../node_modules/lodash-es/_baseIndexOf.js
801
- function baseIndexOf(array, value, fromIndex) {
802
- return value === value ? strictIndexOf_default(array, value, fromIndex) : baseFindIndex_default(array, baseIsNaN_default, fromIndex);
803
- }
804
- var baseIndexOf_default = baseIndexOf;
805
-
806
- // ../node_modules/lodash-es/_arrayIncludes.js
807
- function arrayIncludes(array, value) {
808
- var length = array == null ? 0 : array.length;
809
- return !!length && baseIndexOf_default(array, value, 0) > -1;
810
- }
811
- var arrayIncludes_default = arrayIncludes;
812
-
813
907
  // ../node_modules/lodash-es/_isIndex.js
814
908
  var MAX_SAFE_INTEGER = 9007199254740991;
815
909
  var reIsUint = /^(?:0|[1-9]\d*)$/;
@@ -1574,66 +1668,6 @@ function baseSlice(array, start, end) {
1574
1668
  }
1575
1669
  var baseSlice_default = baseSlice;
1576
1670
 
1577
- // ../node_modules/lodash-es/_castSlice.js
1578
- function castSlice(array, start, end) {
1579
- var length = array.length;
1580
- end = end === void 0 ? length : end;
1581
- return !start && end >= length ? array : baseSlice_default(array, start, end);
1582
- }
1583
- var castSlice_default = castSlice;
1584
-
1585
- // ../node_modules/lodash-es/_hasUnicode.js
1586
- var rsAstralRange = "\\ud800-\\udfff";
1587
- var rsComboMarksRange = "\\u0300-\\u036f";
1588
- var reComboHalfMarksRange = "\\ufe20-\\ufe2f";
1589
- var rsComboSymbolsRange = "\\u20d0-\\u20ff";
1590
- var rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange;
1591
- var rsVarRange = "\\ufe0e\\ufe0f";
1592
- var rsZWJ = "\\u200d";
1593
- var reHasUnicode = RegExp("[" + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + "]");
1594
- function hasUnicode(string) {
1595
- return reHasUnicode.test(string);
1596
- }
1597
- var hasUnicode_default = hasUnicode;
1598
-
1599
- // ../node_modules/lodash-es/_asciiToArray.js
1600
- function asciiToArray(string) {
1601
- return string.split("");
1602
- }
1603
- var asciiToArray_default = asciiToArray;
1604
-
1605
- // ../node_modules/lodash-es/_unicodeToArray.js
1606
- var rsAstralRange2 = "\\ud800-\\udfff";
1607
- var rsComboMarksRange2 = "\\u0300-\\u036f";
1608
- var reComboHalfMarksRange2 = "\\ufe20-\\ufe2f";
1609
- var rsComboSymbolsRange2 = "\\u20d0-\\u20ff";
1610
- var rsComboRange2 = rsComboMarksRange2 + reComboHalfMarksRange2 + rsComboSymbolsRange2;
1611
- var rsVarRange2 = "\\ufe0e\\ufe0f";
1612
- var rsAstral = "[" + rsAstralRange2 + "]";
1613
- var rsCombo = "[" + rsComboRange2 + "]";
1614
- var rsFitz = "\\ud83c[\\udffb-\\udfff]";
1615
- var rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")";
1616
- var rsNonAstral = "[^" + rsAstralRange2 + "]";
1617
- var rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
1618
- var rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
1619
- var rsZWJ2 = "\\u200d";
1620
- var reOptMod = rsModifier + "?";
1621
- var rsOptVar = "[" + rsVarRange2 + "]?";
1622
- var rsOptJoin = "(?:" + rsZWJ2 + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*";
1623
- var rsSeq = rsOptVar + reOptMod + rsOptJoin;
1624
- var rsSymbol = "(?:" + [rsNonAstral + rsCombo + "?", rsCombo, rsRegional, rsSurrPair, rsAstral].join("|") + ")";
1625
- var reUnicode = RegExp(rsFitz + "(?=" + rsFitz + ")|" + rsSymbol + rsSeq, "g");
1626
- function unicodeToArray(string) {
1627
- return string.match(reUnicode) || [];
1628
- }
1629
- var unicodeToArray_default = unicodeToArray;
1630
-
1631
- // ../node_modules/lodash-es/_stringToArray.js
1632
- function stringToArray(string) {
1633
- return hasUnicode_default(string) ? unicodeToArray_default(string) : asciiToArray_default(string);
1634
- }
1635
- var stringToArray_default = stringToArray;
1636
-
1637
1671
  // ../node_modules/lodash-es/_stackClear.js
1638
1672
  function stackClear() {
1639
1673
  this.__data__ = new ListCache_default();
@@ -2514,17 +2548,6 @@ function baseIteratee(value) {
2514
2548
  }
2515
2549
  var baseIteratee_default = baseIteratee;
2516
2550
 
2517
- // ../node_modules/lodash-es/_arrayAggregator.js
2518
- function arrayAggregator(array, setter, iteratee, accumulator) {
2519
- var index = -1, length = array == null ? 0 : array.length;
2520
- while (++index < length) {
2521
- var value = array[index];
2522
- setter(accumulator, value, iteratee(value), array);
2523
- }
2524
- return accumulator;
2525
- }
2526
- var arrayAggregator_default = arrayAggregator;
2527
-
2528
2551
  // ../node_modules/lodash-es/_createBaseFor.js
2529
2552
  function createBaseFor(fromRight) {
2530
2553
  return function(object, iteratee, keysFunc) {
@@ -2574,24 +2597,6 @@ var createBaseEach_default = createBaseEach;
2574
2597
  var baseEach = createBaseEach_default(baseForOwn_default);
2575
2598
  var baseEach_default = baseEach;
2576
2599
 
2577
- // ../node_modules/lodash-es/_baseAggregator.js
2578
- function baseAggregator(collection, setter, iteratee, accumulator) {
2579
- baseEach_default(collection, function(value, key, collection2) {
2580
- setter(accumulator, value, iteratee(value), collection2);
2581
- });
2582
- return accumulator;
2583
- }
2584
- var baseAggregator_default = baseAggregator;
2585
-
2586
- // ../node_modules/lodash-es/_createAggregator.js
2587
- function createAggregator(setter, initializer) {
2588
- return function(collection, iteratee) {
2589
- var func = isArray_default(collection) ? arrayAggregator_default : baseAggregator_default, accumulator = initializer ? initializer() : {};
2590
- return func(collection, setter, baseIteratee_default(iteratee, 2), accumulator);
2591
- };
2592
- }
2593
- var createAggregator_default = createAggregator;
2594
-
2595
2600
  // ../node_modules/lodash-es/_assignMergeValue.js
2596
2601
  function assignMergeValue(object, key, value) {
2597
2602
  if (value !== void 0 && !eq_default(object[key], value) || value === void 0 && !(key in object)) {
@@ -2690,18 +2695,6 @@ function baseMerge(object, source, srcIndex, customizer, stack) {
2690
2695
  }
2691
2696
  var baseMerge_default = baseMerge;
2692
2697
 
2693
- // ../node_modules/lodash-es/_arrayIncludesWith.js
2694
- function arrayIncludesWith(array, value, comparator) {
2695
- var index = -1, length = array == null ? 0 : array.length;
2696
- while (++index < length) {
2697
- if (comparator(value, array[index])) {
2698
- return true;
2699
- }
2700
- }
2701
- return false;
2702
- }
2703
- var arrayIncludesWith_default = arrayIncludesWith;
2704
-
2705
2698
  // ../node_modules/lodash-es/last.js
2706
2699
  function last(array) {
2707
2700
  var length = array == null ? 0 : array.length;
@@ -2719,48 +2712,18 @@ function baseMap(collection, iteratee) {
2719
2712
  }
2720
2713
  var baseMap_default = baseMap;
2721
2714
 
2722
- // ../node_modules/lodash-es/groupBy.js
2723
- var objectProto17 = Object.prototype;
2724
- var hasOwnProperty14 = objectProto17.hasOwnProperty;
2725
- var groupBy = createAggregator_default(function(result, value, key) {
2726
- if (hasOwnProperty14.call(result, key)) {
2727
- result[key].push(value);
2728
- } else {
2729
- baseAssignValue_default(result, key, [value]);
2730
- }
2731
- });
2732
- var groupBy_default = groupBy;
2733
-
2734
2715
  // ../node_modules/lodash-es/_parent.js
2735
2716
  function parent(object, path2) {
2736
2717
  return path2.length < 2 ? object : baseGet_default(object, baseSlice_default(path2, 0, -1));
2737
2718
  }
2738
2719
  var parent_default = parent;
2739
2720
 
2740
- // ../node_modules/lodash-es/isEqual.js
2741
- function isEqual(value, other) {
2742
- return baseIsEqual_default(value, other);
2743
- }
2744
- var isEqual_default = isEqual;
2745
-
2746
2721
  // ../node_modules/lodash-es/isNil.js
2747
2722
  function isNil(value) {
2748
2723
  return value == null;
2749
2724
  }
2750
2725
  var isNil_default = isNil;
2751
2726
 
2752
- // ../node_modules/lodash-es/_baseIsRegExp.js
2753
- var regexpTag5 = "[object RegExp]";
2754
- function baseIsRegExp(value) {
2755
- return isObjectLike_default(value) && baseGetTag_default(value) == regexpTag5;
2756
- }
2757
- var baseIsRegExp_default = baseIsRegExp;
2758
-
2759
- // ../node_modules/lodash-es/isRegExp.js
2760
- var nodeIsRegExp = nodeUtil_default && nodeUtil_default.isRegExp;
2761
- var isRegExp = nodeIsRegExp ? baseUnary_default(nodeIsRegExp) : baseIsRegExp_default;
2762
- var isRegExp_default = isRegExp;
2763
-
2764
2727
  // ../node_modules/lodash-es/merge.js
2765
2728
  var merge = createAssigner_default(function(object, source, srcIndex) {
2766
2729
  baseMerge_default(object, source, srcIndex);
@@ -2992,86 +2955,6 @@ var sortBy = baseRest_default(function(collection, iteratees) {
2992
2955
  });
2993
2956
  var sortBy_default = sortBy;
2994
2957
 
2995
- // ../node_modules/lodash-es/split.js
2996
- var MAX_ARRAY_LENGTH = 4294967295;
2997
- function split(string, separator, limit) {
2998
- if (limit && typeof limit != "number" && isIterateeCall_default(string, separator, limit)) {
2999
- separator = limit = void 0;
3000
- }
3001
- limit = limit === void 0 ? MAX_ARRAY_LENGTH : limit >>> 0;
3002
- if (!limit) {
3003
- return [];
3004
- }
3005
- string = toString_default(string);
3006
- if (string && (typeof separator == "string" || separator != null && !isRegExp_default(separator))) {
3007
- separator = baseToString_default(separator);
3008
- if (!separator && hasUnicode_default(string)) {
3009
- return castSlice_default(stringToArray_default(string), 0, limit);
3010
- }
3011
- }
3012
- return string.split(separator, limit);
3013
- }
3014
- var split_default = split;
3015
-
3016
- // ../node_modules/lodash-es/_createSet.js
3017
- var INFINITY3 = 1 / 0;
3018
- var createSet = !(Set_default && 1 / setToArray_default(new Set_default([, -0]))[1] == INFINITY3) ? noop_default : function(values) {
3019
- return new Set_default(values);
3020
- };
3021
- var createSet_default = createSet;
3022
-
3023
- // ../node_modules/lodash-es/_baseUniq.js
3024
- var LARGE_ARRAY_SIZE2 = 200;
3025
- function baseUniq(array, iteratee, comparator) {
3026
- var index = -1, includes = arrayIncludes_default, length = array.length, isCommon = true, result = [], seen = result;
3027
- if (comparator) {
3028
- isCommon = false;
3029
- includes = arrayIncludesWith_default;
3030
- } else if (length >= LARGE_ARRAY_SIZE2) {
3031
- var set = iteratee ? null : createSet_default(array);
3032
- if (set) {
3033
- return setToArray_default(set);
3034
- }
3035
- isCommon = false;
3036
- includes = cacheHas_default;
3037
- seen = new SetCache_default();
3038
- } else {
3039
- seen = iteratee ? [] : result;
3040
- }
3041
- outer:
3042
- while (++index < length) {
3043
- var value = array[index], computed = iteratee ? iteratee(value) : value;
3044
- value = comparator || value !== 0 ? value : 0;
3045
- if (isCommon && computed === computed) {
3046
- var seenIndex = seen.length;
3047
- while (seenIndex--) {
3048
- if (seen[seenIndex] === computed) {
3049
- continue outer;
3050
- }
3051
- }
3052
- if (iteratee) {
3053
- seen.push(computed);
3054
- }
3055
- result.push(value);
3056
- } else if (!includes(seen, computed, comparator)) {
3057
- if (seen !== result) {
3058
- seen.push(computed);
3059
- }
3060
- result.push(value);
3061
- }
3062
- }
3063
- return result;
3064
- }
3065
- var baseUniq_default = baseUniq;
3066
-
3067
- // ../node_modules/lodash-es/unionWith.js
3068
- var unionWith = baseRest_default(function(arrays) {
3069
- var comparator = last_default(arrays);
3070
- comparator = typeof comparator == "function" ? comparator : void 0;
3071
- return baseUniq_default(baseFlatten_default(arrays, 1, isArrayLikeObject_default, true), void 0, comparator);
3072
- });
3073
- var unionWith_default = unionWith;
3074
-
3075
2958
  // dist/utils/config.js
3076
2959
  async function readNapiConfig(path2, configPath) {
3077
2960
  if (configPath && !await fileExists(configPath)) {
@@ -3081,9 +2964,9 @@ async function readNapiConfig(path2, configPath) {
3081
2964
  throw new Error(`package.json not found at ${path2}`);
3082
2965
  }
3083
2966
  const content = await readFileAsync(path2, "utf8");
3084
- let pkgJson2;
2967
+ let pkgJson;
3085
2968
  try {
3086
- pkgJson2 = JSON.parse(content);
2969
+ pkgJson = JSON.parse(content);
3087
2970
  } catch (e) {
3088
2971
  throw new Error(`Failed to parse package.json at ${path2}`, {
3089
2972
  cause: e
@@ -3100,8 +2983,8 @@ async function readNapiConfig(path2, configPath) {
3100
2983
  });
3101
2984
  }
3102
2985
  }
3103
- const userNapiConfig = pkgJson2.napi ?? {};
3104
- if (pkgJson2.napi && separatedConfig) {
2986
+ const userNapiConfig = pkgJson.napi ?? {};
2987
+ if (pkgJson.napi && separatedConfig) {
3105
2988
  const pkgJsonPath = (0, import_colorette.underline)(path2);
3106
2989
  const configPathUnderline = (0, import_colorette.underline)(configPath);
3107
2990
  console.warn((0, import_colorette.yellow)(`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`));
@@ -3109,9 +2992,9 @@ async function readNapiConfig(path2, configPath) {
3109
2992
  }
3110
2993
  const napiConfig = merge_default({
3111
2994
  binaryName: "index",
3112
- packageName: pkgJson2.name,
2995
+ packageName: pkgJson.name,
3113
2996
  targets: [],
3114
- packageJson: pkgJson2,
2997
+ packageJson: pkgJson,
3115
2998
  npmClient: "npm"
3116
2999
  }, omit_default(userNapiConfig, "targets"));
3117
3000
  let targets = userNapiConfig.targets ?? [];
@@ -3236,11 +3119,10 @@ function exportDeclare(ambient) {
3236
3119
  }
3237
3120
  return "export declare";
3238
3121
  }
3239
- async function processTypeDef(intermediateTypeFile, constEnum, header) {
3122
+ async function processTypeDef(intermediateTypeFile, constEnum) {
3240
3123
  const exports2 = [];
3241
3124
  const defs = await readIntermediateTypeFile(intermediateTypeFile);
3242
3125
  const groupedDefs = preprocessTypeDef(defs);
3243
- header = header ?? "";
3244
3126
  const dts = sortBy_default(Array.from(groupedDefs), ([namespace]) => namespace).map(([namespace, defs2]) => {
3245
3127
  if (namespace === TOP_LEVEL_NAMESPACE) {
3246
3128
  return defs2.map((def) => {
@@ -3273,31 +3155,17 @@ async function processTypeDef(intermediateTypeFile, constEnum, header) {
3273
3155
  return declaration;
3274
3156
  }
3275
3157
  }).join("\n\n") + "\n";
3276
- if (dts.indexOf("ExternalObject<") > -1) {
3277
- header += `
3278
- export declare class ExternalObject<T> {
3279
- readonly '': {
3280
- readonly '': unique symbol
3281
- [K: symbol]: T
3282
- }
3283
- }
3284
- `;
3285
- }
3286
3158
  return {
3287
- dts: header + dts,
3159
+ dts,
3288
3160
  exports: exports2
3289
3161
  };
3290
3162
  }
3291
3163
  async function readIntermediateTypeFile(file) {
3292
3164
  const content = await readFileAsync(file, "utf8");
3293
- const defs = unionWith_default(content.split("\n").filter(Boolean).map((line) => {
3165
+ const defs = content.split("\n").filter(Boolean).map((line) => {
3294
3166
  line = line.trim();
3295
- if (!line.startsWith("{")) {
3296
- const start = line.indexOf(":") + 1;
3297
- line = line.slice(start);
3298
- }
3299
3167
  return JSON.parse(line);
3300
- }).filter((def) => !!def.kind), (a, b) => isEqual_default(a, b));
3168
+ });
3301
3169
  return defs.sort((a, b) => {
3302
3170
  if (a.kind === TypeDefKind.Struct) {
3303
3171
  if (b.kind === TypeDefKind.Struct) {
@@ -3439,7 +3307,7 @@ async function collectNodeBinaries(root2) {
3439
3307
  var import_node_child_process4 = require("node:child_process");
3440
3308
  var import_node_crypto = require("node:crypto");
3441
3309
  var import_node_fs3 = require("node:fs");
3442
- var import_node_module2 = require("node:module");
3310
+ var import_node_module = require("node:module");
3443
3311
  var import_node_os = require("node:os");
3444
3312
  var import_node_path2 = require("node:path");
3445
3313
  var colors3 = __toESM(require("colorette"), 1);
@@ -4946,13 +4814,10 @@ globalThis.onmessage = function (e) {
4946
4814
 
4947
4815
  // dist/api/build.js
4948
4816
  var debug3 = debugFactory("build");
4949
- var require3 = (0, import_node_module2.createRequire)(__filename);
4817
+ var require2 = (0, import_node_module.createRequire)(__filename);
4950
4818
  async function buildProject(options) {
4951
4819
  debug3("napi build command receive options: %O", options);
4952
- options = {
4953
- dtsCache: true,
4954
- ...options
4955
- };
4820
+ options = { dtsCache: true, ...options };
4956
4821
  const cwd = options.cwd ?? process.cwd();
4957
4822
  const resolvePath = (...paths) => (0, import_node_path2.resolve)(cwd, ...paths);
4958
4823
  const manifestPath = resolvePath(options.manifestPath ?? "Cargo.toml");
@@ -4967,9 +4832,8 @@ async function buildProject(options) {
4967
4832
  if (!pkg) {
4968
4833
  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.");
4969
4834
  }
4970
- 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"));
4971
4835
  const crateDir = (0, import_node_path2.parse)(pkg.manifest_path).dir;
4972
- 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);
4836
+ 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));
4973
4837
  return builder.build();
4974
4838
  }
4975
4839
  var Builder = class {
@@ -4981,11 +4845,10 @@ var Builder = class {
4981
4845
  outputDir;
4982
4846
  targetDir;
4983
4847
  config;
4984
- depsNapiPackages;
4985
4848
  args = [];
4986
4849
  envs = {};
4987
4850
  outputs = [];
4988
- constructor(options, crate, cwd, target, crateDir, outputDir, targetDir, config, depsNapiPackages) {
4851
+ constructor(options, crate, cwd, target, crateDir, outputDir, targetDir, config) {
4989
4852
  this.options = options;
4990
4853
  this.crate = crate;
4991
4854
  this.cwd = cwd;
@@ -4994,7 +4857,6 @@ var Builder = class {
4994
4857
  this.outputDir = outputDir;
4995
4858
  this.targetDir = targetDir;
4996
4859
  this.config = config;
4997
- this.depsNapiPackages = depsNapiPackages;
4998
4860
  }
4999
4861
  get cdyLibName() {
5000
4862
  return this.crate.targets.find((t) => t.crate_types.includes("cdylib"))?.name;
@@ -5025,7 +4887,7 @@ var Builder = class {
5025
4887
  debug3.warn("You are trying to use both `--cross-compile` and `--use-napi-cross` options, `--cross-compile` will be ignored.");
5026
4888
  }
5027
4889
  try {
5028
- const { version: version2, download } = require3("@napi-rs/cross-toolchain");
4890
+ const { version: version2, download } = require2("@napi-rs/cross-toolchain");
5029
4891
  const alias = {
5030
4892
  "s390x-unknown-linux-gnu": "s390x-ibm-linux-gnu"
5031
4893
  };
@@ -5089,10 +4951,7 @@ var Builder = class {
5089
4951
  }
5090
4952
  const command = process.env.CARGO ?? (this.options.useCross ? "cross" : "cargo");
5091
4953
  const buildProcess = (0, import_node_child_process4.spawn)(command, this.args, {
5092
- env: {
5093
- ...process.env,
5094
- ...this.envs
5095
- },
4954
+ env: { ...process.env, ...this.envs },
5096
4955
  stdio: watch ? ["inherit", "inherit", "pipe"] : "inherit",
5097
4956
  cwd: this.cwd,
5098
4957
  signal: controller.signal
@@ -5106,9 +4965,7 @@ var Builder = class {
5106
4965
  }
5107
4966
  });
5108
4967
  buildProcess.once("error", (e) => {
5109
- reject(new Error(`Build failed with error: ${e.message}`, {
5110
- cause: e
5111
- }));
4968
+ reject(new Error(`Build failed with error: ${e.message}`, { cause: e }));
5112
4969
  });
5113
4970
  buildProcess.stderr?.on("data", (data) => {
5114
4971
  const output = data.toString();
@@ -5196,58 +5053,7 @@ var Builder = class {
5196
5053
  return this;
5197
5054
  }
5198
5055
  setEnvs() {
5199
- this.envs.TYPE_DEF_TMP_PATH = this.getIntermediateTypeFile();
5200
- if ((0, import_node_fs3.existsSync)(this.envs.TYPE_DEF_TMP_PATH)) {
5201
- const { depsNapiPackages, crate } = this;
5202
- let shouldInvalidateSelf = false;
5203
- const content = (0, import_node_fs3.readFileSync)(this.envs.TYPE_DEF_TMP_PATH, "utf-8");
5204
- const typedefRaw = content.split("\n").filter((line) => line.trim().length).map((line) => {
5205
- const [pkgName, ...jsonContents] = split_default(line, ":");
5206
- return {
5207
- pkgName,
5208
- jsonContent: jsonContents.join(":")
5209
- };
5210
- });
5211
- const groupedTypedefRaw = groupBy_default(typedefRaw, ({ pkgName }) => pkgName);
5212
- const invalidPackages = /* @__PURE__ */ new Set();
5213
- for (const [pkgName, value] of Object.entries(groupedTypedefRaw)) {
5214
- const packageInvalidKey = `NAPI_PACKAGE_${pkgName.toUpperCase().replaceAll("-", "_")}_INVALID`;
5215
- let done = false;
5216
- for (const { jsonContent } of value) {
5217
- try {
5218
- const json = JSON.parse(jsonContent);
5219
- if (json.done === true) {
5220
- done = true;
5221
- break;
5222
- }
5223
- } catch {
5224
- done = false;
5225
- break;
5226
- }
5227
- }
5228
- if (!done) {
5229
- process.env[packageInvalidKey] = `${Date.now()}`;
5230
- shouldInvalidateSelf = true;
5231
- invalidPackages.add(pkgName);
5232
- }
5233
- }
5234
- const typedefPackages = new Set(Object.keys(groupedTypedefRaw));
5235
- for (const crate2 of depsNapiPackages) {
5236
- if (!typedefPackages.has(crate2.name)) {
5237
- debug3("Set invalid package typedef: %i", crate2.name);
5238
- shouldInvalidateSelf = true;
5239
- process.env[`NAPI_PACKAGE_${crate2.name.toUpperCase().replaceAll("-", "_")}_INVALID`] = `${Date.now()}`;
5240
- }
5241
- }
5242
- if (shouldInvalidateSelf) {
5243
- debug3("Set invalid package typedef: %i", crate.name);
5244
- process.env[`NAPI_PACKAGE_${crate.name.toUpperCase().replaceAll("-", "_")}_INVALID`] = `${Date.now()}`;
5245
- }
5246
- if (invalidPackages.size) {
5247
- debug3("Clean invalid packages typedef: %O", invalidPackages);
5248
- (0, import_node_fs3.writeFileSync)(this.envs.TYPE_DEF_TMP_PATH, typedefRaw.filter(({ pkgName }) => !invalidPackages.has(pkgName)).map(({ pkgName, jsonContent }) => `${pkgName}:${jsonContent}`).join("\n"));
5249
- }
5250
- }
5056
+ this.envs.TYPE_DEF_TMP_FOLDER = this.generateIntermediateTypeDefFolder();
5251
5057
  let rustflags = process.env.RUSTFLAGS ?? process.env.CARGO_BUILD_RUSTFLAGS ?? "";
5252
5058
  if (this.target.abi?.includes("musl") && !rustflags.includes("target-feature=-crt-static")) {
5253
5059
  rustflags += " -C target-feature=-crt-static";
@@ -5283,7 +5089,7 @@ var Builder = class {
5283
5089
  });
5284
5090
  }
5285
5091
  if (this.target.platform === "wasi") {
5286
- const emnapi = (0, import_node_path2.join)(require3.resolve("emnapi"), "..", "lib", "wasm32-wasi-threads");
5092
+ const emnapi = (0, import_node_path2.join)(require2.resolve("emnapi"), "..", "lib", "wasm32-wasi-threads");
5287
5093
  this.envs.EMNAPI_LINK_DIR = emnapi;
5288
5094
  this.envs.SETJMP_LINK_DIR = import_wasm_sjlj.lib;
5289
5095
  const { WASI_SDK_PATH } = process.env;
@@ -5346,16 +5152,14 @@ var Builder = class {
5346
5152
  }
5347
5153
  return this;
5348
5154
  }
5349
- getIntermediateTypeFile() {
5350
- const dtsPath = (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_type_def`);
5155
+ generateIntermediateTypeDefFolder() {
5156
+ let folder = (0, import_node_path2.join)(this.targetDir, "napi-rs", `${this.crate.name}-${(0, import_node_crypto.createHash)("sha256").update(this.crate.manifest_path).update(CLI_VERSION).digest("hex").substring(0, 8)}`);
5351
5157
  if (!this.options.dtsCache) {
5352
- try {
5353
- (0, import_node_fs3.unlinkSync)(dtsPath);
5354
- } catch {
5355
- }
5356
- return `${dtsPath}_${Date.now()}.tmp`;
5158
+ (0, import_node_fs3.rmSync)(folder, { recursive: true, force: true });
5159
+ folder += `_${Date.now()}`;
5357
5160
  }
5358
- return `${dtsPath}.tmp`;
5161
+ mkdirAsync(folder, { recursive: true });
5162
+ return folder;
5359
5163
  }
5360
5164
  async postBuild() {
5361
5165
  try {
@@ -5423,9 +5227,7 @@ var Builder = class {
5423
5227
  });
5424
5228
  return wasmBinaryName ? (0, import_node_path2.join)(this.outputDir, wasmBinaryName) : null;
5425
5229
  } catch (e) {
5426
- throw new Error("Failed to copy artifact", {
5427
- cause: e
5428
- });
5230
+ throw new Error("Failed to copy artifact", { cause: e });
5429
5231
  }
5430
5232
  }
5431
5233
  getArtifactNames() {
@@ -5454,22 +5256,57 @@ var Builder = class {
5454
5256
  return [];
5455
5257
  }
5456
5258
  async generateTypeDef() {
5457
- if (!await fileExists(this.envs.TYPE_DEF_TMP_PATH)) {
5259
+ const typeDefDir = this.envs.TYPE_DEF_TMP_FOLDER;
5260
+ if (!await dirExistsAsync(typeDefDir)) {
5458
5261
  return [];
5459
5262
  }
5460
5263
  const dest = (0, import_node_path2.join)(this.outputDir, this.options.dts ?? "index.d.ts");
5461
- const { dts, exports: exports2 } = await processTypeDef(this.envs.TYPE_DEF_TMP_PATH, this.options.constEnum ?? this.config.constEnum ?? true, !this.options.noDtsHeader ? this.options.dtsHeader ?? (this.config.dtsHeaderFile ? await readFileAsync((0, import_node_path2.join)(this.cwd, this.config.dtsHeaderFile), "utf-8").catch(() => {
5462
- debug3.warn(`Failed to read dts header file ${this.config.dtsHeaderFile}`);
5463
- return null;
5464
- }) : null) ?? this.config.dtsHeader ?? DEFAULT_TYPE_DEF_HEADER : "");
5264
+ let header = "";
5265
+ let dts = "";
5266
+ let exports2 = [];
5267
+ if (!this.options.noDtsHeader) {
5268
+ const dtsHeader = this.options.dtsHeader ?? this.config.dtsHeaderFile;
5269
+ if (dtsHeader) {
5270
+ header = dtsHeader;
5271
+ } else if (this.config.dtsHeaderFile) {
5272
+ try {
5273
+ header = await readFileAsync((0, import_node_path2.join)(this.cwd, this.config.dtsHeaderFile), "utf-8");
5274
+ } catch (e) {
5275
+ debug3.warn(`Failed to read dts header file ${this.config.dtsHeaderFile}`, e);
5276
+ }
5277
+ } else {
5278
+ header = DEFAULT_TYPE_DEF_HEADER;
5279
+ }
5280
+ }
5281
+ const files = await readdirAsync(typeDefDir, { withFileTypes: true });
5282
+ if (!files.length) {
5283
+ debug3("No type def files found. Skip generating dts file.");
5284
+ return [];
5285
+ }
5286
+ for (const file of files) {
5287
+ if (!file.isFile()) {
5288
+ continue;
5289
+ }
5290
+ const { dts: fileDts, exports: fileExports } = await processTypeDef((0, import_node_path2.join)(typeDefDir, file.name), this.options.constEnum ?? this.config.constEnum ?? true);
5291
+ dts += fileDts;
5292
+ exports2.push(...fileExports);
5293
+ }
5294
+ if (dts.indexOf("ExternalObject<") > -1) {
5295
+ header += `
5296
+ export declare class ExternalObject<T> {
5297
+ readonly '': {
5298
+ readonly '': unique symbol
5299
+ [K: symbol]: T
5300
+ }
5301
+ }
5302
+ `;
5303
+ }
5304
+ dts = header + dts;
5465
5305
  try {
5466
5306
  debug3("Writing type def to:");
5467
5307
  debug3(" %i", dest);
5468
5308
  await writeFileAsync(dest, dts, "utf-8");
5469
- this.outputs.push({
5470
- kind: "dts",
5471
- path: dest
5472
- });
5309
+ this.outputs.push({ kind: "dts", path: dest });
5473
5310
  } catch (e) {
5474
5311
  debug3.error("Failed to write type def file");
5475
5312
  debug3.error(e);
@@ -5489,10 +5326,7 @@ var Builder = class {
5489
5326
  debug3("Writing js binding to:");
5490
5327
  debug3(" %i", dest);
5491
5328
  await writeFileAsync(dest, binding, "utf-8");
5492
- return {
5493
- kind: "js",
5494
- path: dest
5495
- };
5329
+ return { kind: "js", path: dest };
5496
5330
  } catch (e) {
5497
5331
  throw new Error("Failed to write js binding file", { cause: e });
5498
5332
  }
@@ -5515,26 +5349,11 @@ var Builder = class {
5515
5349
  await writeFileAsync(browserEntryPath, `export * from '${this.config.packageName}-wasm32-wasi'
5516
5350
  `);
5517
5351
  return [
5518
- {
5519
- kind: "js",
5520
- path: bindingPath
5521
- },
5522
- {
5523
- kind: "js",
5524
- path: browserBindingPath
5525
- },
5526
- {
5527
- kind: "js",
5528
- path: workerPath
5529
- },
5530
- {
5531
- kind: "js",
5532
- path: browserWorkerPath
5533
- },
5534
- {
5535
- kind: "js",
5536
- path: browserEntryPath
5537
- }
5352
+ { kind: "js", path: bindingPath },
5353
+ { kind: "js", path: browserBindingPath },
5354
+ { kind: "js", path: workerPath },
5355
+ { kind: "js", path: browserWorkerPath },
5356
+ { kind: "js", path: browserEntryPath }
5538
5357
  ];
5539
5358
  }
5540
5359
  return [];
@@ -6745,7 +6564,7 @@ var createTokenAuth = function createTokenAuth2(token) {
6745
6564
  var VERSION4 = "7.0.2";
6746
6565
 
6747
6566
  // ../node_modules/@octokit/rest/node_modules/@octokit/core/dist-src/index.js
6748
- var noop2 = () => {
6567
+ var noop = () => {
6749
6568
  };
6750
6569
  var consoleWarn = console.warn.bind(console);
6751
6570
  var consoleError = console.error.bind(console);
@@ -6818,8 +6637,8 @@ var Octokit = class {
6818
6637
  this.graphql = withCustomRequest(this.request).defaults(requestDefaults);
6819
6638
  this.log = Object.assign(
6820
6639
  {
6821
- debug: noop2,
6822
- info: noop2,
6640
+ debug: noop,
6641
+ info: noop,
6823
6642
  warn: consoleWarn,
6824
6643
  error: consoleError
6825
6644
  },