Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: version update in package-lock.json #26

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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