@napi-rs/cli 3.0.0-alpha.17 → 3.0.0-alpha.19

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 (67) hide show
  1. package/dist/api/build.js +1 -1
  2. package/dist/api/build.js.map +1 -1
  3. package/dist/api/create-npm-dirs.js +2 -2
  4. package/dist/api/create-npm-dirs.js.map +1 -1
  5. package/dist/api/pre-publish.js +3 -3
  6. package/dist/api/pre-publish.js.map +1 -1
  7. package/dist/api/rename.js +8 -0
  8. package/dist/api/rename.js.map +1 -1
  9. package/dist/api/universalize.js +1 -1
  10. package/dist/api/universalize.js.map +1 -1
  11. package/dist/api/version.js +1 -1
  12. package/dist/api/version.js.map +1 -1
  13. package/dist/def/artifacts.d.ts +11 -1
  14. package/dist/def/artifacts.js +5 -1
  15. package/dist/def/artifacts.js.map +1 -1
  16. package/dist/def/build.d.ts +9 -3
  17. package/dist/def/build.js +7 -3
  18. package/dist/def/build.js.map +1 -1
  19. package/dist/def/create-npm-dirs.d.ts +10 -0
  20. package/dist/def/create-npm-dirs.js +4 -0
  21. package/dist/def/create-npm-dirs.js.map +1 -1
  22. package/dist/def/new.d.ts +2 -2
  23. package/dist/def/pre-publish.d.ts +10 -0
  24. package/dist/def/pre-publish.js +5 -1
  25. package/dist/def/pre-publish.js.map +1 -1
  26. package/dist/def/rename.d.ts +11 -1
  27. package/dist/def/rename.js +5 -1
  28. package/dist/def/rename.js.map +1 -1
  29. package/dist/def/universalize.d.ts +10 -0
  30. package/dist/def/universalize.js +4 -0
  31. package/dist/def/universalize.js.map +1 -1
  32. package/dist/def/version.d.ts +10 -0
  33. package/dist/def/version.js +4 -0
  34. package/dist/def/version.js.map +1 -1
  35. package/dist/index.cjs +82 -20
  36. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  37. package/dist/utils/__tests__/config.spec.js +63 -0
  38. package/dist/utils/__tests__/config.spec.js.map +1 -0
  39. package/dist/utils/config.d.ts +2 -3
  40. package/dist/utils/config.js +33 -3
  41. package/dist/utils/config.js.map +1 -1
  42. package/dist/utils/version.d.ts +2 -1
  43. package/dist/utils/version.js +10 -8
  44. package/dist/utils/version.js.map +1 -1
  45. package/package.json +2 -2
  46. package/src/api/build.ts +4 -1
  47. package/src/api/create-npm-dirs.ts +5 -2
  48. package/src/api/pre-publish.ts +6 -3
  49. package/src/api/rename.ts +9 -0
  50. package/src/api/universalize.ts +4 -1
  51. package/src/api/version.ts +4 -1
  52. package/src/def/artifacts.ts +11 -2
  53. package/src/def/build.ts +15 -6
  54. package/src/def/create-npm-dirs.ts +9 -0
  55. package/src/def/new.ts +1 -1
  56. package/src/def/pre-publish.ts +10 -1
  57. package/src/def/rename.ts +11 -2
  58. package/src/def/universalize.ts +9 -0
  59. package/src/def/version.ts +9 -0
  60. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  61. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  62. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  63. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +8 -7
  64. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  65. package/src/utils/__tests__/config.spec.ts +81 -0
  66. package/src/utils/config.ts +43 -4
  67. package/src/utils/version.ts +10 -8
