@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,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectPackageSecondaryEntryPoints = exports.recursivelyCollectSecondaryEntryPointsFromDirectory = exports.getNonNodeModulesSubDirs = exports.collectWorkspaceLibrarySecondaryEntryPoints = void 0;
4
+ const path_1 = require("path");
5
+ const fs_1 = require("fs");
6
+ const devkit_1 = require("@nx/devkit");
7
+ const nx_1 = require("@nx/devkit/nx");
8
+ let { readModulePackageJson } = (0, nx_1.requireNx)();
9
+ // TODO: Remove this in Nx 19 when Nx 16.7.0 is no longer supported
10
+ readModulePackageJson =
11
+ readModulePackageJson ??
12
+ require('nx/src/utils/package-json').readModulePackageJson;
13
+ function collectWorkspaceLibrarySecondaryEntryPoints(library, tsconfigPathAliases) {
14
+ const libraryRoot = (0, path_1.join)(devkit_1.workspaceRoot, library.root);
15
+ const needsSecondaryEntryPointsCollected = (0, fs_1.existsSync)((0, path_1.join)(libraryRoot, 'ng-package.json'));
16
+ const secondaryEntryPoints = [];
17
+ if (needsSecondaryEntryPointsCollected) {
18
+ const tsConfigAliasesForLibWithSecondaryEntryPoints = Object.entries(tsconfigPathAliases).reduce((acc, [tsKey, tsPaths]) => {
19
+ if (!tsKey.startsWith(library.importKey)) {
20
+ return { ...acc };
21
+ }
22
+ if (tsPaths.some((path) => path.startsWith(`${library.root}/`))) {
23
+ acc = { ...acc, [tsKey]: tsPaths };
24
+ }
25
+ return acc;
26
+ }, {});
27
+ for (const [alias] of Object.entries(tsConfigAliasesForLibWithSecondaryEntryPoints)) {
28
+ const pathToLib = (0, path_1.dirname)((0, path_1.join)(devkit_1.workspaceRoot, tsconfigPathAliases[alias][0]));
29
+ let searchDir = pathToLib;
30
+ while (searchDir !== libraryRoot) {
31
+ if ((0, fs_1.existsSync)((0, path_1.join)(searchDir, 'ng-package.json'))) {
32
+ secondaryEntryPoints.push({ name: alias, path: pathToLib });
33
+ break;
34
+ }
35
+ searchDir = (0, path_1.dirname)(searchDir);
36
+ }
37
+ }
38
+ }
39
+ return secondaryEntryPoints;
40
+ }
41
+ exports.collectWorkspaceLibrarySecondaryEntryPoints = collectWorkspaceLibrarySecondaryEntryPoints;
42
+ function getNonNodeModulesSubDirs(directory) {
43
+ return (0, fs_1.readdirSync)(directory)
44
+ .filter((file) => file !== 'node_modules')
45
+ .map((file) => (0, path_1.join)(directory, file))
46
+ .filter((file) => (0, fs_1.lstatSync)(file).isDirectory());
47
+ }
48
+ exports.getNonNodeModulesSubDirs = getNonNodeModulesSubDirs;
49
+ function recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, directories, collectedPackages) {
50
+ for (const directory of directories) {
51
+ const packageJsonPath = (0, path_1.join)(directory, 'package.json');
52
+ const relativeEntryPointPath = (0, path_1.relative)(pkgRoot, directory);
53
+ const entryPointName = (0, devkit_1.joinPathFragments)(pkgName, relativeEntryPointPath);
54
+ if ((0, fs_1.existsSync)(packageJsonPath)) {
55
+ try {
56
+ // require the secondary entry point to try to rule out sample code
57
+ require.resolve(entryPointName, { paths: [devkit_1.workspaceRoot] });
58
+ const { name } = (0, devkit_1.readJsonFile)(packageJsonPath);
59
+ // further check to make sure what we were able to require is the
60
+ // same as the package name
61
+ if (name === entryPointName) {
62
+ collectedPackages.push({ name, version: pkgVersion });
63
+ }
64
+ }
65
+ catch { }
66
+ }
67
+ else if (mainEntryPointExports) {
68
+ // if the package.json doesn't exist, check if the directory is
69
+ // exported by the main entry point
70
+ const entryPointExportKey = `./${relativeEntryPointPath}`;
71
+ const entryPointInfo = mainEntryPointExports[entryPointExportKey];
72
+ if (entryPointInfo) {
73
+ collectedPackages.push({
74
+ name: entryPointName,
75
+ version: pkgVersion,
76
+ });
77
+ }
78
+ }
79
+ const subDirs = getNonNodeModulesSubDirs(directory);
80
+ recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pkgRoot, mainEntryPointExports, subDirs, collectedPackages);
81
+ }
82
+ }
83
+ exports.recursivelyCollectSecondaryEntryPointsFromDirectory = recursivelyCollectSecondaryEntryPointsFromDirectory;
84
+ function collectPackageSecondaryEntryPoints(pkgName, pkgVersion, collectedPackages) {
85
+ let pathToPackage;
86
+ let packageJsonPath;
87
+ let packageJson;
88
+ try {
89
+ ({ path: packageJsonPath, packageJson } = readModulePackageJson(pkgName));
90
+ pathToPackage = (0, path_1.dirname)(packageJsonPath);
91
+ }
92
+ catch {
93
+ // the package.json might not resolve if the package has the "exports"
94
+ // entry and is not exporting the package.json file, fall back to trying
95
+ // to find it from the top-level node_modules
96
+ pathToPackage = (0, path_1.join)(devkit_1.workspaceRoot, 'node_modules', pkgName);
97
+ packageJsonPath = (0, path_1.join)(pathToPackage, 'package.json');
98
+ if (!(0, fs_1.existsSync)(packageJsonPath)) {
99
+ // might not exist if it's nested in another package, just return here
100
+ return;
101
+ }
102
+ packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
103
+ }
104
+ const { exports } = packageJson;
105
+ const subDirs = getNonNodeModulesSubDirs(pathToPackage);
106
+ recursivelyCollectSecondaryEntryPointsFromDirectory(pkgName, pkgVersion, pathToPackage, exports, subDirs, collectedPackages);
107
+ }
108
+ exports.collectPackageSecondaryEntryPoints = collectPackageSecondaryEntryPoints;
@@ -0,0 +1,48 @@
1
+ import type { SharedLibraryConfig, SharedWorkspaceLibraryConfig, WorkspaceLibrary } from './models';
2
+ import { AdditionalSharedConfig, SharedFunction } from './models';
3
+ import { type ProjectGraph } from '@nx/devkit';
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;
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyAdditionalShared = exports.applySharedFunction = exports.sharePackages = exports.getNpmPackageSharedConfig = exports.shareWorkspaceLibraries = void 0;
4
+ const path_1 = require("path");
5
+ const package_json_1 = require("./package-json");
6
+ const typescript_1 = require("./typescript");
7
+ const secondary_entry_points_1 = require("./secondary-entry-points");
8
+ const devkit_1 = require("@nx/devkit");
9
+ const fs_1 = require("fs");
10
+ /**
11
+ * Build an object of functions to be used with the ModuleFederationPlugin to
12
+ * share Nx Workspace Libraries between Hosts and Remotes.
13
+ *
14
+ * @param workspaceLibs - The Nx Workspace Libraries to share
15
+ * @param tsConfigPath - The path to TS Config File that contains the Path Mappings for the Libraries
16
+ */
17
+ function shareWorkspaceLibraries(workspaceLibs, tsConfigPath = process.env.NX_TSCONFIG_PATH ?? (0, typescript_1.getRootTsConfigPath)()) {
18
+ if (!workspaceLibs) {
19
+ return getEmptySharedLibrariesConfig();
20
+ }
21
+ const tsconfigPathAliases = (0, typescript_1.readTsPathMappings)(tsConfigPath);
22
+ if (!Object.keys(tsconfigPathAliases).length) {
23
+ return getEmptySharedLibrariesConfig();
24
+ }
25
+ const pathMappings = [];
26
+ for (const [key, paths] of Object.entries(tsconfigPathAliases)) {
27
+ const library = workspaceLibs.find((lib) => lib.importKey === key);
28
+ if (!library) {
29
+ continue;
30
+ }
31
+ // This is for Angular Projects that use ng-package.json
32
+ // It will do nothing for React Projects
33
+ (0, secondary_entry_points_1.collectWorkspaceLibrarySecondaryEntryPoints)(library, tsconfigPathAliases).forEach(({ name, path }) => pathMappings.push({
34
+ name,
35
+ path,
36
+ }));
37
+ pathMappings.push({
38
+ name: key,
39
+ path: (0, path_1.normalize)((0, path_1.join)(devkit_1.workspaceRoot, paths[0])),
40
+ });
41
+ }
42
+ const webpack = require('webpack');
43
+ return {
44
+ getAliases: () => pathMappings.reduce((aliases, library) => ({ ...aliases, [library.name]: library.path }), {}),
45
+ getLibraries: (projectRoot, eager) => {
46
+ let pkgJson = null;
47
+ if (projectRoot &&
48
+ (0, fs_1.existsSync)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'))) {
49
+ pkgJson = (0, devkit_1.readJsonFile)((0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot, 'package.json'));
50
+ }
51
+ return pathMappings.reduce((libraries, library) => {
52
+ // Check to see if the library version is declared in the app's package.json
53
+ let version = pkgJson?.dependencies?.[library.name];
54
+ if (!version && workspaceLibs.length > 0) {
55
+ const workspaceLib = workspaceLibs.find((lib) => lib.importKey === library.name);
56
+ const libPackageJsonPath = workspaceLib
57
+ ? (0, path_1.join)(workspaceLib.root, 'package.json')
58
+ : null;
59
+ if (libPackageJsonPath && (0, fs_1.existsSync)(libPackageJsonPath)) {
60
+ pkgJson = (0, devkit_1.readJsonFile)(libPackageJsonPath);
61
+ if (pkgJson) {
62
+ version = pkgJson.version;
63
+ }
64
+ }
65
+ }
66
+ return {
67
+ ...libraries,
68
+ [library.name]: {
69
+ ...(version
70
+ ? {
71
+ requiredVersion: version,
72
+ singleton: true,
73
+ }
74
+ : { requiredVersion: false }),
75
+ eager,
76
+ },
77
+ };
78
+ }, {});
79
+ },
80
+ getReplacementPlugin: () => new webpack.NormalModuleReplacementPlugin(/./, (req) => {
81
+ if (!req.request.startsWith('.')) {
82
+ return;
83
+ }
84
+ const from = req.context;
85
+ const to = (0, path_1.normalize)((0, path_1.join)(req.context, req.request));
86
+ for (const library of pathMappings) {
87
+ const libFolder = (0, path_1.normalize)((0, path_1.dirname)(library.path));
88
+ if (!from.startsWith(libFolder) && to.startsWith(libFolder)) {
89
+ req.request = library.name;
90
+ }
91
+ }
92
+ }),
93
+ };
94
+ }
95
+ exports.shareWorkspaceLibraries = shareWorkspaceLibraries;
96
+ /**
97
+ * Build the Module Federation Share Config for a specific package and the
98
+ * specified version of that package.
99
+ * @param pkgName - Name of the package to share
100
+ * @param version - Version of the package to require by other apps in the Module Federation setup
101
+ */
102
+ function getNpmPackageSharedConfig(pkgName, version) {
103
+ if (!version) {
104
+ devkit_1.logger.warn(`Could not find a version for "${pkgName}" in the root "package.json" ` +
105
+ 'when collecting shared packages for the Module Federation setup. ' +
106
+ 'The package will not be shared.');
107
+ return undefined;
108
+ }
109
+ return { singleton: true, strictVersion: true, requiredVersion: version };
110
+ }
111
+ exports.getNpmPackageSharedConfig = getNpmPackageSharedConfig;
112
+ /**
113
+ * Create a dictionary of packages and their Module Federation Shared Config
114
+ * from an array of package names.
115
+ *
116
+ * Lookup the versions of the packages from the root package.json file in the
117
+ * workspace.
118
+ * @param packages - Array of package names as strings
119
+ */
120
+ function sharePackages(packages) {
121
+ const pkgJson = (0, package_json_1.readRootPackageJson)();
122
+ const allPackages = [];
123
+ packages.forEach((pkg) => {
124
+ const pkgVersion = pkgJson.dependencies?.[pkg] ?? pkgJson.devDependencies?.[pkg];
125
+ allPackages.push({ name: pkg, version: pkgVersion });
126
+ (0, secondary_entry_points_1.collectPackageSecondaryEntryPoints)(pkg, pkgVersion, allPackages);
127
+ });
128
+ return allPackages.reduce((shared, pkg) => {
129
+ const config = getNpmPackageSharedConfig(pkg.name, pkg.version);
130
+ if (config) {
131
+ shared[pkg.name] = config;
132
+ }
133
+ return shared;
134
+ }, {});
135
+ }
136
+ exports.sharePackages = sharePackages;
137
+ /**
138
+ * Apply a custom function provided by the user that will modify the Shared Config
139
+ * of the dependencies for the Module Federation build.
140
+ *
141
+ * @param sharedConfig - The original Shared Config to be modified
142
+ * @param sharedFn - The custom function to run
143
+ */
144
+ function applySharedFunction(sharedConfig, sharedFn) {
145
+ if (!sharedFn) {
146
+ return;
147
+ }
148
+ for (const [libraryName, library] of Object.entries(sharedConfig)) {
149
+ const mappedDependency = sharedFn(libraryName, library);
150
+ if (mappedDependency === false) {
151
+ delete sharedConfig[libraryName];
152
+ continue;
153
+ }
154
+ else if (!mappedDependency) {
155
+ continue;
156
+ }
157
+ sharedConfig[libraryName] = mappedDependency;
158
+ }
159
+ }
160
+ exports.applySharedFunction = applySharedFunction;
161
+ /**
162
+ * Add additional dependencies to the shared package that may not have been
163
+ * discovered by the project graph.
164
+ *
165
+ * This can be useful for applications that use a Dependency Injection system
166
+ * that expects certain Singleton values to be present in the shared injection
167
+ * hierarchy.
168
+ *
169
+ * @param sharedConfig - The original Shared Config
170
+ * @param additionalShared - The additional dependencies to add
171
+ * @param projectGraph - The Nx project graph
172
+ */
173
+ function applyAdditionalShared(sharedConfig, additionalShared, projectGraph) {
174
+ if (!additionalShared) {
175
+ return;
176
+ }
177
+ for (const shared of additionalShared) {
178
+ if (typeof shared === 'string') {
179
+ addStringDependencyToSharedConfig(sharedConfig, shared, projectGraph);
180
+ }
181
+ else if (Array.isArray(shared)) {
182
+ sharedConfig[shared[0]] = shared[1];
183
+ }
184
+ else if (typeof shared === 'object') {
185
+ sharedConfig[shared.libraryName] = shared.sharedConfig;
186
+ }
187
+ }
188
+ }
189
+ exports.applyAdditionalShared = applyAdditionalShared;
190
+ function addStringDependencyToSharedConfig(sharedConfig, dependency, projectGraph) {
191
+ if (projectGraph.nodes[dependency]) {
192
+ sharedConfig[dependency] = { requiredVersion: false };
193
+ }
194
+ else if (projectGraph.externalNodes?.[`npm:${dependency}`]) {
195
+ const pkgJson = (0, package_json_1.readRootPackageJson)();
196
+ const config = getNpmPackageSharedConfig(dependency, pkgJson.dependencies?.[dependency] ??
197
+ pkgJson.devDependencies?.[dependency]);
198
+ if (!config) {
199
+ return;
200
+ }
201
+ sharedConfig[dependency] = config;
202
+ }
203
+ else {
204
+ throw new Error(`The specified dependency "${dependency}" in the additionalShared configuration does not exist in the project graph. ` +
205
+ `Please check your additionalShared configuration and make sure you are including valid workspace projects or npm packages.`);
206
+ }
207
+ }
208
+ function getEmptySharedLibrariesConfig() {
209
+ const webpack = require('webpack');
210
+ return {
211
+ getAliases: () => ({}),
212
+ getLibraries: () => ({}),
213
+ getReplacementPlugin: () => new webpack.NormalModuleReplacementPlugin(/./, () => { }),
214
+ };
215
+ }
@@ -0,0 +1,4 @@
1
+ import { ParsedCommandLine } from 'typescript';
2
+ export declare function readTsPathMappings(tsConfigPath?: string): ParsedCommandLine['options']['paths'];
3
+ export declare function readTsConfig(tsConfigPath: string): ParsedCommandLine;
4
+ export declare function getRootTsConfigPath(): string | null;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootTsConfigPath = exports.readTsConfig = exports.readTsPathMappings = void 0;
4
+ const fs_1 = require("fs");
5
+ const path_1 = require("path");
6
+ const devkit_1 = require("@nx/devkit");
7
+ let tsConfig = new Map();
8
+ let tsPathMappings = new Map();
9
+ function readTsPathMappings(tsConfigPath = process.env.NX_TSCONFIG_PATH ?? getRootTsConfigPath()) {
10
+ if (tsPathMappings.has(tsConfigPath)) {
11
+ return tsPathMappings.get(tsConfigPath);
12
+ }
13
+ if (!tsConfig.has(tsConfigPath)) {
14
+ tsConfig.set(tsConfigPath, readTsConfiguration(tsConfigPath));
15
+ }
16
+ tsPathMappings.set(tsConfigPath, {});
17
+ Object.entries(tsConfig.get(tsConfigPath).options?.paths ?? {}).forEach(([alias, paths]) => {
18
+ tsPathMappings.set(tsConfigPath, {
19
+ ...tsPathMappings.get(tsConfigPath),
20
+ [alias]: paths.map((path) => path.replace(/^\.\//, '')),
21
+ });
22
+ });
23
+ return tsPathMappings.get(tsConfigPath);
24
+ }
25
+ exports.readTsPathMappings = readTsPathMappings;
26
+ function readTsConfiguration(tsConfigPath) {
27
+ if (!(0, fs_1.existsSync)(tsConfigPath)) {
28
+ throw new Error(`NX MF: TsConfig Path for workspace libraries does not exist! (${tsConfigPath}).`);
29
+ }
30
+ return readTsConfig(tsConfigPath);
31
+ }
32
+ let tsModule;
33
+ function readTsConfig(tsConfigPath) {
34
+ if (!tsModule) {
35
+ tsModule = require('typescript');
36
+ }
37
+ const readResult = tsModule.readConfigFile(tsConfigPath, tsModule.sys.readFile);
38
+ return tsModule.parseJsonConfigFileContent(readResult.config, tsModule.sys, (0, path_1.dirname)(tsConfigPath));
39
+ }
40
+ exports.readTsConfig = readTsConfig;
41
+ function getRootTsConfigPath() {
42
+ const tsConfigFileName = getRootTsConfigFileName();
43
+ return tsConfigFileName ? (0, path_1.join)(devkit_1.workspaceRoot, tsConfigFileName) : null;
44
+ }
45
+ exports.getRootTsConfigPath = getRootTsConfigPath;
46
+ function getRootTsConfigFileName() {
47
+ for (const tsConfigName of ['tsconfig.base.json', 'tsconfig.json']) {
48
+ const tsConfigPath = (0, path_1.join)(devkit_1.workspaceRoot, tsConfigName);
49
+ if ((0, fs_1.existsSync)(tsConfigPath)) {
50
+ return tsConfigName;
51
+ }
52
+ }
53
+ return null;
54
+ }
@@ -0,0 +1,5 @@
1
+ import { Observable } from 'rxjs';
2
+ export declare function runWebpackDevServer(config: any, webpack: typeof import('webpack'), WebpackDevServer: typeof import('webpack-dev-server')): Observable<{
3
+ stats: any;
4
+ baseUrl: string;
5
+ }>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runWebpackDevServer = void 0;
4
+ const rxjs_1 = require("rxjs");
5
+ function runWebpackDevServer(config, webpack, WebpackDevServer) {
6
+ return new rxjs_1.Observable((subscriber) => {
7
+ const webpackCompiler = webpack(config);
8
+ let baseUrl;
9
+ webpackCompiler.hooks.done.tap('build-webpack', (stats) => {
10
+ subscriber.next({ stats, baseUrl });
11
+ });
12
+ const devServerConfig = config.devServer || {};
13
+ const originalOnListen = devServerConfig.onListening;
14
+ devServerConfig.onListening = function (server) {
15
+ if (typeof originalOnListen === 'function') {
16
+ originalOnListen(server);
17
+ }
18
+ const devServerOptions = server.options;
19
+ baseUrl = `${server.options.https ? 'https' : 'http'}://${server.options.host}:${server.options.port}${devServerOptions.devMiddleware.publicPath}`;
20
+ };
21
+ const webpackServer = new WebpackDevServer(devServerConfig, webpackCompiler);
22
+ try {
23
+ webpackServer.start().catch((err) => subscriber.error(err));
24
+ return () => webpackServer.stop();
25
+ }
26
+ catch (e) {
27
+ throw new Error('Could not start start dev server');
28
+ }
29
+ });
30
+ }
31
+ exports.runWebpackDevServer = runWebpackDevServer;
@@ -0,0 +1,8 @@
1
+ export declare const nxVersion: any;
2
+ export declare const swcLoaderVersion = "0.1.15";
3
+ export declare const tsLibVersion = "^2.3.0";
4
+ export declare const webpackCliVersion = "^5.1.4";
5
+ export declare const reactRefreshWebpackPluginVersion = "^0.5.7";
6
+ export declare const svgrWebpackVersion = "^8.0.1";
7
+ export declare const reactRefreshVersion = "^0.10.0";
8
+ export declare const urlLoaderVersion = "^4.1.1";
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.urlLoaderVersion = exports.reactRefreshVersion = exports.svgrWebpackVersion = exports.reactRefreshWebpackPluginVersion = exports.webpackCliVersion = exports.tsLibVersion = exports.swcLoaderVersion = exports.nxVersion = void 0;
4
+ exports.nxVersion = require('../../package.json').version;
5
+ exports.swcLoaderVersion = '0.1.15';
6
+ exports.tsLibVersion = '^2.3.0';
7
+ exports.webpackCliVersion = '^5.1.4';
8
+ // React apps
9
+ exports.reactRefreshWebpackPluginVersion = '^0.5.7';
10
+ exports.svgrWebpackVersion = '^8.0.1';
11
+ exports.reactRefreshVersion = '^0.10.0';
12
+ exports.urlLoaderVersion = '^4.1.1';
File without changes
@@ -0,0 +1,17 @@
1
+ module.exports = require('babel-loader').custom(() => {
2
+ return {
3
+ customOptions({ isTest, isModern, emitDecoratorMetadata, ...loader }) {
4
+ return {
5
+ custom: { isTest, isModern, emitDecoratorMetadata },
6
+ loader,
7
+ };
8
+ },
9
+ config(cfg, { customOptions: { isTest, isModern, emitDecoratorMetadata } }) {
10
+ // Add hint to our babel preset so it can handle modern vs legacy bundles.
11
+ cfg.options.caller.isModern = isModern;
12
+ cfg.options.caller.isTest = isTest;
13
+ cfg.options.caller.emitDecoratorMetadata = emitDecoratorMetadata;
14
+ return cfg.options;
15
+ },
16
+ };
17
+ });
@@ -0,0 +1 @@
1
+ export default function (source: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ // @ts-ignore
5
+ const stylusLoader = require("stylus-loader");
6
+ // TOOD(v19): Remove this file and stylus support.
7
+ function default_1(source) {
8
+ devkit_1.logger.warn(`Stylus is support is deprecated and will be removed in Nx 19. We recommend that you migrate to Sass by renaming \`.styl\` files to \`.scss\` and ensuring that the content is valid Sass.`);
9
+ return stylusLoader.call(this, source);
10
+ }
11
+ exports.default = default_1;
@@ -0,0 +1 @@
1
+ export declare function interpolateEnvironmentVariablesToIndex(contents: string, deployUrl?: string): string;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.interpolateEnvironmentVariablesToIndex = void 0;
4
+ function interpolateEnvironmentVariablesToIndex(contents, deployUrl) {
5
+ const environmentVariables = getClientEnvironment(deployUrl || '');
6
+ return interpolateEnvironmentVariables(contents, environmentVariables);
7
+ }
8
+ exports.interpolateEnvironmentVariablesToIndex = interpolateEnvironmentVariablesToIndex;
9
+ const NX_PREFIX = /^NX_/i;
10
+ function isNxEnvironmentKey(x) {
11
+ return NX_PREFIX.test(x);
12
+ }
13
+ function getClientEnvironment(deployUrl) {
14
+ return Object.keys(process.env)
15
+ .filter(isNxEnvironmentKey)
16
+ .reduce((env, key) => {
17
+ env[key] = process.env[key];
18
+ return env;
19
+ }, {
20
+ NODE_ENV: process.env.NODE_ENV || 'development',
21
+ DEPLOY_URL: deployUrl || process.env.DEPLOY_URL || '',
22
+ });
23
+ }
24
+ function interpolateEnvironmentVariables(documentContents, environmentVariables) {
25
+ let temp = documentContents;
26
+ for (const [key, value] of Object.entries(environmentVariables)) {
27
+ temp = temp.replace(new RegExp(`%${key}%`, 'g'), value);
28
+ }
29
+ return temp;
30
+ }
@@ -0,0 +1,2 @@
1
+ import { ExtraEntryPoint, NormalizedEntryPoint } from '../models';
2
+ export declare function normalizeExtraEntryPoints(extraEntryPoints: ExtraEntryPoint[], defaultBundleName: string): NormalizedEntryPoint[];
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeExtraEntryPoints = void 0;
4
+ function normalizeExtraEntryPoints(extraEntryPoints, defaultBundleName) {
5
+ return extraEntryPoints.map((entry) => {
6
+ let normalizedEntry;
7
+ if (typeof entry === 'string') {
8
+ normalizedEntry = {
9
+ input: entry,
10
+ inject: true,
11
+ bundleName: defaultBundleName,
12
+ };
13
+ }
14
+ else {
15
+ const { inject = true, ...newEntry } = entry;
16
+ let bundleName;
17
+ if (entry.bundleName) {
18
+ bundleName = entry.bundleName;
19
+ }
20
+ else {
21
+ bundleName = defaultBundleName;
22
+ }
23
+ normalizedEntry = { ...newEntry, bundleName };
24
+ }
25
+ return normalizedEntry;
26
+ });
27
+ }
28
+ exports.normalizeExtraEntryPoints = normalizeExtraEntryPoints;
@@ -0,0 +1,5 @@
1
+ import { ExtraEntryPoint } from '../models';
2
+ export declare function generateEntryPoints(appConfig: {
3
+ styles: ExtraEntryPoint[];
4
+ scripts: ExtraEntryPoint[];
5
+ }): string[];
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateEntryPoints = void 0;
4
+ const normalize_entry_1 = require("./normalize-entry");
5
+ function generateEntryPoints(appConfig) {
6
+ // Add all styles/scripts, except lazy-loaded ones.
7
+ const extraEntryPoints = (extraEntryPoints, defaultBundleName) => {
8
+ const entryPoints = (0, normalize_entry_1.normalizeExtraEntryPoints)(extraEntryPoints, defaultBundleName).map((entry) => entry.bundleName);
9
+ // remove duplicates
10
+ return [...new Set(entryPoints)];
11
+ };
12
+ const entryPoints = [
13
+ 'runtime',
14
+ 'polyfills',
15
+ 'sw-register',
16
+ ...extraEntryPoints(appConfig.styles, 'styles'),
17
+ ...extraEntryPoints(appConfig.scripts, 'scripts'),
18
+ 'vendor',
19
+ 'main',
20
+ ];
21
+ const duplicates = [
22
+ ...new Set(entryPoints.filter((x) => entryPoints.indexOf(x) !== entryPoints.lastIndexOf(x))),
23
+ ];
24
+ if (duplicates.length > 0) {
25
+ throw new Error(`Multiple bundles have been named the same: '${duplicates.join(`', '`)}'.`);
26
+ }
27
+ return entryPoints;
28
+ }
29
+ exports.generateEntryPoints = generateEntryPoints;
@@ -0,0 +1,13 @@
1
+ import { LoaderContext } from 'webpack';
2
+ export interface PostcssCliResourcesOptions {
3
+ baseHref?: string;
4
+ deployUrl?: string;
5
+ resourcesOutputPath?: string;
6
+ rebaseRootRelative?: boolean;
7
+ filename: string;
8
+ loader: LoaderContext<unknown>;
9
+ }
10
+ export declare function PostcssCliResources(options: PostcssCliResourcesOptions): {
11
+ postcssPlugin: string;
12
+ Once(root: any): Promise<void[]>;
13
+ };