Skip to content

Commit

Permalink
chore: convert yarn util to ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Feb 11, 2020
1 parent 5d10984 commit 2441311
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lib/protect/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const moduleToObject = require('snyk-module');
const semver = require('semver');
const errors = require('../errors/legacy-errors');
const npm = require('../npm');
const yarn = require('../yarn');
const { yarn } = require('../yarn');
const spinner = require('../spinner');
const analytics = require('../analytics');

Expand Down
26 changes: 17 additions & 9 deletions src/lib/yarn.js → src/lib/yarn.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module.exports = yarn;

const debug = require('debug')('snyk');
const exec = require('child_process').exec;

function yarn(method, packages, live, cwd, flags) {
import * as Debug from 'debug';
import { exec } from 'child_process';
import { CustomError } from './errors';

const debug = Debug('snyk');

export function yarn(
method: string,
packages: string[],
live: boolean,
cwd: string,
flags: string[],
) {
flags = flags || [];
if (!packages) {
packages = [];
Expand All @@ -30,7 +37,7 @@ function yarn(method, packages, live, cwd, flags) {
exec(
cmd,
{
cwd: cwd,
cwd,
},
(error, stdout, stderr) => {
if (error) {
Expand All @@ -39,8 +46,9 @@ function yarn(method, packages, live, cwd, flags) {

if (stderr.indexOf('ERR!') !== -1) {
console.error(stderr.trim());
const e = new Error('Yarn update issues: ' + stderr.trim());
e.code = 'FAIL_UPDATE';
const e = new CustomError('Yarn update issues: ' + stderr.trim());
e.strCode = 'FAIL_UPDATE';
e.code = 422;
return reject(e);
}

Expand Down

0 comments on commit 2441311

Please sign in to comment.