From 2f395da56189090215462bb88cfd2014c842be57 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Mon, 30 Oct 2017 08:26:50 -0700 Subject: [PATCH] chore(TypeScript): Bump up typescript to latest (#3009) * chore(package): bump up typescript to latest * chore(typings): remove deprecated typings * chore(spec): remove redundant reference * fix(error): custom error inherits via setPrototypeof BREAKING CHANGE: IE10 and lower will need to polyfill `Object.setPrototypeOf` --- .dependency-cruiser.json | 107 ++++++++++++++++++++++++++ .travis.yml | 2 +- package.json | 16 ++-- spec/helpers/marble-testing.ts | 1 - spec/helpers/test-helper.ts | 2 - spec/helpers/testScheduler-ui.ts | 2 - spec/util/UnsubscriptionError-spec.ts | 4 +- src/observable/dom/AjaxObservable.ts | 4 + src/util/ArgumentOutOfRangeError.ts | 7 +- src/util/EmptyError.ts | 7 +- src/util/ObjectUnsubscribedError.ts | 7 +- src/util/TimeoutError.ts | 7 +- src/util/UnsubscriptionError.ts | 8 +- typings.json | 12 --- 14 files changed, 138 insertions(+), 48 deletions(-) create mode 100644 .dependency-cruiser.json delete mode 100644 typings.json diff --git a/.dependency-cruiser.json b/.dependency-cruiser.json new file mode 100644 index 0000000000..56d0cf216a --- /dev/null +++ b/.dependency-cruiser.json @@ -0,0 +1,107 @@ +{ + "forbidden": [ + { + "name": "not-to-spec", + "comment": "Don't allow dependencies from outside the spec folder to spec", + "severity": "error", + "from": { + "pathNot": "^spec" + }, + "to": { + "path": "^spec" + } + }, + { + "name": "not-to-spec", + "comment": "Don't allow dependencies to (typescript/ javascript/ coffeescript) spec files", + "severity": "error", + "from": {}, + "to": { + "path": "\\.spec\\.[js|ts|ls|coffee|litcoffee|coffee\\.md]$" + } + }, + { + "name": "no-deprecated-core", + "comment": "Warn about dependencies on deprecated core modules.", + "severity": "warn", + "from": {}, + "to": { + "dependencyTypes": [ + "core" + ], + "path": "^(punycode|domain)$" + } + }, + { + "name": "no-deprecated-npm", + "comment": "These npm modules are deprecated - find an alternative.", + "severity": "warn", + "from": {}, + "to": { + "dependencyTypes": [ + "deprecated" + ] + } + }, + { + "name": "not-to-dev-dep", + "severity": "error", + "comment": "Don't allow dependencies from src/app/lib to a development only package", + "from": { + "path": "^(src|app|lib)" + }, + "to": { + "dependencyTypes": [ + "npm-dev" + ] + } + }, + { + "name": "no-non-package-json", + "severity": "error", + "comment": "Don't allow dependencies to packages not in package.json (except from within node_modules)", + "from": { + "pathNot": "^node_modules" + }, + "to": { + "dependencyTypes": [ + "undetermined", + "npm-no-pkg", + "npm-unknown" + ], + "pathNot": "^electron" + } + }, + { + "name": "peer-deps-used", + "comment": "Error about the use of a peer dependency (peer dependencies are deprecated).", + "severity": "error", + "from": {}, + "to": { + "dependencyTypes": [ + "npm-peer" + ] + } + }, + { + "name": "no-duplicate-dep-types", + "comment": "Warn if a dependency occurs in your package.json more than once (technically: has more than one dependency type)", + "severity": "warn", + "from": {}, + "to": { + "moreThanOneDependencyType": true + } + }, + { + "name": "no-circular", + "severity": "error", + "comment": "Error in case we have circular dependencies", + "from": { + "path": "^src" + }, + "to": { + "circular": true + } + } + ] +} diff --git a/.travis.yml b/.travis.yml index 8c81800286..0302f70603 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,7 +26,7 @@ before_install: install: - npm install - - if [ "$FULL_VALIDATE" == "true" ]; then npm run lint && npm run check_circular_dependencies; fi + - if [ "$FULL_VALIDATE" == "true" ]; then npm run lint && npm run test:circular; fi script: - if [ "$FULL_VALIDATE" == "true" ] && [ -n "DANGER_GITHUB_API_TOKEN" ]; then echo {} > ./.babelrc && npx danger; fi diff --git a/package.json b/package.json index 25b5f8c737..c0280dce15 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ "exclude": [ "node_modules", "dist", - "typings", "*.d.ts", "src/**/MiscJSDoc.ts" ], @@ -52,7 +51,6 @@ "build_perf": "Build CJS & Global build, run macro performance test", "build_test": "Build CJS package & test spec, execute mocha test runner", "build_docs": "Build ESM2015 & global package, create documentation using it", - "check_circular_dependencies": "Check codebase has circular dependencies", "clean_dist_cjs": "Clean up existing CJS package output", "clean_dist_esm5": "Clean up existing ESM/ES5 package output", "clean_dist_esm2015": "Clean up existing ESM/ES2015 package output", @@ -90,7 +88,6 @@ "build_perf": "webdriver-manager update && npm-run-all build_cjs build_global perf", "build_docs": "npm-run-all build_global build_esm2015_for_docs build_cjs tests2png decision_tree_widget && esdoc -c esdoc.json && npm-run-all clean_dist_esm2015", "build_spec_browser": "webpack --config spec/support/webpack.mocha.config.js", - "check_circular_dependencies": "madge ./dist/cjs --circular", "clean_dist": "shx rm -rf ./dist", "clean_dist_cjs": "shx rm -rf ./dist/cjs", "clean_dist_esm5": "shx rm -rf ./dist/esm5", @@ -113,11 +110,12 @@ "lint": "npm-run-all --parallel lint_*", "perf": "protractor protractor.conf.js", "perf_micro": "node ./perf/micro/index.js", - "prepublish": "shx rm -rf ./typings && typings install && npm run build_all", + "prepublish": "shx rm -rf ./typings && npm run build_all", "publish_docs": "./publish_docs.sh", "test_browser": "npm-run-all build_spec_browser && opn spec/support/mocha-browser-runner.html", "test": "cross-env TS_NODE_FAST=true mocha --compilers ts:ts-node/register --opts spec/support/coverage.opts \"spec/**/*-spec.ts\"", "test:cover": "cross-env TS_NODE_FAST=true nyc npm test", + "test:circular": "dependency-cruise --validate .dependency-cruiser.json -x \"^node_modules\" src", "tests2png": "tsc && mkdirp tmp/docs/img && mkdirp spec-js/support && shx cp spec/support/*.opts spec-js/support/ && mocha --opts spec/support/tests2png.opts spec-js", "watch": "watch \"echo triggering build && npm run build_test && echo build completed\" src -d -u -w=15" }, @@ -171,6 +169,12 @@ "homepage": "https://github.com/ReactiveX/RxJS", "devDependencies": { "@angular-devkit/build-optimizer": "0.0.24", + "@types/chai": "^4.0.4", + "@types/lodash": "^4.14.80", + "@types/mocha": "^2.2.44", + "@types/node": "^8.0.47", + "@types/sinon": "^2.3.7", + "@types/sinon-chai": "^2.7.29", "babel-polyfill": "^6.23.0", "benchmark": "^2.1.0", "benchpress": "2.0.0-beta.1", @@ -182,6 +186,7 @@ "cross-env": "^5.1.0", "cz-conventional-changelog": "^1.2.0", "danger": "^1.1.0", + "dependency-cruiser": "^2.6.0", "doctoc": "^1.0.0", "escape-string-regexp": "^1.0.5 ", "esdoc": "^0.4.7", @@ -222,8 +227,7 @@ "ts-node": "^3.3.0", "tslib": "^1.5.0", "tslint": "^4.4.2", - "typescript": "~2.0.6", - "typings": "^2.0.0", + "typescript": "latest", "validate-commit-msg": "^2.14.0", "watch": "^1.0.1", "webpack": "^1.13.1", diff --git a/spec/helpers/marble-testing.ts b/spec/helpers/marble-testing.ts index 1589bb2941..56007993d6 100644 --- a/spec/helpers/marble-testing.ts +++ b/spec/helpers/marble-testing.ts @@ -1,4 +1,3 @@ -/// import { Observable } from '../../src/Observable'; import { SubscriptionLog } from '../../src/testing/SubscriptionLog'; import { ColdObservable } from '../../src/testing/ColdObservable'; diff --git a/spec/helpers/test-helper.ts b/spec/helpers/test-helper.ts index 24a8626348..753756a181 100644 --- a/spec/helpers/test-helper.ts +++ b/spec/helpers/test-helper.ts @@ -1,4 +1,3 @@ -/// declare const global: any; import * as Rx from '../../src/Rx'; @@ -6,7 +5,6 @@ import { ObservableInput } from '../../src/Observable'; import { root } from '../../src/util/root'; import { $$iterator } from '../../src/symbol/iterator'; import $$symbolObservable from 'symbol-observable'; -import { Observable } from '../../src/Observable'; export function lowerCaseO(...args: Array): Rx.Observable { diff --git a/spec/helpers/testScheduler-ui.ts b/spec/helpers/testScheduler-ui.ts index 5d0c2d455c..5f24505ef6 100644 --- a/spec/helpers/testScheduler-ui.ts +++ b/spec/helpers/testScheduler-ui.ts @@ -1,5 +1,3 @@ -/// - import * as _ from 'lodash'; //import * as commonInterface from 'mocha/lib/interfaces/common'; //import * as escapeRe from 'escape-string-regexp'; diff --git a/spec/util/UnsubscriptionError-spec.ts b/spec/util/UnsubscriptionError-spec.ts index dad0143705..f2f1db9b27 100644 --- a/spec/util/UnsubscriptionError-spec.ts +++ b/spec/util/UnsubscriptionError-spec.ts @@ -19,9 +19,7 @@ describe('UnsubscriptionError', () => { subscription.unsubscribe(); } catch (err) { expect(err instanceof UnsubscriptionError).to.equal(true); - expect(err.message).to.equal(`2 errors occurred during unsubscription: - 1) ${err1} - 2) ${err2}`); + expect(err.errors).to.deep.equal([err1, err2]); expect(err.name).to.equal('UnsubscriptionError'); } }); diff --git a/src/observable/dom/AjaxObservable.ts b/src/observable/dom/AjaxObservable.ts index b8fc058a7c..427d1f1eee 100644 --- a/src/observable/dom/AjaxObservable.ts +++ b/src/observable/dom/AjaxObservable.ts @@ -452,6 +452,9 @@ export class AjaxError extends Error { this.status = xhr.status; this.responseType = xhr.responseType || request.responseType; this.response = parseXhrResponse(this.responseType, xhr); + + this.name = 'AjaxError'; + (Object as any).setPrototypeOf(this, AjaxError.prototype); } } @@ -480,5 +483,6 @@ function parseXhrResponse(responseType: string, xhr: XMLHttpRequest) { export class AjaxTimeoutError extends AjaxError { constructor(xhr: XMLHttpRequest, request: AjaxRequest) { super('ajax timeout', xhr, request); + (Object as any).setPrototypeOf(this, AjaxTimeoutError.prototype); } } diff --git a/src/util/ArgumentOutOfRangeError.ts b/src/util/ArgumentOutOfRangeError.ts index 4384a2b465..d3155f3361 100644 --- a/src/util/ArgumentOutOfRangeError.ts +++ b/src/util/ArgumentOutOfRangeError.ts @@ -10,9 +10,8 @@ */ export class ArgumentOutOfRangeError extends Error { constructor() { - const err: any = super('argument out of range'); - ( this).name = err.name = 'ArgumentOutOfRangeError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('argument out of range'); + this.name = 'ArgumentOutOfRangeError'; + (Object as any).setPrototypeOf(this, ArgumentOutOfRangeError.prototype); } } diff --git a/src/util/EmptyError.ts b/src/util/EmptyError.ts index d1184ab189..fbfe7bf88d 100644 --- a/src/util/EmptyError.ts +++ b/src/util/EmptyError.ts @@ -10,9 +10,8 @@ */ export class EmptyError extends Error { constructor() { - const err: any = super('no elements in sequence'); - ( this).name = err.name = 'EmptyError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('no elements in sequence'); + this.name = 'EmptyError'; + (Object as any).setPrototypeOf(this, EmptyError.prototype); } } diff --git a/src/util/ObjectUnsubscribedError.ts b/src/util/ObjectUnsubscribedError.ts index 460a31029a..fb005457e7 100644 --- a/src/util/ObjectUnsubscribedError.ts +++ b/src/util/ObjectUnsubscribedError.ts @@ -9,9 +9,8 @@ */ export class ObjectUnsubscribedError extends Error { constructor() { - const err: any = super('object unsubscribed'); - ( this).name = err.name = 'ObjectUnsubscribedError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('object unsubscribed'); + this.name = 'ObjectUnsubscribedError'; + (Object as any).setPrototypeOf(this, ObjectUnsubscribedError.prototype); } } diff --git a/src/util/TimeoutError.ts b/src/util/TimeoutError.ts index c68adffac4..506249e94d 100644 --- a/src/util/TimeoutError.ts +++ b/src/util/TimeoutError.ts @@ -7,9 +7,8 @@ */ export class TimeoutError extends Error { constructor() { - const err: any = super('Timeout has occurred'); - ( this).name = err.name = 'TimeoutError'; - ( this).stack = err.stack; - ( this).message = err.message; + super('Timeout has occurred'); + + (Object as any).setPrototypeOf(this, TimeoutError.prototype); } } diff --git a/src/util/UnsubscriptionError.ts b/src/util/UnsubscriptionError.ts index 412164ed76..47999fc1e0 100644 --- a/src/util/UnsubscriptionError.ts +++ b/src/util/UnsubscriptionError.ts @@ -4,12 +4,10 @@ */ export class UnsubscriptionError extends Error { constructor(public errors: any[]) { - super(); - const err: any = Error.call(this, errors ? + super(errors ? `${errors.length} errors occurred during unsubscription: ${errors.map((err, i) => `${i + 1}) ${err.toString()}`).join('\n ')}` : ''); - ( this).name = err.name = 'UnsubscriptionError'; - ( this).stack = err.stack; - ( this).message = err.message; + this.name = 'UnsubscriptionError'; + (Object as any).setPrototypeOf(this, UnsubscriptionError.prototype); } } diff --git a/typings.json b/typings.json deleted file mode 100644 index e329d616d7..0000000000 --- a/typings.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "devDependencies": { - "chai": "registry:npm/chai#3.5.0+20160723033700", - "lodash": "registry:npm/lodash#4.0.0+20161015015725", - "sinon": "registry:npm/sinon#1.16.0+20160723033700", - "sinon-chai": "registry:npm/sinon-chai#2.8.0+20160310030142" - }, - "globalDevDependencies": { - "mocha": "registry:env/mocha#2.2.5+20160926180742", - "node": "registry:env/node#6.0.0+20161105011511" - } -}