From ce376824eeac2db23a17e27b91928bd1e92af55f Mon Sep 17 00:00:00 2001 From: Michael Kriese Date: Tue, 8 Aug 2023 07:53:01 +0200 Subject: [PATCH] feat(node): convert npm tools to typescript (#1285) --- src/cli/install-tool/index.ts | 16 ++ .../install-tool/install-tool-base.service.ts | 11 +- src/cli/install-tool/install-tool.service.ts | 15 +- src/cli/prepare-tool/prepare-tool.service.ts | 5 + src/cli/services/version.service.ts | 2 +- src/cli/tools/flux/index.ts | 4 - src/cli/tools/index.ts | 10 ++ src/cli/tools/node/npm.ts | 73 +++++++++ src/cli/tools/node/utils.ts | 139 ++++++++++++++++++ src/cli/utils/versions.ts | 6 +- .../local/containerbase/tools/v2/corepack.sh | 36 ----- src/usr/local/containerbase/tools/v2/lerna.sh | 35 ----- src/usr/local/containerbase/tools/v2/node.sh | 36 +++-- src/usr/local/containerbase/tools/v2/npm.sh | 37 ----- src/usr/local/containerbase/tools/v2/pnpm.sh | 35 ----- .../local/containerbase/tools/v2/renovate.sh | 43 ------ .../local/containerbase/tools/v2/yarn-slim.sh | 41 ------ src/usr/local/containerbase/tools/v2/yarn.sh | 35 ----- test/node/Dockerfile | 14 +- 19 files changed, 299 insertions(+), 294 deletions(-) create mode 100644 src/cli/tools/index.ts create mode 100644 src/cli/tools/node/npm.ts create mode 100644 src/cli/tools/node/utils.ts delete mode 100644 src/usr/local/containerbase/tools/v2/corepack.sh delete mode 100644 src/usr/local/containerbase/tools/v2/lerna.sh delete mode 100644 src/usr/local/containerbase/tools/v2/npm.sh delete mode 100644 src/usr/local/containerbase/tools/v2/pnpm.sh delete mode 100644 src/usr/local/containerbase/tools/v2/renovate.sh delete mode 100644 src/usr/local/containerbase/tools/v2/yarn-slim.sh delete mode 100644 src/usr/local/containerbase/tools/v2/yarn.sh diff --git a/src/cli/install-tool/index.ts b/src/cli/install-tool/index.ts index bbff59e804..dcd154d467 100644 --- a/src/cli/install-tool/index.ts +++ b/src/cli/install-tool/index.ts @@ -3,6 +3,15 @@ import { rootContainer } from '../services'; import { InstallDartService } from '../tools/dart'; import { InstallDockerService } from '../tools/docker'; import { InstallFluxService } from '../tools/flux'; +import { + InstallCorepackService, + InstallLernaService, + InstallNpmService, + InstallPnpmService, + InstallRenovateService, + InstallYarnService, + InstallYarnSlimService, +} from '../tools/node/npm'; import { logger } from '../utils'; import { InstallLegacyToolService } from './install-legacy-tool.service'; import { INSTALL_TOOL_TOKEN, InstallToolService } from './install-tool.service'; @@ -17,9 +26,16 @@ function prepareContainer(): Container { container.bind(InstallLegacyToolService).toSelf(); // tool services + container.bind(INSTALL_TOOL_TOKEN).to(InstallCorepackService); container.bind(INSTALL_TOOL_TOKEN).to(InstallDockerService); container.bind(INSTALL_TOOL_TOKEN).to(InstallDartService); container.bind(INSTALL_TOOL_TOKEN).to(InstallFluxService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallLernaService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallNpmService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallPnpmService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallRenovateService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallYarnService); + container.bind(INSTALL_TOOL_TOKEN).to(InstallYarnSlimService); logger.trace('preparing container done'); return container; diff --git a/src/cli/install-tool/install-tool-base.service.ts b/src/cli/install-tool/install-tool-base.service.ts index 418b66a79d..3edf1457f6 100644 --- a/src/cli/install-tool/install-tool-base.service.ts +++ b/src/cli/install-tool/install-tool-base.service.ts @@ -2,6 +2,7 @@ import { chmod, chown, stat, writeFile } from 'node:fs/promises'; import { join } from 'node:path'; import { injectable } from 'inversify'; import type { EnvService, PathService } from '../services'; +import { NoPrepareTools } from '../tools'; import { fileRights, isValid, logger } from '../utils'; export interface ShellWrapperConfig { @@ -33,7 +34,11 @@ export abstract class InstallToolBaseService { abstract link(version: string): Promise; needsPrepare(): boolean { - return true; + return !NoPrepareTools.includes(this.name); + } + + postInstall(_version: string): Promise { + return Promise.resolve(); } test(_version: string): Promise { @@ -44,8 +49,8 @@ export abstract class InstallToolBaseService { return this.name; } - validate(version: string): boolean { - return isValid(version); + validate(version: string): Promise { + return Promise.resolve(isValid(version)); } protected async shellwrapper({ diff --git a/src/cli/install-tool/install-tool.service.ts b/src/cli/install-tool/install-tool.service.ts index 04773368e4..cfca978513 100644 --- a/src/cli/install-tool/install-tool.service.ts +++ b/src/cli/install-tool/install-tool.service.ts @@ -52,8 +52,8 @@ export class InstallToolService { } logger.debug({ tool }, 'validate tool'); - if (!toolSvc.validate(version)) { - logger.fatal({ tool }, 'tool version not supported'); + if (!(await toolSvc.validate(version))) { + logger.fatal({ tool, version }, 'tool version not supported'); return 1; } @@ -80,11 +80,16 @@ export class InstallToolService { ): Promise { if (version === (await this.versionSvc.find(toolSvc.name))) { logger.debug({ tool: toolSvc.name }, 'tool already linked'); - return; + } else { + logger.debug({ tool: toolSvc.name }, 'link tool'); + await toolSvc.link(version); } - logger.debug({ tool: toolSvc.name }, 'link tool'); - await toolSvc.link(version); + await this.versionSvc.update(toolSvc.name, version); + + logger.debug({ tool: toolSvc.name }, 'post-install tool'); + await toolSvc.postInstall(version); + logger.debug({ tool: toolSvc.name }, 'test tool'); if (!this.envSvc.skipTests) { await toolSvc.test(version); diff --git a/src/cli/prepare-tool/prepare-tool.service.ts b/src/cli/prepare-tool/prepare-tool.service.ts index 4dadcd91a2..a8809f9310 100644 --- a/src/cli/prepare-tool/prepare-tool.service.ts +++ b/src/cli/prepare-tool/prepare-tool.service.ts @@ -1,5 +1,6 @@ import { inject, injectable, multiInject, optional } from 'inversify'; import { EnvService, PathService } from '../services'; +import { NoPrepareTools } from '../tools'; import { logger } from '../utils'; import { PrepareLegacyToolsService } from './prepare-legacy-tools.service'; import type { PrepareToolBaseService } from './prepare-tool-base.service'; @@ -52,6 +53,10 @@ export class PrepareToolService { logger.info({ tool }, 'tool ignored'); continue; } + if (NoPrepareTools.includes(tool)) { + logger.info({ tool }, 'tool does not need to be prepared'); + continue; + } const toolSvc = this.toolSvcs.find((t) => t.name === tool); if (toolSvc) { if (await this.pathSvc.findToolPath(tool)) { diff --git a/src/cli/services/version.service.ts b/src/cli/services/version.service.ts index 6374c469cb..097288ae18 100644 --- a/src/cli/services/version.service.ts +++ b/src/cli/services/version.service.ts @@ -11,7 +11,7 @@ export class VersionService { async find(tool: string): Promise { const path = join(this.pathSvc.versionPath, tool); try { - return (await readFile(path, { encoding: 'utf8' })) ?? null; + return (await readFile(path, { encoding: 'utf8' })).trim() ?? null; } catch (err) { if (err instanceof Error && err.code === 'ENOENT') { logger.debug({ tool }, 'tool version not found'); diff --git a/src/cli/tools/flux/index.ts b/src/cli/tools/flux/index.ts index 8da447c9f6..cdf5d53265 100644 --- a/src/cli/tools/flux/index.ts +++ b/src/cli/tools/flux/index.ts @@ -67,10 +67,6 @@ export class InstallFluxService extends InstallToolBaseService { await this.shellwrapper({ srcDir: src }); } - override needsPrepare(): boolean { - return false; - } - override async test(_version: string): Promise { await execa('flux', ['--version'], { stdio: 'inherit' }); } diff --git a/src/cli/tools/index.ts b/src/cli/tools/index.ts new file mode 100644 index 0000000000..c683437369 --- /dev/null +++ b/src/cli/tools/index.ts @@ -0,0 +1,10 @@ +export const NoPrepareTools = [ + 'corepack', + 'flux', + 'lerna', + 'npm', + 'pnpm', + 'renovate', + 'yarn', + 'yarn-slim', +]; diff --git a/src/cli/tools/node/npm.ts b/src/cli/tools/node/npm.ts new file mode 100644 index 0000000000..d61691f6a8 --- /dev/null +++ b/src/cli/tools/node/npm.ts @@ -0,0 +1,73 @@ +import { join } from 'node:path'; +import { execa } from 'execa'; +import { injectable } from 'inversify'; +import { InstallNpmBaseService } from './utils'; + +@injectable() +export class InstallCorepackService extends InstallNpmBaseService { + override name: string = 'corepack'; + + override async postInstall(version: string): Promise { + await super.postInstall(version); + + const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin'); + await this.shellwrapper({ srcDir: src, name: 'pnpm' }); + await this.shellwrapper({ srcDir: src, name: 'yarn' }); + } +} + +@injectable() +export class InstallLernaService extends InstallNpmBaseService { + override readonly name: string = 'lerna'; +} + +@injectable() +export class InstallNpmService extends InstallNpmBaseService { + override readonly name: string = 'npm'; +} + +@injectable() +export class InstallPnpmService extends InstallNpmBaseService { + override readonly name: string = 'pnpm'; +} + +@injectable() +export class InstallRenovateService extends InstallNpmBaseService { + override readonly name: string = 'renovate'; + + override async postInstall(version: string): Promise { + await super.postInstall(version); + + const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin'); + await this.shellwrapper({ srcDir: src, name: 'renovate-config-validator' }); + } +} + +@injectable() +export class InstallYarnService extends InstallNpmBaseService { + override readonly name: string = 'yarn'; +} + +@injectable() +export class InstallYarnSlimService extends InstallNpmBaseService { + override readonly name: string = 'yarn-slim'; + + protected override get tool(): string { + return 'yarn'; + } + + override async install(version: string): Promise { + await super.install(version); + // TODO: replace with javascript + const prefix = await this.pathSvc.findVersionedToolPath(this.name, version); + await execa( + 'sed', + [ + '-i', + 's/ steps,/ steps.slice(0,1),/', + `${prefix}/node_modules/yarn/lib/cli.js`, + ], + { stdio: 'inherit' } + ); + } +} diff --git a/src/cli/tools/node/utils.ts b/src/cli/tools/node/utils.ts new file mode 100644 index 0000000000..ff8f1d342e --- /dev/null +++ b/src/cli/tools/node/utils.ts @@ -0,0 +1,139 @@ +import fs from 'node:fs/promises'; +import { join } from 'node:path'; +import { env as penv } from 'node:process'; +import { execa } from 'execa'; +import { inject, injectable } from 'inversify'; +import { InstallToolBaseService } from '../../install-tool/install-tool-base.service'; +import { EnvService, PathService, VersionService } from '../../services'; +import { parse } from '../../utils'; + +const defaultRegistry = 'https://registry.npmjs.org/'; + +@injectable() +export abstract class InstallNpmBaseService extends InstallToolBaseService { + protected get tool(): string { + return this.name; + } + + constructor( + @inject(EnvService) envSvc: EnvService, + @inject(PathService) pathSvc: PathService, + @inject(VersionService) protected versionSvc: VersionService + ) { + super(pathSvc, envSvc); + } + + override async install(version: string): Promise { + const npm = await this.getNodeNpm(); + const tmp = await fs.mkdtemp( + join(this.pathSvc.tmpDir, 'containerbase-npm-') + ); + const env: NodeJS.ProcessEnv = { + NO_UPDATE_NOTIFIER: '1', + npm_config_update_notifier: 'false', + npm_config_fund: 'false', + }; + + if (!penv.npm_config_cache && !penv.NPM_CONFIG_CACHE) { + env.npm_config_cache = tmp; + } + + if (!penv.npm_config_registry && !penv.NPM_CONFIG_REGISTRY) { + const registry = this.envSvc.replaceUrl(defaultRegistry); + if (registry !== defaultRegistry) { + env.npm_config_registry = registry; + } + } + + // TODO: create recursive + if (!(await this.pathSvc.findToolPath(this.name))) { + await this.pathSvc.createToolPath(this.name); + } + + const prefix = await this.pathSvc.createVersionedToolPath( + this.name, + version + ); + + await execa( + npm, + [ + 'install', + `${this.tool}@${version}`, + '--save-exact', + '--no-audit', + '--prefix', + prefix, + '--cache', + tmp, + '--silent', + ], + { stdio: ['inherit', 'inherit', 1], env } + ); + + await fs.symlink(`${prefix}/node_modules/.bin`, `${prefix}/bin`); + + const ver = parse(version)!; + + if (this.name === 'npm' && ver.major < 7) { + // update to latest node-gyp to fully support python3 + await execa( + join(prefix, 'bin/npm'), + [ + 'explore', + 'npm', + '--prefix', + prefix, + '--silent', + '--', + 'npm', + 'install', + 'node-gyp@latest', + '--no-audit', + '--cache', + tmp, + '--silent', + ], + { stdio: ['inherit', 'inherit', 1], env } + ); + } + + await fs.rm(tmp, { recursive: true, force: true }); + await fs.rm(join(this.envSvc.home, '.npm/_logs'), { + recursive: true, + force: true, + }); + } + + override async link(version: string): Promise { + await this.postInstall(version); + } + + override async postInstall(version: string): Promise { + const src = join(this.pathSvc.versionedToolPath(this.name, version), 'bin'); + + await this.shellwrapper({ srcDir: src, name: this.tool }); + } + + override async test(_version: string): Promise { + await execa(this.tool, ['--version'], { stdio: 'inherit' }); + } + + override async validate(version: string): Promise { + if (!(await super.validate(version))) { + return false; + } + + return (await this.versionSvc.find('node')) !== null; + } + + protected async getNodeNpm(): Promise { + const nodeVersion = await this.versionSvc.find('node'); + + if (!nodeVersion) { + throw new Error('Node not installed'); + } + + return join(this.pathSvc.versionedToolPath('node', nodeVersion), 'bin/npm'); + } +} diff --git a/src/cli/utils/versions.ts b/src/cli/utils/versions.ts index 26354b4cce..cdf138c6b6 100644 --- a/src/cli/utils/versions.ts +++ b/src/cli/utils/versions.ts @@ -1,10 +1,14 @@ -import semver from 'semver'; +import semver, { type SemVer } from 'semver'; import { type StrictValidator, makeValidator } from 'typanion'; export function isValid(version: string): boolean { return semver.valid(version) !== null; } +export function parse(version: string): SemVer | null { + return semver.parse(version); +} + export function validateSemver(): StrictValidator { return makeValidator({ test: (value, state): value is string => { diff --git a/src/usr/local/containerbase/tools/v2/corepack.sh b/src/usr/local/containerbase/tools/v2/corepack.sh deleted file mode 100644 index 378cd6d2f4..0000000000 --- a/src/usr/local/containerbase/tools/v2/corepack.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - link_wrapper "${TOOL_NAME}" "$(find_versioned_tool_path)/bin" - [[ -n $SKIP_VERSION ]] || corepack --version - post_install -} - -function post_install () { - corepack enable --install-directory "$(get_bin_path)" -} diff --git a/src/usr/local/containerbase/tools/v2/lerna.sh b/src/usr/local/containerbase/tools/v2/lerna.sh deleted file mode 100644 index 8f44664aa6..0000000000 --- a/src/usr/local/containerbase/tools/v2/lerna.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - versioned_tool_path=$(create_versioned_tool_path) - - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - local versioned_tool_path - versioned_tool_path=$(find_versioned_tool_path) - - link_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" - [[ -n $SKIP_VERSION ]] || lerna --version -} diff --git a/src/usr/local/containerbase/tools/v2/node.sh b/src/usr/local/containerbase/tools/v2/node.sh index 4172cbbe79..8fe0b230f0 100644 --- a/src/usr/local/containerbase/tools/v2/node.sh +++ b/src/usr/local/containerbase/tools/v2/node.sh @@ -38,7 +38,6 @@ function check_tool_requirements () { function install_tool () { local versioned_tool_path - local npm # temp npm executable local arch=${ARCHITECTURE} local name=${TOOL_NAME} local version=${TOOL_VERSION} @@ -92,7 +91,6 @@ function install_tool () { # init temp dir npm_init - npm=${versioned_tool_path}/bin/npm if [[ $(is_root) -eq 0 ]]; then # redirect root install @@ -105,13 +103,10 @@ function install_tool () { prepare_global_config "${USER_HOME}/.npm-global" fi - # required for npm - link_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" - if [[ ${MAJOR} -lt 15 ]]; then echo "updating node-gyp" # update to latest node-gyp to fully support python3 - $npm explore npm -g --prefix "$versioned_tool_path" --silent -- "$npm" install node-gyp@latest --no-audit --cache "${NPM_CONFIG_CACHE}" --silent 2>&1 + PATH=${versioned_tool_path}/bin:$PATH npm explore npm -g --prefix "$versioned_tool_path" --silent -- "npm" install node-gyp@latest --no-audit --cache "${NPM_CONFIG_CACHE}" --silent 2>&1 fi # clean temp dir @@ -126,16 +121,12 @@ function link_tool () { reset_tool_env - link_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" - if [[ ! -f "$(get_bin_path)/npm" ]]; then - link_wrapper npm "${versioned_tool_path}/bin" - link_wrapper npx "${versioned_tool_path}/bin" - fi + post_install export_tool_path "${USER_HOME}/.npm-global/bin" export_tool_env NO_UPDATE_NOTIFIER 1 - export_tool_env NPM_CONFIG_UPDATE_NOTIFIER false - export_tool_env NPM_CONFIG_FUND false + export_tool_env npm_config_update_notifier false + export_tool_env npm_config_fund false tool_env=$(find_tool_env) @@ -143,10 +134,27 @@ function link_tool () { cat >> "$tool_env" <<- EOM # openshift override unknown user home if [ "\${EUID}" != 0 ] && [ "\${EUID}" != ${USER_ID} ]; then - export NPM_CONFIG_PREFIX="${USER_HOME}/.npm-global" + export npm_config_prefix="${USER_HOME}/.npm-global" fi EOM [[ -n $SKIP_VERSION ]] || echo "node: $(node --version) $(command -v node)" [[ -n $SKIP_VERSION ]] || echo "npm: $(npm --version) $(command -v npm)" + if [[ -n $SKIP_VERSION && -e "${versioned_tool_path}/bin/corepack" ]];then + echo "corepack: $(corepack --version) $(command -v corepack)" + fi +} + + + +function post_install () { + local versioned_tool_path + versioned_tool_path=$(find_versioned_tool_path) + + shell_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" + shell_wrapper npm "${versioned_tool_path}/bin" + shell_wrapper npx "${versioned_tool_path}/bin" + if [[ -e "${versioned_tool_path}/bin/corepack" ]];then + shell_wrapper corepack "${versioned_tool_path}/bin" + fi } diff --git a/src/usr/local/containerbase/tools/v2/npm.sh b/src/usr/local/containerbase/tools/v2/npm.sh deleted file mode 100644 index 4e9c76f76e..0000000000 --- a/src/usr/local/containerbase/tools/v2/npm.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "minor" -} - -function install_tool () { - local versioned_tool_path - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - local versioned_tool_path - versioned_tool_path=$(find_versioned_tool_path) - - link_wrapper "${TOOL_NAME}" "${versioned_tool_path}/bin" - link_wrapper npx "${versioned_tool_path}/bin" - - hash -d npm npx 2>/dev/null || true - [[ -n $SKIP_VERSION ]] || npm --version -} diff --git a/src/usr/local/containerbase/tools/v2/pnpm.sh b/src/usr/local/containerbase/tools/v2/pnpm.sh deleted file mode 100644 index 547d5c2141..0000000000 --- a/src/usr/local/containerbase/tools/v2/pnpm.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - post_install - [[ -n $SKIP_VERSION ]] || pnpm --version -} - -function post_install () { - link_wrapper "${TOOL_NAME}" "$(find_versioned_tool_path)/bin" -} diff --git a/src/usr/local/containerbase/tools/v2/renovate.sh b/src/usr/local/containerbase/tools/v2/renovate.sh deleted file mode 100644 index 0530e93109..0000000000 --- a/src/usr/local/containerbase/tools/v2/renovate.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - local node_version - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - node_version="$(get_tool_version node)" - - # pin node version - sed -i --follow-symlinks "1 s:.*:#\!\/opt\/containerbase\/tools\/node\/${node_version}\/bin\/node:" "${versioned_tool_path}/bin/renovate"; - sed -i --follow-symlinks "1 s:.*:#\!\/opt\/containerbase\/tools\/node\/${node_version}\/bin\/node:" "${versioned_tool_path}/bin/renovate-config-validator"; - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - post_install - [[ -n $SKIP_VERSION ]] || renovate --version -} - -function post_install () { - shell_wrapper "${TOOL_NAME}" "$(find_versioned_tool_path)/bin" - shell_wrapper "${TOOL_NAME}-config-validator" "$(find_versioned_tool_path)/bin" -} diff --git a/src/usr/local/containerbase/tools/v2/yarn-slim.sh b/src/usr/local/containerbase/tools/v2/yarn-slim.sh deleted file mode 100644 index 226595f22b..0000000000 --- a/src/usr/local/containerbase/tools/v2/yarn-slim.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - local npm - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - npm="$(get_node_npm)" - - npm_init - $npm install "yarn@${TOOL_VERSION}" --global --no-audit --prefix "${versioned_tool_path}" --cache "${NPM_CONFIG_CACHE}" 2>&1 - npm_clean - - # patch yarn - sed -i 's/ steps,/ steps.slice(0,1),/' "${versioned_tool_path}/lib/node_modules/yarn/lib/cli.js" - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi - -} - -function link_tool () { - post_install - [[ -n $SKIP_VERSION ]] || yarn --version -} - -function post_install () { - link_wrapper yarn "$(find_versioned_tool_path)/bin/yarn" -} diff --git a/src/usr/local/containerbase/tools/v2/yarn.sh b/src/usr/local/containerbase/tools/v2/yarn.sh deleted file mode 100644 index 2d53ce3ed3..0000000000 --- a/src/usr/local/containerbase/tools/v2/yarn.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -function check_tool_requirements () { - check_command node - check_semver "$TOOL_VERSION" "all" -} - -function install_tool () { - local versioned_tool_path - versioned_tool_path=$(create_versioned_tool_path) - - if [[ $(restore_folder_from_cache "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}") -ne 0 ]]; then - # restore from cache not possible - # either not in cache or error, install - - # shellcheck source=/dev/null - . "$(get_containerbase_path)/utils/node.sh" - - npm_init - npm_install - npm_clean - - # store in cache - cache_folder "${versioned_tool_path}" "${TOOL_NAME}/${TOOL_VERSION}" - fi -} - -function link_tool () { - post_install - [[ -n $SKIP_VERSION ]] || yarn --version -} - -function post_install () { - link_wrapper "${TOOL_NAME}" "$(find_versioned_tool_path)/bin" -} diff --git a/test/node/Dockerfile b/test/node/Dockerfile index f7a8ab178e..54997b51c8 100644 --- a/test/node/Dockerfile +++ b/test/node/Dockerfile @@ -69,7 +69,7 @@ RUN set -ex; \ [ "$(command -v yarn)" = "/home/${USER_NAME}/.npm-global/bin/yarn" ] && echo "works" || exit 1; \ yarn --version; -RUN set -ex; cd a; yarn +RUN set -ex; cd a; yarn; [[ -d node_modules/.bin ]] || exit 1 SHELL [ "/bin/sh", "-c" ] @@ -164,11 +164,11 @@ RUN npm --version | grep '8.0.0' USER 1000 -# don't update!! Should not overwrite npm +# don't update!! Should overwrite npm RUN install-tool node 18.13.0 RUN set -ex; npm --version -RUN set -ex; npm --version | grep '8.0.0' +RUN set -ex; npm --version | grep '8.19.3' # don't update!! RUN install-tool npm 7.24.2 @@ -227,7 +227,7 @@ FROM build as testh RUN install-tool yarn-slim 1.22.19 RUN set -ex; yarn --version -RUN set -ex; cd a; yarn install +RUN set -ex; cd a; yarn install; [[ ! -d node_modules/.bin ]] || exit 1 #-------------------------------------- # test: npm (install-tool npm, node v14) @@ -338,6 +338,9 @@ RUN set -ex; \ FROM build as testl SHELL [ "/bin/sh", "-c" ] +RUN set -ex; \ + [ "$(command -v corepack)" = "/usr/local/bin/corepack" ] && echo "works" || exit 1; + USER root @@ -438,6 +441,9 @@ ARG PNPM_VERSION=6.0.0 ARG YARN_VERSION=1.22.0 ARG YARN_SLIM_VERSION=1.22.5 +ENV URL_REPLACE_0_FROM=https://registry.npmjs.org/ +ENV URL_REPLACE_0_TO=https://registry.yarnpkg.com/ + RUN install-tool pnpm RUN install-tool yarn RUN install-tool yarn-slim