@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/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(path, JSON.stringify({ ...old, ...partial }, null, 2))
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
@@ -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