Skip to content

Commit 3b58277

Browse files
Build Angular packages with ng-packagr (#2236)
This replaces the use of ngc with ng-packagr when building the angular packages. With this, the libraries don't provide a cjs output anymore, only (partially compiled) *esm. In order to tidy the output, the sources have been moved to a library sub folder and exposed via a commonly used public_api file. The example for the angular material renderer has also been modified to import the output of the library instead of the sources. This allows to actually validate that the package can be loaded and fully compiled (rather than rebuilding everything, the lib + the app, all at once). Therefore, the use of rollup has been dropped in favor of the internal angular browser builder. This also adds `@angular/core` as dev dependency to root package.json to facilitate the new build working with angular-material's `dev` npm script from within the package. --------- Co-authored-by: Lucas Koehler <lkoehler@eclipsesource.com>
1 parent 0e4f7ed commit 3b58277

81 files changed

Lines changed: 379 additions & 441 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"build:examples-app": "lerna run build:examples-app && node packages/examples-app/prepare-examples-app.js"
2121
},
2222
"devDependencies": {
23+
"@angular/core": "^16.0.0",
2324
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.5",
2425
"@babel/plugin-proposal-optional-chaining": "^7.16.5",
2526
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const path = require('path');
2+
const ngCore = require('@angular-devkit/core');
3+
const buildWebpackBrowser = require('@angular-devkit/build-angular/src/builders/browser').buildWebpackBrowser;
4+
5+
const main = async () => new Promise((resolve, reject) => {
6+
const project = 'angular-material';
7+
const target = 'build';
8+
const configuration = '';
9+
const workspaceRoot = path.join(process.cwd(), '../..');
10+
const root = `packages/${project}`;
11+
const options = {
12+
outputPath: root + '/example/dist',
13+
tsConfig: root + '/tsconfig.example.json',
14+
main: root + '/example/main.ts',
15+
index: root + '/example/index.html',
16+
styles: [
17+
root + '/node_modules/@angular/material/prebuilt-themes/indigo-pink.css'
18+
],
19+
allowedCommonJsDependencies: [
20+
'lodash',
21+
'hammerjs'
22+
],
23+
watch: false,
24+
buildOptimizer: false,
25+
optimization: false,
26+
outputHashing: 'none',
27+
};
28+
const sourceRoot = root;
29+
const teardownLogics = [];
30+
const context = {
31+
workspaceRoot,
32+
logger: new ngCore.logging.Logger(`${project}:${target}:`),
33+
target: {
34+
project,
35+
configuration,
36+
target
37+
},
38+
getProjectMetadata: (projectName) => Promise.resolve({
39+
root,
40+
sourceRoot
41+
}),
42+
getBuilderNameForTarget: () => '@angular-devkit/build-angular:karma',
43+
getTargetOptions: (target) => ({...options}),
44+
validateOptions: (options) => options,
45+
addTeardown: (teardown) => {
46+
teardownLogics.push(teardown);
47+
}
48+
};
49+
let exitCode = 1;
50+
buildWebpackBrowser(options, context, {}).subscribe({
51+
next: out => {
52+
if (out.success) {
53+
exitCode = 0;
54+
}
55+
},
56+
error: (err) => {
57+
reject(err);
58+
},
59+
complete: () => {
60+
if (!exitCode) return resolve();
61+
reject();
62+
}
63+
});
64+
return exitCode;
65+
});
66+
67+
main()
68+
.then(() => {
69+
process.exit(0);
70+
})
71+
.catch(err => {
72+
process.exit(1);
73+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const ngPackage = require('ng-packagr');
2+
3+
ngPackage
4+
.ngPackagr()
5+
.forProject('ng-package.json')
6+
.withTsConfig('tsconfig.json')
7+
.build()
8+
.catch(error => {
9+
console.error(error);
10+
process.exit(1);
11+
});

packages/angular-material/example/app/app.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
UISchemaElement,
3030
UISchemaTester,
3131
} from '@jsonforms/core';
32-
import { angularMaterialRenderers } from '../../src/index';
32+
import { angularMaterialRenderers } from '../../lib';
3333
import { DateAdapter } from '@angular/material/core';
3434

3535
const uiSchema = {

packages/angular-material/example/app/app.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { BrowserModule } from '@angular/platform-browser';
2626
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
2727
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
2828
import { AppComponent } from './app.component';
29-
import { JsonFormsAngularMaterialModule } from '../../src/module';
29+
import { JsonFormsAngularMaterialModule } from '../../lib';
3030

3131
@NgModule({
3232
declarations: [AppComponent],

packages/angular-material/example/index.bundled.html

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/angular-material/example/index.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
<html lang="en">
33
<head>
44
<meta charset="utf-8" />
5-
<title>Tour of Heroes</title>
6-
<base href="/" />
5+
<title>JSON Forms Angular Material RendererSet</title>
76

87
<meta name="viewport" content="width=device-width, initial-scale=1" />
98
<link rel="icon" type="image/x-icon" href="favicon.ico" />
10-
<link href="assets/indigo-pink.css" rel="stylesheet" />
119
<link
1210
href="https://fonts.googleapis.com/icon?family=Material+Icons"
1311
rel="stylesheet"
@@ -21,7 +19,6 @@
2119
<body>
2220
<app-root></app-root>
2321
</body>
24-
<script src="assets/bundle.js"></script>
2522
</html>
2623

2724
<!--

packages/angular-material/example/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
THE SOFTWARE.
2424
*/
25-
import 'core-js/es/reflect';
26-
import 'zone.js/dist/zone';
25+
import 'zone.js';
2726
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
2827

2928
import { AppModule } from './app/app.module';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "./lib",
4+
"allowedNonPeerDependencies": [
5+
"@jsonforms/angular",
6+
"@jsonforms/core",
7+
"hammerjs",
8+
"lodash"
9+
]
10+
}

packages/angular-material/package.json

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,11 @@
3434
"layout",
3535
"customization"
3636
],
37-
"main": "./lib/cjs/index.js",
38-
"module": "./lib/esm/index.js",
39-
"typings": "./lib/esm/index.d.ts",
37+
"module": "./lib/fesm2022/jsonforms-angular-material.mjs",
38+
"typings": "./lib/index.d.ts",
4039
"scripts": {
41-
"build": "ngc && ngc -p tsconfig.cjs.json",
42-
"build:examples-app": "ngc -p tsconfig.example.json && rollup -c rollup.example.config.js --bundleConfigAsCjs",
40+
"build": "node ./build-package.js",
41+
"build:examples-app": "pnpm run build && node ./build-example.js",
4342
"dev": "pnpm run build:examples-app && npx http-server ./example/dist/ -c-1 -o",
4443
"clean": "rimraf lib coverage dist .nyc_output 2> /dev/null",
4544
"lint": "eslint .",
@@ -79,6 +78,7 @@
7978
},
8079
"devDependencies": {
8180
"@angular-devkit/build-angular": "^16.0.0",
81+
"@angular-devkit/core": "^16.0.0",
8282
"@angular-eslint/eslint-plugin": "^16.0.0",
8383
"@angular-eslint/eslint-plugin-template": "^16.0.0",
8484
"@angular-eslint/schematics": "^16.0.0",
@@ -101,10 +101,6 @@
101101
"@jsonforms/core": "workspace:*",
102102
"@jsonforms/examples": "workspace:*",
103103
"@ngtools/webpack": "^16.0.0",
104-
"@rollup/plugin-commonjs": "^23.0.3",
105-
"@rollup/plugin-json": "^6.0.0",
106-
"@rollup/plugin-node-resolve": "^15.0.1",
107-
"@rollup/plugin-replace": "^5.0.1",
108104
"@types/jasmine": "~3.8.0",
109105
"@types/lodash": "4.14.149",
110106
"@types/node": "^18.19.4",
@@ -133,10 +129,6 @@
133129
"prettier": "^2.8.4",
134130
"protractor": "^7.0.0",
135131
"rimraf": "^3.0.2",
136-
"rollup": "^3.0.0",
137-
"rollup-plugin-copy": "^3.4.0",
138-
"rollup-plugin-import-css": "^3.3.1",
139-
"rollup-plugin-typescript2": "^0.34.1",
140132
"rxjs": "^6.6.0",
141133
"ts-loader": "^6.2.1",
142134
"tslib": "^2.5.0",

0 commit comments

Comments
 (0)