@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/api/new.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { execSync } from 'node:child_process'
|
|
2
|
+
import path from 'node:path'
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
applyDefaultNewOptions,
|
|
@@ -10,7 +11,11 @@ import {
|
|
|
10
11
|
debugFactory,
|
|
11
12
|
DEFAULT_TARGETS,
|
|
12
13
|
mkdirAsync,
|
|
14
|
+
readdirAsync,
|
|
15
|
+
statAsync,
|
|
16
|
+
type SupportedTestFramework,
|
|
13
17
|
writeFileAsync,
|
|
18
|
+
SupportedPackageManager,
|
|
14
19
|
} from '../utils/index.js'
|
|
15
20
|
import { napiEngineRequirement } from '../utils/version.js'
|
|
16
21
|
|
|
@@ -23,6 +28,7 @@ import {
|
|
|
23
28
|
gitIgnore,
|
|
24
29
|
npmIgnore,
|
|
25
30
|
} from './templates/index.js'
|
|
31
|
+
import { WasiTargetName } from './templates/ci-template.js'
|
|
26
32
|
|
|
27
33
|
const debug = debugFactory('new')
|
|
28
34
|
|
|
@@ -35,6 +41,9 @@ type NewOptions = Required<RawNewOptions>
|
|
|
35
41
|
|
|
36
42
|
function processOptions(options: RawNewOptions) {
|
|
37
43
|
debug('Processing options...')
|
|
44
|
+
if (!options.path) {
|
|
45
|
+
throw new Error('Please provide the path as the argument')
|
|
46
|
+
}
|
|
38
47
|
options.path = path.resolve(process.cwd(), options.path)
|
|
39
48
|
debug(`Resolved target path to: ${options.path}`)
|
|
40
49
|
|
|
@@ -54,6 +63,20 @@ function processOptions(options: RawNewOptions) {
|
|
|
54
63
|
throw new Error('At least one target must be enabled')
|
|
55
64
|
}
|
|
56
65
|
}
|
|
66
|
+
if (
|
|
67
|
+
options.targets.some((target) => target === 'wasm32-wasi-preview1-threads')
|
|
68
|
+
) {
|
|
69
|
+
const out = execSync(`rustup target list`, {
|
|
70
|
+
encoding: 'utf8',
|
|
71
|
+
})
|
|
72
|
+
if (out.includes('wasm32-wasip1-threads')) {
|
|
73
|
+
options.targets.map((target) =>
|
|
74
|
+
target === 'wasm32-wasi-preview1-threads'
|
|
75
|
+
? 'wasm32-wasip1-threads'
|
|
76
|
+
: target,
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
57
80
|
|
|
58
81
|
return applyDefaultNewOptions(options) as NewOptions
|
|
59
82
|
}
|
|
@@ -67,47 +90,75 @@ export async function newProject(userOptions: RawNewOptions) {
|
|
|
67
90
|
debug('Targets to be enabled:')
|
|
68
91
|
debug(options.targets)
|
|
69
92
|
|
|
70
|
-
const outputs = generateFiles(options)
|
|
93
|
+
const outputs = await generateFiles(options)
|
|
71
94
|
|
|
72
|
-
|
|
73
|
-
debug(`Try to create target directory: ${options.path}`)
|
|
74
|
-
if (!options.dryRun) {
|
|
75
|
-
await mkdirAsync(options.path, { recursive: true })
|
|
76
|
-
}
|
|
77
|
-
} catch (e) {
|
|
78
|
-
throw new Error(`Failed to create target directory: ${options.path}`, {
|
|
79
|
-
cause: e,
|
|
80
|
-
})
|
|
81
|
-
}
|
|
95
|
+
await ensurePath(options.path, options.dryRun)
|
|
82
96
|
|
|
83
97
|
await dumpOutputs(outputs, options.dryRun)
|
|
84
98
|
debug(`Project created at: ${options.path}`)
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
function
|
|
101
|
+
async function ensurePath(path: string, dryRun = false) {
|
|
102
|
+
const stat = await statAsync(path, {}).catch(() => undefined)
|
|
103
|
+
|
|
104
|
+
// file descriptor exists
|
|
105
|
+
if (stat) {
|
|
106
|
+
if (stat.isFile()) {
|
|
107
|
+
throw new Error(
|
|
108
|
+
`Path ${path} for creating new napi-rs project already exists and it's not a directory.`,
|
|
109
|
+
)
|
|
110
|
+
} else if (stat.isDirectory()) {
|
|
111
|
+
const files = await readdirAsync(path)
|
|
112
|
+
if (files.length) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`Path ${path} for creating new napi-rs project already exists and it's not empty.`,
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!dryRun) {
|
|
121
|
+
try {
|
|
122
|
+
debug(`Try to create target directory: ${path}`)
|
|
123
|
+
if (!dryRun) {
|
|
124
|
+
await mkdirAsync(path, { recursive: true })
|
|
125
|
+
}
|
|
126
|
+
} catch (e) {
|
|
127
|
+
throw new Error(`Failed to create target directory: ${path}`, {
|
|
128
|
+
cause: e,
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function generateFiles(options: NewOptions): Promise<Output[]> {
|
|
135
|
+
const packageJson = await generatePackageJson(options)
|
|
88
136
|
return [
|
|
89
137
|
generateCargoToml,
|
|
90
138
|
generateLibRs,
|
|
91
139
|
generateBuildRs,
|
|
92
|
-
generatePackageJson,
|
|
93
140
|
generateGithubWorkflow,
|
|
94
141
|
generateIgnoreFiles,
|
|
95
|
-
]
|
|
96
|
-
|
|
142
|
+
]
|
|
143
|
+
.flatMap((generator) => {
|
|
144
|
+
const output = generator(options)
|
|
97
145
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
146
|
+
if (!output) {
|
|
147
|
+
return []
|
|
148
|
+
}
|
|
101
149
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
150
|
+
if (Array.isArray(output)) {
|
|
151
|
+
return output.map((o) => ({
|
|
152
|
+
...o,
|
|
153
|
+
target: path.join(options.path, o.target),
|
|
154
|
+
}))
|
|
155
|
+
} else {
|
|
156
|
+
return [{ ...output, target: path.join(options.path, output.target) }]
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
.concat([
|
|
160
|
+
{ ...packageJson, target: path.join(options.path, packageJson.target) },
|
|
161
|
+
])
|
|
111
162
|
}
|
|
112
163
|
|
|
113
164
|
function generateCargoToml(options: NewOptions): Output {
|
|
@@ -136,16 +187,17 @@ function generateBuildRs(_options: NewOptions): Output {
|
|
|
136
187
|
}
|
|
137
188
|
}
|
|
138
189
|
|
|
139
|
-
function generatePackageJson(options: NewOptions): Output {
|
|
190
|
+
async function generatePackageJson(options: NewOptions): Promise<Output> {
|
|
140
191
|
return {
|
|
141
192
|
target: './package.json',
|
|
142
|
-
content: createPackageJson({
|
|
193
|
+
content: await createPackageJson({
|
|
143
194
|
name: options.name,
|
|
144
195
|
binaryName: getBinaryName(options.name),
|
|
145
196
|
targets: options.targets,
|
|
146
197
|
license: options.license,
|
|
147
198
|
engineRequirement: napiEngineRequirement(options.minNodeApiVersion),
|
|
148
199
|
cliVersion: CLI_VERSION,
|
|
200
|
+
testFramework: options.testFramework as SupportedTestFramework,
|
|
149
201
|
}),
|
|
150
202
|
}
|
|
151
203
|
}
|
|
@@ -158,8 +210,11 @@ function generateGithubWorkflow(options: NewOptions): Output | null {
|
|
|
158
210
|
return {
|
|
159
211
|
target: './.github/workflows/ci.yml',
|
|
160
212
|
content: createGithubActionsCIYml(
|
|
161
|
-
getBinaryName(options.name),
|
|
162
213
|
options.targets,
|
|
214
|
+
options.packageManager as SupportedPackageManager,
|
|
215
|
+
(options.targets.find((t) =>
|
|
216
|
+
t.includes('wasm32-wasi'),
|
|
217
|
+
) as WasiTargetName) ?? 'wasm32-wasi-preview1-threads',
|
|
163
218
|
),
|
|
164
219
|
}
|
|
165
220
|
}
|
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,4 +1,4 @@
|
|
|
1
|
-
import { resolve } from 'path'
|
|
1
|
+
import { resolve } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { isNil, merge, omitBy, pick } from 'lodash-es'
|
|
4
4
|
|
|
@@ -30,6 +30,15 @@ export async function renameProject(userOptions: RenameOptions) {
|
|
|
30
30
|
},
|
|
31
31
|
)
|
|
32
32
|
|
|
33
|
+
if (options.configPath) {
|
|
34
|
+
const configPath = resolve(options.cwd, options.configPath)
|
|
35
|
+
const configContent = await readFileAsync(configPath, 'utf8')
|
|
36
|
+
const configData = JSON.parse(configContent)
|
|
37
|
+
configData.binaryName = options.binaryName
|
|
38
|
+
configData.packageName = options.packageName
|
|
39
|
+
await writeFileAsync(configPath, JSON.stringify(configData, null, 2))
|
|
40
|
+
}
|
|
41
|
+
|
|
33
42
|
await writeFileAsync(
|
|
34
43
|
packageJsonPath,
|
|
35
44
|
JSON.stringify(packageJsonData, null, 2),
|