@napi-rs/cli 3.6.0 → 3.6.1
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 +44 -27
- package/dist/index.cjs +44 -27
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +44 -27
- package/package.json +3 -3
- package/src/api/build.ts +5 -29
- package/src/api/create-npm-dirs.ts +50 -4
- package/src/api/new.ts +9 -18
- package/src/api/rename.ts +11 -3
- package/src/utils/metadata.ts +5 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/cli",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "Cli tools for napi-rs",
|
|
5
5
|
"author": "LongYinan <lynweklm@gmail.com>",
|
|
6
6
|
"homepage": "https://napi.rs/",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@emnapi/runtime": "^1.9.1",
|
|
78
|
-
"@oxc-node/core": "^0.0
|
|
78
|
+
"@oxc-node/core": "^0.1.0",
|
|
79
79
|
"@std/toml": "npm:@jsr/std__toml@^1.0.11",
|
|
80
80
|
"@types/inquirer": "^9.0.9",
|
|
81
81
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"ava": "^7.0.0",
|
|
85
85
|
"empathic": "^2.0.0",
|
|
86
86
|
"env-paths": "^4.0.0",
|
|
87
|
-
"oxc-parser": "^0.
|
|
87
|
+
"oxc-parser": "^0.124.0",
|
|
88
88
|
"prettier": "^3.6.2",
|
|
89
89
|
"tsdown": "^0.21.0",
|
|
90
90
|
"tslib": "^2.8.1",
|
package/src/api/build.ts
CHANGED
|
@@ -381,35 +381,11 @@ class Builder {
|
|
|
381
381
|
set = true
|
|
382
382
|
}
|
|
383
383
|
} else {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
const glibcVersionRuntime =
|
|
390
|
-
// @ts-expect-error
|
|
391
|
-
process.report?.getReport()?.header?.glibcVersionRuntime
|
|
392
|
-
const libc = glibcVersionRuntime ? 'gnu' : 'musl'
|
|
393
|
-
return abi === libc
|
|
394
|
-
})(this.target.abi)
|
|
395
|
-
) {
|
|
396
|
-
debug.warn(
|
|
397
|
-
'You are trying to cross compile to linux target on linux platform which is unnecessary.',
|
|
398
|
-
)
|
|
399
|
-
} else if (
|
|
400
|
-
this.target.platform === 'darwin' &&
|
|
401
|
-
process.platform === 'darwin'
|
|
402
|
-
) {
|
|
403
|
-
debug.warn(
|
|
404
|
-
'You are trying to cross compile to darwin target on darwin platform which is unnecessary.',
|
|
405
|
-
)
|
|
406
|
-
} else {
|
|
407
|
-
// use cargo-zigbuild to cross compile to other platforms
|
|
408
|
-
debug('Use %i', 'cargo-zigbuild')
|
|
409
|
-
tryInstallCargoBinary('cargo-zigbuild', 'zigbuild')
|
|
410
|
-
this.args.push('zigbuild')
|
|
411
|
-
set = true
|
|
412
|
-
}
|
|
384
|
+
// use cargo-zigbuild to cross compile to other platforms
|
|
385
|
+
debug('Use %i', 'cargo-zigbuild')
|
|
386
|
+
tryInstallCargoBinary('cargo-zigbuild', 'zigbuild')
|
|
387
|
+
this.args.push('zigbuild')
|
|
388
|
+
set = true
|
|
413
389
|
}
|
|
414
390
|
}
|
|
415
391
|
|
|
@@ -25,6 +25,52 @@ export interface PackageMeta {
|
|
|
25
25
|
'dist-tags': { [index: string]: string }
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
const WASM_RUNTIME_PACKAGE_NAME = '@napi-rs/wasm-runtime'
|
|
29
|
+
|
|
30
|
+
async function getLatestWasmRuntimeVersion() {
|
|
31
|
+
const npmRegistryBase =
|
|
32
|
+
process.env.npm_config_registry?.replace(/\/?$/, '/') ??
|
|
33
|
+
'https://registry.npmjs.org/'
|
|
34
|
+
const packageMetadataUrl = `${npmRegistryBase}${WASM_RUNTIME_PACKAGE_NAME}`
|
|
35
|
+
let response: Response
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
response = await fetch(packageMetadataUrl)
|
|
39
|
+
} catch (error) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
`Failed to fetch ${packageMetadataUrl} while resolving ${WASM_RUNTIME_PACKAGE_NAME}. Check your network connection and npm registry availability.`,
|
|
42
|
+
{ cause: error },
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
throw new Error(
|
|
48
|
+
`Failed to fetch ${packageMetadataUrl} while resolving ${WASM_RUNTIME_PACKAGE_NAME}: npm registry responded with ${response.status} ${response.statusText || 'Unknown Status'}`,
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let packageMeta: PackageMeta
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
packageMeta = (await response.json()) as PackageMeta
|
|
56
|
+
} catch (error) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`Failed to parse npm registry metadata for ${WASM_RUNTIME_PACKAGE_NAME} from ${packageMetadataUrl}`,
|
|
59
|
+
{ cause: error },
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const latestVersion = packageMeta['dist-tags']?.latest
|
|
64
|
+
|
|
65
|
+
if (typeof latestVersion !== 'string' || latestVersion.trim().length === 0) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
`npm registry metadata for ${WASM_RUNTIME_PACKAGE_NAME} from ${packageMetadataUrl} did not include a latest dist-tag`,
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return latestVersion.trim()
|
|
72
|
+
}
|
|
73
|
+
|
|
28
74
|
export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
29
75
|
const options = applyDefaultCreateNpmDirsOptions(userOptions)
|
|
30
76
|
|
|
@@ -60,6 +106,9 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
60
106
|
packageJsonPath,
|
|
61
107
|
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
62
108
|
)
|
|
109
|
+
const wasmRuntimeVersion = targets.some((target) => target.arch === 'wasm32')
|
|
110
|
+
? await getLatestWasmRuntimeVersion()
|
|
111
|
+
: undefined
|
|
63
112
|
|
|
64
113
|
for (const target of targets) {
|
|
65
114
|
const targetDir = join(npmPath, `${target.platformArchABI}`)
|
|
@@ -126,11 +175,8 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
126
175
|
}
|
|
127
176
|
}
|
|
128
177
|
const emnapiVersion = require('emnapi/package.json').version
|
|
129
|
-
const wasmRuntime = await fetch(
|
|
130
|
-
`https://registry.npmjs.org/@napi-rs/wasm-runtime`,
|
|
131
|
-
).then((res) => res.json() as Promise<PackageMeta>)
|
|
132
178
|
scopedPackageJson.dependencies = {
|
|
133
|
-
'@napi-rs/wasm-runtime': `^${
|
|
179
|
+
'@napi-rs/wasm-runtime': `^${wasmRuntimeVersion}`,
|
|
134
180
|
'@emnapi/core': emnapiVersion,
|
|
135
181
|
'@emnapi/runtime': emnapiVersion,
|
|
136
182
|
}
|
package/src/api/new.ts
CHANGED
|
@@ -34,24 +34,15 @@ const TEMPLATE_REPOS = {
|
|
|
34
34
|
} as const
|
|
35
35
|
|
|
36
36
|
async function checkGitCommand(): Promise<boolean> {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
resolve(false)
|
|
42
|
-
})
|
|
43
|
-
cp.on('exit', (code) => {
|
|
44
|
-
if (code === 0) {
|
|
45
|
-
resolve(true)
|
|
46
|
-
} else {
|
|
47
|
-
resolve(false)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
37
|
+
return new Promise<boolean>((resolve) => {
|
|
38
|
+
const cp = exec('git --version')
|
|
39
|
+
cp.on('error', () => {
|
|
40
|
+
resolve(false)
|
|
50
41
|
})
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
42
|
+
cp.on('exit', (code) => {
|
|
43
|
+
resolve(code === 0)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
55
46
|
}
|
|
56
47
|
|
|
57
48
|
async function ensureCacheDir(
|
|
@@ -132,7 +123,7 @@ async function copyDirectory(
|
|
|
132
123
|
!includeWasiBindings &&
|
|
133
124
|
(entry.name.endsWith('.wasi-browser.js') ||
|
|
134
125
|
entry.name.endsWith('.wasi.cjs') ||
|
|
135
|
-
entry.name.endsWith('wasi-worker
|
|
126
|
+
entry.name.endsWith('wasi-worker-browser.mjs') ||
|
|
136
127
|
entry.name.endsWith('wasi-worker.mjs') ||
|
|
137
128
|
entry.name.endsWith('browser.js'))
|
|
138
129
|
) {
|
package/src/api/rename.ts
CHANGED
|
@@ -45,8 +45,16 @@ export async function renameProject(userOptions: RenameOptions) {
|
|
|
45
45
|
const configPath = resolve(options.cwd, options.configPath)
|
|
46
46
|
const configContent = await readFileAsync(configPath, 'utf8')
|
|
47
47
|
const configData = JSON.parse(configContent)
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
merge(
|
|
49
|
+
configData,
|
|
50
|
+
omitBy(
|
|
51
|
+
{
|
|
52
|
+
binaryName: options.binaryName,
|
|
53
|
+
packageName: options.packageName,
|
|
54
|
+
},
|
|
55
|
+
isNil,
|
|
56
|
+
),
|
|
57
|
+
)
|
|
50
58
|
await writeFileAsync(configPath, JSON.stringify(configData, null, 2))
|
|
51
59
|
}
|
|
52
60
|
|
|
@@ -73,7 +81,7 @@ export async function renameProject(userOptions: RenameOptions) {
|
|
|
73
81
|
const updatedTomlContent = stringifyToml(cargoToml)
|
|
74
82
|
|
|
75
83
|
await writeFileAsync(cargoTomlPath, updatedTomlContent)
|
|
76
|
-
if (oldName !== options.binaryName) {
|
|
84
|
+
if (options.binaryName && oldName !== options.binaryName) {
|
|
77
85
|
const githubActionsPath = find.dir('.github', {
|
|
78
86
|
cwd: options.cwd,
|
|
79
87
|
})
|
package/src/utils/metadata.ts
CHANGED
|
@@ -62,7 +62,7 @@ export async function parseMetadata(manifestPath: string) {
|
|
|
62
62
|
let stdout = ''
|
|
63
63
|
let stderr = ''
|
|
64
64
|
let status = 0
|
|
65
|
-
let error = null
|
|
65
|
+
let error: Error | null = null
|
|
66
66
|
|
|
67
67
|
childProcess.stdout.on('data', (data) => {
|
|
68
68
|
stdout += data
|
|
@@ -72,6 +72,10 @@ export async function parseMetadata(manifestPath: string) {
|
|
|
72
72
|
stderr += data
|
|
73
73
|
})
|
|
74
74
|
|
|
75
|
+
childProcess.on('error', (err) => {
|
|
76
|
+
error = err
|
|
77
|
+
})
|
|
78
|
+
|
|
75
79
|
await new Promise<void>((resolve) => {
|
|
76
80
|
childProcess.on('close', (code) => {
|
|
77
81
|
status = code ?? 0
|