Skip to content

Commit ba39e94

Browse files
authoredJan 22, 2024
feat: version update in package-lock.json (#26)
1 parent 6ec68b4 commit ba39e94

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed
 

‎src/manifest.ts

+23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ export interface Manifest {
88
[key: string]: unknown
99
}
1010

11+
/**
12+
* The npm package lock manifest (package-lock.json)
13+
*/
14+
export interface PackageLockManifest extends Manifest {
15+
packages: {
16+
'': {
17+
version: string
18+
}
19+
}
20+
}
21+
1122
/**
1223
* Determines whether the specified value is a package manifest.
1324
*/
@@ -19,6 +30,18 @@ export function isManifest(obj: any): obj is Manifest {
1930
&& isOptionalString(obj.description)
2031
}
2132

33+
/**
34+
* Determines whether the specified manifest is package-lock.json
35+
*/
36+
export function isPackageLockManifest(
37+
manifest: Manifest
38+
): manifest is PackageLockManifest {
39+
return (
40+
typeof (manifest as PackageLockManifest).packages?.['']?.version ===
41+
'string'
42+
)
43+
}
44+
2245
/**
2346
* Determines whether the specified value is a string, null, or undefined.
2447
*/

‎src/update-files.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'node:path'
22
import { readJsonFile, readTextFile, writeJsonFile, writeTextFile } from './fs'
3-
import { isManifest } from './manifest'
3+
import { isManifest, isPackageLockManifest } from './manifest'
44
import type { Operation } from './operation'
55
import { ProgressEvent } from './types/version-bump-progress'
66

@@ -67,6 +67,9 @@ async function updateManifestFile(relPath: string, operation: Operation): Promis
6767

6868
if (isManifest(file.data) && file.data.version !== newVersion) {
6969
file.data.version = newVersion
70+
if (isPackageLockManifest(file.data)) {
71+
file.data.packages[''].version = newVersion
72+
}
7073
await writeJsonFile(file)
7174
modified = true
7275
}

0 commit comments

Comments
 (0)
Please sign in to comment.