Skip to content

Commit

Permalink
fix(@angular/build): lazy load Node.js inspector for dev server
Browse files Browse the repository at this point in the history
The Node.js inspector will now only be imported if SSR is enabled and
the `inspect` option is used. This prevents potential failures when a
custom Node.js binary build is used that has not enabled inspector usage.
While this is not common, loading the inspector on demand is a minimal
change that also avoids loading code that will not be used for the majority
of development server usage.
  • Loading branch information
clydin committed Aug 7, 2024
1 parent c4fa7b6 commit 34908a3
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { BuilderContext } from '@angular-devkit/architect';
import type { Plugin } from 'esbuild';
import assert from 'node:assert';
import { readFile } from 'node:fs/promises';
import inspector from 'node:inspector';
import { builtinModules } from 'node:module';
import { join } from 'node:path';
import type { Connect, DepOptimizationConfig, InlineConfig, ViteDevServer } from 'vite';
Expand Down Expand Up @@ -275,6 +274,7 @@ export async function* serveWithVite(

if (browserOptions.ssr && serverOptions.inspect) {
const { host, port } = serverOptions.inspect as { host?: string; port?: number };
const { default: inspector } = await import('node:inspector');
inspector.open(port, host, true);
context.addTeardown(() => inspector.close());
}
Expand Down

0 comments on commit 34908a3

Please sign in to comment.