From 1e3a3470a5d6b0f4137507fd7a66008a7020bf2d Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 2 Aug 2024 12:37:36 +0200 Subject: [PATCH] build: add `--without-amaro` build flag PR-URL: https://github.com/nodejs/node/pull/54136 Reviewed-By: Yagiz Nizipli Reviewed-By: Marco Ippolito Reviewed-By: Rafael Gonzaga --- configure.py | 7 +++++++ node.gyp | 7 ++++++- node.gypi | 5 +++++ src/node_metadata.cc | 3 +++ src/node_metadata.h | 8 +++++++- test/es-module/test-typescript-commonjs.mjs | 4 +++- test/es-module/test-typescript-eval.mjs | 4 +++- test/es-module/test-typescript-module.mjs | 4 +++- test/es-module/test-typescript.mjs | 4 +++- test/parallel/test-process-versions.js | 4 +++- 10 files changed, 43 insertions(+), 7 deletions(-) diff --git a/configure.py b/configure.py index 5b53fd0ea87..351bcf99ea9 100755 --- a/configure.py +++ b/configure.py @@ -765,6 +765,12 @@ http2_optgroup.add_argument('--debug-nghttp2', default=None, help='build nghttp2 with DEBUGBUILD (default is false)') +parser.add_argument('--without-amaro', + action='store_true', + dest='without_amaro', + default=None, + help='do not install the bundled Amaro (TypeScript utils)') + parser.add_argument('--without-npm', action='store_true', dest='without_npm', @@ -1380,6 +1386,7 @@ def configure_node(o): o['variables']['node_prefix'] = options.prefix o['variables']['node_install_npm'] = b(not options.without_npm) o['variables']['node_install_corepack'] = b(not options.without_corepack) + o['variables']['node_use_amaro'] = b(not options.without_amaro) o['variables']['debug_node'] = b(options.debug_node) o['default_configuration'] = 'Debug' if options.debug else 'Release' o['variables']['error_on_warn'] = b(options.error_on_warn) diff --git a/node.gyp b/node.gyp index 2827ddf4c0d..5d93e38182c 100644 --- a/node.gyp +++ b/node.gyp @@ -14,6 +14,7 @@ 'force_dynamic_crt%': 0, 'ossfuzz' : 'false', 'node_module_version%': '', + 'node_use_amaro%': 'true', 'node_shared_brotli%': 'false', 'node_shared_zlib%': 'false', 'node_shared_http_parser%': 'false', @@ -56,7 +57,6 @@ 'deps/acorn/acorn/dist/acorn.js', 'deps/acorn/acorn-walk/dist/walk.js', 'deps/minimatch/index.js', - 'deps/amaro/dist/index.js', '<@(node_builtin_shareable_builtins)', ], 'node_sources': [ @@ -461,6 +461,11 @@ }, { 'use_openssl_def%': 0, }], + [ 'node_use_amaro=="true"', { + 'deps_files': [ + 'deps/amaro/dist/index.js', + ] + } ] ], }, diff --git a/node.gypi b/node.gypi index fc1a87fc0b6..44780fe3b12 100644 --- a/node.gypi +++ b/node.gypi @@ -412,5 +412,10 @@ }, { 'defines': [ 'HAVE_OPENSSL=0' ] }], + [ 'node_use_amaro=="true"', { + 'defines': [ 'HAVE_AMARO=1' ], + }, { + 'defines': [ 'HAVE_AMARO=0' ] + }], ], } diff --git a/src/node_metadata.cc b/src/node_metadata.cc index bc39fafcbb3..4ab98d91d84 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -126,7 +126,10 @@ Metadata::Versions::Versions() { acorn = ACORN_VERSION; cjs_module_lexer = CJS_MODULE_LEXER_VERSION; uvwasi = UVWASI_VERSION_STRING; + +#if HAVE_AMARO amaro = AMARO_VERSION; +#endif #if HAVE_OPENSSL openssl = GetOpenSSLVersion(); diff --git a/src/node_metadata.h b/src/node_metadata.h index 5502c9696cc..76ec862fda1 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -27,6 +27,12 @@ namespace node { #define NODE_HAS_RELEASE_URLS #endif +#if HAVE_AMARO +#define NODE_VERSIONS_KEY_AMARO(V) V(amaro) +#else +#define NODE_VERSIONS_KEY_AMARO(V) +#endif + #ifndef NODE_SHARED_BUILTIN_UNDICI_UNDICI_PATH #define NODE_VERSIONS_KEY_UNDICI(V) V(undici) #else @@ -51,7 +57,7 @@ namespace node { V(sqlite) \ V(ada) \ V(nbytes) \ - V(amaro) \ + NODE_VERSIONS_KEY_AMARO(V) \ NODE_VERSIONS_KEY_UNDICI(V) \ V(cjs_module_lexer) diff --git a/test/es-module/test-typescript-commonjs.mjs b/test/es-module/test-typescript-commonjs.mjs index aa3550bbab9..40594588f10 100644 --- a/test/es-module/test-typescript-commonjs.mjs +++ b/test/es-module/test-typescript-commonjs.mjs @@ -1,8 +1,10 @@ -import { spawnPromisified } from '../common/index.mjs'; +import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { match, strictEqual } from 'node:assert'; import { test } from 'node:test'; +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); + test('require a .ts file with explicit extension succeeds', async () => { const result = await spawnPromisified(process.execPath, [ '--experimental-strip-types', diff --git a/test/es-module/test-typescript-eval.mjs b/test/es-module/test-typescript-eval.mjs index aba4c01108f..196953ef531 100644 --- a/test/es-module/test-typescript-eval.mjs +++ b/test/es-module/test-typescript-eval.mjs @@ -1,7 +1,9 @@ -import { spawnPromisified } from '../common/index.mjs'; +import { skip, spawnPromisified } from '../common/index.mjs'; import { match, strictEqual } from 'node:assert'; import { test } from 'node:test'; +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); + test('eval TypeScript ESM syntax', async () => { const result = await spawnPromisified(process.execPath, [ '--input-type=module', diff --git a/test/es-module/test-typescript-module.mjs b/test/es-module/test-typescript-module.mjs index 976e6004100..53c3c4fed04 100644 --- a/test/es-module/test-typescript-module.mjs +++ b/test/es-module/test-typescript-module.mjs @@ -1,8 +1,10 @@ -import { spawnPromisified } from '../common/index.mjs'; +import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { match, strictEqual } from 'node:assert'; import { test } from 'node:test'; +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); + test('expect failure of a .mts file with CommonJS syntax', async () => { const result = await spawnPromisified(process.execPath, [ '--experimental-strip-types', diff --git a/test/es-module/test-typescript.mjs b/test/es-module/test-typescript.mjs index 1c41215f06c..f8df87b540a 100644 --- a/test/es-module/test-typescript.mjs +++ b/test/es-module/test-typescript.mjs @@ -1,8 +1,10 @@ -import { spawnPromisified } from '../common/index.mjs'; +import { skip, spawnPromisified } from '../common/index.mjs'; import * as fixtures from '../common/fixtures.mjs'; import { match, strictEqual } from 'node:assert'; import { test } from 'node:test'; +if (!process.config.variables.node_use_amaro) skip('Requires Amaro'); + test('execute a TypeScript file', async () => { const result = await spawnPromisified(process.execPath, [ '--experimental-strip-types', diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 41186c1a1af..7475b275940 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -24,11 +24,13 @@ const expected_keys = [ 'ada', 'cjs_module_lexer', 'nbytes', - 'amaro', ]; const hasUndici = process.config.variables.node_builtin_shareable_builtins.includes('deps/undici/undici.js'); +if (process.config.variables.node_use_amaro) { + expected_keys.push('amaro'); +} if (hasUndici) { expected_keys.push('undici'); }