Skip to content

Commit efb170e

Browse files
committed
Give ability to specify preview version when updating package dependencies
1 parent ff34b31 commit efb170e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

.vscode/launch.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@
154154
"env": {
155155
"NEW_DEPS_ID": "OmniSharp",
156156
"NEW_DEPS_URLS": "https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-x64-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-x86-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-arm64-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-osx-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-x64-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-x86-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-arm64-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-musl-x64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-musl-arm64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-x64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-linux-arm64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-osx-x64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-osx-arm64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-x64-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-x86-net6.0-1.39.11.zip,https://roslynomnisharp.blob.core.windows.net/releases/1.39.11/omnisharp-win-arm64-net6.0-1.39.11.zip",
157-
"NEW_DEPS_VERSION": "1.39.11"
157+
"OLD_DEPS_VERSION": "1.39.10",
158+
"NEW_DEPS_VERSION": "1.39.11",
158159
},
159160
"cwd": "${workspaceFolder}"
160161
},

src/tools/updatePackageDependencies.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const dashedVersionRegExp = /[0-9]+-[0-9]+-[0-9]+/g;
2626
export async function updatePackageDependencies(): Promise<void> {
2727
const newPrimaryUrls = process.env['NEW_DEPS_URLS'];
2828
const newVersion = process.env['NEW_DEPS_VERSION'];
29+
const oldVersion = process.env['OLD_DEPS_VERSION'] ?? ''; // Optional: Will fallback to trying to replace version with a regex.
2930
const packageId = process.env['NEW_DEPS_ID'];
3031

3132
if ((!packageId && !newPrimaryUrls) || !newVersion) {
@@ -51,6 +52,10 @@ export async function updatePackageDependencies(): Promise<void> {
5152
throw new Error("Unexpected 'NEW_DEPS_VERSION' value. Expected format similar to: 1.2.3.");
5253
}
5354

55+
if (oldVersion.length > 0 && !/^[0-9]+\.[0-9]+\.[0-9]+[-a-zA-Z0-9.]*$/.test(oldVersion)) {
56+
throw new Error("Unexpected 'OLD_DEPS_VERSION' value. Expected format similar to: 1.2.2.");
57+
}
58+
5459
const packageJSON: PackageJSONFile = JSON.parse(fs.readFileSync('package.json').toString());
5560

5661
const eventStream = new EventStream();
@@ -72,9 +77,9 @@ export async function updatePackageDependencies(): Promise<void> {
7277

7378
const updateDependency = async (dependency: Package): Promise<void> => {
7479
dependency.integrity = await downloadAndGetHash(dependency.url);
75-
dependency.fallbackUrl = replaceVersion(dependency.fallbackUrl, newVersion);
76-
dependency.installPath = replaceVersion(dependency.installPath, newVersion);
77-
dependency.installTestPath = replaceVersion(dependency.installTestPath, newVersion);
80+
dependency.fallbackUrl = replaceVersion(dependency.fallbackUrl, oldVersion, newVersion);
81+
dependency.installPath = replaceVersion(dependency.installPath, oldVersion, newVersion);
82+
dependency.installTestPath = replaceVersion(dependency.installTestPath, oldVersion, newVersion);
7883
Object.keys(packageJSON.defaults).forEach((key) => {
7984
//Update the version present in the defaults
8085
if (key.toLowerCase() == dependency.id.toLowerCase()) {
@@ -169,7 +174,7 @@ export async function updatePackageDependencies(): Promise<void> {
169174
continue;
170175
}
171176

172-
dependency.url = replaceVersion(dependency.url, newVersion);
177+
dependency.url = replaceVersion(dependency.url, oldVersion, newVersion);
173178
await updateDependency(dependency);
174179
}
175180
}
@@ -186,14 +191,18 @@ export async function updatePackageDependencies(): Promise<void> {
186191
fs.writeFileSync('package.json', content);
187192
}
188193

189-
function replaceVersion(fileName: string, newVersion: string): string;
190-
function replaceVersion(fileName: undefined, newVersion: string): undefined;
191-
function replaceVersion(fileName: string | undefined, newVersion: string): string | undefined;
192-
function replaceVersion(fileName: string | undefined, newVersion: string): string | undefined {
194+
function replaceVersion(fileName: string, oldVersion: string, newVersion: string): string;
195+
function replaceVersion(fileName: undefined, oldVersion: string, newVersion: string): undefined;
196+
function replaceVersion(fileName: string | undefined, oldVersion: string, newVersion: string): string | undefined;
197+
function replaceVersion(fileName: string | undefined, oldVersion: string, newVersion: string): string | undefined {
193198
if (fileName === undefined) {
194199
return undefined; // If the file name is undefined, no version to replace
195200
}
196201

202+
if (oldVersion.length > 0) {
203+
return fileName.replaceAll(oldVersion, newVersion);
204+
}
205+
197206
let regex: RegExp = dottedVersionRegExp;
198207
let newValue: string = newVersion;
199208
if (!dottedVersionRegExp.test(fileName)) {

0 commit comments

Comments
 (0)