@napi-rs/cli 3.6.0 → 3.6.2
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 +187 -116
- package/dist/index.cjs +186 -115
- package/dist/index.d.cts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +187 -116
- package/package.json +3 -3
- package/src/api/build.ts +23 -45
- package/src/api/create-npm-dirs.ts +123 -22
- package/src/api/new.ts +83 -33
- package/src/api/pre-publish.ts +1 -0
- package/src/api/rename.ts +23 -3
- package/src/api/universalize.ts +2 -2
- package/src/commands/build.ts +1 -0
- package/src/commands/new.ts +12 -5
- package/src/utils/metadata.ts +5 -1
- package/src/utils/misc.ts +25 -1
- package/src/utils/version.ts +4 -0
package/src/utils/misc.ts
CHANGED
|
@@ -43,6 +43,27 @@ export function pick<O, K extends keyof O>(o: O, ...keys: K[]): Pick<O, K> {
|
|
|
43
43
|
}, {} as O)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
function isPlainObject(value: unknown): value is Record<string, any> {
|
|
47
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function mergePackageJson(
|
|
51
|
+
old: Record<string, any>,
|
|
52
|
+
partial: Record<string, any>,
|
|
53
|
+
): Record<string, any> {
|
|
54
|
+
const merged = { ...old }
|
|
55
|
+
|
|
56
|
+
for (const [key, value] of Object.entries(partial)) {
|
|
57
|
+
if (isPlainObject(merged[key]) && isPlainObject(value)) {
|
|
58
|
+
merged[key] = mergePackageJson(merged[key], value)
|
|
59
|
+
} else {
|
|
60
|
+
merged[key] = value
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return merged
|
|
65
|
+
}
|
|
66
|
+
|
|
46
67
|
export async function updatePackageJson(
|
|
47
68
|
path: string,
|
|
48
69
|
partial: Record<string, any>,
|
|
@@ -53,7 +74,10 @@ export async function updatePackageJson(
|
|
|
53
74
|
return
|
|
54
75
|
}
|
|
55
76
|
const old = JSON.parse(await readFileAsync(path, 'utf8'))
|
|
56
|
-
await writeFileAsync(
|
|
77
|
+
await writeFileAsync(
|
|
78
|
+
path,
|
|
79
|
+
JSON.stringify(mergePackageJson(old, partial), null, 2),
|
|
80
|
+
)
|
|
57
81
|
}
|
|
58
82
|
|
|
59
83
|
export const CLI_VERSION = pkgJson.version
|
package/src/utils/version.ts
CHANGED
|
@@ -25,6 +25,10 @@ const NAPI_VERSION_MATRIX = new Map<NapiVersion, string>([
|
|
|
25
25
|
[NapiVersion.Napi9, '18.17.0 | 20.3.0 | 21.1.0'],
|
|
26
26
|
])
|
|
27
27
|
|
|
28
|
+
export const SUPPORTED_NAPI_VERSIONS = Object.values(NapiVersion).filter(
|
|
29
|
+
(v): v is NapiVersion => typeof v === 'number',
|
|
30
|
+
)
|
|
31
|
+
|
|
28
32
|
interface NodeVersion {
|
|
29
33
|
major: number
|
|
30
34
|
minor: number
|