@napi-rs/cli 3.0.0-alpha.8 → 3.0.0-alpha.81
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/artifacts.js +28 -7
- package/dist/api/artifacts.js.map +1 -1
- package/dist/api/build.js +310 -65
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +46 -9
- package/dist/api/create-npm-dirs.js.map +1 -1
- package/dist/api/new.js +57 -20
- package/dist/api/new.js.map +1 -1
- package/dist/api/pre-publish.js +9 -7
- package/dist/api/pre-publish.js.map +1 -1
- package/dist/api/rename.js +9 -1
- package/dist/api/rename.js.map +1 -1
- package/dist/api/templates/cargo.toml.js +1 -0
- package/dist/api/templates/cargo.toml.js.map +1 -1
- package/dist/api/templates/ci-template.d.ts +3 -1
- package/dist/api/templates/ci-template.js +140 -125
- package/dist/api/templates/ci-template.js.map +1 -1
- package/dist/api/templates/ci.yml.d.ts +3 -1
- package/dist/api/templates/ci.yml.js +21 -5
- package/dist/api/templates/ci.yml.js.map +1 -1
- package/dist/api/templates/js-binding.d.ts +1 -0
- package/dist/api/templates/js-binding.js +141 -222
- package/dist/api/templates/js-binding.js.map +1 -1
- package/dist/api/templates/lib.rs.js +1 -4
- package/dist/api/templates/lib.rs.js.map +1 -1
- package/dist/api/templates/load-wasi-template.d.ts +2 -0
- package/dist/api/templates/load-wasi-template.js +168 -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 +26 -4
- package/dist/api/templates/package.json.js.map +1 -1
- package/dist/api/templates/wasi-worker-template.d.ts +2 -0
- package/dist/api/templates/wasi-worker-template.js +122 -0
- package/dist/api/templates/wasi-worker-template.js.map +1 -0
- package/dist/api/universalize.js +5 -5
- package/dist/api/universalize.js.map +1 -1
- package/dist/api/version.js +2 -2
- package/dist/api/version.js.map +1 -1
- package/dist/commands/artifacts.js +2 -2
- package/dist/commands/artifacts.js.map +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/new.js +34 -34
- package/dist/commands/new.js.map +1 -1
- package/dist/def/artifacts.d.ts +21 -1
- package/dist/def/artifacts.js +10 -2
- package/dist/def/artifacts.js.map +1 -1
- package/dist/def/build.d.ts +155 -4
- package/dist/def/build.js +30 -4
- package/dist/def/build.js.map +1 -1
- package/dist/def/create-npm-dirs.d.ts +10 -0
- package/dist/def/create-npm-dirs.js +4 -0
- package/dist/def/create-npm-dirs.js.map +1 -1
- package/dist/def/new.d.ts +25 -7
- package/dist/def/new.js +11 -1
- package/dist/def/new.js.map +1 -1
- package/dist/def/pre-publish.d.ts +12 -2
- package/dist/def/pre-publish.js +7 -3
- package/dist/def/pre-publish.js.map +1 -1
- package/dist/def/rename.d.ts +16 -6
- package/dist/def/rename.js +5 -1
- package/dist/def/rename.js.map +1 -1
- package/dist/def/universalize.d.ts +10 -0
- package/dist/def/universalize.js +4 -0
- package/dist/def/universalize.js.map +1 -1
- package/dist/def/version.d.ts +10 -0
- package/dist/def/version.js +4 -0
- package/dist/def/version.js.map +1 -1
- package/dist/index.cjs +7596 -13754
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- 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__/typegen.spec.js +8 -4
- package/dist/utils/__tests__/typegen.spec.js.map +1 -1
- package/dist/utils/cargo.js +2 -2
- package/dist/utils/cargo.js.map +1 -1
- package/dist/utils/config.d.ts +52 -4
- package/dist/utils/config.js +37 -5
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/metadata.d.ts +13 -1
- package/dist/utils/metadata.js +31 -11
- package/dist/utils/metadata.js.map +1 -1
- package/dist/utils/misc.d.ts +1 -2
- package/dist/utils/misc.js +3 -3
- package/dist/utils/misc.js.map +1 -1
- package/dist/utils/target.d.ts +7 -5
- package/dist/utils/target.js +17 -3
- package/dist/utils/target.js.map +1 -1
- package/dist/utils/typegen.d.ts +1 -1
- package/dist/utils/typegen.js +55 -20
- package/dist/utils/typegen.js.map +1 -1
- package/dist/utils/version.d.ts +2 -1
- package/dist/utils/version.js +10 -8
- package/dist/utils/version.js.map +1 -1
- package/package.json +27 -26
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +468 -88
- package/src/api/create-npm-dirs.ts +57 -9
- package/src/api/new.ts +89 -31
- package/src/api/pre-publish.ts +13 -7
- package/src/api/rename.ts +10 -1
- 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 +147 -220
- package/src/api/templates/lib.rs.ts +1 -4
- 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 +64 -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/index.ts +2 -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 +711 -158
- 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 +2 -2
- package/src/utils/config.ts +116 -10
- package/src/utils/index.ts +0 -1
- package/src/utils/metadata.ts +52 -14
- package/src/utils/misc.ts +11 -3
- package/src/utils/target.ts +22 -4
- package/src/utils/typegen.ts +98 -49
- package/src/utils/version.ts +10 -8
- 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/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/utils/ci.d.ts +0 -11
- package/dist/utils/ci.js +0 -96
- package/dist/utils/ci.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
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { join, resolve } from 'path'
|
|
1
|
+
import { join, resolve } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { parse } from 'semver'
|
|
2
4
|
|
|
3
5
|
import {
|
|
4
6
|
applyDefaultCreateNpmDirsOptions,
|
|
@@ -13,6 +15,8 @@ import {
|
|
|
13
15
|
Target,
|
|
14
16
|
} from '../utils/index.js'
|
|
15
17
|
|
|
18
|
+
import type { PackageMeta } from './templates/package.json.js'
|
|
19
|
+
|
|
16
20
|
const debug = debugFactory('create-npm-dirs')
|
|
17
21
|
|
|
18
22
|
export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
@@ -43,20 +47,25 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
43
47
|
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
44
48
|
const npmPath = resolve(options.cwd, options.npmDir)
|
|
45
49
|
|
|
46
|
-
debug(`Read content from [${packageJsonPath}]`)
|
|
50
|
+
debug(`Read content from [${options.configPath ?? packageJsonPath}]`)
|
|
47
51
|
|
|
48
52
|
const { targets, binaryName, packageName, packageJson } =
|
|
49
|
-
await readNapiConfig(
|
|
53
|
+
await readNapiConfig(
|
|
54
|
+
packageJsonPath,
|
|
55
|
+
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
56
|
+
)
|
|
50
57
|
|
|
51
58
|
for (const target of targets) {
|
|
52
59
|
const targetDir = join(npmPath, `${target.platformArchABI}`)
|
|
53
60
|
await mkdirAsync(targetDir)
|
|
54
61
|
|
|
55
|
-
const binaryFileName =
|
|
62
|
+
const binaryFileName =
|
|
63
|
+
target.arch === 'wasm32'
|
|
64
|
+
? `${binaryName}.${target.platformArchABI}.wasm`
|
|
65
|
+
: `${binaryName}.${target.platformArchABI}.node`
|
|
56
66
|
const scopedPackageJson = {
|
|
57
67
|
name: `${packageName}-${target.platformArchABI}`,
|
|
58
68
|
version: packageJson.version,
|
|
59
|
-
os: [target.platform],
|
|
60
69
|
cpu: target.arch !== 'universal' ? [target.arch] : undefined,
|
|
61
70
|
main: binaryFileName,
|
|
62
71
|
files: [binaryFileName],
|
|
@@ -74,9 +83,48 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
74
83
|
'bugs',
|
|
75
84
|
),
|
|
76
85
|
}
|
|
86
|
+
if (target.arch !== 'wasm32') {
|
|
87
|
+
// @ts-expect-error
|
|
88
|
+
scopedPackageJson.os = [target.platform]
|
|
89
|
+
} else {
|
|
90
|
+
const entry = `${binaryName}.wasi.cjs`
|
|
91
|
+
scopedPackageJson.main = entry
|
|
92
|
+
// @ts-expect-error
|
|
93
|
+
scopedPackageJson.browser = `${binaryName}.wasi-browser.js`
|
|
94
|
+
scopedPackageJson.files.push(
|
|
95
|
+
entry,
|
|
96
|
+
// @ts-expect-error
|
|
97
|
+
scopedPackageJson.browser,
|
|
98
|
+
`wasi-worker.mjs`,
|
|
99
|
+
`wasi-worker-browser.mjs`,
|
|
100
|
+
)
|
|
101
|
+
let needRestrictNodeVersion = true
|
|
102
|
+
if (scopedPackageJson.engines?.node) {
|
|
103
|
+
try {
|
|
104
|
+
const { major } = parse(scopedPackageJson.engines.node) ?? {
|
|
105
|
+
major: 0,
|
|
106
|
+
}
|
|
107
|
+
if (major >= 14) {
|
|
108
|
+
needRestrictNodeVersion = false
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
// ignore
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (needRestrictNodeVersion) {
|
|
115
|
+
scopedPackageJson.engines = {
|
|
116
|
+
node: '>=14.0.0',
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const wasmRuntime = await fetch(
|
|
120
|
+
`https://registry.npmjs.org/@napi-rs/wasm-runtime`,
|
|
121
|
+
).then((res) => res.json() as Promise<PackageMeta>)
|
|
122
|
+
// @ts-expect-error
|
|
123
|
+
scopedPackageJson.dependencies = {
|
|
124
|
+
'@napi-rs/wasm-runtime': `^${wasmRuntime['dist-tags'].latest}`,
|
|
125
|
+
}
|
|
126
|
+
}
|
|
77
127
|
|
|
78
|
-
// Only works with yarn 3.1+
|
|
79
|
-
// https://github.com/yarnpkg/berry/pull/3981
|
|
80
128
|
if (target.abi === 'gnu') {
|
|
81
129
|
// @ts-expect-error
|
|
82
130
|
scopedPackageJson.libc = ['glibc']
|
|
@@ -88,12 +136,12 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
88
136
|
const targetPackageJson = join(targetDir, 'package.json')
|
|
89
137
|
await writeFileAsync(
|
|
90
138
|
targetPackageJson,
|
|
91
|
-
JSON.stringify(scopedPackageJson, null, 2),
|
|
139
|
+
JSON.stringify(scopedPackageJson, null, 2) + '\n',
|
|
92
140
|
)
|
|
93
141
|
const targetReadme = join(targetDir, 'README.md')
|
|
94
142
|
await writeFileAsync(targetReadme, readme(packageName, target))
|
|
95
143
|
|
|
96
|
-
debug.info(`${packageName}-${target.platformArchABI} created`)
|
|
144
|
+
debug.info(`${packageName} -${target.platformArchABI} created`)
|
|
97
145
|
}
|
|
98
146
|
}
|
|
99
147
|
|
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
|
}
|
|
@@ -157,7 +209,13 @@ function generateGithubWorkflow(options: NewOptions): Output | null {
|
|
|
157
209
|
|
|
158
210
|
return {
|
|
159
211
|
target: './.github/workflows/ci.yml',
|
|
160
|
-
content: createGithubActionsCIYml(
|
|
212
|
+
content: createGithubActionsCIYml(
|
|
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',
|
|
218
|
+
),
|
|
161
219
|
}
|
|
162
220
|
}
|
|
163
221
|
|
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),
|