Skip to content

Commit c0b27fd

Browse files
committed
fix(mf): adjust to new builder name in nx
1 parent 6978663 commit c0b27fd

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

libs/mf-runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@angular-architects/module-federation-runtime",
33
"license": "MIT",
4-
"version": "14.3.12",
4+
"version": "14.3.14",
55
"peerDependencies": {
66
"@angular/common": ">=14.0.0",
77
"@angular/core": ">=14.0.0"

libs/mf-tools/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@angular-architects/module-federation-tools",
3-
"version": "14.3.12",
3+
"version": "14.3.14",
44
"license": "MIT",
55
"peerDependencies": {
66
"@angular/common": ">=14.0.0",
77
"@angular/core": ">=14.0.0",
88
"@angular/router": ">=14.0.0",
9-
"@angular-architects/module-federation": "^14.3.12",
9+
"@angular-architects/module-federation": "^14.3.14",
1010
"@angular/platform-browser": ">=14.0.0",
1111
"rxjs": ">= 6.0.0"
1212
},

libs/mf/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@angular-architects/module-federation",
3-
"version": "14.3.12",
3+
"version": "14.3.14",
44
"license": "MIT",
55
"repository": {
66
"type": "GitHub",
@@ -17,7 +17,7 @@
1717
"schematics": "./collection.json",
1818
"builders": "./builders.json",
1919
"dependencies": {
20-
"@angular-architects/module-federation-runtime": "14.3.12",
20+
"@angular-architects/module-federation-runtime": "14.3.14",
2121
"word-wrap": "^1.2.3",
2222
"callsite": "^1.0.0",
2323
"node-fetch": "^2.6.7",

libs/mf/src/schematics/mf/schematic.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
getPackageJsonDependency,
2727
NodeDependencyType,
2828
} from '@schematics/angular/utility/dependencies';
29+
import { serve } from 'esbuild';
2930

3031
export function add(options: MfSchematicSchema): Rule {
3132
return config(options);
@@ -157,6 +158,39 @@ function nxBuildersAvailable(tree: Tree): boolean {
157158
return semver.satisfies(minVersion, '>=12.9.0');
158159
}
159160

161+
function infereNxBuilderNames(
162+
tree: Tree
163+
): { dev: string; prod: string } {
164+
165+
const defaultResult = {
166+
dev: '@nrwl/angular:webpack-dev-server',
167+
prod: '@nrwl/angular:webpack-browser',
168+
};
169+
170+
const fallbackResult = {
171+
dev: '@nrwl/angular:webpack-server',
172+
prod: '@nrwl/angular:webpack-browser',
173+
};
174+
175+
if (!tree.exists('nx.json')) return defaultResult;
176+
177+
const packageJson = JSON.parse(tree.read('package.json').toString('utf-8'));
178+
179+
const version =
180+
packageJson?.devDependencies?.['@nrwl/angular'] ??
181+
packageJson?.dependencies?.['@nrwl/angular'];
182+
183+
if (!version) defaultResult;
184+
185+
const minVersion = semver.minVersion(version).raw;
186+
187+
if (semver.satisfies(minVersion, '>=15.0.0')) {
188+
return defaultResult;
189+
} else {
190+
return fallbackResult;
191+
}
192+
}
193+
160194
async function generateWebpackConfig(
161195
remoteMap: Record<string, string>,
162196
projectRoot: string,
@@ -272,6 +306,8 @@ export default function config(options: MfSchematicSchema): Rule {
272306
options.nxBuilders = nxBuildersAvailable(tree); // tree.exists('nx.json');
273307
}
274308

309+
const nxBuilderNames = infereNxBuilderNames(tree);
310+
275311
if (options.nxBuilders) {
276312
console.log('Using Nx builders!');
277313
}
@@ -280,10 +316,10 @@ export default function config(options: MfSchematicSchema): Rule {
280316
? 'customWebpackConfig'
281317
: 'extraWebpackConfig';
282318
const buildBuilder = options.nxBuilders
283-
? '@nrwl/angular:webpack-browser'
319+
? nxBuilderNames.prod
284320
: 'ngx-build-plus:browser';
285321
const serveBuilder = options.nxBuilders
286-
? '@nrwl/angular:webpack-server'
322+
? nxBuilderNames.dev
287323
: 'ngx-build-plus:dev-server';
288324

289325
if (!projectConfig?.architect?.build || !projectConfig?.architect?.serve) {

0 commit comments

Comments
 (0)