Skip to content

Commit 8f08209

Browse files
Blithe-Chiangjiangzs
and
jiangzs
authoredJan 22, 2025
fix: version update issue (#70)
Co-authored-by: jiangzs <2373806028@qq.com>
1 parent bf80c85 commit 8f08209

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed
 

‎src/fs.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function readJsoncFile(name: string, cwd: string): Promise<JsonFile
4242
export async function writeJsoncFile(file: JsonFile): Promise<void> {
4343
let newJSON = file.text
4444
for (const [key, value] of file.modified) {
45-
const edit = (jsonc.modify(file.text, key, value, {}))
45+
const edit = (jsonc.modify(newJSON, key, value, {}))
4646
newJSON = jsonc.applyEdits(newJSON, edit)
4747
}
4848

‎src/update-files.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export async function updateFiles(operation: Operation): Promise<Operation> {
3737
* @returns - `true` if the file was actually modified
3838
*/
3939
async function updateFile(relPath: string, operation: Operation): Promise<boolean> {
40-
if (!existsSync(relPath)) {
40+
if (!existsSync(path.join(operation.options.cwd, relPath))) {
4141
return false
4242
}
4343

‎test/update-files.test.ts

+46
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,49 @@ it('should skip to modify the manifest file if version field is not specified',
2929
const updatedPackageJSON = await readFile(join(cwd(), 'test', 'update-files', 'testdata', 'package.json'), 'utf8')
3030
expect(JSON.parse(updatedPackageJSON)).toMatchObject({})
3131
})
32+
33+
it('should update the manifest file correctly', async () => {
34+
await writeFile(join(cwd(), 'test', 'update-files', 'testdata', 'package-lock.json'), JSON.stringify(
35+
{
36+
"name": "example",
37+
"version": "1.0.43",
38+
"lockfileVersion": 2,
39+
"requires": true,
40+
"packages": {
41+
"": {
42+
"name": "example",
43+
"version": "1.0.43",
44+
"hasInstallScript": true,
45+
"dependencies": {}
46+
}
47+
}
48+
}, null, 2
49+
), 'utf8')
50+
51+
const operation = await Operation.start({
52+
cwd: join(cwd(), 'test', 'update-files', 'testdata'),
53+
currentVersion: '1.0.0',
54+
})
55+
56+
operation.update({
57+
newVersion: '2.0.0',
58+
})
59+
60+
await updateFiles(operation)
61+
const updatedPackageJSON = await readFile(join(cwd(), 'test', 'update-files', 'testdata', 'package-lock.json'), 'utf8')
62+
expect(JSON.parse(updatedPackageJSON)).toMatchObject({
63+
"name": "example",
64+
"version": "2.0.0",
65+
"lockfileVersion": 2,
66+
"requires": true,
67+
"packages": {
68+
"": {
69+
"name": "example",
70+
"version": "2.0.0",
71+
"hasInstallScript": true,
72+
"dependencies": {}
73+
}
74+
}
75+
})
76+
})
77+

0 commit comments

Comments
 (0)
Please sign in to comment.