Skip to content

Commit

Permalink
Update TypeScript build setup (visgl#6802)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Apr 4, 2022
1 parent a942ada commit 853a8f6
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 145 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const config = deepMerge(defaultConfig, {
project: ['./tsconfig.json'],
ecmaVersion: 2020
},
extends: ['prettier'],

env: {
es2020: true
Expand Down
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workers/
**/dist*/**/*.js
**/dist*/**/*
dist.js
*.min.js
**/mapbox-gl-dev.js
Expand Down
2 changes: 1 addition & 1 deletion modules/aggregation-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@luma.gl/shadertools": "^8.5.10",
"@math.gl/web-mercator": "3.6.0-alpha.3",
"@math.gl/web-mercator": "3.6.0-alpha.5",
"d3-hexbin": "^0.2.1"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion modules/aggregation-layers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"},
Expand Down
2 changes: 1 addition & 1 deletion modules/arcgis/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/carto/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@loaders.gl/mvt": "^3.1.5",
"@loaders.gl/tiles": "^3.1.5",
"@luma.gl/constants": "^8.5.10",
"@math.gl/web-mercator": "3.6.0-alpha.3",
"@math.gl/web-mercator": "3.6.0-alpha.5",
"cartocolor": "^4.0.2",
"d3-array": "^2.8.0",
"d3-color": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/carto/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"},
Expand Down
6 changes: 3 additions & 3 deletions modules/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@
"@loaders.gl/images": "^3.1.5",
"@luma.gl/constants": "^8.5.10",
"@luma.gl/core": "^8.5.10",
"@math.gl/core": "3.6.0-alpha.3",
"@math.gl/web-mercator": "3.6.0-alpha.3",
"@math.gl/core": "3.6.0-alpha.5",
"@math.gl/web-mercator": "3.6.0-alpha.5",
"@probe.gl/env": "^3.5.0",
"@probe.gl/log": "^3.5.0",
"@probe.gl/stats": "^3.5.0",
"gl-matrix": "^3.0.0",
"math.gl": "3.6.0-alpha.3",
"math.gl": "3.6.0-alpha.5",
"mjolnir.js": "^2.7.0-alpha.2"
}
}
2 changes: 1 addition & 1 deletion modules/core/src/controllers/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export type ControllerOptions = {
inertia?: boolean | number;
};

type ControllerProps = {
export type ControllerProps = {
/** Identifier of the controller */
id: string;
/** Viewport x position */
Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/effect-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default class EffectManager {
}

// Private
setEffects(effects = []) {
setEffects(effects: Effect[] = []) {
this.cleanup();
this.effects = effects;

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/lib/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ export default abstract class Layer<
return false;
}

let redraw: string | boolean = false;
let redraw: string | false = false;
redraw = redraw || (this.internalState.needsRedraw && this.id);
this.internalState.needsRedraw = this.internalState.needsRedraw && !opts.clearRedrawFlags;

Expand Down
2 changes: 1 addition & 1 deletion modules/core/src/passes/pick-layers-pass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default class PickLayersPass extends LayersPass {
}

protected shouldDrawLayer(layer: Layer): boolean {
return layer.props.pickable && layer.props.operation === OPERATION.DRAW;
return (layer.props.pickable as boolean) && layer.props.operation === OPERATION.DRAW;
}

protected getModuleParameters() {
Expand Down
34 changes: 22 additions & 12 deletions modules/core/src/transitions/fly-to-interpolator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const LINEARLY_INTERPOLATED_PROPS = ['bearing', 'pitch'];
const DEFAULT_OPTS = {
speed: 1.2,
curve: 1.414
// screenSpeed and maxDuration are used only if specified
};

/**
Expand All @@ -18,24 +17,35 @@ const DEFAULT_OPTS = {
* "Jarke J. van Wijk and Wim A.A. Nuij"
*/
export default class FlyToInterpolator extends TransitionInterpolator {
/**
* @param props {Object}
- `props.curve` (Number, optional, default: 1.414) - The zooming "curve" that will occur along the flight path.
- `props.speed` (Number, optional, default: 1.2) - The average speed of the animation defined in relation to `options.curve`, it linearly affects the duration, higher speed returns smaller durations and vice versa.
- `props.screenSpeed` (Number, optional) - The average speed of the animation measured in screenfuls per second. Similar to `opts.speed` it linearly affects the duration, when specified `opts.speed` is ignored.
- `props.maxDuration` (Number, optional) - Maximum duration in milliseconds, if calculated duration exceeds this value, `0` is returned.
*/
constructor(props = {}) {
opts: {
curve: number;
speed: number;
screenSpeed?: number;
maxDuration?: number;
};

constructor(
opts: {
/** The zooming "curve" that will occur along the flight path. Default 1.414 */
curve?: number;
/** The average speed of the animation defined in relation to `options.curve`, it linearly affects the duration, higher speed returns smaller durations and vice versa. Default 1.2 */
speed?: number;
/** The average speed of the animation measured in screenfuls per second. Similar to `opts.speed` it linearly affects the duration, when specified `opts.speed` is ignored. */
screenSpeed?: number;
/** Maximum duration in milliseconds, if calculated duration exceeds this value, `0` is returned. */
maxDuration?: number;
} = {}
) {
super({
compare: ['longitude', 'latitude', 'zoom', 'bearing', 'pitch'],
extract: ['width', 'height', 'longitude', 'latitude', 'zoom', 'bearing', 'pitch'],
required: ['width', 'height', 'latitude', 'longitude', 'zoom']
});
this.props = {...DEFAULT_OPTS, ...props};
this.opts = {...DEFAULT_OPTS, ...opts};
}

interpolateProps(startProps, endProps, t) {
const viewport = flyToViewport(startProps, endProps, t, this.props);
const viewport = flyToViewport(startProps, endProps, t, this.opts);

// Linearly interpolate 'bearing' and 'pitch'.
// If pitch/bearing are not supplied, they are interpreted as zeros in viewport calculation
Expand All @@ -54,7 +64,7 @@ export default class FlyToInterpolator extends TransitionInterpolator {
let {transitionDuration} = endProps;
if (transitionDuration === 'auto') {
// auto calculate duration based on start and end props
transitionDuration = getFlyToDuration(startProps, endProps, this.props);
transitionDuration = getFlyToDuration(startProps, endProps, this.opts);
}
return transitionDuration;
}
Expand Down
16 changes: 11 additions & 5 deletions modules/core/src/transitions/linear-interpolator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import type Viewport from '../viewports/viewport';
const DEFAULT_PROPS = ['longitude', 'latitude', 'zoom', 'bearing', 'pitch'];
const DEFAULT_REQUIRED_PROPS = ['longitude', 'latitude', 'zoom'];

type PropsWithAnchor = {
around?: number[];
aroundPosition?: number[];
[key: string]: any;
};

/**
* Performs linear interpolation of two view states.
*/
Expand Down Expand Up @@ -58,8 +64,8 @@ export default class LinearInterpolator extends TransitionInterpolator {
startProps: Record<string, any>,
endProps: Record<string, any>
): {
start: Record<string, any>;
end: Record<string, any>;
start: PropsWithAnchor;
end: PropsWithAnchor;
} {
const result = super.initializeProps(startProps, endProps);

Expand All @@ -81,8 +87,8 @@ export default class LinearInterpolator extends TransitionInterpolator {
}

interpolateProps(
startProps: Record<string, any>,
endProps: Record<string, any>,
startProps: PropsWithAnchor,
endProps: PropsWithAnchor,
t: number
): Record<string, any> {
const propsInTransition = {};
Expand All @@ -98,7 +104,7 @@ export default class LinearInterpolator extends TransitionInterpolator {
viewport.panByPosition(
endProps.aroundPosition,
// anchor point in current screen coordinates
lerp(startProps.around, endProps.around, t)
lerp(startProps.around as number[], endProps.around as number[], t) as number[]
)
);
}
Expand Down
2 changes: 0 additions & 2 deletions modules/core/src/utils/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import {NumericArray} from '../types/types';

type NumericArray = number[];

/** Parse array or string color */
function parseColor(
color: NumericArray,
Expand Down
2 changes: 1 addition & 1 deletion modules/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
]
Expand Down
2 changes: 1 addition & 1 deletion modules/extensions/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
6 changes: 3 additions & 3 deletions modules/geo-layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"@loaders.gl/terrain": "^3.1.5",
"@loaders.gl/tiles": "^3.1.5",
"@luma.gl/experimental": "^8.5.10",
"@math.gl/core": "3.6.0-alpha.3",
"@math.gl/culling": "3.6.0-alpha.3",
"@math.gl/web-mercator": "3.6.0-alpha.3",
"@math.gl/core": "3.6.0-alpha.5",
"@math.gl/culling": "3.6.0-alpha.5",
"@math.gl/web-mercator": "3.6.0-alpha.5",
"h3-js": "^3.6.0",
"long": "^3.2.0"
},
Expand Down
2 changes: 1 addition & 1 deletion modules/geo-layers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"},
Expand Down
2 changes: 1 addition & 1 deletion modules/google-maps/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/json/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/jupyter-widget/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../aggregation-layers"},
Expand Down
2 changes: 1 addition & 1 deletion modules/layers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"dependencies": {
"@loaders.gl/images": "^3.1.5",
"@mapbox/tiny-sdf": "^1.1.0",
"@math.gl/polygon": "3.6.0-alpha.3",
"@math.gl/polygon": "3.6.0-alpha.5",
"earcut": "^2.0.6"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion modules/layers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../aggregation-layers"},
Expand Down
2 changes: 1 addition & 1 deletion modules/mapbox/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/mesh-layers/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/react/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
2 changes: 1 addition & 1 deletion modules/test-utils/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "dist"
"outDir": "dist/typed"
},
"references": [
{"path": "../core"}
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
"resolutions": {
"acorn": "7.4.1",
"prettier": "^2.4.1",
"@math.gl/core": "3.6.0-alpha.3"
"@math.gl/core": "3.6.0-alpha.5"
},
"scripts": {
"bootstrap": "PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true yarn && ocular-bootstrap",
"clean": "ocular-clean",
"build": "ocular-clean && ocular-build && lerna run build",
"build": "ocular-clean && ocular-build && npm run tsbuild && lerna run build",
"version": "ocular-build core",
"lint": "ocular-lint",
"cover": "ocular-test cover",
Expand All @@ -37,6 +37,8 @@
"test-fast": "ocular-test fast",
"test-node": "ocular-test node",
"test-browser": "ocular-test browser",
"tsclean": "find . -name tsconfig.tsbuildinfo -exec rm {} \\;",
"tsbuild": "tsc -b tsconfig.build.json",
"bench": "ocular-test bench",
"bench-browser": "ocular-test bench-browser",
"metrics": "ocular-metrics",
Expand Down
Loading

0 comments on commit 853a8f6

Please sign in to comment.