From eff92a61b95fb6a72e1bc5d1450d882b645ebf7a Mon Sep 17 00:00:00 2001 From: Debadree Chatterjee Date: Sun, 18 Dec 2022 21:19:08 +0530 Subject: [PATCH] src: add undici and acorn to `process.versions` Fixes: https://github.com/nodejs/node/issues/45260 Refs: https://github.com/nodejs/node/pull/45599 Refs: https://github.com/nodejs/node/issues/45260 PR-URL: https://github.com/nodejs/node/pull/45621 Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Joyee Cheung Reviewed-By: Darshan Sen --- src/acorn_version.h | 6 ++++++ src/node_metadata.cc | 6 ++++++ src/node_metadata.h | 10 +++++++++- src/undici_version.h | 6 ++++++ test/parallel/test-process-versions.js | 24 ++++++++++++++++++++++++ tools/update-acorn.sh | 11 +++++++++++ tools/update-undici.sh | 10 ++++++++++ 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/acorn_version.h create mode 100644 src/undici_version.h diff --git a/src/acorn_version.h b/src/acorn_version.h new file mode 100644 index 00000000000000..986d1de1f07e34 --- /dev/null +++ b/src/acorn_version.h @@ -0,0 +1,6 @@ +// This is an auto generated file, please do not edit. +// Refer to tools/update-acorn.sh +#ifndef SRC_ACORN_VERSION_H_ +#define SRC_ACORN_VERSION_H_ +#define ACORN_VERSION "8.8.1" +#endif // SRC_ACORN_VERSION_H_ diff --git a/src/node_metadata.cc b/src/node_metadata.cc index d4c8ccde21d397..fefad37c894fd6 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -1,9 +1,11 @@ #include "node_metadata.h" +#include "acorn_version.h" #include "ares.h" #include "brotli/encode.h" #include "llhttp.h" #include "nghttp2/nghttp2ver.h" #include "node.h" +#include "undici_version.h" #include "util.h" #include "uv.h" #include "uvwasi.h" @@ -90,6 +92,10 @@ Metadata::Versions::Versions() { std::to_string((BrotliEncoderVersion() & 0xFFF000) >> 12) + "." + std::to_string(BrotliEncoderVersion() & 0xFFF); +#ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH + undici = UNDICI_VERSION; +#endif + acorn = ACORN_VERSION; uvwasi = UVWASI_VERSION_STRING; diff --git a/src/node_metadata.h b/src/node_metadata.h index 89c2d36611ee7b..6c29c0ebdd7c01 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -27,6 +27,12 @@ namespace node { #define NODE_HAS_RELEASE_URLS #endif +#ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH +#define NODE_VERSIONS_KEY_UNDICI(V) V(undici) +#else +#define NODE_VERSIONS_KEY_UNDICI(V) +#endif + #define NODE_VERSIONS_KEYS_BASE(V) \ V(node) \ V(v8) \ @@ -38,7 +44,9 @@ namespace node { V(nghttp2) \ V(napi) \ V(llhttp) \ - V(uvwasi) + V(uvwasi) \ + V(acorn) \ + NODE_VERSIONS_KEY_UNDICI(V) #if HAVE_OPENSSL #define NODE_VERSIONS_KEY_CRYPTO(V) V(openssl) diff --git a/src/undici_version.h b/src/undici_version.h new file mode 100644 index 00000000000000..a788b1f78e7a4e --- /dev/null +++ b/src/undici_version.h @@ -0,0 +1,6 @@ +// This is an auto generated file, please do not edit. +// Refer to tools/update-undici.sh +#ifndef SRC_UNDICI_VERSION_H_ +#define SRC_UNDICI_VERSION_H_ +#define UNDICI_VERSION "5.14.0" +#endif // SRC_UNDICI_VERSION_H_ diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 2ec7a0f84a5280..54722cbf59ab66 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -2,6 +2,9 @@ const common = require('../common'); const assert = require('assert'); +// Import of pure js (non-shared) deps for comparison +const acorn = require('../../deps/acorn/acorn/package.json'); + const expected_keys = [ 'ares', 'brotli', @@ -14,8 +17,15 @@ const expected_keys = [ 'napi', 'llhttp', 'uvwasi', + 'acorn', ]; +const hasUndici = process.config.variables.node_builtin_shareable_builtins.includes('deps/undici/undici.js'); + +if (hasUndici) { + expected_keys.push('undici'); +} + if (common.hasCrypto) { expected_keys.push('openssl'); } @@ -39,6 +49,7 @@ assert.deepStrictEqual(actual_keys, expected_keys); const commonTemplate = /^\d+\.\d+\.\d+(?:-.*)?$/; +assert.match(process.versions.acorn, commonTemplate); assert.match(process.versions.ares, commonTemplate); assert.match(process.versions.brotli, commonTemplate); assert.match(process.versions.llhttp, commonTemplate); @@ -46,6 +57,10 @@ assert.match(process.versions.node, commonTemplate); assert.match(process.versions.uv, commonTemplate); assert.match(process.versions.zlib, commonTemplate); +if (hasUndici) { + assert.match(process.versions.undici, commonTemplate); +} + assert.match( process.versions.v8, /^\d+\.\d+\.\d+(?:\.\d+)?-node\.\d+(?: \(candidate\))?$/ @@ -70,3 +85,12 @@ for (let i = 0; i < expected_keys.length; i++) { assert.strictEqual(process.config.variables.napi_build_version, process.versions.napi); + +if (hasUndici) { + const undici = require('../../deps/undici/src/package.json'); + const expectedUndiciVersion = undici.version; + assert.strictEqual(process.versions.undici, expectedUndiciVersion); +} + +const expectedAcornVersion = acorn.version; +assert.strictEqual(process.versions.acorn, expectedAcornVersion); diff --git a/tools/update-acorn.sh b/tools/update-acorn.sh index fadcb242884d77..514b5e509706d2 100755 --- a/tools/update-acorn.sh +++ b/tools/update-acorn.sh @@ -23,6 +23,17 @@ rm -rf deps/acorn/acorn "$NODE" "$NPM" init --yes "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts acorn + cd node_modules/acorn + # get acorn version + ACORN_VERSION=$("$NODE" -p "require('./package.json').version") + # update this version information in src/acorn_version.h + FILE_PATH="$ROOT/src/acorn_version.h" + echo "// This is an auto generated file, please do not edit." > "$FILE_PATH" + echo "// Refer to tools/update-acorn.sh" >> "$FILE_PATH" + echo "#ifndef SRC_ACORN_VERSION_H_" >> "$FILE_PATH" + echo "#define SRC_ACORN_VERSION_H_" >> "$FILE_PATH" + echo "#define ACORN_VERSION \"$ACORN_VERSION\"" >> "$FILE_PATH" + echo "#endif // SRC_ACORN_VERSION_H_" >> "$FILE_PATH" ) mv acorn-tmp/node_modules/acorn deps/acorn diff --git a/tools/update-undici.sh b/tools/update-undici.sh index 8350e215272808..d3642088c5a14e 100755 --- a/tools/update-undici.sh +++ b/tools/update-undici.sh @@ -26,6 +26,16 @@ rm -f deps/undici/undici.js "$NODE" "$NPM" install --global-style --no-bin-links --ignore-scripts undici cd node_modules/undici "$NODE" "$NPM" run build:node + # get the new version of undici + UNDICI_VERSION=$("$NODE" -p "require('./package.json').version") + # update this version information in src/undici_version.h + FILE_PATH="$ROOT/src/undici_version.h" + echo "// This is an auto generated file, please do not edit." > "$FILE_PATH" + echo "// Refer to tools/update-undici.sh" >> "$FILE_PATH" + echo "#ifndef SRC_ACORN_VERSION_H_" >> "$FILE_PATH" + echo "#define SRC_ACORN_VERSION_H_" >> "$FILE_PATH" + echo "#define UNDICI_VERSION \"$UNDICI_VERSION\"" >> "$FILE_PATH" + echo "#endif // SRC_ACORN_VERSION_H_" >> "$FILE_PATH" ) mv undici-tmp/node_modules/undici deps/undici/src