@napi-rs/cli 3.0.0-alpha.18 → 3.0.0-alpha.19
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/build.js +1 -1
- package/dist/api/build.js.map +1 -1
- package/dist/api/create-npm-dirs.js +2 -2
- package/dist/api/create-npm-dirs.js.map +1 -1
- package/dist/api/pre-publish.js +3 -3
- package/dist/api/pre-publish.js.map +1 -1
- package/dist/api/rename.js +8 -0
- package/dist/api/rename.js.map +1 -1
- package/dist/api/universalize.js +1 -1
- package/dist/api/universalize.js.map +1 -1
- package/dist/api/version.js +1 -1
- package/dist/api/version.js.map +1 -1
- package/dist/def/artifacts.d.ts +10 -0
- package/dist/def/artifacts.js +4 -0
- package/dist/def/artifacts.js.map +1 -1
- package/dist/def/build.d.ts +8 -2
- package/dist/def/build.js +6 -2
- 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 +2 -2
- package/dist/def/pre-publish.d.ts +10 -0
- package/dist/def/pre-publish.js +5 -1
- package/dist/def/pre-publish.js.map +1 -1
- package/dist/def/rename.d.ts +11 -1
- 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 +81 -19
- 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/config.d.ts +2 -3
- package/dist/utils/config.js +33 -3
- package/dist/utils/config.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 +2 -2
- package/src/api/build.ts +4 -1
- package/src/api/create-npm-dirs.ts +5 -2
- package/src/api/pre-publish.ts +6 -3
- package/src/api/rename.ts +9 -0
- package/src/api/universalize.ts +4 -1
- package/src/api/version.ts +4 -1
- package/src/def/artifacts.ts +9 -0
- package/src/def/build.ts +13 -4
- package/src/def/create-npm-dirs.ts +9 -0
- package/src/def/new.ts +1 -1
- package/src/def/pre-publish.ts +10 -1
- 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__/__snapshots__/config.spec.ts.md +97 -0
- package/src/utils/__tests__/__snapshots__/config.spec.ts.snap +0 -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/config.ts +43 -4
- package/src/utils/version.ts +10 -8
package/dist/utils/version.d.ts
CHANGED
package/dist/utils/version.js
CHANGED
|
@@ -8,19 +8,21 @@ export var NapiVersion;
|
|
|
8
8
|
NapiVersion[NapiVersion["Napi6"] = 6] = "Napi6";
|
|
9
9
|
NapiVersion[NapiVersion["Napi7"] = 7] = "Napi7";
|
|
10
10
|
NapiVersion[NapiVersion["Napi8"] = 8] = "Napi8";
|
|
11
|
+
NapiVersion[NapiVersion["Napi9"] = 9] = "Napi9";
|
|
11
12
|
})(NapiVersion || (NapiVersion = {}));
|
|
12
13
|
/// because node support new napi version in some minor version updates, so we might meet such situation:
|
|
13
14
|
/// `node v10.20.0` supports `napi5` and `napi6`, but `node v12.0.0` only support `napi4`,
|
|
14
|
-
/// by which, we can not tell directly napi version
|
|
15
|
+
/// by which, we can not tell directly napi version supportless from node version directly.
|
|
15
16
|
const NAPI_VERSION_MATRIX = new Map([
|
|
16
|
-
[NapiVersion.Napi1, '8.6.0'],
|
|
17
|
-
[NapiVersion.Napi2, '8.10.0 | 9.3.0'],
|
|
18
|
-
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0'],
|
|
19
|
-
[NapiVersion.Napi4, '10.16.0 | 11.8.0'],
|
|
20
|
-
[NapiVersion.Napi5, '10.17.0 | 12.11.0'],
|
|
17
|
+
[NapiVersion.Napi1, '8.6.0 | 9.0.0 | 10.0.0'],
|
|
18
|
+
[NapiVersion.Napi2, '8.10.0 | 9.3.0 | 10.0.0'],
|
|
19
|
+
[NapiVersion.Napi3, '6.14.2 | 8.11.2 | 9.11.0 | 10.0.0'],
|
|
20
|
+
[NapiVersion.Napi4, '10.16.0 | 11.8.0 | 12.0.0'],
|
|
21
|
+
[NapiVersion.Napi5, '10.17.0 | 12.11.0 | 13.0.0'],
|
|
21
22
|
[NapiVersion.Napi6, '10.20.0 | 12.17.0 | 14.0.0'],
|
|
22
|
-
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0'],
|
|
23
|
-
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0'],
|
|
23
|
+
[NapiVersion.Napi7, '10.23.0 | 12.19.0 | 14.12.0 | 15.0.0'],
|
|
24
|
+
[NapiVersion.Napi8, '12.22.0 | 14.17.0 | 15.12.0 | 16.0.0'],
|
|
25
|
+
[NapiVersion.Napi9, '18.17.0 | 20.3.0 | 21.1.0'],
|
|
24
26
|
]);
|
|
25
27
|
function parseNodeVersion(v) {
|
|
26
28
|
const matches = v.match(/v?([0-9]+)\.([0-9]+)\.([0-9]+)/i);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/utils/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,WAUX;AAVD,WAAY,WAAW;IACrB,+CAAS,CAAA;IACT,+CAAK,C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napi-rs",
|
|
5
5
|
"author": "LongYinan <lynweklm@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/napi-rs/napi-rs",
|
|
@@ -129,5 +129,5 @@
|
|
|
129
129
|
"**/__tests__/**/*.spec.ts"
|
|
130
130
|
]
|
|
131
131
|
},
|
|
132
|
-
"gitHead": "
|
|
132
|
+
"gitHead": "3423557cb59f548e8d4a201ce48d28b04c3fcbbf"
|
|
133
133
|
}
|
package/src/api/build.ts
CHANGED
|
@@ -90,7 +90,10 @@ export async function buildProject(options: BuildOptions) {
|
|
|
90
90
|
process.env.CARGO_BUILD_TARGET_DIR ??
|
|
91
91
|
metadata.target_directory,
|
|
92
92
|
await readNapiConfig(
|
|
93
|
-
resolvePath(
|
|
93
|
+
resolvePath(
|
|
94
|
+
options.configPath ?? options.packageJsonPath ?? 'package.json',
|
|
95
|
+
),
|
|
96
|
+
options.configPath ? resolvePath(options.configPath) : undefined,
|
|
94
97
|
),
|
|
95
98
|
)
|
|
96
99
|
|
|
@@ -43,10 +43,13 @@ export async function createNpmDirs(userOptions: CreateNpmDirsOptions) {
|
|
|
43
43
|
const packageJsonPath = resolve(options.cwd, options.packageJsonPath)
|
|
44
44
|
const npmPath = resolve(options.cwd, options.npmDir)
|
|
45
45
|
|
|
46
|
-
debug(`Read content from [${packageJsonPath}]`)
|
|
46
|
+
debug(`Read content from [${options.configPath ?? packageJsonPath}]`)
|
|
47
47
|
|
|
48
48
|
const { targets, binaryName, packageName, packageJson } =
|
|
49
|
-
await readNapiConfig(
|
|
49
|
+
await readNapiConfig(
|
|
50
|
+
packageJsonPath,
|
|
51
|
+
options.configPath ? resolve(options.cwd, options.configPath) : undefined,
|
|
52
|
+
)
|
|
50
53
|
|
|
51
54
|
for (const target of targets) {
|
|
52
55
|
const targetDir = join(npmPath, `${target.platformArchABI}`)
|
package/src/api/pre-publish.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execSync } from 'child_process'
|
|
2
2
|
import { existsSync, statSync } from 'fs'
|
|
3
|
-
import { join,
|
|
3
|
+
import { join, resolve } from '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) {
|
package/src/api/rename.ts
CHANGED
|
@@ -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),
|
package/src/api/universalize.ts
CHANGED
|
@@ -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',
|
package/src/api/version.ts
CHANGED
|
@@ -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)
|
package/src/def/artifacts.ts
CHANGED
|
@@ -15,6 +15,10 @@ 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
|
})
|
|
@@ -31,6 +35,7 @@ export abstract class BaseArtifactsCommand extends Command {
|
|
|
31
35
|
getOptions() {
|
|
32
36
|
return {
|
|
33
37
|
cwd: this.cwd,
|
|
38
|
+
configPath: this.configPath,
|
|
34
39
|
packageJsonPath: this.packageJsonPath,
|
|
35
40
|
outputDir: this.outputDir,
|
|
36
41
|
npmDir: this.npmDir,
|
|
@@ -48,6 +53,10 @@ export interface ArtifactsOptions {
|
|
|
48
53
|
* @default process.cwd()
|
|
49
54
|
*/
|
|
50
55
|
cwd?: string
|
|
56
|
+
/**
|
|
57
|
+
* Path to `napi` config json file
|
|
58
|
+
*/
|
|
59
|
+
configPath?: string
|
|
51
60
|
/**
|
|
52
61
|
* Path to `package.json`
|
|
53
62
|
*
|
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
|
})
|
|
@@ -117,7 +121,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
117
121
|
|
|
118
122
|
watch?: boolean = Option.Boolean('--watch,-w', {
|
|
119
123
|
description:
|
|
120
|
-
'watch the crate changes and build
|
|
124
|
+
'watch the crate changes and build continuously with `cargo-watch` crates',
|
|
121
125
|
})
|
|
122
126
|
|
|
123
127
|
features?: string[] = Option.Array('--features,-F', {
|
|
@@ -137,6 +141,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
137
141
|
target: this.target,
|
|
138
142
|
cwd: this.cwd,
|
|
139
143
|
manifestPath: this.manifestPath,
|
|
144
|
+
configPath: this.configPath,
|
|
140
145
|
packageJsonPath: this.packageJsonPath,
|
|
141
146
|
targetDir: this.targetDir,
|
|
142
147
|
outputDir: this.outputDir,
|
|
@@ -166,7 +171,7 @@ export abstract class BaseBuildCommand extends Command {
|
|
|
166
171
|
}
|
|
167
172
|
|
|
168
173
|
/**
|
|
169
|
-
* Build the
|
|
174
|
+
* Build the NAPI-RS project
|
|
170
175
|
*/
|
|
171
176
|
export interface BuildOptions {
|
|
172
177
|
/**
|
|
@@ -181,6 +186,10 @@ export interface BuildOptions {
|
|
|
181
186
|
* Path to `Cargo.toml`
|
|
182
187
|
*/
|
|
183
188
|
manifestPath?: string
|
|
189
|
+
/**
|
|
190
|
+
* Path to `napi` config json file
|
|
191
|
+
*/
|
|
192
|
+
configPath?: string
|
|
184
193
|
/**
|
|
185
194
|
* Path to `package.json`
|
|
186
195
|
*/
|
|
@@ -262,7 +271,7 @@ export interface BuildOptions {
|
|
|
262
271
|
*/
|
|
263
272
|
useNapiCross?: boolean
|
|
264
273
|
/**
|
|
265
|
-
* watch the crate changes and build
|
|
274
|
+
* watch the crate changes and build continuously with `cargo-watch` crates
|
|
266
275
|
*/
|
|
267
276
|
watch?: boolean
|
|
268
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
package/src/def/pre-publish.ts
CHANGED
|
@@ -15,6 +15,10 @@ 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
|
})
|
|
@@ -23,7 +27,7 @@ export abstract class BasePrePublishCommand extends Command {
|
|
|
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,-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
|
*
|
package/src/def/rename.ts
CHANGED
|
@@ -6,7 +6,7 @@ export abstract class BaseRenameCommand extends Command {
|
|
|
6
6
|
static paths = [['rename']]
|
|
7
7
|
|
|
8
8
|
static usage = Command.Usage({
|
|
9
|
-
description: 'Rename the
|
|
9
|
+
description: 'Rename the NAPI-RS project',
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
cwd = Option.String('--cwd', process.cwd(), {
|
|
@@ -14,6 +14,10 @@ export abstract class BaseRenameCommand 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
|
})
|
|
@@ -49,6 +53,7 @@ export abstract class BaseRenameCommand extends Command {
|
|
|
49
53
|
getOptions() {
|
|
50
54
|
return {
|
|
51
55
|
cwd: this.cwd,
|
|
56
|
+
configPath: this.configPath,
|
|
52
57
|
packageJsonPath: this.packageJsonPath,
|
|
53
58
|
npmDir: this.npmDir,
|
|
54
59
|
name: this.$$name,
|
|
@@ -62,7 +67,7 @@ export abstract class BaseRenameCommand extends Command {
|
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
|
-
* Rename the
|
|
70
|
+
* Rename the NAPI-RS project
|
|
66
71
|
*/
|
|
67
72
|
export interface RenameOptions {
|
|
68
73
|
/**
|
|
@@ -71,6 +76,10 @@ export interface RenameOptions {
|
|
|
71
76
|
* @default process.cwd()
|
|
72
77
|
*/
|
|
73
78
|
cwd?: string
|
|
79
|
+
/**
|
|
80
|
+
* Path to `napi` config json file
|
|
81
|
+
*/
|
|
82
|
+
configPath?: string
|
|
74
83
|
/**
|
|
75
84
|
* Path to `package.json`
|
|
76
85
|
*
|
package/src/def/universalize.ts
CHANGED
|
@@ -14,6 +14,10 @@ export abstract class BaseUniversalizeCommand 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
|
})
|
|
@@ -26,6 +30,7 @@ export abstract class BaseUniversalizeCommand extends Command {
|
|
|
26
30
|
getOptions() {
|
|
27
31
|
return {
|
|
28
32
|
cwd: this.cwd,
|
|
33
|
+
configPath: this.configPath,
|
|
29
34
|
packageJsonPath: this.packageJsonPath,
|
|
30
35
|
outputDir: this.outputDir,
|
|
31
36
|
}
|
|
@@ -42,6 +47,10 @@ export interface UniversalizeOptions {
|
|
|
42
47
|
* @default process.cwd()
|
|
43
48
|
*/
|
|
44
49
|
cwd?: string
|
|
50
|
+
/**
|
|
51
|
+
* Path to `napi` config json file
|
|
52
|
+
*/
|
|
53
|
+
configPath?: string
|
|
45
54
|
/**
|
|
46
55
|
* Path to `package.json`
|
|
47
56
|
*
|
package/src/def/version.ts
CHANGED
|
@@ -14,6 +14,10 @@ export abstract class BaseVersionCommand 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
|
})
|
|
@@ -25,6 +29,7 @@ export abstract class BaseVersionCommand extends Command {
|
|
|
25
29
|
getOptions() {
|
|
26
30
|
return {
|
|
27
31
|
cwd: this.cwd,
|
|
32
|
+
configPath: this.configPath,
|
|
28
33
|
packageJsonPath: this.packageJsonPath,
|
|
29
34
|
npmDir: this.npmDir,
|
|
30
35
|
}
|
|
@@ -41,6 +46,10 @@ export interface VersionOptions {
|
|
|
41
46
|
* @default process.cwd()
|
|
42
47
|
*/
|
|
43
48
|
cwd?: string
|
|
49
|
+
/**
|
|
50
|
+
* Path to `napi` config json file
|
|
51
|
+
*/
|
|
52
|
+
configPath?: string
|
|
44
53
|
/**
|
|
45
54
|
* Path to `package.json`
|
|
46
55
|
*
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Snapshot report for `src/utils/__tests__/config.spec.ts`
|
|
2
|
+
|
|
3
|
+
The actual snapshot is saved in `config.spec.ts.snap`.
|
|
4
|
+
|
|
5
|
+
Generated by [AVA](https://avajs.dev).
|
|
6
|
+
|
|
7
|
+
## should be able to read config from package.json
|
|
8
|
+
|
|
9
|
+
> Snapshot 1
|
|
10
|
+
|
|
11
|
+
{
|
|
12
|
+
binaryName: 'testing',
|
|
13
|
+
npmClient: 'npm',
|
|
14
|
+
packageJson: {
|
|
15
|
+
name: '@napi-rs/testing',
|
|
16
|
+
napi: {
|
|
17
|
+
binaryName: 'testing',
|
|
18
|
+
packageName: '@napi-rs/testing',
|
|
19
|
+
targets: [
|
|
20
|
+
'x86_64-unknown-linux-gnu',
|
|
21
|
+
'x86_64-pc-windows-msvc',
|
|
22
|
+
'x86_64-apple-darwin',
|
|
23
|
+
],
|
|
24
|
+
},
|
|
25
|
+
version: '0.0.0',
|
|
26
|
+
},
|
|
27
|
+
packageName: '@napi-rs/testing',
|
|
28
|
+
targets: [
|
|
29
|
+
{
|
|
30
|
+
abi: 'gnu',
|
|
31
|
+
arch: 'x64',
|
|
32
|
+
platform: 'linux',
|
|
33
|
+
platformArchABI: 'linux-x64-gnu',
|
|
34
|
+
triple: 'x86_64-unknown-linux-gnu',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
abi: 'msvc',
|
|
38
|
+
arch: 'x64',
|
|
39
|
+
platform: 'win32',
|
|
40
|
+
platformArchABI: 'win32-x64-msvc',
|
|
41
|
+
triple: 'x86_64-pc-windows-msvc',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
abi: null,
|
|
45
|
+
arch: 'x64',
|
|
46
|
+
platform: 'darwin',
|
|
47
|
+
platformArchABI: 'darwin-x64',
|
|
48
|
+
triple: 'x86_64-apple-darwin',
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
## should be able to read config from napi.json
|
|
54
|
+
|
|
55
|
+
> Snapshot 1
|
|
56
|
+
|
|
57
|
+
{
|
|
58
|
+
binaryName: 'testing',
|
|
59
|
+
npmClient: 'npm',
|
|
60
|
+
packageJson: {
|
|
61
|
+
name: '@napi-rs/testing',
|
|
62
|
+
napi: {
|
|
63
|
+
binaryName: 'testing',
|
|
64
|
+
packageName: '@node-rs/testing',
|
|
65
|
+
targets: [
|
|
66
|
+
'x86_64-unknown-linux-gnu',
|
|
67
|
+
'x86_64-apple-darwin',
|
|
68
|
+
'aarch64-apple-darwin',
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
version: '0.0.0',
|
|
72
|
+
},
|
|
73
|
+
packageName: '@node-rs/testing',
|
|
74
|
+
targets: [
|
|
75
|
+
{
|
|
76
|
+
abi: 'gnu',
|
|
77
|
+
arch: 'x64',
|
|
78
|
+
platform: 'linux',
|
|
79
|
+
platformArchABI: 'linux-x64-gnu',
|
|
80
|
+
triple: 'x86_64-unknown-linux-gnu',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
abi: null,
|
|
84
|
+
arch: 'x64',
|
|
85
|
+
platform: 'darwin',
|
|
86
|
+
platformArchABI: 'darwin-x64',
|
|
87
|
+
triple: 'x86_64-apple-darwin',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
abi: null,
|
|
91
|
+
arch: 'arm64',
|
|
92
|
+
platform: 'darwin',
|
|
93
|
+
platformArchABI: 'darwin-arm64',
|
|
94
|
+
triple: 'aarch64-apple-darwin',
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -9,12 +9,13 @@ Generated by [AVA](https://avajs.dev).
|
|
|
9
9
|
> Snapshot 1
|
|
10
10
|
|
|
11
11
|
[
|
|
12
|
-
'>= 8.6.0',
|
|
13
|
-
'>= 8.10.0 < 9 || >= 9.3.0',
|
|
14
|
-
'>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0',
|
|
15
|
-
'>= 10.16.0 < 11 || >= 11.8.0',
|
|
16
|
-
'>= 10.17.0 < 11 || >= 12.11.0',
|
|
12
|
+
'>= 8.6.0 < 9 || >= 9.0.0 < 10 || >= 10.0.0',
|
|
13
|
+
'>= 8.10.0 < 9 || >= 9.3.0 < 10 || >= 10.0.0',
|
|
14
|
+
'>= 6.14.2 < 7 || >= 8.11.2 < 9 || >= 9.11.0 < 10 || >= 10.0.0',
|
|
15
|
+
'>= 10.16.0 < 11 || >= 11.8.0 < 12 || >= 12.0.0',
|
|
16
|
+
'>= 10.17.0 < 11 || >= 12.11.0 < 13 || >= 13.0.0',
|
|
17
17
|
'>= 10.20.0 < 11 || >= 12.17.0 < 13 || >= 14.0.0',
|
|
18
|
-
'>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0',
|
|
19
|
-
'>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0',
|
|
18
|
+
'>= 10.23.0 < 11 || >= 12.19.0 < 13 || >= 14.12.0 < 15 || >= 15.0.0',
|
|
19
|
+
'>= 12.22.0 < 13 || >= 14.17.0 < 15 || >= 15.12.0 < 16 || >= 16.0.0',
|
|
20
|
+
'>= 18.17.0 < 19 || >= 20.3.0 < 21 || >= 21.1.0',
|
|
20
21
|
]
|
|
Binary file
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { unlink, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { tmpdir } from 'node:os'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
|
|
5
|
+
import ava, { TestFn } from 'ava'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
CommonPackageJsonFields,
|
|
9
|
+
UserNapiConfig,
|
|
10
|
+
readNapiConfig,
|
|
11
|
+
} from '../config.js'
|
|
12
|
+
|
|
13
|
+
const NON_EXISTENT_FILE = 'non-existent-file'
|
|
14
|
+
|
|
15
|
+
const test = ava as TestFn<{
|
|
16
|
+
configPath: string
|
|
17
|
+
packageJson: string
|
|
18
|
+
pkgJson: CommonPackageJsonFields
|
|
19
|
+
config: UserNapiConfig
|
|
20
|
+
}>
|
|
21
|
+
|
|
22
|
+
test.before(async (t) => {
|
|
23
|
+
const tmp = tmpdir()
|
|
24
|
+
const configPath = join(tmp, 'napi.json')
|
|
25
|
+
const packageJson = join(tmp, 'package.json')
|
|
26
|
+
const pkgJson = {
|
|
27
|
+
name: '@napi-rs/testing',
|
|
28
|
+
version: '0.0.0',
|
|
29
|
+
napi: {
|
|
30
|
+
binaryName: 'testing',
|
|
31
|
+
packageName: '@napi-rs/testing',
|
|
32
|
+
targets: [
|
|
33
|
+
'x86_64-unknown-linux-gnu',
|
|
34
|
+
'x86_64-pc-windows-msvc',
|
|
35
|
+
'x86_64-apple-darwin',
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
await writeFile(packageJson, JSON.stringify(pkgJson, null, 2))
|
|
40
|
+
const config = {
|
|
41
|
+
binaryName: 'testing',
|
|
42
|
+
packageName: '@node-rs/testing',
|
|
43
|
+
targets: [
|
|
44
|
+
'x86_64-unknown-linux-gnu',
|
|
45
|
+
'x86_64-apple-darwin',
|
|
46
|
+
'aarch64-apple-darwin',
|
|
47
|
+
],
|
|
48
|
+
}
|
|
49
|
+
await writeFile(configPath, JSON.stringify(config, null, 2))
|
|
50
|
+
t.context = { configPath, config, packageJson, pkgJson }
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
test.after(async (t) => {
|
|
54
|
+
await unlink(t.context.configPath)
|
|
55
|
+
await unlink(t.context.packageJson)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('should throw if package.json not found', async (t) => {
|
|
59
|
+
await t.throwsAsync(() => readNapiConfig(NON_EXISTENT_FILE), {
|
|
60
|
+
message: `package.json not found at ${NON_EXISTENT_FILE}`,
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test('should throw if napi.json not found', async (t) => {
|
|
65
|
+
const { packageJson } = t.context
|
|
66
|
+
await t.throwsAsync(() => readNapiConfig(packageJson, NON_EXISTENT_FILE), {
|
|
67
|
+
message: `NAPI-RS config not found at ${NON_EXISTENT_FILE}`,
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
test('should be able to read config from package.json', async (t) => {
|
|
72
|
+
const { packageJson } = t.context
|
|
73
|
+
const config = await readNapiConfig(packageJson)
|
|
74
|
+
t.snapshot(config)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('should be able to read config from napi.json', async (t) => {
|
|
78
|
+
const { packageJson, configPath } = t.context
|
|
79
|
+
const config = await readNapiConfig(packageJson, configPath)
|
|
80
|
+
t.snapshot(config)
|
|
81
|
+
})
|