-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c932c5e
commit f0e8ea3
Showing
11 changed files
with
186 additions
and
24 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
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,34 @@ | ||
# Update to Native Federation for Angular 18 | ||
|
||
The package ``@angular-architects/native-federation`` version 18 was successfully tested with Angular 18. | ||
|
||
## Option 1 | ||
|
||
Just use ``ng update``: | ||
|
||
``` | ||
ng update @angular-architects/native-federation | ||
``` | ||
|
||
## Option 2 | ||
|
||
Use npm install: | ||
|
||
``` | ||
npm i @angular-architects/native-federation@^18 | ||
``` | ||
|
||
Make sure you have the following ``postinstall`` script in your ``package.json``: | ||
|
||
```json | ||
"scripts": { | ||
[...] | ||
"postinstall": "node node_modules/@angular-architects/native-federation/src/patch-angular-build.js" | ||
}, | ||
``` | ||
|
||
Run the ``postinstall`` script once manually for initialization: | ||
|
||
``` | ||
npm run postinstall | ||
``` |
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 @@ | ||
{ | ||
"$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
"name": "native-federation", | ||
"version": "0.0.1", | ||
"schematics": { | ||
"update18": { | ||
"version": "18", | ||
"factory": "./src/schematics/update18/schematic", | ||
"schema": "./src/schematics/update18/schema.json", | ||
"description": "migrating to v18" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { patchAngularBuild } from './utils/patch-angular-build'; | ||
|
||
const workspaceRoot = process.cwd(); | ||
patchAngularBuild(workspaceRoot); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"$id": "mf", | ||
"title": "", | ||
"type": "object", | ||
"properties": { | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
libs/native-federation/src/schematics/update18/schematic.ts
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,10 @@ | ||
import { Rule, Tree } from '@angular-devkit/schematics'; | ||
|
||
import { patchAngularBuild, updatePackageJson } from '../init/schematic'; | ||
|
||
export default function update18(): Rule { | ||
return async function (tree: Tree) { | ||
updatePackageJson(tree); | ||
patchAngularBuild(tree); | ||
}; | ||
} |
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,30 @@ | ||
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
|
||
export function patchAngularBuildPackageJson(packageJson: unknown): void { | ||
const exportsMap = packageJson['exports']; | ||
|
||
if (!exportsMap) { | ||
console.log('No need to patch @angular/build/package.json') | ||
return; | ||
} | ||
|
||
packageJson['_exports'] = exportsMap; | ||
delete packageJson['exports']; | ||
|
||
packageJson['types'] = './src/index.d.ts'; | ||
packageJson['main'] = './src/index.js'; | ||
packageJson['module'] = './src/index.js'; | ||
} | ||
|
||
export function patchAngularBuild(workspaceRoot: string): void { | ||
const packagePath = path.join(workspaceRoot, 'node_modules/@angular/build/package.json'); | ||
|
||
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8')); | ||
|
||
patchAngularBuildPackageJson(packageJson); | ||
|
||
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2)); | ||
|
||
console.log('@angular/build/package.json patched'); | ||
} |