From 339e3125736403b1942826260dd8e8d01ac532ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Thu, 14 Dec 2023 19:58:25 +0100 Subject: [PATCH] npm installation: Don't require Python if valid worker prebuilt binary is fetched --- CHANGELOG.md | 3 ++- npm-scripts.mjs | 31 ++++++++++++++++++++----------- package.json | 1 - 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 782d84724e..4690870b50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,8 @@ ### NEXT -* worker: Disable RtcLogger usage if not enabled ([PR #1264](https://github.com/versatica/mediasoup/pull/1264)). +* worker: Disable `RtcLogger` usage if not enabled ([PR #1264](https://github.com/versatica/mediasoup/pull/1264)). +* npm installation: Don't require Python if valid worker prebuilt binary is fetched ([PR #1265](https://github.com/versatica/mediasoup/pull/1265)). ### 3.13.11 diff --git a/npm-scripts.mjs b/npm-scripts.mjs index d6754989fc..25c1928a72 100644 --- a/npm-scripts.mjs +++ b/npm-scripts.mjs @@ -47,13 +47,6 @@ async function run() { switch (task) { - case 'preinstall': - { - installInvoke(); - - break; - } - // As per NPM documentation (https://docs.npmjs.com/cli/v9/using-npm/scripts) // `prepare` script: // @@ -167,6 +160,8 @@ async function run() case 'format:worker': { + installInvoke(); + executeCmd(`"${PYTHON}" -m invoke -r worker format`); break; @@ -351,6 +346,8 @@ function buildWorker() { logInfo('buildWorker()'); + installInvoke(); + executeCmd(`"${PYTHON}" -m invoke -r worker mediasoup-worker`); } @@ -358,6 +355,8 @@ function cleanWorkerArtifacts() { logInfo('cleanWorkerArtifacts()'); + installInvoke(); + // Clean build artifacts except `mediasoup-worker`. executeCmd(`"${PYTHON}" -m invoke -r worker clean-build`); // Clean downloaded dependencies. @@ -377,6 +376,8 @@ function lintWorker() { logInfo('lintWorker()'); + installInvoke(); + executeCmd(`"${PYTHON}" -m invoke -r worker lint`); } @@ -384,6 +385,8 @@ function flatcNode() { logInfo('flatcNode()'); + installInvoke(); + // Build flatc if needed. executeCmd(`"${PYTHON}" -m invoke -r worker flatc`); @@ -410,6 +413,8 @@ function flatcWorker() { logInfo('flatcWorker()'); + installInvoke(); + executeCmd(`"${PYTHON}" -m invoke -r worker flatc`); } @@ -431,6 +436,8 @@ function testWorker() { logInfo('testWorker()'); + installInvoke(); + executeCmd(`"${PYTHON}" -m invoke -r worker test`); } @@ -575,6 +582,8 @@ async function downloadPrebuiltWorker() { const resolvedBinPath = path.resolve(WORKER_RELEASE_BIN_PATH); + // This will always fail on purpose, but if status code is 41 then + // it's good. execSync( `"${resolvedBinPath}"`, { @@ -583,15 +592,15 @@ async function downloadPrebuiltWorker() env : {} } ); - - logInfo( - 'downloadPrebuiltWorker() | fetched mediasoup-worker prebuilt binary is valid for current host' - ); } catch (error) { if (error.status === 41) { + logInfo( + 'downloadPrebuiltWorker() | fetched mediasoup-worker prebuilt binary is valid for current host' + ); + resolve(true); } else diff --git a/package.json b/package.json index b31d3cfda5..dcfbfe77ea 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,6 @@ "nodejs" ], "scripts": { - "preinstall": "node npm-scripts.mjs preinstall", "prepare": "node npm-scripts.mjs prepare", "postinstall": "node npm-scripts.mjs postinstall", "typescript:build": "node npm-scripts.mjs typescript:build",