Skip to content

Commit

Permalink
[@osd/pm] Automate multi-target bootstrap and build
Browse files Browse the repository at this point in the history
Also:
* build @osd/std for multiple targets
* convert @osd/i18n and @osd/ace from custom build scripts to targeted build process
* have @osd/optimizer ignore already built artifacts

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Aug 1, 2023
1 parent a52e95c commit 5607ebe
Show file tree
Hide file tree
Showing 17 changed files with 9,757 additions and 9,388 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Removes `minimatch` manual resolution ([#3019](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3019))
- Upgrade `vega-lite` dependency from `4.17.0` to `^5.6.0` ([#3076](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3076)). Backwards-compatible version included in v2.5.0 release.
- Bump `js-yaml` from `3.14.0` to `4.1.0` ([#3770](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/3770))
- [@osd/pm] Automate multi-target bootstrap and build ([#4650](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/4650))

### 🪛 Refactoring

Expand Down
7 changes: 6 additions & 1 deletion packages/osd-ace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "@osd/ace",
"version": "1.0.0",
"private": true,
"main": "./target/index.js",
"browser": "./target/web/index.js",
"main": "./target/web/index.js",
"types": "./target/types/index.d.ts",
"license": "Apache-2.0",
"scripts": {
"build": "../../scripts/use_node ./scripts/build.js",
Expand All @@ -17,5 +19,8 @@
"raw-loader": "^4.0.2",
"typescript": "4.0.2",
"webpack": "npm:@amoo-miki/[email protected]"
},
"@osd/pm": {
"web": true
}
}
5 changes: 3 additions & 2 deletions packages/osd-ace/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./target",
"outDir": "./target/types",
"declaration": true,
"sourceMap": true,
"types": [
Expand All @@ -11,5 +11,6 @@
},
"include": [
"src/**/*"
]
],
"exclude": ["target"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ export function simpleOpenSearchDashboardsPlatformPluginDiscovery(
(acc: string[], dir) => [
...acc,
resolve(dir, '*/opensearch_dashboards.json'),
resolve(dir, '*/*/opensearch_dashboards.json'),
resolve(dir, '*/*/*/opensearch_dashboards.json'),
resolve(dir, '*/*/*/*/opensearch_dashboards.json'),
resolve(dir, '*/*/*/*/*/opensearch_dashboards.json'),
resolve(dir, '*/!(build)/opensearch_dashboards.json'),
resolve(dir, '*/!(build)/*/opensearch_dashboards.json'),
resolve(dir, '*/!(build)/*/*/opensearch_dashboards.json'),
resolve(dir, '*/!(build)/*/*/*/opensearch_dashboards.json'),
],
[]
),
Expand Down
9 changes: 4 additions & 5 deletions packages/osd-i18n/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
"version": "1.0.0",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "../../scripts/use_node scripts/build",
"osd:bootstrap": "../../scripts/use_node scripts/build --source-maps",
"osd:watch": "../../scripts/use_node scripts/build --watch --source-maps"
},
"devDependencies": {
"@babel/cli": "^7.16.0",
"@babel/core": "^7.16.5",
Expand All @@ -30,5 +25,9 @@
"prop-types": "^15.7.2",
"react": "^16.14.0",
"react-intl": "^2.8.0"
},
"@osd/pm": {
"node": true,
"web": true
}
}
5 changes: 4 additions & 1 deletion packages/osd-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,10 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
test: /\.(js|tsx?)$/,
// vega-lite and some of its dependencies don't have es5 builds
// so we need to build from source and transpile for webpack v4
exclude: /[\/\\]node_modules[\/\\](?!vega-(lite|label|functions)[\/\\])/,
exclude: [
/[\/\\]node_modules[\/\\](?!vega-(lite|label|functions)[\/\\])/,
/[\/\\]plugins[\/\\][^\/\\]+[\/\\]build[\/\\]/,
],
use: {
loader: 'babel-loader',
options: {
Expand Down
21 changes: 21 additions & 0 deletions packages/osd-pm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,27 @@ The production build process relies on both the Grunt setup at the root of the
OpenSearch Dashboards project and code in `@osd/pm`. The full process is described in
`tasks/build/packages.js`.

## Targeted builds

Packages that are only compiled to CommonJS for consumption in Node.js code, simply use a `tsconfig.json`
that extends the `tsconfig.base.json` found at the root of the project. Similarly, packages that need to be
compiled into ES modules, to be consumed in the browser and benefit from tree-shaking, would use a
`tsconfig.json` that extends the `tsconfig.browser.json` available at the root of the project. However,
some packages would need to be compiled to be used by both Node.js and the browser. This can be achieved by
retaining the `tsconfig.json` and adding the following block to the `package.json` of the package:
```json
"@osd/pm": {
"node": true,
"web": true
}
```
This would result in the relevant presets from `@osd/babel-preset` being applied to the code to produce
both, bootstrap and production build artifacts, for the selected targets. It is acceptable to have only one
target and that would be equivalent to setting the appropriate `extends` in ths `tsconfig.json`.

Targeted builds call `babel` on the `src` folder and place artifacts into `target/node` and `target/web`
folders after calling `tsc` in the package root to generate type definitions.

## Development

This package is run from OpenSearch Dashboards root, using `yarn osd`. This will run the
Expand Down
Loading

0 comments on commit 5607ebe

Please sign in to comment.