From 080aa9aa52a10499f1c038db970b3f9cab1c6332 Mon Sep 17 00:00:00 2001 From: Evgeniy Timokhov Date: Fri, 15 May 2020 14:58:12 +0300 Subject: [PATCH] Introduced ts-transformer-properties-rename instead of ts-transformer-minify-privates It allows to minify everything aren't exported to the public space, so it reduces bundle size a lot (by several KB which is several % in min.gz) --- .circleci/config.yml | 9 +++------ BUILDING.md | 3 +-- dts-config.js | 4 ++-- package.json | 9 ++++----- rollup.config.js | 10 +++++----- scripts/check-dts-changes.sh | 2 ++ scripts/githooks/pre-commit/lint.js | 2 +- src/api/series-api.ts | 4 ++-- src/api/tsconfig.composite.json | 5 +---- src/formatters/tsconfig.composite.json | 5 +---- src/gui/tsconfig.composite.json | 5 +---- src/helpers/color.ts | 1 + src/helpers/tsconfig.composite.json | 6 +----- src/model/series-data.ts | 1 + src/model/series.ts | 4 ++-- src/tsconfig.composite.json | 5 +---- src/tsconfig.model.json | 5 +---- src/views/pane/series-markers-pane-view.ts | 2 +- tests/e2e/memleaks/helpers/get-test-cases.ts | 2 +- tests/e2e/tsconfig.json | 2 +- tests/unittests/tsconfig.composite.json | 3 +-- tsconfig.composite.base.json | 9 +++++++++ tsconfig.composite.json | 8 ++------ tsconfig.json | 5 ++--- tsconfig.base.json => tsconfig.options.json | 5 ----- tsconfig.prod.json | 14 ++++++++++++++ tslint.json | 2 +- 27 files changed, 62 insertions(+), 70 deletions(-) create mode 100644 tsconfig.composite.base.json rename tsconfig.base.json => tsconfig.options.json (82%) create mode 100644 tsconfig.prod.json diff --git a/.circleci/config.yml b/.circleci/config.yml index c99c1645e..236dfb62d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -80,12 +80,9 @@ jobs: executor: node-latest-executor steps: - checkout-with-deps - - run: npm run tsc-all - - # make sure that the project is compiled with non-composite project - # it doesn't output anything, but is used by IDE or tools - - run: ./node_modules/.bin/tsc -p tsconfig.json - + # make sure that the project is compiled successfully with composite projects + # so we don't have cyclic deps between projects and wrong imports + - run: npm run tsc-verify - run: npm run build:prod - persist_to_workspace: root: ./ diff --git a/BUILDING.md b/BUILDING.md index c9acade08..af4372dcf 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -6,8 +6,7 @@ The minimal supported version of [NodeJS](https://nodejs.org/) for development i - `npm run tsc` - compiles the source code only (excluding tests) - `npm run tsc-watch` - runs the TypeScript compiler in the watch mode for source code (same as `tsc`, but in the watch mode) -- `npm run tsc-all` - compiles everything (source code and tests) -- `npm run tsc-all-watch` - runs the TypeScript compiler in watch mode for source code and tests (same as `tsc-all`, but in watch mode) +- `npm run tsc-verify` - compiles everything (source code and tests) with composite projects config to ensure that no invalid imports or cyclic deps are found ## Bundling diff --git a/dts-config.js b/dts-config.js index 52707c189..cf93f5167 100644 --- a/dts-config.js +++ b/dts-config.js @@ -3,11 +3,11 @@ /** @type import('dts-bundle-generator/config-schema').BundlerConfig */ const config = { compilationOptions: { - preferredConfigPath: './tsconfig.json', + preferredConfigPath: './tsconfig.prod.json', }, entries: [ { - filePath: './src/index.ts', + filePath: './lib/prod/src/index.d.ts', outFile: './dist/typings.d.ts', output: { sortNodes: true, diff --git a/package.json b/package.json index 178db7c0a..526ae4bd0 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "rollup-plugin-replace": "~2.2.0", "rollup-plugin-terser": "~5.3.0", "ts-node": "~8.10.0", - "ts-transformer-minify-privates": "~0.3.0", + "ts-transformer-properties-rename": "~0.1.0", "ts-transformer-strip-const-enums": "~1.0.1", "tslib": "1.12.0", "tslint": "6.1.1", @@ -72,10 +72,9 @@ "install-hooks": "node scripts/githooks/install.js", "clean": "rimraf lib/ dist/", "bundle-dts": "tsc --noEmit --allowJs dts-config.js && dts-bundle-generator --config dts-config.js", - "tsc": "ttsc -b src/tsconfig.composite.json", + "tsc": "ttsc -p tsconfig.prod.json", "tsc-watch": "npm run tsc -- --watch --preserveWatchOutput", - "tsc-all": "ttsc -b tsconfig.composite.json", - "tsc-all-watch": "npm run tsc-all -- --watch --preserveWatchOutput", + "tsc-verify": "tsc -b tsconfig.composite.json", "lint": "npm-run-all -p lint:**", "lint:eslint": "eslint --format=unix --ext .js ./", "lint:tslint": "tslint --config tslint.json --project tsconfig.json", @@ -87,7 +86,7 @@ "build:watch": "npm-run-all tsc -p tsc-watch rollup-watch", "build:prod": "cross-env NODE_ENV=production npm run build", "codechecks": "codechecks", - "verify": "npm-run-all clean -p tsc-all lint check-markdown-links -s build:prod test codechecks", + "verify": "npm-run-all clean -p lint check-markdown-links build:prod -p tsc-verify test codechecks", "test": "mocha tests/unittests/**/*.spec.ts" } } diff --git a/rollup.config.js b/rollup.config.js index 84c4dee42..0a561573d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -50,7 +50,7 @@ function getConfig(inputFile, type, isProd) { mangle: { module: (type === 'module'), properties: { - regex: /^_private_/, + regex: /^_(private|internal)_/, }, }, }), @@ -62,14 +62,14 @@ function getConfig(inputFile, type, isProd) { } const configs = [ - getConfig('./lib/src/index.js', 'module', false), - getConfig('./lib/src/standalone.js', 'standalone', false), + getConfig('./lib/prod/src/index.js', 'module', false), + getConfig('./lib/prod/src/standalone.js', 'standalone', false), ]; if (process.env.NODE_ENV === 'production') { configs.push( - getConfig('./lib/src/index.js', 'module', true), - getConfig('./lib/src/standalone.js', 'standalone', true) + getConfig('./lib/prod/src/index.js', 'module', true), + getConfig('./lib/prod/src/standalone.js', 'standalone', true) ); } diff --git a/scripts/check-dts-changes.sh b/scripts/check-dts-changes.sh index 619cd16d4..f26556fb6 100755 --- a/scripts/check-dts-changes.sh +++ b/scripts/check-dts-changes.sh @@ -23,6 +23,8 @@ function generate_dts_for_rev { npm install print_step "Generate dts to $dts_filename" + npm run clean + npm run tsc npm run bundle-dts mv ./dist/typings.d.ts $dts_filename } diff --git a/scripts/githooks/pre-commit/lint.js b/scripts/githooks/pre-commit/lint.js index 5c3575d0e..29f143920 100755 --- a/scripts/githooks/pre-commit/lint.js +++ b/scripts/githooks/pre-commit/lint.js @@ -89,7 +89,7 @@ function lintFiles(files) { // tsc & tslint const tsFiles = filterByExt(files, '.ts'); if (tsFiles.length !== 0) { - hasErrors = run('npm run tsc-all') || hasErrors; + hasErrors = run('npm run tsc-verify') || hasErrors; // we won't run tslint for all files // because it's slow as fuck (18s for all project) diff --git a/src/api/series-api.ts b/src/api/series-api.ts index 785271239..1307cc5dc 100644 --- a/src/api/series-api.ts +++ b/src/api/series-api.ts @@ -14,7 +14,7 @@ import { SeriesPartialOptionsMap, SeriesType, } from '../model/series-options'; -import { Logical, Range, TimePointIndex } from '../model/time-data'; +import { Logical, Range, TimePoint, TimePointIndex } from '../model/time-data'; import { TimeScaleVisibleRange } from '../model/time-scale-visible-range'; import { IPriceScaleApiProvider } from './chart-api'; @@ -138,7 +138,7 @@ export class SeriesApi implements ISeriesApi[]): void { - const convertedMarkers = data.map((marker: SeriesMarker