@napi-rs/cli 3.1.4 → 3.2.0
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/cli.js +300 -313
- package/dist/index.cjs +327 -242
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +289 -220
- package/package.json +18 -18
- package/src/api/artifacts.ts +7 -4
- package/src/api/build.ts +1 -3
- package/src/api/new.ts +1 -0
- package/src/api/pre-publish.ts +20 -4
- package/src/api/templates/js-binding.ts +26 -5
- package/src/commands/new.ts +1 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +7 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/misc.ts +15 -15
- package/src/utils/read-config.ts +1 -3
- package/src/utils/target.ts +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Cli tools for napi-rs",
|
|
5
5
|
"author": "LongYinan <lynweklm@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/napi-rs/napi-rs",
|
|
@@ -59,36 +59,36 @@
|
|
|
59
59
|
"url": "https://github.com/napi-rs/napi-rs/issues"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@inquirer/prompts": "^7.4
|
|
63
|
-
"@napi-rs/cross-toolchain": "^1.0.
|
|
64
|
-
"@napi-rs/wasm-tools": "^1.0.
|
|
62
|
+
"@inquirer/prompts": "^7.8.4",
|
|
63
|
+
"@napi-rs/cross-toolchain": "^1.0.3",
|
|
64
|
+
"@napi-rs/wasm-tools": "^1.0.1",
|
|
65
65
|
"@octokit/rest": "^22.0.0",
|
|
66
66
|
"clipanion": "^4.0.0-rc.4",
|
|
67
67
|
"colorette": "^2.0.20",
|
|
68
|
-
"debug": "^4.4.
|
|
69
|
-
"emnapi": "^1.
|
|
70
|
-
"es-toolkit": "^1.39.
|
|
68
|
+
"debug": "^4.4.1",
|
|
69
|
+
"emnapi": "^1.5.0",
|
|
70
|
+
"es-toolkit": "^1.39.10",
|
|
71
71
|
"find-up": "^7.0.0",
|
|
72
72
|
"js-yaml": "^4.1.0",
|
|
73
|
-
"semver": "^7.7.
|
|
73
|
+
"semver": "^7.7.2",
|
|
74
74
|
"typanion": "^3.14.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@emnapi/core": "^1.
|
|
78
|
-
"@emnapi/runtime": "^1.
|
|
77
|
+
"@emnapi/core": "^1.5.0",
|
|
78
|
+
"@emnapi/runtime": "^1.5.0",
|
|
79
79
|
"@oxc-node/core": "^0.0.32",
|
|
80
|
-
"@std/toml": "npm:@jsr/std__toml@^1.0.
|
|
80
|
+
"@std/toml": "npm:@jsr/std__toml@^1.0.10",
|
|
81
81
|
"@types/debug": "^4.1.12",
|
|
82
|
-
"@types/inquirer": "^9.0.
|
|
82
|
+
"@types/inquirer": "^9.0.9",
|
|
83
83
|
"@types/js-yaml": "^4.0.9",
|
|
84
|
-
"@types/node": "^
|
|
85
|
-
"@types/semver": "^7.7.
|
|
86
|
-
"ava": "^6.
|
|
84
|
+
"@types/node": "^24.3.1",
|
|
85
|
+
"@types/semver": "^7.7.1",
|
|
86
|
+
"ava": "^6.4.1",
|
|
87
87
|
"env-paths": "^3.0.0",
|
|
88
|
-
"prettier": "^3.
|
|
89
|
-
"tsdown": "^0.
|
|
88
|
+
"prettier": "^3.6.2",
|
|
89
|
+
"tsdown": "^0.15.0",
|
|
90
90
|
"tslib": "^2.8.1",
|
|
91
|
-
"typescript": "^5.
|
|
91
|
+
"typescript": "^5.9.2"
|
|
92
92
|
},
|
|
93
93
|
"peerDependencies": {
|
|
94
94
|
"@emnapi/runtime": "^1.1.0",
|
package/src/api/artifacts.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, parse } from 'node:path'
|
|
1
|
+
import { join, resolve, parse } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import * as colors from 'colorette'
|
|
4
4
|
|
|
@@ -20,9 +20,12 @@ const debug = debugFactory('artifacts')
|
|
|
20
20
|
export async function collectArtifacts(userOptions: ArtifactsOptions) {
|
|
21
21
|
const options = applyDefaultArtifactsOptions(userOptions)
|
|
22
22
|
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
23
|
+
const resolvePath = (...paths: string[]) => resolve(options.cwd, ...paths)
|
|
24
|
+
const packageJsonPath = resolvePath(options.packageJsonPath)
|
|
25
|
+
const { targets, binaryName, packageName } = await readNapiConfig(
|
|
26
|
+
packageJsonPath,
|
|
27
|
+
options.configPath ? resolvePath(options.configPath) : undefined,
|
|
28
|
+
)
|
|
26
29
|
|
|
27
30
|
const distDirs = targets.map((platform) =>
|
|
28
31
|
join(options.cwd, options.npmDir, platform.platformArchABI),
|
package/src/api/build.ts
CHANGED
|
@@ -82,9 +82,7 @@ export async function buildProject(rawOptions: BuildOptions) {
|
|
|
82
82
|
)
|
|
83
83
|
}
|
|
84
84
|
const config = await readNapiConfig(
|
|
85
|
-
resolvePath(
|
|
86
|
-
options.configPath ?? options.packageJsonPath ?? 'package.json',
|
|
87
|
-
),
|
|
85
|
+
resolvePath(options.packageJsonPath ?? 'package.json'),
|
|
88
86
|
options.configPath ? resolvePath(options.configPath) : undefined,
|
|
89
87
|
)
|
|
90
88
|
|
package/src/api/new.ts
CHANGED
|
@@ -180,6 +180,7 @@ async function filterTargetsInGithubActions(
|
|
|
180
180
|
'aarch64-unknown-linux-musl',
|
|
181
181
|
'armv7-unknown-linux-gnueabihf',
|
|
182
182
|
'armv7-unknown-linux-musleabihf',
|
|
183
|
+
'loongarch64-unknown-linux-gnu',
|
|
183
184
|
'riscv64gc-unknown-linux-gnu',
|
|
184
185
|
'powerpc64le-unknown-linux-gnu',
|
|
185
186
|
's390x-unknown-linux-gnu',
|
package/src/api/pre-publish.ts
CHANGED
|
@@ -165,10 +165,26 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
if (!options.skipOptionalPublish) {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
168
|
+
try {
|
|
169
|
+
const output = execSync(`${npmClient} publish`, {
|
|
170
|
+
cwd: pkgDir,
|
|
171
|
+
env: process.env,
|
|
172
|
+
stdio: 'pipe',
|
|
173
|
+
})
|
|
174
|
+
process.stdout.write(output)
|
|
175
|
+
} catch (e) {
|
|
176
|
+
if (
|
|
177
|
+
e instanceof Error &&
|
|
178
|
+
e.message.includes(
|
|
179
|
+
'You cannot publish over the previously published versions',
|
|
180
|
+
)
|
|
181
|
+
) {
|
|
182
|
+
console.info(e.message)
|
|
183
|
+
debug.warn(`${pkgDir} has been published, skipping`)
|
|
184
|
+
} else {
|
|
185
|
+
throw e
|
|
186
|
+
}
|
|
187
|
+
}
|
|
172
188
|
}
|
|
173
189
|
|
|
174
190
|
if (options.ghRelease && repo && owner) {
|
|
@@ -132,7 +132,7 @@ const isMuslFromChildProcess = () => {
|
|
|
132
132
|
function requireNative() {
|
|
133
133
|
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
134
134
|
try {
|
|
135
|
-
|
|
135
|
+
return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
136
136
|
} catch (err) {
|
|
137
137
|
loadErrors.push(err)
|
|
138
138
|
}
|
|
@@ -190,6 +190,12 @@ function requireNative() {
|
|
|
190
190
|
} else {
|
|
191
191
|
${requireTuple('linux-arm-gnueabihf', 10)}
|
|
192
192
|
}
|
|
193
|
+
} else if (process.arch === 'loong64') {
|
|
194
|
+
if (isMusl()) {
|
|
195
|
+
${requireTuple('linux-loong64-musl', 10)}
|
|
196
|
+
} else {
|
|
197
|
+
${requireTuple('linux-loong64-gnu', 10)}
|
|
198
|
+
}
|
|
193
199
|
} else if (process.arch === 'riscv64') {
|
|
194
200
|
if (isMusl()) {
|
|
195
201
|
${requireTuple('linux-riscv64-musl', 10)}
|
|
@@ -221,22 +227,32 @@ function requireNative() {
|
|
|
221
227
|
nativeBinding = requireNative()
|
|
222
228
|
|
|
223
229
|
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
230
|
+
let wasiBinding = null
|
|
231
|
+
let wasiBindingError = null
|
|
224
232
|
try {
|
|
225
|
-
|
|
233
|
+
wasiBinding = require('./${localName}.wasi.cjs')
|
|
234
|
+
nativeBinding = wasiBinding
|
|
226
235
|
} catch (err) {
|
|
227
236
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
228
|
-
|
|
237
|
+
wasiBindingError = err
|
|
229
238
|
}
|
|
230
239
|
}
|
|
231
240
|
if (!nativeBinding) {
|
|
232
241
|
try {
|
|
233
|
-
|
|
242
|
+
wasiBinding = require('${pkgName}-wasm32-wasi')
|
|
243
|
+
nativeBinding = wasiBinding
|
|
234
244
|
} catch (err) {
|
|
235
245
|
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
246
|
+
wasiBindingError.cause = err
|
|
236
247
|
loadErrors.push(err)
|
|
237
248
|
}
|
|
238
249
|
}
|
|
239
250
|
}
|
|
251
|
+
if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
|
|
252
|
+
const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
|
|
253
|
+
error.cause = wasiBindingError
|
|
254
|
+
throw error
|
|
255
|
+
}
|
|
240
256
|
}
|
|
241
257
|
|
|
242
258
|
if (!nativeBinding) {
|
|
@@ -245,7 +261,12 @@ if (!nativeBinding) {
|
|
|
245
261
|
\`Cannot find native binding. \` +
|
|
246
262
|
\`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). \` +
|
|
247
263
|
'Please try \`npm i\` again after removing both package-lock.json and node_modules directory.',
|
|
248
|
-
{
|
|
264
|
+
{
|
|
265
|
+
cause: loadErrors.reduce((err, cur) => {
|
|
266
|
+
cur.cause = err
|
|
267
|
+
return cur
|
|
268
|
+
}),
|
|
269
|
+
},
|
|
249
270
|
)
|
|
250
271
|
}
|
|
251
272
|
throw new Error(\`Failed to load native binding\`)
|
package/src/commands/new.ts
CHANGED
|
@@ -76,6 +76,7 @@ export class NewCommand extends BaseNewCommand {
|
|
|
76
76
|
return select({
|
|
77
77
|
message: 'Minimum node-api version (with node version requirement)',
|
|
78
78
|
loop: false,
|
|
79
|
+
pageSize: 10,
|
|
79
80
|
choices: Array.from({ length: 8 }, (_, i) => ({
|
|
80
81
|
name: `napi${i + 1} (${napiEngineRequirement(i + 1)})`,
|
|
81
82
|
value: i + 1,
|
|
@@ -128,6 +128,13 @@ Generated by [AVA](https://avajs.dev).
|
|
|
128
128
|
platformArchABI: 'darwin-universal',
|
|
129
129
|
triple: 'universal-apple-darwin',
|
|
130
130
|
},
|
|
131
|
+
{
|
|
132
|
+
abi: 'gnu',
|
|
133
|
+
arch: 'loong64',
|
|
134
|
+
platform: 'linux',
|
|
135
|
+
platformArchABI: 'linux-loong64-gnu',
|
|
136
|
+
triple: 'loongarch64-unknown-linux-gnu',
|
|
137
|
+
},
|
|
131
138
|
{
|
|
132
139
|
abi: 'gnu',
|
|
133
140
|
arch: 'riscv64',
|
|
Binary file
|
package/src/utils/misc.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import {
|
|
2
2
|
readFile,
|
|
3
3
|
writeFile,
|
|
4
|
+
unlink,
|
|
4
5
|
copyFile,
|
|
5
6
|
mkdir,
|
|
6
|
-
unlink,
|
|
7
7
|
stat,
|
|
8
8
|
readdir,
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
access,
|
|
10
|
+
} from 'node:fs/promises'
|
|
11
11
|
|
|
12
12
|
import pkgJson from '../../package.json' with { type: 'json' }
|
|
13
13
|
import { debug } from './log.js'
|
|
14
14
|
|
|
15
|
-
export const readFileAsync =
|
|
16
|
-
export const writeFileAsync =
|
|
17
|
-
export const unlinkAsync =
|
|
18
|
-
export const copyFileAsync =
|
|
19
|
-
export const mkdirAsync =
|
|
20
|
-
export const statAsync =
|
|
21
|
-
export const readdirAsync =
|
|
15
|
+
export const readFileAsync = readFile
|
|
16
|
+
export const writeFileAsync = writeFile
|
|
17
|
+
export const unlinkAsync = unlink
|
|
18
|
+
export const copyFileAsync = copyFile
|
|
19
|
+
export const mkdirAsync = mkdir
|
|
20
|
+
export const statAsync = stat
|
|
21
|
+
export const readdirAsync = readdir
|
|
22
22
|
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export function fileExists(path: string): Promise<boolean> {
|
|
24
|
+
return access(path).then(
|
|
25
|
+
() => true,
|
|
26
|
+
() => false,
|
|
27
|
+
)
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export async function dirExistsAsync(path: string) {
|
package/src/utils/read-config.ts
CHANGED
|
@@ -11,9 +11,7 @@ interface MinimalNapiOptions {
|
|
|
11
11
|
export async function readConfig(options: MinimalNapiOptions) {
|
|
12
12
|
const resolvePath = (...paths: string[]) => resolve(options.cwd, ...paths)
|
|
13
13
|
const config = await readNapiConfig(
|
|
14
|
-
resolvePath(
|
|
15
|
-
options.configPath ?? options.packageJsonPath ?? 'package.json',
|
|
16
|
-
),
|
|
14
|
+
resolvePath(options.packageJsonPath ?? 'package.json'),
|
|
17
15
|
options.configPath ? resolvePath(options.configPath) : undefined,
|
|
18
16
|
)
|
|
19
17
|
return config
|
package/src/utils/target.ts
CHANGED
|
@@ -26,6 +26,7 @@ export const AVAILABLE_TARGETS = [
|
|
|
26
26
|
'armv7-unknown-linux-musleabihf',
|
|
27
27
|
'armv7-linux-androideabi',
|
|
28
28
|
'universal-apple-darwin',
|
|
29
|
+
'loongarch64-unknown-linux-gnu',
|
|
29
30
|
'riscv64gc-unknown-linux-gnu',
|
|
30
31
|
'powerpc64le-unknown-linux-gnu',
|
|
31
32
|
's390x-unknown-linux-gnu',
|
|
@@ -44,6 +45,8 @@ export const DEFAULT_TARGETS = [
|
|
|
44
45
|
|
|
45
46
|
export const TARGET_LINKER: Record<string, string> = {
|
|
46
47
|
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
|
48
|
+
// TODO: Switch to loongarch64-linux-gnu-gcc when available
|
|
49
|
+
'loongarch64-unknown-linux-gnu': 'loongarch64-linux-gnu-gcc-13',
|
|
47
50
|
'riscv64gc-unknown-linux-gnu': 'riscv64-linux-gnu-gcc',
|
|
48
51
|
'powerpc64le-unknown-linux-gnu': 'powerpc64le-linux-gnu-gcc',
|
|
49
52
|
's390x-unknown-linux-gnu': 's390x-linux-gnu-gcc',
|
|
@@ -54,6 +57,7 @@ type NodeJSArch =
|
|
|
54
57
|
| 'arm'
|
|
55
58
|
| 'arm64'
|
|
56
59
|
| 'ia32'
|
|
60
|
+
| 'loong64'
|
|
57
61
|
| 'mips'
|
|
58
62
|
| 'mipsel'
|
|
59
63
|
| 'ppc'
|
|
@@ -71,6 +75,7 @@ const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
|
71
75
|
aarch64: 'arm64',
|
|
72
76
|
i686: 'ia32',
|
|
73
77
|
armv7: 'arm',
|
|
78
|
+
loongarch64: 'loong64',
|
|
74
79
|
riscv64gc: 'riscv64',
|
|
75
80
|
powerpc64le: 'ppc64',
|
|
76
81
|
}
|
|
@@ -80,6 +85,7 @@ export const NodeArchToCpu: Record<string, string> = {
|
|
|
80
85
|
arm64: 'aarch64',
|
|
81
86
|
ia32: 'i686',
|
|
82
87
|
arm: 'armv7',
|
|
88
|
+
loong64: 'loongarch64',
|
|
83
89
|
riscv64: 'riscv64gc',
|
|
84
90
|
ppc64: 'powerpc64le',
|
|
85
91
|
}
|