|
| 1 | +## Table of content |
| 2 | + |
| 3 | +[Update `typescript`](#update-typescript) |
| 4 | + |
| 5 | +[Update `@types/node`](#update-typesnode) |
| 6 | + |
| 7 | +[Update `task-lib` and `tool-lib`](#update-task-lib-and-tool-lib) |
| 8 | + |
| 9 | +[Add `Node20_1` handler](#add-node20_1-handler) |
| 10 | + |
| 11 | +[Specify `minimumAgentVersion`](#specify-minimumagentversion) |
| 12 | + |
| 13 | +[Test the changes](#test-the-changes) |
| 14 | + |
| 15 | +[Feedback](#feedback) |
| 16 | + |
| 17 | +## Update `typescript` |
| 18 | + |
| 19 | +Update `typescript` to the `5.1.6` version in `devDependencies` in the `package.json` file and fix type errors. |
| 20 | + |
| 21 | +```json |
| 22 | +"devDependencies": { |
| 23 | + "typescript": "5.1.6" |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | +## Update `@types/node` |
| 28 | + |
| 29 | +Update `@types/node` to the `^20.3.1` version in `dependencies` in the `package.json` file. |
| 30 | + |
| 31 | +```json |
| 32 | +"dependencies": { |
| 33 | + "@types/node": "^20.3.1" |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +If the task does not use built-in Node.JS modules (such as `fs` or `path`) directly, remove `@types/node` from the task dependencies. |
| 38 | + |
| 39 | +## Update `task-lib` and `tool-lib` |
| 40 | + |
| 41 | +Update `azure-pipelines-task-lib` to `^4.13.0` and `azure-pipelines-tool-lib` to `^2.0.7` in `package.json` dependencies, if a task has these packages. |
| 42 | + |
| 43 | +`task-lib` package uses some shared (e.g. global object) resources to operate so it may cause unexpected errors in cases when more than one version of the package is installed for a task. This happens if `task-lib` in subdependencies of the task (e.g. in some common npm packages used by the task) has a different version than in dependencies of the task itself. Same for `tool-lib`. |
| 44 | + |
| 45 | +If the task uses `task-lib`, `tool-lib`, and some common npm packages that use `task-lib` and `tool-lib` as well, make sure `task-lib` and `tool-lib` have the same version in common npm packages as in the task itself. |
| 46 | +As a possible solution you also can remove these package versions via the `make.json` file, for example: |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "rm": [ |
| 51 | + { |
| 52 | + "items": [ |
| 53 | + "node_modules/any-common-npm-package/node_modules/azure-pipelines-task-lib", |
| 54 | + "node_modules/any-common-npm-package/node_modules/azure-pipelines-tool-lib" |
| 55 | + ], |
| 56 | + "options": "-Rf" |
| 57 | + } |
| 58 | + ] |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +Here is [the repo with different common npm packages](https://github.com/microsoft/azure-pipelines-tasks-common-packages) that can be used in the task. |
| 63 | + |
| 64 | +## Add `Node20_1` handler |
| 65 | + |
| 66 | +Add a new `Node20_1` execution handler in the `task.json` file. |
| 67 | + |
| 68 | +<table> |
| 69 | +<tr> |
| 70 | +<th>From</th> |
| 71 | +<th>To</th> |
| 72 | +</tr> |
| 73 | +<tr> |
| 74 | +<td> |
| 75 | + |
| 76 | +```json |
| 77 | +"execution": { |
| 78 | + "Node10": { |
| 79 | + "target": "main.js", |
| 80 | + "argumentFormat": "" |
| 81 | + }, |
| 82 | + "Node16": { |
| 83 | + "target": "main.js", |
| 84 | + "argumentFormat": "" |
| 85 | + } |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +</td> |
| 90 | +<td> |
| 91 | + |
| 92 | +```json |
| 93 | +"execution": { |
| 94 | + "Node10": { |
| 95 | + "target": "main.js", |
| 96 | + "argumentFormat": "" |
| 97 | + }, |
| 98 | + "Node16": { |
| 99 | + "target": "main.js", |
| 100 | + "argumentFormat": "" |
| 101 | + }, |
| 102 | + "Node20_1": { |
| 103 | + "target": "main.js", |
| 104 | + "argumentFormat": "" |
| 105 | + } |
| 106 | +} |
| 107 | +``` |
| 108 | + |
| 109 | +</td> |
| 110 | +</tr> |
| 111 | +</table> |
| 112 | + |
| 113 | +## Specify `minimumAgentVersion` |
| 114 | + |
| 115 | +If several handlers are specified in the `task.json` file, the highest one will be selected from handlers that are available on the certain agent. For example, if `Node10`, `Node16`, and `Node20_1` handlers are specified in the `task.json` file, and an old version of the agent (that is going to execute the task) has `Node` (version 6), `Node10`, and `Node16` handlers, then the `Node16` handler will be used. At the same time, the same agent will fail to execute the task if the `Node20_1` handler only is specified in the `task.json` file. Therefore you should specify `minimumAgentVersion`. |
| 116 | + |
| 117 | +`minimumAgentVersion` specified in the `task.json` file will trigger [an automatic upgrade](https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/agents?view=azure-devops&tabs=browser#agent-version-and-upgrades) for agents less than the specified version. |
| 118 | + |
| 119 | +* [Agent version `2.144.0`](https://github.com/microsoft/azure-pipelines-agent/releases/tag/v2.144.0) is the first version that supports `Node10` handler. So set `minimumAgentVersion` at least to `2.144.0`. |
| 120 | + |
| 121 | +```json |
| 122 | +"minimumAgentVersion": "2.144.0" |
| 123 | +``` |
| 124 | + |
| 125 | +* [Agent version `2.209.0`](https://github.com/microsoft/azure-pipelines-agent/releases/tag/v2.209.0) is the first version that supports `Node16` handler. If you want to run the task using at least `Node16` handler, set `minimumAgentVersion` to `2.209.0`. |
| 126 | + |
| 127 | +```json |
| 128 | +"minimumAgentVersion": "2.209.0" |
| 129 | +``` |
| 130 | + |
| 131 | +* [Agent version `3.232.1`](https://github.com/microsoft/azure-pipelines-agent/releases/tag/v3.232.1) is the first version that supports `Node20_1` handler. If you want to run the task using `Node20_1` handler for sure, set `minimumAgentVersion` to `3.232.1`. |
| 132 | + |
| 133 | +```json |
| 134 | +"minimumAgentVersion": "3.232.1" |
| 135 | +``` |
| 136 | + |
| 137 | +## Test the changes |
| 138 | + |
| 139 | +Test that the task works correctly on each execution handler specified in the `task.json` file. |
| 140 | + |
| 141 | +How to test the changes: |
| 142 | +* Run unit tests (they should pass on each handler specified in the `task.json` file). |
| 143 | +* Run pipeline with the task using `Node10` handler (if it is specified in the `task.json` file). |
| 144 | +* Run pipeline with the task using `Node16` handler (if it is specified in the `task.json` file). |
| 145 | +* Run pipeline with the task using `Node20_1` handler. |
| 146 | + |
| 147 | +To force the agent to use Node 10 handler for all Node-based tasks, set the pipeline variable / the agent environment variable `AGENT_USE_NODE10` to `true`. |
| 148 | + |
| 149 | +To force the agent to use Node 20 handler for all Node-based tasks, set the pipeline variable / the agent environment variable `AGENT_USE_NODE20_1` to `true`. |
| 150 | + |
| 151 | +## Feedback |
| 152 | + |
| 153 | +If you run into some issues while migrating to Node 20, please create a ticket with the label `node-migration: Node20`. |
0 commit comments