yarn use --json output
nclazz/depresolve/pipeline/head There was a failure building this commit Details

develop
Niclas Thobaben 2022-11-27 18:18:15 +01:00
parent 299c40e359
commit 432a9e8103
4 changed files with 10 additions and 35 deletions

View File

@ -5,14 +5,8 @@ describe('process-yarn', () => {
describe('parseOutdatedLibraries()', () => {
it('contains correct library for input', () => {
const input = `
yarn outdated v1.22.19
info Color legend :
"<red>" : Major Update backward-incompatible updates
"<yellow>" : Minor Update backward-compatible features
"<green>" : Patch Update backward-compatible bug fixes
Package Current Wanted Latest Package Type URL
@types/jest 23.3.14 23.3.14 29.2.3 devDependencies https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest
Done in 12.56s.
{"type":"info","data":"Color legend : \\n \\"<red>\\" : Major Update backward-incompatible updates \\n \\"<yellow>\\" : Minor Update backward-compatible features \\n \\"<green>\\" : Patch Update backward-compatible bug fixes"}
{"type":"table","data":{"head":["Package","Current","Wanted","Latest","Package Type","URL"],"body":[["@types/jest","23.3.14","23.3.14","29.2.3","devDependencies","https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest"],["jest","28.1.3","28.1.3","29.3.1","devDependencies","https://jestjs.io/"],["jest-junit","14.0.1","14.0.1","15.0.0","devDependencies","https://github.com/jest-community/jest-junit#readme"],["tslint","5.20.1","5.20.1","6.1.3","devDependencies","https://palantir.github.io/tslint"]]}}
`
expect(parseOutdatedLibraries(input, 'package.json')).toEqual(
expect.arrayContaining([

View File

@ -21,7 +21,7 @@ export class NpmResolver implements Resolver<NpmResolverOptions> {
private async resolveWithYarn(): Promise<ResolveResult[]> {
console.log('Run npm resolver using yarn')
try {
child_process.execSync('yarn outdated', { })
child_process.execSync('yarn outdated --json', { })
}catch (e: any) {
// Unfortunately the command throws an error, that we have to catch
const stdout = String(e.stdout)

View File

@ -1,32 +1,13 @@
import { ResolveResult } from '../resolver'
import { compareVersions, parseSemver } from '../helpers'
/**
* yarn outdated v1.22.19
* info Color legend :
* "<red>" : Major Update backward-incompatible updates
* "<yellow>" : Minor Update backward-compatible features
* "<green>" : Patch Update backward-compatible bug fixes
* Package Current Wanted Latest Package Type URL
* @types/jest 23.3.14 23.3.14 29.2.3 devDependencies https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/jest
* jest 28.1.3 28.1.3 29.3.1 devDependencies https://jestjs.io/
* jest-junit 14.0.1 14.0.1 15.0.0 devDependencies https://github.com/jest-community/jest-junit#readme
* tslint 5.20.1 5.20.1 6.1.3 devDependencies https://palantir.github.io/tslint
* Done in 12.56s.
*/
export const parseOutdatedLibraries = (stdout: string, location: string): ResolveResult[] => {
const startHeaders = stdout.indexOf('Package')
const endDone = stdout.indexOf('Done in')
const data = stdout.substring(startHeaders, endDone)
const linesRaw = data.split('\n')
const lines = data.split('\n')
.slice(1, linesRaw.length-1) //Ignore headers and 'Done'
const lines = stdout.split('\n')
.map((line) => line.trim())
.map((line) => line.split(/\s+/).map((item) => item.trim()))
.filter((line) => !!line)
.map((line) => JSON.parse(line))
.filter((item) => item.type !== 'info')
.map((item) => item.data.body as string[])[0]
const results = lines
.map(([name, current, , latest, packageType, url]) => {

View File

@ -47,7 +47,7 @@
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
@ -57,7 +57,7 @@
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
"inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */