mirror of
https://github.com/tradingview/lightweight-charts.git
synced 2024-11-25 16:50:59 +08:00
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)
This commit is contained in:
parent
6f582133cf
commit
080aa9aa52
@ -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: ./
|
||||
|
@ -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
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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<TSeriesType extends SeriesType> implements ISeriesApi<TSe
|
||||
}
|
||||
|
||||
public setMarkers(data: SeriesMarker<Time>[]): void {
|
||||
const convertedMarkers = data.map((marker: SeriesMarker<Time>) => ({
|
||||
const convertedMarkers = data.map<SeriesMarker<TimePoint>>((marker: SeriesMarker<Time>) => ({
|
||||
...marker,
|
||||
time: convertTime(marker.time),
|
||||
}));
|
||||
|
@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "../../tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "../formatters/tsconfig.composite.json" },
|
||||
{ "path": "../gui/tsconfig.composite.json" },
|
||||
|
@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "../../tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "../helpers/tsconfig.composite.json" }
|
||||
],
|
||||
|
@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "../../tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "../tsconfig.model.json" }
|
||||
],
|
||||
|
@ -28,6 +28,7 @@ type AlphaComponent = Nominal<number, 'AlphaComponent'>;
|
||||
export type Rgb = [RedComponent, GreenComponent, BlueComponent];
|
||||
type Rgba = [RedComponent, GreenComponent, BlueComponent, AlphaComponent];
|
||||
|
||||
/** @public */
|
||||
const namedColorRgbHexStrings: Record<string, string> = {
|
||||
aliceblue: '#f0f8ff',
|
||||
antiquewhite: '#faebd7',
|
||||
|
@ -1,9 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [],
|
||||
"extends": "../../tsconfig.composite.base.json",
|
||||
"include": [
|
||||
"./**/*.ts"
|
||||
]
|
||||
|
@ -20,6 +20,7 @@ export const enum SeriesPlotIndex {
|
||||
Color = 4,
|
||||
}
|
||||
|
||||
/** @public */
|
||||
const barFunctions = {
|
||||
open: (bar: Bar['value']) => bar[SeriesPlotIndex.Open] as BarPrice,
|
||||
|
||||
|
@ -284,7 +284,7 @@ export class Series<T extends SeriesType = SeriesType> extends PriceDataSource i
|
||||
}
|
||||
|
||||
public setMarkers(data: SeriesMarker<TimePoint>[]): void {
|
||||
this._markers = data.map((item: SeriesMarker<TimePoint>) => ({ ...item }));
|
||||
this._markers = data.map<SeriesMarker<TimePoint>>((item: SeriesMarker<TimePoint>) => ({ ...item }));
|
||||
this._recalculateMarkers();
|
||||
const sourcePane = this.model().paneForSource(this);
|
||||
this._markersPaneView.update('data');
|
||||
@ -564,7 +564,7 @@ export class Series<T extends SeriesType = SeriesType> extends PriceDataSource i
|
||||
return;
|
||||
}
|
||||
|
||||
this._indexedMarkers = this._markers.map((marker: SeriesMarker<TimePoint>, index: number) => ({
|
||||
this._indexedMarkers = this._markers.map<InternalSeriesMarker<TimePointIndex>>((marker: SeriesMarker<TimePoint>, index: number) => ({
|
||||
time: ensureNotNull(timeScalePoints.indexOf(marker.time.timestamp, true)),
|
||||
position: marker.position,
|
||||
shape: marker.shape,
|
||||
|
@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "../tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "./api/tsconfig.composite.json" },
|
||||
{ "path": "./formatters/tsconfig.composite.json" },
|
||||
|
@ -1,8 +1,5 @@
|
||||
{
|
||||
"extends": "../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "../tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "./formatters/tsconfig.composite.json" },
|
||||
{ "path": "./helpers/tsconfig.composite.json" }
|
||||
|
@ -150,7 +150,7 @@ export class SeriesMarkersPaneView implements IUpdatablePaneView {
|
||||
const timeScale = this._model.timeScale();
|
||||
const seriesMarkers = this._series.indexedMarkers();
|
||||
if (this._dataInvalidated) {
|
||||
this._data.items = seriesMarkers.map((marker: InternalSeriesMarker<TimePointIndex>) => ({
|
||||
this._data.items = seriesMarkers.map<SeriesMarkerRendererDataItem>((marker: InternalSeriesMarker<TimePointIndex>) => ({
|
||||
time: marker.time,
|
||||
x: 0 as Coordinate,
|
||||
y: 0 as Coordinate,
|
||||
|
@ -22,7 +22,7 @@ function isTestCaseFile(filePath: string): boolean {
|
||||
export function getTestCases(): TestCase[] {
|
||||
return fs.readdirSync(testCasesDir)
|
||||
.filter(isTestCaseFile)
|
||||
.map((testCaseFile: string) => ({
|
||||
.map<TestCase>((testCaseFile: string) => ({
|
||||
name: extractTestCaseName(testCaseFile) as string,
|
||||
caseContent: fs.readFileSync(path.join(testCasesDir, testCaseFile), { encoding: 'utf-8' }),
|
||||
}));
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"extends": "../../tsconfig.options.json",
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"lib": [
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"extends": "../../tsconfig.composite.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "commonjs"
|
||||
},
|
||||
"references": [
|
||||
|
9
tsconfig.composite.base.json
Normal file
9
tsconfig.composite.base.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "./tsconfig.options.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"outDir": "lib/composite"
|
||||
},
|
||||
"references": [],
|
||||
"include": []
|
||||
}
|
@ -1,11 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"extends": "./tsconfig.composite.base.json",
|
||||
"references": [
|
||||
{ "path": "./src/tsconfig.composite.json" },
|
||||
{ "path": "./tests/unittests/tsconfig.composite.json" }
|
||||
],
|
||||
"include": []
|
||||
]
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
{
|
||||
"extends": "./tsconfig.base.json",
|
||||
"extends": "./tsconfig.options.json",
|
||||
"compilerOptions": {
|
||||
"noEmit": true,
|
||||
"stripInternal": true,
|
||||
"noEmit": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
|
@ -18,11 +18,6 @@
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noImplicitReturns": true,
|
||||
"noUnusedLocals": true,
|
||||
"outDir": "lib",
|
||||
"plugins": [
|
||||
{ "transform": "ts-transformer-minify-privates" },
|
||||
{ "transform": "ts-transformer-strip-const-enums" }
|
||||
],
|
||||
"preserveConstEnums": true,
|
||||
"resolveJsonModule": true,
|
||||
"rootDir": "./",
|
14
tsconfig.prod.json
Normal file
14
tsconfig.prod.json
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "./tsconfig.options.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "lib/prod",
|
||||
"plugins": [
|
||||
{ "transform": "ts-transformer-strip-const-enums", "entrySourceFiles": ["./src/index.ts"] },
|
||||
{ "transform": "ts-transformer-properties-rename", "entrySourceFiles": ["./src/index.ts"] }
|
||||
],
|
||||
"stripInternal": true
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts"
|
||||
]
|
||||
}
|
@ -131,7 +131,7 @@
|
||||
"no-parameter-properties": true,
|
||||
"no-parameter-reassignment": false,
|
||||
"no-promise-as-boolean": false,
|
||||
"no-redundant-jsdoc": true,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-reference": false,
|
||||
"no-reference-import": true,
|
||||
"no-require-imports": false,
|
||||
|
Loading…
Reference in New Issue
Block a user