@napi-rs/cli 3.0.0-alpha.9 → 3.0.0-alpha.91
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__/new.spec.d.ts +1 -0
- package/dist/api/build.d.ts +1 -1
- package/dist/api/templates/ci-template.d.ts +3 -1
- package/dist/api/templates/ci.yml.d.ts +3 -1
- 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/package.json.d.ts +9 -2
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/cli.js +3867 -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 +12 -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 +9946 -15669
- package/dist/index.js +3618 -32
- package/dist/utils/__tests__/config.spec.d.ts +1 -0
- package/dist/utils/config.d.ts +48 -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 +7 -5
- 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__/new.spec.ts +429 -0
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +498 -149
- package/src/api/create-npm-dirs.ts +57 -9
- package/src/api/new.ts +389 -122
- package/src/api/pre-publish.ts +13 -7
- package/src/api/rename.ts +103 -17
- 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 +148 -220
- 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 +55 -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/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 +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 +110 -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 +22 -4
- 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 -64
- 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.js +0 -200
- package/dist/api/templates/.gitignore.js.map +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.js +0 -5
- package/dist/api/templates/build.rs.js.map +0 -1
- 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.js +0 -578
- package/dist/api/templates/ci-template.js.map +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.js +0 -8
- package/dist/api/templates/lib.rs.js.map +0 -1
- 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 -66
- 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) {
|
|
@@ -187,7 +192,8 @@ export async function prePublish(userOptions: PrePublishOptions) {
|
|
|
187
192
|
'content-length': dstFileStats.size,
|
|
188
193
|
'content-type': 'application/octet-stream',
|
|
189
194
|
},
|
|
190
|
-
|
|
195
|
+
// @ts-expect-error octokit types are wrong
|
|
196
|
+
data: await readFileAsync(dstPath),
|
|
191
197
|
})
|
|
192
198
|
debug.info(`GitHub release created`)
|
|
193
199
|
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
|
}
|