11cb0ef41Sopenharmony_ci# Node.js Node-API version release process 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciThis document describes the technical aspects of the Node.js Node-API version 41cb0ef41Sopenharmony_cirelease process. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci## Table of contents 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ci* [How to create a release](#how-to-create-a-release) 91cb0ef41Sopenharmony_ci * [0. Pre-release steps](#0-pre-release-steps) 101cb0ef41Sopenharmony_ci * [1. Update the main branch](#1-update-the-main-branch) 111cb0ef41Sopenharmony_ci * [2. Create a new branch for the release](#2-create-a-new-branch-for-the-release) 121cb0ef41Sopenharmony_ci * [3. Update `NODE_API_SUPPORTED_VERSION_MAX`](#3-update-node_api_supported_version_max) 131cb0ef41Sopenharmony_ci * [4. Define `addon_context_register_func`](#4-define-addon_context_register_func) 141cb0ef41Sopenharmony_ci * [5. Update version guards](#5-update-version-guards) 151cb0ef41Sopenharmony_ci * [6. Create release commit](#6-create-release-commit) 161cb0ef41Sopenharmony_ci * [7. Propose release on GitHub](#7-propose-release-on-github) 171cb0ef41Sopenharmony_ci * [8. Ensure that the release branch is stable](#8-ensure-that-the-release-branch-is-stable) 181cb0ef41Sopenharmony_ci * [9. Land the release](#9-land-the-release) 191cb0ef41Sopenharmony_ci * [10. Backport the release](#10-backport-the-release) 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci## How to create a release 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciNotes: 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci* Version strings are listed below as _"vx"_ or _"x"_. Substitute for 261cb0ef41Sopenharmony_ci the release version. 271cb0ef41Sopenharmony_ci* Examples will use the integer release version `10`. 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci### 0. Pre-release steps 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ciBefore preparing a Node.js Node-API version release, the Node-API Working Group 321cb0ef41Sopenharmony_cimust be notified at least one business day in advance of the expected release. 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ciNode-API Working Group can be contacted best by opening up an issue on the 351cb0ef41Sopenharmony_ci[abi-stable-node issue tracker][]. 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci### 1. Update the main Branch 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ciCheckout the staging branch locally. 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci```console 421cb0ef41Sopenharmony_ci$ git remote update 431cb0ef41Sopenharmony_ci$ git checkout main 441cb0ef41Sopenharmony_ci$ git reset --hard upstream/main 451cb0ef41Sopenharmony_ci``` 461cb0ef41Sopenharmony_ci 471cb0ef41Sopenharmony_ciIf the staging branch is not up to date relative to `main`, bring the 481cb0ef41Sopenharmony_ciappropriate PRs and commits into it. 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci### 2. Create a new branch for the release 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ciCreate a new branch named `node-api-x-proposal`, off the main branch. 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci```console 551cb0ef41Sopenharmony_ci$ git checkout -b node-api-10-proposal upstream/main 561cb0ef41Sopenharmony_ci``` 571cb0ef41Sopenharmony_ci 581cb0ef41Sopenharmony_ci### 3. Update `NODE_API_SUPPORTED_VERSION_MAX` 591cb0ef41Sopenharmony_ci 601cb0ef41Sopenharmony_ciSet the version for the proposed release using the following macros, which are 611cb0ef41Sopenharmony_cialready defined in `src/node_version.h`: 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci```c 641cb0ef41Sopenharmony_ci#define NODE_API_SUPPORTED_VERSION_MAX x 651cb0ef41Sopenharmony_ci``` 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci> Note: Do not update the `NAPI_VERSION` defined in `src/js_native_api.h`. It 681cb0ef41Sopenharmony_ci> is a fixed constant baseline version of Node-API. 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci### 4. Define `addon_context_register_func` 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ciFor each new version of Node-API an `else if` case must be added to 731cb0ef41Sopenharmony_ci`get_node_api_context_register_func` in `src/node_api.cc` and the numeric 741cb0ef41Sopenharmony_ciliteral used in the `static_assert` statement in that function must be updated 751cb0ef41Sopenharmony_cito the new Node-API version. 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ci### 5. Update version guards 781cb0ef41Sopenharmony_ci 791cb0ef41Sopenharmony_ci#### Step 1. Update define version guards 801cb0ef41Sopenharmony_ci 811cb0ef41Sopenharmony_ciIf this release includes new Node-APIs that were first released in this 821cb0ef41Sopenharmony_civersion, the relevant commits should already include the `NAPI_EXPERIMENTAL` 831cb0ef41Sopenharmony_cidefine guards on the declaration of the new Node-API. Check for these guards 841cb0ef41Sopenharmony_ciwith: 851cb0ef41Sopenharmony_ci 861cb0ef41Sopenharmony_ci```console 871cb0ef41Sopenharmony_cigrep \ 881cb0ef41Sopenharmony_ci -E \ 891cb0ef41Sopenharmony_ci 'N(ODE_)?API_EXPERIMENTAL' \ 901cb0ef41Sopenharmony_ci src/js_native_api{_types,}.h \ 911cb0ef41Sopenharmony_ci src/node_api{_types,}.h 921cb0ef41Sopenharmony_ci``` 931cb0ef41Sopenharmony_ci 941cb0ef41Sopenharmony_ciand update the define version guards with the release version: 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci```diff 971cb0ef41Sopenharmony_ci- #ifdef NAPI_EXPERIMENTAL 981cb0ef41Sopenharmony_ci+ #if NAPI_VERSION >= 10 991cb0ef41Sopenharmony_ci 1001cb0ef41Sopenharmony_ci NAPI_EXTERN napi_status NAPI_CDECL 1011cb0ef41Sopenharmony_ci node_api_function(napi_env env); 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci- #endif // NAPI_EXPERIMENTAL 1041cb0ef41Sopenharmony_ci+ #endif // NAPI_VERSION >= 10 1051cb0ef41Sopenharmony_ci``` 1061cb0ef41Sopenharmony_ci 1071cb0ef41Sopenharmony_ciRemove any feature flags of the form `NODE_API_EXPERIMENTAL_HAS_<FEATURE>`. 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_ciRemove any additional `NODE_API_EXPERIMENTAL_*` guards along with 1101cb0ef41Sopenharmony_ci`NAPI_EXPERIMENTAL`. 1111cb0ef41Sopenharmony_ci 1121cb0ef41Sopenharmony_ciAlso, update the Node-API version value of the `napi_get_version` test in 1131cb0ef41Sopenharmony_ci`test/js-native-api/test_general/test.js` with the release version `x`: 1141cb0ef41Sopenharmony_ci 1151cb0ef41Sopenharmony_ci```diff 1161cb0ef41Sopenharmony_ci // Test version management functions 1171cb0ef41Sopenharmony_ci- assert.strictEqual(test_general.testGetVersion(), 9); 1181cb0ef41Sopenharmony_ci+ assert.strictEqual(test_general.testGetVersion(), 10); 1191cb0ef41Sopenharmony_ci``` 1201cb0ef41Sopenharmony_ci 1211cb0ef41Sopenharmony_ci#### Step 2. Update runtime version guards 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ciIf this release includes runtime behavior version guards, the relevant commits 1241cb0ef41Sopenharmony_cishould already include `NAPI_VERSION_EXPERIMENTAL` guard for the change. Check 1251cb0ef41Sopenharmony_cifor these guards with: 1261cb0ef41Sopenharmony_ci 1271cb0ef41Sopenharmony_ci```console 1281cb0ef41Sopenharmony_cigrep NAPI_VERSION_EXPERIMENTAL src/js_native_api_v8* src/node_api.cc 1291cb0ef41Sopenharmony_ci``` 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_ciand substitute this guard version with the release version `x`. 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci#### Step 3. Update test version guards 1341cb0ef41Sopenharmony_ci 1351cb0ef41Sopenharmony_ciIf this release includes add-on tests for the new Node-APIs, the relevant 1361cb0ef41Sopenharmony_cicommits should already include `NAPI_EXPERIMENTAL` definition for the tests. 1371cb0ef41Sopenharmony_ciCheck for these definitions with: 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ci```console 1401cb0ef41Sopenharmony_cigrep \ 1411cb0ef41Sopenharmony_ci -E \ 1421cb0ef41Sopenharmony_ci 'N(ODE_)?API_EXPERIMENTAL' \ 1431cb0ef41Sopenharmony_ci test/node-api/*/{*.{h,c},binding.gyp} \ 1441cb0ef41Sopenharmony_ci test/js-native-api/*/{*.{h,c},binding.gyp} 1451cb0ef41Sopenharmony_ci``` 1461cb0ef41Sopenharmony_ci 1471cb0ef41Sopenharmony_ciand substitute the `NAPI_EXPERIMENTAL` with the release version 1481cb0ef41Sopenharmony_ci`NAPI_VERSION x`; 1491cb0ef41Sopenharmony_ci 1501cb0ef41Sopenharmony_ci```diff 1511cb0ef41Sopenharmony_ci- #define NAPI_EXPERIMENTAL 1521cb0ef41Sopenharmony_ci+ #define NAPI_VERSION 10 1531cb0ef41Sopenharmony_ci``` 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ciRemove any `NODE_API_EXPERIMENTAL_*` flags. 1561cb0ef41Sopenharmony_ci 1571cb0ef41Sopenharmony_ci#### Step 4. Update document 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_ciIf this release includes new Node-APIs that were first released in this 1601cb0ef41Sopenharmony_civersion and are necessary to document, the relevant commits should already 1611cb0ef41Sopenharmony_cihave documented the new Node-API. 1621cb0ef41Sopenharmony_ci 1631cb0ef41Sopenharmony_ciFor all Node-API functions and types with define guards updated in Step 1, 1641cb0ef41Sopenharmony_ciin `doc/api/n-api.md`, add the `napiVersion: x` metadata to the Node-API types 1651cb0ef41Sopenharmony_ciand functions that are released in the version, and remove the experimental 1661cb0ef41Sopenharmony_cistability banner: 1671cb0ef41Sopenharmony_ci 1681cb0ef41Sopenharmony_ci```diff 1691cb0ef41Sopenharmony_ci #### node_api_function 1701cb0ef41Sopenharmony_ci <!-- YAML 1711cb0ef41Sopenharmony_ci added: 1721cb0ef41Sopenharmony_ci - v1.2.3 1731cb0ef41Sopenharmony_ci+ napiVersion: 10 1741cb0ef41Sopenharmony_ci --> 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_ci- > Stability: 1 - Experimental 1771cb0ef41Sopenharmony_ci``` 1781cb0ef41Sopenharmony_ci 1791cb0ef41Sopenharmony_ci#### Step 5. Update change history 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_ciIf this release includes new Node-APIs runtime version guards that were first 1821cb0ef41Sopenharmony_cireleased in this version and are necessary to document, the relevant commits 1831cb0ef41Sopenharmony_cishould already have documented the new behavior in a "Change History" section. 1841cb0ef41Sopenharmony_ci 1851cb0ef41Sopenharmony_ciFor all runtime version guards updated in Step 2, check for these definitions 1861cb0ef41Sopenharmony_ciwith: 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci```console 1891cb0ef41Sopenharmony_cigrep NAPI_EXPERIMENTAL doc/api/n-api.md 1901cb0ef41Sopenharmony_ci``` 1911cb0ef41Sopenharmony_ci 1921cb0ef41Sopenharmony_ciIn `doc/api/n-api.md`, update the `experimental` change history item to be the 1931cb0ef41Sopenharmony_cireleased version `x`: 1941cb0ef41Sopenharmony_ci 1951cb0ef41Sopenharmony_ci```diff 1961cb0ef41Sopenharmony_ci Change History: 1971cb0ef41Sopenharmony_ci 1981cb0ef41Sopenharmony_ci- * experimental (`NAPI_EXPERIMENTAL` is defined): 1991cb0ef41Sopenharmony_ci+ * version 10: 2001cb0ef41Sopenharmony_ci``` 2011cb0ef41Sopenharmony_ci 2021cb0ef41Sopenharmony_ci### 6. Create release commit 2031cb0ef41Sopenharmony_ci 2041cb0ef41Sopenharmony_ciWhen committing these to git, use the following message format: 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_ci```text 2071cb0ef41Sopenharmony_cinode-api: define version x 2081cb0ef41Sopenharmony_ci``` 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci### 7. Propose release on GitHub 2111cb0ef41Sopenharmony_ci 2121cb0ef41Sopenharmony_ciCreate a pull request targeting the `main` branch. These PRs should be left 2131cb0ef41Sopenharmony_ciopen for at least 24 hours, and can be updated as new commits land. 2141cb0ef41Sopenharmony_ci 2151cb0ef41Sopenharmony_ciIf you need any additional information about any of the commits, this PR is a 2161cb0ef41Sopenharmony_cigood place to @-mention the relevant contributors. 2171cb0ef41Sopenharmony_ci 2181cb0ef41Sopenharmony_ciTag the PR with the `notable-change` label, and @-mention the GitHub team 2191cb0ef41Sopenharmony_ci@nodejs/node-api and @nodejs/node-api-implementer. 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_ci### 8. Ensure that the release branch is stable 2221cb0ef41Sopenharmony_ci 2231cb0ef41Sopenharmony_ciRun a **[`node-test-pull-request`](https://ci.nodejs.org/job/node-test-pull-request/)** 2241cb0ef41Sopenharmony_citest run to ensure that the build is stable and the HEAD commit is ready for 2251cb0ef41Sopenharmony_cirelease. 2261cb0ef41Sopenharmony_ci 2271cb0ef41Sopenharmony_ci### 9. Land the release 2281cb0ef41Sopenharmony_ci 2291cb0ef41Sopenharmony_ciSee the steps documented in [Collaborator Guide - Landing a PR][] to land the 2301cb0ef41Sopenharmony_ciPR. 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_ci### 10. Backport the release 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ciConsider backporting the release to all LTS versions following the steps 2351cb0ef41Sopenharmony_cidocumented in the [backporting guide][]. 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ci[Collaborator Guide - Landing a PR]: ./collaborator-guide.md#landing-pull-requests 2381cb0ef41Sopenharmony_ci[abi-stable-node issue tracker]: https://github.com/nodejs/abi-stable-node/issues 2391cb0ef41Sopenharmony_ci[backporting guide]: backporting-to-release-lines.md 240