@@ -3,6 +3,7 @@ export declare abstract class BaseRenameCommand extends Command {
3
3
  static paths: string[][];
4
4
  static usage: import("clipanion").Usage;
5
5
  cwd: string;
6
+ configPath?: string;
6
7
  packageJsonPath: string;
7
8
  npmDir: string;
8
9
  $$name?: string;
@@ -13,6 +14,7 @@ export declare abstract class BaseRenameCommand extends Command {
13
14
  description?: string;
14
15
  getOptions(): {
15
16
  cwd: string;
17
+ configPath: string | undefined;
16
18
  packageJsonPath: string;
17
19
  npmDir: string;
18
20
  name: string | undefined;
@@ -24,7 +26,7 @@ export declare abstract class BaseRenameCommand extends Command {
24
26
  };
25
27
  }
26
28
  /**
27
- * Rename the napi-rs project
29
+ * Rename the NAPI-RS project
28
30
  */
29
31
  export interface RenameOptions {
30
32
  /**
@@ -33,6 +35,10 @@ export interface RenameOptions {
33
35
  * @default process.cwd()
34
36
  */
35
37
  cwd?: string;
38
+ /**
39
+ * Path to `napi` config json file
40
+ */
41
+ configPath?: string;
36
42
  /**
37
43
  * Path to `package.json`
38
44
  *
@@ -74,6 +80,10 @@ export interface RenameOptions {
74
80
  }
75
81
  export declare function applyDefaultRenameOptions(options: RenameOptions): {
76
82
  cwd: string;
83
+ /**
84
+ * Path to `napi` config json file
85
+ */
86
+ configPath?: string | undefined;
77
87
  packageJsonPath: string;
78
88
  npmDir: string;
79
89
  /**
@@ -4,11 +4,14 @@ import { Command, Option } from 'clipanion';
4
4
  export class BaseRenameCommand extends Command {
5
5
  static paths = [['rename']];
6
6
  static usage = Command.Usage({
7
- description: 'Rename the napi-rs project',
7
+ description: 'Rename the NAPI-RS project',
8
8
  });
9
9
  cwd = Option.String('--cwd', process.cwd(), {
10
10
  description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
11
11
  });
12
+ configPath = Option.String('--config-path,-c', {
13
+ description: 'Path to `napi` config json file',
14
+ });
12
15
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
13
16
  description: 'Path to `package.json`',
14
17
  });
@@ -36,6 +39,7 @@ export class BaseRenameCommand extends Command {
36
39
  getOptions() {
37
40
  return {
38
41
  cwd: this.cwd,
42
+ configPath: this.configPath,
39
43
  packageJsonPath: this.packageJsonPath,
40
44
  npmDir: this.npmDir,
41
45
  name: this.$$name,
@@ -1 +1 @@
1
- {"version":3,"file":"rename.js","sourceRoot":"","sources":["../../src/def/rename.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,iCAAiC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,OAAgB,iBAAkB,SAAQ,OAAO;IACrD,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,C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AAO;KACX,CAAA;AACH,CAAC"}
@@ -3,10 +3,12 @@ export declare abstract class BaseUniversalizeCommand extends Command {
3
3
  static paths: string[][];
4
4
  static usage: import("clipanion").Usage;
5
5
  cwd: string;
6
+ configPath?: string;
6
7
  packageJsonPath: string;
7
8
  outputDir: string;
8
9
  getOptions(): {
9
10
  cwd: string;
11
+ configPath: string | undefined;
10
12
  packageJsonPath: string;
11
13
  outputDir: string;
12
14
  };
@@ -21,6 +23,10 @@ export interface UniversalizeOptions {
21
23
  * @default process.cwd()
22
24
  */
23
25
  cwd?: string;
26
+ /**
27
+ * Path to `napi` config json file
28
+ */
29
+ configPath?: string;
24
30
  /**
25
31
  * Path to `package.json`
26
32
  *
@@ -36,6 +42,10 @@ export interface UniversalizeOptions {
36
42
  }
37
43
  export declare function applyDefaultUniversalizeOptions(options: UniversalizeOptions): {
38
44
  cwd: string;
45
+ /**
46
+ * Path to `napi` config json file
47
+ */
48
+ configPath?: string | undefined;
39
49
  packageJsonPath: string;
40
50
  outputDir: string;
41
51
  };
@@ -9,6 +9,9 @@ export class BaseUniversalizeCommand extends Command {
9
9
  cwd = Option.String('--cwd', process.cwd(), {
10
10
  description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
11
11
  });
12
+ configPath = Option.String('--config-path,-c', {
13
+ description: 'Path to `napi` config json file',
14
+ });
12
15
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
13
16
  description: 'Path to `package.json`',
14
17
  });
@@ -18,6 +21,7 @@ export class BaseUniversalizeCommand extends Command {
18
21
  getOptions() {
19
22
  return {
20
23
  cwd: this.cwd,
24
+ configPath: this.configPath,
21
25
  packageJsonPath: this.packageJsonPath,
22
26
  outputDir: this.outputDir,
23
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"universalize.js","sourceRoot":"","sources":["../../src/def/universalize.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,iCAAiC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW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AC;QAC3B,WAAW,EAAE,kDAAkD;KAChE,CAAC,CAAA;IAEF,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE;QAC1C,WAAW,EACT,oHAAoH;KACvH,CAAC,CAAA;IAEF,UAAU,GAAY,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;QACtD,WAAW,EAAE,iCAAiC;KAC/C,CAAC,CAAA;IAEF,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,cAAc,EAAE;QACrE,WAAW,EAAE,wBAAwB;KACtC,CAAC,CAAA;IAEF,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,EAAE;QACjD,WAAW,EACT,+FAA+F;KAClG,CAAC,CAAA;IAEF,UAAU;QACR,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAA;IACH,CAAC;;AA+BH,MAAM,UAAU,+BAA+B,CAAC,OAA4B;IAC1E,OAAO;QACL,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,eAAe,EAAE,cAAc;QAC/B,SAAS,EAAE,IAAI;QACf,GAAG,OAAO;KACX,CAAA;AACH,CAAC"}
@@ -3,10 +3,12 @@ export declare abstract class BaseVersionCommand extends Command {
3
3
  static paths: string[][];
4
4
  static usage: import("clipanion").Usage;
5
5
  cwd: string;
6
+ configPath?: string;
6
7
  packageJsonPath: string;
7
8
  npmDir: string;
8
9
  getOptions(): {
9
10
  cwd: string;
11
+ configPath: string | undefined;
10
12
  packageJsonPath: string;
11
13
  npmDir: string;
12
14
  };
@@ -21,6 +23,10 @@ export interface VersionOptions {
21
23
  * @default process.cwd()
22
24
  */
23
25
  cwd?: string;
26
+ /**
27
+ * Path to `napi` config json file
28
+ */
29
+ configPath?: string;
24
30
  /**
25
31
  * Path to `package.json`
26
32
  *
@@ -36,6 +42,10 @@ export interface VersionOptions {
36
42
  }
37
43
  export declare function applyDefaultVersionOptions(options: VersionOptions): {
38
44
  cwd: string;
45
+ /**
46
+ * Path to `napi` config json file
47
+ */
48
+ configPath?: string | undefined;
39
49
  packageJsonPath: string;
40
50
  npmDir: string;
41
51
  };
@@ -9,6 +9,9 @@ export class BaseVersionCommand extends Command {
9
9
  cwd = Option.String('--cwd', process.cwd(), {
10
10
  description: 'The working directory of where napi command will be executed in, all other paths options are relative to this path',
11
11
  });
12
+ configPath = Option.String('--config-path,-c', {
13
+ description: 'Path to `napi` config json file',
14
+ });
12
15
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
13
16
  description: 'Path to `package.json`',
14
17
  });
@@ -18,6 +21,7 @@ export class BaseVersionCommand extends Command {
18
21
  getOptions() {
19
22
  return {
20
23
  cwd: this.cwd,
24
+ configPath: this.configPath,
21
25
  packageJsonPath: this.packageJsonPath,
22
26
  npmDir: this.npmDir,
23
27
  };
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/def/version.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,iCAAiC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAE3C,MAAM,OAAgB,kBAAmB,SAAQ,OAAO;IACtD,MAAM,CAAC,KAAK,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;IAE5B,MAAM,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,WAAW,EAAE,wCAAwC;KACtD,CAAC,CAAA;IAEF,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE;QAC1C,WAAW,EACT,oHAAoH;KACvH,CAAC,CAAA;IAEF,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,qBAAqB,EAAE,cAAc,E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AAC,MAAM,CAAC,WAAW,EAAE,KAAK,EAAE;QACzC,WAAW,EAAE,+CAA+C;KAC7D,CAAC,CAAA;IAEF,UAAU;QACR,OAAO;YACL,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,eAAe,EAAE,IAAI,CAAC,eAAe;YACrC,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB,CAAA;IACH,CAAC;;AA+BH,MAAM,UAAU,0BAA0B,CAAC,OAAuB;IAChE,OAAO;QACL,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;QAClB,eAAe,EAAE,cAAc;QAC/B,MAAM,EAAE,KAAK;QACb,GAAG,OAAO;KACX,CAAA;AACH,CAAC"}
package/dist/index.cjs CHANGED
@@ -7768,10 +7768,13 @@ var BaseArtifactsCommand = class extends import_clipanion.Command {
7768
7768
  cwd = import_clipanion.Option.String("--cwd", process.cwd(), {
7769
7769
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
7770
7770
  });
7771
+ configPath = import_clipanion.Option.String("--config-path,-c", {
7772
+ description: "Path to `napi` config json file"
7773
+ });
7771
7774
  packageJsonPath = import_clipanion.Option.String("--package-json-path", "package.json", {
7772
7775
  description: "Path to `package.json`"
7773
7776
  });
7774
- outputDir = import_clipanion.Option.String("--output-dir,-o", "./", {
7777
+ outputDir = import_clipanion.Option.String("--output-dir,-o", "./artifacts", {
7775
7778
  description: "Path to the folder where all built `.node` files put, same as `--output-dir` of build command"
7776
7779
  });
7777
7780
  npmDir = import_clipanion.Option.String("--npm-dir", "npm", {
@@ -7780,6 +7783,7 @@ var BaseArtifactsCommand = class extends import_clipanion.Command {
7780
7783
  getOptions() {
7781
7784
  return {
7782
7785
  cwd: this.cwd,
7786
+ configPath: this.configPath,
7783
7787
  packageJsonPath: this.packageJsonPath,
7784
7788
  outputDir: this.outputDir,
7785
7789
  npmDir: this.npmDir
@@ -7955,16 +7959,18 @@ var NapiVersion;
7955
7959
  NapiVersion2[NapiVersion2["Napi6"] = 6] = "Napi6";
7956
7960
  NapiVersion2[NapiVersion2["Napi7"] = 7] = "Napi7";
7957
7961
  NapiVersion2[NapiVersion2["Napi8"] = 8] = "Napi8";
7962
+ NapiVersion2[NapiVersion2["Napi9"] = 9] = "Napi9";
7958
7963
  })(NapiVersion || (NapiVersion = {}));
7959
7964
  var NAPI_VERSION_MATRIX = /* @__PURE__ */ new Map([
7960
- [NapiVersion.Napi1, "8.6.0"],
7961
- [NapiVersion.Napi2, "8.10.0 | 9.3.0"],
7962
- [NapiVersion.Napi3, "6.14.2 | 8.11.2 | 9.11.0"],
7963
- [NapiVersion.Napi4, "10.16.0 | 11.8.0"],
7964
- [NapiVersion.Napi5, "10.17.0 | 12.11.0"],
7965
+ [NapiVersion.Napi1, "8.6.0 | 9.0.0 | 10.0.0"],
7966
+ [NapiVersion.Napi2, "8.10.0 | 9.3.0 | 10.0.0"],
7967
+ [NapiVersion.Napi3, "6.14.2 | 8.11.2 | 9.11.0 | 10.0.0"],
7968
+ [NapiVersion.Napi4, "10.16.0 | 11.8.0 | 12.0.0"],
7969
+ [NapiVersion.Napi5, "10.17.0 | 12.11.0 | 13.0.0"],
7965
7970
  [NapiVersion.Napi6, "10.20.0 | 12.17.0 | 14.0.0"],
7966
- [NapiVersion.Napi7, "10.23.0 | 12.19.0 | 14.12.0"],
7967
- [NapiVersion.Napi8, "12.22.0 | 14.17.0 | 15.12.0"]
7971
+ [NapiVersion.Napi7, "10.23.0 | 12.19.0 | 14.12.0 | 15.0.0"],
7972
+ [NapiVersion.Napi8, "12.22.0 | 14.17.0 | 15.12.0 | 16.0.0"],
7973
+ [NapiVersion.Napi9, "18.17.0 | 20.3.0 | 21.1.0"]
7968
7974
  ]);
7969
7975
  function parseNodeVersion(v) {
7970
7976
  const matches = v.match(/v?([0-9]+)\.([0-9]+)\.([0-9]+)/i);
@@ -10386,20 +10392,40 @@ var sortBy = baseRest_default(function(collection, iteratees) {
10386
10392
  var sortBy_default = sortBy;
10387
10393
 
10388
10394
  // dist/utils/config.js
10389
- async function readNapiConfig(path2) {
10395
+ async function readNapiConfig(path2, configPath) {
10396
+ if (configPath && !await fileExists(configPath)) {
10397
+ throw new Error(`NAPI-RS config not found at ${configPath}`);
10398
+ }
10390
10399
  if (!await fileExists(path2)) {
10391
- throw new Error(`napi-rs config not found at ${path2}`);
10400
+ throw new Error(`package.json not found at ${path2}`);
10392
10401
  }
10393
10402
  const content = await readFileAsync(path2, "utf8");
10394
10403
  let pkgJson2;
10395
10404
  try {
10396
10405
  pkgJson2 = JSON.parse(content);
10397
10406
  } catch (e) {
10398
- throw new Error("Failed to parse napi-rs config", {
10407
+ throw new Error(`Failed to parse package.json at ${path2}`, {
10399
10408
  cause: e
10400
10409
  });
10401
10410
  }
10411
+ let separatedConfig;
10412
+ if (configPath) {
10413
+ const configContent = await readFileAsync(configPath, "utf8");
10414
+ try {
10415
+ separatedConfig = JSON.parse(configContent);
10416
+ } catch (e) {
10417
+ throw new Error(`Failed to parse NAPI-RS config at ${configPath}`, {
10418
+ cause: e
10419
+ });
10420
+ }
10421
+ }
10402
10422
  const userNapiConfig = pkgJson2.napi ?? {};
10423
+ if (pkgJson2.napi && separatedConfig) {
10424
+ const pkgJsonPath = underline(path2);
10425
+ const configPathUnderline = underline(configPath);
10426
+ console.warn(yellow(`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`));
10427
+ Object.assign(userNapiConfig, separatedConfig);
10428
+ }
10403
10429
  const napiConfig = merge_default({
10404
10430
  binaryName: "index",
10405
10431
  packageName: pkgJson2.name,
@@ -10409,14 +10435,22 @@ async function readNapiConfig(path2) {
10409
10435
  }, omit_default(userNapiConfig, "targets"));
10410
10436
  let targets = userNapiConfig.targets ?? [];
10411
10437
  if (userNapiConfig?.name) {
10438
+ console.warn(`[DEPRECATED] napi.name is deprecated, use napi.binaryName instead.`);
10412
10439
  napiConfig.binaryName = userNapiConfig.name;
10413
10440
  }
10414
10441
  if (!targets.length) {
10442
+ let deprecatedWarned = false;
10443
+ const warning = `[DEPRECATED] napi.triples is deprecated, use napi.targets instead.`;
10415
10444
  if (userNapiConfig.triples?.defaults) {
10445
+ deprecatedWarned = true;
10446
+ console.warn(warning);
10416
10447
  targets = targets.concat(DEFAULT_TARGETS);
10417
10448
  }
10418
10449
  if (userNapiConfig.triples?.additional?.length) {
10419
10450
  targets = targets.concat(userNapiConfig.triples.additional);
10451
+ if (!deprecatedWarned) {
10452
+ console.warn(warning);
10453
+ }
10420
10454
  }
10421
10455
  }
10422
10456
  napiConfig.targets = targets.map(parseTriple);
@@ -14749,7 +14783,7 @@ async function buildProject(options) {
14749
14783
  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.");
14750
14784
  }
14751
14785
  const crateDir = (0, import_node_path2.parse)(pkg.manifest_path).dir;
14752
- 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.packageJsonPath ?? "package.json")));
14786
+ 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));
14753
14787
  return builder.build();
14754
14788
  }
14755
14789
  var Builder = class {
@@ -15206,6 +15240,9 @@ var BaseCreateNpmDirsCommand = class extends import_clipanion2.Command {
15206
15240
  cwd = import_clipanion2.Option.String("--cwd", process.cwd(), {
15207
15241
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
15208
15242
  });
15243
+ configPath = import_clipanion2.Option.String("--config-path,-c", {
15244
+ description: "Path to `napi` config json file"
15245
+ });
15209
15246
  packageJsonPath = import_clipanion2.Option.String("--package-json-path", "package.json", {
15210
15247
  description: "Path to `package.json`"
15211
15248
  });
@@ -15218,6 +15255,7 @@ var BaseCreateNpmDirsCommand = class extends import_clipanion2.Command {
15218
15255
  getOptions() {
15219
15256
  return {
15220
15257
  cwd: this.cwd,
15258
+ configPath: this.configPath,
15221
15259
  packageJsonPath: this.packageJsonPath,
15222
15260
  npmDir: this.npmDir,
15223
15261
  dryRun: this.dryRun
@@ -15257,8 +15295,8 @@ async function createNpmDirs(userOptions) {
15257
15295
  }
15258
15296
  const packageJsonPath = (0, import_path.resolve)(options.cwd, options.packageJsonPath);
15259
15297
  const npmPath = (0, import_path.resolve)(options.cwd, options.npmDir);
15260
- debug4(`Read content from [${packageJsonPath}]`);
15261
- const { targets, binaryName, packageName, packageJson } = await readNapiConfig(packageJsonPath);
15298
+ debug4(`Read content from [${options.configPath ?? packageJsonPath}]`);
15299
+ const { targets, binaryName, packageName, packageJson } = await readNapiConfig(packageJsonPath, options.configPath ? (0, import_path.resolve)(options.cwd, options.configPath) : void 0);
15262
15300
  for (const target of targets) {
15263
15301
  const targetDir = (0, import_path.join)(npmPath, `${target.platformArchABI}`);
15264
15302
  await mkdirAsync2(targetDir);
@@ -15537,13 +15575,16 @@ var BasePrePublishCommand = class extends import_clipanion4.Command {
15537
15575
  cwd = import_clipanion4.Option.String("--cwd", process.cwd(), {
15538
15576
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
15539
15577
  });
15578
+ configPath = import_clipanion4.Option.String("--config-path,-c", {
15579
+ description: "Path to `napi` config json file"
15580
+ });
15540
15581
  packageJsonPath = import_clipanion4.Option.String("--package-json-path", "package.json", {
15541
15582
  description: "Path to `package.json`"
15542
15583
  });
15543
15584
  npmDir = import_clipanion4.Option.String("--npm-dir", "npm", {
15544
15585
  description: "Path to the folder where the npm packages put"
15545
15586
  });
15546
- tagStyle = import_clipanion4.Option.String("--tag-style", "lerna", {
15587
+ tagStyle = import_clipanion4.Option.String("--tag-style,-t", "lerna", {
15547
15588
  description: "git tag style, `npm` or `lerna`"
15548
15589
  });
15549
15590
  ghRelease = import_clipanion4.Option.Boolean("--gh-release", true, {
@@ -15561,6 +15602,7 @@ var BasePrePublishCommand = class extends import_clipanion4.Command {
15561
15602
  getOptions() {
15562
15603
  return {
15563
15604
  cwd: this.cwd,
15605
+ configPath: this.configPath,
15564
15606
  packageJsonPath: this.packageJsonPath,
15565
15607
  npmDir: this.npmDir,
15566
15608
  tagStyle: this.tagStyle,
@@ -15596,6 +15638,9 @@ var BaseVersionCommand = class extends import_clipanion5.Command {
15596
15638
  cwd = import_clipanion5.Option.String("--cwd", process.cwd(), {
15597
15639
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
15598
15640
  });
15641
+ configPath = import_clipanion5.Option.String("--config-path,-c", {
15642
+ description: "Path to `napi` config json file"
15643
+ });
15599
15644
  packageJsonPath = import_clipanion5.Option.String("--package-json-path", "package.json", {
15600
15645
  description: "Path to `package.json`"
15601
15646
  });
@@ -15605,6 +15650,7 @@ var BaseVersionCommand = class extends import_clipanion5.Command {
15605
15650
  getOptions() {
15606
15651
  return {
15607
15652
  cwd: this.cwd,
15653
+ configPath: this.configPath,
15608
15654
  packageJsonPath: this.packageJsonPath,
15609
15655
  npmDir: this.npmDir
15610
15656
  };
@@ -15624,7 +15670,7 @@ var debug6 = debugFactory("version");
15624
15670
  async function version(userOptions) {
15625
15671
  const options = applyDefaultVersionOptions(userOptions);
15626
15672
  const packageJsonPath = (0, import_path3.resolve)(options.cwd, options.packageJsonPath);
15627
- const config = await readNapiConfig(packageJsonPath);
15673
+ const config = await readNapiConfig(packageJsonPath, options.configPath ? (0, import_path3.resolve)(options.cwd, options.configPath) : void 0);
15628
15674
  for (const target of config.targets) {
15629
15675
  const pkgDir = (0, import_path3.resolve)(options.cwd, options.npmDir, target.platformArchABI);
15630
15676
  debug6(`Update version to %i in [%i]`, config.packageJson.version, pkgDir);
@@ -15640,8 +15686,8 @@ async function prePublish(userOptions) {
15640
15686
  debug7("Receive pre-publish options:");
15641
15687
  debug7(" %O", userOptions);
15642
15688
  const options = applyDefaultPrePublishOptions(userOptions);
15643
- const packageJsonPath = (0, import_path4.relative)(options.cwd, options.packageJsonPath);
15644
- const { packageJson, targets, packageName, binaryName, npmClient } = await readNapiConfig(packageJsonPath);
15689
+ const packageJsonPath = (0, import_path4.resolve)(options.cwd, options.packageJsonPath);
15690
+ const { packageJson, targets, packageName, binaryName, npmClient } = await readNapiConfig(packageJsonPath, options.configPath ? (0, import_path4.resolve)(options.cwd, options.configPath) : void 0);
15645
15691
  async function createGhRelease(packageName2, version2) {
15646
15692
  if (!options.ghRelease) {
15647
15693
  return {
@@ -15780,11 +15826,14 @@ var import_clipanion6 = __toESM(require_advanced(), 1);
15780
15826
  var BaseRenameCommand = class extends import_clipanion6.Command {
15781
15827
  static paths = [["rename"]];
15782
15828
  static usage = import_clipanion6.Command.Usage({
15783
- description: "Rename the napi-rs project"
15829
+ description: "Rename the NAPI-RS project"
15784
15830
  });
15785
15831
  cwd = import_clipanion6.Option.String("--cwd", process.cwd(), {
15786
15832
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
15787
15833
  });
15834
+ configPath = import_clipanion6.Option.String("--config-path,-c", {
15835
+ description: "Path to `napi` config json file"
15836
+ });
15788
15837
  packageJsonPath = import_clipanion6.Option.String("--package-json-path", "package.json", {
15789
15838
  description: "Path to `package.json`"
15790
15839
  });
@@ -15812,6 +15861,7 @@ var BaseRenameCommand = class extends import_clipanion6.Command {
15812
15861
  getOptions() {
15813
15862
  return {
15814
15863
  cwd: this.cwd,
15864
+ configPath: this.configPath,
15815
15865
  packageJsonPath: this.packageJsonPath,
15816
15866
  npmDir: this.npmDir,
15817
15867
  name: this.$$name,
@@ -15846,6 +15896,14 @@ async function renameProject(userOptions) {
15846
15896
  packageName: options.packageName
15847
15897
  }, isNil_default)
15848
15898
  });
15899
+ if (options.configPath) {
15900
+ const configPath = (0, import_path5.resolve)(options.cwd, options.configPath);
15901
+ const configContent = await readFileAsync(configPath, "utf8");
15902
+ const configData = JSON.parse(configContent);
15903
+ configData.binaryName = options.binaryName;
15904
+ configData.packageName = options.packageName;
15905
+ await writeFileAsync(configPath, JSON.stringify(configData, null, 2));
15906
+ }
15849
15907
  await writeFileAsync(packageJsonPath, JSON.stringify(packageJsonData, null, 2));
15850
15908
  let tomlContent = await readFileAsync(cargoTomlPath, "utf8");
15851
15909
  tomlContent = tomlContent.replace(/name\s?=\s?"([\w+])"/, `name = "${options.binaryName}"`);
@@ -15872,6 +15930,9 @@ var BaseUniversalizeCommand = class extends import_clipanion7.Command {
15872
15930
  cwd = import_clipanion7.Option.String("--cwd", process.cwd(), {
15873
15931
  description: "The working directory of where napi command will be executed in, all other paths options are relative to this path"
15874
15932
  });
15933
+ configPath = import_clipanion7.Option.String("--config-path,-c", {
15934
+ description: "Path to `napi` config json file"
15935
+ });
15875
15936
  packageJsonPath = import_clipanion7.Option.String("--package-json-path", "package.json", {
15876
15937
  description: "Path to `package.json`"
15877
15938
  });
@@ -15881,6 +15942,7 @@ var BaseUniversalizeCommand = class extends import_clipanion7.Command {
15881
15942
  getOptions() {
15882
15943
  return {
15883
15944
  cwd: this.cwd,
15945
+ configPath: this.configPath,
15884
15946
  packageJsonPath: this.packageJsonPath,
15885
15947
  outputDir: this.outputDir
15886
15948
  };
@@ -15907,7 +15969,7 @@ var universalizers = {
15907
15969
  async function universalizeBinaries(userOptions) {
15908
15970
  const options = applyDefaultUniversalizeOptions(userOptions);
15909
15971
  const packageJsonPath = (0, import_path6.join)(options.cwd, options.packageJsonPath);
15910
- const config = await readNapiConfig(packageJsonPath);
15972
+ const config = await readNapiConfig(packageJsonPath, options.configPath ? (0, import_path6.resolve)(options.cwd, options.configPath) : void 0);
15911
15973
  const target = config.targets.find((t) => t.platform === process.platform && t.arch === "universal");
15912
15974
  if (!target) {
15913
15975
  throw new Error(`'universal' arch for platform '${process.platform}' not found in config!`);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,63 @@
1
+ import { unlink, writeFile } from 'node:fs/promises';
2
+ import { tmpdir } from 'node:os';
3
+ import { join } from 'node:path';
4
+ import ava from 'ava';
5
+ import { readNapiConfig, } from '../config.js';
6
+ const NON_EXISTENT_FILE = 'non-existent-file';
7
+ const test = ava;
8
+ test.before(async (t) => {
9
+ const tmp = tmpdir();
10
+ const configPath = join(tmp, 'napi.json');
11
+ const packageJson = join(tmp, 'package.json');
12
+ const pkgJson = {
13
+ name: '@napi-rs/testing',
14
+ version: '0.0.0',
15
+ napi: {
16
+ binaryName: 'testing',
17
+ packageName: '@napi-rs/testing',
18
+ targets: [
19
+ 'x86_64-unknown-linux-gnu',
20
+ 'x86_64-pc-windows-msvc',
21
+ 'x86_64-apple-darwin',
22
+ ],
23
+ },
24
+ };
25
+ await writeFile(packageJson, JSON.stringify(pkgJson, null, 2));
26
+ const config = {
27
+ binaryName: 'testing',
28
+ packageName: '@node-rs/testing',
29
+ targets: [
30
+ 'x86_64-unknown-linux-gnu',
31
+ 'x86_64-apple-darwin',
32
+ 'aarch64-apple-darwin',
33
+ ],
34
+ };
35
+ await writeFile(configPath, JSON.stringify(config, null, 2));
36
+ t.context = { configPath, config, packageJson, pkgJson };
37
+ });
38
+ test.after(async (t) => {
39
+ await unlink(t.context.configPath);
40
+ await unlink(t.context.packageJson);
41
+ });
42
+ test('should throw if package.json not found', async (t) => {
43
+ await t.throwsAsync(() => readNapiConfig(NON_EXISTENT_FILE), {
44
+ message: `package.json not found at ${NON_EXISTENT_FILE}`,
45
+ });
46
+ });
47
+ test('should throw if napi.json not found', async (t) => {
48
+ const { packageJson } = t.context;
49
+ await t.throwsAsync(() => readNapiConfig(packageJson, NON_EXISTENT_FILE), {
50
+ message: `NAPI-RS config not found at ${NON_EXISTENT_FILE}`,
51
+ });
52
+ });
53
+ test('should be able to read config from package.json', async (t) => {
54
+ const { packageJson } = t.context;
55
+ const config = await readNapiConfig(packageJson);
56
+ t.snapshot(config);
57
+ });
58
+ test('should be able to read config from napi.json', async (t) => {
59
+ const { packageJson, configPath } = t.context;
60
+ const config = await readNapiConfig(packageJson, configPath);
61
+ t.snapshot(config);
62
+ });
63
+ //# sourceMappingURL=config.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.spec.js","sourceRoot":"","sources":["../../../src/utils/__tests__/config.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC,OAAO,GAAe,MAAM,KAAK,CAAA;AAEjC,OAAO,EAGL,cAAc,GACf,MAAM,cAAc,CAAA;AAErB,MAAM,iBAAiB,GAAG,mBAAmB,CAAA;AAE7C,MAAM,IAAI,GAAG,GAKX,CAAA;AAEF,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;IACtB,MAAM,GAAG,GAAG,MAAM,EAAE,CAAA;IACpB,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;IACzC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAC7C,MAAM,OAAO,GAAG;QACd,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE;YACJ,UAAU,EAAE,SAAS;YACrB,WAAW,EAAE,kBAAkB;YAC/B,OAAO,EAAE;gBACP,0BAA0B;gBAC1B,wBAAwB;gBACxB,qBAAqB;aACtB;SACF;KACF,CAAA;IACD,MAAM,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IA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AClE,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC,OAAO,CAAA;IACjC,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAA;IAChD,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AACpB,CAAC,CAAC,CAAA;AAEF,IAAI,CAAC,8CAA8C,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC/D,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC,OAAO,CAAA;IAC7C,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AACpB,CAAC,CAAC,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { Target } from './target.js';
2
- interface UserNapiConfig {
2
+ export interface UserNapiConfig {
3
3
  /**
4
4
  * Name of the binary to be generated, default to `index`
5
5
  */
@@ -73,5 +73,4 @@ export type NapiConfig = Required<Pick<UserNapiConfig, 'binaryName' | 'packageNa
73
73
  targets: Target[];
74
74
  packageJson: CommonPackageJsonFields;
75
75
  };
76
- export declare function readNapiConfig(path: string): Promise<NapiConfig>;
77
- export {};
76
+ export declare function readNapiConfig(path: string, configPath?: string): Promise<NapiConfig>;
@@ -1,9 +1,13 @@
1
+ import { underline, yellow } from 'colorette';
1
2
  import { merge, omit } from 'lodash-es';
2
3
  import { fileExists, readFileAsync } from './misc.js';
3
4
  import { DEFAULT_TARGETS, parseTriple } from './target.js';
4
- export async function readNapiConfig(path) {
5
+ export async function readNapiConfig(path, configPath) {
6
+ if (configPath && !(await fileExists(configPath))) {
7
+ throw new Error(`NAPI-RS config not found at ${configPath}`);
8
+ }
5
9
  if (!(await fileExists(path))) {
6
- throw new Error(`napi-rs config not found at ${path}`);
10
+ throw new Error(`package.json not found at ${path}`);
7
11
  }
8
12
  // May support multiple config sources later on.
9
13
  const content = await readFileAsync(path, 'utf8');
@@ -12,11 +16,29 @@ export async function readNapiConfig(path) {
12
16
  pkgJson = JSON.parse(content);
13
17
  }
14
18
  catch (e) {
15
- throw new Error('Failed to parse napi-rs config', {
19
+ throw new Error(`Failed to parse package.json at ${path}`, {
16
20
  cause: e,
17
21
  });
18
22
  }
23
+ let separatedConfig;
24
+ if (configPath) {
25
+ const configContent = await readFileAsync(configPath, 'utf8');
26
+ try {
27
+ separatedConfig = JSON.parse(configContent);
28
+ }
29
+ catch (e) {
30
+ throw new Error(`Failed to parse NAPI-RS config at ${configPath}`, {
31
+ cause: e,
32
+ });
33
+ }
34
+ }
19
35
  const userNapiConfig = pkgJson.napi ?? {};
36
+ if (pkgJson.napi && separatedConfig) {
37
+ const pkgJsonPath = underline(path);
38
+ const configPathUnderline = underline(configPath);
39
+ console.warn(yellow(`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`));
40
+ Object.assign(userNapiConfig, separatedConfig);
41
+ }
20
42
  const napiConfig = merge({
21
43
  binaryName: 'index',
22
44
  packageName: pkgJson.name,
@@ -27,14 +49,22 @@ export async function readNapiConfig(path) {
27
49
  let targets = userNapiConfig.targets ?? [];
28
50
  // compatible with old config
29
51
  if (userNapiConfig?.name) {
52
+ console.warn(`[DEPRECATED] napi.name is deprecated, use napi.binaryName instead.`);
30
53
  napiConfig.binaryName = userNapiConfig.name;
31
54
  }
32
55
  if (!targets.length) {
56
+ let deprecatedWarned = false;
57
+ const warning = `[DEPRECATED] napi.triples is deprecated, use napi.targets instead.`;
33
58
  if (userNapiConfig.triples?.defaults) {
59
+ deprecatedWarned = true;
60
+ console.warn(warning);
34
61
  targets = targets.concat(DEFAULT_TARGETS);
35
62
  }
36
63
  if (userNapiConfig.triples?.additional?.length) {
37
64
  targets = targets.concat(userNapiConfig.triples.additional);
65
+ if (!deprecatedWarned) {
66
+ console.warn(warning);
67
+ }
38
68
  }
39
69
  }
40
70
  napiConfig.targets = targets.map(parseTriple);
@@ -1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