@napi-rs/cli 3.0.0-alpha.56 → 3.0.0-alpha.57
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/build.js +13 -6
- package/dist/api/build.js.map +1 -1
- package/dist/index.cjs +2702 -16852
- package/package.json +2 -2
- package/src/api/build.ts +36 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/cli",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.57",
|
|
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",
|
|
@@ -129,5 +129,5 @@
|
|
|
129
129
|
"**/__tests__/**/*.spec.ts"
|
|
130
130
|
]
|
|
131
131
|
},
|
|
132
|
-
"gitHead": "
|
|
132
|
+
"gitHead": "488762791dc31a3a9b156fb214ab3a6af9b4aa6a"
|
|
133
133
|
}
|
package/src/api/build.ts
CHANGED
|
@@ -671,40 +671,41 @@ class Builder {
|
|
|
671
671
|
})
|
|
672
672
|
}
|
|
673
673
|
|
|
674
|
-
const
|
|
674
|
+
const wasmBinaryName = await this.copyArtifact()
|
|
675
675
|
|
|
676
676
|
// only for cdylib
|
|
677
677
|
if (this.cdyLibName) {
|
|
678
678
|
const idents = await this.generateTypeDef()
|
|
679
679
|
const intermediateWasiRegisterFile = this.envs.WASI_REGISTER_TMP_PATH
|
|
680
|
-
const wasiRegisterFunctions =
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
)
|
|
692
|
-
|
|
680
|
+
const wasiRegisterFunctions = this.config.targets.some(
|
|
681
|
+
(t) => t.platform === 'wasi',
|
|
682
|
+
)
|
|
683
|
+
? await (async function readIntermediateWasiRegisterFile() {
|
|
684
|
+
const fileContent = await readFileAsync(
|
|
685
|
+
intermediateWasiRegisterFile,
|
|
686
|
+
'utf8',
|
|
687
|
+
).catch((err) => {
|
|
688
|
+
console.warn(
|
|
689
|
+
`Read ${colors.yellowBright(
|
|
690
|
+
intermediateWasiRegisterFile,
|
|
691
|
+
)} failed, reason: ${err.message}`,
|
|
692
|
+
)
|
|
693
|
+
return ``
|
|
694
|
+
})
|
|
695
|
+
return fileContent
|
|
696
|
+
.split('\n')
|
|
697
|
+
.map((l) => l.trim())
|
|
698
|
+
.filter((l) => l.length)
|
|
699
|
+
.map((line) => {
|
|
700
|
+
const [_, fn] = line.split(':')
|
|
701
|
+
return fn.trim()
|
|
693
702
|
})
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
.map((l) => l.trim())
|
|
697
|
-
.filter((l) => l.length)
|
|
698
|
-
.map((line) => {
|
|
699
|
-
const [_, fn] = line.split(':')
|
|
700
|
-
return fn.trim()
|
|
701
|
-
})
|
|
702
|
-
})()
|
|
703
|
-
: []
|
|
703
|
+
})()
|
|
704
|
+
: []
|
|
704
705
|
const jsOutput = await this.writeJsBinding(idents)
|
|
705
706
|
const wasmBindingsOutput = await this.writeWasiBinding(
|
|
706
707
|
wasiRegisterFunctions,
|
|
707
|
-
|
|
708
|
+
wasmBinaryName ?? 'index.wasm',
|
|
708
709
|
idents,
|
|
709
710
|
)
|
|
710
711
|
if (jsOutput) {
|
|
@@ -719,7 +720,7 @@ class Builder {
|
|
|
719
720
|
}
|
|
720
721
|
|
|
721
722
|
private async copyArtifact() {
|
|
722
|
-
const [srcName, destName] = this.getArtifactNames()
|
|
723
|
+
const [srcName, destName, wasmBinaryName] = this.getArtifactNames()
|
|
723
724
|
if (!srcName || !destName) {
|
|
724
725
|
return
|
|
725
726
|
}
|
|
@@ -778,7 +779,7 @@ class Builder {
|
|
|
778
779
|
kind: dest.endsWith('.node') ? 'node' : isWasm ? 'wasm' : 'exe',
|
|
779
780
|
path: dest,
|
|
780
781
|
})
|
|
781
|
-
return
|
|
782
|
+
return wasmBinaryName
|
|
782
783
|
} catch (e) {
|
|
783
784
|
throw new Error('Failed to copy artifact', {
|
|
784
785
|
cause: e,
|
|
@@ -789,6 +790,7 @@ class Builder {
|
|
|
789
790
|
private getArtifactNames() {
|
|
790
791
|
if (this.cdyLibName) {
|
|
791
792
|
const cdyLib = this.cdyLibName.replace(/-/g, '_')
|
|
793
|
+
const wasiTarget = this.config.targets.find((t) => t.platform === 'wasi')
|
|
792
794
|
|
|
793
795
|
const srcName =
|
|
794
796
|
this.target.platform === 'darwin'
|
|
@@ -812,7 +814,13 @@ class Builder {
|
|
|
812
814
|
destName += '.node'
|
|
813
815
|
}
|
|
814
816
|
|
|
815
|
-
return [
|
|
817
|
+
return [
|
|
818
|
+
srcName,
|
|
819
|
+
destName,
|
|
820
|
+
wasiTarget
|
|
821
|
+
? `${this.config.binaryName}.${wasiTarget.platformArchABI}.wasm`
|
|
822
|
+
: null,
|
|
823
|
+
]
|
|
816
824
|
} else if (this.binName) {
|
|
817
825
|
const srcName =
|
|
818
826
|
this.target.platform === 'win32' ? `${this.binName}.exe` : this.binName
|