Skip to content

Commit bf387fb

Browse files
committed
refactor: ensure prerender routes start with a forward slash and update package resolution to use createRequire
This fixes broken e2e tests
1 parent 02ce8bf commit bf387fb

3 files changed

Lines changed: 6 additions & 3 deletions

File tree

packages/angular_devkit/build_angular/src/builders/app-shell/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ async function _renderUniversal(
8282
localeDirectory,
8383
);
8484

85+
const route = options.route;
8586
let html: string = await renderWorker.run({
8687
serverBundlePath,
8788
document: indexHtml,
88-
url: options.route,
89+
url: route?.[0] === '/' ? route : '/' + route,
8990
});
9091

9192
// Overwrite the client index file.

packages/angular_devkit/build_angular/src/builders/prerender/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ async function _renderUniversal(
209209
inlineCriticalCss: !!normalizedStylesOptimization.inlineCritical,
210210
minifyCss: !!normalizedStylesOptimization.minify,
211211
outputPath,
212-
route,
212+
route: route[0] === '/' ? route : '/' + route,
213213
serverBundlePath,
214214
};
215215

packages/angular_devkit/build_angular/src/tools/webpack/utils/helpers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import type { ObjectPattern } from 'copy-webpack-plugin';
1010
import glob from 'fast-glob';
1111
import { createHash } from 'node:crypto';
12+
import { createRequire } from 'node:module';
1213
import * as path from 'node:path';
1314
import type { Configuration, WebpackOptionsNormalized } from 'webpack';
1415
import {
@@ -314,7 +315,8 @@ export function getStatsOptions(verbose = false): WebpackStatsOptions {
314315
*/
315316
export function isPackageInstalled(root: string, name: string): boolean {
316317
try {
317-
require.resolve(name, { paths: [root] });
318+
const resolve = createRequire(root + '/').resolve;
319+
resolve(name);
318320

319321
return true;
320322
} catch {

0 commit comments

Comments
 (0)