1818
1919class Build extends ConsoleCommand
2020{
21- public const RECOMMENDED_NODE_VERSION = '16 .0.0 ' ;
22- public const RECOMMENDED_NPM_VERSION = '7 .0.0 ' ;
21+ public const RECOMMENDED_NODE_VERSION = '20 .0.0 ' ;
22+ public const RECOMMENDED_NPM_VERSION = '10 .0.0 ' ;
2323 public const RETRY_COUNT = 2 ;
2424
2525 protected function configure ()
@@ -127,10 +127,12 @@ private function build(array $plugins, bool $printBuildCommand, array $allPlugin
127127
128128 private function watch (array $ plugins , bool $ printBuildCommand , array $ allPluginNames ): void
129129 {
130+ $ nodeCompatibilityEnv = $ this ->getNodeCompatibilityEnv ();
131+
130132 $ commandSingle = 'cd ' . PIWIK_INCLUDE_PATH . ' && '
131133 . "BROWSERSLIST_IGNORE_OLD_DATA=1 FORCE_COLOR=1 MATOMO_CURRENT_PLUGIN=%2 \$s "
132134 . 'MATOMO_ALL_PLUGINS= ' . implode (', ' , $ allPluginNames ) . ' '
133- . 'node ' . self ::getVueCliServiceProxyBin () . ' build --mode=development --target lib --name '
135+ . $ nodeCompatibilityEnv . 'node ' . self ::getVueCliServiceProxyBin () . ' build --mode=development --target lib --name '
134136 . "%1 \$s --filename=%1 \$s.development --no-clean %2 \$s/vue/src/index.ts --dest %2 \$s/vue/dist --watch & " ;
135137
136138 $ command = '' ;
@@ -151,11 +153,12 @@ private function buildFiles(string $plugin, bool $printBuildCommand, array $allP
151153 {
152154 $ output = $ this ->getOutput ();
153155 $ pluginDirPath = Manager::getRelativePluginDirectory ($ plugin );
156+ $ nodeCompatibilityEnv = $ this ->getNodeCompatibilityEnv ();
154157
155158 $ command = 'cd ' . PIWIK_INCLUDE_PATH . ' && '
156159 . "BROWSERSLIST_IGNORE_OLD_DATA=1 FORCE_COLOR=1 MATOMO_CURRENT_PLUGIN= $ pluginDirPath "
157160 . 'MATOMO_ALL_PLUGINS= ' . implode (', ' , $ allPluginNames ) . ' '
158- . 'node ' . self ::getVueCliServiceProxyBin () . ' build --target lib --name ' . $ plugin
161+ . $ nodeCompatibilityEnv . 'node ' . self ::getVueCliServiceProxyBin () . ' build --target lib --name ' . $ plugin
159162 . " $ pluginDirPath/vue/src/index.ts --dest $ pluginDirPath/vue/dist " ;
160163
161164 if ($ printBuildCommand ) {
@@ -292,6 +295,21 @@ private function checkNodeJsVersion(): void
292295 }
293296 }
294297
298+ private function getNodeCompatibilityEnv (): string
299+ {
300+ $ nodeVersion = ltrim (trim (`node -v `), 'v ' );
301+ if (version_compare ($ nodeVersion , '17.0.0 ' , '< ' )) {
302+ return '' ;
303+ }
304+
305+ $ nodeOptions = getenv ('NODE_OPTIONS ' ) ?: '' ;
306+ if (strpos ($ nodeOptions , '--openssl-legacy-provider ' ) === false ) {
307+ $ nodeOptions = trim ($ nodeOptions . ' --openssl-legacy-provider ' );
308+ }
309+
310+ return 'NODE_OPTIONS= ' . escapeshellarg ($ nodeOptions ) . ' ' ;
311+ }
312+
295313 private function isTypeScriptRaceConditionInOutput (string $ plugin , string $ concattedOutput ): bool
296314 {
297315 // Console output can contain ANSI escape sequences; remove them first to make regex matching stable.
0 commit comments