@nx/webpack 0.0.0-pr-22179-271588f

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.
Files changed (146) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +68 -0
  3. package/executors.json +19 -0
  4. package/generators.json +20 -0
  5. package/index.d.ts +18 -0
  6. package/index.js +24 -0
  7. package/migrations.json +60 -0
  8. package/package.json +74 -0
  9. package/plugin.d.ts +1 -0
  10. package/plugin.js +5 -0
  11. package/src/executors/dev-server/dev-server.impl.d.ts +7 -0
  12. package/src/executors/dev-server/dev-server.impl.js +79 -0
  13. package/src/executors/dev-server/lib/get-dev-server-config.d.ts +4 -0
  14. package/src/executors/dev-server/lib/get-dev-server-config.js +79 -0
  15. package/src/executors/dev-server/lib/serve-path.d.ts +3 -0
  16. package/src/executors/dev-server/lib/serve-path.js +45 -0
  17. package/src/executors/dev-server/schema.d.ts +17 -0
  18. package/src/executors/dev-server/schema.json +76 -0
  19. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.d.ts +1 -0
  20. package/src/executors/ssr-dev-server/lib/wait-until-server-is-listening.js +39 -0
  21. package/src/executors/ssr-dev-server/schema.d.ts +11 -0
  22. package/src/executors/ssr-dev-server/schema.json +37 -0
  23. package/src/executors/ssr-dev-server/ssr-dev-server.impl.d.ts +8 -0
  24. package/src/executors/ssr-dev-server/ssr-dev-server.impl.js +39 -0
  25. package/src/executors/webpack/lib/normalize-options.d.ts +3 -0
  26. package/src/executors/webpack/lib/normalize-options.js +40 -0
  27. package/src/executors/webpack/lib/run-webpack.d.ts +3 -0
  28. package/src/executors/webpack/lib/run-webpack.js +36 -0
  29. package/src/executors/webpack/schema.d.ts +96 -0
  30. package/src/executors/webpack/schema.json +394 -0
  31. package/src/executors/webpack/webpack.impl.d.ts +13 -0
  32. package/src/executors/webpack/webpack.impl.js +125 -0
  33. package/src/generators/configuration/configuration.d.ts +5 -0
  34. package/src/generators/configuration/configuration.js +194 -0
  35. package/src/generators/configuration/schema.d.ts +14 -0
  36. package/src/generators/configuration/schema.json +77 -0
  37. package/src/generators/init/init.d.ts +5 -0
  38. package/src/generators/init/init.js +60 -0
  39. package/src/generators/init/schema.d.ts +7 -0
  40. package/src/generators/init/schema.json +33 -0
  41. package/src/migrations/update-15-0-0/add-babel-inputs.d.ts +2 -0
  42. package/src/migrations/update-15-0-0/add-babel-inputs.js +9 -0
  43. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.d.ts +2 -0
  44. package/src/migrations/update-15-4-5/remove-es2015-polyfills-option.js +20 -0
  45. package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
  46. package/src/migrations/update-15-6-3/webpack-config-setup.js +100 -0
  47. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.d.ts +2 -0
  48. package/src/migrations/update-15-7-2/add-babelUpwardRootMode-flag.js +17 -0
  49. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +2 -0
  50. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +9 -0
  51. package/src/migrations/update-17-2-1/webpack-config-setup.d.ts +2 -0
  52. package/src/migrations/update-17-2-1/webpack-config-setup.js +31 -0
  53. package/src/plugins/generate-package-json-plugin.d.ts +14 -0
  54. package/src/plugins/generate-package-json-plugin.js +44 -0
  55. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.d.ts +8 -0
  56. package/src/plugins/nx-typescript-webpack-plugin/nx-tsconfig-paths-webpack-plugin.js +31 -0
  57. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.d.ts +5 -0
  58. package/src/plugins/nx-webpack-plugin/lib/apply-base-config.js +318 -0
  59. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.d.ts +5 -0
  60. package/src/plugins/nx-webpack-plugin/lib/apply-web-config.js +372 -0
  61. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.d.ts +53 -0
  62. package/src/plugins/nx-webpack-plugin/lib/compiler-loaders.js +78 -0
  63. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.d.ts +1 -0
  64. package/src/plugins/nx-webpack-plugin/lib/get-terser-ecma-version.js +35 -0
  65. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.d.ts +3 -0
  66. package/src/plugins/nx-webpack-plugin/lib/instantiate-script-plugins.js +42 -0
  67. package/src/plugins/nx-webpack-plugin/lib/normalize-options.d.ts +4 -0
  68. package/src/plugins/nx-webpack-plugin/lib/normalize-options.js +143 -0
  69. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.d.ts +73 -0
  70. package/src/plugins/nx-webpack-plugin/lib/stylesheet-loaders.js +117 -0
  71. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.d.ts +216 -0
  72. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin-options.js +2 -0
  73. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.d.ts +17 -0
  74. package/src/plugins/nx-webpack-plugin/nx-webpack-plugin.js +48 -0
  75. package/src/plugins/plugin.d.ts +9 -0
  76. package/src/plugins/plugin.js +131 -0
  77. package/src/plugins/stats-json-plugin.d.ts +4 -0
  78. package/src/plugins/stats-json-plugin.js +13 -0
  79. package/src/plugins/webpack-nx-build-coordination-plugin.d.ts +11 -0
  80. package/src/plugins/webpack-nx-build-coordination-plugin.js +85 -0
  81. package/src/plugins/write-index-html-plugin.d.ts +22 -0
  82. package/src/plugins/write-index-html-plugin.js +249 -0
  83. package/src/utils/config.d.ts +22 -0
  84. package/src/utils/config.js +66 -0
  85. package/src/utils/create-copy-plugin.d.ts +3 -0
  86. package/src/utils/create-copy-plugin.js +26 -0
  87. package/src/utils/ensure-dependencies.d.ts +6 -0
  88. package/src/utils/ensure-dependencies.js +28 -0
  89. package/src/utils/fs.d.ts +6 -0
  90. package/src/utils/fs.js +58 -0
  91. package/src/utils/get-client-environment.d.ts +5 -0
  92. package/src/utils/get-client-environment.js +29 -0
  93. package/src/utils/get-css-module-local-ident.d.ts +1 -0
  94. package/src/utils/get-css-module-local-ident.js +18 -0
  95. package/src/utils/has-plugin.d.ts +2 -0
  96. package/src/utils/has-plugin.js +11 -0
  97. package/src/utils/hash-format.d.ts +7 -0
  98. package/src/utils/hash-format.js +23 -0
  99. package/src/utils/models.d.ts +23 -0
  100. package/src/utils/models.js +2 -0
  101. package/src/utils/module-federation/dependencies.d.ts +6 -0
  102. package/src/utils/module-federation/dependencies.js +57 -0
  103. package/src/utils/module-federation/get-remotes-for-host.d.ts +14 -0
  104. package/src/utils/module-federation/get-remotes-for-host.js +88 -0
  105. package/src/utils/module-federation/index.d.ts +6 -0
  106. package/src/utils/module-federation/index.js +9 -0
  107. package/src/utils/module-federation/models/index.d.ts +39 -0
  108. package/src/utils/module-federation/models/index.js +2 -0
  109. package/src/utils/module-federation/package-json.d.ts +8 -0
  110. package/src/utils/module-federation/package-json.js +13 -0
  111. package/src/utils/module-federation/public-api.d.ts +6 -0
  112. package/src/utils/module-federation/public-api.js +16 -0
  113. package/src/utils/module-federation/remotes.d.ts +19 -0
  114. package/src/utils/module-federation/remotes.js +80 -0
  115. package/src/utils/module-federation/secondary-entry-points.d.ts +12 -0
  116. package/src/utils/module-federation/secondary-entry-points.js +108 -0
  117. package/src/utils/module-federation/share.d.ts +48 -0
  118. package/src/utils/module-federation/share.js +215 -0
  119. package/src/utils/module-federation/typescript.d.ts +4 -0
  120. package/src/utils/module-federation/typescript.js +54 -0
  121. package/src/utils/run-webpack.d.ts +5 -0
  122. package/src/utils/run-webpack.js +31 -0
  123. package/src/utils/versions.d.ts +8 -0
  124. package/src/utils/versions.js +12 -0
  125. package/src/utils/web-babel-loader.d.ts +0 -0
  126. package/src/utils/web-babel-loader.js +17 -0
  127. package/src/utils/webpack/deprecated-stylus-loader.d.ts +1 -0
  128. package/src/utils/webpack/deprecated-stylus-loader.js +11 -0
  129. package/src/utils/webpack/interpolate-env-variables-to-index.d.ts +1 -0
  130. package/src/utils/webpack/interpolate-env-variables-to-index.js +30 -0
  131. package/src/utils/webpack/normalize-entry.d.ts +2 -0
  132. package/src/utils/webpack/normalize-entry.js +28 -0
  133. package/src/utils/webpack/package-chunk-sort.d.ts +5 -0
  134. package/src/utils/webpack/package-chunk-sort.js +29 -0
  135. package/src/utils/webpack/plugins/postcss-cli-resources.d.ts +13 -0
  136. package/src/utils/webpack/plugins/postcss-cli-resources.js +165 -0
  137. package/src/utils/webpack/plugins/scripts-webpack-plugin.d.ts +17 -0
  138. package/src/utils/webpack/plugins/scripts-webpack-plugin.js +119 -0
  139. package/src/utils/webpack/read-webpack-options.d.ts +10 -0
  140. package/src/utils/webpack/read-webpack-options.js +41 -0
  141. package/src/utils/webpack/resolve-user-defined-webpack-config.d.ts +3 -0
  142. package/src/utils/webpack/resolve-user-defined-webpack-config.js +39 -0
  143. package/src/utils/with-nx.d.ts +8 -0
  144. package/src/utils/with-nx.js +34 -0
  145. package/src/utils/with-web.d.ts +22 -0
  146. package/src/utils/with-web.js +26 -0
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
6
+ const versions_1 = require("./versions");
7
+ function ensureDependencies(tree, options) {
8
+ const tasks = [];
9
+ const devDependencies = {};
10
+ if (options.compiler === 'swc') {
11
+ devDependencies['swc-loader'] = versions_1.swcLoaderVersion;
12
+ const addSwcTask = (0, add_swc_dependencies_1.addSwcDependencies)(tree);
13
+ tasks.push(addSwcTask);
14
+ }
15
+ if (options.compiler === 'tsc') {
16
+ devDependencies['tslib'] = versions_1.tsLibVersion;
17
+ }
18
+ if (options.uiFramework === 'react') {
19
+ devDependencies['@pmmmwh/react-refresh-webpack-plugin'] =
20
+ versions_1.reactRefreshWebpackPluginVersion;
21
+ devDependencies['@svgr/webpack'] = versions_1.svgrWebpackVersion;
22
+ devDependencies['react-refresh'] = versions_1.reactRefreshVersion;
23
+ devDependencies['url-loader'] = versions_1.urlLoaderVersion;
24
+ }
25
+ tasks.push((0, devkit_1.addDependenciesToPackageJson)(tree, {}, devDependencies));
26
+ return (0, devkit_1.runTasksInSerial)(...tasks);
27
+ }
28
+ exports.ensureDependencies = ensureDependencies;
@@ -0,0 +1,6 @@
1
+ export declare function findUp(names: string | string[], from: string, stopOnNodeModules?: boolean): string;
2
+ export declare function findAllNodeModules(from: string, root?: string): string[];
3
+ /**
4
+ * Delete an output directory, but error out if it's the root of the project.
5
+ */
6
+ export declare function deleteOutputDir(root: string, outputPath: string): void;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deleteOutputDir = exports.findAllNodeModules = exports.findUp = void 0;
4
+ const path = require("path");
5
+ const fs_1 = require("fs");
6
+ const fileutils_1 = require("nx/src/utils/fileutils");
7
+ function findUp(names, from, stopOnNodeModules = false) {
8
+ if (!Array.isArray(names)) {
9
+ names = [names];
10
+ }
11
+ const root = path.parse(from).root;
12
+ let currentDir = from;
13
+ while (currentDir && currentDir !== root) {
14
+ for (const name of names) {
15
+ const p = path.join(currentDir, name);
16
+ if ((0, fs_1.existsSync)(p)) {
17
+ return p;
18
+ }
19
+ }
20
+ if (stopOnNodeModules) {
21
+ const nodeModuleP = path.join(currentDir, 'node_modules');
22
+ if ((0, fs_1.existsSync)(nodeModuleP)) {
23
+ return null;
24
+ }
25
+ }
26
+ currentDir = path.dirname(currentDir);
27
+ }
28
+ return null;
29
+ }
30
+ exports.findUp = findUp;
31
+ function findAllNodeModules(from, root) {
32
+ const nodeModules = [];
33
+ let current = from;
34
+ while (current && current !== root) {
35
+ const potential = path.join(current, 'node_modules');
36
+ if ((0, fileutils_1.directoryExists)(potential)) {
37
+ nodeModules.push(potential);
38
+ }
39
+ const next = path.dirname(current);
40
+ if (next === current) {
41
+ break;
42
+ }
43
+ current = next;
44
+ }
45
+ return nodeModules;
46
+ }
47
+ exports.findAllNodeModules = findAllNodeModules;
48
+ /**
49
+ * Delete an output directory, but error out if it's the root of the project.
50
+ */
51
+ function deleteOutputDir(root, outputPath) {
52
+ const resolvedOutputPath = path.resolve(root, outputPath);
53
+ if (resolvedOutputPath === root) {
54
+ throw new Error('Output path MUST not be project root directory!');
55
+ }
56
+ (0, fs_1.rmSync)(resolvedOutputPath, { recursive: true, force: true });
57
+ }
58
+ exports.deleteOutputDir = deleteOutputDir;
@@ -0,0 +1,5 @@
1
+ export declare function getClientEnvironment(mode?: string): {
2
+ stringified: {
3
+ 'process.env': {};
4
+ };
5
+ };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getClientEnvironment = void 0;
4
+ function getClientEnvironment(mode) {
5
+ // Grab NODE_ENV and NX_* environment variables and prepare them to be
6
+ // injected into the application via DefinePlugin in webpack configuration.
7
+ const NX_APP = /^NX_/i;
8
+ const raw = Object.keys(process.env)
9
+ .filter((key) => NX_APP.test(key))
10
+ .reduce((env, key) => {
11
+ env[key] = process.env[key];
12
+ return env;
13
+ },
14
+ // If mode is undefined or is dev or prod then webpack already defines this variable for us.
15
+ !mode || mode === 'development' || mode === 'production'
16
+ ? {}
17
+ : {
18
+ NODE_ENV: process.env.NODE_ENV,
19
+ });
20
+ // Stringify all values so we can feed into webpack DefinePlugin
21
+ const stringified = {
22
+ 'process.env': Object.keys(raw).reduce((env, key) => {
23
+ env[key] = JSON.stringify(raw[key]);
24
+ return env;
25
+ }, {}),
26
+ };
27
+ return { stringified };
28
+ }
29
+ exports.getClientEnvironment = getClientEnvironment;
@@ -0,0 +1 @@
1
+ export declare function getCSSModuleLocalIdent(ctx: any, localIdentName: any, localName: any, options: any): any;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCSSModuleLocalIdent = void 0;
4
+ const path_1 = require("path");
5
+ const loader_utils_1 = require("loader-utils");
6
+ function getCSSModuleLocalIdent(ctx, localIdentName, localName, options) {
7
+ // Use the filename or folder name, based on some uses the index.js / index.module.(css|scss|sass) project style
8
+ const fileNameOrFolder = ctx.resourcePath.match(/index\.module\.(css|scss|sass)$/)
9
+ ? '[folder]'
10
+ : '[name]';
11
+ // Create a hash based on a the file location and class name. Will be unique across a project, and close to globally unique.
12
+ const hash = (0, loader_utils_1.getHashDigest)(path_1.posix.relative(ctx.rootContext, ctx.resourcePath) + localName, 'md5', 'base64', 5);
13
+ // Use loaderUtils to find the file or folder name
14
+ const className = (0, loader_utils_1.interpolateName)(ctx, `${fileNameOrFolder}_${localName}__${hash}`, options);
15
+ // Remove the .module that appears in every classname when based on the file and replace all "." with "_".
16
+ return className.replace('.module_', '_').replace(/\./g, '_');
17
+ }
18
+ exports.getCSSModuleLocalIdent = getCSSModuleLocalIdent;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasPlugin(tree: Tree): boolean;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPlugin = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return !!nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/webpack/plugin'
9
+ : p.plugin === '@nx/webpack/plugin');
10
+ }
11
+ exports.hasPlugin = hasPlugin;
@@ -0,0 +1,7 @@
1
+ export interface HashFormat {
2
+ chunk: string;
3
+ extract: string;
4
+ file: string;
5
+ script: string;
6
+ }
7
+ export declare function getOutputHashFormat(option: string, length?: number): HashFormat;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getOutputHashFormat = void 0;
4
+ function getOutputHashFormat(option, length = 20) {
5
+ const hashFormats = {
6
+ none: { chunk: '', extract: '', file: '', script: '' },
7
+ media: { chunk: '', extract: '', file: `.[hash:${length}]`, script: '' },
8
+ bundles: {
9
+ chunk: `.[chunkhash:${length}]`,
10
+ extract: `.[contenthash:${length}]`,
11
+ file: '',
12
+ script: `.[contenthash:${length}]`,
13
+ },
14
+ all: {
15
+ chunk: `.[chunkhash:${length}]`,
16
+ extract: `.[contenthash:${length}]`,
17
+ file: `.[contenthash:${length}]`,
18
+ script: `.[contenthash:${length}]`,
19
+ },
20
+ };
21
+ return hashFormats[option] || hashFormats['none'];
22
+ }
23
+ exports.getOutputHashFormat = getOutputHashFormat;
@@ -0,0 +1,23 @@
1
+ export type ExtraEntryPoint = ExtraEntryPointClass | string;
2
+ export interface ExtraEntryPointClass {
3
+ bundleName?: string;
4
+ inject?: boolean;
5
+ input: string;
6
+ }
7
+ export type NormalizedEntryPoint = Required<ExtraEntryPointClass>;
8
+ export interface EmittedFile {
9
+ id?: string;
10
+ name?: string;
11
+ file: string;
12
+ extension: string;
13
+ initial: boolean;
14
+ asset?: boolean;
15
+ }
16
+ export interface CreateWebpackConfigOptions<T = any> {
17
+ root: string;
18
+ projectRoot: string;
19
+ sourceRoot?: string;
20
+ buildOptions: T;
21
+ tsConfig: any;
22
+ tsConfigPath: string;
23
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import type { ProjectGraph } from '@nx/devkit';
2
+ import type { WorkspaceLibrary } from './models';
3
+ export declare function getDependentPackagesForProject(projectGraph: ProjectGraph, name: string): {
4
+ workspaceLibraries: WorkspaceLibrary[];
5
+ npmPackages: string[];
6
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDependentPackagesForProject = void 0;
4
+ const typescript_1 = require("./typescript");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function getDependentPackagesForProject(projectGraph, name) {
7
+ const { npmPackages, workspaceLibraries } = collectDependencies(projectGraph, name);
8
+ return {
9
+ workspaceLibraries: [...workspaceLibraries.values()],
10
+ npmPackages: [...npmPackages],
11
+ };
12
+ }
13
+ exports.getDependentPackagesForProject = getDependentPackagesForProject;
14
+ function collectDependencies(projectGraph, name, dependencies = {
15
+ workspaceLibraries: new Map(),
16
+ npmPackages: new Set(),
17
+ }, seen = new Set()) {
18
+ if (seen.has(name)) {
19
+ return dependencies;
20
+ }
21
+ seen.add(name);
22
+ (projectGraph.dependencies[name] ?? []).forEach((dependency) => {
23
+ if (dependency.target.startsWith('npm:')) {
24
+ dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
25
+ }
26
+ else {
27
+ dependencies.workspaceLibraries.set(dependency.target, {
28
+ name: dependency.target,
29
+ root: projectGraph.nodes[dependency.target].data.root,
30
+ importKey: getLibraryImportPath(dependency.target, projectGraph),
31
+ });
32
+ collectDependencies(projectGraph, dependency.target, dependencies, seen);
33
+ }
34
+ });
35
+ return dependencies;
36
+ }
37
+ function getLibraryImportPath(library, projectGraph) {
38
+ let buildLibsFromSource = true;
39
+ if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
40
+ buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
41
+ }
42
+ const libraryNode = projectGraph.nodes[library];
43
+ let sourceRoots = [libraryNode.data.sourceRoot];
44
+ if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
45
+ const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
46
+ sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
47
+ }
48
+ const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
49
+ for (const [key, value] of Object.entries(tsConfigPathMappings)) {
50
+ for (const src of sourceRoots) {
51
+ if (value.find((path) => path.startsWith(src))) {
52
+ return key;
53
+ }
54
+ }
55
+ }
56
+ return undefined;
57
+ }
@@ -0,0 +1,14 @@
1
+ import { type ProjectGraph } from '@nx/devkit';
2
+ import { ModuleFederationConfig } from './models/index';
3
+ interface ModuleFederationExecutorContext {
4
+ projectName: string;
5
+ projectGraph: ProjectGraph;
6
+ root: string;
7
+ }
8
+ export declare function getRemotes(devRemotes: string[], skipRemotes: string[], config: ModuleFederationConfig, context: ModuleFederationExecutorContext, pathToManifestFile?: string): {
9
+ staticRemotes: string[];
10
+ devRemotes: string[];
11
+ remotePorts: any[];
12
+ };
13
+ export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
14
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModuleFederationConfig = exports.getRemotes = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const internal_1 = require("@nx/js/src/internal");
6
+ const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
7
+ const chalk = require("chalk");
8
+ const path_1 = require("path");
9
+ const fs_1 = require("fs");
10
+ function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
11
+ const remotes = [];
12
+ if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
13
+ const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
14
+ if (moduleFederationManifestJson) {
15
+ // This should have shape of
16
+ // {
17
+ // "remoteName": "remoteLocation",
18
+ // }
19
+ const parsedManifest = JSON.parse(moduleFederationManifestJson);
20
+ if (Object.keys(parsedManifest).every((key) => typeof key === 'string' && typeof parsedManifest[key] === 'string')) {
21
+ remotes.push(...Object.keys(parsedManifest));
22
+ }
23
+ }
24
+ }
25
+ const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
26
+ remotes.push(...staticRemotes);
27
+ return remotes;
28
+ }
29
+ function collectRemoteProjects(remote, collected, context) {
30
+ const remoteProject = context.projectGraph.nodes[remote]?.data;
31
+ if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
32
+ return;
33
+ }
34
+ collected.add(remote);
35
+ const remoteProjectRoot = remoteProject.root;
36
+ const remoteProjectTsConfig = remoteProject.targets['build'].options.tsConfig;
37
+ const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
38
+ const remoteProjectRemotes = extractRemoteProjectsFromConfig(remoteProjectConfig);
39
+ remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
40
+ }
41
+ function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
42
+ const collectedRemotes = new Set();
43
+ const remotes = extractRemoteProjectsFromConfig(config, pathToManifestFile);
44
+ remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
45
+ const remotesToSkip = new Set((0, find_matching_projects_1.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
46
+ if (remotesToSkip.size > 0) {
47
+ devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
48
+ }
49
+ const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
50
+ devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk.bold(context.projectName)} with ${knownRemotes.length} remotes`);
51
+ const devServeApps = new Set(!devRemotes
52
+ ? []
53
+ : Array.isArray(devRemotes)
54
+ ? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
55
+ : (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
56
+ const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
57
+ const devServeRemotes = knownRemotes.filter((r) => devServeApps.has(r));
58
+ const remotePorts = devServeRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
59
+ return {
60
+ staticRemotes,
61
+ devRemotes: devServeRemotes,
62
+ remotePorts,
63
+ };
64
+ }
65
+ exports.getRemotes = getRemotes;
66
+ function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
67
+ const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
68
+ const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
69
+ let moduleFederationConfigPath = moduleFederationConfigPathJS;
70
+ // create a no-op so this can be called with issue
71
+ const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
72
+ ? tsconfigPath
73
+ : (0, path_1.join)(workspaceRoot, tsconfigPath);
74
+ let cleanupTranspiler = () => { };
75
+ if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
76
+ cleanupTranspiler = (0, internal_1.registerTsProject)(fullTSconfigPath);
77
+ moduleFederationConfigPath = moduleFederationConfigPathTS;
78
+ }
79
+ try {
80
+ const config = require(moduleFederationConfigPath);
81
+ cleanupTranspiler();
82
+ return config.default || config;
83
+ }
84
+ catch {
85
+ throw new Error(`Could not load ${moduleFederationConfigPath}. Was this project generated with "@nx/${pluginName}:host"?\nSee: https://nx.dev/concepts/more-concepts/faster-builds-with-module-federation`);
86
+ }
87
+ }
88
+ exports.getModuleFederationConfig = getModuleFederationConfig;
@@ -0,0 +1,6 @@
1
+ export * from './share';
2
+ export * from './dependencies';
3
+ export * from './package-json';
4
+ export * from './remotes';
5
+ export * from './models';
6
+ export * from './get-remotes-for-host';
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./share"), exports);
5
+ tslib_1.__exportStar(require("./dependencies"), exports);
6
+ tslib_1.__exportStar(require("./package-json"), exports);
7
+ tslib_1.__exportStar(require("./remotes"), exports);
8
+ tslib_1.__exportStar(require("./models"), exports);
9
+ tslib_1.__exportStar(require("./get-remotes-for-host"), exports);
@@ -0,0 +1,39 @@
1
+ import type { NormalModuleReplacementPlugin } from 'webpack';
2
+ export type ModuleFederationLibrary = {
3
+ type: string;
4
+ name: string;
5
+ };
6
+ export type WorkspaceLibrary = {
7
+ name: string;
8
+ root: string;
9
+ importKey: string | undefined;
10
+ };
11
+ export type SharedWorkspaceLibraryConfig = {
12
+ getAliases: () => Record<string, string>;
13
+ getLibraries: (projectRoot: string, eager?: boolean) => Record<string, SharedLibraryConfig>;
14
+ getReplacementPlugin: () => NormalModuleReplacementPlugin;
15
+ };
16
+ export type Remotes = Array<string | [remoteName: string, remoteUrl: string]>;
17
+ export interface SharedLibraryConfig {
18
+ singleton?: boolean;
19
+ strictVersion?: boolean;
20
+ requiredVersion?: false | string;
21
+ eager?: boolean;
22
+ }
23
+ export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
24
+ export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
25
+ libraryName: string;
26
+ sharedConfig: SharedLibraryConfig;
27
+ }>;
28
+ export interface ModuleFederationConfig {
29
+ name: string;
30
+ remotes?: Remotes;
31
+ library?: ModuleFederationLibrary;
32
+ exposes?: Record<string, string>;
33
+ shared?: SharedFunction;
34
+ additionalShared?: AdditionalSharedConfig;
35
+ }
36
+ export type WorkspaceLibrarySecondaryEntryPoint = {
37
+ name: string;
38
+ path: string;
39
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ export declare function readRootPackageJson(): {
2
+ dependencies?: {
3
+ [key: string]: string;
4
+ };
5
+ devDependencies?: {
6
+ [key: string]: string;
7
+ };
8
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRootPackageJson = void 0;
4
+ const fs_1 = require("fs");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function readRootPackageJson() {
7
+ const pkgJsonPath = (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, 'package.json');
8
+ if (!(0, fs_1.existsSync)(pkgJsonPath)) {
9
+ throw new Error('NX MF: Could not find root package.json to determine dependency versions.');
10
+ }
11
+ return (0, devkit_1.readJsonFile)(pkgJsonPath);
12
+ }
13
+ exports.readRootPackageJson = readRootPackageJson;
@@ -0,0 +1,6 @@
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
+ export { ModuleFederationConfig, SharedLibraryConfig, SharedWorkspaceLibraryConfig, AdditionalSharedConfig, WorkspaceLibrary, SharedFunction, WorkspaceLibrarySecondaryEntryPoint, Remotes, ModuleFederationLibrary, applySharedFunction, applyAdditionalShared, getNpmPackageSharedConfig, shareWorkspaceLibraries, sharePackages, mapRemotes, mapRemotesForSSR, getDependentPackagesForProject, readRootPackageJson, };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readRootPackageJson = exports.getDependentPackagesForProject = exports.mapRemotesForSSR = exports.mapRemotes = exports.sharePackages = exports.shareWorkspaceLibraries = exports.getNpmPackageSharedConfig = exports.applyAdditionalShared = exports.applySharedFunction = 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; } });
@@ -0,0 +1,19 @@
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, isRemoteGlobal?: boolean): 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>;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mapRemotesForSSR = exports.mapRemotes = void 0;
4
+ const path_1 = require("path");
5
+ /**
6
+ * Map remote names to a format that can be understood and used by Module
7
+ * Federation.
8
+ *
9
+ * @param remotes - The remotes to map
10
+ * @param remoteEntryExt - The file extension of the remoteEntry file
11
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
12
+ */
13
+ function mapRemotes(remotes, remoteEntryExt, determineRemoteUrl, isRemoteGlobal = false) {
14
+ const mappedRemotes = {};
15
+ for (const remote of remotes) {
16
+ if (Array.isArray(remote)) {
17
+ mappedRemotes[remote[0]] = handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal);
18
+ }
19
+ else if (typeof remote === 'string') {
20
+ mappedRemotes[remote] = handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal);
21
+ }
22
+ }
23
+ return mappedRemotes;
24
+ }
25
+ exports.mapRemotes = mapRemotes;
26
+ // Helper function to deal with remotes that are arrays
27
+ function handleArrayRemote(remote, remoteEntryExt, isRemoteGlobal) {
28
+ const [remoteName, remoteLocation] = remote;
29
+ const remoteLocationExt = (0, path_1.extname)(remoteLocation);
30
+ // If remote location already has .js or .mjs extension
31
+ if (['.js', '.mjs'].includes(remoteLocationExt)) {
32
+ return remoteLocation;
33
+ }
34
+ const baseRemote = remoteLocation.endsWith('/')
35
+ ? remoteLocation.slice(0, -1)
36
+ : remoteLocation;
37
+ const globalPrefix = isRemoteGlobal
38
+ ? `${remoteName.replace(/-/g, '_')}@`
39
+ : '';
40
+ // if the remote is defined with anything other than http then we assume it's a promise based remote
41
+ // In that case we should use what the user provides as the remote location
42
+ if (!remoteLocation.startsWith('promise new Promise')) {
43
+ return `${globalPrefix}${baseRemote}/remoteEntry.${remoteEntryExt}`;
44
+ }
45
+ else {
46
+ return remoteLocation;
47
+ }
48
+ }
49
+ // Helper function to deal with remotes that are strings
50
+ function handleStringRemote(remote, determineRemoteUrl, isRemoteGlobal) {
51
+ const globalPrefix = isRemoteGlobal ? `${remote.replace(/-/g, '_')}@` : '';
52
+ return `${globalPrefix}${determineRemoteUrl(remote)}`;
53
+ }
54
+ /**
55
+ * Map remote names to a format that can be understood and used by Module
56
+ * Federation.
57
+ *
58
+ * @param remotes - The remotes to map
59
+ * @param remoteEntryExt - The file extension of the remoteEntry file
60
+ * @param determineRemoteUrl - The function used to lookup the URL of the served remote
61
+ */
62
+ function mapRemotesForSSR(remotes, remoteEntryExt, determineRemoteUrl) {
63
+ const mappedRemotes = {};
64
+ for (const remote of remotes) {
65
+ if (Array.isArray(remote)) {
66
+ const [remoteName, remoteLocation] = remote;
67
+ const remoteLocationExt = (0, path_1.extname)(remoteLocation);
68
+ mappedRemotes[remoteName] = `${remoteName}@${['.js', '.mjs'].includes(remoteLocationExt)
69
+ ? remoteLocation
70
+ : `${remoteLocation.endsWith('/')
71
+ ? remoteLocation.slice(0, -1)
72
+ : remoteLocation}/remoteEntry.${remoteEntryExt}`}`;
73
+ }
74
+ else if (typeof remote === 'string') {
75
+ mappedRemotes[remote] = `${remote}@${determineRemoteUrl(remote)}`;
76
+ }
77
+ }
78
+ return mappedRemotes;
79
+ }
80
+ exports.mapRemotesForSSR = mapRemotesForSSR;
@@ -0,0 +1,12 @@
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;