@napi-rs/cli 3.0.0-alpha.3 → 3.0.0-alpha.30

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 (209) hide show
  1. package/dist/api/artifacts.js +23 -7
  2. package/dist/api/artifacts.js.map +1 -0
  3. package/dist/api/build.d.ts +1 -1
  4. package/dist/api/build.js +184 -32
  5. package/dist/api/build.js.map +1 -0
  6. package/dist/api/create-npm-dirs.js +43 -7
  7. package/dist/api/create-npm-dirs.js.map +1 -0
  8. package/dist/api/new.js +47 -20
  9. package/dist/api/new.js.map +1 -0
  10. package/dist/api/pre-publish.js +10 -7
  11. package/dist/api/pre-publish.js.map +1 -0
  12. package/dist/api/rename.js +10 -1
  13. package/dist/api/rename.js.map +1 -0
  14. package/dist/api/templates/.gitignore.d.ts +1 -1
  15. package/dist/api/templates/.gitignore.js +2 -0
  16. package/dist/api/templates/.gitignore.js.map +1 -0
  17. package/dist/api/templates/.npmignore.js +1 -0
  18. package/dist/api/templates/.npmignore.js.map +1 -0
  19. package/dist/api/templates/build.rs.js +1 -0
  20. package/dist/api/templates/build.rs.js.map +1 -0
  21. package/dist/api/templates/cargo.toml.js +1 -0
  22. package/dist/api/templates/cargo.toml.js.map +1 -0
  23. package/dist/api/templates/ci-template.d.ts +2 -1
  24. package/dist/api/templates/ci-template.js +156 -157
  25. package/dist/api/templates/ci-template.js.map +1 -0
  26. package/dist/api/templates/ci.yml.d.ts +2 -1
  27. package/dist/api/templates/ci.yml.js +19 -4
  28. package/dist/api/templates/ci.yml.js.map +1 -0
  29. package/dist/api/templates/index.js +1 -0
  30. package/dist/api/templates/index.js.map +1 -0
  31. package/dist/api/templates/js-binding.d.ts +1 -1
  32. package/dist/api/templates/js-binding.js +320 -107
  33. package/dist/api/templates/js-binding.js.map +1 -0
  34. package/dist/api/templates/lib.rs.js +2 -4
  35. package/dist/api/templates/lib.rs.js.map +1 -0
  36. package/dist/api/templates/load-wasi-template.d.ts +1 -0
  37. package/dist/api/templates/load-wasi-template.js +78 -0
  38. package/dist/api/templates/load-wasi-template.js.map +1 -0
  39. package/dist/api/templates/package.json.d.ts +9 -2
  40. package/dist/api/templates/package.json.js +55 -28
  41. package/dist/api/templates/package.json.js.map +1 -0
  42. package/dist/api/templates/wasi-worker-template.d.ts +1 -0
  43. package/dist/api/templates/wasi-worker-template.js +53 -0
  44. package/dist/api/templates/wasi-worker-template.js.map +1 -0
  45. package/dist/api/universalize.js +4 -3
  46. package/dist/api/universalize.js.map +1 -0
  47. package/dist/api/version.js +3 -2
  48. package/dist/api/version.js.map +1 -0
  49. package/dist/cli.js +1 -0
  50. package/dist/cli.js.map +1 -0
  51. package/dist/commands/artifacts.js +3 -2
  52. package/dist/commands/artifacts.js.map +1 -0
  53. package/dist/commands/build.js +2 -1
  54. package/dist/commands/build.js.map +1 -0
  55. package/dist/commands/create-npm-dirs.js +1 -0
  56. package/dist/commands/create-npm-dirs.js.map +1 -0
  57. package/dist/commands/help.js +1 -0
  58. package/dist/commands/help.js.map +1 -0
  59. package/dist/commands/new.js +15 -7
  60. package/dist/commands/new.js.map +1 -0
  61. package/dist/commands/pre-publish.js +1 -0
  62. package/dist/commands/pre-publish.js.map +1 -0
  63. package/dist/commands/rename.js +1 -0
  64. package/dist/commands/rename.js.map +1 -0
  65. package/dist/commands/universalize.js +1 -0
  66. package/dist/commands/universalize.js.map +1 -0
  67. package/dist/commands/version.js +1 -0
  68. package/dist/commands/version.js.map +1 -0
  69. package/dist/def/artifacts.d.ts +21 -1
  70. package/dist/def/artifacts.js +11 -2
  71. package/dist/def/artifacts.js.map +1 -0
  72. package/dist/def/build.d.ts +32 -2
  73. package/dist/def/build.js +23 -2
  74. package/dist/def/build.js.map +1 -0
  75. package/dist/def/create-npm-dirs.d.ts +10 -0
  76. package/dist/def/create-npm-dirs.js +5 -0
  77. package/dist/def/create-npm-dirs.js.map +1 -0
  78. package/dist/def/new.d.ts +24 -6
  79. package/dist/def/new.js +12 -1
  80. package/dist/def/new.js.map +1 -0
  81. package/dist/def/pre-publish.d.ts +10 -0
  82. package/dist/def/pre-publish.js +8 -3
  83. package/dist/def/pre-publish.js.map +1 -0
  84. package/dist/def/rename.d.ts +11 -1
  85. package/dist/def/rename.js +6 -1
  86. package/dist/def/rename.js.map +1 -0
  87. package/dist/def/universalize.d.ts +10 -0
  88. package/dist/def/universalize.js +5 -0
  89. package/dist/def/universalize.js.map +1 -0
  90. package/dist/def/version.d.ts +10 -0
  91. package/dist/def/version.js +5 -0
  92. package/dist/def/version.js.map +1 -0
  93. package/dist/index.cjs +6020 -8093
  94. package/dist/index.d.ts +1 -0
  95. package/dist/index.js +2 -0
  96. package/dist/index.js.map +1 -0
  97. package/dist/utils/__tests__/config.spec.d.ts +1 -0
  98. package/dist/utils/__tests__/config.spec.js +63 -0
  99. package/dist/utils/__tests__/config.spec.js.map +1 -0
  100. package/dist/utils/__tests__/target.spec.js +1 -0
  101. package/dist/utils/__tests__/target.spec.js.map +1 -0
  102. package/dist/utils/__tests__/typegen.spec.js +9 -4
  103. package/dist/utils/__tests__/typegen.spec.js.map +1 -0
  104. package/dist/utils/__tests__/version.spec.js +1 -0
  105. package/dist/utils/__tests__/version.spec.js.map +1 -0
  106. package/dist/utils/cargo.js +2 -1
  107. package/dist/utils/cargo.js.map +1 -0
  108. package/dist/utils/ci.js +10 -0
  109. package/dist/utils/ci.js.map +1 -0
  110. package/dist/utils/config.d.ts +24 -5
  111. package/dist/utils/config.js +39 -6
  112. package/dist/utils/config.js.map +1 -0
  113. package/dist/utils/index.js +1 -0
  114. package/dist/utils/index.js.map +1 -0
  115. package/dist/utils/log.js +1 -0
  116. package/dist/utils/log.js.map +1 -0
  117. package/dist/utils/metadata.js +3 -2
  118. package/dist/utils/metadata.js.map +1 -0
  119. package/dist/utils/misc.d.ts +1 -1
  120. package/dist/utils/misc.js +4 -3
  121. package/dist/utils/misc.js.map +1 -0
  122. package/dist/utils/target.d.ts +9 -5
  123. package/dist/utils/target.js +20 -1
  124. package/dist/utils/target.js.map +1 -0
  125. package/dist/utils/typegen.d.ts +4 -1
  126. package/dist/utils/typegen.js +27 -6
  127. package/dist/utils/typegen.js.map +1 -0
  128. package/dist/utils/version.d.ts +2 -1
  129. package/dist/utils/version.js +13 -10
  130. package/dist/utils/version.js.map +1 -0
  131. package/package.json +50 -15
  132. package/src/api/artifacts.ts +53 -9
  133. package/src/api/build.ts +289 -39
  134. package/src/api/create-npm-dirs.ts +51 -7
  135. package/src/api/new.ts +69 -33
  136. package/src/api/pre-publish.ts +21 -12
  137. package/src/api/rename.ts +10 -1
  138. package/src/api/templates/.gitignore.ts +1 -0
  139. package/src/api/templates/ci-template.ts +157 -157
  140. package/src/api/templates/ci.yml.ts +19 -4
  141. package/src/api/templates/js-binding.ts +312 -102
  142. package/src/api/templates/lib.rs.ts +1 -4
  143. package/src/api/templates/load-wasi-template.ts +81 -0
  144. package/src/api/templates/package.json.ts +78 -27
  145. package/src/api/templates/wasi-worker-template.ts +52 -0
  146. package/src/api/universalize.ts +6 -3
  147. package/src/api/version.ts +5 -2
  148. package/src/commands/artifacts.ts +2 -2
  149. package/src/commands/build.ts +1 -1
  150. package/src/commands/new.ts +14 -8
  151. package/src/def/artifacts.ts +22 -3
  152. package/src/def/build.ts +51 -4
  153. package/src/def/create-npm-dirs.ts +9 -0
  154. package/src/def/new.ts +28 -3
  155. package/src/def/pre-publish.ts +12 -3
  156. package/src/def/rename.ts +11 -2
  157. package/src/def/universalize.ts +9 -0
  158. package/src/def/version.ts +9 -0
  159. package/src/index.ts +2 -0
  160. package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
  161. package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
  162. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +14 -0
  163. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  164. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +555 -0
  165. package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
  166. package/src/utils/__tests__/__snapshots__/version.spec.ts.md +9 -8
  167. package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
  168. package/src/utils/__tests__/config.spec.ts +81 -0
  169. package/src/utils/__tests__/typegen.spec.ts +19 -4
  170. package/src/utils/cargo.ts +1 -1
  171. package/src/utils/ci.ts +9 -0
  172. package/src/utils/config.ts +84 -9
  173. package/src/utils/metadata.ts +2 -2
  174. package/src/utils/misc.ts +11 -3
  175. package/src/utils/target.ts +28 -7
  176. package/src/utils/typegen.ts +30 -5
  177. package/src/utils/version.ts +11 -9
  178. package/dist/def/commands/artifacts.d.ts +0 -15
  179. package/dist/def/commands/artifacts.js +0 -29
  180. package/dist/def/commands/build.d.ts +0 -53
  181. package/dist/def/commands/build.js +0 -105
  182. package/dist/def/commands/create-npm-dirs.d.ts +0 -15
  183. package/dist/def/commands/create-npm-dirs.js +0 -29
  184. package/dist/def/commands/new.d.ts +0 -27
  185. package/dist/def/commands/new.js +0 -53
  186. package/dist/def/commands/pre-publish.d.ts +0 -23
  187. package/dist/def/commands/pre-publish.js +0 -45
  188. package/dist/def/commands/rename.d.ts +0 -25
  189. package/dist/def/commands/rename.js +0 -49
  190. package/dist/def/commands/universalize.d.ts +0 -13
  191. package/dist/def/commands/universalize.js +0 -25
  192. package/dist/def/commands/version.d.ts +0 -13
  193. package/dist/def/commands/version.js +0 -25
  194. package/dist/def/options/artifacts.d.ts +0 -35
  195. package/dist/def/options/artifacts.js +0 -11
  196. package/dist/def/options/build.d.ts +0 -97
  197. package/dist/def/options/build.js +0 -3
  198. package/dist/def/options/create-npm-dirs.d.ts +0 -35
  199. package/dist/def/options/create-npm-dirs.js +0 -11
  200. package/dist/def/options/new.d.ts +0 -79
  201. package/dist/def/options/new.js +0 -15
  202. package/dist/def/options/pre-publish.d.ts +0 -65
  203. package/dist/def/options/pre-publish.js +0 -13
  204. package/dist/def/options/rename.d.ts +0 -75
  205. package/dist/def/options/rename.js +0 -11
  206. package/dist/def/options/universalize.d.ts +0 -28
  207. package/dist/def/options/universalize.js +0 -10
  208. package/dist/def/options/version.d.ts +0 -28
  209. package/dist/def/options/version.js +0 -10
