-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #348 from jaegertracing/plexus-type-defs
Export plexus type declarations, remove Neutrino
- Loading branch information
Showing
24 changed files
with
766 additions
and
403 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
build/**/*.js | ||
coverage/**/*.js | ||
build | ||
coverage | ||
packages/plexus/src/LayoutManager/layout.worker*js* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build | ||
dist | ||
lib | ||
src/LayoutManager/layout.worker*js* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,97 @@ | ||
# Build Considerations: `./packages/plexus` | ||
|
||
The package is implemented in TypeScript and must be compiled to JavaScript. The build output goes into `./build` as one main file, `./build/index.js`. | ||
**Note:** File references are relative to `./packages/plexus`; `./` refers to `./packages/plexus`. | ||
|
||
**Note:** File references are relative to `./packages/plexus`. E.g. `./` is actually referring to `./packages/plexus`, relative to the project root. | ||
The package is implemented in TypeScript and must be compiled to JavaScript. | ||
|
||
## Neutrino | ||
There are three build scenarios and one pre-step common to all of them. | ||
|
||
[Neutrino](https://master.neutrinojs.org/) is used to build `plexus`. The [release candidate for `v9`](https://github.com/neutrinojs/neutrino/milestone/6) is used. | ||
Pre-step: | ||
|
||
While Neutrino intends to allow for "zero initial configuration", that turned out not to be the case for `plexus`. | ||
* Bundle `./src/LayoutManager/layout.worker.tsx` to a UMD module which can initialize a `WebWorker` from a `Blob` URL | ||
|
||
`.neutrinorc.js` has a fair bit of configuration. It's well commented, so it won't be rehashed, here. | ||
Build scenarios: | ||
|
||
### `webpack.config.js` | ||
* Production ES modules | ||
* **This is the project's default export as `./lib/index.js`.** This build is not bundled and therefore does not use Webpack. | ||
* Production UMD module | ||
* Webpack dev server | ||
* Runs `./demo/src/index.tsx` which has a few example graphs. | ||
|
||
**Configures the webpack entry point.** Neutrino is used to generate the webpack config, but there were challenges in using it to set a non-Neutrino default entry point. | ||
The pre-step, which they all require, is to bundle `./src/LayoutManager/layout.worker.tsx` via the `worker-loader` Webpack loader. | ||
|
||
### `worker-alias` | ||
## Babel | ||
|
||
`worker-alias` is set up as a webpack alias in `.neutrinorc.js`. This alias matches a declaration in the project root: `../../typings/custom.d.ts`. See `../../BUILD.md` for details. | ||
Babel is used to transpile the TypeScript for all scenarios and the pre-step. See `babel.config.js` for specifics. | ||
|
||
## `package.json` | ||
The production ES module build is not bundled and therefore does not use Webpack. | ||
|
||
### Script `prepublishOnly` | ||
## Webpack | ||
|
||
Executed after `yarn install` is run in the project root. | ||
Webpack is used to: | ||
|
||
### Dependencies (dev and otherwise) | ||
* Bundle `./src/LayoutManager/layout.worker.tsx` so we can have a `WebWorker` without forcing folks to deal with an additional JavaScript asset | ||
* Bundle the production UMD module | ||
* Run the Webpack dev server during development | ||
|
||
#### `[email protected]` | ||
`./webpack-factory.js` is used to generate the Webpack configurations for each scenario. | ||
|
||
This specific version of [viz.js](https://github.com/mdaines/viz.js) is used to avoid a regression. Meanwhile, [looks like `2.x.x`](https://github.com/mdaines/viz.js/issues/120#issuecomment-389281407) has recovered a lot of ground; [GitHub ticket](https://github.com/jaegertracing/jaeger-ui/issues/339) to upgrade. | ||
## TypeScript `--emitDeclarationOnly` | ||
|
||
Compiling TypeScript via Babel does not allow for type declarations to be generated. So, `tsc` is used with `./tsconfig.json` to generate the type defs. | ||
|
||
This only applies to the ES module production build, output to `./lib`. | ||
|
||
Note: `./tsconfig.json` does not extend `../../tsconfig.json`. | ||
|
||
## Pre-step: `layout.worker` | ||
|
||
#### `worker-loader` | ||
`./src/LayoutManager/layout.worker.tsx` is intended to be loaded as a `WebWorker`. To be able to load it as a `Worker` without requiring an extra JS file, Webpack and the [`worker-loader`](https://github.com/webpack-contrib/worker-loader) loader are used to bundle it into a UMD module, `./src/LayoutManager/layout.worker.bundled.js`. | ||
|
||
[`worker-loader`](https://github.com/webpack-contrib/worker-loader) is a webpack plugin that allows a file to be imported as a class which, when instantiated, creates a WebWorker from the underlying source. | ||
Within the UMD module, `layout.worker.tsx` (and everything bundled into it) is turned into a `Blob` URL that's used to initialize a `WebWorker`. | ||
|
||
#### `@babel/preset-typescript` | ||
The resultant UMD module can be initialized as a class: | ||
|
||
TypeScript is compiled through Babel via [`@babel/preset-typescript`](https://babeljs.io/docs/en/babel-preset-typescript). **The TypeScript compiler is not used to compile TS files.** Note: `tsc` is used to compliment the use of ESLint to lint TypeScript, though. | ||
```ts | ||
import LayoutWorker from './layout.worker.bundled'; | ||
|
||
const leWorker = new LayoutWorker(); | ||
|
||
leWorker.postMessage(...); | ||
``` | ||
|
||
> It's all fun and games until type checking loses an eye. | ||
To make sure we don't end up with an implicit `any`, `layout.worker.bundled.d.ts` provides a type declaration: | ||
|
||
```ts | ||
class LayoutWorker extends Worker { ... } | ||
``` | ||
|
||
## `package.json` | ||
|
||
### Scripts | ||
|
||
* `build` — Generates the UMD bundle and ES module production builds | ||
* `prepublishOnly` — Executed after `yarn install` is run in the project root; runs the `build` script | ||
* `start` — Starts the Webpack dev server and watches all files, including `layout.worker` | ||
|
||
The `_tasks/*` scripts are not intended to be run, directly. | ||
|
||
* `_tasks/clean/*` | ||
* Remove generated files | ||
* `_tasks/bundle-worker` | ||
* Generates the `layout.worker` UMD bundle | ||
* `_tasks/build/*` | ||
* Generates the production ES and UMD builds | ||
* `_tasks/dev-server` | ||
* Starts the Webpack dev server | ||
|
||
### Dependencies (dev and otherwise) | ||
|
||
#### `[email protected]` | ||
|
||
This specific version of [viz.js](https://github.com/mdaines/viz.js) is used to avoid a regression. Meanwhile, [looks like `2.x.x`](https://github.com/mdaines/viz.js/issues/120#issuecomment-389281407) has recovered a lot of ground; [GitHub ticket](https://github.com/jaegertracing/jaeger-ui/issues/339) to upgrade. | ||
|
||
#### `[email protected]` | ||
|
||
|
@@ -48,8 +101,8 @@ Jest is not actually be used, yet. Present as a placeholder. ([Ticket](https://g | |
|
||
Configures ESLint for TypeScript. ESLint is executed from the project root, but this file is merged with the project root `.eslintrc.js` and overrides where there is overlap. | ||
|
||
Uses [`@typescript-eslint/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) as the parser. | ||
`prettier/@typescript-eslint` needs to be last in the `extends` so it overrides the formatting rules from `plugin:@typescript-eslint/recommended`. | ||
|
||
It's worth noting that the `tsconfig.json` is in the project root and `tsconfigRootDir: '.'` refers to the project root. | ||
Uses [`@typescript-eslint/parser`](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser) as the parser. | ||
|
||
`prettier/@typescript-eslint` needs to be last in the `extends` so it overrides the formatting rules from `plugin:@typescript-eslint/recommended`. | ||
The `tsconfigRootDir: '.'` refers to the project root because that is where ESLint is executed, from. And, the `tsconfig.json` referred to by `./.eslintrc.js` is that in the project root. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) 2019 Uber Technologies, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
function getBabelConfig(api) { | ||
const env = api.env(); | ||
return { | ||
plugins: [ | ||
'@babel/plugin-syntax-dynamic-import', | ||
[ | ||
'babel-plugin-transform-react-remove-prop-types', | ||
{ | ||
removeImport: true, | ||
}, | ||
], | ||
[ | ||
'@babel/plugin-proposal-class-properties', | ||
{ | ||
loose: true, | ||
}, | ||
], | ||
], | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
// this should match the settings in jaeger-ui/package.json | ||
targets: ['>0.5%', 'not dead', 'not ie <= 11', 'not op_mini all'], | ||
}, | ||
], | ||
[ | ||
'@babel/preset-react', | ||
{ | ||
development: env === 'development', | ||
useBuiltIns: true, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
], | ||
}; | ||
} | ||
|
||
module.exports = getBabelConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="<%= htmlWebpackPlugin.options.lang %>"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
|
||
<body> | ||
<div id="<%= htmlWebpackPlugin.options.appMountId %>"></div> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.