From 1847865c98dc005e767bd386a09a6288bc4d06b5 Mon Sep 17 00:00:00 2001 From: ssube Date: Mon, 28 Dec 2020 23:24:46 -0600 Subject: [PATCH] fix(async): split up defer with and without value, update typescript BREAKING CHANGE: usage of `defer(number, T)` must be replaced with `deferValue(number, T)`. Uses of `defer(number)` do not need to change. --- docs/api/js-utils.defer.md | 5 +- docs/api/js-utils.md | 2 +- package.json | 10 ++-- src/Async.ts | 10 +++- src/Rollup.ts | 34 +++++++++++ test/utils/TestAsync.ts | 13 ++++- yarn.lock | 113 +++++++++++++++++++------------------ 7 files changed, 120 insertions(+), 67 deletions(-) create mode 100644 src/Rollup.ts diff --git a/docs/api/js-utils.defer.md b/docs/api/js-utils.defer.md index ba49c637..ab22c28b 100644 --- a/docs/api/js-utils.defer.md +++ b/docs/api/js-utils.defer.md @@ -9,7 +9,7 @@ Resolve after a set amount of time. Signature: ```typescript -export declare function defer(ms: number, val?: T): Promise; +export declare function defer(ms: number): Promise; ``` ## Parameters @@ -17,9 +17,8 @@ export declare function defer(ms: number, val?: T): Promise; | Parameter | Type | Description | | --- | --- | --- | | ms | number | | -| val | T | | Returns: -Promise<T> +Promise<void> diff --git a/docs/api/js-utils.md b/docs/api/js-utils.md index f15610f8..6173c05b 100644 --- a/docs/api/js-utils.md +++ b/docs/api/js-utils.md @@ -31,7 +31,7 @@ | [constructorName(val)](./js-utils.constructorname.md) | Get the constructor name from an instance. | | [countOf(val)](./js-utils.countof.md) | Calculate the "length" of an array or value.Arrays return their length, single values return 1, and nil values return 0. This counts the number of elements that setOrPush would add. | | [defaultWhen(condition, items)](./js-utils.defaultwhen.md) | Return the first element when condition is true and the second element when condition is false. | -| [defer(ms, val)](./js-utils.defer.md) | Resolve after a set amount of time. | +| [defer(ms)](./js-utils.defer.md) | Resolve after a set amount of time. | | [doesExist(val)](./js-utils.doesexist.md) | Check if a variable is not nil. | | [encode(chunks, encoding)](./js-utils.encode.md) | Concatenate then encode a list of buffers. | | [ensureArray(val)](./js-utils.ensurearray.md) | | diff --git a/package.json b/package.json index dc9d4c52..c213cb5a 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,9 @@ "@types/node": "14.14.6", "@types/sinon-chai": "3.2.5", "@types/source-map-support": "0.5.3", - "@typescript-eslint/eslint-plugin": "4.6.0", - "@typescript-eslint/eslint-plugin-tslint": "4.6.0", - "@typescript-eslint/parser": "4.6.0", + "@typescript-eslint/eslint-plugin": "4.11.1", + "@typescript-eslint/eslint-plugin-tslint": "4.11.1", + "@typescript-eslint/parser": "4.11.1", "chai": "4.2.0", "chai-as-promised": "7.1.1", "eslint": "7.12.1", @@ -70,10 +70,10 @@ "tslint": "6.1.3", "tslint-clean-code": "0.2.10", "tslint-consistent-codestyle": "1.16.0", - "tslint-etc": "1.13.7", + "tslint-etc": "1.13.9", "tslint-microsoft-contrib": "6.2.0", "tslint-sonarts": "1.9.0", - "typescript": "4.0.5" + "typescript": "4.1.3" }, "nyc": { "extends": "@istanbuljs/nyc-config-typescript" diff --git a/src/Async.ts b/src/Async.ts index ead005fa..304bd15d 100644 --- a/src/Async.ts +++ b/src/Async.ts @@ -5,7 +5,15 @@ import { PredicateC0 } from './Predicate'; * Resolve after a set amount of time. * @public */ -export function defer(ms: number, val?: T): Promise { +export function defer(ms: number): Promise { + return new Promise((res, rej) => { + setTimeout(() => { + res(); + }, ms); + }); +} + +export function deferValue(ms: number, val: T): Promise { return new Promise((res, rej) => { setTimeout(() => { res(val); diff --git a/src/Rollup.ts b/src/Rollup.ts new file mode 100644 index 00000000..65eca738 --- /dev/null +++ b/src/Rollup.ts @@ -0,0 +1,34 @@ +import { sep } from 'path'; + +export interface ChunkMatch { + includes: Array; + match: Array; +} + +export type ChunkMap = Record; + +export function fixPath(name: string): string { + return name.replace('/', sep); +} + +export function chunkMap(map: ChunkMap, name: string): string { + for (const [chunk, def] of Object.entries(map)) { + for (const include of def.includes) { + if (name.includes(include)) { + return chunk; + } + } + + for (const match of def.match) { + if (name.match(match)) { + return chunk; + } + } + } + + if (name.length === 30 && name.match(/^[a-f0-9]+$/)) { + return 'vendor'; + } + + return 'unknown'; +} diff --git a/test/utils/TestAsync.ts b/test/utils/TestAsync.ts index 2abeffcb..6515181c 100644 --- a/test/utils/TestAsync.ts +++ b/test/utils/TestAsync.ts @@ -1,14 +1,21 @@ import { expect } from 'chai'; -import { defer, timeout } from '../../src/Async'; +import { defer, deferValue, timeout } from '../../src/Async'; import { TimeoutError } from '../../src/error/TimeoutError'; +const TEST_DEFER = 10; +const TEST_TOO_LONG = 25; + describe('async utils', async () => { describe('defer', async () => { - it('should resolve', async () => expect(defer(10, true)).to.eventually.equal(true)); + it('should resolve', async () => expect(defer(TEST_DEFER)).to.eventually.equal(undefined)); + }); + + describe('defer value', async () => { + it('should resolve to the given value', async () => expect(deferValue(TEST_DEFER, true)).to.eventually.equal(true)); }); describe('timeout', async () => { - it('should reject slow promises', async () => expect(timeout(10, defer(20))).to.eventually.be.rejectedWith(TimeoutError)); + it('should reject slow promises', async () => expect(timeout(TEST_DEFER, defer(TEST_TOO_LONG))).to.eventually.be.rejectedWith(TimeoutError)); }); }); diff --git a/yarn.lock b/yarn.lock index 1d76a641..ec3476d5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -466,69 +466,69 @@ dependencies: source-map "^0.6.0" -"@typescript-eslint/eslint-plugin-tslint@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-4.6.0.tgz#aad2ed5a1b242f738711412e4ad4dcb0be3e21a6" - integrity sha512-3ba/AAcufH6Gd2UB4Qzsx0PoxzALiad5sulv82kshNJju1bWcvFa3EKdleGwBjEkaK8pvo1bE3n4wZFP2p6Y3g== +"@typescript-eslint/eslint-plugin-tslint@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/eslint-plugin-tslint/-/eslint-plugin-tslint-4.11.1.tgz#1cc9d7d8a3bc3ba4ffb75b90377ebd4c466f5f79" + integrity sha512-jkfv3a1w/wG09G7BZv/TH0S4XXDxa2uBt7TDz9I+bmVGis+jKy7zbA3CDi8d8AGA7IGLAdBZObGwf80s3AQWLQ== dependencies: - "@typescript-eslint/experimental-utils" "4.6.0" + "@typescript-eslint/experimental-utils" "4.11.1" lodash "^4.17.15" -"@typescript-eslint/eslint-plugin@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.6.0.tgz#210cd538bb703f883aff81d3996961f5dba31fdb" - integrity sha512-1+419X+Ynijytr1iWI+/IcX/kJryc78YNpdaXR1aRO1sU3bC0vZrIAF1tIX7rudVI84W7o7M4zo5p1aVt70fAg== +"@typescript-eslint/eslint-plugin@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.11.1.tgz#7579c6d17ad862154c10bc14b40e5427b729e209" + integrity sha512-fABclAX2QIEDmTMk6Yd7Muv1CzFLwWM4505nETzRHpP3br6jfahD9UUJkhnJ/g2m7lwfz8IlswcwGGPGiq9exw== dependencies: - "@typescript-eslint/experimental-utils" "4.6.0" - "@typescript-eslint/scope-manager" "4.6.0" + "@typescript-eslint/experimental-utils" "4.11.1" + "@typescript-eslint/scope-manager" "4.11.1" debug "^4.1.1" functional-red-black-tree "^1.0.1" regexpp "^3.0.0" semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/experimental-utils@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/experimental-utils/-/experimental-utils-4.6.0.tgz#f750aef4dd8e5970b5c36084f0a5ca2f0db309a4" - integrity sha512-pnh6Beh2/4xjJVNL+keP49DFHk3orDHHFylSp3WEjtgW3y1U+6l+jNnJrGlbs6qhAz5z96aFmmbUyKhunXKvKw== +"@typescript-eslint/experimental-utils@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/experimental-utils/-/experimental-utils-4.11.1.tgz#2dad3535b878c25c7424e40bfa79d899f3f485bc" + integrity sha512-mAlWowT4A6h0TC9F+J5pdbEhjNiEMO+kqPKQ4sc3fVieKL71dEqfkKgtcFVSX3cjSBwYwhImaQ/mXQF0oaI38g== dependencies: "@types/json-schema" "^7.0.3" - "@typescript-eslint/scope-manager" "4.6.0" - "@typescript-eslint/types" "4.6.0" - "@typescript-eslint/typescript-estree" "4.6.0" + "@typescript-eslint/scope-manager" "4.11.1" + "@typescript-eslint/types" "4.11.1" + "@typescript-eslint/typescript-estree" "4.11.1" eslint-scope "^5.0.0" eslint-utils "^2.0.0" -"@typescript-eslint/parser@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/parser/-/parser-4.6.0.tgz#7e9ff7df2f21d5c8f65f17add3b99eeeec33199d" - integrity sha512-Dj6NJxBhbdbPSZ5DYsQqpR32MwujF772F2H3VojWU6iT4AqL4BKuoNWOPFCoSZvCcADDvQjDpa6OLDAaiZPz2Q== +"@typescript-eslint/parser@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/parser/-/parser-4.11.1.tgz#981e18de2e019d6ca312596615f92e8f6f6598ed" + integrity sha512-BJ3jwPQu1jeynJ5BrjLuGfK/UJu6uwHxJ/di7sanqmUmxzmyIcd3vz58PMR7wpi8k3iWq2Q11KMYgZbUpRoIPw== dependencies: - "@typescript-eslint/scope-manager" "4.6.0" - "@typescript-eslint/types" "4.6.0" - "@typescript-eslint/typescript-estree" "4.6.0" + "@typescript-eslint/scope-manager" "4.11.1" + "@typescript-eslint/types" "4.11.1" + "@typescript-eslint/typescript-estree" "4.11.1" debug "^4.1.1" -"@typescript-eslint/scope-manager@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/scope-manager/-/scope-manager-4.6.0.tgz#b7d8b57fe354047a72dfb31881d9643092838662" - integrity sha512-uZx5KvStXP/lwrMrfQQwDNvh2ppiXzz5TmyTVHb+5TfZ3sUP7U1onlz3pjoWrK9konRyFe1czyxObWTly27Ang== +"@typescript-eslint/scope-manager@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/scope-manager/-/scope-manager-4.11.1.tgz#72dc2b60b0029ab0888479b12bf83034920b4b69" + integrity sha512-Al2P394dx+kXCl61fhrrZ1FTI7qsRDIUiVSuN6rTwss6lUn8uVO2+nnF4AvO0ug8vMsy3ShkbxLu/uWZdTtJMQ== dependencies: - "@typescript-eslint/types" "4.6.0" - "@typescript-eslint/visitor-keys" "4.6.0" + "@typescript-eslint/types" "4.11.1" + "@typescript-eslint/visitor-keys" "4.11.1" -"@typescript-eslint/types@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/types/-/types-4.6.0.tgz#157ca925637fd53c193c6bf226a6c02b752dde2f" - integrity sha512-5FAgjqH68SfFG4UTtIFv+rqYJg0nLjfkjD0iv+5O27a0xEeNZ5rZNDvFGZDizlCD1Ifj7MAbSW2DPMrf0E9zjA== +"@typescript-eslint/types@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/types/-/types-4.11.1.tgz#3ba30c965963ef9f8ced5a29938dd0c465bd3e05" + integrity sha512-5kvd38wZpqGY4yP/6W3qhYX6Hz0NwUbijVsX2rxczpY6OXaMxh0+5E5uLJKVFwaBM7PJe1wnMym85NfKYIh6CA== -"@typescript-eslint/typescript-estree@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/typescript-estree/-/typescript-estree-4.6.0.tgz#85bd98dcc8280511cfc5b2ce7b03a9ffa1732b08" - integrity sha512-s4Z9qubMrAo/tw0CbN0IN4AtfwuehGXVZM0CHNMdfYMGBDhPdwTEpBrecwhP7dRJu6d9tT9ECYNaWDHvlFSngA== +"@typescript-eslint/typescript-estree@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/typescript-estree/-/typescript-estree-4.11.1.tgz#a4416b4a65872a48773b9e47afabdf7519eb10bc" + integrity sha512-tC7MKZIMRTYxQhrVAFoJq/DlRwv1bnqA4/S2r3+HuHibqvbrPcyf858lNzU7bFmy4mLeIHFYr34ar/1KumwyRw== dependencies: - "@typescript-eslint/types" "4.6.0" - "@typescript-eslint/visitor-keys" "4.6.0" + "@typescript-eslint/types" "4.11.1" + "@typescript-eslint/visitor-keys" "4.11.1" debug "^4.1.1" globby "^11.0.1" is-glob "^4.0.1" @@ -536,12 +536,12 @@ semver "^7.3.2" tsutils "^3.17.1" -"@typescript-eslint/visitor-keys@4.6.0": - version "4.6.0" - resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/visitor-keys/-/visitor-keys-4.6.0.tgz#fb05d6393891b0a089b243fc8f9fb8039383d5da" - integrity sha512-38Aa9Ztl0XyFPVzmutHXqDMCu15Xx8yKvUo38Gu3GhsuckCh3StPI5t2WIO9LHEsOH7MLmlGfKUisU8eW1Sjhg== +"@typescript-eslint/visitor-keys@4.11.1": + version "4.11.1" + resolved "https://artifacts.apextoaster.com/repository/group-npm/@typescript-eslint/visitor-keys/-/visitor-keys-4.11.1.tgz#4c050a4c1f7239786e2dd4e69691436143024e05" + integrity sha512-IrlBhD9bm4bdYcS8xpWarazkKXlE7iYb1HzRuyBP114mIaj5DJPo11Us1HgH60dTt41TCZXMaTCAW+OILIYPOg== dependencies: - "@typescript-eslint/types" "4.6.0" + "@typescript-eslint/types" "4.11.1" eslint-visitor-keys "^2.0.0" "@ungap/promise-all-settled@1.1.2": @@ -4415,10 +4415,10 @@ tslint-consistent-codestyle@1.16.0: tslib "^1.7.1" tsutils "^2.29.0" -tslint-etc@1.13.7: - version "1.13.7" - resolved "https://artifacts.apextoaster.com/repository/group-npm/tslint-etc/-/tslint-etc-1.13.7.tgz#3fc6dacc21b3ffa2e727398b7a8d7099dbb95942" - integrity sha512-v66dIwtWwc1epHH/KjrUnl97oMRwuoSOYdh0YNHGKwZvtxJzM1Afb23ugfrj028+DZoR1vCxb4/YV7eXgTn2nw== +tslint-etc@1.13.9: + version "1.13.9" + resolved "https://artifacts.apextoaster.com/repository/group-npm/tslint-etc/-/tslint-etc-1.13.9.tgz#46464af0f03efb6d4b2c71b9b4adce41a2b2ed71" + integrity sha512-plelxI+RH0w1irVPxOX7REqnwaAM1FJcgoe12UU1Ft3zIvGx9VX4BNf9jRLAt2wd00TJPpCb0ACumaDoCXp7hA== dependencies: "@phenomnomnominal/tsquery" "^4.0.0" tslib "^2.0.0" @@ -4561,16 +4561,21 @@ typedarray@^0.0.6: resolved "https://artifacts.apextoaster.com/repository/group-npm/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@4.0.5, typescript@~4.0.5: - version "4.0.5" - resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" - integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== +typescript@4.1.3: + version "4.1.3" + resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.1.3.tgz#519d582bd94cba0cf8934c7d8e8467e473f53bb7" + integrity sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg== typescript@^3.0.0: version "3.6.3" resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw== +typescript@~4.0.5: + version "4.0.5" + resolved "https://artifacts.apextoaster.com/repository/group-npm/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389" + integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ== + uglify-js@^3.1.4: version "3.6.0" resolved "https://artifacts.apextoaster.com/repository/group-npm/uglify-js/-/uglify-js-3.6.0.tgz#704681345c53a8b2079fb6cec294b05ead242ff5"