Skip to content
This repository was archived by the owner on Nov 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #11 from iOffice/dep-updates
Browse files Browse the repository at this point in the history
Dep updates
  • Loading branch information
Manuel Lopez authored Apr 20, 2020
2 parents 880cda6 + 656224a commit 46a842f
Show file tree
Hide file tree
Showing 11 changed files with 1,126 additions and 867 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js

node_js:
- "8"
- "10"

branches:
Expand Down
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,40 @@
"@ioffice/ci-builder": "0.3.3",
"@ioffice/fp": "0.2.0",
"@types/chai": "4.1.7",
"@types/colors": "1.2.1",
"@types/eslint": "4.16.6",
"@types/fs-extra": "8.0.0",
"@types/inquirer": "6.0.3",
"@types/karma": "3.0.3",
"@types/karma": "5.0.0",
"@types/mocha": "7.0.2",
"@types/node": "12.6.2",
"@types/puppeteer": "1.19.0",
"@types/semver": "6.0.1",
"@types/sinon": "7.0.13",
"@types/webpack": "4.32.1",
"@typescript-eslint/eslint-plugin": "1.12.0",
"@typescript-eslint/parser": "1.12.0",
"@types/webpack": "4.41.12",
"@typescript-eslint/eslint-plugin": "2.28.0",
"@typescript-eslint/parser": "2.28.0",
"chai": "4.2.0",
"colors": "1.3.3",
"eslint": "6.0.1",
"eslint": "6.8.0",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-prettier": "3.1.0",
"fs-extra": "8.1.0",
"fs-extra": "9.0.0",
"inquirer": "6.5.0",
"karma": "4.2.0",
"karma": "5.0.2",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "3.0.0",
"karma-mocha": "1.3.0",
"karma-mocha": "2.0.0",
"karma-spec-reporter": "0.0.32",
"mocha": "7.1.1",
"mocked-env": "1.3.1",
"prettier": "1.18.2",
"prettier": "2.0.4",
"puppeteer": "1.19.0",
"semver": "6.2.0",
"sinon": "7.3.2",
"ts-loader": "6.0.4",
"typescript": "3.5.3",
"webpack": "4.41.5",
"webpack-cli": "3.3.6"
"ts-loader": "7.0.0",
"typescript": "3.8.3",
"webpack": "4.42.1",
"webpack-cli": "3.3.11"
},
"peerDependencies": {},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion src/main/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ abstract class Either<A, B> implements Iterable<B> {
* Equivalent to `flatMap(id => id)`
*/
flatten<A1, B1>(): Either<A1, B1> {
return this.flatMap(id => (id as unknown) as Either<A1, B1>);
return this.flatMap((id) => (id as unknown) as Either<A1, B1>);
}

/**
Expand Down Expand Up @@ -289,6 +289,7 @@ abstract class Either<A, B> implements Iterable<B> {
*/
[Symbol.iterator](): Iterator<B> {
let isDone = false;
// eslint-disable-next-line @typescript-eslint/no-this-alias
const instance = this;
return {
next(): IteratorResult<B> {
Expand Down
6 changes: 3 additions & 3 deletions src/main/Matcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Constructor<T> = { new (): T };
type TypedTuple<B, U> = [Constructor<B>, (val: B) => U];

const match = <T, U>(value: T, ...options: Tuple<T, U>[]): Option<U> => {
for (let entry of options) {
for (const entry of options) {
if (entry[0] === value) return Some(entry[1]());
}
return None;
Expand All @@ -14,7 +14,7 @@ const match = <T, U>(value: T, ...options: Tuple<T, U>[]): Option<U> => {
const ifElseChain = <A>(
...options: [boolean, (_?: unknown) => A][]
): Option<A> => {
for (let entry of options) {
for (const entry of options) {
if (entry[0]) return Some(entry[1]());
}
return None;
Expand Down Expand Up @@ -66,7 +66,7 @@ function matchType<B, U, T>(
value: T,
...options: TypedTuple<B, U>[]
): Option<U> {
for (let entry of options) {
for (const entry of options) {
if (value instanceof ((entry[0] as unknown) as Function)) {
return Some(entry[1]((value as unknown) as B));
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/Option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ abstract class OptionW<A> {
* no way at the moment to let Typescript know this.
*/
flatten<B>(): Option<B> {
return this.flatMap<B>(id => {
return this.flatMap<B>((id) => {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return id instanceof OptionW ? id : Some<B>(id as any);
});
Expand Down Expand Up @@ -187,7 +187,11 @@ abstract class OptionW<A> {
const item = this.get();
const callback = item['subscribe'] || item['then'];
if (callback) {
callback.call(item, (res: D) => fn(Maybe(res)), () => fn(None));
callback.call(
item,
(res: D) => fn(Maybe(res)),
() => fn(None),
);
}
}
}
Expand Down
32 changes: 17 additions & 15 deletions src/test/Either.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ describe('Either', () => {

it('(mapIfLeft) should map left values', () => {
const left: Either<string, number> = Left('left');
const mapped: Either<string, number> = left.mapIfLeft(x => `${x}: mapped`);
const mapped: Either<string, number> = left.mapIfLeft(
(x) => `${x}: mapped`,
);
compareValues([
[left.isLeft, true, 'left should be Left'],
[mapped.isLeft, true, 'right should be Right'],
Expand All @@ -98,54 +100,54 @@ describe('Either', () => {
compareValues([
[
Left(obj.so)
.map(x => `string: ${x}`)
.map((x) => `string: ${x}`)
.toOption(),
None,
],
[Right(obj.s).map(x => `string: ${x}`).value, 'string: value'],
[Right(obj.s).map((x) => `string: ${x}`).value, 'string: value'],
[
Left<number, number>(obj.no)
.map(x => x + 2)
.map((x) => x + 2)
.toOption(),
None,
],
[Right(obj.n).map(x => x + 2).value, 7],
[Right(obj.n).map((x) => x + 2).value, 7],
[
Left(obj.bo)
.map(x => (x ? 100 : 10))
.map((x) => (x ? 100 : 10))
.toOption(),
None,
],
[Right(obj.b).map(x => (x ? 100 : 10)).value, 100],
[Right(obj.b).map((x) => (x ? 100 : 10)).value, 100],
[
Maybe(obj.a)
.toRight(new Error('empty'))
.map(x => x.length + 1)
.map((x) => x.length + 1)
.toOption(),
None,
],
[Right(obj.b).map(x => x).value, true],
[Right(obj.b).map((x) => x).value, true],
[
Maybe(roomA.type)
.toRight(() => new Error('no type'))
.map(x => Maybe(x.name))
.map(x => x.map(_ => _.trim()).getOrElse(''))
.map((x) => Maybe(x.name))
.map((x) => x.map((_) => _.trim()).getOrElse(''))
.getOrElse('none'),
'none',
],
[
Maybe(roomB.type)
.toRight(() => new Error('no type'))
.map(x => Maybe(x.name))
.map(x => x.map(_ => _.trim()).getOrElse('almost got it'))
.map((x) => Maybe(x.name))
.map((x) => x.map((_) => _.trim()).getOrElse('almost got it'))
.getOrElse('none'),
'almost got it',
],
[
Maybe(roomC.type)
.toRight(() => new Error('no type'))
.map(x => Maybe(x.name))
.map(x => x.map(_ => _.trim()).getOrElse('almost got it'))
.map((x) => Maybe(x.name))
.map((x) => x.map((_) => _.trim()).getOrElse('almost got it'))
.getOrElse('none'),
'roomC',
],
Expand Down
13 changes: 6 additions & 7 deletions src/test/Option.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as Promise from 'bluebird';
import { assert, expect } from 'chai';
import * as sinon from 'sinon';

Expand Down Expand Up @@ -259,12 +258,12 @@ describe('Option', () => {
]);
});

it('(later:promise) should handle rejected promises', done => {
it('(later:promise) should handle rejected promises', (done) => {
const x = new Promise<number[]>((_resolve, reject) => {
reject(new Error('rejection_test'));
});

Maybe(x).later<number[]>(res => {
Maybe(x).later<number[]>((res) => {
try {
assert.deepEqual(res.getOrElse([5]), [5]);
done();
Expand All @@ -274,15 +273,15 @@ describe('Option', () => {
});
});

it('(later:promise) should handle resolved promises', done => {
it('(later:promise) should handle resolved promises', (done) => {
type objType = { id: number; name: string };
const x = new Promise<objType[]>(resolve => {
const x = new Promise<objType[]>((resolve) => {
resolve([]);
});

Maybe(x).later<objType[]>(res => {
Maybe(x).later<objType[]>((res) => {
const validArray = res
.filter(v => v.length > 0)
.filter((v) => v.length > 0)
.getOrElse([{ id: 0, name: 'No Data' }]);
const name = validArray[0].name;
try {
Expand Down
2 changes: 1 addition & 1 deletion src/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { assert } from 'chai';
function compareValues(
tests: ([unknown, unknown] | [unknown, unknown, string])[],
): void {
tests.forEach(item => {
tests.forEach((item) => {
assert.deepEqual(item[0], item[1], item[2]);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/Paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ const PATHS = {
};

// Normalizing since having `//` in the path can be bad in some machines.
Object.keys(PATHS).forEach(key => (PATHS[key] = path.normalize(PATHS[key])));
Object.keys(PATHS).forEach((key) => (PATHS[key] = path.normalize(PATHS[key])));

export { PATHS };
32 changes: 17 additions & 15 deletions src/tools/ciBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ class Builder extends CIBuilder {

async isRelease(branch: string, commitMsg: string): Promise<boolean> {
const isMasterBranch = ['master', 'refs/heads/master'].includes(branch);
// Only running the release build in node 8
const isNode8 = (await this.buildUtil.getNodeVersion())
.map(ver => ver.major === 8)
// Only running the release build in node 10
const isNode10 = (await this.buildUtil.getNodeVersion())
.map((ver) => ver.major === 10)
.getOrElse(false);

return (
isNode8 && isMasterBranch && !!commitMsg.match(this.releaseBranchMerged)
isNode10 && isMasterBranch && !!commitMsg.match(this.releaseBranchMerged)
);
}

Expand All @@ -50,7 +50,7 @@ class Builder extends CIBuilder {
mocha.useColors(true);
}
mocha.addFile('build_node/test/index.node.js');
mocha.run(failures => {
mocha.run((failures) => {
if (failures > 0) {
const verb = failures === 1 ? 'is' : 'are';
const amount = failures === 1 ? '' : 's';
Expand All @@ -68,7 +68,7 @@ class Builder extends CIBuilder {
this.io.openBlock('browser_testing', 'running browser tests');
const browserTesting = new Promise<void>((fulfill, reject) => {
const configFile = `${PATHS.buildNode}/tools/karma.conf.js`;
const server = new Server({ configFile }, exitCode => {
const server = new Server({ configFile }, (exitCode) => {
if (exitCode === 0) {
this.io.log('Browser testing passed');
fulfill();
Expand Down Expand Up @@ -102,23 +102,25 @@ class Builder extends CIBuilder {

async beforePublish(): Promise<StepResult> {
const ensurePromise = Promise.all(
['node', 'fesm5', 'types'].map(_ => ensureDir(_)),
['node', 'fesm5', 'types'].map((_) => ensureDir(_)),
);

return (await asyncEvalIteration<Exception, 0>(async () => {
let _;
for (_ of (await TryAsync(() => ensurePromise)).toEither())
for (_ of util.move('build_node/main/', './node'))
for (_ of util.move('build_browser/main/', './fesm5'))
for (_ of util.move('declarations/main/', './types')) return 0;
})).mapIfLeft(err => new Exception('failed to move files', err));
return (
await asyncEvalIteration<Exception, 0>(async () => {
let _;
for (_ of (await TryAsync(() => ensurePromise)).toEither())
for (_ of util.move('build_node/main/', './node'))
for (_ of util.move('build_browser/main/', './fesm5'))
for (_ of util.move('declarations/main/', './types')) return 0;
})
).mapIfLeft((err) => new Exception('failed to move files', err));
}

async getPublishInfo(): Promise<Either<Exception, [string, string]>> {
const version = this.env.packageVersion;
if (this.env.isPreRelease) {
const majorEither = Maybe(semver.parse(version))
.map(x => x.major)
.map((x) => x.major)
.toRight(new Exception(`Unable to parse version: ${version}`));
return asyncEvalIteration(async () => {
for (const major of majorEither)
Expand Down
Loading

0 comments on commit 46a842f

Please sign in to comment.