Skip to content

Commit

Permalink
refactor: buildComputedPackage
Browse files Browse the repository at this point in the history
  • Loading branch information
bluelovers committed Jul 31, 2020
1 parent 80d3ccd commit 7e12b92
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 17 deletions.
3 changes: 2 additions & 1 deletion packages/@yarn-tool/yarnlock-diff/lib/diff-service.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="node" />
import { Diff } from "deep-diff";
import { Option } from "fp-ts/lib/Option";
export declare function buildDiff(oldYarnLockContent: string[], newYarnLockContent: string[]): Option<Diff<{}, {}>[]>;
export declare function buildDiff(oldYarnLockContent: (Buffer | string)[], newYarnLockContent: (Buffer | string)[]): Option<Diff<{}, {}>[]>;
11 changes: 3 additions & 8 deletions packages/@yarn-tool/yarnlock-diff/lib/diff-service.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions packages/@yarn-tool/yarnlock-diff/lib/diff-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ import { diff, Diff } from "deep-diff";
import { fromNullable, Option } from "fp-ts/lib/Option";
import { yarnLockParse } from '@yarn-tool/yarnlock-parse/index';
import { computeHashmapOfPackageAndVersionList } from './diff-service/computeHashmapOfPackageAndVersionList';
import { buildComputedPackage } from './diff-service/buildComputedPackage';

export function buildDiff(
oldYarnLockContent: string[],
newYarnLockContent: string[],
oldYarnLockContent: (Buffer | string)[],
newYarnLockContent: (Buffer | string)[],
): Option<Diff<{}, {}>[]>
{
const oldPacakges = oldYarnLockContent
.map(v => yarnLockParse(v))
.reduce(computeHashmapOfPackageAndVersionList, {});
const oldPacakges = buildComputedPackage(oldYarnLockContent);

const newPackages = newYarnLockContent
.map(v => yarnLockParse(v))
.reduce(computeHashmapOfPackageAndVersionList, {});
const newPackages = buildComputedPackage(newYarnLockContent);

return fromNullable(diff(oldPacakges, newPackages));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="node" />
import { IComputedPackage } from './types';
export declare function buildComputedPackage(yarnLockContentList: (Buffer | string)[], alreadyComputedPackage?: IComputedPackage): IComputedPackage;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { IComputedPackage } from './types';
import { yarnLockParse } from '@yarn-tool/yarnlock-parse/index';
import { computeHashmapOfPackageAndVersionList } from './computeHashmapOfPackageAndVersionList';

export function buildComputedPackage(yarnLockContentList: (Buffer | string)[], alreadyComputedPackage: IComputedPackage = {})
{
return yarnLockContentList
.map(v => yarnLockParse(v))
.reduce(computeHashmapOfPackageAndVersionList, alreadyComputedPackage);
}

0 comments on commit 7e12b92

Please sign in to comment.