Skip to content

Commit 63cb5d7

Browse files
committed
docs(nf): remarks for the postinstall script
1 parent f0e8ea3 commit 63cb5d7

File tree

6 files changed

+66
-46
lines changed

6 files changed

+66
-46
lines changed

libs/native-federation/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ We will at least provide a new version of this package per Angular major. If nec
2626
- Use version 17.1.x for Angular 17.1+
2727
- Use version 18.x for Angular 18+
2828

29+
## Updates
30+
31+
You can use ng update for updating Native Federation.
32+
33+
Notes for [updating to version 18](https://github.com/angular-architects/module-federation-plugin/blob/main/libs/native-federation/docs/update18.md)
34+
2935
## Angular Integration
3036

3137
Since 17.1, Native Federation for Angular uses the Angular CLI's `esbuild`-based **Application Builder** and the CLI's **Dev Server** to keep track with all the innovations and performance-improvements in that space.

libs/native-federation/docs/update18.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Update to Native Federation for Angular 18
22

3-
The package ``@angular-architects/native-federation`` version 18 was successfully tested with Angular 18.
3+
The package `@angular-architects/native-federation` version 18 was successfully tested with Angular 18.
44

55
## Option 1
66

7-
Just use ``ng update``:
7+
Just use `ng update`:
88

99
```
1010
ng update @angular-architects/native-federation
@@ -18,7 +18,7 @@ Use npm install:
1818
npm i @angular-architects/native-federation@^18
1919
```
2020

21-
Make sure you have the following ``postinstall`` script in your ``package.json``:
21+
Make sure you have the following `postinstall` script in your `package.json`:
2222

2323
```json
2424
"scripts": {
@@ -27,8 +27,10 @@ Make sure you have the following ``postinstall`` script in your ``package.json``
2727
},
2828
```
2929

30-
Run the ``postinstall`` script once manually for initialization:
30+
**Remarks:** This script is just a temporary solution. It won't be necessary in future versions.
31+
32+
Run the `postinstall` script once manually for initialization:
3133

3234
```
3335
npm run postinstall
34-
```
36+
```

libs/native-federation/src/builders/build/builder.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import {
1111
createBuilder,
1212
} from '@angular-devkit/architect';
1313

14-
import { buildApplication, buildApplicationInternal } from '@angular/build/src/builders/application';
14+
import {
15+
buildApplication,
16+
buildApplicationInternal,
17+
} from '@angular/build/src/builders/application';
1518
import { serveWithVite } from '@angular/build/src/builders/dev-server/vite-server';
1619

17-
import {
18-
DevServerBuilderOptions,
19-
} from '@angular-devkit/build-angular';
20+
import { DevServerBuilderOptions } from '@angular-devkit/build-angular';
2021
import { normalizeOptions } from '@angular-devkit/build-angular/src/builders/dev-server/options';
2122

2223
import { setLogLevel, logger } from '@softarc/native-federation/build';
@@ -59,11 +60,15 @@ function _buildApplication(options, context, pluginsOrExtensions) {
5960
extensions = {
6061
codePlugins: pluginsOrExtensions,
6162
};
62-
}
63-
else {
63+
} else {
6464
extensions = pluginsOrExtensions;
6565
}
66-
return buildApplicationInternal(options, context, { write: false }, extensions);
66+
return buildApplicationInternal(
67+
options,
68+
context,
69+
{ write: false },
70+
extensions
71+
);
6772
}
6873

6974
export async function* runBuilder(
@@ -235,18 +240,18 @@ export async function* runBuilder(
235240

236241
const builderRun = nfOptions.dev
237242
? serveWithVite(
238-
normOuterOptions,
239-
appBuilderName,
240-
_buildApplication,
241-
context,
242-
nfOptions.skipHtmlTransform
243-
? {}
244-
: { indexHtml: transformIndexHtml(nfOptions) },
245-
{
246-
buildPlugins: plugins,
247-
middleware,
248-
}
249-
)
243+
normOuterOptions,
244+
appBuilderName,
245+
_buildApplication,
246+
context,
247+
nfOptions.skipHtmlTransform
248+
? {}
249+
: { indexHtml: transformIndexHtml(nfOptions) },
250+
{
251+
buildPlugins: plugins,
252+
middleware,
253+
}
254+
)
250255
: buildApplication(options, context, plugins);
251256

252257
// builderRun.output.subscribe(async (output) => {

libs/native-federation/src/schematics/init/schematic.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ type NormalizedOptions = {
3737
export function updatePackageJson(tree: Tree): void {
3838
const packageJson = tree.readJson('package.json');
3939

40-
const scriptCall = 'node node_modules/@angular-architects/native-federation/src/patch-angular-build.js';
40+
const scriptCall =
41+
'node node_modules/@angular-architects/native-federation/src/patch-angular-build.js';
4142

4243
if (!packageJson['scripts']) {
4344
packageJson['scripts'] = {};
@@ -57,7 +58,6 @@ export function updatePackageJson(tree: Tree): void {
5758
packageJson['scripts']['postinstall'] = postInstall;
5859

5960
tree.overwrite('package.json', JSON.stringify(packageJson, null, 2));
60-
6161
}
6262

6363
export default function config(options: MfSchematicSchema): Rule {
@@ -117,9 +117,14 @@ export default function config(options: MfSchematicSchema): Rule {
117117
}
118118

119119
export function patchAngularBuild(tree) {
120-
const packageJson = JSON.parse(tree.read('node_modules/@angular/build/package.json'));
120+
const packageJson = JSON.parse(
121+
tree.read('node_modules/@angular/build/package.json')
122+
);
121123
patchAngularBuildPackageJson(packageJson);
122-
tree.overwrite('node_modules/@angular/build/package.json', JSON.stringify(packageJson, null, 2));
124+
tree.overwrite(
125+
'node_modules/@angular/build/package.json',
126+
JSON.stringify(packageJson, null, 2)
127+
);
123128
}
124129

125130
function updateWorkspaceConfig(

libs/native-federation/src/schematics/update18/schema.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
"$id": "mf",
44
"title": "",
55
"type": "object",
6-
"properties": {
7-
}
6+
"properties": {}
87
}

libs/native-federation/src/utils/patch-angular-build.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@ import * as path from 'path';
22
import * as fs from 'fs';
33

44
export function patchAngularBuildPackageJson(packageJson: unknown): void {
5-
const exportsMap = packageJson['exports'];
5+
const exportsMap = packageJson['exports'];
66

7-
if (!exportsMap) {
8-
console.log('No need to patch @angular/build/package.json')
9-
return;
10-
}
7+
if (!exportsMap) {
8+
console.log('No need to patch @angular/build/package.json');
9+
return;
10+
}
1111

12-
packageJson['_exports'] = exportsMap;
13-
delete packageJson['exports'];
12+
packageJson['_exports'] = exportsMap;
13+
delete packageJson['exports'];
1414

15-
packageJson['types'] = './src/index.d.ts';
16-
packageJson['main'] = './src/index.js';
17-
packageJson['module'] = './src/index.js';
15+
packageJson['types'] = './src/index.d.ts';
16+
packageJson['main'] = './src/index.js';
17+
packageJson['module'] = './src/index.js';
1818
}
1919

2020
export function patchAngularBuild(workspaceRoot: string): void {
21-
const packagePath = path.join(workspaceRoot, 'node_modules/@angular/build/package.json');
21+
const packagePath = path.join(
22+
workspaceRoot,
23+
'node_modules/@angular/build/package.json'
24+
);
2225

23-
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
26+
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
2427

25-
patchAngularBuildPackageJson(packageJson);
28+
patchAngularBuildPackageJson(packageJson);
2629

27-
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
30+
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
2831

29-
console.log('@angular/build/package.json patched');
30-
}
32+
console.log('@angular/build/package.json patched');
33+
}

0 commit comments

Comments
 (0)