Skip to content

Commit de7f2be

Browse files
Renamed the name variable to relPath to be more clear
1 parent 4c4c353 commit de7f2be

1 file changed

Lines changed: 25 additions & 28 deletions

File tree

src/update-files.ts

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { ProgressEvent } from "./version-bump-progress";
1010
export async function updateFiles(operation: Operation): Promise<Operation> {
1111
let { files } = operation.options;
1212

13-
for (let name of files) {
14-
let modified = await updateFile(name, operation);
13+
for (let relPath of files) {
14+
let modified = await updateFile(relPath, operation);
1515

1616
if (modified) {
1717
operation.update({
1818
event: ProgressEvent.FileUpdated,
19-
files: [name],
19+
files: [relPath],
2020
});
2121
}
2222
}
@@ -29,18 +29,18 @@ export async function updateFiles(operation: Operation): Promise<Operation> {
2929
*
3030
* @returns - `true` if the file was actually modified
3131
*/
32-
async function updateFile(name: string, operation: Operation): Promise<boolean> {
33-
name = path.basename(name).trim().toLowerCase();
32+
async function updateFile(relPath: string, operation: Operation): Promise<boolean> {
33+
let name = path.basename(relPath).trim().toLowerCase();
3434

3535
switch (name) {
3636
case "package.json":
3737
case "package-lock.json":
3838
case "bower.json":
3939
case "component.json":
40-
return updateManifestFile(name, operation);
40+
return updateManifestFile(relPath, operation);
4141

4242
default:
43-
return updateTextFile(name, operation);
43+
return updateTextFile(relPath, operation);
4444
}
4545
}
4646

@@ -52,19 +52,17 @@ async function updateFile(name: string, operation: Operation): Promise<boolean>
5252
*
5353
* @returns - `true` if the file was actually modified
5454
*/
55-
async function updateManifestFile(name: string, operation: Operation): Promise<boolean> {
55+
async function updateManifestFile(relPath: string, operation: Operation): Promise<boolean> {
5656
let { cwd } = operation.options;
5757
let { newVersion } = operation.state;
5858
let modified = false;
5959

60-
let file = await readJsonFile(name, cwd);
60+
let file = await readJsonFile(relPath, cwd);
6161

62-
if (isManifest(file.data) && file.data.version !== newVersion) {
63-
file.data.version = newVersion;
64-
await writeJsonFile(file);
65-
modified = true;
66-
}
67-
}
62+
if (isManifest(file.data) && file.data.version !== newVersion) {
63+
file.data.version = newVersion;
64+
await writeJsonFile(file);
65+
modified = true;
6866
}
6967

7068
return modified;
@@ -75,27 +73,26 @@ async function updateManifestFile(name: string, operation: Operation): Promise<b
7573
*
7674
* @returns - `true` if the file was actually modified
7775
*/
78-
async function updateTextFile(name: string, operation: Operation): Promise<boolean> {
76+
async function updateTextFile(relPath: string, operation: Operation): Promise<boolean> {
7977
let { cwd } = operation.options;
8078
let { oldVersion, newVersion } = operation.state;
8179
let modified = false;
8280

83-
let file = await readTextFile(name, cwd);
81+
let file = await readTextFile(relPath, cwd);
8482

85-
// Only update the file if it contains at least one occurrence of the old version
86-
if (file.data.includes(oldVersion)) {
87-
// Escape all non-alphanumeric characters in the version
88-
let sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
83+
// Only update the file if it contains at least one occurrence of the old version
84+
if (file.data.includes(oldVersion)) {
85+
// Escape all non-alphanumeric characters in the version
86+
let sanitizedVersion = oldVersion.replace(/(\W)/g, "\\$1");
8987

90-
// Replace occurrences of the old version number that are surrounded by word boundaries.
91-
// This ensures that it matches "1.23.456" or "v1.23.456", but not "321.23.456".
92-
let replacePattern = new RegExp("(\\b|v)" + sanitizedVersion + "\\b", "g");
88+
// Replace occurrences of the old version number that are surrounded by word boundaries.
89+
// This ensures that it matches "1.23.456" or "v1.23.456", but not "321.23.456".
90+
let replacePattern = new RegExp("(\\b|v)" + sanitizedVersion + "\\b", "g");
9391

94-
file.data = file.data.replace(replacePattern, "$1" + newVersion);
95-
await writeTextFile(file);
92+
file.data = file.data.replace(replacePattern, "$1" + newVersion);
93+
await writeTextFile(file);
9694

97-
return true;
98-
}
95+
return true;
9996
}
10097

10198
return modified;

0 commit comments

Comments
 (0)