@napi-rs/cli 3.0.0-alpha.8 → 3.0.0-alpha.80
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/cli.mjs +1 -1
- package/dist/api/artifacts.js +28 -7
- package/dist/api/artifacts.js.map +1 -1
- package/dist/api/build.js +309 -64
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +46 -9
- package/dist/api/create-npm-dirs.js.map +1 -1
- package/dist/api/new.js +57 -20
- package/dist/api/new.js.map +1 -1
- package/dist/api/pre-publish.js +9 -7
- package/dist/api/pre-publish.js.map +1 -1
- package/dist/api/rename.js +9 -1
- package/dist/api/rename.js.map +1 -1
- package/dist/api/templates/cargo.toml.js +1 -0
- package/dist/api/templates/cargo.toml.js.map +1 -1
- package/dist/api/templates/ci-template.d.ts +3 -1
- package/dist/api/templates/ci-template.js +140 -125
- package/dist/api/templates/ci-template.js.map +1 -1
- package/dist/api/templates/ci.yml.d.ts +3 -1
- package/dist/api/templates/ci.yml.js +21 -5
- package/dist/api/templates/ci.yml.js.map +1 -1
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/js-binding.js +141 -222
- package/dist/api/templates/js-binding.js.map +1 -1
- package/dist/api/templates/lib.rs.js +1 -4
- package/dist/api/templates/lib.rs.js.map +1 -1
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/load-wasi-template.js +168 -0
- package/dist/api/templates/load-wasi-template.js.map +1 -0
- package/dist/api/templates/package.json.d.ts +9 -2
- package/dist/api/templates/package.json.js +26 -4
- package/dist/api/templates/package.json.js.map +1 -1
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.js +122 -0
- package/dist/api/templates/wasi-worker-template.js.map +1 -0
- package/dist/api/universalize.js +5 -5
- package/dist/api/universalize.js.map +1 -1
- package/dist/api/version.js +2 -2
- package/dist/api/version.js.map +1 -1
- package/dist/commands/artifacts.js +2 -2
- package/dist/commands/artifacts.js.map +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/new.js +34 -34
- package/dist/commands/new.js.map +1 -1
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/artifacts.js +10 -2
- package/dist/def/artifacts.js.map +1 -1
- package/dist/def/build.d.ts +155 -4
- package/dist/def/build.js +30 -4
- package/dist/def/build.js.map +1 -1
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/create-npm-dirs.js +4 -0
- package/dist/def/create-npm-dirs.js.map +1 -1
- package/dist/def/new.d.ts +25 -7
- package/dist/def/new.js +11 -1
- package/dist/def/new.js.map +1 -1
- package/dist/def/pre-publish.d.ts +12 -2
- package/dist/def/pre-publish.js +7 -3
- package/dist/def/pre-publish.js.map +1 -1
- package/dist/def/rename.d.ts +16 -6
- package/dist/def/rename.js +5 -1
- package/dist/def/rename.js.map +1 -1
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/universalize.js +4 -0
- package/dist/def/universalize.js.map +1 -1
- package/dist/def/version.d.ts +10 -0
- package/dist/def/version.js +4 -0
- package/dist/def/version.js.map +1 -1
- package/dist/index.cjs +8706 -14649
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/__tests__/config.spec.d.ts +1 -0
- package/dist/utils/__tests__/config.spec.js +63 -0
- package/dist/utils/__tests__/config.spec.js.map +1 -0
- package/dist/utils/__tests__/typegen.spec.js +8 -4
- package/dist/utils/__tests__/typegen.spec.js.map +1 -1
- package/dist/utils/cargo.js +2 -2
- package/dist/utils/cargo.js.map +1 -1
- package/dist/utils/config.d.ts +52 -4
- package/dist/utils/config.js +37 -5
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/metadata.d.ts +12 -0
- package/dist/utils/metadata.js +21 -10
- package/dist/utils/metadata.js.map +1 -1
- package/dist/utils/misc.d.ts +1 -2
- package/dist/utils/misc.js +3 -3
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/target.d.ts +7 -5
- package/dist/utils/target.js +17 -3
- package/dist/utils/target.js.map +1 -1
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +55 -20
- package/dist/utils/typegen.js.map +1 -1
- package/dist/utils/version.d.ts +2 -1
- package/dist/utils/version.js +10 -8
- package/dist/utils/version.js.map +1 -1
- package/package.json +27 -26
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +467 -87
- package/src/api/create-npm-dirs.ts +57 -9
- package/src/api/new.ts +89 -31
- package/src/api/pre-publish.ts +13 -7
- package/src/api/rename.ts +10 -1
- package/src/api/templates/cargo.toml.ts +1 -0
- package/src/api/templates/ci-template.ts +150 -125
- package/src/api/templates/ci.yml.ts +27 -6
- package/src/api/templates/js-binding.ts +147 -220
- package/src/api/templates/lib.rs.ts +1 -4
- package/src/api/templates/load-wasi-template.ts +182 -0
- package/src/api/templates/package.json.ts +47 -5
- package/src/api/templates/wasi-worker-template.ts +122 -0
- package/src/api/universalize.ts +13 -8
- package/src/api/version.ts +5 -2
- package/src/commands/artifacts.ts +2 -2
- package/src/commands/build.ts +1 -1
- package/src/commands/new.ts +46 -45
- package/src/def/artifacts.ts +22 -3
- package/src/def/build.ts +64 -8
- package/src/def/create-npm-dirs.ts +9 -0
- package/src/def/new.ts +28 -3
- package/src/def/pre-publish.ts +12 -3
- package/src/def/rename.ts +11 -2
- package/src/def/universalize.ts +9 -0
- package/src/def/version.ts +9 -0
- package/src/index.ts +2 -0
- package/src/utils/__tests__/__fixtures__/napi_type_def +130 -130
- package/src/utils/__tests__/__snapshots__/config.spec.ts.md +97 -0
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +28 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +711 -158
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/version.spec.ts.md +8 -7
- package/src/utils/__tests__/__snapshots__/version.spec.ts.snap +0 -0
- package/src/utils/__tests__/config.spec.ts +81 -0
- package/src/utils/__tests__/typegen.spec.ts +18 -3
- package/src/utils/cargo.ts +2 -2
- package/src/utils/config.ts +116 -10
- package/src/utils/index.ts +0 -1
- package/src/utils/metadata.ts +38 -13
- package/src/utils/misc.ts +11 -3
- package/src/utils/target.ts +22 -4
- package/src/utils/typegen.ts +98 -49
- package/src/utils/version.ts +10 -8
- package/dist/api/load-wasi-template.d.ts +0 -1
- package/dist/api/load-wasi-template.js +0 -64
- package/dist/api/load-wasi-template.js.map +0 -1
- package/dist/api/wasi-worker-template.d.ts +0 -1
- package/dist/api/wasi-worker-template.js +0 -53
- package/dist/api/wasi-worker-template.js.map +0 -1
- package/dist/utils/ci.d.ts +0 -11
- package/dist/utils/ci.js +0 -96
- package/dist/utils/ci.js.map +0 -1
- package/src/api/load-wasi-template.ts +0 -66
- package/src/api/wasi-worker-template.ts +0 -52
- package/src/utils/ci.ts +0 -111
|
Binary file
|
|
@@ -9,12 +9,13 @@ Generated by [AVA](https://avajs.dev).
|
|
|
9
9
|
> Snapshot 1
|
|
10
10
|
|
|
11
11
|
[
|
|
12
|
-
'>= 8.6.0',
|
|
13
|
-
'>= 8.10.0 < 9 || >= 9.3.0',
|
|
14
|
-
'>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0',
|
|
15
|
-
'>= 10.16.0 < 11 || >= 11.8.0',
|
|
16
|
-
'>= 10.17.0 < 11 || >= 12.11.0',
|
|
12
|
+
'>= 8.6.0 < 9 || >= 9.0.0 < 10 || >= 10.0.0',
|
|
13
|
+
'>= 8.10.0 < 9 || >= 9.3.0 < 10 || >= 10.0.0',
|
|
14
|
+
'>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0',
|
|
15
|
+
'>= 10.16.0 < 11 || >= 11.8.0 < 12 || >= 12.0.0',
|
|
16
|
+
'>= 10.17.0 < 11 || >= 12.11.0 < 13 || >= 13.0.0',
|
|
17
17
|
'>= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0',
|
|
18
|
-
'>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0',
|
|
19
|
-
'>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0',
|
|
18
|
+
'>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0 < 15 || >= 15.0.0',
|
|
19
|
+
'>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0',
|
|
20
|
+
'>= 18.17.0 < 19 || >= 20.3.0 < 21 || >= 21.1.0',
|
|
20
21
|
]
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import ava, { TestFn } from 'ava'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CommonPackageJsonFields,
|
|
9
|
+
UserNapiConfig,
|
|
10
|
+
readNapiConfig,
|
|
11
|
+
} from '../config.js'
|
|
12
|
+
|
|
13
|
+
const NON_EXISTENT_FILE = 'non-existent-file'
|
|
14
|
+
|
|
15
|
+
const test = ava as TestFn<{
|
|
16
|
+
configPath: string
|
|
17
|
+
packageJson: string
|
|
18
|
+
pkgJson: CommonPackageJsonFields
|
|
19
|
+
config: UserNapiConfig
|
|
20
|
+
}>
|
|
21
|
+
|
|
22
|
+
test.before(async (t) => {
|
|
23
|
+
const tmp = tmpdir()
|
|
24
|
+
const configPath = join(tmp, 'napi.json')
|
|
25
|
+
const packageJson = join(tmp, 'package.json')
|
|
26
|
+
const pkgJson = {
|
|
27
|
+
name: '@napi-rs/testing',
|
|
28
|
+
version: '0.0.0',
|
|
29
|
+
napi: {
|
|
30
|
+
binaryName: 'testing',
|
|
31
|
+
packageName: '@napi-rs/testing',
|
|
32
|
+
targets: [
|
|
33
|
+
'x86_64-unknown-linux-gnu',
|
|
34
|
+
'x86_64-pc-windows-msvc',
|
|
35
|
+
'x86_64-apple-darwin',
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
await writeFile(packageJson, JSON.stringify(pkgJson, null, 2))
|
|
40
|
+
const config = {
|
|
41
|
+
binaryName: 'testing',
|
|
42
|
+
packageName: '@node-rs/testing',
|
|
43
|
+
targets: [
|
|
44
|
+
'x86_64-unknown-linux-gnu',
|
|
45
|
+
'x86_64-apple-darwin',
|
|
46
|
+
'aarch64-apple-darwin',
|
|
47
|
+
],
|
|
48
|
+
}
|
|
49
|
+
await writeFile(configPath, JSON.stringify(config, null, 2))
|
|
50
|
+
t.context = { configPath, config, packageJson, pkgJson }
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test.after(async (t) => {
|
|
54
|
+
await unlink(t.context.configPath)
|
|
55
|
+
await unlink(t.context.packageJson)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('should throw if package.json not found', async (t) => {
|
|
59
|
+
await t.throwsAsync(() => readNapiConfig(NON_EXISTENT_FILE), {
|
|
60
|
+
message: `package.json not found at ${NON_EXISTENT_FILE}`,
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('should throw if napi.json not found', async (t) => {
|
|
65
|
+
const { packageJson } = t.context
|
|
66
|
+
await t.throwsAsync(() => readNapiConfig(packageJson, NON_EXISTENT_FILE), {
|
|
67
|
+
message: `NAPI-RS config not found at ${NON_EXISTENT_FILE}`,
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('should be able to read config from package.json', async (t) => {
|
|
72
|
+
const { packageJson } = t.context
|
|
73
|
+
const config = await readNapiConfig(packageJson)
|
|
74
|
+
t.snapshot(config)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('should be able to read config from napi.json', async (t) => {
|
|
78
|
+
const { packageJson, configPath } = t.context
|
|
79
|
+
const config = await readNapiConfig(packageJson, configPath)
|
|
80
|
+
t.snapshot(config)
|
|
81
|
+
})
|
|
@@ -18,13 +18,13 @@ test('should ident string correctly', (t) => {
|
|
|
18
18
|
foo() {
|
|
19
19
|
a = b
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
bar = () => {
|
|
23
|
-
|
|
23
|
+
|
|
24
24
|
}
|
|
25
25
|
boz = 1
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
namespace B {
|
|
29
29
|
namespace C {
|
|
30
30
|
type D = A
|
|
@@ -43,6 +43,21 @@ test('should process type def correctly', async (t) => {
|
|
|
43
43
|
'__fixtures__',
|
|
44
44
|
'napi_type_def',
|
|
45
45
|
),
|
|
46
|
+
true,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
t.snapshot(dts)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
test('should process type def with noConstEnum correctly', async (t) => {
|
|
53
|
+
const { dts } = await processTypeDef(
|
|
54
|
+
join(
|
|
55
|
+
fileURLToPath(import.meta.url),
|
|
56
|
+
'../',
|
|
57
|
+
'__fixtures__',
|
|
58
|
+
'napi_type_def',
|
|
59
|
+
),
|
|
60
|
+
false,
|
|
46
61
|
)
|
|
47
62
|
|
|
48
63
|
t.snapshot(dts)
|
package/src/utils/cargo.ts
CHANGED
|
@@ -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
|
|
|
@@ -28,7 +28,7 @@ function detectCargoBinary(bin: string) {
|
|
|
28
28
|
})
|
|
29
29
|
debug('Cargo binary detected: %s', bin)
|
|
30
30
|
return true
|
|
31
|
-
} catch
|
|
31
|
+
} catch {
|
|
32
32
|
debug('Cargo binary not detected: %s', bin)
|
|
33
33
|
return false
|
|
34
34
|
}
|
package/src/utils/config.ts
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
|
+
import { underline, yellow } from 'colorette'
|
|
1
2
|
import { merge, omit } from 'lodash-es'
|
|
2
3
|
|
|
3
4
|
import { fileExists, readFileAsync } from './misc.js'
|
|
4
5
|
import { DEFAULT_TARGETS, parseTriple, Target } from './target.js'
|
|
5
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
|
+
|
|
19
|
+
export interface UserNapiConfig {
|
|
7
20
|
/**
|
|
8
21
|
* Name of the binary to be generated, default to `index`
|
|
9
22
|
*/
|
|
@@ -24,6 +37,51 @@ interface UserNapiConfig {
|
|
|
24
37
|
*/
|
|
25
38
|
npmClient?: string
|
|
26
39
|
|
|
40
|
+
/**
|
|
41
|
+
* Whether generate const enum for typescript bindings
|
|
42
|
+
*/
|
|
43
|
+
constEnum?: boolean
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* dts header prepend to the generated dts file
|
|
47
|
+
*/
|
|
48
|
+
dtsHeader?: string
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* dts header file path to be prepended to the generated dts file
|
|
52
|
+
* if both dtsHeader and dtsHeaderFile are provided, dtsHeaderFile will be used
|
|
53
|
+
*/
|
|
54
|
+
dtsHeaderFile?: string
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* wasm compilation options
|
|
58
|
+
*/
|
|
59
|
+
wasm?: {
|
|
60
|
+
/**
|
|
61
|
+
* https://developer.mozilla.org/en-US/docs/WebAssembly/JavaScript_interface/Memory
|
|
62
|
+
* @default 4000 pages (256MiB)
|
|
63
|
+
*/
|
|
64
|
+
initialMemory?: number
|
|
65
|
+
/**
|
|
66
|
+
* @default 65536 pages (4GiB)
|
|
67
|
+
*/
|
|
68
|
+
maximumMemory?: number
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Browser wasm binding configuration
|
|
72
|
+
*/
|
|
73
|
+
browser: {
|
|
74
|
+
/**
|
|
75
|
+
* Whether to use fs module in browser
|
|
76
|
+
*/
|
|
77
|
+
fs?: boolean
|
|
78
|
+
/**
|
|
79
|
+
* Whether to initialize wasm asynchronously
|
|
80
|
+
*/
|
|
81
|
+
asyncInit?: boolean
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
27
85
|
/**
|
|
28
86
|
* @deprecated binaryName instead
|
|
29
87
|
*/
|
|
@@ -71,22 +129,34 @@ export interface CommonPackageJsonFields {
|
|
|
71
129
|
main?: string
|
|
72
130
|
module?: string
|
|
73
131
|
types?: string
|
|
132
|
+
browser?: string
|
|
74
133
|
exports?: any
|
|
75
134
|
|
|
76
135
|
dependencies?: Record<string, string>
|
|
77
136
|
devDependencies?: Record<string, string>
|
|
137
|
+
|
|
138
|
+
ava?: {
|
|
139
|
+
timeout?: string
|
|
140
|
+
}
|
|
78
141
|
}
|
|
79
142
|
|
|
80
143
|
export type NapiConfig = Required<
|
|
81
144
|
Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>
|
|
82
|
-
> &
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
145
|
+
> &
|
|
146
|
+
Pick<UserNapiConfig, 'wasm' | 'dtsHeader' | 'dtsHeaderFile' | 'constEnum'> & {
|
|
147
|
+
targets: Target[]
|
|
148
|
+
packageJson: CommonPackageJsonFields
|
|
149
|
+
}
|
|
86
150
|
|
|
87
|
-
export async function readNapiConfig(
|
|
151
|
+
export async function readNapiConfig(
|
|
152
|
+
path: string,
|
|
153
|
+
configPath?: string,
|
|
154
|
+
): Promise<NapiConfig> {
|
|
155
|
+
if (configPath && !(await fileExists(configPath))) {
|
|
156
|
+
throw new Error(`NAPI-RS config not found at ${configPath}`)
|
|
157
|
+
}
|
|
88
158
|
if (!(await fileExists(path))) {
|
|
89
|
-
throw new Error(`
|
|
159
|
+
throw new Error(`package.json not found at ${path}`)
|
|
90
160
|
}
|
|
91
161
|
// May support multiple config sources later on.
|
|
92
162
|
const content = await readFileAsync(path, 'utf8')
|
|
@@ -94,12 +164,34 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
94
164
|
try {
|
|
95
165
|
pkgJson = JSON.parse(content) as CommonPackageJsonFields
|
|
96
166
|
} catch (e) {
|
|
97
|
-
throw new Error(
|
|
167
|
+
throw new Error(`Failed to parse package.json at ${path}`, {
|
|
98
168
|
cause: e,
|
|
99
169
|
})
|
|
100
170
|
}
|
|
101
171
|
|
|
172
|
+
let separatedConfig: UserNapiConfig | undefined
|
|
173
|
+
if (configPath) {
|
|
174
|
+
const configContent = await readFileAsync(configPath, 'utf8')
|
|
175
|
+
try {
|
|
176
|
+
separatedConfig = JSON.parse(configContent) as UserNapiConfig
|
|
177
|
+
} catch (e) {
|
|
178
|
+
throw new Error(`Failed to parse NAPI-RS config at ${configPath}`, {
|
|
179
|
+
cause: e,
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
102
184
|
const userNapiConfig = pkgJson.napi ?? {}
|
|
185
|
+
if (pkgJson.napi && separatedConfig) {
|
|
186
|
+
const pkgJsonPath = underline(path)
|
|
187
|
+
const configPathUnderline = underline(configPath!)
|
|
188
|
+
console.warn(
|
|
189
|
+
yellow(
|
|
190
|
+
`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`,
|
|
191
|
+
),
|
|
192
|
+
)
|
|
193
|
+
Object.assign(userNapiConfig, separatedConfig)
|
|
194
|
+
}
|
|
103
195
|
const napiConfig: NapiConfig = merge(
|
|
104
196
|
{
|
|
105
197
|
binaryName: 'index',
|
|
@@ -114,17 +206,31 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
114
206
|
let targets: string[] = userNapiConfig.targets ?? []
|
|
115
207
|
|
|
116
208
|
// compatible with old config
|
|
117
|
-
if (userNapiConfig
|
|
118
|
-
|
|
209
|
+
if (userNapiConfig?.name) {
|
|
210
|
+
console.warn(
|
|
211
|
+
yellow(
|
|
212
|
+
`[DEPRECATED] napi.name is deprecated, use napi.binaryName instead.`,
|
|
213
|
+
),
|
|
214
|
+
)
|
|
215
|
+
napiConfig.binaryName = userNapiConfig.name
|
|
119
216
|
}
|
|
120
217
|
|
|
121
218
|
if (!targets.length) {
|
|
219
|
+
let deprecatedWarned = false
|
|
220
|
+
const warning = yellow(
|
|
221
|
+
`[DEPRECATED] napi.triples is deprecated, use napi.targets instead.`,
|
|
222
|
+
)
|
|
122
223
|
if (userNapiConfig.triples?.defaults) {
|
|
224
|
+
deprecatedWarned = true
|
|
225
|
+
console.warn(warning)
|
|
123
226
|
targets = targets.concat(DEFAULT_TARGETS)
|
|
124
227
|
}
|
|
125
228
|
|
|
126
229
|
if (userNapiConfig.triples?.additional?.length) {
|
|
127
230
|
targets = targets.concat(userNapiConfig.triples.additional)
|
|
231
|
+
if (!deprecatedWarned) {
|
|
232
|
+
console.warn(warning)
|
|
233
|
+
}
|
|
128
234
|
}
|
|
129
235
|
}
|
|
130
236
|
|
package/src/utils/index.ts
CHANGED
package/src/utils/metadata.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import fs from 'fs'
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import fs from 'node:fs'
|
|
3
3
|
|
|
4
4
|
export type CrateTargetKind =
|
|
5
5
|
| 'bin'
|
|
@@ -26,6 +26,18 @@ export interface Crate {
|
|
|
26
26
|
targets: CrateTarget[]
|
|
27
27
|
features: Record<string, string[]>
|
|
28
28
|
manifest_path: string
|
|
29
|
+
dependencies: Array<{
|
|
30
|
+
name: string
|
|
31
|
+
source: string
|
|
32
|
+
req: string
|
|
33
|
+
kind: string | null
|
|
34
|
+
rename: string | null
|
|
35
|
+
optional: boolean
|
|
36
|
+
uses_default_features: boolean
|
|
37
|
+
features: string[]
|
|
38
|
+
target: string | null
|
|
39
|
+
registry: string | null
|
|
40
|
+
}>
|
|
29
41
|
}
|
|
30
42
|
|
|
31
43
|
export interface CargoWorkspaceMetadata {
|
|
@@ -41,19 +53,32 @@ export function parseMetadata(manifestPath: string) {
|
|
|
41
53
|
throw new Error(`No crate found in manifest: ${manifestPath}`)
|
|
42
54
|
}
|
|
43
55
|
|
|
44
|
-
const
|
|
56
|
+
const { stdout, stderr, status, error } = spawnSync(
|
|
57
|
+
'cargo',
|
|
58
|
+
[
|
|
59
|
+
'metadata',
|
|
60
|
+
'--manifest-path',
|
|
61
|
+
manifestPath,
|
|
62
|
+
'--format-version',
|
|
63
|
+
'1',
|
|
64
|
+
'--no-deps',
|
|
65
|
+
],
|
|
66
|
+
{ encoding: 'utf-8' },
|
|
67
|
+
)
|
|
45
68
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
if (error) {
|
|
70
|
+
throw new Error('cargo metadata failed to run', { cause: error })
|
|
71
|
+
}
|
|
72
|
+
if (status !== 0) {
|
|
73
|
+
const simpleMessage = `cargo metadata exited with code ${status}`
|
|
74
|
+
throw new Error(`${simpleMessage} and error message:\n\n${stderr}`, {
|
|
75
|
+
cause: new Error(simpleMessage),
|
|
49
76
|
})
|
|
50
|
-
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
return JSON.parse(stdout) as CargoWorkspaceMetadata
|
|
51
81
|
} catch (e) {
|
|
52
|
-
throw new Error(
|
|
53
|
-
`Failed to parse cargo metadata output by command: ${cmd}`,
|
|
54
|
-
{
|
|
55
|
-
cause: e,
|
|
56
|
-
},
|
|
57
|
-
)
|
|
82
|
+
throw new Error('Failed to parse cargo metadata JSON', { cause: e })
|
|
58
83
|
}
|
|
59
84
|
}
|
package/src/utils/misc.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
package/src/utils/target.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
1
|
+
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',
|
|
@@ -15,15 +19,20 @@ export const AVAILABLE_TARGETS = [
|
|
|
15
19
|
'x86_64-unknown-freebsd',
|
|
16
20
|
'i686-pc-windows-msvc',
|
|
17
21
|
'armv7-unknown-linux-gnueabihf',
|
|
22
|
+
'armv7-unknown-linux-musleabihf',
|
|
18
23
|
'armv7-linux-androideabi',
|
|
19
24
|
'universal-apple-darwin',
|
|
20
25
|
'riscv64gc-unknown-linux-gnu',
|
|
26
|
+
'powerpc64le-unknown-linux-gnu',
|
|
27
|
+
's390x-unknown-linux-gnu',
|
|
28
|
+
'wasm32-wasi-preview1-threads',
|
|
21
29
|
] as const
|
|
22
30
|
|
|
23
31
|
export type TargetTriple = (typeof AVAILABLE_TARGETS)[number]
|
|
24
32
|
|
|
25
33
|
export const DEFAULT_TARGETS = [
|
|
26
34
|
'x86_64-apple-darwin',
|
|
35
|
+
'aarch64-apple-darwin',
|
|
27
36
|
'x86_64-pc-windows-msvc',
|
|
28
37
|
'x86_64-unknown-linux-gnu',
|
|
29
38
|
] as const
|
|
@@ -31,6 +40,8 @@ export const DEFAULT_TARGETS = [
|
|
|
31
40
|
export const TARGET_LINKER: Record<string, string> = {
|
|
32
41
|
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
|
33
42
|
'riscv64gc-unknown-linux-gnu': 'riscv64-linux-gnu-gcc',
|
|
43
|
+
'powerpc64le-unknown-linux-gnu': 'powerpc64le-linux-gnu-gcc',
|
|
44
|
+
's390x-unknown-linux-gnu': 's390x-linux-gnu-gcc',
|
|
34
45
|
}
|
|
35
46
|
|
|
36
47
|
// https://nodejs.org/api/process.html#process_process_arch
|
|
@@ -48,6 +59,7 @@ type NodeJSArch =
|
|
|
48
59
|
| 'x32'
|
|
49
60
|
| 'x64'
|
|
50
61
|
| 'universal'
|
|
62
|
+
| 'wasm32'
|
|
51
63
|
|
|
52
64
|
const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
53
65
|
x86_64: 'x64',
|
|
@@ -55,6 +67,7 @@ const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
|
55
67
|
i686: 'ia32',
|
|
56
68
|
armv7: 'arm',
|
|
57
69
|
riscv64gc: 'riscv64',
|
|
70
|
+
powerpc64le: 'ppc64',
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
export const NodeArchToCpu: Record<string, string> = {
|
|
@@ -63,6 +76,7 @@ export const NodeArchToCpu: Record<string, string> = {
|
|
|
63
76
|
ia32: 'i686',
|
|
64
77
|
arm: 'armv7',
|
|
65
78
|
riscv64: 'riscv64gc',
|
|
79
|
+
ppc64: 'powerpc64le',
|
|
66
80
|
}
|
|
67
81
|
|
|
68
82
|
const SysToNodePlatform: Record<string, Platform> = {
|
|
@@ -80,7 +94,7 @@ export interface Target {
|
|
|
80
94
|
triple: string
|
|
81
95
|
platformArchABI: string
|
|
82
96
|
platform: Platform
|
|
83
|
-
arch: NodeJSArch
|
|
97
|
+
arch: NodeJSArch
|
|
84
98
|
abi: string | null
|
|
85
99
|
}
|
|
86
100
|
|
|
@@ -95,10 +109,14 @@ export interface Target {
|
|
|
95
109
|
* - `abi` = The ABI, for example `gnu`, `android`, `eabi`, etc.
|
|
96
110
|
*/
|
|
97
111
|
export function parseTriple(rawTriple: string): Target {
|
|
98
|
-
if (
|
|
112
|
+
if (
|
|
113
|
+
rawTriple === 'wasm32-wasi' ||
|
|
114
|
+
rawTriple === 'wasm32-wasi-preview1-threads' ||
|
|
115
|
+
rawTriple.startsWith('wasm32-wasip')
|
|
116
|
+
) {
|
|
99
117
|
return {
|
|
100
118
|
triple: rawTriple,
|
|
101
|
-
platformArchABI:
|
|
119
|
+
platformArchABI: 'wasm32-wasi',
|
|
102
120
|
platform: 'wasi',
|
|
103
121
|
arch: 'wasm32',
|
|
104
122
|
abi: 'wasi',
|