Skip to content

Commit

Permalink
chore: move getFileContents to a helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Aug 28, 2020
1 parent aaf9fbc commit 2780cac
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
22 changes: 22 additions & 0 deletions src/lib/get-file-contents.ts
@@ -0,0 +1,22 @@
import * as fs from 'fs';
import * as path from 'path';

export function getFileContents(
root: string,
fileName: string,
): {
content: string;
name: string;
} {
const fullPath = path.resolve(root, fileName);
if (!fs.existsSync(fullPath)) {
throw new Error(
'Manifest ' + fileName + ' not found at location: ' + fileName,
);
}
const content = fs.readFileSync(fullPath, 'utf-8');
return {
content,
name: fileName,
};
}
22 changes: 1 addition & 21 deletions src/lib/plugins/nodejs-plugin/yarn-workspaces-parser.ts
Expand Up @@ -3,14 +3,14 @@ import * as pathUtil from 'path';
import * as _ from '@snyk/lodash';

const debug = baseDebug('snyk:yarn-workspaces');
import * as fs from 'fs';
import * as lockFileParser from 'snyk-nodejs-lockfile-parser';
import * as path from 'path';
import { NoSupportedManifestsFoundError } from '../../errors';
import {
MultiProjectResultCustom,
ScannedProjectCustom,
} from '../get-multi-plugin-result';
import { getFileContents } from '../../get-file-contents';

export async function processYarnWorkspaces(
root: string,
Expand Down Expand Up @@ -102,26 +102,6 @@ export async function processYarnWorkspaces(
return result;
}

function getFileContents(
root: string,
fileName: string,
): {
content: string;
name: string;
} {
const fullPath = path.resolve(root, fileName);
if (!fs.existsSync(fullPath)) {
throw new Error(
'Manifest ' + fileName + ' not found at location: ' + fileName,
);
}
const content = fs.readFileSync(fullPath, 'utf-8');
return {
content,
name: fileName,
};
}

interface YarnWorkspacesMap {
[packageJsonName: string]: {
workspaces: string[];
Expand Down

0 comments on commit 2780cac

Please sign in to comment.