Skip to content

Commit 24c49a5

Browse files
authored
feat: ignore manifest files without version property (#49)
1 parent 5d4591b commit 24c49a5

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/update-files.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ async function updateManifestFile(relPath: string, operation: Operation): Promis
7474

7575
const file = await readJsoncFile(relPath, cwd)
7676

77-
if (isManifest(file.data) && file.data.version !== newVersion) {
77+
if (!isManifest(file.data)) {
78+
return modified
79+
}
80+
if (file.data.version == null) {
81+
return modified
82+
}
83+
if (file.data.version !== newVersion) {
7884
file.modified.push([['version'], newVersion])
7985
if (isPackageLockManifest(file.data))
8086
file.modified.push([['packages', '', 'version'], newVersion])

test/update-files.test.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { mkdir, readFile, rmdir, writeFile } from 'node:fs/promises'
2+
import { join } from 'node:path'
3+
import { cwd } from 'node:process'
4+
import { afterEach, beforeEach, expect, it } from 'vitest'
5+
import { Operation } from '../src/operation'
6+
import { updateFiles } from '../src/update-files'
7+
8+
beforeEach(async () => {
9+
mkdir(join(cwd(), 'test', 'update-files', 'testdata'), { recursive: true }).catch(() => { })
10+
})
11+
12+
afterEach(async () => {
13+
rmdir(join(cwd(), 'test', 'update-files', 'testdata'), { recursive: true }).catch(() => { })
14+
})
15+
16+
it('should skip to modify the manifest file if version field is not specified', async () => {
17+
await writeFile(join(cwd(), 'test', 'update-files', 'testdata', 'package.json'), JSON.stringify({}), 'utf8')
18+
19+
const operation = await Operation.start({
20+
cwd: join(cwd(), 'test', 'update-files', 'testdata'),
21+
currentVersion: '1.0.0',
22+
})
23+
24+
operation.update({
25+
newVersion: '2.0.0',
26+
})
27+
28+
await updateFiles(operation)
29+
const updatedPackageJSON = await readFile(join(cwd(), 'test', 'update-files', 'testdata', 'package.json'), 'utf8')
30+
expect(JSON.parse(updatedPackageJSON)).toMatchObject({})
31+
})

0 commit comments

Comments
 (0)