Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce tl.getNodeMajorVersion #979

Merged
merged 4 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion node/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ Backported from ver.`3.4.0`:

## 4.6.0

- Replaced deprecated "sync-request" lib and Added new Async methods - [#932](https://github.com/microsoft/azure-pipelines-task-lib/pull/932)
- Replaced deprecated "sync-request" lib and Added new Async methods - [#932](https://github.com/microsoft/azure-pipelines-task-lib/pull/932)

## 4.6.1

- Added `getNodeMajorVersion` [#979](https://github.com/microsoft/azure-pipelines-task-lib/pull/979)
3 changes: 2 additions & 1 deletion node/Strings/resources.resjson/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
"loc.messages.LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
"loc.messages.LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
"loc.messages.LIB_PlatformNotSupported": "Platform not supported: %s",
"loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s"
"loc.messages.LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
"loc.messages.LIB_UndefinedNodeVersion": "Node version is undefined."
}
3 changes: 2 additions & 1 deletion node/lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"LIB_UseFirstGlobMatch": "Multiple workspace matches. using first.",
"LIB_MergeTestResultNotSupported": "Merging test results from multiple files to one test run is not supported on this version of build agent for OSX/Linux, each test result file will be published as a separate test run in VSO/TFS.",
"LIB_PlatformNotSupported": "Platform not supported: %s",
"LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s"
"LIB_CopyFileFailed": "Error while copying the file. Attempts left: %s",
"LIB_UndefinedNodeVersion": "Node version is undefined."
}
}
1 change: 1 addition & 0 deletions node/mock-answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface TaskLibAnswers {
find?: { [key: string]: string[] },
findMatch?: { [key: string]: string[] },
getPlatform?: { [key: string]: task.Platform },
getNodeMajorVersion?: { [key: string]: Number },
getAgentMode?: { [key: string]: task.AgentHostedMode },
legacyFindFiles?: { [key: string]: string[] },
ls?: { [key: string]: string },
Expand Down
4 changes: 4 additions & 0 deletions node/mock-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ export function getPlatform(): task.Platform {
return mock.getResponse('getPlatform', 'getPlatform', module.exports.debug);
}

export function getNodeMajorVersion(): Number {
return mock.getResponse('getNodeMajorVersion', 'getNodeMajorVersion', module.exports.debug);
}

export function getAgentMode(): task.AgentHostedMode {
return mock.getResponse('getAgentMode', 'getAgentMode', module.exports.debug);
}
Expand Down
9 changes: 5 additions & 4 deletions node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "azure-pipelines-task-lib",
"version": "4.6.0",
"version": "4.6.1",
"description": "Azure Pipelines Task SDK",
"main": "./task.js",
"typings": "./task.d.ts",
Expand Down
18 changes: 18 additions & 0 deletions node/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,24 @@ export function getPlatform(): Platform {
}
}

/**
* Resolves major version of Node.js engine used by the agent.
* @returns {Number} Node's major version.
*/
export function getNodeMajorVersion(): Number {
const version = process?.versions?.node;
if (!version) {
onetocny marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(loc('LIB_UndefinedNodeVersion'));
}

const parts = version.split('.').map(Number);
if (parts.length < 1) {
return NaN;
}

return parts[0];
}

/**
* Return hosted type of Agent
* @returns {AgentHostedMode}
Expand Down