@napi-rs/cli 3.0.0-alpha.10 → 3.0.0-alpha.100
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/__tests__/create-npm-dirs.spec.d.ts +1 -0
- package/dist/api/__tests__/new.spec.d.ts +1 -0
- package/dist/api/build.d.ts +1 -1
- package/dist/api/create-npm-dirs.d.ts +5 -0
- package/dist/api/templates/index.d.ts +0 -7
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/cli.js +3961 -15
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/build.d.ts +149 -4
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/new.d.ts +25 -7
- package/dist/def/pre-publish.d.ts +21 -2
- package/dist/def/rename.d.ts +16 -6
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/version.d.ts +10 -0
- package/dist/index.cjs +10052 -15662
- package/dist/index.js +3712 -32
- package/dist/utils/__tests__/config.spec.d.ts +1 -0
- package/dist/utils/config.d.ts +56 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/metadata.d.ts +13 -1
- package/dist/utils/misc.d.ts +3 -3
- package/dist/utils/read-config.d.ts +7 -0
- package/dist/utils/target.d.ts +8 -6
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/version.d.ts +2 -1
- package/package.json +38 -34
- package/src/api/__tests__/create-npm-dirs.spec.ts +210 -0
- package/src/api/__tests__/new.spec.ts +429 -0
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +595 -183
- package/src/api/create-npm-dirs.ts +64 -13
- package/src/api/new.ts +389 -122
- package/src/api/pre-publish.ts +19 -11
- package/src/api/rename.ts +103 -17
- package/src/api/templates/index.ts +0 -7
- package/src/api/templates/js-binding.ts +159 -220
- package/src/api/templates/load-wasi-template.ts +216 -0
- 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 +55 -8
- package/src/def/create-npm-dirs.ts +9 -0
- package/src/def/new.ts +28 -3
- package/src/def/pre-publish.ts +24 -3
- package/src/def/rename.ts +11 -2
- package/src/def/universalize.ts +9 -0
- package/src/def/version.ts +9 -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 +49 -0
- package/src/utils/__tests__/__snapshots__/target.spec.ts.snap +0 -0
- package/src/utils/__tests__/__snapshots__/typegen.spec.ts.md +316 -332
- 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/cargo.ts +2 -2
- package/src/utils/config.ts +127 -9
- package/src/utils/index.ts +1 -1
- package/src/utils/log.ts +1 -1
- package/src/utils/metadata.ts +52 -14
- package/src/utils/misc.ts +21 -12
- package/src/utils/read-config.ts +20 -0
- package/src/utils/target.ts +37 -5
- package/src/utils/typegen.ts +87 -52
- package/src/utils/version.ts +10 -8
- package/dist/api/artifacts.js +0 -53
- package/dist/api/artifacts.js.map +0 -1
- package/dist/api/build.js +0 -498
- package/dist/api/build.js.map +0 -1
- package/dist/api/create-npm-dirs.js +0 -64
- package/dist/api/create-npm-dirs.js.map +0 -1
- package/dist/api/load-wasi-template.d.ts +0 -1
- package/dist/api/load-wasi-template.js +0 -60
- package/dist/api/load-wasi-template.js.map +0 -1
- package/dist/api/new.js +0 -155
- package/dist/api/new.js.map +0 -1
- package/dist/api/pre-publish.js +0 -158
- package/dist/api/pre-publish.js.map +0 -1
- package/dist/api/rename.js +0 -29
- package/dist/api/rename.js.map +0 -1
- package/dist/api/templates/.gitignore.d.ts +0 -1
- package/dist/api/templates/.gitignore.js +0 -200
- package/dist/api/templates/.gitignore.js.map +0 -1
- package/dist/api/templates/.npmignore.d.ts +0 -1
- package/dist/api/templates/.npmignore.js +0 -15
- package/dist/api/templates/.npmignore.js.map +0 -1
- package/dist/api/templates/build.rs.d.ts +0 -1
- package/dist/api/templates/build.rs.js +0 -5
- package/dist/api/templates/build.rs.js.map +0 -1
- package/dist/api/templates/cargo.toml.d.ts +0 -6
- package/dist/api/templates/cargo.toml.js +0 -26
- package/dist/api/templates/cargo.toml.js.map +0 -1
- package/dist/api/templates/ci-template.d.ts +0 -1
- package/dist/api/templates/ci-template.js +0 -578
- package/dist/api/templates/ci-template.js.map +0 -1
- package/dist/api/templates/ci.yml.d.ts +0 -1
- package/dist/api/templates/ci.yml.js +0 -99
- package/dist/api/templates/ci.yml.js.map +0 -1
- package/dist/api/templates/index.js +0 -9
- package/dist/api/templates/index.js.map +0 -1
- package/dist/api/templates/js-binding.js +0 -293
- package/dist/api/templates/js-binding.js.map +0 -1
- package/dist/api/templates/lib.rs.d.ts +0 -1
- package/dist/api/templates/lib.rs.js +0 -8
- package/dist/api/templates/lib.rs.js.map +0 -1
- package/dist/api/templates/package.json.d.ts +0 -8
- package/dist/api/templates/package.json.js +0 -32
- package/dist/api/templates/package.json.js.map +0 -1
- package/dist/api/universalize.js +0 -39
- package/dist/api/universalize.js.map +0 -1
- package/dist/api/version.js +0 -17
- package/dist/api/version.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/cli.js.map +0 -1
- package/dist/commands/artifacts.js +0 -20
- package/dist/commands/artifacts.js.map +0 -1
- package/dist/commands/build.js +0 -35
- package/dist/commands/build.js.map +0 -1
- package/dist/commands/create-npm-dirs.js +0 -8
- package/dist/commands/create-npm-dirs.js.map +0 -1
- package/dist/commands/help.js +0 -13
- package/dist/commands/help.js.map +0 -1
- package/dist/commands/new.js +0 -110
- package/dist/commands/new.js.map +0 -1
- package/dist/commands/pre-publish.js +0 -9
- package/dist/commands/pre-publish.js.map +0 -1
- package/dist/commands/rename.js +0 -8
- package/dist/commands/rename.js.map +0 -1
- package/dist/commands/universalize.js +0 -8
- package/dist/commands/universalize.js.map +0 -1
- package/dist/commands/version.js +0 -8
- package/dist/commands/version.js.map +0 -1
- package/dist/def/artifacts.js +0 -39
- package/dist/def/artifacts.js.map +0 -1
- package/dist/def/build.js +0 -118
- package/dist/def/build.js.map +0 -1
- package/dist/def/create-npm-dirs.js +0 -39
- package/dist/def/create-npm-dirs.js.map +0 -1
- package/dist/def/new.js +0 -67
- package/dist/def/new.js.map +0 -1
- package/dist/def/pre-publish.js +0 -57
- package/dist/def/pre-publish.js.map +0 -1
- package/dist/def/rename.js +0 -59
- package/dist/def/rename.js.map +0 -1
- package/dist/def/universalize.js +0 -34
- package/dist/def/universalize.js.map +0 -1
- package/dist/def/version.js +0 -34
- package/dist/def/version.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/utils/__tests__/target.spec.js +0 -11
- package/dist/utils/__tests__/target.spec.js.map +0 -1
- package/dist/utils/__tests__/typegen.spec.js +0 -42
- package/dist/utils/__tests__/typegen.spec.js.map +0 -1
- package/dist/utils/__tests__/version.spec.js +0 -6
- package/dist/utils/__tests__/version.spec.js.map +0 -1
- package/dist/utils/cargo.js +0 -34
- package/dist/utils/cargo.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/dist/utils/config.js +0 -43
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/index.js +0 -10
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/log.js +0 -15
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/metadata.js +0 -20
- package/dist/utils/metadata.js.map +0 -1
- package/dist/utils/misc.js +0 -41
- package/dist/utils/misc.js.map +0 -1
- package/dist/utils/target.js +0 -121
- package/dist/utils/target.js.map +0 -1
- package/dist/utils/typegen.js +0 -179
- package/dist/utils/typegen.js.map +0 -1
- package/dist/utils/version.js +0 -60
- package/dist/utils/version.js.map +0 -1
- package/src/api/load-wasi-template.ts +0 -62
- package/src/api/templates/.gitignore.ts +0 -199
- package/src/api/templates/.npmignore.ts +0 -14
- package/src/api/templates/build.rs.ts +0 -4
- package/src/api/templates/cargo.toml.ts +0 -35
- package/src/api/templates/ci-template.ts +0 -577
- package/src/api/templates/ci.yml.ts +0 -119
- package/src/api/templates/lib.rs.ts +0 -7
- package/src/api/templates/package.json.ts +0 -48
- package/src/api/wasi-worker-template.ts +0 -52
- package/src/utils/ci.ts +0 -111
package/src/api/pre-publish.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { execSync } from 'child_process'
|
|
2
|
-
import { existsSync, statSync } from 'fs'
|
|
3
|
-
import { join,
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import { existsSync, statSync } from 'node:fs'
|
|
3
|
+
import { join, resolve } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import { Octokit } from '@octokit/rest'
|
|
6
6
|
|
|
@@ -31,10 +31,13 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
31
31
|
|
|
32
32
|
const options = applyDefaultPrePublishOptions(userOptions)
|
|
33
33
|
|
|
34
|
-
const packageJsonPath =
|
|
34
|
+
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
35
35
|
|
|
36
36
|
const { packageJson, targets, packageName, binaryName, npmClient } =
|
|
37
|
-
await readNapiConfig(
|
|
37
|
+
await readNapiConfig(
|
|
38
|
+
packageJsonPath,
|
|
39
|
+
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
40
|
+
)
|
|
38
41
|
|
|
39
42
|
async function createGhRelease(packageName: string, version: string) {
|
|
40
43
|
if (!options.ghRelease) {
|
|
@@ -150,7 +153,9 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
150
153
|
options.npmDir,
|
|
151
154
|
`${target.platformArchABI}`,
|
|
152
155
|
)
|
|
153
|
-
const
|
|
156
|
+
const ext =
|
|
157
|
+
target.platform === 'wasi' || target.platform === 'wasm' ? 'wasm' : 'node'
|
|
158
|
+
const filename = `${binaryName}.${target.platformArchABI}.${ext}`
|
|
154
159
|
const dstPath = join(pkgDir, filename)
|
|
155
160
|
|
|
156
161
|
if (!options.dryRun) {
|
|
@@ -159,10 +164,12 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
159
164
|
continue
|
|
160
165
|
}
|
|
161
166
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
if (!options.skipOptionalPublish) {
|
|
168
|
+
execSync(`${npmClient} publish`, {
|
|
169
|
+
cwd: pkgDir,
|
|
170
|
+
env: process.env,
|
|
171
|
+
})
|
|
172
|
+
}
|
|
166
173
|
|
|
167
174
|
if (options.ghRelease && repo && owner) {
|
|
168
175
|
debug.info(`Creating GitHub release ${pkgInfo.tag}`)
|
|
@@ -187,7 +194,8 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
187
194
|
'content-length': dstFileStats.size,
|
|
188
195
|
'content-type': 'application/octet-stream',
|
|
189
196
|
},
|
|
190
|
-
|
|
197
|
+
// @ts-expect-error octokit types are wrong
|
|
198
|
+
data: await readFileAsync(dstPath),
|
|
191
199
|
})
|
|
192
200
|
debug.info(`GitHub release created`)
|
|
193
201
|
debug.info(`Download URL: %s`, assetInfo.data.browser_download_url)
|
package/src/api/rename.ts
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { rename } from 'node:fs/promises'
|
|
3
|
+
import { resolve, join } from 'node:path'
|
|
2
4
|
|
|
5
|
+
import { parse as parseToml, stringify as stringifyToml } from '@std/toml'
|
|
6
|
+
import { load as yamlParse, dump as yamlStringify } from 'js-yaml'
|
|
3
7
|
import { isNil, merge, omitBy, pick } from 'lodash-es'
|
|
8
|
+
import { findUp } from 'find-up'
|
|
4
9
|
|
|
5
10
|
import { applyDefaultRenameOptions, RenameOptions } from '../def/rename.js'
|
|
6
|
-
import { readFileAsync, writeFileAsync } from '../utils/index.js'
|
|
7
|
-
|
|
8
|
-
import { createNpmDirs } from './create-npm-dirs.js'
|
|
11
|
+
import { readConfig, readFileAsync, writeFileAsync } from '../utils/index.js'
|
|
9
12
|
|
|
10
13
|
export async function renameProject(userOptions: RenameOptions) {
|
|
11
14
|
const options = applyDefaultRenameOptions(userOptions)
|
|
15
|
+
const napiConfig = await readConfig(options)
|
|
16
|
+
const oldName = napiConfig.binaryName
|
|
12
17
|
|
|
13
18
|
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
14
19
|
const cargoTomlPath = resolve(options.cwd, options.manifestPath)
|
|
@@ -30,22 +35,103 @@ export async function renameProject(userOptions: RenameOptions) {
|
|
|
30
35
|
},
|
|
31
36
|
)
|
|
32
37
|
|
|
38
|
+
if (options.configPath) {
|
|
39
|
+
const configPath = resolve(options.cwd, options.configPath)
|
|
40
|
+
const configContent = await readFileAsync(configPath, 'utf8')
|
|
41
|
+
const configData = JSON.parse(configContent)
|
|
42
|
+
configData.binaryName = options.binaryName
|
|
43
|
+
configData.packageName = options.packageName
|
|
44
|
+
await writeFileAsync(configPath, JSON.stringify(configData, null, 2))
|
|
45
|
+
}
|
|
46
|
+
|
|
33
47
|
await writeFileAsync(
|
|
34
48
|
packageJsonPath,
|
|
35
49
|
JSON.stringify(packageJsonData, null, 2),
|
|
36
50
|
)
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
52
|
+
const tomlContent = await readFileAsync(cargoTomlPath, 'utf8')
|
|
53
|
+
const cargoToml = parseToml(tomlContent) as any
|
|
54
|
+
|
|
55
|
+
// Update the package name
|
|
56
|
+
if (cargoToml.package && options.binaryName) {
|
|
57
|
+
// Sanitize the binary name for Rust package naming conventions
|
|
58
|
+
const sanitizedName = options.binaryName
|
|
59
|
+
.replace('@', '')
|
|
60
|
+
.replace('/', '_')
|
|
61
|
+
.replace(/-/g, '_')
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
cargoToml.package.name = sanitizedName
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Stringify the updated TOML
|
|
67
|
+
const updatedTomlContent = stringifyToml(cargoToml)
|
|
68
|
+
|
|
69
|
+
await writeFileAsync(cargoTomlPath, updatedTomlContent)
|
|
70
|
+
if (oldName !== options.binaryName) {
|
|
71
|
+
const githubActionsPath = await findUp('.github', {
|
|
72
|
+
cwd: options.cwd,
|
|
73
|
+
type: 'directory',
|
|
74
|
+
})
|
|
75
|
+
if (githubActionsPath) {
|
|
76
|
+
const githubActionsCIYmlPath = join(
|
|
77
|
+
githubActionsPath,
|
|
78
|
+
'workflows',
|
|
79
|
+
'CI.yml',
|
|
80
|
+
)
|
|
81
|
+
if (existsSync(githubActionsCIYmlPath)) {
|
|
82
|
+
const githubActionsContent = await readFileAsync(
|
|
83
|
+
githubActionsCIYmlPath,
|
|
84
|
+
'utf8',
|
|
85
|
+
)
|
|
86
|
+
const githubActionsData = yamlParse(githubActionsContent) as any
|
|
87
|
+
if (githubActionsData.env?.APP_NAME) {
|
|
88
|
+
githubActionsData.env.APP_NAME = options.binaryName
|
|
89
|
+
await writeFileAsync(
|
|
90
|
+
githubActionsCIYmlPath,
|
|
91
|
+
yamlStringify(githubActionsData, {
|
|
92
|
+
lineWidth: -1,
|
|
93
|
+
noRefs: true,
|
|
94
|
+
sortKeys: false,
|
|
95
|
+
}),
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const oldWasiBrowserBindingPath = join(
|
|
101
|
+
options.cwd,
|
|
102
|
+
`${oldName}.wasi-browser.js`,
|
|
103
|
+
)
|
|
104
|
+
if (existsSync(oldWasiBrowserBindingPath)) {
|
|
105
|
+
await rename(
|
|
106
|
+
oldWasiBrowserBindingPath,
|
|
107
|
+
join(options.cwd, `${options.binaryName}.wasi-browser.js`),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
const oldWasiBindingPath = join(options.cwd, `${oldName}.wasi.cjs`)
|
|
111
|
+
if (existsSync(oldWasiBindingPath)) {
|
|
112
|
+
await rename(
|
|
113
|
+
oldWasiBindingPath,
|
|
114
|
+
join(options.cwd, `${options.binaryName}.wasi.cjs`),
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
const gitAttributesPath = join(options.cwd, '.gitattributes')
|
|
118
|
+
if (existsSync(gitAttributesPath)) {
|
|
119
|
+
const gitAttributesContent = await readFileAsync(
|
|
120
|
+
gitAttributesPath,
|
|
121
|
+
'utf8',
|
|
122
|
+
)
|
|
123
|
+
const gitAttributesData = gitAttributesContent
|
|
124
|
+
.split('\n')
|
|
125
|
+
.map((line) => {
|
|
126
|
+
return line
|
|
127
|
+
.replace(
|
|
128
|
+
`${oldName}.wasi-browser.js`,
|
|
129
|
+
`${options.binaryName}.wasi-browser.js`,
|
|
130
|
+
)
|
|
131
|
+
.replace(`${oldName}.wasi.cjs`, `${options.binaryName}.wasi.cjs`)
|
|
132
|
+
})
|
|
133
|
+
.join('\n')
|
|
134
|
+
await writeFileAsync(gitAttributesPath, gitAttributesData)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
51
137
|
}
|
|
@@ -3,18 +3,59 @@ export function createCjsBinding(
|
|
|
3
3
|
pkgName: string,
|
|
4
4
|
idents: string[],
|
|
5
5
|
): string {
|
|
6
|
-
return
|
|
6
|
+
return `${bindingHeader}
|
|
7
|
+
const { createRequire } = require('node:module')
|
|
8
|
+
require = createRequire(__filename)
|
|
9
|
+
|
|
10
|
+
${createCommonBinding(localName, pkgName)}
|
|
11
|
+
module.exports = nativeBinding
|
|
12
|
+
${idents
|
|
13
|
+
.map((ident) => `module.exports.${ident} = nativeBinding.${ident}`)
|
|
14
|
+
.join('\n')}
|
|
15
|
+
`
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function createEsmBinding(
|
|
19
|
+
localName: string,
|
|
20
|
+
pkgName: string,
|
|
21
|
+
idents: string[],
|
|
22
|
+
): string {
|
|
23
|
+
return `${bindingHeader}
|
|
24
|
+
import { createRequire } from 'node:module'
|
|
25
|
+
const require = createRequire(import.meta.url)
|
|
26
|
+
const __dirname = new URL('.', import.meta.url).pathname
|
|
27
|
+
|
|
28
|
+
${createCommonBinding(localName, pkgName)}
|
|
29
|
+
const { ${idents.join(', ')} } = nativeBinding
|
|
30
|
+
${idents.map((ident) => `export { ${ident} }`).join('\n')}
|
|
31
|
+
`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const bindingHeader = `// prettier-ignore
|
|
7
35
|
/* eslint-disable */
|
|
36
|
+
// @ts-nocheck
|
|
8
37
|
/* auto-generated by NAPI-RS */
|
|
38
|
+
`
|
|
9
39
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
40
|
+
function createCommonBinding(localName: string, pkgName: string): string {
|
|
41
|
+
function requireTuple(tuple: string, identSize = 8) {
|
|
42
|
+
const identLow = ' '.repeat(identSize - 2)
|
|
43
|
+
const ident = ' '.repeat(identSize)
|
|
44
|
+
return `try {
|
|
45
|
+
${ident}return require('./${localName}.${tuple}.node')
|
|
46
|
+
${identLow}} catch (e) {
|
|
47
|
+
${ident}loadErrors.push(e)
|
|
48
|
+
${identLow}}
|
|
49
|
+
${identLow}try {
|
|
50
|
+
${ident}return require('${pkgName}-${tuple}')
|
|
51
|
+
${identLow}} catch (e) {
|
|
52
|
+
${ident}loadErrors.push(e)
|
|
53
|
+
${identLow}}`
|
|
54
|
+
}
|
|
14
55
|
|
|
56
|
+
return `const { readFileSync } = require('node:fs')
|
|
15
57
|
let nativeBinding = null
|
|
16
|
-
|
|
17
|
-
let loadError = null
|
|
58
|
+
const loadErrors = []
|
|
18
59
|
|
|
19
60
|
const isMusl = () => {
|
|
20
61
|
let musl = false
|
|
@@ -41,7 +82,11 @@ const isMuslFromFilesystem = () => {
|
|
|
41
82
|
}
|
|
42
83
|
|
|
43
84
|
const isMuslFromReport = () => {
|
|
44
|
-
|
|
85
|
+
let report = null
|
|
86
|
+
if (typeof process.report?.getReport === 'function') {
|
|
87
|
+
process.report.excludeNetwork = true
|
|
88
|
+
report = process.report.getReport()
|
|
89
|
+
}
|
|
45
90
|
if (!report) {
|
|
46
91
|
return null
|
|
47
92
|
}
|
|
@@ -65,232 +110,126 @@ const isMuslFromChildProcess = () => {
|
|
|
65
110
|
}
|
|
66
111
|
}
|
|
67
112
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (localFileExisted) {
|
|
75
|
-
nativeBinding = require('./${localName}.android-arm64.node')
|
|
76
|
-
} else {
|
|
77
|
-
nativeBinding = require('${pkgName}-android-arm64')
|
|
78
|
-
}
|
|
79
|
-
} catch (e) {
|
|
80
|
-
loadError = e
|
|
81
|
-
}
|
|
82
|
-
break
|
|
83
|
-
case 'arm':
|
|
84
|
-
localFileExisted = existsSync(join(__dirname, '${localName}.android-arm-eabi.node'))
|
|
85
|
-
try {
|
|
86
|
-
if (localFileExisted) {
|
|
87
|
-
nativeBinding = require('./${localName}.android-arm-eabi.node')
|
|
88
|
-
} else {
|
|
89
|
-
nativeBinding = require('${pkgName}-android-arm-eabi')
|
|
90
|
-
}
|
|
91
|
-
} catch (e) {
|
|
92
|
-
loadError = e
|
|
93
|
-
}
|
|
94
|
-
break
|
|
95
|
-
default:
|
|
96
|
-
throw new Error(\`Unsupported architecture on Android \${arch}\`)
|
|
113
|
+
function requireNative() {
|
|
114
|
+
if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
|
|
115
|
+
try {
|
|
116
|
+
nativeBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
loadErrors.push(err)
|
|
97
119
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
try {
|
|
106
|
-
if (localFileExisted) {
|
|
107
|
-
nativeBinding = require('./${localName}.win32-x64-msvc.node')
|
|
108
|
-
} else {
|
|
109
|
-
nativeBinding = require('${pkgName}-win32-x64-msvc')
|
|
110
|
-
}
|
|
111
|
-
} catch (e) {
|
|
112
|
-
loadError = e
|
|
113
|
-
}
|
|
114
|
-
break
|
|
115
|
-
case 'ia32':
|
|
116
|
-
localFileExisted = existsSync(
|
|
117
|
-
join(__dirname, '${localName}.win32-ia32-msvc.node')
|
|
118
|
-
)
|
|
119
|
-
try {
|
|
120
|
-
if (localFileExisted) {
|
|
121
|
-
nativeBinding = require('./${localName}.win32-ia32-msvc.node')
|
|
122
|
-
} else {
|
|
123
|
-
nativeBinding = require('${pkgName}-win32-ia32-msvc')
|
|
124
|
-
}
|
|
125
|
-
} catch (e) {
|
|
126
|
-
loadError = e
|
|
127
|
-
}
|
|
128
|
-
break
|
|
129
|
-
case 'arm64':
|
|
130
|
-
localFileExisted = existsSync(
|
|
131
|
-
join(__dirname, '${localName}.win32-arm64-msvc.node')
|
|
132
|
-
)
|
|
133
|
-
try {
|
|
134
|
-
if (localFileExisted) {
|
|
135
|
-
nativeBinding = require('./${localName}.win32-arm64-msvc.node')
|
|
136
|
-
} else {
|
|
137
|
-
nativeBinding = require('${pkgName}-win32-arm64-msvc')
|
|
138
|
-
}
|
|
139
|
-
} catch (e) {
|
|
140
|
-
loadError = e
|
|
141
|
-
}
|
|
142
|
-
break
|
|
143
|
-
default:
|
|
144
|
-
throw new Error(\`Unsupported architecture on Windows: \${arch}\`)
|
|
120
|
+
} else if (process.platform === 'android') {
|
|
121
|
+
if (process.arch === 'arm64') {
|
|
122
|
+
${requireTuple('android-arm64')}
|
|
123
|
+
} else if (process.arch === 'arm') {
|
|
124
|
+
${requireTuple('android-arm-eabi')}
|
|
125
|
+
} else {
|
|
126
|
+
loadErrors.push(new Error(\`Unsupported architecture on Android \${process.arch}\`))
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
128
|
+
} else if (process.platform === 'win32') {
|
|
129
|
+
if (process.arch === 'x64') {
|
|
130
|
+
${requireTuple('win32-x64-msvc')}
|
|
131
|
+
} else if (process.arch === 'ia32') {
|
|
132
|
+
${requireTuple('win32-ia32-msvc')}
|
|
133
|
+
} else if (process.arch === 'arm64') {
|
|
134
|
+
${requireTuple('win32-arm64-msvc')}
|
|
135
|
+
} else {
|
|
136
|
+
loadErrors.push(new Error(\`Unsupported architecture on Windows: \${process.arch}\`))
|
|
137
|
+
}
|
|
138
|
+
} else if (process.platform === 'darwin') {
|
|
139
|
+
${requireTuple('darwin-universal', 6)}
|
|
140
|
+
if (process.arch === 'x64') {
|
|
141
|
+
${requireTuple('darwin-x64')}
|
|
142
|
+
} else if (process.arch === 'arm64') {
|
|
143
|
+
${requireTuple('darwin-arm64')}
|
|
144
|
+
} else {
|
|
145
|
+
loadErrors.push(new Error(\`Unsupported architecture on macOS: \${process.arch}\`))
|
|
146
|
+
}
|
|
147
|
+
} else if (process.platform === 'freebsd') {
|
|
148
|
+
if (process.arch === 'x64') {
|
|
149
|
+
${requireTuple('freebsd-x64')}
|
|
150
|
+
} else if (process.arch === 'arm64') {
|
|
151
|
+
${requireTuple('freebsd-arm64')}
|
|
152
|
+
} else {
|
|
153
|
+
loadErrors.push(new Error(\`Unsupported architecture on FreeBSD: \${process.arch}\`))
|
|
154
|
+
}
|
|
155
|
+
} else if (process.platform === 'linux') {
|
|
156
|
+
if (process.arch === 'x64') {
|
|
157
|
+
if (isMusl()) {
|
|
158
|
+
${requireTuple('linux-x64-musl', 10)}
|
|
159
|
+
} else {
|
|
160
|
+
${requireTuple('linux-x64-gnu', 10)}
|
|
161
|
+
}
|
|
162
|
+
} else if (process.arch === 'arm64') {
|
|
163
|
+
if (isMusl()) {
|
|
164
|
+
${requireTuple('linux-arm64-musl', 10)}
|
|
165
|
+
} else {
|
|
166
|
+
${requireTuple('linux-arm64-gnu', 10)}
|
|
167
|
+
}
|
|
168
|
+
} else if (process.arch === 'arm') {
|
|
169
|
+
if (isMusl()) {
|
|
170
|
+
${requireTuple('linux-arm-musleabihf', 10)}
|
|
152
171
|
} else {
|
|
153
|
-
|
|
172
|
+
${requireTuple('linux-arm-gnueabihf', 10)}
|
|
154
173
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
} else {
|
|
178
|
-
nativeBinding = require('${pkgName}-darwin-arm64')
|
|
179
|
-
}
|
|
180
|
-
} catch (e) {
|
|
181
|
-
loadError = e
|
|
182
|
-
}
|
|
183
|
-
break
|
|
184
|
-
default:
|
|
185
|
-
throw new Error(\`Unsupported architecture on macOS: \${arch}\`)
|
|
174
|
+
} else if (process.arch === 'riscv64') {
|
|
175
|
+
if (isMusl()) {
|
|
176
|
+
${requireTuple('linux-riscv64-musl', 10)}
|
|
177
|
+
} else {
|
|
178
|
+
${requireTuple('linux-riscv64-gnu', 10)}
|
|
179
|
+
}
|
|
180
|
+
} else if (process.arch === 'ppc64') {
|
|
181
|
+
${requireTuple('linux-ppc64-gnu')}
|
|
182
|
+
} else if (process.arch === 's390x') {
|
|
183
|
+
${requireTuple('linux-s390x-gnu')}
|
|
184
|
+
} else {
|
|
185
|
+
loadErrors.push(new Error(\`Unsupported architecture on Linux: \${process.arch}\`))
|
|
186
|
+
}
|
|
187
|
+
} else if (process.platform === 'openharmony') {
|
|
188
|
+
if (process.arch === 'arm64') {
|
|
189
|
+
${requireTuple('linux-arm64-ohos')}
|
|
190
|
+
} else if (process.arch === 'x64') {
|
|
191
|
+
${requireTuple('linux-x64-ohos')}
|
|
192
|
+
} else if (process.arch === 'arm') {
|
|
193
|
+
${requireTuple('linux-arm-ohos')}
|
|
194
|
+
} else {
|
|
195
|
+
loadErrors.push(new Error(\`Unsupported architecture on OpenHarmony: \${process.arch}\`))
|
|
186
196
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
197
|
+
} else {
|
|
198
|
+
loadErrors.push(new Error(\`Unsupported OS: \${process.platform}, architecture: \${process.arch}\`))
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
nativeBinding = requireNative()
|
|
203
|
+
|
|
204
|
+
if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
|
|
205
|
+
try {
|
|
206
|
+
nativeBinding = require('./${localName}.wasi.cjs')
|
|
207
|
+
} catch (err) {
|
|
208
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
209
|
+
loadErrors.push(err)
|
|
191
210
|
}
|
|
192
|
-
|
|
211
|
+
}
|
|
212
|
+
if (!nativeBinding) {
|
|
193
213
|
try {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
214
|
+
nativeBinding = require('${pkgName}-wasm32-wasi')
|
|
215
|
+
} catch (err) {
|
|
216
|
+
if (process.env.NAPI_RS_FORCE_WASI) {
|
|
217
|
+
loadErrors.push(err)
|
|
198
218
|
}
|
|
199
|
-
} catch (e) {
|
|
200
|
-
loadError = e
|
|
201
|
-
}
|
|
202
|
-
break
|
|
203
|
-
case 'linux':
|
|
204
|
-
switch (arch) {
|
|
205
|
-
case 'x64':
|
|
206
|
-
if (isMusl()) {
|
|
207
|
-
localFileExisted = existsSync(
|
|
208
|
-
join(__dirname, '${localName}.linux-x64-musl.node')
|
|
209
|
-
)
|
|
210
|
-
try {
|
|
211
|
-
if (localFileExisted) {
|
|
212
|
-
nativeBinding = require('./${localName}.linux-x64-musl.node')
|
|
213
|
-
} else {
|
|
214
|
-
nativeBinding = require('${pkgName}-linux-x64-musl')
|
|
215
|
-
}
|
|
216
|
-
} catch (e) {
|
|
217
|
-
loadError = e
|
|
218
|
-
}
|
|
219
|
-
} else {
|
|
220
|
-
localFileExisted = existsSync(
|
|
221
|
-
join(__dirname, '${localName}.linux-x64-gnu.node')
|
|
222
|
-
)
|
|
223
|
-
try {
|
|
224
|
-
if (localFileExisted) {
|
|
225
|
-
nativeBinding = require('./${localName}.linux-x64-gnu.node')
|
|
226
|
-
} else {
|
|
227
|
-
nativeBinding = require('${pkgName}-linux-x64-gnu')
|
|
228
|
-
}
|
|
229
|
-
} catch (e) {
|
|
230
|
-
loadError = e
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
break
|
|
234
|
-
case 'arm64':
|
|
235
|
-
if (isMusl()) {
|
|
236
|
-
localFileExisted = existsSync(
|
|
237
|
-
join(__dirname, '${localName}.linux-arm64-musl.node')
|
|
238
|
-
)
|
|
239
|
-
try {
|
|
240
|
-
if (localFileExisted) {
|
|
241
|
-
nativeBinding = require('./${localName}.linux-arm64-musl.node')
|
|
242
|
-
} else {
|
|
243
|
-
nativeBinding = require('${pkgName}-linux-arm64-musl')
|
|
244
|
-
}
|
|
245
|
-
} catch (e) {
|
|
246
|
-
loadError = e
|
|
247
|
-
}
|
|
248
|
-
} else {
|
|
249
|
-
localFileExisted = existsSync(
|
|
250
|
-
join(__dirname, '${localName}.linux-arm64-gnu.node')
|
|
251
|
-
)
|
|
252
|
-
try {
|
|
253
|
-
if (localFileExisted) {
|
|
254
|
-
nativeBinding = require('./${localName}.linux-arm64-gnu.node')
|
|
255
|
-
} else {
|
|
256
|
-
nativeBinding = require('${pkgName}-linux-arm64-gnu')
|
|
257
|
-
}
|
|
258
|
-
} catch (e) {
|
|
259
|
-
loadError = e
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
break
|
|
263
|
-
case 'arm':
|
|
264
|
-
localFileExisted = existsSync(
|
|
265
|
-
join(__dirname, '${localName}.linux-arm-gnueabihf.node')
|
|
266
|
-
)
|
|
267
|
-
try {
|
|
268
|
-
if (localFileExisted) {
|
|
269
|
-
nativeBinding = require('./${localName}.linux-arm-gnueabihf.node')
|
|
270
|
-
} else {
|
|
271
|
-
nativeBinding = require('${pkgName}-linux-arm-gnueabihf')
|
|
272
|
-
}
|
|
273
|
-
} catch (e) {
|
|
274
|
-
loadError = e
|
|
275
|
-
}
|
|
276
|
-
break
|
|
277
|
-
default:
|
|
278
|
-
throw new Error(\`Unsupported architecture on Linux: \${arch}\`)
|
|
279
219
|
}
|
|
280
|
-
|
|
281
|
-
default:
|
|
282
|
-
throw new Error(\`Unsupported OS: \${platform}, architecture: \${arch}\`)
|
|
220
|
+
}
|
|
283
221
|
}
|
|
284
222
|
|
|
285
223
|
if (!nativeBinding) {
|
|
286
|
-
if (
|
|
287
|
-
throw
|
|
224
|
+
if (loadErrors.length > 0) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
\`Cannot find native binding. \` +
|
|
227
|
+
\`npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). \` +
|
|
228
|
+
'Please try \`npm i\` again after removing both package-lock.json and node_modules directory.',
|
|
229
|
+
{ cause: loadErrors }
|
|
230
|
+
)
|
|
288
231
|
}
|
|
289
232
|
throw new Error(\`Failed to load native binding\`)
|
|
290
233
|
}
|
|
291
|
-
|
|
292
|
-
${idents
|
|
293
|
-
.map((ident) => `module.exports.${ident} = nativeBinding.${ident}`)
|
|
294
|
-
.join('\n')}
|
|
295
234
|
`
|
|
296
235
|
}
|