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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"@angular/build": "~22.1.0",
"@eslint/js": "^10.0.1",
"@nx/devkit": "^23.1.0",
"@schematics/angular": "~22.1.0",
"@types/node": "~24.10.0",
"@vitest/coverage-v8": "^4.0.0",
"eslint": "^10.8.0",
Expand Down
16 changes: 0 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 39 additions & 34 deletions src/schematics/init/steps/add-dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,45 @@
import type { SchematicContext, Tree } from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks/index.js';
import {
addPackageJsonDependency,
NodeDependencyType,
} from '@schematics/angular/utility/dependencies';

export function addDependencies(tree: Tree, context: SchematicContext, ssr: boolean): void {
addPackageJsonDependency(tree, {
name: 'es-module-shims',
type: NodeDependencyType.Default,
version: '^2.8.0',
overwrite: false,
});

// Browser-only projects bundle the orchestrator into the app, so a dev
// dependency suffices. For SSR it must be a runtime dependency: the generated
// server entry imports '@softarc/native-federation-orchestrator/node' as a
// bare specifier resolved from node_modules at runtime.
addPackageJsonDependency(tree, {
name: '@softarc/native-federation-orchestrator',
type: ssr ? NodeDependencyType.Default : NodeDependencyType.Dev,
version: '^4.2.2',
overwrite: true,
});
import type { SchematicContext, Tree } from "@angular-devkit/schematics";
import { NodePackageInstallTask } from "@angular-devkit/schematics/tasks/index.js";

type DependencyType = "dependencies" | "devDependencies";
type PackageJson = Partial<Record<DependencyType, Record<string, string>>>;

export function addDependencies(
tree: Tree,
context: SchematicContext,
ssr: boolean,
): void {
const packageJson = (tree.readJson("package.json") as PackageJson) ?? {};

function addDependency(
type: DependencyType,
name: string,
version: string,
overwrite = false,
): void {
const deps = (packageJson[type] ??= {});
if (overwrite || !deps[name]) {
deps[name] = version;
}
}

addDependency("dependencies", "es-module-shims", "^2.8.0");

addDependency(
"devDependencies",
"@softarc/native-federation-orchestrator",
"^4.6.0",
true,
);

if (ssr) {
console.log('SSR detected ...');
console.log('Activating CORS ...');

addPackageJsonDependency(tree, {
name: 'cors',
type: NodeDependencyType.Default,
version: '^2.8.5',
overwrite: false,
});
console.log("SSR detected ...");

Check warning on line 36 in src/schematics/init/steps/add-dependencies.ts

View workflow job for this annotation

GitHub Actions / verify

Unexpected console statement. Only these console methods are allowed: warn, error
console.log("Activating CORS ...");

Check warning on line 37 in src/schematics/init/steps/add-dependencies.ts

View workflow job for this annotation

GitHub Actions / verify

Unexpected console statement. Only these console methods are allowed: warn, error

addDependency("dependencies", "cors", "^2.8.5");
}

tree.overwrite("package.json", JSON.stringify(packageJson, null, 2));

context.addTask(new NodePackageInstallTask());
}
24 changes: 13 additions & 11 deletions src/schematics/init/steps/make-main-async.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Rule } from '@angular-devkit/schematics';
import type { NfSchematicSchema } from '../schema.js';
import * as path from 'path';
import type { Rule } from "@angular-devkit/schematics";
import type { NfSchematicSchema } from "../schema.js";
import * as path from "path";

// The adapter's `initFederation` wrapper hides shimMode/logger/storage, so
// generated apps don't ship internal orchestrator options or `logLevel: 'debug'`.
Expand All @@ -9,30 +9,30 @@
function getFederationArg(
options: NfSchematicSchema,
remoteMap: unknown,
manifestRelPath: string
manifestRelPath: string,
): string {
switch (options.type) {
case 'dynamic-host':
case "dynamic-host":
return `'${manifestRelPath}'`;
case 'host':
case "host":
return JSON.stringify(remoteMap, null, 2).replace(/"/g, "'");
default:
return `{ '${options.project}': './remoteEntry.json' }`;
return `{}`;
}
}

export function makeMainAsync(
main: string,
options: NfSchematicSchema,
remoteMap: unknown,
manifestRelPath: string
manifestRelPath: string,
): Rule {
return async function (tree) {
const mainPath = path.dirname(main);
const bootstrapName = path.join(mainPath, 'bootstrap.ts');
const bootstrapName = path.join(mainPath, "bootstrap.ts");

if (tree.exists(bootstrapName)) {
console.info(`${bootstrapName} already exists.`);

Check warning on line 35 in src/schematics/init/steps/make-main-async.ts

View workflow job for this annotation

GitHub Actions / verify

Unexpected console statement. Only these console methods are allowed: warn, error
return;
}

Expand All @@ -45,11 +45,13 @@
main,
`${FEDERATION_IMPORT}

initFederation(${federationArg})
initFederation(${federationArg}, {
hostRemoteEntry: { url: "./remoteEntry.json" }
})
.catch(err => console.error(err))
.then(_ => import('./bootstrap'))
.catch(err => console.error(err));
`
`,
);
};
}
Loading