@napi-rs/cli 3.7.4 → 3.8.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/README.md +33 -0
- package/cli.mjs +9 -12
- package/dist/cli.js +9248 -1311
- package/dist/index.cjs +9268 -1331
- package/dist/index.d.cts +175 -157
- package/dist/index.d.ts +175 -157
- package/dist/index.js +9248 -1311
- package/docs/artifacts.md +33 -0
- package/docs/build.md +58 -0
- package/docs/create-npm-dirs.md +32 -0
- package/docs/new.md +39 -0
- package/docs/pre-publish.md +37 -0
- package/docs/rename.md +37 -0
- package/docs/universalize.md +31 -0
- package/docs/version.md +31 -0
- package/docs/wasi.md +161 -0
- package/package.json +11 -10
- package/src/api/__tests__/__snapshots__/templates.spec.ts.md +1019 -114
- package/src/api/__tests__/__snapshots__/templates.spec.ts.snap +0 -0
- package/src/api/__tests__/artifacts.spec.ts +17 -0
- package/src/api/__tests__/create-npm-dirs.spec.ts +14 -15
- package/src/api/__tests__/new.spec.ts +41 -5
- package/src/api/artifacts.ts +934 -108
- package/src/api/build.ts +1317 -188
- package/src/api/create-npm-dirs.ts +472 -101
- package/src/api/new.ts +354 -35
- package/src/api/pre-publish.ts +2845 -99
- package/src/api/rename.ts +1638 -124
- package/src/api/templates/js-binding.ts +216 -38
- package/src/api/templates/load-wasi-template.ts +1641 -111
- package/src/api/templates/wasi-worker-template.ts +32 -3
- package/src/commands/rename.ts +8 -3
- package/src/def/artifacts.ts +2 -2
- package/src/utils/__tests__/__snapshots__/target.spec.ts.md +2 -2
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/misc.spec.ts +124 -3
- package/src/utils/__tests__/version.spec.ts +47 -1
- package/src/utils/config.ts +15 -2
- package/src/utils/metadata.ts +155 -47
- package/src/utils/misc.ts +6079 -0
- package/src/utils/target.ts +66 -8
- package/src/utils/typegen.ts +1223 -63
- package/src/utils/version.ts +96 -0
package/src/utils/target.ts
CHANGED
|
@@ -31,7 +31,7 @@ export const AVAILABLE_TARGETS = [
|
|
|
31
31
|
'riscv64gc-unknown-linux-gnu',
|
|
32
32
|
'powerpc64le-unknown-linux-gnu',
|
|
33
33
|
's390x-unknown-linux-gnu',
|
|
34
|
-
'wasm32-
|
|
34
|
+
'wasm32-wasip1',
|
|
35
35
|
'wasm32-wasip1-threads',
|
|
36
36
|
] as const
|
|
37
37
|
|
|
@@ -111,6 +111,51 @@ export interface Target {
|
|
|
111
111
|
abi: string | null
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
export type WasiFlavor = 'single' | 'threads'
|
|
115
|
+
|
|
116
|
+
export interface WasiTarget {
|
|
117
|
+
canonicalTriple: string
|
|
118
|
+
flavor: WasiFlavor
|
|
119
|
+
platformArchABI: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Resolve historical WASI spellings to one build target and one artifact
|
|
124
|
+
* identity. `wasm32-wasi` historically produced the threaded package, so it
|
|
125
|
+
* must never be inferred as threadless merely because its name lacks the
|
|
126
|
+
* `-threads` suffix.
|
|
127
|
+
*/
|
|
128
|
+
export function getWasiTarget(
|
|
129
|
+
target: string | Pick<Target, 'triple'>,
|
|
130
|
+
): WasiTarget | undefined {
|
|
131
|
+
const triple = typeof target === 'string' ? target : target.triple
|
|
132
|
+
|
|
133
|
+
switch (triple) {
|
|
134
|
+
case 'wasm32-wasi':
|
|
135
|
+
case 'wasm32-wasi-preview1-threads':
|
|
136
|
+
case 'wasm32-wasip1-threads':
|
|
137
|
+
return {
|
|
138
|
+
canonicalTriple: 'wasm32-wasip1-threads',
|
|
139
|
+
flavor: 'threads',
|
|
140
|
+
platformArchABI: 'wasm32-wasi',
|
|
141
|
+
}
|
|
142
|
+
case 'wasm32-wasip1':
|
|
143
|
+
return {
|
|
144
|
+
canonicalTriple: 'wasm32-wasip1',
|
|
145
|
+
flavor: 'single',
|
|
146
|
+
platformArchABI: 'wasm32-wasip1',
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function wasiTargetHasThreads(
|
|
154
|
+
target: string | Pick<Target, 'triple'>,
|
|
155
|
+
): boolean {
|
|
156
|
+
return getWasiTarget(target)?.flavor === 'threads'
|
|
157
|
+
}
|
|
158
|
+
|
|
114
159
|
/**
|
|
115
160
|
* A triple is a specific format for specifying a target architecture.
|
|
116
161
|
* Triples may be referred to as a target triple which is the architecture for the artifact produced, and the host triple which is the architecture that the compiler is running on.
|
|
@@ -122,19 +167,21 @@ export interface Target {
|
|
|
122
167
|
* - `abi` = The ABI, for example `gnu`, `android`, `eabi`, etc.
|
|
123
168
|
*/
|
|
124
169
|
export function parseTriple(rawTriple: string): Target {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
rawTriple === 'wasm32-wasi-preview1-threads' ||
|
|
128
|
-
rawTriple.startsWith('wasm32-wasip')
|
|
129
|
-
) {
|
|
170
|
+
const wasiTarget = getWasiTarget(rawTriple)
|
|
171
|
+
if (wasiTarget) {
|
|
130
172
|
return {
|
|
131
|
-
triple:
|
|
132
|
-
platformArchABI:
|
|
173
|
+
triple: wasiTarget.canonicalTriple,
|
|
174
|
+
platformArchABI: wasiTarget.platformArchABI,
|
|
133
175
|
platform: 'wasi',
|
|
134
176
|
arch: 'wasm32',
|
|
135
177
|
abi: 'wasi',
|
|
136
178
|
}
|
|
137
179
|
}
|
|
180
|
+
if (/^wasm32-(?:wasip|wasi(?:-|$))/.test(rawTriple)) {
|
|
181
|
+
throw new TypeError(
|
|
182
|
+
`Unsupported WASI target ${rawTriple}. Supported targets are wasm32-wasip1, wasm32-wasip1-threads, wasm32-wasi, and wasm32-wasi-preview1-threads.`,
|
|
183
|
+
)
|
|
184
|
+
}
|
|
138
185
|
const triple = rawTriple.endsWith('eabi')
|
|
139
186
|
? `${rawTriple.slice(0, -4)}-eabi`
|
|
140
187
|
: rawTriple
|
|
@@ -188,6 +235,17 @@ export function getTargetLinker(target: string): string | undefined {
|
|
|
188
235
|
return TARGET_LINKER[target]
|
|
189
236
|
}
|
|
190
237
|
|
|
238
|
+
/**
|
|
239
|
+
* Loader-file suffix for a WASI flavor, derived from its `platformArchABI`:
|
|
240
|
+
* the legacy threaded flavor keeps the historical `wasi` stem
|
|
241
|
+
* (`<binaryName>.wasi.cjs`, `<binaryName>.wasi-browser.js`), while each
|
|
242
|
+
* distinctly named non-threaded flavor derives its own
|
|
243
|
+
* (`<binaryName>.wasip1.cjs`, `<binaryName>.wasip1-browser.js`, ...).
|
|
244
|
+
*/
|
|
245
|
+
export function wasiLoaderSuffix(platformArchABI: string): string {
|
|
246
|
+
return platformArchABI.replace(/^wasm32-/, '')
|
|
247
|
+
}
|
|
248
|
+
|
|
191
249
|
export function targetToEnvVar(target: string): string {
|
|
192
250
|
return target.replace(/-/g, '_').toUpperCase()
|
|
193
251
|
}
|