@napi-rs/cli 3.0.0-alpha.23 → 3.0.0-alpha.24

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 (78) hide show
  1. package/dist/api/build.js +3 -3
  2. package/dist/api/build.js.map +1 -1
  3. package/dist/api/create-npm-dirs.js +8 -5
  4. package/dist/api/create-npm-dirs.js.map +1 -1
  5. package/dist/api/new.js +17 -9
  6. package/dist/api/new.js.map +1 -1
  7. package/dist/api/pre-publish.js +5 -4
  8. package/dist/api/pre-publish.js.map +1 -1
  9. package/dist/api/rename.js +1 -1
  10. package/dist/api/rename.js.map +1 -1
  11. package/dist/api/templates/ci-template.d.ts +2 -1
  12. package/dist/api/templates/ci-template.js +102 -110
  13. package/dist/api/templates/ci-template.js.map +1 -1
  14. package/dist/api/templates/ci.yml.d.ts +2 -1
  15. package/dist/api/templates/ci.yml.js +10 -2
  16. package/dist/api/templates/ci.yml.js.map +1 -1
  17. package/dist/api/templates/js-binding.js +15 -0
  18. package/dist/api/templates/js-binding.js.map +1 -1
  19. package/dist/api/templates/load-wasi-template.js.map +1 -0
  20. package/dist/api/templates/package.json.d.ts +4 -2
  21. package/dist/api/templates/package.json.js +28 -4
  22. package/dist/api/templates/package.json.js.map +1 -1
  23. package/dist/api/templates/wasi-worker-template.js.map +1 -0
  24. package/dist/api/universalize.js +2 -2
  25. package/dist/api/universalize.js.map +1 -1
  26. package/dist/api/version.js +1 -1
  27. package/dist/api/version.js.map +1 -1
  28. package/dist/commands/build.js +1 -1
  29. package/dist/commands/build.js.map +1 -1
  30. package/dist/commands/new.js +13 -3
  31. package/dist/commands/new.js.map +1 -1
  32. package/dist/def/new.d.ts +22 -4
  33. package/dist/def/new.js +11 -1
  34. package/dist/def/new.js.map +1 -1
  35. package/dist/index.cjs +318 -267
  36. package/dist/utils/cargo.js +1 -1
  37. package/dist/utils/cargo.js.map +1 -1
  38. package/dist/utils/config.d.ts +8 -0
  39. package/dist/utils/config.js +2 -0
  40. package/dist/utils/config.js.map +1 -1
  41. package/dist/utils/metadata.js +2 -2
  42. package/dist/utils/metadata.js.map +1 -1
  43. package/dist/utils/misc.d.ts +1 -1
  44. package/dist/utils/misc.js +3 -3
  45. package/dist/utils/misc.js.map +1 -1
  46. package/dist/utils/target.d.ts +7 -4
  47. package/dist/utils/target.js +6 -1
  48. package/dist/utils/target.js.map +1 -1
  49. package/package.json +2 -2
  50. package/src/api/build.ts +3 -3
  51. package/src/api/create-npm-dirs.ts +9 -5
  52. package/src/api/new.ts +34 -21
  53. package/src/api/pre-publish.ts +6 -4
  54. package/src/api/rename.ts +1 -1
  55. package/src/api/templates/ci-template.ts +104 -110
  56. package/src/api/templates/ci.yml.ts +14 -2
  57. package/src/api/templates/js-binding.ts +15 -0
  58. package/src/api/templates/package.json.ts +51 -5
  59. package/src/api/universalize.ts +2 -2
  60. package/src/api/version.ts +1 -1
  61. package/src/commands/build.ts +1 -1
  62. package/src/commands/new.ts +13 -3
  63. package/src/def/new.ts +27 -2
  64. package/src/utils/__tests__/__snapshots__/target.spec.ts.md +7 -0
  65. package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
  66. package/src/utils/cargo.ts +1 -1
  67. package/src/utils/config.ts +16 -0
  68. package/src/utils/metadata.ts +2 -2
  69. package/src/utils/misc.ts +11 -3
  70. package/src/utils/target.ts +9 -2
  71. package/dist/api/load-wasi-template.js.map +0 -1
  72. package/dist/api/wasi-worker-template.js.map +0 -1
  73. /package/dist/api/{load-wasi-template.d.ts → templates/load-wasi-template.d.ts} +0 -0
  74. /package/dist/api/{load-wasi-template.js → templates/load-wasi-template.js} +0 -0
  75. /package/dist/api/{wasi-worker-template.d.ts → templates/wasi-worker-template.d.ts} +0 -0
  76. /package/dist/api/{wasi-worker-template.js → templates/wasi-worker-template.js} +0 -0
  77. /package/src/api/{load-wasi-template.ts → templates/load-wasi-template.ts} +0 -0
  78. /package/src/api/{wasi-worker-template.ts → templates/wasi-worker-template.ts} +0 -0
@@ -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(),
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
  }
