Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/angular/src/builders/build/builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import './setup-builder-env-variables.js';

import {
DEFAULT_NF_CONFIG_FILE_NAME,
LEGACY_NF_CONFIG_FILE_NAME,
} from '../../config/constants.js';

import * as fs from 'fs';
import * as mrmime from 'mrmime';
import * as path from 'path';
Expand Down Expand Up @@ -236,7 +241,7 @@ export async function* runBuilder(
projectName: nfBuilderOptions.projectName,
workspaceRoot: context.workspaceRoot,
outputPath: browserOutputPath,
federationConfig: inferConfigPath(federationTsConfig, context.workspaceRoot),
federationConfig: inferConfigPath(federationTsConfig, context.workspaceRoot, nfBuilderOptions.federationConfigPath),
tsConfig: federationTsConfig,
verbose: ngBuilderOptions.verbose,
watch: ngBuilderOptions.watch,
Expand Down Expand Up @@ -575,15 +580,20 @@ function getLocaleFilter(options: ApplicationBuilderOptions, runViteServer: bool
return localize;
}

function inferConfigPath(tsConfig: string, workspaceRoot: string): string {
function inferConfigPath(
tsConfig: string,
workspaceRoot: string,
federationConfigPath = DEFAULT_NF_CONFIG_FILE_NAME
): string {
const relProjectPath = path.dirname(tsConfig);
const mjsRelPath = path.join(relProjectPath, 'federation.config.mjs');

const mjsRelPath = path.join(relProjectPath, federationConfigPath);

if (fs.existsSync(path.resolve(workspaceRoot, mjsRelPath))) {
return mjsRelPath;
}

return path.join(relProjectPath, 'federation.config.js');
return path.join(relProjectPath, LEGACY_NF_CONFIG_FILE_NAME);
}

function transformIndexHtml(nfOptions: NfBuilderSchema): (content: string) => Promise<string> {
Expand Down
1 change: 1 addition & 0 deletions packages/angular/src/builders/build/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface NfBuilderSchema extends JsonObject {
port: number;
rebuildDelay: number;
buildNotifications?: BuildNotificationOptions;
federationConfigPath?: string;
watch?: boolean;
skipHtmlTransform: boolean;
esmsInitOptions: ESMSInitOptions;
Expand Down
5 changes: 5 additions & 0 deletions packages/angular/src/builders/build/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
"description": "You can override the default endpoint to send build completion events to."
}
}
},
"federationConfigPath": {
"type": "string",
"description": "The path to the federation config file. If not provided, the default path will be used.",
"default": "federation.config.mjs"
}
}
}
2 changes: 2 additions & 0 deletions packages/angular/src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const DEFAULT_NF_CONFIG_FILE_NAME = 'federation.config.mjs';
export const LEGACY_NF_CONFIG_FILE_NAME = 'federation.config.js';
3 changes: 2 additions & 1 deletion packages/angular/src/schematics/init/schematic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { chain, noop, type Rule, url } from '@angular-devkit/schematics';
import { DEFAULT_NF_CONFIG_FILE_NAME } from '../../config/constants.js';
import type { NfSchematicSchema } from './schema.js';
import * as path from 'path';

Expand Down Expand Up @@ -46,7 +47,7 @@ export default function config(options: NfSchematicSchema): Rule {
tree.create(manifestPath, JSON.stringify(remoteMap, null, '\t'));
}

const federationConfigPath = path.join(projectRoot, 'federation.config.mjs');
const federationConfigPath = path.join(projectRoot, DEFAULT_NF_CONFIG_FILE_NAME);

const exists = tree.exists(federationConfigPath);

Expand Down
8 changes: 6 additions & 2 deletions packages/angular/src/schematics/update22/schematic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { Rule, Tree } from '@angular-devkit/schematics';

import {
DEFAULT_NF_CONFIG_FILE_NAME,
LEGACY_NF_CONFIG_FILE_NAME,
} from '../../config/constants.js';
import { getWorkspaceFileName } from '../init/schematic.js';

import * as path from 'path';
Expand Down Expand Up @@ -60,8 +64,8 @@ function normalizeBuilderReferences(tree: Tree, workspace: any, workspaceFileNam
// only get their package references normalized.
function migrateFederationConfigs(tree: Tree, workspace: any): void {
for (const { projectRoot } of resolveProjects(workspace)) {
const jsConfigPath = path.join(projectRoot, 'federation.config.js');
const mjsConfigPath = path.join(projectRoot, 'federation.config.mjs');
const jsConfigPath = path.join(projectRoot, LEGACY_NF_CONFIG_FILE_NAME);
const mjsConfigPath = path.join(projectRoot, DEFAULT_NF_CONFIG_FILE_NAME);

if (!tree.exists(jsConfigPath) && tree.exists(mjsConfigPath)) {
const content = tree.readText(mjsConfigPath);
Expand Down
Loading