Skip to content

Commit

Permalink
fix(@nguniversal/builders): correctly handle path normalizations on W…
Browse files Browse the repository at this point in the history
…indows

Closes #2706

(cherry picked from commit c1383d1)
  • Loading branch information
alan-agius4 committed Jun 23, 2022
1 parent fa24bc6 commit ddffd97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions modules/builders/src/prerender/index.ts
Expand Up @@ -15,7 +15,6 @@ import {
import { BrowserBuilderOptions } from '@angular-devkit/build-angular';
import { normalizeOptimization } from '@angular-devkit/build-angular/src/utils/normalize-optimization';
import { augmentAppWithServiceWorker } from '@angular-devkit/build-angular/src/utils/service-worker';
import { normalize, resolve as resolvePath } from '@angular-devkit/core';
import * as fs from 'fs';
import ora from 'ora';
import * as path from 'path';
Expand Down Expand Up @@ -92,9 +91,11 @@ async function _renderUniversal(
throw new Error('The builder requires a target.');
}

const root = normalize(context.workspaceRoot);
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = resolvePath(root, normalize((projectMetadata.root as string) || ''));
const projectRoot = path.join(
context.workspaceRoot,
(projectMetadata.root as string | undefined) ?? '',
);

// Users can specify a different base html file e.g. "src/home.html"
const indexFile = getIndexOutputFile(browserOptions);
Expand Down Expand Up @@ -160,7 +161,7 @@ async function _renderUniversal(
await augmentAppWithServiceWorker(
projectRoot,
context.workspaceRoot,
normalize(outputPath),
outputPath,
browserOptions.baseHref || '/',
browserOptions.ngswConfigPath,
);
Expand Down
9 changes: 5 additions & 4 deletions modules/builders/src/static-generator/index.ts
Expand Up @@ -15,7 +15,6 @@ import {
import { BrowserBuilderOptions, BrowserBuilderOutput } from '@angular-devkit/build-angular';
import { normalizeOptimization } from '@angular-devkit/build-angular/src/utils/normalize-optimization';
import { augmentAppWithServiceWorker } from '@angular-devkit/build-angular/src/utils/service-worker';
import { normalize, resolve } from '@angular-devkit/core';
import express from 'express';
import * as http from 'http';
import ora from 'ora';
Expand Down Expand Up @@ -145,14 +144,16 @@ async function generateServiceWorker(
throw new Error('The builder requires a target.');
}

const root = normalize(context.workspaceRoot);
const projectMetadata = await context.getProjectMetadata(projectName);
const projectRoot = resolve(root, normalize((projectMetadata.root as string) ?? ''));
const projectRoot = path.join(
context.workspaceRoot,
(projectMetadata.root as string | undefined) ?? '',
);

await augmentAppWithServiceWorker(
projectRoot,
context.workspaceRoot,
normalize(outputPath),
outputPath,
browserOptions.baseHref || '/',
browserOptions.ngswConfigPath,
);
Expand Down

0 comments on commit ddffd97

Please sign in to comment.