Skip to content

Commit 6170f35

Browse files
committed
fix(nf): don't patch @angular/build if it is not present
1 parent 63cb5d7 commit 6170f35

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
1414
import { strings } from '@angular-devkit/core';
1515
import { MfSchematicSchema } from './schema';
1616

17-
import { patchAngularBuildPackageJson } from '../../utils/patch-angular-build';
17+
import { patchAngularBuildPackageJson, privateEntrySrc } from '../../utils/patch-angular-build';
1818

1919
import {
2020
addPackageJsonDependency,
@@ -117,14 +117,26 @@ export default function config(options: MfSchematicSchema): Rule {
117117
}
118118

119119
export function patchAngularBuild(tree) {
120+
const packagePath = 'node_modules/@angular/build/package.json';
121+
const privatePath = 'node_modules/@angular/build/private.js';
122+
123+
if (!tree.exists(packagePath)) {
124+
return;
125+
}
126+
120127
const packageJson = JSON.parse(
121-
tree.read('node_modules/@angular/build/package.json')
128+
tree.read(packagePath)
122129
);
123130
patchAngularBuildPackageJson(packageJson);
124131
tree.overwrite(
125-
'node_modules/@angular/build/package.json',
132+
packagePath,
126133
JSON.stringify(packageJson, null, 2)
127134
);
135+
tree.overwrite(
136+
privatePath,
137+
privateEntrySrc
138+
);
139+
128140
}
129141

130142
function updateWorkspaceConfig(

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
33

4+
export const privateEntrySrc = `
5+
exports = require('./src/private.js');
6+
`;
7+
48
export function patchAngularBuildPackageJson(packageJson: unknown): void {
59
const exportsMap = packageJson['exports'];
610

@@ -23,11 +27,21 @@ export function patchAngularBuild(workspaceRoot: string): void {
2327
'node_modules/@angular/build/package.json'
2428
);
2529

30+
const privatePath = path.join(
31+
workspaceRoot,
32+
'node_modules/@angular/build/private.js'
33+
);
34+
35+
if (!fs.existsSync(packagePath)) {
36+
return;
37+
}
38+
2639
const packageJson = JSON.parse(fs.readFileSync(packagePath, 'utf-8'));
2740

2841
patchAngularBuildPackageJson(packageJson);
2942

3043
fs.writeFileSync(packagePath, JSON.stringify(packageJson, null, 2));
44+
fs.writeFileSync(privatePath, privateEntrySrc);
3145

3246
console.log('@angular/build/package.json patched');
3347
}

0 commit comments

Comments
 (0)