@nx/angular 18.2.2 → 18.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/src/executors/module-federation-dev-server/lib/start-dev-remotes.d.ts +1 -5
- package/src/executors/module-federation-dev-server/lib/start-dev-remotes.js +14 -14
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +3 -2
- package/src/generators/application/lib/add-e2e.js +5 -5
- package/src/generators/application/lib/normalize-options.js +14 -0
- package/src/generators/application/lib/normalized-schema.d.ts +3 -0
- package/src/generators/setup-mf/files/ts-webpack/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/setup-mf/files/webpack/module-federation.config.js__tmpl__ +1 -1
- package/src/generators/setup-mf/lib/add-remote-to-host.d.ts +7 -2
- package/src/generators/setup-mf/lib/add-remote-to-host.js +2 -15
- package/src/generators/setup-mf/lib/generate-config.js +1 -0
- package/src/generators/setup-mf/lib/update-host-app-routes.js +1 -4
- package/src/generators/setup-mf/setup-mf.js +14 -1
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/angular",
|
3
|
-
"version": "18.2.
|
3
|
+
"version": "18.2.4",
|
4
4
|
"private": false,
|
5
5
|
"description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -78,14 +78,14 @@
|
|
78
78
|
"tslib": "^2.3.0",
|
79
79
|
"webpack": "^5.80.0",
|
80
80
|
"webpack-merge": "^5.8.0",
|
81
|
-
"@nx/devkit": "18.2.
|
82
|
-
"@nx/js": "18.2.
|
83
|
-
"@nx/eslint": "18.2.
|
84
|
-
"@nx/webpack": "18.2.
|
85
|
-
"@nx/web": "18.2.
|
86
|
-
"@nx/workspace": "18.2.
|
81
|
+
"@nx/devkit": "18.2.4",
|
82
|
+
"@nx/js": "18.2.4",
|
83
|
+
"@nx/eslint": "18.2.4",
|
84
|
+
"@nx/webpack": "18.2.4",
|
85
|
+
"@nx/web": "18.2.4",
|
86
|
+
"@nx/workspace": "18.2.4",
|
87
87
|
"piscina": "^4.4.0",
|
88
|
-
"@nrwl/angular": "18.2.
|
88
|
+
"@nrwl/angular": "18.2.4"
|
89
89
|
},
|
90
90
|
"peerDependencies": {
|
91
91
|
"@angular-devkit/build-angular": ">= 15.0.0 < 18.0.0",
|
@@ -1,9 +1,5 @@
|
|
1
1
|
import { type Schema } from '../schema';
|
2
2
|
import { type ExecutorContext, type ProjectConfiguration } from '@nx/devkit';
|
3
|
-
export declare function
|
4
|
-
remotePorts: any[];
|
5
|
-
staticRemotes: string[];
|
6
|
-
devRemotes: string[];
|
7
|
-
}, workspaceProjects: Record<string, ProjectConfiguration>, options: Schema, context: ExecutorContext): Promise<AsyncIterable<{
|
3
|
+
export declare function startRemotes(remotes: string[], workspaceProjects: Record<string, ProjectConfiguration>, options: Schema, context: ExecutorContext, target?: 'serve' | 'serve-static'): Promise<AsyncIterable<{
|
8
4
|
success: boolean;
|
9
5
|
}>[]>;
|
@@ -1,29 +1,29 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
3
|
+
exports.startRemotes = void 0;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
-
async function
|
6
|
-
const
|
7
|
-
for (const app of remotes
|
8
|
-
if (!workspaceProjects[app].targets?.[
|
9
|
-
throw new Error(`Could not find "
|
5
|
+
async function startRemotes(remotes, workspaceProjects, options, context, target = 'serve') {
|
6
|
+
const remoteIters = [];
|
7
|
+
for (const app of remotes) {
|
8
|
+
if (!workspaceProjects[app].targets?.[target]) {
|
9
|
+
throw new Error(`Could not find "${target}" target in "${app}" project.`);
|
10
10
|
}
|
11
|
-
else if (!workspaceProjects[app].targets?.[
|
12
|
-
throw new Error(`Could not find executor for "
|
11
|
+
else if (!workspaceProjects[app].targets?.[target].executor) {
|
12
|
+
throw new Error(`Could not find executor for "${target}" target in "${app}" project.`);
|
13
13
|
}
|
14
|
-
const [collection, executor] = workspaceProjects[app].targets[
|
14
|
+
const [collection, executor] = workspaceProjects[app].targets[target].executor.split(':');
|
15
15
|
const isUsingModuleFederationDevServerExecutor = executor.includes('module-federation-dev-server');
|
16
|
-
|
16
|
+
remoteIters.push(await (0, devkit_1.runExecutor)({
|
17
17
|
project: app,
|
18
|
-
target
|
18
|
+
target,
|
19
19
|
configuration: context.configurationName,
|
20
20
|
}, {
|
21
|
-
verbose: options.verbose ?? false,
|
21
|
+
...(target === 'serve' ? { verbose: options.verbose ?? false } : {}),
|
22
22
|
...(isUsingModuleFederationDevServerExecutor
|
23
23
|
? { isInitialHost: false }
|
24
24
|
: {}),
|
25
25
|
}, context));
|
26
26
|
}
|
27
|
-
return
|
27
|
+
return remoteIters;
|
28
28
|
}
|
29
|
-
exports.
|
29
|
+
exports.startRemotes = startRemotes;
|
@@ -70,7 +70,8 @@ async function* moduleFederationDevServerExecutor(schema, context) {
|
|
70
70
|
}
|
71
71
|
const staticRemotesConfig = (0, lib_1.parseStaticRemotesConfig)(remotes.staticRemotes, context);
|
72
72
|
await (0, lib_1.buildStaticRemotes)(staticRemotesConfig, nxBin, context, options);
|
73
|
-
const devRemoteIters = await (0, lib_1.
|
73
|
+
const devRemoteIters = await (0, lib_1.startRemotes)(remotes.devRemotes, workspaceProjects, options, context, 'serve');
|
74
|
+
const dynamicRemoteIters = await (0, lib_1.startRemotes)(remotes.dynamicRemotes, workspaceProjects, options, context, 'serve-static');
|
74
75
|
const staticRemotesIter = remotes.staticRemotes.length > 0
|
75
76
|
? (0, lib_1.startStaticRemotesFileServer)(staticRemotesConfig, context, options)
|
76
77
|
: undefined;
|
@@ -78,7 +79,7 @@ async function* moduleFederationDevServerExecutor(schema, context) {
|
|
78
79
|
...v,
|
79
80
|
baseUrl: undefined,
|
80
81
|
}));
|
81
|
-
return yield* (0, async_iterable_1.combineAsyncIterables)(removeBaseUrlEmission(currIter), ...devRemoteIters.map(removeBaseUrlEmission), ...(staticRemotesIter ? [removeBaseUrlEmission(staticRemotesIter)] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
82
|
+
return yield* (0, async_iterable_1.combineAsyncIterables)(removeBaseUrlEmission(currIter), ...devRemoteIters.map(removeBaseUrlEmission), ...dynamicRemoteIters.map(removeBaseUrlEmission), ...(staticRemotesIter ? [removeBaseUrlEmission(staticRemotesIter)] : []), (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
82
83
|
if (!options.isInitialHost) {
|
83
84
|
done();
|
84
85
|
return;
|
@@ -27,8 +27,8 @@ async function addE2e(tree, options) {
|
|
27
27
|
linter: options.linter,
|
28
28
|
skipPackageJson: options.skipPackageJson,
|
29
29
|
skipFormat: true,
|
30
|
-
devServerTarget: `${options.name}:
|
31
|
-
baseUrl:
|
30
|
+
devServerTarget: `${options.name}:${options.e2eWebServerTarget}:development`,
|
31
|
+
baseUrl: options.e2eWebServerAddress,
|
32
32
|
rootProject: options.rootProject,
|
33
33
|
addPlugin,
|
34
34
|
});
|
@@ -50,8 +50,8 @@ async function addE2e(tree, options) {
|
|
50
50
|
js: false,
|
51
51
|
linter: options.linter,
|
52
52
|
setParserOptionsProject: options.setParserOptionsProject,
|
53
|
-
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx
|
54
|
-
webServerAddress:
|
53
|
+
webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.name}`,
|
54
|
+
webServerAddress: options.e2eWebServerAddress,
|
55
55
|
rootProject: options.rootProject,
|
56
56
|
addPlugin,
|
57
57
|
});
|
@@ -67,7 +67,7 @@ function addFileServerTarget(tree, options, targetName) {
|
|
67
67
|
executor: '@nx/web:file-server',
|
68
68
|
options: {
|
69
69
|
buildTarget: `${options.name}:build`,
|
70
|
-
port: options.
|
70
|
+
port: options.e2ePort,
|
71
71
|
staticFilePath: isUsingApplicationBuilder
|
72
72
|
? (0, devkit_1.joinPathFragments)(options.outputPath, 'browser')
|
73
73
|
: undefined,
|
@@ -17,8 +17,19 @@ async function normalizeOptions(host, options) {
|
|
17
17
|
});
|
18
18
|
options.rootProject = appProjectRoot === '.';
|
19
19
|
options.projectNameAndRootFormat = projectNameAndRootFormat;
|
20
|
+
const nxJson = (0, devkit_1.readNxJson)(host);
|
21
|
+
let e2eWebServerTarget = 'serve';
|
22
|
+
let e2ePort = options.port ?? 4200;
|
23
|
+
if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
|
24
|
+
(nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
|
25
|
+
nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT)) {
|
26
|
+
e2ePort =
|
27
|
+
nxJson.targetDefaults?.[e2eWebServerTarget].options?.port ||
|
28
|
+
nxJson.targetDefaults?.[e2eWebServerTarget].options?.env?.PORT;
|
29
|
+
}
|
20
30
|
const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
|
21
31
|
const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
|
32
|
+
const e2eWebServerAddress = `http://localhost:${e2ePort}`;
|
22
33
|
const parsedTags = options.tags
|
23
34
|
? options.tags.split(',').map((s) => s.trim())
|
24
35
|
: [];
|
@@ -47,6 +58,9 @@ async function normalizeOptions(host, options) {
|
|
47
58
|
appProjectSourceRoot: `${appProjectRoot}/src`,
|
48
59
|
e2eProjectRoot,
|
49
60
|
e2eProjectName,
|
61
|
+
e2eWebServerAddress,
|
62
|
+
e2eWebServerTarget,
|
63
|
+
e2ePort,
|
50
64
|
parsedTags,
|
51
65
|
bundler,
|
52
66
|
outputPath: (0, devkit_1.joinPathFragments)('dist', !options.rootProject ? appProjectRoot : appProjectName),
|
@@ -10,6 +10,9 @@ export interface NormalizedSchema extends Schema {
|
|
10
10
|
appProjectSourceRoot: string;
|
11
11
|
e2eProjectName: string;
|
12
12
|
e2eProjectRoot: string;
|
13
|
+
e2eWebServerAddress: string;
|
14
|
+
e2eWebServerTarget: string;
|
15
|
+
e2ePort: number;
|
13
16
|
parsedTags: string[];
|
14
17
|
outputPath: string;
|
15
18
|
}
|
@@ -14,7 +14,7 @@ const config: ModuleFederationConfig = {
|
|
14
14
|
* declare module 'my-external-remote';
|
15
15
|
*
|
16
16
|
*/
|
17
|
-
remotes: [<% remotes.forEach(function(remote) { %>'<%= remote.remoteName %>',<% }); %>]<% } %><% if(type === 'remote') { %>
|
17
|
+
remotes: [<% if (federationType === 'static') { remotes.forEach(function(remote) { %>'<%= remote.remoteName %>',<% }); } %>]<% } %><% if(type === 'remote') { %>
|
18
18
|
exposes: {<% if(standalone) { %>
|
19
19
|
'./Routes': '<%= projectRoot %>/src/app/remote-entry/entry.routes.ts',<% } else { %>
|
20
20
|
'./Module': '<%= projectRoot %>/src/app/remote-entry/entry.module.ts',<% } %>
|
@@ -12,7 +12,7 @@ module.exports = {
|
|
12
12
|
* declare module 'my-external-remote';
|
13
13
|
*
|
14
14
|
*/
|
15
|
-
remotes: [<% remotes.forEach(function(remote) { %>'<%= remote.remoteName %>',<% }); %>]<% } %><% if(type === 'remote') { %>
|
15
|
+
remotes: [<% if (federationType === 'static') { remotes.forEach(function(remote) { %>'<%= remote.remoteName %>',<% }); } %>]<% } %><% if(type === 'remote') { %>
|
16
16
|
exposes: {<% if(standalone) { %>
|
17
17
|
'./Routes': '<%= projectRoot %>/src/app/remote-entry/entry.routes.ts',<% } else { %>
|
18
18
|
'./Module': '<%= projectRoot %>/src/app/remote-entry/entry.module.ts',<% } %>
|
@@ -1,4 +1,9 @@
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
2
|
-
|
2
|
+
export type AddRemoteOptions = {
|
3
|
+
host: string;
|
4
|
+
appName: string;
|
5
|
+
standalone: boolean;
|
6
|
+
port: number;
|
7
|
+
};
|
3
8
|
export declare function checkIsCommaNeeded(mfRemoteText: string): boolean;
|
4
|
-
export declare function addRemoteToHost(tree: Tree, options:
|
9
|
+
export declare function addRemoteToHost(tree: Tree, options: AddRemoteOptions): void;
|
@@ -27,19 +27,6 @@ function addRemoteToHost(tree, options) {
|
|
27
27
|
else if (hostFederationType === 'dynamic') {
|
28
28
|
addRemoteToDynamicHost(tree, options, pathToMFManifest);
|
29
29
|
}
|
30
|
-
// const declarationFilePath = joinPathFragments(
|
31
|
-
// hostProject.sourceRoot,
|
32
|
-
// 'remotes.d.ts'
|
33
|
-
// );
|
34
|
-
//
|
35
|
-
// const declarationFileContent =
|
36
|
-
// (tree.exists(declarationFilePath)
|
37
|
-
// ? tree.read(declarationFilePath, 'utf-8')
|
38
|
-
// : '') +
|
39
|
-
// `\ndeclare module '${options.appName}/${
|
40
|
-
// options.standalone ? `Routes` : `Module`
|
41
|
-
// }';`;
|
42
|
-
// tree.write(declarationFilePath, declarationFileContent);
|
43
30
|
addLazyLoadedRouteToHostAppModule(tree, options, hostFederationType);
|
44
31
|
}
|
45
32
|
}
|
@@ -47,8 +34,8 @@ exports.addRemoteToHost = addRemoteToHost;
|
|
47
34
|
function determineHostFederationType(tree, pathToMfManifest) {
|
48
35
|
return tree.exists(pathToMfManifest) ? 'dynamic' : 'static';
|
49
36
|
}
|
50
|
-
function addRemoteToStaticHost(tree, options, hostProject,
|
51
|
-
const hostMFConfigPath = (0, devkit_1.joinPathFragments)(hostProject.root,
|
37
|
+
function addRemoteToStaticHost(tree, options, hostProject, isHostUsingTypescript) {
|
38
|
+
const hostMFConfigPath = (0, devkit_1.joinPathFragments)(hostProject.root, isHostUsingTypescript
|
52
39
|
? 'module-federation.config.ts'
|
53
40
|
: 'module-federation.config.js');
|
54
41
|
if (!hostMFConfigPath || !tree.exists(hostMFConfigPath)) {
|
@@ -18,6 +18,7 @@ function generateWebpackConfig(tree, options, appRoot, remotesWithPorts) {
|
|
18
18
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToWebpackTemplateFiles}`), appRoot, {
|
19
19
|
tmpl: '',
|
20
20
|
type: options.mfType,
|
21
|
+
federationType: options.federationType,
|
21
22
|
name: options.appName,
|
22
23
|
remotes: remotesWithPorts ?? [],
|
23
24
|
projectRoot: appRoot,
|
@@ -11,11 +11,8 @@ function updateHostAppRoutes(tree, options) {
|
|
11
11
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
12
12
|
}
|
13
13
|
const { sourceRoot } = (0, project_configuration_1.readProjectConfiguration)(tree, options.appName);
|
14
|
-
const remoteRoutes = options.remotes && Array.isArray(options.remotes)
|
15
|
-
? options.remotes.reduce((routes, remote) => `${routes}\n<li><a routerLink='${remote}'>${(0, devkit_1.names)(remote).className}</a></li>`, '')
|
16
|
-
: '';
|
17
14
|
tree.write((0, devkit_1.joinPathFragments)(sourceRoot, 'app/app.component.html'), `<ul class="remote-menu">
|
18
|
-
<li><a routerLink="/">Home</a></li
|
15
|
+
<li><a routerLink="/">Home</a></li>
|
19
16
|
</ul>
|
20
17
|
<router-outlet></router-outlet>
|
21
18
|
`);
|
@@ -9,7 +9,12 @@ async function setupMf(tree, rawOptions) {
|
|
9
9
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.appName);
|
10
10
|
let installTask = () => { };
|
11
11
|
if (options.mfType === 'remote') {
|
12
|
-
(0, lib_1.addRemoteToHost)(tree,
|
12
|
+
(0, lib_1.addRemoteToHost)(tree, {
|
13
|
+
appName: options.appName,
|
14
|
+
host: options.host,
|
15
|
+
standalone: options.standalone,
|
16
|
+
port: options.port,
|
17
|
+
});
|
13
18
|
(0, lib_1.addRemoteEntry)(tree, options, projectConfig.root);
|
14
19
|
(0, lib_1.removeDeadCodeFromRemote)(tree, options);
|
15
20
|
(0, lib_1.setupTspathForRemote)(tree, options);
|
@@ -24,6 +29,14 @@ async function setupMf(tree, rawOptions) {
|
|
24
29
|
if (options.mfType === 'host') {
|
25
30
|
(0, lib_1.setupHostIfDynamic)(tree, options);
|
26
31
|
(0, lib_1.updateHostAppRoutes)(tree, options);
|
32
|
+
for (const { remoteName, port } of remotesWithPorts) {
|
33
|
+
(0, lib_1.addRemoteToHost)(tree, {
|
34
|
+
appName: remoteName,
|
35
|
+
host: options.appName,
|
36
|
+
standalone: options.standalone,
|
37
|
+
port,
|
38
|
+
});
|
39
|
+
}
|
27
40
|
installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, { '@nx/webpack': versions_1.nxVersion });
|
28
41
|
}
|
29
42
|
if (!options.skipE2E) {
|