From bed3cba38b9eda8b91f7efcb616034eabbc3298b Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Mon, 7 Aug 2023 16:19:32 +0300 Subject: [PATCH] npm installer ignore git versions --- package.json | 2 +- src/npm/executor.ts | 54 ++++++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index b91bd92..76cba28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@squeebot/core", - "version": "3.6.1", + "version": "3.6.2", "description": "Squeebot v3 core for the execution environment", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/npm/executor.ts b/src/npm/executor.ts index 644dd7c..9f4f6ac 100644 --- a/src/npm/executor.ts +++ b/src/npm/executor.ts @@ -9,12 +9,12 @@ import { spawnProcess } from '../util/run'; */ export class NPMExecutor { private installed: Record = {}; - private packageFile: string = path.join(this.environment.path, 'package.json'); + private packageFile: string = path.join( + this.environment.path, + 'package.json' + ); - constructor( - private environment: IEnvironment, - private coreModule: string - ) {} + constructor(private environment: IEnvironment, private coreModule: string) {} /** * Create a package.json file and install the core. @@ -27,7 +27,11 @@ export class NPMExecutor { } // Install core module - const c2 = await spawnProcess('npm', ['install', this.coreModule], this.environment); + const c2 = await spawnProcess( + 'npm', + ['install', this.coreModule], + this.environment + ); if (c2.code > 0) { throw new Error(c2.stderr.join('\n')); } @@ -37,7 +41,7 @@ export class NPMExecutor { * Load a package.json file into memory */ public async loadPackageFile(): Promise { - if (!await fs.pathExists(this.packageFile)) { + if (!(await fs.pathExists(this.packageFile))) { await this.init(); } @@ -54,7 +58,7 @@ export class NPMExecutor { * @param pkg Package name */ public async installPackage(pkg: string): Promise { - if (!await fs.pathExists(this.packageFile)) { + if (!(await fs.pathExists(this.packageFile))) { await this.init(); } @@ -65,16 +69,32 @@ export class NPMExecutor { const pkgRefSplit = pkg.split('@'); const pkgFullName = (spi === 1 ? '@' : '') + pkgRefSplit[spi]; - const pkgVersion = this.removeVersionWildcard(pkgRefSplit[spi + 1]) || 'latest'; + const pkgVersion = + this.removeVersionWildcard(pkgRefSplit[spi + 1]) || 'latest'; const installedVersion = this.installed[pkgFullName]; - if (installedVersion && installedVersion !== 'latest' && pkgVersion !== 'latest') { - const cardless = this.removeVersionWildcard(installedVersion) as string; - if (semver.lte(pkgVersion, cardless)) { + + if (installedVersion) { + // Ignore git or http version + if ( + installedVersion.startsWith('http') || + installedVersion.startsWith('git+') || + installedVersion.startsWith('github:') + ) return; + + if (installedVersion !== 'latest' && pkgVersion !== 'latest') { + const cardless = this.removeVersionWildcard(installedVersion) as string; + if (semver.lte(pkgVersion, cardless)) { + return; + } } } - const { code, stderr, stdout } = await spawnProcess('npm', ['install', pkg], this.environment); + const { code, stderr, stdout } = await spawnProcess( + 'npm', + ['install', pkg], + this.environment + ); if (code > 0) { throw new Error(stderr.join('\n')); } @@ -89,11 +109,15 @@ export class NPMExecutor { * @param pkg Package name */ public async uninstallPackage(pkg: string): Promise { - if (!await fs.pathExists(this.packageFile)) { + if (!(await fs.pathExists(this.packageFile))) { await this.init(); } - const { code, stderr, stdout } = await spawnProcess('npm', ['remove', pkg], this.environment); + const { code, stderr, stdout } = await spawnProcess( + 'npm', + ['remove', pkg], + this.environment + ); if (code > 0) { throw new Error(stderr.join('\n')); }