@@ -74,7 +85,7 @@ export interface NewOptions {
74
85
  /**
75
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
  }
@@ -114,4 +114,11 @@ Generated by [AVA](https://avajs.dev).
114
114
  platformArchABI: 'linux-riscv64-gnu',
115
115
  triple: 'riscv64gc-unknown-linux-gnu',
116
116
  },
117
+ {
118
+ abi: 'wasi',
119
+ arch: 'wasm32',
120
+ platform: 'wasi',
121
+ platformArchABI: 'wasm32-wasi',
122
+ triple: 'wasm32-wasi-preview1-threads',
123
+ },
117
124
  ]
@@ -1,4 +1,4 @@
1
- import { execSync } from 'child_process'
1
+ import { execSync } from 'node:child_process'
2
2
 
3
3
  import { debug } from './log.js'
4
4
 
@@ -4,6 +4,18 @@ import { merge, omit } from 'lodash-es'
4
4
  import { fileExists, readFileAsync } from './misc.js'
5
5
  import { DEFAULT_TARGETS, parseTriple, Target } from './target.js'
6
6
 
7
+ export type ValueOfConstArray<T> = T[Exclude<keyof T, keyof Array<any>>]
8
+
9
+ export const SupportedPackageManagers = ['yarn'] as const
10
+ export const SupportedTestFrameworks = ['ava'] as const
11
+
12
+ export type SupportedPackageManager = ValueOfConstArray<
13
+ typeof SupportedPackageManagers
14
+ >
15
+ export type SupportedTestFramework = ValueOfConstArray<
16
+ typeof SupportedTestFrameworks
17
+ >
18
+
7
19
  export interface UserNapiConfig {
8
20
  /**
9
21
  * Name of the binary to be generated, default to `index`
@@ -81,6 +93,10 @@ export interface CommonPackageJsonFields {
81
93
 
82
94
  dependencies?: Record<string, string>
83
95
  devDependencies?: Record<string, string>
96
+
97
+ ava?: {
98
+ timeout?: string
99
+ }
84
100
  }
85
101
 
86
102
  export type NapiConfig = Required<
@@ -1,5 +1,5 @@
1
- import { execSync } from 'child_process'
2
- import fs from 'fs'
1
+ import { execSync } from 'node:child_process'
2
+ import fs from 'node:fs'
3
3
 
4
4
  export type CrateTargetKind =
5
5
  | 'bin'
package/src/utils/misc.ts CHANGED
@@ -1,6 +1,14 @@
1
- import { readFile, writeFile, copyFile, mkdir, unlink, stat, readdir } from 'fs'
2
- import { createRequire } from 'module'
3
- import { promisify } from 'util'
1
+ import {
2
+ readFile,
3
+ writeFile,
4
+ copyFile,
5
+ mkdir,
6
+ unlink,
7
+ stat,
8
+ readdir,
9
+ } from 'node:fs'
10
+ import { createRequire } from 'node:module'
11
+ import { promisify } from 'node:util'
4
12
 
5
13
  import { debug } from './log.js'
6
14
 
@@ -2,6 +2,10 @@ import { execSync } from 'node:child_process'
2
2
 
3
3
  export type Platform = NodeJS.Platform | 'wasm' | 'wasi'
4
4
 
5
+ export const UNIVERSAL_TARGETS = {
6
+ 'universal-apple-darwin': ['aarch64-apple-darwin', 'x86_64-apple-darwin'],
7
+ } as const
8
+
5
9
  export const AVAILABLE_TARGETS = [
6
10
  'aarch64-apple-darwin',
7
11
  'aarch64-linux-android',
@@ -18,12 +22,14 @@ export const AVAILABLE_TARGETS = [
18
22
  'armv7-linux-androideabi',
19
23
  'universal-apple-darwin',
20
24
  'riscv64gc-unknown-linux-gnu',
25
+ 'wasm32-wasi-preview1-threads',
21
26
  ] as const
22
27
 
23
28
  export type TargetTriple = (typeof AVAILABLE_TARGETS)[number]
24
29
 
25
30
  export const DEFAULT_TARGETS = [
26
31
  'x86_64-apple-darwin',
32
+ 'aarch64-apple-darwin',
27
33
  'x86_64-pc-windows-msvc',
28
34
  'x86_64-unknown-linux-gnu',
29
35
  ] as const
@@ -48,6 +54,7 @@ type NodeJSArch =
48
54
  | 'x32'
49
55
  | 'x64'
50
56
  | 'universal'
57
+ | 'wasm32'
51
58
 
52
59
  const CpuToNodeArch: Record<string, NodeJSArch> = {
53
60
  x86_64: 'x64',
@@ -80,7 +87,7 @@ export interface Target {
80
87
  triple: string
81
88
  platformArchABI: string
82
89
  platform: Platform
83
- arch: NodeJSArch | 'wasm32'
90
+ arch: NodeJSArch
84
91
  abi: string | null
85
92
  }
86
93
 
@@ -98,7 +105,7 @@ export function parseTriple(rawTriple: string): Target {
98
105
  if (rawTriple === 'wasm32-wasi-preview1-threads') {
99
106
  return {
100
107
  triple: rawTriple,
101
- platformArchABI: rawTriple,
108
+ platformArchABI: 'wasm32-wasi',
102
109
  platform: 'wasi',
103
110
  arch: 'wasm32',
104
111
  abi: 'wasi',
@@ -1 +0,0 @@
1
- {"version":3,"file":"load-wasi-template.js","sourceRoot":"","sources":["../../src/api/load-wasi-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,YAAoB,EACpB,qBAA+B,EAC/B,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2KA6BsK,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;EAyBrL,qBAAqB;KACpB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,6BAA6B,IAAI,QAAQ,CAAC;KACxD,IAAI,CAAC,IAAI,CAAC;;CAEZ,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"wasi-worker-template.js","sourceRoot":"","sources":["../../src/api/wasi-worker-template.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmDnC,CAAA"}