From 46e00d6fc8795178ef7f4802949099fef716b94e Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Mon, 1 Jan 2024 10:11:11 +0100 Subject: [PATCH] bundles/nodejs: only install nodesource packages if debian does not ship that version --- bundles/nodejs/items.py | 4 ++-- bundles/nodejs/metadata.py | 40 ++++++++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/bundles/nodejs/items.py b/bundles/nodejs/items.py index dc8607c..54f8ca7 100644 --- a/bundles/nodejs/items.py +++ b/bundles/nodejs/items.py @@ -2,8 +2,8 @@ actions = { 'nodejs_install_yarn': { 'command': 'npm install -g yarn@latest', 'unless': 'test -e /usr/lib/node_modules/yarn', - 'needs': { - 'pkg_apt:nodejs', + 'after': { + 'pkg_apt:', }, }, } diff --git a/bundles/nodejs/metadata.py b/bundles/nodejs/metadata.py index 18f0de6..544cd9c 100644 --- a/bundles/nodejs/metadata.py +++ b/bundles/nodejs/metadata.py @@ -2,7 +2,6 @@ defaults = { 'apt': { 'additional_update_commands': { # update npm to latest version - 'npm install -g npm@latest', 'npm install -g yarn@latest', }, 'packages': { @@ -14,20 +13,41 @@ defaults = { }, } +VERSIONS_SHIPPED_BY_DEBIAN = { + 10: 10, + 11: 12, + 12: 18, + 13: 18, +} + @metadata_reactor.provides( 'apt/repos/nodejs/items', ) def nodejs_from_version(metadata): version = metadata.get('nodejs/version') - return { - 'apt': { - 'repos': { - 'nodejs': { - 'items': { - f'deb https://deb.nodesource.com/node_{version}.x {{os_release}} main', - f'deb-src https://deb.nodesource.com/node_{version}.x {{os_release}} main', + + if version != VERSIONS_SHIPPED_BY_DEBIAN[node.os_version[0]]: + return { + 'apt': { + 'additional_update_commands': { + # update npm to latest version + 'npm install -g npm@latest', + }, + 'repos': { + 'nodejs': { + 'items': { + f'deb https://deb.nodesource.com/node_{version}.x {{os_release}} main', + f'deb-src https://deb.nodesource.com/node_{version}.x {{os_release}} main', + }, }, }, }, - }, - } + } + else: + return { + 'apt': { + 'packages': { + 'npm': {}, + }, + }, + }