@napi-rs/cli 3.0.0-alpha.5 → 3.0.0-alpha.51
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/api/artifacts.js +32 -8
- package/dist/api/artifacts.js.map +1 -0
- package/dist/api/build.d.ts +1 -1
- package/dist/api/build.js +249 -25
- package/dist/api/build.js.map +1 -0
- package/dist/api/create-npm-dirs.js +46 -8
- package/dist/api/create-npm-dirs.js.map +1 -0
- package/dist/api/new.js +58 -20
- package/dist/api/new.js.map +1 -0
- package/dist/api/pre-publish.js +10 -7
- package/dist/api/pre-publish.js.map +1 -0
- package/dist/api/rename.js +10 -1
- package/dist/api/rename.js.map +1 -0
- package/dist/api/templates/.gitignore.d.ts +1 -1
- package/dist/api/templates/.gitignore.js +2 -0
- package/dist/api/templates/.gitignore.js.map +1 -0
- package/dist/api/templates/.npmignore.js +1 -0
- package/dist/api/templates/.npmignore.js.map +1 -0
- package/dist/api/templates/build.rs.js +1 -0
- package/dist/api/templates/build.rs.js.map +1 -0
- package/dist/api/templates/cargo.toml.js +1 -0
- package/dist/api/templates/cargo.toml.js.map +1 -0
- package/dist/api/templates/ci-template.d.ts +3 -1
- package/dist/api/templates/ci-template.js +165 -150
- package/dist/api/templates/ci-template.js.map +1 -0
- package/dist/api/templates/ci.yml.d.ts +3 -1
- package/dist/api/templates/ci.yml.js +22 -5
- package/dist/api/templates/ci.yml.js.map +1 -0
- package/dist/api/templates/index.js +1 -0
- package/dist/api/templates/index.js.map +1 -0
- package/dist/api/templates/js-binding.js +150 -225
- package/dist/api/templates/js-binding.js.map +1 -0
- package/dist/api/templates/lib.rs.js +2 -4
- package/dist/api/templates/lib.rs.js.map +1 -0
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/load-wasi-template.js +155 -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 +27 -4
- package/dist/api/templates/package.json.js.map +1 -0
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.js +103 -0
- package/dist/api/templates/wasi-worker-template.js.map +1 -0
- package/dist/api/universalize.js +6 -5
- package/dist/api/universalize.js.map +1 -0
- package/dist/api/version.js +3 -2
- package/dist/api/version.js.map +1 -0
- package/dist/cli.js +1 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/artifacts.js +3 -2
- package/dist/commands/artifacts.js.map +1 -0
- package/dist/commands/build.js +2 -1
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/create-npm-dirs.js +1 -0
- package/dist/commands/create-npm-dirs.js.map +1 -0
- package/dist/commands/help.js +1 -0
- package/dist/commands/help.js.map +1 -0
- package/dist/commands/new.js +25 -6
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/pre-publish.js +1 -0
- package/dist/commands/pre-publish.js.map +1 -0
- package/dist/commands/rename.js +1 -0
- package/dist/commands/rename.js.map +1 -0
- package/dist/commands/universalize.js +1 -0
- package/dist/commands/universalize.js.map +1 -0
- package/dist/commands/version.js +1 -0
- package/dist/commands/version.js.map +1 -0
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/artifacts.js +11 -2
- package/dist/def/artifacts.js.map +1 -0
- package/dist/def/build.d.ts +20 -2
- package/dist/def/build.js +15 -2
- package/dist/def/build.js.map +1 -0
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/create-npm-dirs.js +5 -0
- package/dist/def/create-npm-dirs.js.map +1 -0
- package/dist/def/new.d.ts +24 -6
- package/dist/def/new.js +12 -1
- package/dist/def/new.js.map +1 -0
- package/dist/def/pre-publish.d.ts +10 -0
- package/dist/def/pre-publish.js +8 -3
- package/dist/def/pre-publish.js.map +1 -0
- package/dist/def/rename.d.ts +11 -1
- package/dist/def/rename.js +6 -1
- package/dist/def/rename.js.map +1 -0
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/universalize.js +5 -0
- package/dist/def/universalize.js.map +1 -0
- package/dist/def/version.d.ts +10 -0
- package/dist/def/version.js +5 -0
- package/dist/def/version.js.map +1 -0
- package/dist/index.cjs +3931 -718
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- 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__/target.spec.js +1 -0
- package/dist/utils/__tests__/target.spec.js.map +1 -0
- package/dist/utils/__tests__/typegen.spec.js +9 -4
- package/dist/utils/__tests__/typegen.spec.js.map +1 -0
- package/dist/utils/__tests__/version.spec.js +1 -0
- package/dist/utils/__tests__/version.spec.js.map +1 -0
- package/dist/utils/cargo.js +2 -1
- package/dist/utils/cargo.js.map +1 -0
- package/dist/utils/config.d.ts +49 -5
- package/dist/utils/config.js +39 -6
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/log.js +1 -0
- package/dist/utils/log.js.map +1 -0
- package/dist/utils/metadata.js +3 -2
- package/dist/utils/metadata.js.map +1 -0
- package/dist/utils/misc.d.ts +1 -1
- package/dist/utils/misc.js +4 -3
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/target.d.ts +9 -5
- package/dist/utils/target.js +25 -1
- package/dist/utils/target.js.map +1 -0
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +8 -6
- package/dist/utils/typegen.js.map +1 -0
- package/dist/utils/version.d.ts +2 -1
- package/dist/utils/version.js +11 -8
- package/dist/utils/version.js.map +1 -0
- package/package.json +46 -13
- package/src/api/artifacts.ts +83 -8
- package/src/api/build.ts +417 -27
- package/src/api/create-npm-dirs.ts +56 -8
- package/src/api/new.ts +86 -31
- package/src/api/pre-publish.ts +13 -7
- package/src/api/rename.ts +10 -1
- package/src/api/templates/.gitignore.ts +1 -0
- package/src/api/templates/ci-template.ts +174 -150
- package/src/api/templates/ci.yml.ts +24 -6
- package/src/api/templates/js-binding.ts +150 -225
- package/src/api/templates/lib.rs.ts +1 -4
- package/src/api/templates/load-wasi-template.ts +168 -0
- package/src/api/templates/package.json.ts +47 -5
- package/src/api/templates/wasi-worker-template.ts +103 -0
- package/src/api/universalize.ts +8 -5
- 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 +25 -6
- package/src/def/artifacts.ts +22 -3
- package/src/def/build.ts +32 -4
- 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__/__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 +555 -0
- 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 +1 -1
- package/src/utils/config.ts +114 -12
- package/src/utils/index.ts +0 -1
- package/src/utils/metadata.ts +2 -2
- package/src/utils/misc.ts +11 -3
- package/src/utils/target.ts +34 -7
- package/src/utils/typegen.ts +11 -5
- package/src/utils/version.ts +10 -8
- package/dist/utils/ci.d.ts +0 -11
- package/dist/utils/ci.js +0 -95
- package/src/utils/ci.ts +0 -111
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,47 @@ 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
|
+
}
|
|
80
|
+
|
|
27
81
|
/**
|
|
28
82
|
* @deprecated binaryName instead
|
|
29
83
|
*/
|
|
@@ -41,7 +95,7 @@ interface UserNapiConfig {
|
|
|
41
95
|
/**
|
|
42
96
|
* Whether enable default targets
|
|
43
97
|
*/
|
|
44
|
-
|
|
98
|
+
defaults: boolean
|
|
45
99
|
/**
|
|
46
100
|
* Additional targets to be compiled for
|
|
47
101
|
*/
|
|
@@ -71,22 +125,34 @@ export interface CommonPackageJsonFields {
|
|
|
71
125
|
main?: string
|
|
72
126
|
module?: string
|
|
73
127
|
types?: string
|
|
128
|
+
browser?: string
|
|
74
129
|
exports?: any
|
|
75
130
|
|
|
76
131
|
dependencies?: Record<string, string>
|
|
77
132
|
devDependencies?: Record<string, string>
|
|
133
|
+
|
|
134
|
+
ava?: {
|
|
135
|
+
timeout?: string
|
|
136
|
+
}
|
|
78
137
|
}
|
|
79
138
|
|
|
80
139
|
export type NapiConfig = Required<
|
|
81
140
|
Pick<UserNapiConfig, 'binaryName' | 'packageName' | 'npmClient'>
|
|
82
|
-
> &
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
141
|
+
> &
|
|
142
|
+
Pick<UserNapiConfig, 'wasm' | 'dtsHeader' | 'dtsHeaderFile'> & {
|
|
143
|
+
targets: Target[]
|
|
144
|
+
packageJson: CommonPackageJsonFields
|
|
145
|
+
}
|
|
86
146
|
|
|
87
|
-
export async function readNapiConfig(
|
|
147
|
+
export async function readNapiConfig(
|
|
148
|
+
path: string,
|
|
149
|
+
configPath?: string,
|
|
150
|
+
): Promise<NapiConfig> {
|
|
151
|
+
if (configPath && !(await fileExists(configPath))) {
|
|
152
|
+
throw new Error(`NAPI-RS config not found at ${configPath}`)
|
|
153
|
+
}
|
|
88
154
|
if (!(await fileExists(path))) {
|
|
89
|
-
throw new Error(`
|
|
155
|
+
throw new Error(`package.json not found at ${path}`)
|
|
90
156
|
}
|
|
91
157
|
// May support multiple config sources later on.
|
|
92
158
|
const content = await readFileAsync(path, 'utf8')
|
|
@@ -94,12 +160,34 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
94
160
|
try {
|
|
95
161
|
pkgJson = JSON.parse(content) as CommonPackageJsonFields
|
|
96
162
|
} catch (e) {
|
|
97
|
-
throw new Error(
|
|
163
|
+
throw new Error(`Failed to parse package.json at ${path}`, {
|
|
98
164
|
cause: e,
|
|
99
165
|
})
|
|
100
166
|
}
|
|
101
167
|
|
|
168
|
+
let separatedConfig: UserNapiConfig | undefined
|
|
169
|
+
if (configPath) {
|
|
170
|
+
const configContent = await readFileAsync(configPath, 'utf8')
|
|
171
|
+
try {
|
|
172
|
+
separatedConfig = JSON.parse(configContent) as UserNapiConfig
|
|
173
|
+
} catch (e) {
|
|
174
|
+
throw new Error(`Failed to parse NAPI-RS config at ${configPath}`, {
|
|
175
|
+
cause: e,
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
102
180
|
const userNapiConfig = pkgJson.napi ?? {}
|
|
181
|
+
if (pkgJson.napi && separatedConfig) {
|
|
182
|
+
const pkgJsonPath = underline(path)
|
|
183
|
+
const configPathUnderline = underline(configPath!)
|
|
184
|
+
console.warn(
|
|
185
|
+
yellow(
|
|
186
|
+
`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`,
|
|
187
|
+
),
|
|
188
|
+
)
|
|
189
|
+
Object.assign(userNapiConfig, separatedConfig)
|
|
190
|
+
}
|
|
103
191
|
const napiConfig: NapiConfig = merge(
|
|
104
192
|
{
|
|
105
193
|
binaryName: 'index',
|
|
@@ -114,17 +202,31 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
114
202
|
let targets: string[] = userNapiConfig.targets ?? []
|
|
115
203
|
|
|
116
204
|
// compatible with old config
|
|
117
|
-
if (userNapiConfig
|
|
118
|
-
|
|
205
|
+
if (userNapiConfig?.name) {
|
|
206
|
+
console.warn(
|
|
207
|
+
yellow(
|
|
208
|
+
`[DEPRECATED] napi.name is deprecated, use napi.binaryName instead.`,
|
|
209
|
+
),
|
|
210
|
+
)
|
|
211
|
+
napiConfig.binaryName = userNapiConfig.name
|
|
119
212
|
}
|
|
120
213
|
|
|
121
214
|
if (!targets.length) {
|
|
122
|
-
|
|
215
|
+
let deprecatedWarned = false
|
|
216
|
+
const warning = yellow(
|
|
217
|
+
`[DEPRECATED] napi.triples is deprecated, use napi.targets instead.`,
|
|
218
|
+
)
|
|
219
|
+
if (userNapiConfig.triples?.defaults) {
|
|
220
|
+
deprecatedWarned = true
|
|
221
|
+
console.warn(warning)
|
|
123
222
|
targets = targets.concat(DEFAULT_TARGETS)
|
|
124
223
|
}
|
|
125
224
|
|
|
126
225
|
if (userNapiConfig.triples?.additional?.length) {
|
|
127
226
|
targets = targets.concat(userNapiConfig.triples.additional)
|
|
227
|
+
if (!deprecatedWarned) {
|
|
228
|
+
console.warn(warning)
|
|
229
|
+
}
|
|
128
230
|
}
|
|
129
231
|
}
|
|
130
232
|
|
package/src/utils/index.ts
CHANGED
package/src/utils/metadata.ts
CHANGED
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,4 +1,10 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
|
|
3
|
+
export type Platform = NodeJS.Platform | 'wasm' | 'wasi'
|
|
4
|
+
|
|
5
|
+
export const UNIVERSAL_TARGETS = {
|
|
6
|
+
'universal-apple-darwin': ['aarch64-apple-darwin', 'x86_64-apple-darwin'],
|
|
7
|
+
} as const
|
|
2
8
|
|
|
3
9
|
export const AVAILABLE_TARGETS = [
|
|
4
10
|
'aarch64-apple-darwin',
|
|
@@ -13,15 +19,20 @@ export const AVAILABLE_TARGETS = [
|
|
|
13
19
|
'x86_64-unknown-freebsd',
|
|
14
20
|
'i686-pc-windows-msvc',
|
|
15
21
|
'armv7-unknown-linux-gnueabihf',
|
|
22
|
+
'armv7-unknown-linux-musleabihf',
|
|
16
23
|
'armv7-linux-androideabi',
|
|
17
24
|
'universal-apple-darwin',
|
|
18
25
|
'riscv64gc-unknown-linux-gnu',
|
|
26
|
+
'powerpc64le-unknown-linux-gnu',
|
|
27
|
+
's390x-unknown-linux-gnu',
|
|
28
|
+
'wasm32-wasi-preview1-threads',
|
|
19
29
|
] as const
|
|
20
30
|
|
|
21
31
|
export type TargetTriple = (typeof AVAILABLE_TARGETS)[number]
|
|
22
32
|
|
|
23
33
|
export const DEFAULT_TARGETS = [
|
|
24
34
|
'x86_64-apple-darwin',
|
|
35
|
+
'aarch64-apple-darwin',
|
|
25
36
|
'x86_64-pc-windows-msvc',
|
|
26
37
|
'x86_64-unknown-linux-gnu',
|
|
27
38
|
] as const
|
|
@@ -29,6 +40,8 @@ export const DEFAULT_TARGETS = [
|
|
|
29
40
|
export const TARGET_LINKER: Record<string, string> = {
|
|
30
41
|
'aarch64-unknown-linux-musl': 'aarch64-linux-musl-gcc',
|
|
31
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',
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
// https://nodejs.org/api/process.html#process_process_arch
|
|
@@ -46,6 +59,7 @@ type NodeJSArch =
|
|
|
46
59
|
| 'x32'
|
|
47
60
|
| 'x64'
|
|
48
61
|
| 'universal'
|
|
62
|
+
| 'wasm32'
|
|
49
63
|
|
|
50
64
|
const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
51
65
|
x86_64: 'x64',
|
|
@@ -53,6 +67,7 @@ const CpuToNodeArch: Record<string, NodeJSArch> = {
|
|
|
53
67
|
i686: 'ia32',
|
|
54
68
|
armv7: 'arm',
|
|
55
69
|
riscv64gc: 'riscv64',
|
|
70
|
+
powerpc64le: 'ppc64',
|
|
56
71
|
}
|
|
57
72
|
|
|
58
73
|
export const NodeArchToCpu: Record<string, string> = {
|
|
@@ -61,25 +76,24 @@ export const NodeArchToCpu: Record<string, string> = {
|
|
|
61
76
|
ia32: 'i686',
|
|
62
77
|
arm: 'armv7',
|
|
63
78
|
riscv64: 'riscv64gc',
|
|
79
|
+
ppc64: 'powerpc64le',
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
const SysToNodePlatform: Record<string,
|
|
82
|
+
const SysToNodePlatform: Record<string, Platform> = {
|
|
67
83
|
linux: 'linux',
|
|
68
84
|
freebsd: 'freebsd',
|
|
69
85
|
darwin: 'darwin',
|
|
70
86
|
windows: 'win32',
|
|
71
87
|
}
|
|
72
88
|
|
|
73
|
-
export const UniArchsByPlatform: Partial<
|
|
74
|
-
Record<NodeJS.Platform, NodeJSArch[]>
|
|
75
|
-
> = {
|
|
89
|
+
export const UniArchsByPlatform: Partial<Record<Platform, NodeJSArch[]>> = {
|
|
76
90
|
darwin: ['x64', 'arm64'],
|
|
77
91
|
}
|
|
78
92
|
|
|
79
93
|
export interface Target {
|
|
80
94
|
triple: string
|
|
81
95
|
platformArchABI: string
|
|
82
|
-
platform:
|
|
96
|
+
platform: Platform
|
|
83
97
|
arch: NodeJSArch
|
|
84
98
|
abi: string | null
|
|
85
99
|
}
|
|
@@ -95,6 +109,19 @@ export interface Target {
|
|
|
95
109
|
* - `abi` = The ABI, for example `gnu`, `android`, `eabi`, etc.
|
|
96
110
|
*/
|
|
97
111
|
export function parseTriple(rawTriple: string): Target {
|
|
112
|
+
if (
|
|
113
|
+
rawTriple === 'wasm32-wasi' ||
|
|
114
|
+
rawTriple === 'wasm32-wasi-preview1-threads' ||
|
|
115
|
+
rawTriple.startsWith('wasm32-wasip')
|
|
116
|
+
) {
|
|
117
|
+
return {
|
|
118
|
+
triple: rawTriple,
|
|
119
|
+
platformArchABI: 'wasm32-wasi',
|
|
120
|
+
platform: 'wasi',
|
|
121
|
+
arch: 'wasm32',
|
|
122
|
+
abi: 'wasi',
|
|
123
|
+
}
|
|
124
|
+
}
|
|
98
125
|
const triple = rawTriple.endsWith('eabi')
|
|
99
126
|
? `${rawTriple.slice(0, -4)}-eabi`
|
|
100
127
|
: rawTriple
|
|
@@ -114,7 +141,7 @@ export function parseTriple(rawTriple: string): Target {
|
|
|
114
141
|
;[cpu, , sys, abi = null] = triples
|
|
115
142
|
}
|
|
116
143
|
|
|
117
|
-
const platform = SysToNodePlatform[sys] ?? (sys as
|
|
144
|
+
const platform = SysToNodePlatform[sys] ?? (sys as Platform)
|
|
118
145
|
const arch = CpuToNodeArch[cpu] ?? (cpu as NodeJSArch)
|
|
119
146
|
return {
|
|
120
147
|
triple: rawTriple,
|
package/src/utils/typegen.ts
CHANGED
|
@@ -25,7 +25,11 @@ interface TypeDefLine {
|
|
|
25
25
|
js_mod?: string
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function prettyPrint(
|
|
28
|
+
function prettyPrint(
|
|
29
|
+
line: TypeDefLine,
|
|
30
|
+
constEnum: boolean,
|
|
31
|
+
ident: number,
|
|
32
|
+
): string {
|
|
29
33
|
let s = line.js_doc ?? ''
|
|
30
34
|
switch (line.kind) {
|
|
31
35
|
case TypeDefKind.Interface:
|
|
@@ -33,7 +37,8 @@ function prettyPrint(line: TypeDefLine, ident: number): string {
|
|
|
33
37
|
break
|
|
34
38
|
|
|
35
39
|
case TypeDefKind.Enum:
|
|
36
|
-
|
|
40
|
+
const enumName = constEnum ? 'const enum' : 'enum'
|
|
41
|
+
s += `export ${enumName} ${line.name} {\n${line.def}\n}`
|
|
37
42
|
break
|
|
38
43
|
|
|
39
44
|
case TypeDefKind.Struct:
|
|
@@ -52,20 +57,21 @@ function prettyPrint(line: TypeDefLine, ident: number): string {
|
|
|
52
57
|
|
|
53
58
|
export async function processTypeDef(
|
|
54
59
|
intermediateTypeFile: string,
|
|
60
|
+
constEnum: boolean,
|
|
55
61
|
header?: string,
|
|
56
62
|
) {
|
|
57
63
|
const exports: string[] = []
|
|
58
64
|
const defs = await readIntermediateTypeFile(intermediateTypeFile)
|
|
59
65
|
const groupedDefs = preprocessTypeDef(defs)
|
|
60
66
|
|
|
61
|
-
header = header
|
|
67
|
+
header = header ?? ''
|
|
62
68
|
let dts = ''
|
|
63
69
|
|
|
64
70
|
sortBy(Array.from(groupedDefs), ([namespace]) => namespace).forEach(
|
|
65
71
|
([namespace, defs]) => {
|
|
66
72
|
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
67
73
|
for (const def of defs) {
|
|
68
|
-
dts += prettyPrint(def, 0) + '\n\n'
|
|
74
|
+
dts += prettyPrint(def, constEnum, 0) + '\n\n'
|
|
69
75
|
switch (def.kind) {
|
|
70
76
|
case TypeDefKind.Const:
|
|
71
77
|
case TypeDefKind.Enum:
|
|
@@ -85,7 +91,7 @@ export async function processTypeDef(
|
|
|
85
91
|
exports.push(namespace)
|
|
86
92
|
dts += `export namespace ${namespace} {\n`
|
|
87
93
|
for (const def of defs) {
|
|
88
|
-
dts += prettyPrint(def, 2) + '\n'
|
|
94
|
+
dts += prettyPrint(def, constEnum, 2) + '\n'
|
|
89
95
|
}
|
|
90
96
|
dts += '}\n\n'
|
|
91
97
|
}
|
package/src/utils/version.ts
CHANGED
|
@@ -7,20 +7,22 @@ export enum NapiVersion {
|
|
|
7
7
|
Napi6,
|
|
8
8
|
Napi7,
|
|
9
9
|
Napi8,
|
|
10
|
+
Napi9,
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/// because node support new napi version in some minor version updates, so we might meet such situation:
|
|
13
14
|
/// `node v10.20.0` supports `napi5` and `napi6`, but `node v12.0.0` only support `napi4`,
|
|
14
|
-
/// by which, we can not tell directly napi version
|
|
15
|
+
/// by which, we can not tell directly napi version supportless from node version directly.
|
|
15
16
|
const NAPI_VERSION_MATRIX = new Map<NapiVersion, string>([
|
|
16
|
-
[NapiVersion.Napi1, '8.6.0'],
|
|
17
|
-
[NapiVersion.Napi2, '8.10.0 | 9.3.0'],
|
|
18
|
-
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0'],
|
|
19
|
-
[NapiVersion.Napi4, '10.16.0 | 11.8.0'],
|
|
20
|
-
[NapiVersion.Napi5, '10.17.0 | 12.11.0'],
|
|
17
|
+
[NapiVersion.Napi1, '8.6.0 | 9.0.0 | 10.0.0'],
|
|
18
|
+
[NapiVersion.Napi2, '8.10.0 | 9.3.0 | 10.0.0'],
|
|
19
|
+
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0 | 10.0.0'],
|
|
20
|
+
[NapiVersion.Napi4, '10.16.0 | 11.8.0 | 12.0.0'],
|
|
21
|
+
[NapiVersion.Napi5, '10.17.0 | 12.11.0 | 13.0.0'],
|
|
21
22
|
[NapiVersion.Napi6, '10.20.0 | 12.17.0 | 14.0.0'],
|
|
22
|
-
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0'],
|
|
23
|
-
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0'],
|
|
23
|
+
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0 | 15.0.0'],
|
|
24
|
+
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0 | 16.0.0'],
|
|
25
|
+
[NapiVersion.Napi9, '18.17.0 | 20.3.0 | 21.1.0'],
|
|
24
26
|
])
|
|
25
27
|
|
|
26
28
|
interface NodeVersion {
|
package/dist/utils/ci.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TargetTriple } from './target.js';
|
|
2
|
-
export declare const CIConfig: Partial<Record<TargetTriple, {
|
|
3
|
-
host: string;
|
|
4
|
-
build_image?: string;
|
|
5
|
-
build_setup?: string[];
|
|
6
|
-
test?: boolean;
|
|
7
|
-
test_image?: string;
|
|
8
|
-
test_setup?: string[];
|
|
9
|
-
yarn_cpu?: string;
|
|
10
|
-
yarn_libc?: string;
|
|
11
|
-
}>>;
|
package/dist/utils/ci.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
export const CIConfig = {
|
|
2
|
-
'x86_64-apple-darwin': {
|
|
3
|
-
host: 'macos-latest',
|
|
4
|
-
},
|
|
5
|
-
'x86_64-pc-windows-msvc': {
|
|
6
|
-
host: 'windows-latest',
|
|
7
|
-
},
|
|
8
|
-
'i686-pc-windows-msvc': {
|
|
9
|
-
host: 'windows-latest',
|
|
10
|
-
test: false,
|
|
11
|
-
},
|
|
12
|
-
'x86_64-unknown-linux-gnu': {
|
|
13
|
-
host: 'ubuntu-latest',
|
|
14
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian',
|
|
15
|
-
},
|
|
16
|
-
'x86_64-unknown-linux-musl': {
|
|
17
|
-
host: 'ubuntu-latest',
|
|
18
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
19
|
-
test_image: 'node:${{ matrix.node }}-alpine',
|
|
20
|
-
yarn_libc: 'musl',
|
|
21
|
-
},
|
|
22
|
-
'aarch64-apple-darwin': {
|
|
23
|
-
host: 'macos-latest',
|
|
24
|
-
build_setup: [
|
|
25
|
-
'sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*',
|
|
26
|
-
'export CC=$(xcrun -f clang)',
|
|
27
|
-
'export CXX=$(xcrun -f clang++)',
|
|
28
|
-
'export SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)',
|
|
29
|
-
'export CFLAGS="-isysroot $SDK_ROOT -isystem $SDK_ROOT"',
|
|
30
|
-
],
|
|
31
|
-
test: false,
|
|
32
|
-
},
|
|
33
|
-
'aarch64-unknown-linux-gnu': {
|
|
34
|
-
host: 'ubuntu-latest',
|
|
35
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64',
|
|
36
|
-
build_setup: [
|
|
37
|
-
'sudo apt-get update',
|
|
38
|
-
'sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y',
|
|
39
|
-
'export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu',
|
|
40
|
-
],
|
|
41
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}',
|
|
42
|
-
yarn_cpu: 'arm64',
|
|
43
|
-
},
|
|
44
|
-
'aarch64-unknown-linux-musl': {
|
|
45
|
-
host: 'ubuntu-latest',
|
|
46
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
47
|
-
build_setup: ['rustup target add aarch64-unknown-linux-musl'],
|
|
48
|
-
test_image: 'multiarch/alpine:aarch64-latest-stable',
|
|
49
|
-
test_setup: ['apk add nodejs npm yarn'],
|
|
50
|
-
yarn_cpu: 'arm64',
|
|
51
|
-
yarn_libc: 'musl',
|
|
52
|
-
},
|
|
53
|
-
'aarch64-pc-windows-msvc': {
|
|
54
|
-
host: 'windows-latest',
|
|
55
|
-
test: false,
|
|
56
|
-
},
|
|
57
|
-
'armv7-unknown-linux-gnueabihf': {
|
|
58
|
-
host: 'ubuntu-latest',
|
|
59
|
-
build_setup: [
|
|
60
|
-
'sudo apt-get update',
|
|
61
|
-
'sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y',
|
|
62
|
-
],
|
|
63
|
-
yarn_cpu: 'arm',
|
|
64
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}',
|
|
65
|
-
},
|
|
66
|
-
'aarch64-linux-android': {
|
|
67
|
-
host: 'ubuntu-latest',
|
|
68
|
-
build_setup: [
|
|
69
|
-
'export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
70
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
71
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"',
|
|
72
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
73
|
-
],
|
|
74
|
-
test: false,
|
|
75
|
-
},
|
|
76
|
-
'armv7-linux-androideabi': {
|
|
77
|
-
host: 'ubuntu-latest',
|
|
78
|
-
build_setup: [
|
|
79
|
-
'export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
80
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
81
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"',
|
|
82
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
83
|
-
],
|
|
84
|
-
test: false,
|
|
85
|
-
},
|
|
86
|
-
'riscv64gc-unknown-linux-gnu': {
|
|
87
|
-
host: 'ubuntu-latest',
|
|
88
|
-
build_setup: [
|
|
89
|
-
'sudo apt-get update',
|
|
90
|
-
'sudo apt-get install g++-riscv64-linux-gnu gcc-riscv64-linux-gnu -y',
|
|
91
|
-
],
|
|
92
|
-
// No official nodejs docker image for riscv64
|
|
93
|
-
test: false,
|
|
94
|
-
},
|
|
95
|
-
};
|
package/src/utils/ci.ts
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { TargetTriple } from './target.js'
|
|
2
|
-
|
|
3
|
-
export const CIConfig: Partial<
|
|
4
|
-
Record<
|
|
5
|
-
TargetTriple,
|
|
6
|
-
{
|
|
7
|
-
host: string
|
|
8
|
-
build_image?: string
|
|
9
|
-
build_setup?: string[]
|
|
10
|
-
test?: boolean
|
|
11
|
-
test_image?: string
|
|
12
|
-
test_setup?: string[]
|
|
13
|
-
yarn_cpu?: string
|
|
14
|
-
yarn_libc?: string
|
|
15
|
-
}
|
|
16
|
-
>
|
|
17
|
-
> = {
|
|
18
|
-
'x86_64-apple-darwin': {
|
|
19
|
-
host: 'macos-latest',
|
|
20
|
-
},
|
|
21
|
-
'x86_64-pc-windows-msvc': {
|
|
22
|
-
host: 'windows-latest',
|
|
23
|
-
},
|
|
24
|
-
'i686-pc-windows-msvc': {
|
|
25
|
-
host: 'windows-latest',
|
|
26
|
-
test: false,
|
|
27
|
-
},
|
|
28
|
-
'x86_64-unknown-linux-gnu': {
|
|
29
|
-
host: 'ubuntu-latest',
|
|
30
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian',
|
|
31
|
-
},
|
|
32
|
-
'x86_64-unknown-linux-musl': {
|
|
33
|
-
host: 'ubuntu-latest',
|
|
34
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
35
|
-
test_image: 'node:${{ matrix.node }}-alpine',
|
|
36
|
-
yarn_libc: 'musl',
|
|
37
|
-
},
|
|
38
|
-
'aarch64-apple-darwin': {
|
|
39
|
-
host: 'macos-latest',
|
|
40
|
-
build_setup: [
|
|
41
|
-
'sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*',
|
|
42
|
-
'export CC=$(xcrun -f clang)',
|
|
43
|
-
'export CXX=$(xcrun -f clang++)',
|
|
44
|
-
'export SDK_ROOT=$(xcrun --sdk macosx --show-sdk-path)',
|
|
45
|
-
'export CFLAGS="-isysroot $SDK_ROOT -isystem $SDK_ROOT"',
|
|
46
|
-
],
|
|
47
|
-
test: false,
|
|
48
|
-
},
|
|
49
|
-
'aarch64-unknown-linux-gnu': {
|
|
50
|
-
host: 'ubuntu-latest',
|
|
51
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64',
|
|
52
|
-
build_setup: [
|
|
53
|
-
'sudo apt-get update',
|
|
54
|
-
'sudo apt-get install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu -y',
|
|
55
|
-
'export CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu',
|
|
56
|
-
],
|
|
57
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:aarch64-${{ matrix.node }}',
|
|
58
|
-
yarn_cpu: 'arm64',
|
|
59
|
-
},
|
|
60
|
-
'aarch64-unknown-linux-musl': {
|
|
61
|
-
host: 'ubuntu-latest',
|
|
62
|
-
build_image: 'ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine',
|
|
63
|
-
build_setup: ['rustup target add aarch64-unknown-linux-musl'],
|
|
64
|
-
test_image: 'multiarch/alpine:aarch64-latest-stable',
|
|
65
|
-
test_setup: ['apk add nodejs npm yarn'],
|
|
66
|
-
yarn_cpu: 'arm64',
|
|
67
|
-
yarn_libc: 'musl',
|
|
68
|
-
},
|
|
69
|
-
'aarch64-pc-windows-msvc': {
|
|
70
|
-
host: 'windows-latest',
|
|
71
|
-
test: false,
|
|
72
|
-
},
|
|
73
|
-
'armv7-unknown-linux-gnueabihf': {
|
|
74
|
-
host: 'ubuntu-latest',
|
|
75
|
-
build_setup: [
|
|
76
|
-
'sudo apt-get update',
|
|
77
|
-
'sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y',
|
|
78
|
-
],
|
|
79
|
-
yarn_cpu: 'arm',
|
|
80
|
-
test_image: 'ghcr.io/napi-rs/napi-rs/nodejs:armhf-${{ matrix.node }}',
|
|
81
|
-
},
|
|
82
|
-
'aarch64-linux-android': {
|
|
83
|
-
host: 'ubuntu-latest',
|
|
84
|
-
build_setup: [
|
|
85
|
-
'export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
86
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang"',
|
|
87
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang++"',
|
|
88
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
89
|
-
],
|
|
90
|
-
test: false,
|
|
91
|
-
},
|
|
92
|
-
'armv7-linux-androideabi': {
|
|
93
|
-
host: 'ubuntu-latest',
|
|
94
|
-
build_setup: [
|
|
95
|
-
'export CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
96
|
-
'export CC="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang"',
|
|
97
|
-
'export CXX="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi24-clang++"',
|
|
98
|
-
'export PATH="${ANDROID_NDK_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin:${PATH}"',
|
|
99
|
-
],
|
|
100
|
-
test: false,
|
|
101
|
-
},
|
|
102
|
-
'riscv64gc-unknown-linux-gnu': {
|
|
103
|
-
host: 'ubuntu-latest',
|
|
104
|
-
build_setup: [
|
|
105
|
-
'sudo apt-get update',
|
|
106
|
-
'sudo apt-get install g++-riscv64-linux-gnu gcc-riscv64-linux-gnu -y',
|
|
107
|
-
],
|
|
108
|
-
// No official nodejs docker image for riscv64
|
|
109
|
-
test: false,
|
|
110
|
-
},
|
|
111
|
-
}
|