@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
|
@@ -15,6 +15,7 @@ exports.determineMain = determineMain;
|
|
|
15
15
|
exports.determineTsConfig = determineTsConfig;
|
|
16
16
|
const devkit_1 = require("@nx/devkit");
|
|
17
17
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
18
|
+
const has_plugin_1 = require("./has-plugin");
|
|
18
19
|
function findExistingTargetsInProject(targets, userProvidedTargets) {
|
|
19
20
|
const output = {
|
|
20
21
|
validFoundTargetName: {},
|
|
@@ -177,82 +178,148 @@ function addOrChangeServeTarget(tree, options, target) {
|
|
|
177
178
|
}
|
|
178
179
|
function writeRspackConfigFile(tree, options, stylePreprocessorOptions) {
|
|
179
180
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
180
|
-
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(options, stylePreprocessorOptions));
|
|
181
|
+
tree.write((0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'), createConfig(tree, { ...options, stylePreprocessorOptions }));
|
|
181
182
|
}
|
|
182
|
-
function createConfig(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
? `
|
|
189
|
-
{
|
|
190
|
-
stylePreprocessorOptions: ${JSON.stringify(stylePreprocessorOptions)},
|
|
191
|
-
}
|
|
192
|
-
`
|
|
193
|
-
: ''}), (config) => {
|
|
194
|
-
return config;
|
|
195
|
-
});
|
|
196
|
-
`;
|
|
183
|
+
function createConfig(tree, options) {
|
|
184
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, options.project);
|
|
185
|
+
const buildOptions = createBuildOptions(tree, options, project);
|
|
186
|
+
const defaultConfig = generateDefaultConfig(project, buildOptions);
|
|
187
|
+
if (isWebFramework(options)) {
|
|
188
|
+
return generateWebConfig(tree, options, defaultConfig);
|
|
197
189
|
}
|
|
198
|
-
else if (options.framework === '
|
|
199
|
-
return
|
|
200
|
-
|
|
190
|
+
else if (options.framework === 'nest') {
|
|
191
|
+
return generateNestConfig(tree, options, project, buildOptions);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
return generateGenericConfig(tree, options, defaultConfig);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function createBuildOptions(tree, options, project) {
|
|
198
|
+
return {
|
|
199
|
+
target: options.target ?? 'web',
|
|
200
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', project.root === '.' ? project.name : project.root),
|
|
201
|
+
main: determineMain(tree, options),
|
|
202
|
+
tsConfig: determineTsConfig(tree, options),
|
|
203
|
+
rspackConfig: (0, devkit_1.joinPathFragments)(project.root, 'rspack.config.js'),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function generateDefaultConfig(project, buildOptions) {
|
|
207
|
+
return `
|
|
208
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
209
|
+
const { join } = require('path');
|
|
201
210
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
|
|
211
|
+
module.exports = {
|
|
212
|
+
output: {
|
|
213
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
214
|
+
},
|
|
215
|
+
plugins: [
|
|
216
|
+
new NxAppRspackPlugin({
|
|
217
|
+
target: '${buildOptions.target}',
|
|
218
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
219
|
+
main: '${buildOptions.main}',
|
|
220
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
221
|
+
})
|
|
222
|
+
]
|
|
223
|
+
}`;
|
|
224
|
+
}
|
|
225
|
+
function isWebFramework(options) {
|
|
226
|
+
return options.framework === 'web' || options.target === 'web';
|
|
227
|
+
}
|
|
228
|
+
function generateWebConfig(tree, options, defaultConfig) {
|
|
229
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
230
|
+
return defaultConfig;
|
|
212
231
|
}
|
|
213
|
-
|
|
232
|
+
return `
|
|
233
|
+
const { composePlugins, withNx, withWeb } = require('@nx/rspack');
|
|
234
|
+
module.exports = composePlugins(withNx(), withWeb(${options.stylePreprocessorOptions
|
|
235
|
+
? `
|
|
236
|
+
{
|
|
237
|
+
stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
|
|
238
|
+
}
|
|
239
|
+
`
|
|
240
|
+
: ''}), (config) => {
|
|
241
|
+
return config;
|
|
242
|
+
});
|
|
243
|
+
`;
|
|
244
|
+
}
|
|
245
|
+
function generateNestConfig(tree, options, project, buildOptions) {
|
|
246
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
214
247
|
return `
|
|
215
|
-
|
|
216
|
-
|
|
248
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
249
|
+
const rspack = require('@rspack/core');
|
|
250
|
+
const { join } = require('path');
|
|
217
251
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
252
|
+
module.exports = {
|
|
253
|
+
output: {
|
|
254
|
+
path: join(__dirname, '${(0, devkit_1.offsetFromRoot)(project.root)}${buildOptions.outputPath}'),
|
|
255
|
+
},
|
|
256
|
+
optimization: {
|
|
257
|
+
minimizer: [
|
|
258
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
259
|
+
minimizerOptions: {
|
|
260
|
+
compress: {
|
|
261
|
+
keep_classnames: true,
|
|
262
|
+
keep_fnames: true,
|
|
263
|
+
},
|
|
264
|
+
mangle: {
|
|
265
|
+
keep_classnames: true,
|
|
266
|
+
keep_fnames: true,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
],
|
|
271
|
+
},
|
|
272
|
+
plugins: [
|
|
273
|
+
new NxAppRspackPlugin({
|
|
274
|
+
target: '${buildOptions.target}',
|
|
275
|
+
tsConfig: '${buildOptions.tsConfig}',
|
|
276
|
+
main: '${buildOptions.main}',
|
|
277
|
+
outputHashing: '${buildOptions.target !== 'web' ? 'none' : 'all'}',
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}`;
|
|
241
281
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
282
|
+
return `
|
|
283
|
+
const { composePlugins, withNx } = require('@nx/rspack');
|
|
284
|
+
const rspack = require('@rspack/core');
|
|
245
285
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
286
|
+
module.exports = composePlugins(withNx(), (config) => {
|
|
287
|
+
config.optimization = {
|
|
288
|
+
minimizer: [
|
|
289
|
+
new rspack.SwcJsMinimizerRspackPlugin({
|
|
290
|
+
minimizerOptions: {
|
|
291
|
+
compress: {
|
|
292
|
+
keep_classnames: true,
|
|
293
|
+
keep_fnames: true,
|
|
294
|
+
},
|
|
295
|
+
mangle: {
|
|
296
|
+
keep_classnames: true,
|
|
297
|
+
keep_fnames: true,
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
}),
|
|
301
|
+
],
|
|
302
|
+
};
|
|
303
|
+
return config;
|
|
304
|
+
});
|
|
305
|
+
`;
|
|
306
|
+
}
|
|
307
|
+
function generateGenericConfig(tree, options, defaultConfig) {
|
|
308
|
+
if ((0, has_plugin_1.hasPlugin)(tree)) {
|
|
309
|
+
return defaultConfig;
|
|
255
310
|
}
|
|
311
|
+
return `
|
|
312
|
+
const { composePlugins, withNx${options.stylePreprocessorOptions ? ', withWeb' : ''} } = require('@nx/rspack');
|
|
313
|
+
|
|
314
|
+
module.exports = composePlugins(withNx()${options.stylePreprocessorOptions
|
|
315
|
+
? `,
|
|
316
|
+
withWeb({
|
|
317
|
+
stylePreprocessorOptions: ${JSON.stringify(options.stylePreprocessorOptions)},
|
|
318
|
+
})`
|
|
319
|
+
: ''}, (config) => {
|
|
320
|
+
return config;
|
|
321
|
+
});
|
|
322
|
+
`;
|
|
256
323
|
}
|
|
257
324
|
function deleteWebpackConfig(tree, projectRoot, webpackConfigFilePath) {
|
|
258
325
|
const webpackConfigPath = webpackConfigFilePath && tree.exists(webpackConfigFilePath)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasPlugin = hasPlugin;
|
|
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/rspack/plugin'
|
|
9
|
+
: p.plugin === '@nx/rspack/plugin');
|
|
10
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ExecutorContext } from '@nx/devkit';
|
|
2
2
|
import { ModuleFederationDevServerOptions } from '../../executors/module-federation-dev-server/schema';
|
|
3
|
-
import type { StaticRemotesConfig } from '
|
|
3
|
+
import type { StaticRemotesConfig } from '@nx/module-federation/src/utils';
|
|
4
4
|
export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
|
package/src/utils/versions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const nxVersion: any;
|
|
2
|
-
export declare const rspackCoreVersion = "1.
|
|
3
|
-
export declare const rspackDevServerVersion = "1.0.
|
|
2
|
+
export declare const rspackCoreVersion = "1.1.2";
|
|
3
|
+
export declare const rspackDevServerVersion = "1.0.9";
|
|
4
4
|
export declare const rspackPluginMinifyVersion = "^0.7.5";
|
|
5
5
|
export declare const rspackPluginReactRefreshVersion = "^1.0.0";
|
|
6
6
|
export declare const lessLoaderVersion = "~11.1.3";
|
package/src/utils/versions.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.eslintPluginReactHooksVersion = exports.eslintPluginReactVersion = exports.eslintPluginJsxA11yVersion = exports.eslintPluginImportVersion = exports.stylusVersion = exports.sassVersion = exports.lessVersion = exports.nestjsMicroservicesVersion = exports.nestjsPlatformExpressVersion = exports.nestjsCoreVersion = exports.nestjsCommonVersion = exports.typesReactDomVersion = exports.typesReactVersion = exports.reactDomVersion = exports.reactRefreshVersion = exports.reactVersion = exports.lessLoaderVersion = exports.rspackPluginReactRefreshVersion = exports.rspackPluginMinifyVersion = exports.rspackDevServerVersion = exports.rspackCoreVersion = exports.nxVersion = void 0;
|
|
4
4
|
exports.nxVersion = require('../../package.json').version;
|
|
5
|
-
exports.rspackCoreVersion = '1.
|
|
6
|
-
exports.rspackDevServerVersion = '1.0.
|
|
5
|
+
exports.rspackCoreVersion = '1.1.2';
|
|
6
|
+
exports.rspackDevServerVersion = '1.0.9';
|
|
7
7
|
exports.rspackPluginMinifyVersion = '^0.7.5';
|
|
8
8
|
exports.rspackPluginReactRefreshVersion = '^1.0.0';
|
|
9
9
|
exports.lessLoaderVersion = '~11.1.3';
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDependentPackagesForProject = getDependentPackagesForProject;
|
|
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
|
-
function collectDependencies(projectGraph, name, dependencies = {
|
|
14
|
-
workspaceLibraries: new Map(),
|
|
15
|
-
npmPackages: new Set(),
|
|
16
|
-
}, seen = new Set()) {
|
|
17
|
-
if (seen.has(name)) {
|
|
18
|
-
return dependencies;
|
|
19
|
-
}
|
|
20
|
-
seen.add(name);
|
|
21
|
-
(projectGraph.dependencies[name] ?? []).forEach((dependency) => {
|
|
22
|
-
if (dependency.target.startsWith('npm:')) {
|
|
23
|
-
dependencies.npmPackages.add(dependency.target.replace('npm:', ''));
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
dependencies.workspaceLibraries.set(dependency.target, {
|
|
27
|
-
name: dependency.target,
|
|
28
|
-
root: projectGraph.nodes[dependency.target].data.root,
|
|
29
|
-
importKey: getLibraryImportPath(dependency.target, projectGraph),
|
|
30
|
-
});
|
|
31
|
-
collectDependencies(projectGraph, dependency.target, dependencies, seen);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return dependencies;
|
|
35
|
-
}
|
|
36
|
-
function getLibraryImportPath(library, projectGraph) {
|
|
37
|
-
let buildLibsFromSource = true;
|
|
38
|
-
if (process.env.NX_BUILD_LIBS_FROM_SOURCE) {
|
|
39
|
-
buildLibsFromSource = process.env.NX_BUILD_LIBS_FROM_SOURCE === 'true';
|
|
40
|
-
}
|
|
41
|
-
const libraryNode = projectGraph.nodes[library];
|
|
42
|
-
let sourceRoots = [libraryNode.data.sourceRoot];
|
|
43
|
-
if (!buildLibsFromSource && process.env.NX_BUILD_TARGET) {
|
|
44
|
-
const buildTarget = (0, devkit_1.parseTargetString)(process.env.NX_BUILD_TARGET, projectGraph);
|
|
45
|
-
sourceRoots = (0, devkit_1.getOutputsForTargetAndConfiguration)(buildTarget, {}, libraryNode);
|
|
46
|
-
}
|
|
47
|
-
const tsConfigPathMappings = (0, typescript_1.readTsPathMappings)();
|
|
48
|
-
for (const [key, value] of Object.entries(tsConfigPathMappings)) {
|
|
49
|
-
for (const src of sourceRoots) {
|
|
50
|
-
if (value.find((path) => path.startsWith(src))) {
|
|
51
|
-
return key;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type ProjectGraph } from '@nx/devkit';
|
|
2
|
-
import { ModuleFederationConfig } from './models';
|
|
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: any[];
|
|
11
|
-
dynamicRemotes: any[];
|
|
12
|
-
remotePorts: any[];
|
|
13
|
-
staticRemotePort: number;
|
|
14
|
-
};
|
|
15
|
-
export declare function getModuleFederationConfig(tsconfigPath: string, workspaceRoot: string, projectRoot: string, pluginName?: 'react' | 'angular'): any;
|
|
16
|
-
export {};
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRemotes = getRemotes;
|
|
4
|
-
exports.getModuleFederationConfig = getModuleFederationConfig;
|
|
5
|
-
const tslib_1 = require("tslib");
|
|
6
|
-
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const internal_1 = require("@nx/js/src/internal");
|
|
8
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
9
|
-
const fs_1 = require("fs");
|
|
10
|
-
const find_matching_projects_1 = require("nx/src/utils/find-matching-projects");
|
|
11
|
-
const path_1 = require("path");
|
|
12
|
-
function extractRemoteProjectsFromConfig(config, pathToManifestFile) {
|
|
13
|
-
const remotes = [];
|
|
14
|
-
const dynamicRemotes = [];
|
|
15
|
-
if (pathToManifestFile && (0, fs_1.existsSync)(pathToManifestFile)) {
|
|
16
|
-
const moduleFederationManifestJson = (0, fs_1.readFileSync)(pathToManifestFile, 'utf-8');
|
|
17
|
-
if (moduleFederationManifestJson) {
|
|
18
|
-
// This should have shape of
|
|
19
|
-
// {
|
|
20
|
-
// "remoteName": "remoteLocation",
|
|
21
|
-
// }
|
|
22
|
-
const parsedManifest = JSON.parse(moduleFederationManifestJson);
|
|
23
|
-
if (Object.keys(parsedManifest).every((key) => typeof key === 'string' && typeof parsedManifest[key] === 'string')) {
|
|
24
|
-
dynamicRemotes.push(...Object.keys(parsedManifest));
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const staticRemotes = config.remotes?.map((r) => (Array.isArray(r) ? r[0] : r)) ?? [];
|
|
29
|
-
remotes.push(...staticRemotes);
|
|
30
|
-
return { remotes, dynamicRemotes };
|
|
31
|
-
}
|
|
32
|
-
function collectRemoteProjects(remote, collected, context) {
|
|
33
|
-
const remoteProject = context.projectGraph.nodes[remote]?.data;
|
|
34
|
-
if (!context.projectGraph.nodes[remote] || collected.has(remote)) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
collected.add(remote);
|
|
38
|
-
const remoteProjectRoot = remoteProject.root;
|
|
39
|
-
const remoteProjectTsConfig = remoteProject.targets['build'].options.tsConfig;
|
|
40
|
-
const remoteProjectConfig = getModuleFederationConfig(remoteProjectTsConfig, context.root, remoteProjectRoot);
|
|
41
|
-
const { remotes: remoteProjectRemotes } = extractRemoteProjectsFromConfig(remoteProjectConfig);
|
|
42
|
-
remoteProjectRemotes.forEach((r) => collectRemoteProjects(r, collected, context));
|
|
43
|
-
}
|
|
44
|
-
function getRemotes(devRemotes, skipRemotes, config, context, pathToManifestFile) {
|
|
45
|
-
const collectedRemotes = new Set();
|
|
46
|
-
const { remotes, dynamicRemotes } = extractRemoteProjectsFromConfig(config, pathToManifestFile);
|
|
47
|
-
remotes.forEach((r) => collectRemoteProjects(r, collectedRemotes, context));
|
|
48
|
-
const remotesToSkip = new Set((0, find_matching_projects_1.findMatchingProjects)(skipRemotes, context.projectGraph.nodes) ?? []);
|
|
49
|
-
if (remotesToSkip.size > 0) {
|
|
50
|
-
devkit_1.logger.info(`Remotes not served automatically: ${[...remotesToSkip.values()].join(', ')}`);
|
|
51
|
-
}
|
|
52
|
-
const knownRemotes = Array.from(collectedRemotes).filter((r) => !remotesToSkip.has(r));
|
|
53
|
-
const knownDynamicRemotes = dynamicRemotes.filter((r) => !remotesToSkip.has(r) && context.projectGraph.nodes[r]);
|
|
54
|
-
devkit_1.logger.info(`NX Starting module federation dev-server for ${chalk_1.default.bold(context.projectName)} with ${[...knownRemotes, ...knownDynamicRemotes].length} remotes`);
|
|
55
|
-
const devServeApps = new Set(!devRemotes
|
|
56
|
-
? []
|
|
57
|
-
: Array.isArray(devRemotes)
|
|
58
|
-
? (0, find_matching_projects_1.findMatchingProjects)(devRemotes, context.projectGraph.nodes)
|
|
59
|
-
: (0, find_matching_projects_1.findMatchingProjects)([devRemotes], context.projectGraph.nodes));
|
|
60
|
-
const staticRemotes = knownRemotes.filter((r) => !devServeApps.has(r));
|
|
61
|
-
const devServeRemotes = [...knownRemotes, ...knownDynamicRemotes].filter((r) => devServeApps.has(r));
|
|
62
|
-
const staticDynamicRemotes = knownDynamicRemotes.filter((r) => !devServeApps.has(r));
|
|
63
|
-
const remotePorts = [...devServeRemotes, ...staticDynamicRemotes].map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port);
|
|
64
|
-
const staticRemotePort = Math.max(...[
|
|
65
|
-
...remotePorts,
|
|
66
|
-
...staticRemotes.map((r) => context.projectGraph.nodes[r].data.targets['serve'].options.port),
|
|
67
|
-
]) +
|
|
68
|
-
(remotesToSkip.size + 1);
|
|
69
|
-
return {
|
|
70
|
-
staticRemotes,
|
|
71
|
-
devRemotes: devServeRemotes,
|
|
72
|
-
dynamicRemotes: staticDynamicRemotes,
|
|
73
|
-
remotePorts,
|
|
74
|
-
staticRemotePort,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function getModuleFederationConfig(tsconfigPath, workspaceRoot, projectRoot, pluginName = 'react') {
|
|
78
|
-
const moduleFederationConfigPathJS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.js');
|
|
79
|
-
const moduleFederationConfigPathTS = (0, path_1.join)(workspaceRoot, projectRoot, 'module-federation.config.ts');
|
|
80
|
-
let moduleFederationConfigPath = moduleFederationConfigPathJS;
|
|
81
|
-
// create a no-op so this can be called with issue
|
|
82
|
-
const fullTSconfigPath = tsconfigPath.startsWith(workspaceRoot)
|
|
83
|
-
? tsconfigPath
|
|
84
|
-
: (0, path_1.join)(workspaceRoot, tsconfigPath);
|
|
85
|
-
let cleanupTranspiler = () => undefined;
|
|
86
|
-
if ((0, fs_1.existsSync)(moduleFederationConfigPathTS)) {
|
|
87
|
-
cleanupTranspiler = (0, internal_1.registerTsProject)(fullTSconfigPath);
|
|
88
|
-
moduleFederationConfigPath = moduleFederationConfigPathTS;
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
92
|
-
const config = require(moduleFederationConfigPath);
|
|
93
|
-
cleanupTranspiler();
|
|
94
|
-
return config.default || config;
|
|
95
|
-
}
|
|
96
|
-
catch {
|
|
97
|
-
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`);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
-
import type { NormalModuleReplacementPlugin } from '@rspack/core';
|
|
3
|
-
export type ModuleFederationLibrary = {
|
|
4
|
-
type: string;
|
|
5
|
-
name: string;
|
|
6
|
-
};
|
|
7
|
-
export type WorkspaceLibrary = {
|
|
8
|
-
name: string;
|
|
9
|
-
root: string;
|
|
10
|
-
importKey: string | undefined;
|
|
11
|
-
};
|
|
12
|
-
export type SharedWorkspaceLibraryConfig = {
|
|
13
|
-
getAliases: () => Record<string, string>;
|
|
14
|
-
getLibraries: (projectRoot: string, eager?: boolean) => Record<string, SharedLibraryConfig>;
|
|
15
|
-
getReplacementPlugin: () => NormalModuleReplacementPlugin;
|
|
16
|
-
};
|
|
17
|
-
export type Remotes = Array<string | [remoteName: string, remoteUrl: string]>;
|
|
18
|
-
export interface SharedLibraryConfig {
|
|
19
|
-
singleton?: boolean;
|
|
20
|
-
strictVersion?: boolean;
|
|
21
|
-
requiredVersion?: false | string;
|
|
22
|
-
eager?: boolean;
|
|
23
|
-
}
|
|
24
|
-
export type SharedFunction = (libraryName: string, sharedConfig: SharedLibraryConfig) => undefined | false | SharedLibraryConfig;
|
|
25
|
-
export type AdditionalSharedConfig = Array<string | [libraryName: string, sharedConfig: SharedLibraryConfig] | {
|
|
26
|
-
libraryName: string;
|
|
27
|
-
sharedConfig: SharedLibraryConfig;
|
|
28
|
-
}>;
|
|
29
|
-
export interface ModuleFederationConfig {
|
|
30
|
-
name: string;
|
|
31
|
-
remotes?: Remotes;
|
|
32
|
-
library?: ModuleFederationLibrary;
|
|
33
|
-
exposes?: Record<string, string>;
|
|
34
|
-
shared?: SharedFunction;
|
|
35
|
-
additionalShared?: AdditionalSharedConfig;
|
|
36
|
-
/**
|
|
37
|
-
* `nxRuntimeLibraryControlPlugin` is a runtime module federation plugin to ensure
|
|
38
|
-
* that shared libraries are resolved from a remote with live reload capabilities.
|
|
39
|
-
* If you run into any issues with loading shared libraries, try disabling this option.
|
|
40
|
-
*/
|
|
41
|
-
disableNxRuntimeLibraryControlPlugin?: boolean;
|
|
42
|
-
}
|
|
43
|
-
export type NxModuleFederationConfigOverride = Omit<moduleFederationPlugin.ModuleFederationPluginOptions, 'exposes' | 'remotes' | 'name' | 'library' | 'shared' | 'filename' | 'remoteType'>;
|
|
44
|
-
export type WorkspaceLibrarySecondaryEntryPoint = {
|
|
45
|
-
name: string;
|
|
46
|
-
path: string;
|
|
47
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.readRootPackageJson = readRootPackageJson;
|
|
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
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ExecutorContext } from '@nx/devkit';
|
|
2
|
-
export type StaticRemoteConfig = {
|
|
3
|
-
basePath: string;
|
|
4
|
-
outputPath: string;
|
|
5
|
-
urlSegment: string;
|
|
6
|
-
port: number;
|
|
7
|
-
};
|
|
8
|
-
export type StaticRemotesConfig = {
|
|
9
|
-
remotes: string[];
|
|
10
|
-
config: Record<string, StaticRemoteConfig> | undefined;
|
|
11
|
-
};
|
|
12
|
-
export declare function parseStaticRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
|
|
13
|
-
export declare function parseStaticSsrRemotesConfig(staticRemotes: string[] | undefined, context: ExecutorContext): StaticRemotesConfig;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseStaticRemotesConfig = parseStaticRemotesConfig;
|
|
4
|
-
exports.parseStaticSsrRemotesConfig = parseStaticSsrRemotesConfig;
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
function parseStaticRemotesConfig(staticRemotes, context) {
|
|
7
|
-
if (!staticRemotes?.length) {
|
|
8
|
-
return { remotes: [], config: undefined };
|
|
9
|
-
}
|
|
10
|
-
const config = {};
|
|
11
|
-
for (const app of staticRemotes) {
|
|
12
|
-
const outputPath = context.projectGraph.nodes[app].data.targets['build'].options.outputPath;
|
|
13
|
-
const basePath = (0, path_1.dirname)(outputPath);
|
|
14
|
-
const urlSegment = (0, path_1.basename)(outputPath);
|
|
15
|
-
const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
|
|
16
|
-
config[app] = { basePath, outputPath, urlSegment, port };
|
|
17
|
-
}
|
|
18
|
-
return { remotes: staticRemotes, config };
|
|
19
|
-
}
|
|
20
|
-
function parseStaticSsrRemotesConfig(staticRemotes, context) {
|
|
21
|
-
if (!staticRemotes?.length) {
|
|
22
|
-
return { remotes: [], config: undefined };
|
|
23
|
-
}
|
|
24
|
-
const config = {};
|
|
25
|
-
for (const app of staticRemotes) {
|
|
26
|
-
const outputPath = (0, path_1.dirname)(context.projectGraph.nodes[app].data.targets['build'].options.outputPath // dist/checkout/browser -> checkout
|
|
27
|
-
);
|
|
28
|
-
const basePath = (0, path_1.dirname)(outputPath); // dist/checkout -> dist
|
|
29
|
-
const urlSegment = (0, path_1.basename)(outputPath); // dist/checkout -> checkout
|
|
30
|
-
const port = context.projectGraph.nodes[app].data.targets['serve'].options.port;
|
|
31
|
-
config[app] = { basePath, outputPath, urlSegment, port };
|
|
32
|
-
}
|
|
33
|
-
return { remotes: staticRemotes, config };
|
|
34
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const runtimeStore = {
|
|
4
|
-
sharedPackagesFromDev: {},
|
|
5
|
-
};
|
|
6
|
-
if (process.env.NX_MF_DEV_REMOTES) {
|
|
7
|
-
// process.env.NX_MF_DEV_REMOTES is replaced by an array value via DefinePlugin, even though the original value is a stringified array.
|
|
8
|
-
runtimeStore.devRemotes = process.env
|
|
9
|
-
.NX_MF_DEV_REMOTES;
|
|
10
|
-
}
|
|
11
|
-
const nxRuntimeLibraryControlPlugin = function () {
|
|
12
|
-
return {
|
|
13
|
-
name: 'nx-runtime-library-control-plugin',
|
|
14
|
-
beforeInit(args) {
|
|
15
|
-
runtimeStore.name = args.options.name;
|
|
16
|
-
return args;
|
|
17
|
-
},
|
|
18
|
-
resolveShare: (args) => {
|
|
19
|
-
const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
|
|
20
|
-
const originalResolver = args.resolver;
|
|
21
|
-
args.resolver = function () {
|
|
22
|
-
if (!runtimeStore.sharedPackagesFromDev[pkgName]) {
|
|
23
|
-
if (!GlobalFederation.__INSTANCES__) {
|
|
24
|
-
return originalResolver();
|
|
25
|
-
}
|
|
26
|
-
else if (!runtimeStore.devRemotes) {
|
|
27
|
-
return originalResolver();
|
|
28
|
-
}
|
|
29
|
-
const devRemoteInstanceToUse = GlobalFederation.__INSTANCES__.find((instance) => instance.options.shared[pkgName] &&
|
|
30
|
-
runtimeStore.devRemotes.find((dr) => instance.name === dr));
|
|
31
|
-
if (!devRemoteInstanceToUse) {
|
|
32
|
-
return originalResolver();
|
|
33
|
-
}
|
|
34
|
-
runtimeStore.sharedPackagesFromDev[pkgName] =
|
|
35
|
-
devRemoteInstanceToUse.name;
|
|
36
|
-
}
|
|
37
|
-
const remoteInstanceName = runtimeStore.sharedPackagesFromDev[pkgName];
|
|
38
|
-
const remoteInstance = GlobalFederation.__INSTANCES__.find((instance) => instance.name === remoteInstanceName);
|
|
39
|
-
try {
|
|
40
|
-
const remotePkgInfo = remoteInstance.options.shared[pkgName].find((shared) => shared.from === remoteInstanceName);
|
|
41
|
-
remotePkgInfo.useIn.push(runtimeStore.name);
|
|
42
|
-
remotePkgInfo.useIn = Array.from(new Set(remotePkgInfo.useIn));
|
|
43
|
-
shareScopeMap[scope][pkgName][version] = remotePkgInfo;
|
|
44
|
-
return remotePkgInfo;
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return originalResolver();
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
return args;
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
exports.default = nxRuntimeLibraryControlPlugin;
|