Skip to content

Commit a11e8f1

Browse files
Coly010FrozenPandaz
andauthoredOct 3, 2023
fix(web): disable tsnode service after loading config (#19387)
Co-authored-by: Jason Jean <jasonjean1993@gmail.com>
1 parent a9230f2 commit a11e8f1

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed
 

‎e2e/react-core/src/react-module-federation.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe('React Module Federation', () => {
125125
it('should should support generating host and remote apps with the new name and root format', async () => {
126126
const shell = uniq('shell');
127127
const remote = uniq('remote');
128+
const shellPort = 4200;
128129

129130
runCLI(
130131
`generate @nx/react:host ${shell} --project-name-and-root-format=as-provided --no-interactive`
@@ -141,6 +142,17 @@ describe('React Module Federation', () => {
141142
// check default generated host is built successfully
142143
const buildOutput = runCLI(`run ${shell}:build:development`);
143144
expect(buildOutput).toContain('Successfully ran target build');
145+
146+
// check serves devRemotes ok
147+
const shellProcess = await runCommandUntil(
148+
`serve ${shell} --devRemotes=${remote} --verbose`,
149+
(output) => {
150+
return output.includes(
151+
`All remotes started, server ready at http://localhost:${shellPort}`
152+
);
153+
}
154+
);
155+
await killProcessAndPorts(shellProcess.pid, shellPort);
144156
}, 500_000);
145157

146158
it('should support different versions workspace libs for host and remote', async () => {

‎packages/angular/src/builders/utilities/module-federation.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import { ProjectConfiguration } from 'nx/src/config/workspace-json-project-json';
21
import { join } from 'path';
32
import { existsSync, readFileSync } from 'fs';
4-
import { logger } from '@nx/devkit';
5-
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
3+
import { logger, ProjectConfiguration } from '@nx/devkit';
4+
import { registerTsProject } from '@nx/js/src/internal';
65

76
export function getDynamicRemotes(
87
project: ProjectConfiguration,
@@ -91,13 +90,19 @@ function getModuleFederationConfig(
9190

9291
let moduleFederationConfigPath = moduleFederationConfigPathJS;
9392

93+
let cleanupTranspiler = () => {};
9494
if (existsSync(moduleFederationConfigPathTS)) {
95-
tsNodeRegister(moduleFederationConfigPathTS, tsconfigPath);
95+
cleanupTranspiler = registerTsProject(
96+
moduleFederationConfigPathTS,
97+
tsconfigPath
98+
);
9699
moduleFederationConfigPath = moduleFederationConfigPathTS;
97100
}
98101

99102
try {
100103
const config = require(moduleFederationConfigPath);
104+
cleanupTranspiler();
105+
101106
return {
102107
mfeConfig: config.default || config,
103108
mfConfigPath: moduleFederationConfigPath,

‎packages/angular/src/builders/utilities/webpack.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { merge } from 'webpack-merge';
2-
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
2+
import { registerTsProject } from '@nx/js/src/internal';
33

44
export async function mergeCustomWebpackConfig(
55
baseWebpackConfig: any,
@@ -26,9 +26,9 @@ export async function mergeCustomWebpackConfig(
2626
}
2727

2828
export function resolveCustomWebpackConfig(path: string, tsConfig: string) {
29-
tsNodeRegister(path, tsConfig);
30-
29+
const cleanupTranspiler = registerTsProject(path, tsConfig);
3130
const customWebpackConfig = require(path);
31+
cleanupTranspiler();
3232
// If the user provides a configuration in TS file
3333
// then there are 2 cases for exporting an object. The first one is:
3434
// `module.exports = { ... }`. And the second one is:
@@ -42,9 +42,10 @@ export function resolveIndexHtmlTransformer(
4242
tsConfig: string,
4343
target: import('@angular-devkit/architect').Target
4444
) {
45-
tsNodeRegister(path, tsConfig);
46-
45+
const cleanupTranspiler = registerTsProject(path, tsConfig);
4746
const indexTransformer = require(path);
47+
cleanupTranspiler();
48+
4849
const transform = indexTransformer.default ?? indexTransformer;
4950

5051
return (indexHtml) => transform(target, indexHtml);

‎packages/react/src/executors/module-federation-dev-server/module-federation-dev-server.impl.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { waitForPortOpen } from '@nx/web/src/utils/wait-for-port-open';
1717
import { findMatchingProjects } from 'nx/src/utils/find-matching-projects';
1818
import { fork } from 'child_process';
1919
import { existsSync } from 'fs';
20-
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
20+
import { registerTsProject } from '@nx/js/src/internal';
2121

2222
type ModuleFederationDevServerOptions = WebDevServerOptions & {
2323
devRemotes?: string | string[];
@@ -53,13 +53,20 @@ function getModuleFederationConfig(
5353

5454
let moduleFederationConfigPath = moduleFederationConfigPathJS;
5555

56+
// create a no-op so this can be called with issue
57+
let cleanupTranspiler = () => {};
5658
if (existsSync(moduleFederationConfigPathTS)) {
57-
tsNodeRegister(moduleFederationConfigPathTS, tsconfigPath);
59+
cleanupTranspiler = registerTsProject(
60+
moduleFederationConfigPathTS,
61+
tsconfigPath
62+
);
5863
moduleFederationConfigPath = moduleFederationConfigPathTS;
5964
}
6065

6166
try {
6267
const config = require(moduleFederationConfigPath);
68+
cleanupTranspiler();
69+
6370
return config.default || config;
6471
} catch {
6572
throw new Error(

‎packages/webpack/src/utils/webpack/custom-webpack.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { tsNodeRegister } from '@nx/js/src/utils/typescript/tsnode-register';
1+
import { registerTsProject } from '@nx/js/src/internal';
22

33
export function resolveCustomWebpackConfig(path: string, tsConfig: string) {
4-
tsNodeRegister(path, tsConfig);
5-
4+
const cleanupTranspiler = registerTsProject(path, tsConfig);
65
const customWebpackConfig = require(path);
6+
cleanupTranspiler();
7+
78
// If the user provides a configuration in TS file
89
// then there are 2 cases for exporing an object. The first one is:
910
// `module.exports = { ... }`. And the second one is:

0 commit comments

Comments
 (0)
Please sign in to comment.