@napi-rs/cli 3.0.0-alpha.6 → 3.0.0-alpha.61
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 +28 -7
- package/dist/api/artifacts.js.map +1 -1
- package/dist/api/build.js +220 -39
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +45 -8
- 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/ci-template.d.ts +3 -1
- package/dist/api/templates/ci-template.js +124 -124
- 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.js +104 -214
- 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 +166 -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 +30 -8
- 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 +22 -4
- package/dist/def/build.js +16 -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 +8143 -14638
- 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 +1 -1
- package/dist/utils/cargo.js.map +1 -1
- package/dist/utils/config.d.ts +49 -5
- package/dist/utils/config.js +38 -6
- 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.js +2 -2
- 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 +29 -9
- 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 +25 -24
- package/src/api/artifacts.ts +81 -9
- package/src/api/build.ts +379 -58
- package/src/api/create-npm-dirs.ts +56 -8
- 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/ci-template.ts +134 -124
- package/src/api/templates/ci.yml.ts +27 -6
- package/src/api/templates/js-binding.ts +105 -214
- package/src/api/templates/lib.rs.ts +1 -4
- package/src/api/templates/load-wasi-template.ts +180 -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 +31 -8
- package/src/def/artifacts.ts +22 -3
- package/src/def/build.ts +36 -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 +713 -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 +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 +22 -4
- package/src/utils/typegen.ts +37 -8
- 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 -63
- 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 -65
- package/src/api/wasi-worker-template.ts +0 -52
- package/src/utils/ci.ts +0 -111
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export const WASI_WORKER_TEMPLATE = `import fs from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { parse } from "node:path";
|
|
4
|
+
import { WASI } from "node:wasi";
|
|
5
|
+
import { parentPort, Worker } from "node:worker_threads";
|
|
6
|
+
|
|
7
|
+
const require = createRequire(import.meta.url);
|
|
8
|
+
|
|
9
|
+
const { instantiateNapiModuleSync, MessageHandler, getDefaultContext } = require("@napi-rs/wasm-runtime");
|
|
10
|
+
|
|
11
|
+
if (parentPort) {
|
|
12
|
+
parentPort.on("message", (data) => {
|
|
13
|
+
globalThis.onmessage({ data });
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Object.assign(globalThis, {
|
|
18
|
+
self: globalThis,
|
|
19
|
+
require,
|
|
20
|
+
Worker,
|
|
21
|
+
importScripts: function (f) {
|
|
22
|
+
;(0, eval)(fs.readFileSync(f, "utf8") + "//# sourceURL=" + f);
|
|
23
|
+
},
|
|
24
|
+
postMessage: function (msg) {
|
|
25
|
+
if (parentPort) {
|
|
26
|
+
parentPort.postMessage(msg);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const emnapiContext = getDefaultContext();
|
|
32
|
+
|
|
33
|
+
const __rootDir = parse(process.cwd()).root;
|
|
34
|
+
|
|
35
|
+
const handler = new MessageHandler({
|
|
36
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
37
|
+
const wasi = new WASI({
|
|
38
|
+
version: 'preview1',
|
|
39
|
+
env: process.env,
|
|
40
|
+
preopens: {
|
|
41
|
+
[__rootDir]: __rootDir,
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
46
|
+
childThread: true,
|
|
47
|
+
wasi,
|
|
48
|
+
context: emnapiContext,
|
|
49
|
+
overwriteImports(importObject) {
|
|
50
|
+
importObject.env = {
|
|
51
|
+
...importObject.env,
|
|
52
|
+
...importObject.napi,
|
|
53
|
+
...importObject.emnapi,
|
|
54
|
+
memory: wasmMemory
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
globalThis.onmessage = function (e) {
|
|
62
|
+
handler.handle(e);
|
|
63
|
+
};
|
|
64
|
+
`
|
|
65
|
+
|
|
66
|
+
export const createWasiBrowserWorkerBinding = (fs: boolean) => {
|
|
67
|
+
const fsImport = fs
|
|
68
|
+
? `import { instantiateNapiModuleSync, MessageHandler, WASI, createFsProxy } from '@napi-rs/wasm-runtime'
|
|
69
|
+
import { memfsExported as __memfsExported } from '@napi-rs/wasm-runtime/fs'
|
|
70
|
+
|
|
71
|
+
const fs = createFsProxy(__memfsExported)`
|
|
72
|
+
: `import { instantiateNapiModuleSync, MessageHandler, WASI } from '@napi-rs/wasm-runtime'`
|
|
73
|
+
const wasiCreation = fs
|
|
74
|
+
? `const wasi = new WASI({
|
|
75
|
+
fs,
|
|
76
|
+
preopens: {
|
|
77
|
+
'/': '/',
|
|
78
|
+
},
|
|
79
|
+
print: function () {
|
|
80
|
+
// eslint-disable-next-line no-console
|
|
81
|
+
console.log.apply(console, arguments)
|
|
82
|
+
},
|
|
83
|
+
printErr: function() {
|
|
84
|
+
// eslint-disable-next-line no-console
|
|
85
|
+
console.error.apply(console, arguments)
|
|
86
|
+
},
|
|
87
|
+
})`
|
|
88
|
+
: `const wasi = new WASI({
|
|
89
|
+
print: function () {
|
|
90
|
+
// eslint-disable-next-line no-console
|
|
91
|
+
console.log.apply(console, arguments)
|
|
92
|
+
},
|
|
93
|
+
printErr: function() {
|
|
94
|
+
// eslint-disable-next-line no-console
|
|
95
|
+
console.error.apply(console, arguments)
|
|
96
|
+
},
|
|
97
|
+
})`
|
|
98
|
+
return `${fsImport}
|
|
99
|
+
|
|
100
|
+
const handler = new MessageHandler({
|
|
101
|
+
onLoad({ wasmModule, wasmMemory }) {
|
|
102
|
+
${wasiCreation}
|
|
103
|
+
return instantiateNapiModuleSync(wasmModule, {
|
|
104
|
+
childThread: true,
|
|
105
|
+
wasi,
|
|
106
|
+
overwriteImports(importObject) {
|
|
107
|
+
importObject.env = {
|
|
108
|
+
...importObject.env,
|
|
109
|
+
...importObject.napi,
|
|
110
|
+
...importObject.emnapi,
|
|
111
|
+
memory: wasmMemory,
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
globalThis.onmessage = function (e) {
|
|
119
|
+
handler.handle(e)
|
|
120
|
+
}
|
|
121
|
+
`
|
|
122
|
+
}
|
package/src/api/universalize.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { spawnSync } from 'child_process'
|
|
2
|
-
import { join, resolve } from 'path'
|
|
1
|
+
import { spawnSync } from 'node:child_process'
|
|
2
|
+
import { join, resolve } from 'node:path'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
5
|
applyDefaultUniversalizeOptions,
|
|
@@ -27,7 +27,10 @@ export async function universalizeBinaries(userOptions: UniversalizeOptions) {
|
|
|
27
27
|
|
|
28
28
|
const packageJsonPath = join(options.cwd, options.packageJsonPath)
|
|
29
29
|
|
|
30
|
-
const config = await readNapiConfig(
|
|
30
|
+
const config = await readNapiConfig(
|
|
31
|
+
packageJsonPath,
|
|
32
|
+
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
33
|
+
)
|
|
31
34
|
|
|
32
35
|
const target = config.targets.find(
|
|
33
36
|
(t) => t.platform === process.platform && t.arch === 'universal',
|
|
@@ -39,8 +42,12 @@ export async function universalizeBinaries(userOptions: UniversalizeOptions) {
|
|
|
39
42
|
)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
const srcFiles = UniArchsByPlatform[process.platform]?.map(
|
|
43
|
-
(
|
|
45
|
+
const srcFiles = UniArchsByPlatform[process.platform]?.map((arch) =>
|
|
46
|
+
resolve(
|
|
47
|
+
options.cwd,
|
|
48
|
+
options.outputDir,
|
|
49
|
+
`${config.binaryName}.${process.platform}-${arch}.node`,
|
|
50
|
+
),
|
|
44
51
|
)
|
|
45
52
|
|
|
46
53
|
if (!srcFiles || !universalizers[process.platform]) {
|
|
@@ -52,9 +59,7 @@ export async function universalizeBinaries(userOptions: UniversalizeOptions) {
|
|
|
52
59
|
debug(`Looking up source binaries to combine: `)
|
|
53
60
|
debug(' %O', srcFiles)
|
|
54
61
|
|
|
55
|
-
const srcFileLookup = await Promise.all(
|
|
56
|
-
srcFiles.map((f) => fileExists(resolve(options.cwd, options.outputDir, f))),
|
|
57
|
-
)
|
|
62
|
+
const srcFileLookup = await Promise.all(srcFiles.map((f) => fileExists(f)))
|
|
58
63
|
|
|
59
64
|
const notFoundFiles = srcFiles.filter((_, i) => !srcFileLookup[i])
|
|
60
65
|
|
package/src/api/version.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { join, resolve } from 'path'
|
|
1
|
+
import { join, resolve } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { applyDefaultVersionOptions, VersionOptions } from '../def/version.js'
|
|
4
4
|
import {
|
|
@@ -13,7 +13,10 @@ export async function version(userOptions: VersionOptions) {
|
|
|
13
13
|
const options = applyDefaultVersionOptions(userOptions)
|
|
14
14
|
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
15
15
|
|
|
16
|
-
const config = await readNapiConfig(
|
|
16
|
+
const config = await readNapiConfig(
|
|
17
|
+
packageJsonPath,
|
|
18
|
+
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
19
|
+
)
|
|
17
20
|
|
|
18
21
|
for (const target of config.targets) {
|
|
19
22
|
const pkgDir = resolve(options.cwd, options.npmDir, target.platformArchABI)
|
|
@@ -8,9 +8,9 @@ export class ArtifactsCommand extends BaseArtifactsCommand {
|
|
|
8
8
|
description: 'Copy artifacts from Github Actions into specified dir',
|
|
9
9
|
examples: [
|
|
10
10
|
[
|
|
11
|
-
'$0 artifacts --dir
|
|
11
|
+
'$0 artifacts --output-dir ./artifacts --dist ./npm',
|
|
12
12
|
`Copy [binaryName].[platform].node under current dir(.) into packages under npm dir.
|
|
13
|
-
e.g: index.linux-x64-gnu.node --> ./npm/linux-x64-gnu/index.node`,
|
|
13
|
+
e.g: index.linux-x64-gnu.node --> ./npm/linux-x64-gnu/index.linux-x64-gnu.node`,
|
|
14
14
|
],
|
|
15
15
|
],
|
|
16
16
|
})
|
package/src/commands/build.ts
CHANGED
package/src/commands/new.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import path from 'path'
|
|
1
|
+
import path from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { Option } from 'clipanion'
|
|
4
4
|
import inquirer from 'inquirer'
|
|
@@ -16,7 +16,7 @@ import { napiEngineRequirement } from '../utils/version.js'
|
|
|
16
16
|
const debug = debugFactory('new')
|
|
17
17
|
|
|
18
18
|
export class NewCommand extends BaseNewCommand {
|
|
19
|
-
interactive = Option.Boolean('--interactive,-i',
|
|
19
|
+
interactive = Option.Boolean('--interactive,-i', true, {
|
|
20
20
|
description:
|
|
21
21
|
'Ask project basic information interactively without just using the default.',
|
|
22
22
|
})
|
|
@@ -37,9 +37,13 @@ export class NewCommand extends BaseNewCommand {
|
|
|
37
37
|
const cmdOptions = super.getOptions()
|
|
38
38
|
|
|
39
39
|
if (this.interactive) {
|
|
40
|
+
const targetPath: string = cmdOptions.path
|
|
41
|
+
? cmdOptions.path
|
|
42
|
+
: await inquirerProjectPath()
|
|
43
|
+
cmdOptions.path = targetPath
|
|
40
44
|
return {
|
|
41
45
|
...cmdOptions,
|
|
42
|
-
name: await this.fetchName(path.parse(
|
|
46
|
+
name: await this.fetchName(path.parse(targetPath).base),
|
|
43
47
|
minNodeApiVersion: await this.fetchNapiVersion(),
|
|
44
48
|
targets: await this.fetchTargets(),
|
|
45
49
|
license: await this.fetchLicense(),
|
|
@@ -54,14 +58,14 @@ export class NewCommand extends BaseNewCommand {
|
|
|
54
58
|
private async fetchName(defaultName: string): Promise<string> {
|
|
55
59
|
return (
|
|
56
60
|
this.$$name ??
|
|
57
|
-
|
|
61
|
+
inquirer
|
|
58
62
|
.prompt({
|
|
59
63
|
type: 'input',
|
|
60
64
|
name: 'name',
|
|
61
65
|
message: 'Package name (the name field in your package.json file)',
|
|
62
66
|
default: defaultName,
|
|
63
67
|
})
|
|
64
|
-
.then(({ name }) => name)
|
|
68
|
+
.then(({ name }) => name)
|
|
65
69
|
)
|
|
66
70
|
}
|
|
67
71
|
|
|
@@ -83,7 +87,7 @@ export class NewCommand extends BaseNewCommand {
|
|
|
83
87
|
name: 'minNodeApiVersion',
|
|
84
88
|
message: 'Minimum node-api version (with node version requirement)',
|
|
85
89
|
loop: false,
|
|
86
|
-
choices:
|
|
90
|
+
choices: Array.from({ length: 8 }, (_, i) => ({
|
|
87
91
|
name: `napi${i + 1} (${napiEngineRequirement(i + 1)})`,
|
|
88
92
|
value: i + 1,
|
|
89
93
|
})),
|
|
@@ -103,8 +107,12 @@ export class NewCommand extends BaseNewCommand {
|
|
|
103
107
|
type: 'checkbox',
|
|
104
108
|
loop: false,
|
|
105
109
|
message: 'Choose target(s) your crate will be compiled to',
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
choices: AVAILABLE_TARGETS.map((target) => ({
|
|
111
|
+
name: target,
|
|
112
|
+
value: target,
|
|
113
|
+
// @ts-expect-error
|
|
114
|
+
checked: DEFAULT_TARGETS.includes(target),
|
|
115
|
+
})),
|
|
108
116
|
})
|
|
109
117
|
|
|
110
118
|
return targets
|
|
@@ -132,3 +140,18 @@ export class NewCommand extends BaseNewCommand {
|
|
|
132
140
|
return enableGithubActions
|
|
133
141
|
}
|
|
134
142
|
}
|
|
143
|
+
|
|
144
|
+
async function inquirerProjectPath(): Promise<string> {
|
|
145
|
+
return inquirer
|
|
146
|
+
.prompt({
|
|
147
|
+
type: 'input',
|
|
148
|
+
name: 'path',
|
|
149
|
+
message: 'Target path to create the project, relative to cwd.',
|
|
150
|
+
})
|
|
151
|
+
.then(({ path }) => {
|
|
152
|
+
if (!path) {
|
|
153
|
+
return inquirerProjectPath()
|
|
154
|
+
}
|
|
155
|
+
return path
|
|
156
|
+
})
|
|
157
|
+
}
|
package/src/def/artifacts.ts
CHANGED
|
@@ -15,11 +15,15 @@ export abstract class BaseArtifactsCommand extends Command {
|
|
|
15
15
|
'The working directory of where napi command will be executed in, all other paths options are relative to this path',
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
+
configPath?: string = Option.String('--config-path,-c', {
|
|
19
|
+
description: 'Path to `napi` config json file',
|
|
20
|
+
})
|
|
21
|
+
|
|
18
22
|
packageJsonPath = Option.String('--package-json-path', 'package.json', {
|
|
19
23
|
description: 'Path to `package.json`',
|
|
20
24
|
})
|
|
21
25
|
|
|
22
|
-
outputDir = Option.String('--output-dir,-o', './', {
|
|
26
|
+
outputDir = Option.String('--output-dir,-o,-d', './artifacts', {
|
|
23
27
|
description:
|
|
24
28
|
'Path to the folder where all built `.node` files put, same as `--output-dir` of build command',
|
|
25
29
|
})
|
|
@@ -28,12 +32,19 @@ export abstract class BaseArtifactsCommand extends Command {
|
|
|
28
32
|
description: 'Path to the folder where the npm packages put',
|
|
29
33
|
})
|
|
30
34
|
|
|
35
|
+
buildOutputDir?: string = Option.String('--build-output-dir', {
|
|
36
|
+
description:
|
|
37
|
+
'Path to the build output dir, only needed when targets contains `wasm32-wasi-*`',
|
|
38
|
+
})
|
|
39
|
+
|
|
31
40
|
getOptions() {
|
|
32
41
|
return {
|
|
33
42
|
cwd: this.cwd,
|
|
43
|
+
configPath: this.configPath,
|
|
34
44
|
packageJsonPath: this.packageJsonPath,
|
|
35
45
|
outputDir: this.outputDir,
|
|
36
46
|
npmDir: this.npmDir,
|
|
47
|
+
buildOutputDir: this.buildOutputDir,
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
@@ -48,6 +59,10 @@ export interface ArtifactsOptions {
|
|
|
48
59
|
* @default process.cwd()
|
|
49
60
|
*/
|
|
50
61
|
cwd?: string
|
|
62
|
+
/**
|
|
63
|
+
* Path to `napi` config json file
|
|
64
|
+
*/
|
|
65
|
+
configPath?: string
|
|
51
66
|
/**
|
|
52
67
|
* Path to `package.json`
|
|
53
68
|
*
|
|
@@ -57,7 +72,7 @@ export interface ArtifactsOptions {
|
|
|
57
72
|
/**
|
|
58
73
|
* Path to the folder where all built `.node` files put, same as `--output-dir` of build command
|
|
59
74
|
*
|
|
60
|
-
* @default './'
|
|
75
|
+
* @default './artifacts'
|
|
61
76
|
*/
|
|
62
77
|
outputDir?: string
|
|
63
78
|
/**
|
|
@@ -66,13 +81,17 @@ export interface ArtifactsOptions {
|
|
|
66
81
|
* @default 'npm'
|
|
67
82
|
*/
|
|
68
83
|
npmDir?: string
|
|
84
|
+
/**
|
|
85
|
+
* Path to the build output dir, only needed when targets contains `wasm32-wasi-*`
|
|
86
|
+
*/
|
|
87
|
+
buildOutputDir?: string
|
|
69
88
|
}
|
|
70
89
|
|
|
71
90
|
export function applyDefaultArtifactsOptions(options: ArtifactsOptions) {
|
|
72
91
|
return {
|
|
73
92
|
cwd: process.cwd(),
|
|
74
93
|
packageJsonPath: 'package.json',
|
|
75
|
-
outputDir: './',
|
|
94
|
+
outputDir: './artifacts',
|
|
76
95
|
npmDir: 'npm',
|
|
77
96
|
...options,
|
|
78
97
|
}
|
package/src/def/build.ts
CHANGED
|
@@ -6,7 +6,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
6
6
|
static paths = [['build']]
|
|
7
7
|
|
|
8
8
|
static usage = Command.Usage({
|
|
9
|
-
description: 'Build the
|
|
9
|
+
description: 'Build the NAPI-RS project',
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
target?: string = Option.String('--target,-t', {
|
|
@@ -23,6 +23,10 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
23
23
|
description: 'Path to `Cargo.toml`',
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
+
configPath?: string = Option.String('--config-path,-c', {
|
|
27
|
+
description: 'Path to `napi` config json file',
|
|
28
|
+
})
|
|
29
|
+
|
|
26
30
|
packageJsonPath?: string = Option.String('--package-json-path', {
|
|
27
31
|
description: 'Path to `package.json`',
|
|
28
32
|
})
|
|
@@ -47,9 +51,13 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
47
51
|
'Package name in generated js binding file. Only works with `--platform` flag',
|
|
48
52
|
})
|
|
49
53
|
|
|
54
|
+
constEnum?: boolean = Option.Boolean('--const-enum', {
|
|
55
|
+
description: 'Whether generate const enum for typescript bindings',
|
|
56
|
+
})
|
|
57
|
+
|
|
50
58
|
jsBinding?: string = Option.String('--js', {
|
|
51
59
|
description:
|
|
52
|
-
'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--
|
|
60
|
+
'Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output-dir`.',
|
|
53
61
|
})
|
|
54
62
|
|
|
55
63
|
noJsBinding?: boolean = Option.Boolean('--no-js', {
|
|
@@ -59,7 +67,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
59
67
|
|
|
60
68
|
dts?: string = Option.String('--dts', {
|
|
61
69
|
description:
|
|
62
|
-
'Path and filename of generated type def file. Relative to `--
|
|
70
|
+
'Path and filename of generated type def file. Relative to `--output-dir`',
|
|
63
71
|
})
|
|
64
72
|
|
|
65
73
|
dtsHeader?: string = Option.String('--dts-header', {
|
|
@@ -106,9 +114,14 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
106
114
|
'[experimental] use [cross](https://github.com/cross-rs/cross) instead of `cargo`',
|
|
107
115
|
})
|
|
108
116
|
|
|
117
|
+
useNapiCross?: boolean = Option.Boolean('--use-napi-cross', {
|
|
118
|
+
description:
|
|
119
|
+
'[experimental] use @napi-rs/cross-toolchain to cross-compile Linux arm/arm64/x64 gnu targets.',
|
|
120
|
+
})
|
|
121
|
+
|
|
109
122
|
watch?: boolean = Option.Boolean('--watch,-w', {
|
|
110
123
|
description:
|
|
111
|
-
'watch the crate changes and build
|
|
124
|
+
'watch the crate changes and build continuously with `cargo-watch` crates',
|
|
112
125
|
})
|
|
113
126
|
|
|
114
127
|
features?: string[] = Option.Array('--features,-F', {
|
|
@@ -128,11 +141,13 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
128
141
|
target: this.target,
|
|
129
142
|
cwd: this.cwd,
|
|
130
143
|
manifestPath: this.manifestPath,
|
|
144
|
+
configPath: this.configPath,
|
|
131
145
|
packageJsonPath: this.packageJsonPath,
|
|
132
146
|
targetDir: this.targetDir,
|
|
133
147
|
outputDir: this.outputDir,
|
|
134
148
|
platform: this.platform,
|
|
135
149
|
jsPackageName: this.jsPackageName,
|
|
150
|
+
constEnum: this.constEnum,
|
|
136
151
|
jsBinding: this.jsBinding,
|
|
137
152
|
noJsBinding: this.noJsBinding,
|
|
138
153
|
dts: this.dts,
|
|
@@ -146,6 +161,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
146
161
|
profile: this.profile,
|
|
147
162
|
crossCompile: this.crossCompile,
|
|
148
163
|
useCross: this.useCross,
|
|
164
|
+
useNapiCross: this.useNapiCross,
|
|
149
165
|
watch: this.watch,
|
|
150
166
|
features: this.features,
|
|
151
167
|
allFeatures: this.allFeatures,
|
|
@@ -155,7 +171,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
155
171
|
}
|
|
156
172
|
|
|
157
173
|
/**
|
|
158
|
-
* Build the
|
|
174
|
+
* Build the NAPI-RS project
|
|
159
175
|
*/
|
|
160
176
|
export interface BuildOptions {
|
|
161
177
|
/**
|
|
@@ -170,6 +186,10 @@ export interface BuildOptions {
|
|
|
170
186
|
* Path to `Cargo.toml`
|
|
171
187
|
*/
|
|
172
188
|
manifestPath?: string
|
|
189
|
+
/**
|
|
190
|
+
* Path to `napi` config json file
|
|
191
|
+
*/
|
|
192
|
+
configPath?: string
|
|
173
193
|
/**
|
|
174
194
|
* Path to `package.json`
|
|
175
195
|
*/
|
|
@@ -191,7 +211,11 @@ export interface BuildOptions {
|
|
|
191
211
|
*/
|
|
192
212
|
jsPackageName?: string
|
|
193
213
|
/**
|
|
194
|
-
*
|
|
214
|
+
* Whether generate const enum for typescript bindings
|
|
215
|
+
*/
|
|
216
|
+
constEnum?: boolean
|
|
217
|
+
/**
|
|
218
|
+
* Path and filename of generated JS binding file. Only works with `--platform` flag. Relative to `--output-dir`.
|
|
195
219
|
*/
|
|
196
220
|
jsBinding?: string
|
|
197
221
|
/**
|
|
@@ -199,7 +223,7 @@ export interface BuildOptions {
|
|
|
199
223
|
*/
|
|
200
224
|
noJsBinding?: boolean
|
|
201
225
|
/**
|
|
202
|
-
* Path and filename of generated type def file. Relative to `--
|
|
226
|
+
* Path and filename of generated type def file. Relative to `--output-dir`
|
|
203
227
|
*/
|
|
204
228
|
dts?: string
|
|
205
229
|
/**
|
|
@@ -243,7 +267,11 @@ export interface BuildOptions {
|
|
|
243
267
|
*/
|
|
244
268
|
useCross?: boolean
|
|
245
269
|
/**
|
|
246
|
-
*
|
|
270
|
+
* [experimental] use @napi-rs/cross-toolchain to cross-compile Linux arm/arm64/x64 gnu targets.
|
|
271
|
+
*/
|
|
272
|
+
useNapiCross?: boolean
|
|
273
|
+
/**
|
|
274
|
+
* watch the crate changes and build continuously with `cargo-watch` crates
|
|
247
275
|
*/
|
|
248
276
|
watch?: boolean
|
|
249
277
|
/**
|
|
@@ -14,6 +14,10 @@ export abstract class BaseCreateNpmDirsCommand extends Command {
|
|
|
14
14
|
'The working directory of where napi command will be executed in, all other paths options are relative to this path',
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
+
configPath?: string = Option.String('--config-path,-c', {
|
|
18
|
+
description: 'Path to `napi` config json file',
|
|
19
|
+
})
|
|
20
|
+
|
|
17
21
|
packageJsonPath = Option.String('--package-json-path', 'package.json', {
|
|
18
22
|
description: 'Path to `package.json`',
|
|
19
23
|
})
|
|
@@ -29,6 +33,7 @@ export abstract class BaseCreateNpmDirsCommand extends Command {
|
|
|
29
33
|
getOptions() {
|
|
30
34
|
return {
|
|
31
35
|
cwd: this.cwd,
|
|
36
|
+
configPath: this.configPath,
|
|
32
37
|
packageJsonPath: this.packageJsonPath,
|
|
33
38
|
npmDir: this.npmDir,
|
|
34
39
|
dryRun: this.dryRun,
|
|
@@ -46,6 +51,10 @@ export interface CreateNpmDirsOptions {
|
|
|
46
51
|
* @default process.cwd()
|
|
47
52
|
*/
|
|
48
53
|
cwd?: string
|
|
54
|
+
/**
|
|
55
|
+
* Path to `napi` config json file
|
|
56
|
+
*/
|
|
57
|
+
configPath?: string
|
|
49
58
|
/**
|
|
50
59
|
* Path to `package.json`
|
|
51
60
|
*
|
package/src/def/new.ts
CHANGED
|
@@ -10,7 +10,7 @@ export abstract class BaseNewCommand extends Command {
|
|
|
10
10
|
description: 'Create a new project with pre-configured boilerplate',
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
$$path = Option.String({ required:
|
|
13
|
+
$$path = Option.String({ required: false })
|
|
14
14
|
|
|
15
15
|
$$name?: string = Option.String('--name,-n', {
|
|
16
16
|
description:
|
|
@@ -22,6 +22,10 @@ export abstract class BaseNewCommand extends Command {
|
|
|
22
22
|
description: 'The minimum Node-API version to support',
|
|
23
23
|
})
|
|
24
24
|
|
|
25
|
+
packageManager = Option.String('--package-manager', 'yarn', {
|
|
26
|
+
description: 'The package manager to use. Only support yarn 4.x for now.',
|
|
27
|
+
})
|
|
28
|
+
|
|
25
29
|
license = Option.String('--license,-l', 'MIT', {
|
|
26
30
|
description: 'License for open-sourced project',
|
|
27
31
|
})
|
|
@@ -47,6 +51,11 @@ export abstract class BaseNewCommand extends Command {
|
|
|
47
51
|
description: 'Whether generate preconfigured GitHub Actions workflow',
|
|
48
52
|
})
|
|
49
53
|
|
|
54
|
+
testFramework = Option.String('--test-framework', 'ava', {
|
|
55
|
+
description:
|
|
56
|
+
'The JavaScript test framework to use, only support `ava` for now',
|
|
57
|
+
})
|
|
58
|
+
|
|
50
59
|
dryRun = Option.Boolean('--dry-run', false, {
|
|
51
60
|
description: 'Whether to run the command in dry-run mode',
|
|
52
61
|
})
|
|
@@ -56,12 +65,14 @@ export abstract class BaseNewCommand extends Command {
|
|
|
56
65
|
path: this.$$path,
|
|
57
66
|
name: this.$$name,
|
|
58
67
|
minNodeApiVersion: this.minNodeApiVersion,
|
|
68
|
+
packageManager: this.packageManager,
|
|
59
69
|
license: this.license,
|
|
60
70
|
targets: this.targets,
|
|
61
71
|
enableDefaultTargets: this.enableDefaultTargets,
|
|
62
72
|
enableAllTargets: this.enableAllTargets,
|
|
63
73
|
enableTypeDef: this.enableTypeDef,
|
|
64
74
|
enableGithubActions: this.enableGithubActions,
|
|
75
|
+
testFramework: this.testFramework,
|
|
65
76
|
dryRun: this.dryRun,
|
|
66
77
|
}
|
|
67
78
|
}
|
|
@@ -72,9 +83,9 @@ export abstract class BaseNewCommand extends Command {
|
|
|
72
83
|
*/
|
|
73
84
|
export interface NewOptions {
|
|
74
85
|
/**
|
|
75
|
-
* The path where the
|
|
86
|
+
* The path where the NAPI-RS project will be created.
|
|
76
87
|
*/
|
|
77
|
-
path
|
|
88
|
+
path?: string
|
|
78
89
|
/**
|
|
79
90
|
* The name of the project, default to the name of the directory if not provided
|
|
80
91
|
*/
|
|
@@ -85,6 +96,12 @@ export interface NewOptions {
|
|
|
85
96
|
* @default 4
|
|
86
97
|
*/
|
|
87
98
|
minNodeApiVersion?: number
|
|
99
|
+
/**
|
|
100
|
+
* The package manager to use. Only support yarn 4.x for now.
|
|
101
|
+
*
|
|
102
|
+
* @default 'yarn'
|
|
103
|
+
*/
|
|
104
|
+
packageManager?: string
|
|
88
105
|
/**
|
|
89
106
|
* License for open-sourced project
|
|
90
107
|
*
|
|
@@ -121,6 +138,12 @@ export interface NewOptions {
|
|
|
121
138
|
* @default true
|
|
122
139
|
*/
|
|
123
140
|
enableGithubActions?: boolean
|
|
141
|
+
/**
|
|
142
|
+
* The JavaScript test framework to use, only support `ava` for now
|
|
143
|
+
*
|
|
144
|
+
* @default 'ava'
|
|
145
|
+
*/
|
|
146
|
+
testFramework?: string
|
|
124
147
|
/**
|
|
125
148
|
* Whether to run the command in dry-run mode
|
|
126
149
|
*
|
|
@@ -132,12 +155,14 @@ export interface NewOptions {
|
|
|
132
155
|
export function applyDefaultNewOptions(options: NewOptions) {
|
|
133
156
|
return {
|
|
134
157
|
minNodeApiVersion: 4,
|
|
158
|
+
packageManager: 'yarn',
|
|
135
159
|
license: 'MIT',
|
|
136
160
|
targets: [],
|
|
137
161
|
enableDefaultTargets: true,
|
|
138
162
|
enableAllTargets: false,
|
|
139
163
|
enableTypeDef: true,
|
|
140
164
|
enableGithubActions: true,
|
|
165
|
+
testFramework: 'ava',
|
|
141
166
|
dryRun: false,
|
|
142
167
|
...options,
|
|
143
168
|
}
|
package/src/def/pre-publish.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { Command, Option } from 'clipanion'
|
|
4
4
|
|
|
5
5
|
export abstract class BasePrePublishCommand extends Command {
|
|
6
|
-
static paths = [['pre-publish']]
|
|
6
|
+
static paths = [['pre-publish'], ['prepublish']]
|
|
7
7
|
|
|
8
8
|
static usage = Command.Usage({
|
|
9
9
|
description:
|
|
@@ -15,15 +15,19 @@ export abstract class BasePrePublishCommand extends Command {
|
|
|
15
15
|
'The working directory of where napi command will be executed in, all other paths options are relative to this path',
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
+
configPath?: string = Option.String('--config-path,-c', {
|
|
19
|
+
description: 'Path to `napi` config json file',
|
|
20
|
+
})
|
|
21
|
+
|
|
18
22
|
packageJsonPath = Option.String('--package-json-path', 'package.json', {
|
|
19
23
|
description: 'Path to `package.json`',
|
|
20
24
|
})
|
|
21
25
|
|
|
22
|
-
npmDir = Option.String('--npm-dir', 'npm', {
|
|
26
|
+
npmDir = Option.String('--npm-dir,-p', 'npm', {
|
|
23
27
|
description: 'Path to the folder where the npm packages put',
|
|
24
28
|
})
|
|
25
29
|
|
|
26
|
-
tagStyle = Option.String('--tag-style', 'lerna', {
|
|
30
|
+
tagStyle = Option.String('--tag-style,--tagstyle,-t', 'lerna', {
|
|
27
31
|
description: 'git tag style, `npm` or `lerna`',
|
|
28
32
|
})
|
|
29
33
|
|
|
@@ -46,6 +50,7 @@ export abstract class BasePrePublishCommand extends Command {
|
|
|
46
50
|
getOptions() {
|
|
47
51
|
return {
|
|
48
52
|
cwd: this.cwd,
|
|
53
|
+
configPath: this.configPath,
|
|
49
54
|
packageJsonPath: this.packageJsonPath,
|
|
50
55
|
npmDir: this.npmDir,
|
|
51
56
|
tagStyle: this.tagStyle,
|
|
@@ -67,6 +72,10 @@ export interface PrePublishOptions {
|
|
|
67
72
|
* @default process.cwd()
|
|
68
73
|
*/
|
|
69
74
|
cwd?: string
|
|
75
|
+
/**
|
|
76
|
+
* Path to `napi` config json file
|
|
77
|
+
*/
|
|
78
|
+
configPath?: string
|
|
70
79
|
/**
|
|
71
80
|
* Path to `package.json`
|
|
72
81
|
*
|