@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/src/utils/config.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { underline, yellow } from 'colorette'
|
|
1
2
|
import { merge, omit } from 'lodash-es'
|
|
2
3
|
|
|
3
4
|
import { fileExists, readFileAsync } from './misc.js'
|
|
4
5
|
import { DEFAULT_TARGETS, parseTriple, Target } from './target.js'
|
|
5
6
|
|
|
6
|
-
interface UserNapiConfig {
|
|
7
|
+
export interface UserNapiConfig {
|
|
7
8
|
/**
|
|
8
9
|
* Name of the binary to be generated, default to `index`
|
|
9
10
|
*/
|
|
@@ -89,9 +90,15 @@ export type NapiConfig = Required<
|
|
|
89
90
|
packageJson: CommonPackageJsonFields
|
|
90
91
|
}
|
|
91
92
|
|
|
92
|
-
export async function readNapiConfig(
|
|
93
|
+
export async function readNapiConfig(
|
|
94
|
+
path: string,
|
|
95
|
+
configPath?: string,
|
|
96
|
+
): Promise<NapiConfig> {
|
|
97
|
+
if (configPath && !(await fileExists(configPath))) {
|
|
98
|
+
throw new Error(`NAPI-RS config not found at ${configPath}`)
|
|
99
|
+
}
|
|
93
100
|
if (!(await fileExists(path))) {
|
|
94
|
-
throw new Error(`
|
|
101
|
+
throw new Error(`package.json not found at ${path}`)
|
|
95
102
|
}
|
|
96
103
|
// May support multiple config sources later on.
|
|
97
104
|
const content = await readFileAsync(path, 'utf8')
|
|
@@ -99,12 +106,34 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
99
106
|
try {
|
|
100
107
|
pkgJson = JSON.parse(content) as CommonPackageJsonFields
|
|
101
108
|
} catch (e) {
|
|
102
|
-
throw new Error(
|
|
109
|
+
throw new Error(`Failed to parse package.json at ${path}`, {
|
|
103
110
|
cause: e,
|
|
104
111
|
})
|
|
105
112
|
}
|
|
106
113
|
|
|
114
|
+
let separatedConfig: UserNapiConfig | undefined
|
|
115
|
+
if (configPath) {
|
|
116
|
+
const configContent = await readFileAsync(configPath, 'utf8')
|
|
117
|
+
try {
|
|
118
|
+
separatedConfig = JSON.parse(configContent) as UserNapiConfig
|
|
119
|
+
} catch (e) {
|
|
120
|
+
throw new Error(`Failed to parse NAPI-RS config at ${configPath}`, {
|
|
121
|
+
cause: e,
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
const userNapiConfig = pkgJson.napi ?? {}
|
|
127
|
+
if (pkgJson.napi && separatedConfig) {
|
|
128
|
+
const pkgJsonPath = underline(path)
|
|
129
|
+
const configPathUnderline = underline(configPath!)
|
|
130
|
+
console.warn(
|
|
131
|
+
yellow(
|
|
132
|
+
`Both napi field in ${pkgJsonPath} and [NAPI-RS config](${configPathUnderline}) file are found, the NAPI-RS config file will be used.`,
|
|
133
|
+
),
|
|
134
|
+
)
|
|
135
|
+
Object.assign(userNapiConfig, separatedConfig)
|
|
136
|
+
}
|
|
108
137
|
const napiConfig: NapiConfig = merge(
|
|
109
138
|
{
|
|
110
139
|
binaryName: 'index',
|
|
@@ -120,16 +149,26 @@ export async function readNapiConfig(path: string): Promise<NapiConfig> {
|
|
|
120
149
|
|
|
121
150
|
// compatible with old config
|
|
122
151
|
if (userNapiConfig?.name) {
|
|
152
|
+
console.warn(
|
|
153
|
+
`[DEPRECATED] napi.name is deprecated, use napi.binaryName instead.`,
|
|
154
|
+
)
|
|
123
155
|
napiConfig.binaryName = userNapiConfig.name
|
|
124
156
|
}
|
|
125
157
|
|
|
126
158
|
if (!targets.length) {
|
|
159
|
+
let deprecatedWarned = false
|
|
160
|
+
const warning = `[DEPRECATED] napi.triples is deprecated, use napi.targets instead.`
|
|
127
161
|
if (userNapiConfig.triples?.defaults) {
|
|
162
|
+
deprecatedWarned = true
|
|
163
|
+
console.warn(warning)
|
|
128
164
|
targets = targets.concat(DEFAULT_TARGETS)
|
|
129
165
|
}
|
|
130
166
|
|
|
131
167
|
if (userNapiConfig.triples?.additional?.length) {
|
|
132
168
|
targets = targets.concat(userNapiConfig.triples.additional)
|
|
169
|
+
if (!deprecatedWarned) {
|
|
170
|
+
console.warn(warning)
|
|
171
|
+
}
|
|
133
172
|
}
|
|
134
173
|
}
|
|
135
174
|
|
package/src/utils/version.ts
CHANGED
|
@@ -7,20 +7,22 @@ export enum NapiVersion {
|
|
|
7
7
|
Napi6,
|
|
8
8
|
Napi7,
|
|
9
9
|
Napi8,
|
|
10
|
+
Napi9,
|
|
10
11
|
}
|
|
11
12
|
|
|
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<NapiVersion, string>([
|
|
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
|
|
|
26
28
|
interface NodeVersion {
|