Skip to content

Commit

Permalink
fix: do no mutate __metadata
Browse files Browse the repository at this point in the history
closes #287
  • Loading branch information
antongolub committed Mar 21, 2023
1 parent 6c50652 commit 97c5706
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main/ts/lockfile/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import {
TLockfileEntry,
TLockfileObject,
} from '../ifaces'
import { formatFlags, formatYaml, invoke, mapFlags, parseYaml } from '../util'
import {addHiddenProp, formatFlags, formatYaml, invoke, mapFlags, parseYaml} from '../util'

export const parse = (raw: string): TLockfileObject => {
const data = parseYaml(raw)
const {__metadata} = data
delete data.__metadata

return Object.entries(data).reduce<Record<string, any>>(
Expand All @@ -17,7 +18,7 @@ export const parse = (raw: string): TLockfileObject => {
})
return m
},
{},
addHiddenProp({}, '__metadata', __metadata),
)
}

Expand Down Expand Up @@ -66,7 +67,7 @@ export const format = (lockfile: TLockfileObject): string => {
return m
},
{
__metadata: {
__metadata: lockfile.__metadata || {
version: 5,
cacheKey: 8,
},
Expand Down
6 changes: 6 additions & 0 deletions src/main/ts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,9 @@ export const getBinVersion = (bin: string, cwd = process.cwd()): string =>
export const getSelfManifest = () => readJson(
join(pkgDir(__dirname) + '', 'package.json'), // eslint-disable-line
)

export const addHiddenProp = (obj: Record<string, any>, prop: string, value: any) =>
Object.defineProperty(obj, prop, {
value,
enumerable: false
})

0 comments on commit 97c5706

Please sign in to comment.