@nx/rspack 20.2.0-beta.1 → 20.2.0-beta.3
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/app-plugin.d.ts +2 -0
- package/app-plugin.js +5 -0
- package/generators.json +10 -0
- package/migrations.json +21 -1
- package/module-federation.d.ts +4 -1
- package/module-federation.js +7 -2
- package/package.json +10 -8
- package/react-plugin.d.ts +1 -0
- package/react-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +5 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -7
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +4 -5
- package/src/executors/rspack/lib/config.d.ts +6 -0
- package/src/executors/rspack/lib/config.js +39 -0
- package/src/executors/rspack/rspack.impl.js +11 -12
- package/src/executors/rspack/schema.d.ts +39 -18
- package/src/executors/rspack/schema.json +191 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.d.ts +7 -0
- package/src/generators/convert-config-to-rspack-plugin/convert-config-to-rspack-plugin.js +92 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.d.ts +6 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/extract-rspack-options.js +106 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.d.ts +2 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/normalize-path-options.js +73 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.d.ts +1 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/utils.js +13 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.d.ts +9 -0
- package/src/generators/convert-config-to-rspack-plugin/lib/validate-project.js +40 -0
- package/src/generators/convert-config-to-rspack-plugin/schema.json +19 -0
- package/src/generators/convert-to-inferred/__snapshots__/convert-to-inferred.spec.ts.snap +268 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.d.ts +12 -0
- package/src/generators/convert-to-inferred/convert-to-inferred.js +114 -0
- package/src/generators/convert-to-inferred/schema.json +19 -0
- package/src/generators/convert-to-inferred/utils/ast.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/ast.js +40 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/build-post-target-transformer.js +210 -0
- package/src/generators/convert-to-inferred/utils/index.d.ts +3 -0
- package/src/generators/convert-to-inferred/utils/index.js +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.d.ts +6 -0
- package/src/generators/convert-to-inferred/utils/serve-post-target-transformer.js +207 -0
- package/src/generators/convert-to-inferred/utils/types.d.ts +11 -0
- package/src/generators/convert-webpack/lib/transform-cjs.js +5 -5
- package/src/generators/convert-webpack/lib/transform-esm.js +5 -5
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.d.ts +16 -0
- package/src/plugins/nx-app-rspack-plugin/nx-app-rspack-plugin.js +43 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.d.ts +8 -0
- package/src/plugins/nx-react-rspack-plugin/nx-react-rspack-plugin.js +13 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.d.ts +31 -0
- package/src/plugins/use-legacy-nx-plugin/use-legacy-nx-plugin.js +73 -0
- package/src/plugins/utils/apply-base-config.js +2 -5
- package/src/plugins/utils/apply-web-config.d.ts +2 -2
- package/src/plugins/utils/apply-web-config.js +1 -8
- package/src/plugins/utils/models.d.ts +2 -2
- package/src/plugins/utils/plugins/normalize-options.js +1 -1
- package/src/plugins/utils/plugins/nx-tsconfig-paths-rspack-plugin.js +3 -2
- package/src/utils/create-compiler.d.ts +2 -2
- package/src/utils/create-compiler.js +12 -49
- package/src/utils/generator-utils.d.ts +2 -2
- package/src/utils/generator-utils.js +134 -67
- package/src/utils/has-plugin.d.ts +2 -0
- package/src/utils/has-plugin.js +10 -0
- package/src/utils/module-federation/build-static.remotes.d.ts +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- package/src/utils/module-federation/dependencies.d.ts +0 -6
- package/src/utils/module-federation/dependencies.js +0 -56
- package/src/utils/module-federation/get-remotes-for-host.d.ts +0 -16
- package/src/utils/module-federation/get-remotes-for-host.js +0 -99
- package/src/utils/module-federation/index.d.ts +0 -6
- package/src/utils/module-federation/index.js +0 -9
- package/src/utils/module-federation/models/index.d.ts +0 -47
- package/src/utils/module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/package-json.js +0 -12
- package/src/utils/module-federation/parse-static-remotes-config.d.ts +0 -13
- package/src/utils/module-federation/parse-static-remotes-config.js +0 -34
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.d.ts +0 -3
- package/src/utils/module-federation/plugins/runtime-library-control.plugin.js +0 -54
- package/src/utils/module-federation/public-api.d.ts +0 -8
- package/src/utils/module-federation/public-api.js +0 -20
- package/src/utils/module-federation/remotes.d.ts +0 -19
- package/src/utils/module-federation/remotes.js +0 -85
- package/src/utils/module-federation/secondary-entry-points.d.ts +0 -12
- package/src/utils/module-federation/secondary-entry-points.js +0 -104
- package/src/utils/module-federation/share.d.ts +0 -48
- package/src/utils/module-federation/share.js +0 -235
- package/src/utils/module-federation/start-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-remote-proxies.js +0 -45
- package/src/utils/module-federation/start-ssr-remote-proxies.d.ts +0 -5
- package/src/utils/module-federation/start-ssr-remote-proxies.js +0 -59
- package/src/utils/module-federation/typescript.d.ts +0 -4
- package/src/utils/module-federation/typescript.js +0 -53
- package/src/utils/module-federation/with-module-federation/package-json.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/package-json.js +0 -12
- package/src/utils/module-federation/with-module-federation/utils.d.ts +0 -12
- package/src/utils/module-federation/with-module-federation/utils.js +0 -76
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.d.ts +0 -3
- package/src/utils/module-federation/with-module-federation/with-module-federation-ssr.js +0 -55
- package/src/utils/module-federation/with-module-federation/with-module-federation.d.ts +0 -8
- package/src/utils/module-federation/with-module-federation/with-module-federation.js +0 -70
- /package/src/{utils/module-federation/models/index.js → generators/convert-to-inferred/utils/types.js} +0 -0
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AdditionalSharedConfig, ModuleFederationConfig, ModuleFederationLibrary, Remotes, SharedFunction, SharedLibraryConfig, SharedWorkspaceLibraryConfig, WorkspaceLibrary, WorkspaceLibrarySecondaryEntryPoint } from './models';
|
|
2
|
-
import { applyAdditionalShared, applySharedFunction, getNpmPackageSharedConfig, sharePackages, shareWorkspaceLibraries } from './share';
|
|
3
|
-
import { mapRemotes, mapRemotesForSSR } from './remotes';
|
|
4
|
-
import { getDependentPackagesForProject } from './dependencies';
|
|
5
|
-
import { readRootPackageJson } from './package-json';
|
|
6
|
-
import { withModuleFederation } from './with-module-federation/with-module-federation';
|
|
7
|
-
import { withModuleFederationForSSR } from './with-module-federation/with-module-federation-ssr';
|
|
8
|
-
export { AdditionalSharedConfig, applyAdditionalShared, applySharedFunction, getDependentPackagesForProject, getNpmPackageSharedConfig, mapRemotes, mapRemotesForSSR, ModuleFederationConfig, ModuleFederationLibrary, readRootPackageJson, Remotes, SharedFunction, SharedLibraryConfig, SharedWorkspaceLibraryConfig, sharePackages, shareWorkspaceLibraries, withModuleFederation, withModuleFederationForSSR, WorkspaceLibrary, WorkspaceLibrarySecondaryEntryPoint, };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.withModuleFederationForSSR = exports.withModuleFederation = exports.shareWorkspaceLibraries = exports.sharePackages = exports.readRootPackageJson = exports.mapRemotesForSSR = exports.mapRemotes = exports.getNpmPackageSharedConfig = exports.getDependentPackagesForProject = exports.applySharedFunction = exports.applyAdditionalShared = void 0;
|
|
4
|
-
const share_1 = require("./share");
|
|
5
|
-
Object.defineProperty(exports, "applyAdditionalShared", { enumerable: true, get: function () { return share_1.applyAdditionalShared; } });
|
|
6
|
-
Object.defineProperty(exports, "applySharedFunction", { enumerable: true, get: function () { return share_1.applySharedFunction; } });
|
|
7
|
-
Object.defineProperty(exports, "getNpmPackageSharedConfig", { enumerable: true, get: function () { return share_1.getNpmPackageSharedConfig; } });
|
|
8
|
-
Object.defineProperty(exports, "sharePackages", { enumerable: true, get: function () { return share_1.sharePackages; } });
|
|
9
|
-
Object.defineProperty(exports, "shareWorkspaceLibraries", { enumerable: true, get: function () { return share_1.shareWorkspaceLibraries; } });
|
|
10
|
-
const remotes_1 = require("./remotes");
|
|
11
|
-
Object.defineProperty(exports, "mapRemotes", { enumerable: true, get: function () { return remotes_1.mapRemotes; } });
|
|
12
|
-
Object.defineProperty(exports, "mapRemotesForSSR", { enumerable: true, get: function () { return remotes_1.mapRemotesForSSR; } });
|
|
13
|
-
const dependencies_1 = require("./dependencies");
|
|
14
|
-
Object.defineProperty(exports, "getDependentPackagesForProject", { enumerable: true, get: function () { return dependencies_1.getDependentPackagesForProject; } });
|
|
15
|
-
const package_json_1 = require("./package-json");
|
|
16
|
-
Object.defineProperty(exports, "readRootPackageJson", { enumerable: true, get: function () { return package_json_1.readRootPackageJson; } });
|
|
17
|
-
const with_module_federation_1 = require("./with-module-federation/with-module-federation");
|
|
18
|
-
Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return with_module_federation_1.withModuleFederation; } });
|
|
19
|
-
const with_module_federation_ssr_1 = require("./with-module-federation/with-module-federation-ssr");
|
|
20
|
-
Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return with_module_federation_ssr_1.withModuleFederationForSSR; } });
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Remotes } from './models';
|
|
2
|
-
/**
|
|
3
|
-
* Map remote names to a format that can be understood and used by Module
|
|
4
|
-
* Federation.
|
|
5
|
-
*
|
|
6
|
-
* @param remotes - The remotes to map
|
|
7
|
-
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
8
|
-
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
9
|
-
*/
|
|
10
|
-
export declare function mapRemotes(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
|
|
11
|
-
/**
|
|
12
|
-
* Map remote names to a format that can be understood and used by Module
|
|
13
|
-
* Federation.
|
|
14
|
-
*
|
|
15
|
-
* @param remotes - The remotes to map
|
|
16
|
-
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
17
|
-
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
18
|
-
*/
|
|
19
|
-
export declare function mapRemotesForSSR(remotes: Remotes, remoteEntryExt: 'js' | 'mjs', determineRemoteUrl: (remote: string) => string): Record<string, string>;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapRemotes = mapRemotes;
|
|
4
|
-
exports.mapRemotesForSSR = mapRemotesForSSR;
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
/**
|
|
7
|
-
* Map remote names to a format that can be understood and used by Module
|
|
8
|
-
* Federation.
|
|
9
|
-
*
|
|
10
|
-
* @param remotes - The remotes to map
|
|
11
|
-
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
12
|
-
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
13
|
-
*/
|
|
14
|
-
function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl) {
|
|
15
|
-
const mappedRemotes = {};
|
|
16
|
-
for (const nxRemoteProjectName of remotes) {
|
|
17
|
-
if (Array.isArray(nxRemoteProjectName)) {
|
|
18
|
-
const mfRemoteName = normalizeRemoteName(nxRemoteProjectName[0]);
|
|
19
|
-
mappedRemotes[mfRemoteName] = handleArrayRemote(nxRemoteProjectName, remoteEntryExt);
|
|
20
|
-
}
|
|
21
|
-
else if (typeof nxRemoteProjectName === 'string') {
|
|
22
|
-
const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
|
|
23
|
-
mappedRemotes[mfRemoteName] = handleStringRemote(nxRemoteProjectName, determineRemoteUrl);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return mappedRemotes;
|
|
27
|
-
}
|
|
28
|
-
// Helper function to deal with remotes that are arrays
|
|
29
|
-
function handleArrayRemote(remote, remoteEntryExt) {
|
|
30
|
-
let [nxRemoteProjectName, remoteLocation] = remote;
|
|
31
|
-
const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
|
|
32
|
-
const remoteLocationExt = (0, path_1.extname)(remoteLocation);
|
|
33
|
-
// If remote location already has .js or .mjs extension
|
|
34
|
-
if (['.js', '.mjs', '.json'].includes(remoteLocationExt)) {
|
|
35
|
-
return remoteLocation;
|
|
36
|
-
}
|
|
37
|
-
const baseRemote = remoteLocation.endsWith('/')
|
|
38
|
-
? remoteLocation.slice(0, -1)
|
|
39
|
-
: remoteLocation;
|
|
40
|
-
const globalPrefix = `${normalizeRemoteName(mfRemoteName)}@`;
|
|
41
|
-
// if the remote is defined with anything other than http then we assume it's a promise based remote
|
|
42
|
-
// In that case we should use what the user provides as the remote location
|
|
43
|
-
if (!remoteLocation.startsWith('promise new Promise')) {
|
|
44
|
-
return `${globalPrefix}${baseRemote}/remoteEntry.${remoteEntryExt}`;
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
return remoteLocation;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
// Helper function to deal with remotes that are strings
|
|
51
|
-
function handleStringRemote(nxRemoteProjectName, determineRemoteUrl) {
|
|
52
|
-
const globalPrefix = `${normalizeRemoteName(nxRemoteProjectName)}@`;
|
|
53
|
-
return `${globalPrefix}${determineRemoteUrl(nxRemoteProjectName)}`;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Map remote names to a format that can be understood and used by Module
|
|
57
|
-
* Federation.
|
|
58
|
-
*
|
|
59
|
-
* @param remotes - The remotes to map
|
|
60
|
-
* @param remoteEntryExt - The file extension of the remoteEntry file
|
|
61
|
-
* @param determineRemoteUrl - The function used to lookup the URL of the served remote
|
|
62
|
-
*/
|
|
63
|
-
function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
|
|
64
|
-
const mappedRemotes = {};
|
|
65
|
-
for (const remote of remotes) {
|
|
66
|
-
if (Array.isArray(remote)) {
|
|
67
|
-
let [nxRemoteProjectName, remoteLocation] = remote;
|
|
68
|
-
const mfRemoteName = normalizeRemoteName(nxRemoteProjectName);
|
|
69
|
-
const remoteLocationExt = (0, path_1.extname)(remoteLocation);
|
|
70
|
-
mappedRemotes[mfRemoteName] = `${mfRemoteName}@${['.js', '.mjs'].includes(remoteLocationExt)
|
|
71
|
-
? remoteLocation
|
|
72
|
-
: `${remoteLocation.endsWith('/')
|
|
73
|
-
? remoteLocation.slice(0, -1)
|
|
74
|
-
: remoteLocation}/remoteEntry.${remoteEntryExt}`}`;
|
|
75
|
-
}
|
|
76
|
-
else if (typeof remote === 'string') {
|
|
77
|
-
const mfRemoteName = normalizeRemoteName(remote);
|
|
78
|
-
mappedRemotes[mfRemoteName] = `${mfRemoteName}@${determineRemoteUrl(remote)}`;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
return mappedRemotes;
|
|
82
|
-
}
|
|
83
|
-
function normalizeRemoteName(nxRemoteProjectName) {
|
|
84
|
-
return nxRemoteProjectName.replace(/-/g, '_');
|
|
85
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { WorkspaceLibrary } from './models';
|
|
2
|
-
import { WorkspaceLibrarySecondaryEntryPoint } from './models';
|
|
3
|
-
export declare function collectWorkspaceLibrarySecondaryEntryPoints(library: WorkspaceLibrary, tsconfigPathAliases: Record<string, string[]>): WorkspaceLibrarySecondaryEntryPoint[];
|
|
4
|
-
export declare function getNonNodeModulesSubDirs(directory: string): string[];
|
|
5
|
-
export declare function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName: string, pkgVersion: string, pkgRoot: string, mainEntryPointExports: any | undefined, directories: string[], collectedPackages: {
|
|
6
|
-
name: string;
|
|
7
|
-
version: string;
|
|
8
|
-
}[]): void;
|
|
9
|
-
export declare function collectPackageSecondaryEntryPoints(pkgName: string, pkgVersion: string, collectedPackages: {
|
|
10
|
-
name: string;
|
|
11
|
-
version: string;
|
|
12
|
-
}[]): void;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.collectWorkspaceLibrarySecondaryEntryPoints = collectWorkspaceLibrarySecondaryEntryPoints;
|
|
4
|
-
exports.getNonNodeModulesSubDirs = getNonNodeModulesSubDirs;
|
|
5
|
-
exports.recursivelyCollectSecondaryEntryPointsFromDirectory = recursivelyCollectSecondaryEntryPointsFromDirectory;
|
|
6
|
-
exports.collectPackageSecondaryEntryPoints = collectPackageSecondaryEntryPoints;
|
|
7
|
-
const devkit_1 = require("@nx/devkit");
|
|
8
|
-
const fs_1 = require("fs");
|
|
9
|
-
const package_json_1 = require("nx/src/utils/package-json");
|
|
10
|
-
const path_1 = require("path");
|
|
11
|
-
function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliases) {
|
|
12
|
-
const libraryRoot = (0, path_1.join)(devkit_1.workspaceRoot, library.root);
|
|
13
|
-
const needsSecondaryEntryPointsCollected = (0, fs_1.existsSync)((0, path_1.join)(libraryRoot, 'ng-package.json'));
|
|
14
|
-
const secondaryEntryPoints = [];
|
|
15
|
-
if (needsSecondaryEntryPointsCollected) {
|
|
16
|
-
const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
|
|
17
|
-
if (!tsKey.startsWith(library.importKey)) {
|
|
18
|
-
return { ...acc };
|
|
19
|
-
}
|
|
20
|
-
if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
|
|
21
|
-
acc = { ...acc, [tsKey]: tsPaths };
|
|
22
|
-
}
|
|
23
|
-
return acc;
|
|
24
|
-
}, {});
|
|
25
|
-
for (const [alias] of Object.entries(tsConfigAliasesForLibWithSecondaryEntryPoints)) {
|
|
26
|
-
const pathToLib = (0, path_1.dirname)((0, path_1.join)(devkit_1.workspaceRoot, tsconfigPathAliases[alias][0]));
|
|
27
|
-
let searchDir = pathToLib;
|
|
28
|
-
while (searchDir !== libraryRoot) {
|
|
29
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(searchDir, 'ng-package.json'))) {
|
|
30
|
-
secondaryEntryPoints.push({ name: alias, path: pathToLib });
|
|
31
|
-
break;
|
|
32
|
-
}
|
|
33
|
-
searchDir = (0, path_1.dirname)(searchDir);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return secondaryEntryPoints;
|
|
38
|
-
}
|
|
39
|
-
function getNonNodeModulesSubDirs(directory) {
|
|
40
|
-
return (0, fs_1.readdirSync)(directory)
|
|
41
|
-
.filter((file) => file !== 'node_modules')
|
|
42
|
-
.map((file) => (0, path_1.join)(directory, file))
|
|
43
|
-
.filter((file) => (0, fs_1.lstatSync)(file).isDirectory());
|
|
44
|
-
}
|
|
45
|
-
function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, directories, collectedPackages) {
|
|
46
|
-
for (const directory of directories) {
|
|
47
|
-
const packageJsonPath = (0, path_1.join)(directory, 'package.json');
|
|
48
|
-
const relativeEntryPointPath = (0, path_1.relative)(pkgRoot, directory);
|
|
49
|
-
const entryPointName = (0, devkit_1.joinPathFragments)(pkgName, relativeEntryPointPath);
|
|
50
|
-
if ((0, fs_1.existsSync)(packageJsonPath)) {
|
|
51
|
-
try {
|
|
52
|
-
// require the secondary entry point to try to rule out sample code
|
|
53
|
-
require.resolve(entryPointName, { paths: [devkit_1.workspaceRoot] });
|
|
54
|
-
const { name } = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
55
|
-
// further check to make sure what we were able to require is the
|
|
56
|
-
// same as the package name
|
|
57
|
-
if (name === entryPointName) {
|
|
58
|
-
collectedPackages.push({ name, version: pkgVersion });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
// do nothing
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
else if (mainEntryPointExports) {
|
|
66
|
-
// if the package.json doesn't exist, check if the directory is
|
|
67
|
-
// exported by the main entry point
|
|
68
|
-
const entryPointExportKey = `./${relativeEntryPointPath}`;
|
|
69
|
-
const entryPointInfo = mainEntryPointExports[entryPointExportKey];
|
|
70
|
-
if (entryPointInfo) {
|
|
71
|
-
collectedPackages.push({
|
|
72
|
-
name: entryPointName,
|
|
73
|
-
version: pkgVersion,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const subDirs = getNonNodeModulesSubDirs(directory);
|
|
78
|
-
recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, subDirs, collectedPackages);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackages) {
|
|
82
|
-
let pathToPackage;
|
|
83
|
-
let packageJsonPath;
|
|
84
|
-
let packageJson;
|
|
85
|
-
try {
|
|
86
|
-
({ path: packageJsonPath, packageJson } = (0, package_json_1.readModulePackageJson)(pkgName));
|
|
87
|
-
pathToPackage = (0, path_1.dirname)(packageJsonPath);
|
|
88
|
-
}
|
|
89
|
-
catch {
|
|
90
|
-
// the package.json might not resolve if the package has the "exports"
|
|
91
|
-
// entry and is not exporting the package.json file, fall back to trying
|
|
92
|
-
// to find it from the top-level node_modules
|
|
93
|
-
pathToPackage = (0, path_1.join)(devkit_1.workspaceRoot, 'node_modules', pkgName);
|
|
94
|
-
packageJsonPath = (0, path_1.join)(pathToPackage, 'package.json');
|
|
95
|
-
if (!(0, fs_1.existsSync)(packageJsonPath)) {
|
|
96
|
-
// might not exist if it's nested in another package, just return here
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
100
|
-
}
|
|
101
|
-
const { exports } = packageJson;
|
|
102
|
-
const subDirs = getNonNodeModulesSubDirs(pathToPackage);
|
|
103
|
-
recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
|
|
104
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { type ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import type { SharedLibraryConfig, SharedWorkspaceLibraryConfig, WorkspaceLibrary } from './models';
|
|
3
|
-
import { AdditionalSharedConfig, SharedFunction } from './models';
|
|
4
|
-
/**
|
|
5
|
-
* Build an object of functions to be used with the ModuleFederationPlugin to
|
|
6
|
-
* share Nx Workspace Libraries between Hosts and Remotes.
|
|
7
|
-
*
|
|
8
|
-
* @param workspaceLibs - The Nx Workspace Libraries to share
|
|
9
|
-
* @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
|
|
10
|
-
*/
|
|
11
|
-
export declare function shareWorkspaceLibraries(workspaceLibs: WorkspaceLibrary[], tsConfigPath?: string): SharedWorkspaceLibraryConfig;
|
|
12
|
-
/**
|
|
13
|
-
* Build the Module Federation Share Config for a specific package and the
|
|
14
|
-
* specified version of that package.
|
|
15
|
-
* @param pkgName - Name of the package to share
|
|
16
|
-
* @param version - Version of the package to require by other apps in the Module Federation setup
|
|
17
|
-
*/
|
|
18
|
-
export declare function getNpmPackageSharedConfig(pkgName: string, version: string): SharedLibraryConfig | undefined;
|
|
19
|
-
/**
|
|
20
|
-
* Create a dictionary of packages and their Module Federation Shared Config
|
|
21
|
-
* from an array of package names.
|
|
22
|
-
*
|
|
23
|
-
* Lookup the versions of the packages from the root package.json file in the
|
|
24
|
-
* workspace.
|
|
25
|
-
* @param packages - Array of package names as strings
|
|
26
|
-
*/
|
|
27
|
-
export declare function sharePackages(packages: string[]): Record<string, SharedLibraryConfig>;
|
|
28
|
-
/**
|
|
29
|
-
* Apply a custom function provided by the user that will modify the Shared Config
|
|
30
|
-
* of the dependencies for the Module Federation build.
|
|
31
|
-
*
|
|
32
|
-
* @param sharedConfig - The original Shared Config to be modified
|
|
33
|
-
* @param sharedFn - The custom function to run
|
|
34
|
-
*/
|
|
35
|
-
export declare function applySharedFunction(sharedConfig: Record<string, SharedLibraryConfig>, sharedFn: SharedFunction | undefined): void;
|
|
36
|
-
/**
|
|
37
|
-
* Add additional dependencies to the shared package that may not have been
|
|
38
|
-
* discovered by the project graph.
|
|
39
|
-
*
|
|
40
|
-
* This can be useful for applications that use a Dependency Injection system
|
|
41
|
-
* that expects certain Singleton values to be present in the shared injection
|
|
42
|
-
* hierarchy.
|
|
43
|
-
*
|
|
44
|
-
* @param sharedConfig - The original Shared Config
|
|
45
|
-
* @param additionalShared - The additional dependencies to add
|
|
46
|
-
* @param projectGraph - The Nx project graph
|
|
47
|
-
*/
|
|
48
|
-
export declare function applyAdditionalShared(sharedConfig: Record<string, SharedLibraryConfig>, additionalShared: AdditionalSharedConfig | undefined, projectGraph: ProjectGraph): void;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.shareWorkspaceLibraries = shareWorkspaceLibraries;
|
|
4
|
-
exports.getNpmPackageSharedConfig = getNpmPackageSharedConfig;
|
|
5
|
-
exports.sharePackages = sharePackages;
|
|
6
|
-
exports.applySharedFunction = applySharedFunction;
|
|
7
|
-
exports.applyAdditionalShared = applyAdditionalShared;
|
|
8
|
-
const devkit_1 = require("@nx/devkit");
|
|
9
|
-
const core_1 = require("@rspack/core");
|
|
10
|
-
const fs_1 = require("fs");
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
const package_json_1 = require("./package-json");
|
|
13
|
-
const secondary_entry_points_1 = require("./secondary-entry-points");
|
|
14
|
-
const typescript_1 = require("./typescript");
|
|
15
|
-
/**
|
|
16
|
-
* Build an object of functions to be used with the ModuleFederationPlugin to
|
|
17
|
-
* share Nx Workspace Libraries between Hosts and Remotes.
|
|
18
|
-
*
|
|
19
|
-
* @param workspaceLibs - The Nx Workspace Libraries to share
|
|
20
|
-
* @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
|
|
21
|
-
*/
|
|
22
|
-
function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
|
|
23
|
-
if (!workspaceLibs) {
|
|
24
|
-
return getEmptySharedLibrariesConfig();
|
|
25
|
-
}
|
|
26
|
-
const tsconfigPathAliases = (0, typescript_1.readTsPathMappings)(tsConfigPath);
|
|
27
|
-
if (!Object.keys(tsconfigPathAliases).length) {
|
|
28
|
-
return getEmptySharedLibrariesConfig();
|
|
29
|
-
}
|
|
30
|
-
// Nested projects must come first, sort them as such
|
|
31
|
-
const sortedTsConfigPathAliases = {};
|
|
32
|
-
Object.keys(tsconfigPathAliases)
|
|
33
|
-
.sort((a, b) => {
|
|
34
|
-
return b.split('/').length - a.split('/').length;
|
|
35
|
-
})
|
|
36
|
-
.forEach((key) => (sortedTsConfigPathAliases[key] = tsconfigPathAliases[key]));
|
|
37
|
-
const pathMappings = [];
|
|
38
|
-
for (const [key, paths] of Object.entries(sortedTsConfigPathAliases)) {
|
|
39
|
-
const library = workspaceLibs.find((lib) => lib.importKey === key);
|
|
40
|
-
if (!library) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
// This is for Angular Projects that use ng-package.json
|
|
44
|
-
// It will do nothing for React Projects
|
|
45
|
-
(0, secondary_entry_points_1.collectWorkspaceLibrarySecondaryEntryPoints)(library, sortedTsConfigPathAliases).forEach(({ name, path }) => pathMappings.push({
|
|
46
|
-
name,
|
|
47
|
-
path,
|
|
48
|
-
}));
|
|
49
|
-
pathMappings.push({
|
|
50
|
-
name: key,
|
|
51
|
-
path: (0, path_1.normalize)((0, path_1.join)(devkit_1.workspaceRoot, paths[0])),
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
getAliases: () => pathMappings.reduce((aliases, library) => ({
|
|
56
|
-
...aliases,
|
|
57
|
-
// If the library path ends in a wildcard, remove it as rspack can't handle this in resolve.alias
|
|
58
|
-
// e.g. path/to/my/lib/* -> path/to/my/lib
|
|
59
|
-
[library.name]: library.path.replace(/\/\*$/, ''),
|
|
60
|
-
}), {}),
|
|
61
|
-
getLibraries: (projectRoot, eager) => {
|
|
62
|
-
let pkgJson = null;
|
|
63
|
-
if (projectRoot &&
|
|
64
|
-
(0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'))) {
|
|
65
|
-
pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
|
|
66
|
-
}
|
|
67
|
-
return pathMappings.reduce((libraries, library) => {
|
|
68
|
-
// Check to see if the library version is declared in the app's package.json
|
|
69
|
-
let version = pkgJson?.dependencies?.[library.name];
|
|
70
|
-
if (!version && workspaceLibs.length > 0) {
|
|
71
|
-
const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
|
|
72
|
-
const libPackageJsonPath = workspaceLib
|
|
73
|
-
? (0, path_1.join)(workspaceLib.root, 'package.json')
|
|
74
|
-
: null;
|
|
75
|
-
if (libPackageJsonPath && (0, fs_1.existsSync)(libPackageJsonPath)) {
|
|
76
|
-
pkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
|
|
77
|
-
if (pkgJson) {
|
|
78
|
-
version = pkgJson.version;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
...libraries,
|
|
84
|
-
[library.name]: {
|
|
85
|
-
...(version
|
|
86
|
-
? {
|
|
87
|
-
requiredVersion: version,
|
|
88
|
-
singleton: true,
|
|
89
|
-
}
|
|
90
|
-
: { requiredVersion: false }),
|
|
91
|
-
eager,
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
}, {});
|
|
95
|
-
},
|
|
96
|
-
getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, (req) => {
|
|
97
|
-
if (!req.request.startsWith('.')) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const from = req.context;
|
|
101
|
-
const to = (0, path_1.normalize)((0, path_1.join)(req.context, req.request));
|
|
102
|
-
for (const library of pathMappings) {
|
|
103
|
-
const libFolder = (0, path_1.normalize)((0, path_1.dirname)(library.path));
|
|
104
|
-
if (!from.startsWith(libFolder) && to.startsWith(libFolder)) {
|
|
105
|
-
const newReq = library.name.endsWith('/*')
|
|
106
|
-
? /**
|
|
107
|
-
* req usually is in the form of "../../../path/to/file"
|
|
108
|
-
* library.path is usually in the form of "/Users/username/path/to/Workspace/path/to/library"
|
|
109
|
-
*
|
|
110
|
-
* When a wildcard is used in the TS path mappings, we want to get everything after the import to
|
|
111
|
-
* re-route the request correctly inline with the rspack resolve.alias
|
|
112
|
-
*/
|
|
113
|
-
(0, path_1.join)(library.name, req.request.split(library.path.replace(devkit_1.workspaceRoot, '').replace('/*', ''))[1])
|
|
114
|
-
: library.name;
|
|
115
|
-
req.request = newReq;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Build the Module Federation Share Config for a specific package and the
|
|
123
|
-
* specified version of that package.
|
|
124
|
-
* @param pkgName - Name of the package to share
|
|
125
|
-
* @param version - Version of the package to require by other apps in the Module Federation setup
|
|
126
|
-
*/
|
|
127
|
-
function getNpmPackageSharedConfig(pkgName, version) {
|
|
128
|
-
if (!version) {
|
|
129
|
-
devkit_1.logger.warn(`Could not find a version for "${pkgName}" in the root "package.json" ` +
|
|
130
|
-
'when collecting shared packages for the Module Federation setup. ' +
|
|
131
|
-
'The package will not be shared.');
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
return { singleton: true, strictVersion: true, requiredVersion: version };
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Create a dictionary of packages and their Module Federation Shared Config
|
|
138
|
-
* from an array of package names.
|
|
139
|
-
*
|
|
140
|
-
* Lookup the versions of the packages from the root package.json file in the
|
|
141
|
-
* workspace.
|
|
142
|
-
* @param packages - Array of package names as strings
|
|
143
|
-
*/
|
|
144
|
-
function sharePackages(packages) {
|
|
145
|
-
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
146
|
-
const allPackages = [];
|
|
147
|
-
packages.forEach((pkg) => {
|
|
148
|
-
const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
|
|
149
|
-
allPackages.push({ name: pkg, version: pkgVersion });
|
|
150
|
-
(0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
|
|
151
|
-
});
|
|
152
|
-
return allPackages.reduce((shared, pkg) => {
|
|
153
|
-
const config = getNpmPackageSharedConfig(pkg.name, pkg.version);
|
|
154
|
-
if (config) {
|
|
155
|
-
shared[pkg.name] = config;
|
|
156
|
-
}
|
|
157
|
-
return shared;
|
|
158
|
-
}, {});
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Apply a custom function provided by the user that will modify the Shared Config
|
|
162
|
-
* of the dependencies for the Module Federation build.
|
|
163
|
-
*
|
|
164
|
-
* @param sharedConfig - The original Shared Config to be modified
|
|
165
|
-
* @param sharedFn - The custom function to run
|
|
166
|
-
*/
|
|
167
|
-
function applySharedFunction(sharedConfig, sharedFn) {
|
|
168
|
-
if (!sharedFn) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
for (const [libraryName, library] of Object.entries(sharedConfig)) {
|
|
172
|
-
const mappedDependency = sharedFn(libraryName, library);
|
|
173
|
-
if (mappedDependency === false) {
|
|
174
|
-
delete sharedConfig[libraryName];
|
|
175
|
-
continue;
|
|
176
|
-
}
|
|
177
|
-
else if (!mappedDependency) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
sharedConfig[libraryName] = mappedDependency;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Add additional dependencies to the shared package that may not have been
|
|
185
|
-
* discovered by the project graph.
|
|
186
|
-
*
|
|
187
|
-
* This can be useful for applications that use a Dependency Injection system
|
|
188
|
-
* that expects certain Singleton values to be present in the shared injection
|
|
189
|
-
* hierarchy.
|
|
190
|
-
*
|
|
191
|
-
* @param sharedConfig - The original Shared Config
|
|
192
|
-
* @param additionalShared - The additional dependencies to add
|
|
193
|
-
* @param projectGraph - The Nx project graph
|
|
194
|
-
*/
|
|
195
|
-
function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
|
|
196
|
-
if (!additionalShared) {
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
for (const shared of additionalShared) {
|
|
200
|
-
if (typeof shared === 'string') {
|
|
201
|
-
addStringDependencyToSharedConfig(sharedConfig, shared, projectGraph);
|
|
202
|
-
}
|
|
203
|
-
else if (Array.isArray(shared)) {
|
|
204
|
-
sharedConfig[shared[0]] = shared[1];
|
|
205
|
-
}
|
|
206
|
-
else if (typeof shared === 'object') {
|
|
207
|
-
sharedConfig[shared.libraryName] = shared.sharedConfig;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
|
|
212
|
-
if (projectGraph.nodes[dependency]) {
|
|
213
|
-
sharedConfig[dependency] = { requiredVersion: false };
|
|
214
|
-
}
|
|
215
|
-
else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
|
|
216
|
-
const pkgJson = (0, package_json_1.readRootPackageJson)();
|
|
217
|
-
const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
|
|
218
|
-
pkgJson.devDependencies?.[dependency]);
|
|
219
|
-
if (!config) {
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
sharedConfig[dependency] = config;
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
throw new Error(`The specified dependency "${dependency}" in the additionalShared configuration does not exist in the project graph. ` +
|
|
226
|
-
`Please check your additionalShared configuration and make sure you are including valid workspace projects or npm packages.`);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
function getEmptySharedLibrariesConfig() {
|
|
230
|
-
return {
|
|
231
|
-
getAliases: () => ({}),
|
|
232
|
-
getLibraries: () => ({}),
|
|
233
|
-
getReplacementPlugin: () => new core_1.NormalModuleReplacementPlugin(/./, () => undefined),
|
|
234
|
-
};
|
|
235
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { StaticRemotesConfig } from './parse-static-remotes-config';
|
|
2
|
-
export declare function startRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
3
|
-
pathToCert: string;
|
|
4
|
-
pathToKey: string;
|
|
5
|
-
}): void;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startRemoteProxies = startRemoteProxies;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
function startRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions) {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
-
const express = require('express');
|
|
11
|
-
let sslCert;
|
|
12
|
-
let sslKey;
|
|
13
|
-
if (sslOptions && sslOptions.pathToCert && sslOptions.pathToKey) {
|
|
14
|
-
if ((0, fs_1.existsSync)(sslOptions.pathToCert) && (0, fs_1.existsSync)(sslOptions.pathToKey)) {
|
|
15
|
-
sslCert = (0, fs_1.readFileSync)(sslOptions.pathToCert);
|
|
16
|
-
sslKey = (0, fs_1.readFileSync)(sslOptions.pathToKey);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
devkit_1.logger.warn(`Encountered SSL options in project.json, however, the certificate files do not exist in the filesystem. Using http.`);
|
|
20
|
-
devkit_1.logger.warn(`Attempted to find '${sslOptions.pathToCert}' and '${sslOptions.pathToKey}'.`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
24
|
-
const http = require('http');
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
26
|
-
const https = require('https');
|
|
27
|
-
devkit_1.logger.info(`NX Starting static remotes proxies...`);
|
|
28
|
-
for (const app of staticRemotesConfig.remotes) {
|
|
29
|
-
const expressProxy = express();
|
|
30
|
-
expressProxy.use(createProxyMiddleware({
|
|
31
|
-
target: mappedLocationsOfRemotes[app],
|
|
32
|
-
changeOrigin: true,
|
|
33
|
-
secure: sslCert ? false : undefined,
|
|
34
|
-
}));
|
|
35
|
-
const proxyServer = (sslCert
|
|
36
|
-
? https.createServer({
|
|
37
|
-
cert: sslCert,
|
|
38
|
-
key: sslKey,
|
|
39
|
-
}, expressProxy)
|
|
40
|
-
: http.createServer(expressProxy)).listen(staticRemotesConfig.config[app].port);
|
|
41
|
-
process.on('SIGTERM', () => proxyServer.close());
|
|
42
|
-
process.on('exit', () => proxyServer.close());
|
|
43
|
-
}
|
|
44
|
-
devkit_1.logger.info(`NX Static remotes proxies started successfully`);
|
|
45
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { StaticRemotesConfig } from './parse-static-remotes-config';
|
|
2
|
-
export declare function startSsrRemoteProxies(staticRemotesConfig: StaticRemotesConfig, mappedLocationsOfRemotes: Record<string, string>, sslOptions?: {
|
|
3
|
-
pathToCert: string;
|
|
4
|
-
pathToKey: string;
|
|
5
|
-
}): void;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startSsrRemoteProxies = startSsrRemoteProxies;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const fs_1 = require("fs");
|
|
6
|
-
function startSsrRemoteProxies(staticRemotesConfig, mappedLocationsOfRemotes, sslOptions) {
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
8
|
-
const { createProxyMiddleware } = require('http-proxy-middleware');
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
10
|
-
const express = require('express');
|
|
11
|
-
let sslCert;
|
|
12
|
-
let sslKey;
|
|
13
|
-
if (sslOptions && sslOptions.pathToCert && sslOptions.pathToKey) {
|
|
14
|
-
if ((0, fs_1.existsSync)(sslOptions.pathToCert) && (0, fs_1.existsSync)(sslOptions.pathToKey)) {
|
|
15
|
-
sslCert = (0, fs_1.readFileSync)(sslOptions.pathToCert);
|
|
16
|
-
sslKey = (0, fs_1.readFileSync)(sslOptions.pathToKey);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
devkit_1.logger.warn(`Encountered SSL options in project.json, however, the certificate files do not exist in the filesystem. Using http.`);
|
|
20
|
-
devkit_1.logger.warn(`Attempted to find '${sslOptions.pathToCert}' and '${sslOptions.pathToKey}'.`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
24
|
-
const http = require('http');
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
26
|
-
const https = require('https');
|
|
27
|
-
devkit_1.logger.info(`NX Starting static remotes proxies...`);
|
|
28
|
-
for (const app of staticRemotesConfig.remotes) {
|
|
29
|
-
const expressProxy = express();
|
|
30
|
-
/**
|
|
31
|
-
* SSR remotes have two output paths: one for the browser and one for the server.
|
|
32
|
-
* We need to handle paths for both of them.
|
|
33
|
-
* The browser output path is used to serve the client-side code.
|
|
34
|
-
* The server output path is used to serve the server-side code.
|
|
35
|
-
*/
|
|
36
|
-
expressProxy.use(createProxyMiddleware({
|
|
37
|
-
target: `${mappedLocationsOfRemotes[app]}`,
|
|
38
|
-
secure: sslCert ? false : undefined,
|
|
39
|
-
changeOrigin: true,
|
|
40
|
-
pathRewrite: (path) => {
|
|
41
|
-
if (path.includes('/server')) {
|
|
42
|
-
return path;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
return `browser/${path}`;
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
}));
|
|
49
|
-
const proxyServer = (sslCert
|
|
50
|
-
? https.createServer({
|
|
51
|
-
cert: sslCert,
|
|
52
|
-
key: sslKey,
|
|
53
|
-
}, expressProxy)
|
|
54
|
-
: http.createServer(expressProxy)).listen(staticRemotesConfig.config[app].port);
|
|
55
|
-
process.on('SIGTERM', () => proxyServer.close());
|
|
56
|
-
process.on('exit', () => proxyServer.close());
|
|
57
|
-
}
|
|
58
|
-
devkit_1.logger.info(`Nx SSR Static remotes proxies started successfully`);
|
|
59
|
-
}
|