Skip to content

Commit

Permalink
feat: version update in package-lock.json (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sec-ant committed Jan 22, 2024
1 parent 6ec68b4 commit ba39e94
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ export interface Manifest {
[key: string]: unknown
}

/**
* The npm package lock manifest (package-lock.json)
*/
export interface PackageLockManifest extends Manifest {
packages: {
'': {
version: string
}
}
}

/**
* Determines whether the specified value is a package manifest.
*/
Expand All @@ -19,6 +30,18 @@ export function isManifest(obj: any): obj is Manifest {
&& isOptionalString(obj.description)
}

/**
* Determines whether the specified manifest is package-lock.json
*/
export function isPackageLockManifest(
manifest: Manifest
): manifest is PackageLockManifest {
return (
typeof (manifest as PackageLockManifest).packages?.['']?.version ===
'string'
)
}

/**
* Determines whether the specified value is a string, null, or undefined.
*/
Expand Down
5 changes: 4 additions & 1 deletion src/update-files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'node:path'
import { readJsonFile, readTextFile, writeJsonFile, writeTextFile } from './fs'
import { isManifest } from './manifest'
import { isManifest, isPackageLockManifest } from './manifest'
import type { Operation } from './operation'
import { ProgressEvent } from './types/version-bump-progress'

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

if (isManifest(file.data) && file.data.version !== newVersion) {
file.data.version = newVersion
if (isPackageLockManifest(file.data)) {
file.data.packages[''].version = newVersion
}
await writeJsonFile(file)
modified = true
}
Expand Down

0 comments on commit ba39e94

Please sign in to comment.