diff --git a/CHANGELOG.md b/CHANGELOG.md index 51fc900..5b434f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # main (unreleased) +# 0.1.2 +- [[bugfix]: update shape of data returned from yarn](https://github.com/ombulabs/depngn/pull/5) + # 0.1.1 - [[bugfix]: specify depth in npm ls to avoid errors from uninstalled peerDeps](https://github.com/ombulabs/depngn/pull/1) diff --git a/package-lock.json b/package-lock.json index 1e909c5..89d0413 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "depngn", - "version": "0.1.1", + "version": "0.1.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "depngn", - "version": "0.1.0", + "version": "0.1.2", "license": "MIT", "dependencies": { "arg": "^5.0.2", diff --git a/package.json b/package.json index b061bf2..e9e3db5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "depngn", - "version": "0.1.1", + "version": "0.1.2", "description": "Determine the compatibility of your packages with a given Node version", "type": "module", "main": "./dist/index.cjs", diff --git a/src/queries/getEngines.ts b/src/queries/getEngines.ts index 9b05986..c5b2675 100644 --- a/src/queries/getEngines.ts +++ b/src/queries/getEngines.ts @@ -1,6 +1,6 @@ -import { asyncExec, execWithLog } from "../cli/exec"; -import { Managers, viewEnginesCommand } from "./getPackageManager"; -import { PackageList } from "../types"; +import { asyncExec, execWithLog } from '../cli/exec'; +import { Managers, viewEnginesCommand } from './getPackageManager'; +import { PackageList } from '../types'; export async function getEngines(deps: PackageList, manager: Managers) { const command = viewEnginesCommand(manager); @@ -8,10 +8,10 @@ export async function getEngines(deps: PackageList, manager: Managers) { const engines = await asyncExec( `${command} ${dep}@${deps[dep].version} engines --json` ); - const version = engines.stdout ? JSON.parse(engines.stdout) : ''; + const range = parseEngines(engines, manager); return { package: dep, - range: version.node ? version.node.replace(' ', '') : '', + range, }; }); @@ -20,3 +20,23 @@ export async function getEngines(deps: PackageList, manager: Managers) { async () => await Promise.all(depsArray) ); } + +function parseEngines( + engines: { stdout: string; stderr: string }, + manager: Managers +) { + const res = engines.stdout ? JSON.parse(engines.stdout) : {}; + switch (manager) { + case 'npm': + return res.node ? res.node : ''; + + case 'yarn': + return res.data?.node ? res.data.node : ''; + + default: + const wrong = manager as never; + throw new Error( + `This error shouldn't happen, but somehow an invalid package manager made it through checks: ${wrong}.` + ); + } +} diff --git a/src/queries/getPackageData.ts b/src/queries/getPackageData.ts index b8cd35d..11b8331 100644 --- a/src/queries/getPackageData.ts +++ b/src/queries/getPackageData.ts @@ -14,10 +14,10 @@ function isCompatible(nodeVersion: string, depRange: string) { const logicalOrRegEx = /||/; if (depRange && logicalOrRegEx.test(depRange)) { - const rangeArray = depRange.split('||').map((range) => range.trim()); + const rangeArray = depRange.split('||').map((range) => range.replaceAll(' ', '')); compatible = rangeArray.some((range) => satisfies(nodeVersion, range)); } else { - compatible = satisfies(nodeVersion, depRange); + compatible = satisfies(nodeVersion, depRange.replaceAll(' ', '')); } return compatible; }