@napi-rs/cli 3.1.2 → 3.1.3
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/cli.js +518 -320
- package/dist/index.cjs +614 -6990
- package/dist/index.d.cts +537 -0
- package/dist/index.d.ts +527 -19
- package/dist/index.js +473 -286
- package/package.json +9 -19
- package/src/api/build.ts +36 -55
- package/src/api/rename.ts +9 -3
- package/src/utils/config.ts +2 -2
- package/src/utils/typegen.ts +14 -2
- package/dist/api/__tests__/create-npm-dirs.spec.d.ts +0 -1
- package/dist/api/__tests__/new.spec.d.ts +0 -1
- package/dist/api/artifacts.d.ts +0 -2
- package/dist/api/build.d.ts +0 -14
- package/dist/api/create-npm-dirs.d.ts +0 -7
- package/dist/api/new.d.ts +0 -4
- package/dist/api/pre-publish.d.ts +0 -2
- package/dist/api/rename.d.ts +0 -2
- package/dist/api/templates/index.d.ts +0 -1
- package/dist/api/templates/js-binding.d.ts +0 -2
- package/dist/api/templates/load-wasi-template.d.ts +0 -2
- package/dist/api/templates/wasi-worker-template.d.ts +0 -2
- package/dist/api/universalize.d.ts +0 -2
- package/dist/api/version.d.ts +0 -2
- package/dist/cli.d.ts +0 -2
- package/dist/commands/artifacts.d.ts +0 -6
- package/dist/commands/build.d.ts +0 -6
- package/dist/commands/create-npm-dirs.d.ts +0 -4
- package/dist/commands/help.d.ts +0 -10
- package/dist/commands/new.d.ts +0 -12
- package/dist/commands/pre-publish.d.ts +0 -4
- package/dist/commands/rename.d.ts +0 -4
- package/dist/commands/universalize.d.ts +0 -4
- package/dist/commands/version.d.ts +0 -4
- package/dist/def/artifacts.d.ts +0 -70
- package/dist/def/build.d.ts +0 -313
- package/dist/def/create-npm-dirs.d.ts +0 -60
- package/dist/def/new.d.ts +0 -124
- package/dist/def/pre-publish.d.ts +0 -107
- package/dist/def/rename.d.ts +0 -110
- package/dist/def/universalize.d.ts +0 -51
- package/dist/def/version.d.ts +0 -51
- package/dist/utils/__tests__/config.spec.d.ts +0 -1
- package/dist/utils/__tests__/target.spec.d.ts +0 -1
- package/dist/utils/__tests__/typegen.spec.d.ts +0 -1
- package/dist/utils/__tests__/version.spec.d.ts +0 -1
- package/dist/utils/cargo.d.ts +0 -1
- package/dist/utils/config.d.ts +0 -129
- package/dist/utils/index.d.ts +0 -9
- package/dist/utils/log.d.ts +0 -10
- package/dist/utils/metadata.d.ts +0 -36
- package/dist/utils/misc.d.ts +0 -13
- package/dist/utils/read-config.d.ts +0 -7
- package/dist/utils/target.d.ts +0 -33
- package/dist/utils/typegen.d.ts +0 -6
- package/dist/utils/version.d.ts +0 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@napi-rs/cli",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
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",
|
|
@@ -15,21 +15,13 @@
|
|
|
15
15
|
},
|
|
16
16
|
"main": "./dist/index.cjs",
|
|
17
17
|
"module": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|
|
20
|
-
"import":
|
|
21
|
-
|
|
22
|
-
"default": "./dist/index.js"
|
|
23
|
-
},
|
|
24
|
-
"require": {
|
|
25
|
-
"types": "./dist/index.d.ts",
|
|
26
|
-
"default": "./dist/index.cjs"
|
|
27
|
-
}
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
28
23
|
},
|
|
29
|
-
"./package.json":
|
|
30
|
-
"import": "./package.json",
|
|
31
|
-
"require": "./package.json"
|
|
32
|
-
}
|
|
24
|
+
"./package.json": "./package.json"
|
|
33
25
|
},
|
|
34
26
|
"files": [
|
|
35
27
|
"dist",
|
|
@@ -75,27 +67,26 @@
|
|
|
75
67
|
"colorette": "^2.0.20",
|
|
76
68
|
"debug": "^4.4.0",
|
|
77
69
|
"emnapi": "^1.4.0",
|
|
70
|
+
"es-toolkit": "^1.39.8",
|
|
78
71
|
"find-up": "^7.0.0",
|
|
79
72
|
"js-yaml": "^4.1.0",
|
|
80
|
-
"lodash-es": "^4.17.21",
|
|
81
73
|
"semver": "^7.7.1",
|
|
82
74
|
"typanion": "^3.14.0"
|
|
83
75
|
},
|
|
84
76
|
"devDependencies": {
|
|
85
77
|
"@emnapi/core": "^1.4.0",
|
|
86
78
|
"@emnapi/runtime": "^1.4.0",
|
|
87
|
-
"@oxc-node/core": "^0.0.
|
|
79
|
+
"@oxc-node/core": "^0.0.32",
|
|
88
80
|
"@std/toml": "npm:@jsr/std__toml@^1.0.8",
|
|
89
81
|
"@types/debug": "^4.1.12",
|
|
90
82
|
"@types/inquirer": "^9.0.7",
|
|
91
83
|
"@types/js-yaml": "^4.0.9",
|
|
92
|
-
"@types/lodash-es": "^4.17.12",
|
|
93
84
|
"@types/node": "^22.13.16",
|
|
94
85
|
"@types/semver": "^7.7.0",
|
|
95
86
|
"ava": "^6.2.0",
|
|
96
87
|
"env-paths": "^3.0.0",
|
|
97
88
|
"prettier": "^3.5.3",
|
|
98
|
-
"
|
|
89
|
+
"tsdown": "^0.14.0",
|
|
99
90
|
"tslib": "^2.8.1",
|
|
100
91
|
"typescript": "^5.8.2"
|
|
101
92
|
},
|
|
@@ -116,9 +107,8 @@
|
|
|
116
107
|
"url": "https://github.com/sponsors/Brooooooklyn"
|
|
117
108
|
},
|
|
118
109
|
"scripts": {
|
|
119
|
-
"clean": "node --import @oxc-node/core/register ./clean.ts",
|
|
120
110
|
"codegen": "node --import @oxc-node/core/register ./codegen/index.ts",
|
|
121
|
-
"build": "
|
|
111
|
+
"build": "tsdown",
|
|
122
112
|
"test": "node --import @oxc-node/core/register ../node_modules/ava/entrypoints/cli.mjs"
|
|
123
113
|
},
|
|
124
114
|
"ava": {
|
package/src/api/build.ts
CHANGED
|
@@ -227,62 +227,43 @@ class Builder {
|
|
|
227
227
|
const upperCaseTarget = targetToEnvVar(this.target.triple)
|
|
228
228
|
const crossTargetName = alias[this.target.triple] ?? this.target.triple
|
|
229
229
|
const linkerEnv = `CARGO_TARGET_${upperCaseTarget}_LINKER`
|
|
230
|
-
this.
|
|
231
|
-
|
|
232
|
-
'bin',
|
|
233
|
-
`${crossTargetName}-gcc`,
|
|
230
|
+
this.setEnvIfNotExists(
|
|
231
|
+
linkerEnv,
|
|
232
|
+
join(toolchainPath, 'bin', `${crossTargetName}-gcc`),
|
|
234
233
|
)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
'usr',
|
|
269
|
-
'include/',
|
|
270
|
-
)
|
|
271
|
-
}
|
|
272
|
-
if (!process.env.TARGET_CC) {
|
|
273
|
-
this.envs[`TARGET_CC`] = join(
|
|
274
|
-
toolchainPath,
|
|
275
|
-
'bin',
|
|
276
|
-
`${crossTargetName}-gcc`,
|
|
277
|
-
)
|
|
278
|
-
}
|
|
279
|
-
if (!process.env.TARGET_CXX) {
|
|
280
|
-
this.envs[`TARGET_CXX`] = join(
|
|
281
|
-
toolchainPath,
|
|
282
|
-
'bin',
|
|
283
|
-
`${crossTargetName}-g++`,
|
|
284
|
-
)
|
|
285
|
-
}
|
|
234
|
+
this.setEnvIfNotExists(
|
|
235
|
+
'TARGET_SYSROOT',
|
|
236
|
+
join(toolchainPath, crossTargetName, 'sysroot'),
|
|
237
|
+
)
|
|
238
|
+
this.setEnvIfNotExists(
|
|
239
|
+
'TARGET_AR',
|
|
240
|
+
join(toolchainPath, 'bin', `${crossTargetName}-ar`),
|
|
241
|
+
)
|
|
242
|
+
this.setEnvIfNotExists(
|
|
243
|
+
'TARGET_RANLIB',
|
|
244
|
+
join(toolchainPath, 'bin', `${crossTargetName}-ranlib`),
|
|
245
|
+
)
|
|
246
|
+
this.setEnvIfNotExists(
|
|
247
|
+
'TARGET_READELF',
|
|
248
|
+
join(toolchainPath, 'bin', `${crossTargetName}-readelf`),
|
|
249
|
+
)
|
|
250
|
+
this.setEnvIfNotExists(
|
|
251
|
+
'TARGET_C_INCLUDE_PATH',
|
|
252
|
+
join(toolchainPath, crossTargetName, 'sysroot', 'usr', 'include/'),
|
|
253
|
+
)
|
|
254
|
+
this.setEnvIfNotExists(
|
|
255
|
+
'TARGET_CC',
|
|
256
|
+
join(toolchainPath, 'bin', `${crossTargetName}-gcc`),
|
|
257
|
+
)
|
|
258
|
+
this.setEnvIfNotExists(
|
|
259
|
+
'TARGET_CXX',
|
|
260
|
+
join(toolchainPath, 'bin', `${crossTargetName}-g++`),
|
|
261
|
+
)
|
|
262
|
+
this.setEnvIfNotExists(
|
|
263
|
+
'BINDGEN_EXTRA_CLANG_ARGS',
|
|
264
|
+
`--sysroot=${this.envs.TARGET_SYSROOT}}`,
|
|
265
|
+
)
|
|
266
|
+
|
|
286
267
|
if (
|
|
287
268
|
process.env.TARGET_CC?.startsWith('clang') ||
|
|
288
269
|
(process.env.CC?.startsWith('clang') && !process.env.TARGET_CC)
|
package/src/api/rename.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { resolve, join } from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
import { parse as parseToml, stringify as stringifyToml } from '@std/toml'
|
|
6
6
|
import { load as yamlParse, dump as yamlStringify } from 'js-yaml'
|
|
7
|
-
import { isNil, merge, omitBy, pick } from '
|
|
7
|
+
import { isNil, merge, omitBy, pick } from 'es-toolkit'
|
|
8
8
|
import { findUp } from 'find-up'
|
|
9
9
|
|
|
10
10
|
import { applyDefaultRenameOptions, RenameOptions } from '../def/rename.js'
|
|
@@ -22,8 +22,14 @@ export async function renameProject(userOptions: RenameOptions) {
|
|
|
22
22
|
const packageJsonData = JSON.parse(packageJsonContent)
|
|
23
23
|
|
|
24
24
|
merge(
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
merge(
|
|
26
|
+
packageJsonData,
|
|
27
|
+
omitBy(
|
|
28
|
+
// @ts-expect-error missing fields: author and license
|
|
29
|
+
pick(options, ['name', 'description', 'author', 'license']),
|
|
30
|
+
isNil,
|
|
31
|
+
),
|
|
32
|
+
),
|
|
27
33
|
{
|
|
28
34
|
napi: omitBy(
|
|
29
35
|
{
|
package/src/utils/config.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { underline, yellow } from 'colorette'
|
|
2
|
-
import { merge, omit } from '
|
|
2
|
+
import { merge, omit } from 'es-toolkit'
|
|
3
3
|
|
|
4
4
|
import { fileExists, readFileAsync } from './misc.js'
|
|
5
5
|
import { DEFAULT_TARGETS, parseTriple, Target } from './target.js'
|
|
@@ -208,7 +208,7 @@ export async function readNapiConfig(
|
|
|
208
208
|
packageJson: pkgJson,
|
|
209
209
|
npmClient: 'npm',
|
|
210
210
|
},
|
|
211
|
-
omit(userNapiConfig, 'targets'),
|
|
211
|
+
omit(userNapiConfig, ['targets']),
|
|
212
212
|
)
|
|
213
213
|
|
|
214
214
|
let targets: string[] = userNapiConfig.targets ?? []
|
package/src/utils/typegen.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sortBy } from '
|
|
1
|
+
import { sortBy } from 'es-toolkit'
|
|
2
2
|
|
|
3
3
|
import { readFileAsync } from './misc.js'
|
|
4
4
|
|
|
@@ -60,6 +60,18 @@ function prettyPrint(
|
|
|
60
60
|
|
|
61
61
|
case TypeDefKind.Struct:
|
|
62
62
|
const extendsDef = line.extends ? ` extends ${line.extends}` : ''
|
|
63
|
+
if (line.extends) {
|
|
64
|
+
// Extract generic params from extends type like Iterator<T, TResult, TNext>
|
|
65
|
+
const genericMatch = line.extends.match(/Iterator<(.+)>$/)
|
|
66
|
+
if (genericMatch) {
|
|
67
|
+
const [T, TResult, TNext] = genericMatch[1]
|
|
68
|
+
.split(',')
|
|
69
|
+
.map((p) => p.trim())
|
|
70
|
+
line.def =
|
|
71
|
+
line.def +
|
|
72
|
+
`\nnext(value?: ${TNext}): IteratorResult<${T}, ${TResult}>`
|
|
73
|
+
}
|
|
74
|
+
}
|
|
63
75
|
s += `${exportDeclare(ambient)} class ${line.name}${extendsDef} {\n${line.def}\n}`
|
|
64
76
|
if (line.original_name && line.original_name !== line.name) {
|
|
65
77
|
s += `\nexport type ${line.original_name} = ${line.name}`
|
|
@@ -94,7 +106,7 @@ export async function processTypeDef(
|
|
|
94
106
|
const groupedDefs = preprocessTypeDef(defs)
|
|
95
107
|
|
|
96
108
|
const dts =
|
|
97
|
-
sortBy(Array.from(groupedDefs), ([namespace]) => namespace)
|
|
109
|
+
sortBy(Array.from(groupedDefs), [([namespace]) => namespace])
|
|
98
110
|
.map(([namespace, defs]) => {
|
|
99
111
|
if (namespace === TOP_LEVEL_NAMESPACE) {
|
|
100
112
|
return defs
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/api/artifacts.d.ts
DELETED
package/dist/api/build.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BuildOptions as RawBuildOptions } from '../def/build.js';
|
|
2
|
-
type OutputKind = 'js' | 'dts' | 'node' | 'exe' | 'wasm';
|
|
3
|
-
type Output = {
|
|
4
|
-
kind: OutputKind;
|
|
5
|
-
path: string;
|
|
6
|
-
};
|
|
7
|
-
type BuildOptions = RawBuildOptions & {
|
|
8
|
-
cargoOptions?: string[];
|
|
9
|
-
};
|
|
10
|
-
export declare function buildProject(rawOptions: BuildOptions): Promise<{
|
|
11
|
-
task: Promise<Output[]>;
|
|
12
|
-
abort: () => void;
|
|
13
|
-
}>;
|
|
14
|
-
export {};
|
package/dist/api/new.d.ts
DELETED
package/dist/api/rename.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './js-binding.js';
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const createWasiBrowserBinding: (wasiFilename: string, initialMemory?: number, maximumMemory?: number, fs?: boolean, asyncInit?: boolean, buffer?: boolean) => string;
|
|
2
|
-
export declare const createWasiBinding: (wasmFileName: string, packageName: string, initialMemory?: number, maximumMemory?: number) => string;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export declare const WASI_WORKER_TEMPLATE = "import fs from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { parse } from \"node:path\";\nimport { WASI } from \"node:wasi\";\nimport { parentPort, Worker } from \"node:worker_threads\";\n\nconst require = createRequire(import.meta.url);\n\nconst { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require(\"@napi-rs/wasm-runtime\");\n\nif (parentPort) {\n parentPort.on(\"message\", (data) => {\n globalThis.onmessage({ data });\n });\n}\n\nObject.assign(globalThis, {\n self: globalThis,\n require,\n Worker,\n importScripts: function (f) {\n ;(0, eval)(fs.readFileSync(f, \"utf8\") + \"//# sourceURL=\" + f);\n },\n postMessage: function (msg) {\n if (parentPort) {\n parentPort.postMessage(msg);\n }\n },\n});\n\nconst emnapiContext = getDefaultContext();\n\nconst __rootDir = parse(process.cwd()).root;\n\nconst handler = new MessageHandler({\n onLoad({ wasmModule, wasmMemory }) {\n const wasi = new WASI({\n version: 'preview1',\n env: process.env,\n preopens: {\n [__rootDir]: __rootDir,\n },\n });\n\n return instantiateNapiModuleSync(wasmModule, {\n childThread: true,\n wasi,\n context: emnapiContext,\n overwriteImports(importObject) {\n importObject.env = {\n ...importObject.env,\n ...importObject.napi,\n ...importObject.emnapi,\n memory: wasmMemory\n };\n },\n });\n },\n});\n\nglobalThis.onmessage = function (e) {\n handler.handle(e);\n};\n";
|
|
2
|
-
export declare const createWasiBrowserWorkerBinding: (fs: boolean) => string;
|
package/dist/api/version.d.ts
DELETED
package/dist/cli.d.ts
DELETED
package/dist/commands/build.d.ts
DELETED
package/dist/commands/help.d.ts
DELETED
package/dist/commands/new.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { BaseNewCommand } from '../def/new.js';
|
|
2
|
-
export declare class NewCommand extends BaseNewCommand {
|
|
3
|
-
interactive: boolean;
|
|
4
|
-
execute(): Promise<0 | 1>;
|
|
5
|
-
private fetchOptions;
|
|
6
|
-
private fetchName;
|
|
7
|
-
private fetchLicense;
|
|
8
|
-
private fetchNapiVersion;
|
|
9
|
-
private fetchTargets;
|
|
10
|
-
private fetchTypeDef;
|
|
11
|
-
private fetchGithubActions;
|
|
12
|
-
}
|
package/dist/def/artifacts.d.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Command } from 'clipanion';
|
|
2
|
-
export declare abstract class BaseArtifactsCommand extends Command {
|
|
3
|
-
static paths: string[][];
|
|
4
|
-
static usage: import("clipanion").Usage;
|
|
5
|
-
cwd: string;
|
|
6
|
-
configPath?: string;
|
|
7
|
-
packageJsonPath: string;
|
|
8
|
-
outputDir: string;
|
|
9
|
-
npmDir: string;
|
|
10
|
-
buildOutputDir?: string;
|
|
11
|
-
getOptions(): {
|
|
12
|
-
cwd: string;
|
|
13
|
-
configPath: string | undefined;
|
|
14
|
-
packageJsonPath: string;
|
|
15
|
-
outputDir: string;
|
|
16
|
-
npmDir: string;
|
|
17
|
-
buildOutputDir: string | undefined;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Copy artifacts from Github Actions into npm packages and ready to publish
|
|
22
|
-
*/
|
|
23
|
-
export interface ArtifactsOptions {
|
|
24
|
-
/**
|
|
25
|
-
* The working directory of where napi command will be executed in, all other paths options are relative to this path
|
|
26
|
-
*
|
|
27
|
-
* @default process.cwd()
|
|
28
|
-
*/
|
|
29
|
-
cwd?: string;
|
|
30
|
-
/**
|
|
31
|
-
* Path to `napi` config json file
|
|
32
|
-
*/
|
|
33
|
-
configPath?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Path to `package.json`
|
|
36
|
-
*
|
|
37
|
-
* @default 'package.json'
|
|
38
|
-
*/
|
|
39
|
-
packageJsonPath?: string;
|
|
40
|
-
/**
|
|
41
|
-
* Path to the folder where all built `.node` files put, same as `--output-dir` of build command
|
|
42
|
-
*
|
|
43
|
-
* @default './artifacts'
|
|
44
|
-
*/
|
|
45
|
-
outputDir?: string;
|
|
46
|
-
/**
|
|
47
|
-
* Path to the folder where the npm packages put
|
|
48
|
-
*
|
|
49
|
-
* @default 'npm'
|
|
50
|
-
*/
|
|
51
|
-
npmDir?: string;
|
|
52
|
-
/**
|
|
53
|
-
* Path to the build output dir, only needed when targets contains `wasm32-wasi-*`
|
|
54
|
-
*/
|
|
55
|
-
buildOutputDir?: string;
|
|
56
|
-
}
|
|
57
|
-
export declare function applyDefaultArtifactsOptions(options: ArtifactsOptions): {
|
|
58
|
-
cwd: string;
|
|
59
|
-
/**
|
|
60
|
-
* Path to `napi` config json file
|
|
61
|
-
*/
|
|
62
|
-
configPath?: string;
|
|
63
|
-
packageJsonPath: string;
|
|
64
|
-
outputDir: string;
|
|
65
|
-
npmDir: string;
|
|
66
|
-
/**
|
|
67
|
-
* Path to the build output dir, only needed when targets contains `wasm32-wasi-*`
|
|
68
|
-
*/
|
|
69
|
-
buildOutputDir?: string;
|
|
70
|
-
};
|