@@ -1,10 +1,21 @@
1
- export const createPackageJson = ({
1
+ import type {
2
+ CommonPackageJsonFields,
3
+ SupportedTestFramework,
4
+ } from '../../utils/config.js'
5
+ import { UNIVERSAL_TARGETS } from '../../utils/target.js'
6
+
7
+ export interface PackageMeta {
8
+ 'dist-tags': { [index: string]: string }
9
+ }
10
+
11
+ export const createPackageJson = async ({
2
12
  name,
3
13
  binaryName,
4
14
  targets,
5
15
  license,
6
16
  engineRequirement,
7
17
  cliVersion,
18
+ testFramework,
8
19
  }: {
9
20
  name: string
10
21
  binaryName: string
@@ -12,32 +23,72 @@ export const createPackageJson = ({
12
23
  license: string
13
24
  engineRequirement: string
14
25
  cliVersion: string
26
+ testFramework: SupportedTestFramework
15
27
  }) => {
16
- return `{
17
- "name": "${name}",
18
- "version": "1.0.0",
19
- "main": "index.js",
20
- "types": "index.d.ts",
21
- "license": "${license}",
22
- "engines": {
23
- "node": "${engineRequirement}"
24
- },
25
- "napi": {
26
- "binaryName": "${binaryName}",
27
- "targets": [
28
- ${targets.map((t) => `"${t}"`).join(',\n ')}
29
- ]
30
- },
31
- "scripts": {
32
- "test": "node -e \\"assert(require('.').sum(1, 2) === 3)\\"",
33
- "build": "napi build --release --platform --strip",
34
- "build:debug": "napi build",
35
- "prepublishOnly": "napi prepublish -t npm",
36
- "artifacts": "napi artifacts",
37
- "version": "napi version"
38
- },
39
- "devDependencies": {
40
- "@napi-rs/cli": "^${cliVersion}"
28
+ const hasWasmTarget = targets.some((t) => t.includes('wasm'))
29
+ const universalTargets = targets.filter(
30
+ (t) => t in UNIVERSAL_TARGETS,
31
+ ) as (keyof typeof UNIVERSAL_TARGETS)[]
32
+ const unifiedtargets = universalTargets.length
33
+ ? targets.filter(
34
+ (target) =>
35
+ !universalTargets.some((t) => {
36
+ // @ts-expect-error
37
+ return UNIVERSAL_TARGETS[t].includes(target)
38
+ }),
39
+ )
40
+ : targets
41
+ const content: CommonPackageJsonFields = {
42
+ name,
43
+ version: '0.0.0',
44
+ license,
45
+ engines: {
46
+ node: engineRequirement,
47
+ },
48
+ type: 'commonjs',
49
+ main: 'index.js',
50
+ types: 'index.d.ts',
51
+ module: undefined,
52
+ exports: undefined,
53
+ napi: {
54
+ binaryName,
55
+ targets: unifiedtargets,
56
+ },
57
+ scripts: {
58
+ test: testFramework,
59
+ build: 'napi build --release --platform --strip',
60
+ 'build:debug': 'napi build',
61
+ prepublishOnly: 'napi prepublish -t npm',
62
+ artifacts: 'napi artifacts',
63
+ version: 'napi version',
64
+ },
65
+ devDependencies: {
66
+ '@napi-rs/cli': `^${cliVersion}`,
67
+ },
68
+ }
69
+
70
+ if (testFramework === 'ava') {
71
+ const avaMeta = await fetch(`https://registry.npmjs.org/ava`).then(
72
+ (res) => res.json() as Promise<PackageMeta>,
73
+ )
74
+ content.devDependencies!['ava'] = `^${avaMeta['dist-tags'].latest}`
75
+ content.ava = {
76
+ timeout: '1m',
77
+ }
78
+ }
79
+
80
+ if (hasWasmTarget) {
81
+ const emnapiCoreMeta = await fetch(
82
+ `https://registry.npmjs.org/@emnapi/core`,
83
+ ).then((res) => res.json() as Promise<PackageMeta>)
84
+ const latest = emnapiCoreMeta['dist-tags'].latest
85
+ content.devDependencies!['@emnapi/core'] = `^${latest}`
86
+ const emnapiRuntimeMeta = await fetch(
87
+ `https://registry.npmjs.org/@emnapi/runtime`,
88
+ ).then((res) => res.json() as Promise<PackageMeta>)
89
+ const runtimeLatest = emnapiRuntimeMeta['dist-tags'].latest
90
+ content.devDependencies!['@emnapi/runtime'] = `^${runtimeLatest}`
41
91
  }
42
- }`
92
+
93
+ return JSON.stringify(content, null, 2)
43
94
  }
@@ -0,0 +1,52 @@
1
+ export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { parentPort, Worker } from "node:worker_threads";
4
+
5
+ import { instantiateNapiModuleSync, MessageHandler } from "@emnapi/core";
6
+ import { WASI } from "@tybys/wasm-util";
7
+
8
+ const require = createRequire(import.meta.url);
9
+
10
+ if (parentPort) {
11
+ parentPort.on("message", (data) => {
12
+ globalThis.onmessage({ data });
13
+ });
14
+ }
15
+
16
+ Object.assign(globalThis, {
17
+ self: globalThis,
18
+ require,
19
+ Worker,
20
+ importScripts: function (f) {
21
+ ;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
22
+ },
23
+ postMessage: function (msg) {
24
+ if (parentPort) {
25
+ parentPort.postMessage(msg);
26
+ }
27
+ },
28
+ });
29
+
30
+ const handler = new MessageHandler({
31
+ onLoad({ wasmModule, wasmMemory }) {
32
+ const wasi = new WASI({ fs });
33
+
34
+ return instantiateNapiModuleSync(wasmModule, {
35
+ childThread: true,
36
+ wasi,
37
+ overwriteImports(importObject) {
38
+ importObject.env = {
39
+ ...importObject.env,
40
+ ...importObject.napi,
41
+ ...importObject.emnapi,
42
+ memory: wasmMemory
43
+ };
44
+ },
45
+ });
46
+ },
47
+ });
48
+
49
+ globalThis.onmessage = function (e) {
50
+ handler.handle(e);
51
+ };
52
+ `
@@ -1,5 +1,5 @@
1
- import { spawnSync } from 'child_process'
2
- import { join, resolve } from 'path'
1
+ import { spawnSync } from 'node:child_process'
2
+ import { join, resolve } from 'node:path'
3
3
 
4
4
  import {
5
5
  applyDefaultUniversalizeOptions,
@@ -27,7 +27,10 @@ export async function universalizeBinaries(userOptions: UniversalizeOptions) {
27
27
 
28
28
  const packageJsonPath = join(options.cwd, options.packageJsonPath)
29
29
 
30
- const config = await readNapiConfig(packageJsonPath)
30
+ const config = await readNapiConfig(
31
+ packageJsonPath,
32
+ options.configPath ? resolve(options.cwd, options.configPath) : undefined,
33
+ )
31
34
 
32
35
  const target = config.targets.find(
33
36
  (t) => t.platform === process.platform && t.arch === 'universal',
@@ -1,4 +1,4 @@
1
- import { join, resolve } from 'path'
1
+ import { join, resolve } from 'node:path'
2
2
 
3
3
  import { applyDefaultVersionOptions, VersionOptions } from '../def/version.js'
4
4
  import {
@@ -13,7 +13,10 @@ export async function version(userOptions: VersionOptions) {
13
13
  const options = applyDefaultVersionOptions(userOptions)
14
14
  const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
15
15
 
16
- const config = await readNapiConfig(packageJsonPath)
16
+ const config = await readNapiConfig(
17
+ packageJsonPath,
18
+ options.configPath ? resolve(options.cwd, options.configPath) : undefined,
19
+ )
17
20
 
18
21
  for (const target of config.targets) {
19
22
  const pkgDir = resolve(options.cwd, options.npmDir, target.platformArchABI)
@@ -8,9 +8,9 @@ export class ArtifactsCommand extends BaseArtifactsCommand {
8
8
  description: 'Copy artifacts from Github Actions into specified dir',
9
9
  examples: [
10
10
  [
11
- '$0 artifacts --dir . --dist ./npm',
11
+ '$0 artifacts --output-dir ./artifacts --dist ./npm',
12
12
  `Copy [binaryName].[platform].node under current dir(.) into packages under npm dir.
13
- e.g: index.linux-x64-gnu.node --> ./npm/linux-x64-gnu/index.node`,
13
+ e.g: index.linux-x64-gnu.node --> ./npm/linux-x64-gnu/index.linux-x64-gnu.node`,
14
14
  ],
15
15
  ],
16
16
  })
@@ -1,4 +1,4 @@
1
- import { execSync } from 'child_process'
1
+ import { execSync } from 'node:child_process'
2
2
 
3
3
  import { Option } from 'clipanion'
4
4
 
@@ -1,4 +1,4 @@
1
- import path from 'path'
1
+ import path from 'node:path'
2
2
 
3
3
  import { Option } from 'clipanion'
4
4
  import inquirer from 'inquirer'
@@ -16,7 +16,7 @@ import { napiEngineRequirement } from '../utils/version.js'
16
16
  const debug = debugFactory('new')
17
17
 
18
18
  export class NewCommand extends BaseNewCommand {
19
- interactive = Option.Boolean('--interactive,-i', false, {
19
+ interactive = Option.Boolean('--interactive,-i', true, {
20
20
  description:
21
21
  'Ask project basic information interactively without just using the default.',
22
22
  })
@@ -37,9 +37,19 @@ export class NewCommand extends BaseNewCommand {
37
37
  const cmdOptions = super.getOptions()
38
38
 
39
39
  if (this.interactive) {
40
+ const targetPath: string = cmdOptions.path
41
+ ? cmdOptions.path
42
+ : await inquirer
43
+ .prompt({
44
+ type: 'input',
45
+ name: 'path',
46
+ message: 'Target path to create the project, relative to cwd',
47
+ })
48
+ .then(({ path }) => path)
49
+ cmdOptions.path = targetPath
40
50
  return {
41
51
  ...cmdOptions,
42
- name: await this.fetchName(path.parse(cmdOptions.path).base),
52
+ name: await this.fetchName(path.parse(targetPath).base),
43
53
  minNodeApiVersion: await this.fetchNapiVersion(),
44
54
  targets: await this.fetchTargets(),
45
55
  license: await this.fetchLicense(),
@@ -94,10 +104,6 @@ export class NewCommand extends BaseNewCommand {
94
104
  }
95
105
 
96
106
  private async fetchTargets(): Promise<TargetTriple[]> {
97
- if (this.enableDefaultTargets) {
98
- return DEFAULT_TARGETS.concat()
99
- }
100
-
101
107
  if (this.enableAllTargets) {
102
108
  return AVAILABLE_TARGETS.concat()
103
109
  }
@@ -107,7 +113,7 @@ export class NewCommand extends BaseNewCommand {
107
113
  type: 'checkbox',
108
114
  loop: false,
109
115
  message: 'Choose target(s) your crate will be compiled to',
110
- default: DEFAULT_TARGETS,
116
+ default: this.enableDefaultTargets ? DEFAULT_TARGETS : [],
111
117
  choices: AVAILABLE_TARGETS,
112
118
  })
113
119
 
@@ -15,11 +15,15 @@ export abstract class BaseArtifactsCommand extends Command {
15
15
  'The working directory of where napi command will be executed in, all other paths options are relative to this path',
16
16
  })
17
17
 
18
+ configPath?: string = Option.String('--config-path,-c', {
19
+ description: 'Path to `napi` config json file',
20
+ })
21
+
18
22
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
19
23
  description: 'Path to `package.json`',
20
24
  })
21
25
 
22
- outputDir = Option.String('--output-dir,-o', './', {
26
+ outputDir = Option.String('--output-dir,-o,-d', './artifacts', {
23
27
  description:
24
28
  'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
25
29
  })
@@ -28,12 +32,19 @@ export abstract class BaseArtifactsCommand extends Command {
28
32
  description: 'Path to the folder where the npm packages put',
29
33
  })
30
34
 
35
+ buildOutputDir?: string = Option.String('--build-output-dir', {
36
+ description:
37
+ 'Path to the build output dir, only needed when targets contains `wasm32-wasi-*`',
38
+ })
39
+
31
40
  getOptions() {
32
41
  return {
33
42
  cwd: this.cwd,
43
+ configPath: this.configPath,
34
44
  packageJsonPath: this.packageJsonPath,
35
45
  outputDir: this.outputDir,
36
46
  npmDir: this.npmDir,
47
+ buildOutputDir: this.buildOutputDir,
37
48
  }
38
49
  }
39
50
  }
@@ -48,6 +59,10 @@ export interface ArtifactsOptions {
48
59
  * @default process.cwd()
49
60
  */
50
61
  cwd?: string
62
+ /**
63
+ * Path to `napi` config json file
64
+ */
65
+ configPath?: string
51
66
  /**
52
67
  * Path to `package.json`
53
68
  *
@@ -57,7 +72,7 @@ export interface ArtifactsOptions {
57
72
  /**
58
73
  * Path to the folder where all built `.node` files put, same as `--output-dir` of build command
59
74
  *
60
- * @default './'
75
+ * @default './artifacts'
61
76
  */
62
77
  outputDir?: string
63
78
  /**
@@ -66,13 +81,17 @@ export interface ArtifactsOptions {
66
81
  * @default 'npm'
67
82
  */
68
83
  npmDir?: string
84
+ /**
85
+ * Path to the build output dir, only needed when targets contains `wasm32-wasi-*`
86
+ */
87
+ buildOutputDir?: string
69
88
  }
70
89
 
71
90
  export function applyDefaultArtifactsOptions(options: ArtifactsOptions) {
72
91
  return {
73
92
  cwd: process.cwd(),
74
93
  packageJsonPath: 'package.json',
75
- outputDir: './',
94
+ outputDir: './artifacts',
76
95
  npmDir: 'npm',
77
96
  ...options,
78
97
  }
package/src/def/build.ts CHANGED
@@ -6,7 +6,7 @@ export abstract class BaseBuildCommand extends Command {
6
6
  static paths = [['build']]
7
7
 
8
8
  static usage = Command.Usage({
9
- description: 'Build the napi-rs project',
9
+ description: 'Build the NAPI-RS project',
10
10
  })
11
11
 
12
12
  target?: string = Option.String('--target,-t', {
@@ -23,6 +23,10 @@ export abstract class BaseBuildCommand extends Command {
23
23
  description: 'Path to `Cargo.toml`',
24
24
  })
25
25
 
26
+ configPath?: string = Option.String('--config-path,-c', {
27
+ description: 'Path to `napi` config json file',
28
+ })
29
+
26
30
  packageJsonPath?: string = Option.String('--package-json-path', {
27
31
  description: 'Path to `package.json`',
28
32
  })
@@ -47,6 +51,10 @@ export abstract class BaseBuildCommand extends Command {
47
51
  'Package name in generated js binding file. Only works with `--platform` flag',
48
52
  })
49
53
 
54
+ constEnum?: boolean = Option.Boolean('--const-enum', {
55
+ description: 'Whether generate const enum for typescript bindings',
56
+ })
57
+
50
58
  jsBinding?: string = Option.String('--js', {
51
59
  description:
52
60
  'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output_dir`.',
@@ -92,14 +100,28 @@ export abstract class BaseBuildCommand extends Command {
92
100
  description: 'Build the specified library or the one at cwd',
93
101
  })
94
102
 
103
+ profile?: string = Option.String('--profile', {
104
+ description: 'Build artifacts with the specified profile',
105
+ })
106
+
95
107
  crossCompile?: boolean = Option.Boolean('--cross-compile,-x', {
96
108
  description:
97
109
  '[experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform',
98
110
  })
99
111
 
112
+ useCross?: boolean = Option.Boolean('--use-cross', {
113
+ description:
114
+ '[experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`',
115
+ })
116
+
117
+ useNapiCross?: boolean = Option.Boolean('--use-napi-cross', {
118
+ description:
119
+ '[experimental] use @napi-rs/cross-toolchain to cross-compile Linux arm/arm64/x64 gnu targets.',
120
+ })
121
+
100
122
  watch?: boolean = Option.Boolean('--watch,-w', {
101
123
  description:
102
- 'watch the crate changes and build continiously with `cargo-watch` crates',
124
+ 'watch the crate changes and build continuously with `cargo-watch` crates',
103
125
  })
104
126
 
105
127
  features?: string[] = Option.Array('--features,-F', {
@@ -119,11 +141,13 @@ export abstract class BaseBuildCommand extends Command {
119
141
  target: this.target,
120
142
  cwd: this.cwd,
121
143
  manifestPath: this.manifestPath,
144
+ configPath: this.configPath,
122
145
  packageJsonPath: this.packageJsonPath,
123
146
  targetDir: this.targetDir,
124
147
  outputDir: this.outputDir,
125
148
  platform: this.platform,
126
149
  jsPackageName: this.jsPackageName,
150
+ constEnum: this.constEnum,
127
151
  jsBinding: this.jsBinding,
128
152
  noJsBinding: this.noJsBinding,
129
153
  dts: this.dts,
@@ -134,7 +158,10 @@ export abstract class BaseBuildCommand extends Command {
134
158
  verbose: this.verbose,
135
159
  bin: this.bin,
136
160
  package: this.package,
161
+ profile: this.profile,
137
162
  crossCompile: this.crossCompile,
163
+ useCross: this.useCross,
164
+ useNapiCross: this.useNapiCross,
138
165
  watch: this.watch,
139
166
  features: this.features,
140
167
  allFeatures: this.allFeatures,
@@ -144,7 +171,7 @@ export abstract class BaseBuildCommand extends Command {
144
171
  }
145
172
 
146
173
  /**
147
- * Build the napi-rs project
174
+ * Build the NAPI-RS project
148
175
  */
149
176
  export interface BuildOptions {
150
177
  /**
@@ -159,6 +186,10 @@ export interface BuildOptions {
159
186
  * Path to `Cargo.toml`
160
187
  */
161
188
  manifestPath?: string
189
+ /**
190
+ * Path to `napi` config json file
191
+ */
192
+ configPath?: string
162
193
  /**
163
194
  * Path to `package.json`
164
195
  */
@@ -179,6 +210,10 @@ export interface BuildOptions {
179
210
  * Package name in generated js binding file. Only works with `--platform` flag
180
211
  */
181
212
  jsPackageName?: string
213
+ /**
214
+ * Whether generate const enum for typescript bindings
215
+ */
216
+ constEnum?: boolean
182
217
  /**
183
218
  * Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output_dir`.
184
219
  */
@@ -219,12 +254,24 @@ export interface BuildOptions {
219
254
  * Build the specified library or the one at cwd
220
255
  */
221
256
  package?: string
257
+ /**
258
+ * Build artifacts with the specified profile
259
+ */
260
+ profile?: string
222
261
  /**
223
262
  * [experimental] cross-compile for the specified target with `cargo-xwin` on windows and `cargo-zigbuild` on other platform
224
263
  */
225
264
  crossCompile?: boolean
226
265
  /**
227
- * watch the crate changes and build continiously with `cargo-watch` crates
266
+ * [experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`
267
+ */
268
+ useCross?: boolean
269
+ /**
270
+ * [experimental] use @napi-rs/cross-toolchain to cross-compile Linux arm/arm64/x64 gnu targets.
271
+ */
272
+ useNapiCross?: boolean
273
+ /**
274
+ * watch the crate changes and build continuously with `cargo-watch` crates
228
275
  */
229
276
  watch?: boolean
230
277
  /**
@@ -14,6 +14,10 @@ export abstract class BaseCreateNpmDirsCommand extends Command {
14
14
  'The working directory of where napi command will be executed in, all other paths options are relative to this path',
15
15
  })
16
16
 
17
+ configPath?: string = Option.String('--config-path,-c', {
18
+ description: 'Path to `napi` config json file',
19
+ })
20
+
17
21
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
18
22
  description: 'Path to `package.json`',
19
23
  })
@@ -29,6 +33,7 @@ export abstract class BaseCreateNpmDirsCommand extends Command {
29
33
  getOptions() {
30
34
  return {
31
35
  cwd: this.cwd,
36
+ configPath: this.configPath,
32
37
  packageJsonPath: this.packageJsonPath,
33
38
  npmDir: this.npmDir,
34
39
  dryRun: this.dryRun,
@@ -46,6 +51,10 @@ export interface CreateNpmDirsOptions {
46
51
  * @default process.cwd()
47
52
  */
48
53
  cwd?: string
54
+ /**
55
+ * Path to `napi` config json file
56
+ */
57
+ configPath?: string
49
58
  /**
50
59
  * Path to `package.json`
51
60
  *
package/src/def/new.ts CHANGED
@@ -10,7 +10,7 @@ export abstract class BaseNewCommand extends Command {
10
10
  description: 'Create a new project with pre-configured boilerplate',
11
11
  })
12
12
 
13
- $$path = Option.String({ required: true })
13
+ $$path = Option.String({ required: false })
14
14
 
15
15
  $$name?: string = Option.String('--name,-n', {
16
16
  description:
@@ -22,6 +22,10 @@ export abstract class BaseNewCommand extends Command {
22
22
  description: 'The minimum Node-API version to support',
23
23
  })
24
24
 
25
+ packageManager = Option.String('--package-manager', 'yarn', {
26
+ description: 'The package manager to use. Only support yarn 4.x for now.',
27
+ })
28
+
25
29
  license = Option.String('--license,-l', 'MIT', {
26
30
  description: 'License for open-sourced project',
27
31
  })
@@ -47,6 +51,11 @@ export abstract class BaseNewCommand extends Command {
47
51
  description: 'Whether generate preconfigured GitHub Actions workflow',
48
52
  })
49
53
 
54
+ testFramework = Option.String('--test-framework', 'ava', {
55
+ description:
56
+ 'The JavaScript test framework to use, only support `ava` for now',
57
+ })
58
+
50
59
  dryRun = Option.Boolean('--dry-run', false, {
51
60
  description: 'Whether to run the command in dry-run mode',
52
61
  })
@@ -56,12 +65,14 @@ export abstract class BaseNewCommand extends Command {
56
65
  path: this.$$path,
57
66
  name: this.$$name,
58
67
  minNodeApiVersion: this.minNodeApiVersion,
68
+ packageManager: this.packageManager,
59
69
  license: this.license,
60
70
  targets: this.targets,
61
71
  enableDefaultTargets: this.enableDefaultTargets,
62
72
  enableAllTargets: this.enableAllTargets,
63
73
  enableTypeDef: this.enableTypeDef,
64
74
  enableGithubActions: this.enableGithubActions,
75
+ testFramework: this.testFramework,
65
76
  dryRun: this.dryRun,
66
77
  }
67
78
  }
@@ -72,9 +83,9 @@ export abstract class BaseNewCommand extends Command {
72
83
  */
73
84
  export interface NewOptions {
74
85
  /**
75
- * The path where the napi-rs project will be created.
86
+ * The path where the NAPI-RS project will be created.
76
87
  */
77
- path: string
88
+ path?: string
78
89
  /**
79
90
  * The name of the project, default to the name of the directory if not provided
80
91
  */
@@ -85,6 +96,12 @@ export interface NewOptions {
85
96
  * @default 4
86
97
  */
87
98
  minNodeApiVersion?: number
99
+ /**
100
+ * The package manager to use. Only support yarn 4.x for now.
101
+ *
102
+ * @default 'yarn'
103
+ */
104
+ packageManager?: string
88
105
  /**
89
106
  * License for open-sourced project
90
107
  *
@@ -121,6 +138,12 @@ export interface NewOptions {
121
138
  * @default true
122
139
  */
123
140
  enableGithubActions?: boolean
141
+ /**
142
+ * The JavaScript test framework to use, only support `ava` for now
143
+ *
144
+ * @default 'ava'
145
+ */
146
+ testFramework?: string
124
147
  /**
125
148
  * Whether to run the command in dry-run mode
126
149
  *
@@ -132,12 +155,14 @@ export interface NewOptions {
132
155
  export function applyDefaultNewOptions(options: NewOptions) {
133
156
  return {
134
157
  minNodeApiVersion: 4,
158
+ packageManager: 'yarn',
135
159
  license: 'MIT',
136
160
  targets: [],
137
161
  enableDefaultTargets: true,
138
162
  enableAllTargets: false,
139
163
  enableTypeDef: true,
140
164
  enableGithubActions: true,
165
+ testFramework: 'ava',
141
166
  dryRun: false,
142
167
  ...options,
143
168
  }
@@ -3,7 +3,7 @@
3
3
  import { Command, Option } from 'clipanion'
4
4
 
5
5
  export abstract class BasePrePublishCommand extends Command {
6
- static paths = [['pre-publish']]
6
+ static paths = [['pre-publish'], ['prepublish']]
7
7
 
8
8
  static usage = Command.Usage({
9
9
  description:
@@ -15,15 +15,19 @@ export abstract class BasePrePublishCommand extends Command {
15
15
  'The working directory of where napi command will be executed in, all other paths options are relative to this path',
16
16
  })
17
17
 
18
+ configPath?: string = Option.String('--config-path,-c', {
19
+ description: 'Path to `napi` config json file',
20
+ })
21
+
18
22
  packageJsonPath = Option.String('--package-json-path', 'package.json', {
19
23
  description: 'Path to `package.json`',
20
24
  })
21
25
 
22
- npmDir = Option.String('--npm-dir', 'npm', {
26
+ npmDir = Option.String('--npm-dir,-p', 'npm', {
23
27
  description: 'Path to the folder where the npm packages put',
24
28
  })
25
29
 
26
- tagStyle = Option.String('--tag-style', 'lerna', {
30
+ tagStyle = Option.String('--tag-style,--tagstyle,-t', 'lerna', {
27
31
  description: 'git tag style, `npm` or `lerna`',
28
32
  })
29
33
 
@@ -46,6 +50,7 @@ export abstract class BasePrePublishCommand extends Command {
46
50
  getOptions() {
47
51
  return {
48
52
  cwd: this.cwd,
53
+ configPath: this.configPath,
49
54
  packageJsonPath: this.packageJsonPath,
50
55
  npmDir: this.npmDir,
51
56
  tagStyle: this.tagStyle,
@@ -67,6 +72,10 @@ export interface PrePublishOptions {
67
72
  * @default process.cwd()
68
73
  */
69
74
  cwd?: string
75
+ /**
76
+ * Path to `napi` config json file
77
+ */
78
+ configPath?: string
70
79
  /**
71
80
  * Path to `package.json`
72
81
  *