Skip to content

Commit bb60b73

Browse files
author
Angular Builds
committed
6b2a8e175 refactor(@angular-devkit/build-angular): remove virtualfs host usage from browser/dev-server
1 parent 6528ce7 commit bb60b73

15 files changed

+43
-50
lines changed

package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
{
22
"name": "@angular-devkit/build-angular",
3-
"version": "0.1101.0-next.4+69.2d7f268",
3+
"version": "0.1101.0-next.4+70.6b2a8e1",
44
"description": "Angular Webpack Build Facade",
55
"experimental": true,
66
"main": "src/index.js",
77
"typings": "src/index.d.ts",
88
"builders": "builders.json",
99
"dependencies": {
10-
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#2d7f268ba",
11-
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#2d7f268ba",
12-
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#2d7f268ba",
13-
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#2d7f268ba",
10+
"@angular-devkit/architect": "github:angular/angular-devkit-architect-builds#6b2a8e175",
11+
"@angular-devkit/build-optimizer": "github:angular/angular-devkit-build-optimizer-builds#6b2a8e175",
12+
"@angular-devkit/build-webpack": "github:angular/angular-devkit-build-webpack-builds#6b2a8e175",
13+
"@angular-devkit/core": "github:angular/angular-devkit-core-builds#6b2a8e175",
1414
"@babel/core": "7.12.10",
1515
"@babel/generator": "7.12.11",
1616
"@babel/plugin-transform-runtime": "7.12.10",
1717
"@babel/preset-env": "7.12.11",
1818
"@babel/runtime": "7.12.5",
1919
"@babel/template": "7.12.7",
2020
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
21-
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#2d7f268ba",
21+
"@ngtools/webpack": "github:angular/ngtools-webpack-builds#6b2a8e175",
2222
"ansi-colors": "4.1.1",
2323
"autoprefixer": "10.2.3",
2424
"babel-loader": "8.2.2",

src/app-shell/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
99
*/
1010
const architect_1 = require("@angular-devkit/architect");
1111
const core_1 = require("@angular-devkit/core");
12-
const node_1 = require("@angular-devkit/core/node");
1312
const fs = require("fs");
1413
const path = require("path");
1514
const utils_1 = require("../utils");
@@ -27,7 +26,6 @@ async function _renderUniversal(options, context, browserResult, serverResult, s
2726
const root = context.workspaceRoot;
2827
const zonePackage = require.resolve('zone.js', { paths: [root] });
2928
await Promise.resolve().then(() => require(zonePackage));
30-
const host = new node_1.NodeJsSyncHost();
3129
const projectName = context.target && context.target.project;
3230
if (!projectName) {
3331
throw new Error('The builder requires a target.');
@@ -82,7 +80,7 @@ async function _renderUniversal(options, context, browserResult, serverResult, s
8280
}
8381
await fs_1.writeFile(outputIndexPath, html);
8482
if (browserOptions.serviceWorker) {
85-
await service_worker_1.augmentAppWithServiceWorker(host, core_1.normalize(root), projectRoot, core_1.normalize(outputPath), browserOptions.baseHref || '/', browserOptions.ngswConfigPath);
83+
await service_worker_1.augmentAppWithServiceWorker(core_1.normalize(root), projectRoot, core_1.normalize(outputPath), browserOptions.baseHref || '/', browserOptions.ngswConfigPath);
8684
}
8785
}
8886
return browserResult;

src/browser/index.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports.buildWebpackBrowser = exports.getCompilerConfig = exports.getAnalyticsCo
1111
const architect_1 = require("@angular-devkit/architect");
1212
const build_webpack_1 = require("@angular-devkit/build-webpack");
1313
const core_1 = require("@angular-devkit/core");
14-
const node_1 = require("@angular-devkit/core/node");
1514
const fs = require("fs");
1615
const path = require("path");
1716
const rxjs_1 = require("rxjs");
@@ -63,7 +62,7 @@ function getCompilerConfig(wco) {
6362
return {};
6463
}
6564
exports.getCompilerConfig = getCompilerConfig;
66-
async function initialize(options, context, host, differentialLoadingNeeded, webpackConfigurationTransform) {
65+
async function initialize(options, context, differentialLoadingNeeded, webpackConfigurationTransform) {
6766
var _a, _b;
6867
const originalOutputPath = options.outputPath;
6968
// Assets are processed directly by the builder except when watching
@@ -76,10 +75,10 @@ async function initialize(options, context, host, differentialLoadingNeeded, web
7675
getAnalyticsConfig(wco, context),
7776
getCompilerConfig(wco),
7877
wco.buildOptions.webWorkerTsConfig ? configs_1.getWorkerConfig(wco) : {},
79-
], host, { differentialLoadingNeeded });
78+
], { differentialLoadingNeeded });
8079
// Validate asset option values if processed directly
8180
if (((_a = options.assets) === null || _a === void 0 ? void 0 : _a.length) && !((_b = adjustedOptions.assets) === null || _b === void 0 ? void 0 : _b.length)) {
82-
utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), core_1.normalize(context.workspaceRoot), core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)).forEach(({ output }) => {
81+
utils_1.normalizeAssetPatterns(options.assets, core_1.normalize(context.workspaceRoot), core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)).forEach(({ output }) => {
8382
if (output.startsWith('..')) {
8483
throw new Error('An asset cannot be written to a location outside of the output path.');
8584
}
@@ -97,7 +96,6 @@ async function initialize(options, context, host, differentialLoadingNeeded, web
9796
// tslint:disable-next-line: no-big-function
9897
function buildWebpackBrowser(options, context, transforms = {}) {
9998
var _a;
100-
const host = new node_1.NodeJsSyncHost();
10199
const root = core_1.normalize(context.workspaceRoot);
102100
const projectName = (_a = context.target) === null || _a === void 0 ? void 0 : _a.project;
103101
if (!projectName) {
@@ -132,7 +130,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
132130
'\nFor additional information: https://v10.angular.io/guide/deprecations#ie-9-10-and-mobile');
133131
}
134132
return {
135-
...(await initialize(options, context, host, isDifferentialLoadingNeeded, transforms.webpackConfiguration)),
133+
...(await initialize(options, context, isDifferentialLoadingNeeded, transforms.webpackConfiguration)),
136134
buildBrowserFeatures,
137135
isDifferentialLoadingNeeded,
138136
target,
@@ -459,7 +457,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
459457
if (!options.watch && ((_d = options.assets) === null || _d === void 0 ? void 0 : _d.length)) {
460458
spinner.start('Copying assets...');
461459
try {
462-
await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, new core_1.virtualFs.SyncDelegateHost(host), root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
460+
await copy_assets_1.copyAssets(utils_1.normalizeAssetPatterns(options.assets, root, core_1.normalize(projectRoot), projectSourceRoot === undefined ? undefined : core_1.normalize(projectSourceRoot)), Array.from(outputPaths.values()), context.workspaceRoot);
463461
spinner.succeed('Copying assets complete.');
464462
}
465463
catch (err) {
@@ -517,7 +515,7 @@ function buildWebpackBrowser(options, context, transforms = {}) {
517515
spinner.start('Generating service worker...');
518516
for (const [locale, outputPath] of outputPaths.entries()) {
519517
try {
520-
await service_worker_1.augmentAppWithServiceWorker(host, root, core_1.normalize(projectRoot), core_1.normalize(outputPath), getLocaleBaseHref(i18n, locale) || options.baseHref || '/', options.ngswConfigPath);
518+
await service_worker_1.augmentAppWithServiceWorker(root, core_1.normalize(projectRoot), core_1.normalize(outputPath), getLocaleBaseHref(i18n, locale) || options.baseHref || '/', options.ngswConfigPath);
521519
}
522520
catch (error) {
523521
spinner.fail('Service worker generation failed.');

src/dev-server/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ exports.serveWebpackBrowser = void 0;
1111
const architect_1 = require("@angular-devkit/architect");
1212
const build_webpack_1 = require("@angular-devkit/build-webpack");
1313
const core_1 = require("@angular-devkit/core");
14-
const node_1 = require("@angular-devkit/core/node");
1514
const path = require("path");
1615
const rxjs_1 = require("rxjs");
1716
const operators_1 = require("rxjs/operators");
@@ -59,7 +58,6 @@ function serveWebpackBrowser(options, context, transforms = {}) {
5958
const { logger, workspaceRoot } = context;
6059
version_1.assertCompatibleAngularVersion(workspaceRoot, logger);
6160
const browserTarget = architect_1.targetFromTargetString(options.browserTarget);
62-
const host = new node_1.NodeJsSyncHost();
6361
async function setup() {
6462
var _a;
6563
// Get the browser configuration from the target name.
@@ -97,7 +95,7 @@ function serveWebpackBrowser(options, context, transforms = {}) {
9795
browser_1.getAnalyticsConfig(wco, context),
9896
browser_1.getCompilerConfig(wco),
9997
browserOptions.webWorkerTsConfig ? configs_1.getWorkerConfig(wco) : {},
100-
], host, devServerOptions);
98+
], devServerOptions);
10199
if (!config.devServer) {
102100
throw new Error('Webpack Dev Server configuration was not set.');
103101
}

src/utils/normalize-asset-patterns.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { BaseException, Path, virtualFs } from '@angular-devkit/core';
8+
import { BaseException, Path } from '@angular-devkit/core';
99
import { AssetPattern, AssetPatternClass } from '../browser/schema';
1010
export declare class MissingAssetSourceRootException extends BaseException {
1111
constructor(path: String);
1212
}
13-
export declare function normalizeAssetPatterns(assetPatterns: AssetPattern[], host: virtualFs.SyncDelegateHost, root: Path, projectRoot: Path, maybeSourceRoot: Path | undefined): AssetPatternClass[];
13+
export declare function normalizeAssetPatterns(assetPatterns: AssetPattern[], root: Path, projectRoot: Path, maybeSourceRoot: Path | undefined): AssetPatternClass[];

src/utils/normalize-asset-patterns.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ exports.normalizeAssetPatterns = exports.MissingAssetSourceRootException = void
99
* found in the LICENSE file at https://angular.io/license
1010
*/
1111
const core_1 = require("@angular-devkit/core");
12+
const fs_1 = require("fs");
1213
class MissingAssetSourceRootException extends core_1.BaseException {
1314
constructor(path) {
1415
super(`The ${path} asset path must start with the project source root.`);
1516
}
1617
}
1718
exports.MissingAssetSourceRootException = MissingAssetSourceRootException;
18-
function normalizeAssetPatterns(assetPatterns, host, root, projectRoot, maybeSourceRoot) {
19+
function normalizeAssetPatterns(assetPatterns, root, projectRoot, maybeSourceRoot) {
1920
// When sourceRoot is not available, we default to ${projectRoot}/src.
2021
const sourceRoot = maybeSourceRoot || core_1.join(projectRoot, 'src');
2122
const resolvedSourceRoot = core_1.resolve(root, sourceRoot);
@@ -35,7 +36,7 @@ function normalizeAssetPatterns(assetPatterns, host, root, projectRoot, maybeSou
3536
let glob, input, output;
3637
let isDirectory = false;
3738
try {
38-
isDirectory = host.isDirectory(resolvedAssetPath);
39+
isDirectory = fs_1.statSync(core_1.getSystemPath(resolvedAssetPath)).isDirectory();
3940
}
4041
catch (_a) {
4142
isDirectory = true;

src/utils/normalize-builder-schema.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Path, virtualFs } from '@angular-devkit/core';
8+
import { Path } from '@angular-devkit/core';
99
import { AssetPatternClass, Schema as BrowserBuilderSchema, SourceMapClass } from '../browser/schema';
1010
import { BuildOptions } from './build-options';
1111
import { NormalizedFileReplacement } from './normalize-file-replacements';
@@ -19,4 +19,4 @@ export declare type NormalizedBrowserBuilderSchema = BrowserBuilderSchema & Buil
1919
fileReplacements: NormalizedFileReplacement[];
2020
optimization: NormalizedOptimizationOptions;
2121
};
22-
export declare function normalizeBrowserSchema(host: virtualFs.Host<{}>, root: Path, projectRoot: Path, sourceRoot: Path | undefined, options: BrowserBuilderSchema): NormalizedBrowserBuilderSchema;
22+
export declare function normalizeBrowserSchema(root: Path, projectRoot: Path, sourceRoot: Path | undefined, options: BrowserBuilderSchema): NormalizedBrowserBuilderSchema;

src/utils/normalize-builder-schema.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
*/
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.normalizeBrowserSchema = void 0;
11-
const core_1 = require("@angular-devkit/core");
1211
const normalize_asset_patterns_1 = require("./normalize-asset-patterns");
1312
const normalize_file_replacements_1 = require("./normalize-file-replacements");
1413
const normalize_optimization_1 = require("./normalize-optimization");
1514
const normalize_source_maps_1 = require("./normalize-source-maps");
16-
function normalizeBrowserSchema(host, root, projectRoot, sourceRoot, options) {
17-
const syncHost = new core_1.virtualFs.SyncDelegateHost(host);
15+
function normalizeBrowserSchema(root, projectRoot, sourceRoot, options) {
1816
const normalizedSourceMapOptions = normalize_source_maps_1.normalizeSourceMaps(options.sourceMap || false);
1917
return {
2018
...options,
21-
assets: normalize_asset_patterns_1.normalizeAssetPatterns(options.assets || [], syncHost, root, projectRoot, sourceRoot),
22-
fileReplacements: normalize_file_replacements_1.normalizeFileReplacements(options.fileReplacements || [], syncHost, root),
19+
assets: normalize_asset_patterns_1.normalizeAssetPatterns(options.assets || [], root, projectRoot, sourceRoot),
20+
fileReplacements: normalize_file_replacements_1.normalizeFileReplacements(options.fileReplacements || [], root),
2321
optimization: normalize_optimization_1.normalizeOptimization(options.optimization),
2422
sourceMap: normalizedSourceMapOptions,
2523
preserveSymlinks: options.preserveSymlinks === undefined ? process.execArgv.includes('--preserve-symlinks') : options.preserveSymlinks,

src/utils/normalize-file-replacements.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { BaseException, Path, virtualFs } from '@angular-devkit/core';
8+
import { BaseException, Path } from '@angular-devkit/core';
99
import { FileReplacement } from '../browser/schema';
1010
export declare class MissingFileReplacementException extends BaseException {
1111
constructor(path: String);
@@ -14,4 +14,4 @@ export interface NormalizedFileReplacement {
1414
replace: Path;
1515
with: Path;
1616
}
17-
export declare function normalizeFileReplacements(fileReplacements: FileReplacement[], host: virtualFs.SyncDelegateHost, root: Path): NormalizedFileReplacement[];
17+
export declare function normalizeFileReplacements(fileReplacements: FileReplacement[], root: Path): NormalizedFileReplacement[];

src/utils/normalize-file-replacements.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@
99
Object.defineProperty(exports, "__esModule", { value: true });
1010
exports.normalizeFileReplacements = exports.MissingFileReplacementException = void 0;
1111
const core_1 = require("@angular-devkit/core");
12+
const fs_1 = require("fs");
1213
class MissingFileReplacementException extends core_1.BaseException {
1314
constructor(path) {
1415
super(`The ${path} path in file replacements does not exist.`);
1516
}
1617
}
1718
exports.MissingFileReplacementException = MissingFileReplacementException;
18-
function normalizeFileReplacements(fileReplacements, host, root) {
19+
function normalizeFileReplacements(fileReplacements, root) {
1920
if (fileReplacements.length === 0) {
2021
return [];
2122
}
2223
const normalizedReplacement = fileReplacements
2324
.map(replacement => normalizeFileReplacement(replacement, root));
2425
for (const { replace, with: replacementWith } of normalizedReplacement) {
25-
if (!host.exists(replacementWith)) {
26+
if (!fs_1.existsSync(core_1.getSystemPath(replacementWith))) {
2627
throw new MissingFileReplacementException(core_1.getSystemPath(replacementWith));
2728
}
28-
if (!host.exists(replace)) {
29+
if (!fs_1.existsSync(core_1.getSystemPath(replace))) {
2930
throw new MissingFileReplacementException(core_1.getSystemPath(replace));
3031
}
3132
}

src/utils/service-worker.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Path, virtualFs } from '@angular-devkit/core';
9-
export declare function augmentAppWithServiceWorker(host: virtualFs.Host, projectRoot: Path, appRoot: Path, outputPath: Path, baseHref: string, ngswConfigPath?: string): Promise<void>;
8+
import { Path } from '@angular-devkit/core';
9+
export declare function augmentAppWithServiceWorker(projectRoot: Path, appRoot: Path, outputPath: Path, baseHref: string, ngswConfigPath?: string): Promise<void>;

src/utils/service-worker.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ exports.augmentAppWithServiceWorker = void 0;
99
* found in the LICENSE file at https://angular.io/license
1010
*/
1111
const core_1 = require("@angular-devkit/core");
12+
const node_1 = require("@angular-devkit/core/node");
1213
const crypto = require("crypto");
1314
class CliFilesystem {
1415
constructor(_host, base) {
@@ -50,7 +51,8 @@ class CliFilesystem {
5051
return items;
5152
}
5253
}
53-
async function augmentAppWithServiceWorker(host, projectRoot, appRoot, outputPath, baseHref, ngswConfigPath) {
54+
async function augmentAppWithServiceWorker(projectRoot, appRoot, outputPath, baseHref, ngswConfigPath) {
55+
const host = new node_1.NodeJsSyncHost();
5456
const distPath = core_1.normalize(outputPath);
5557
const systemProjectRoot = core_1.getSystemPath(projectRoot);
5658
// Find the service worker package

0 commit comments

Comments
 (0)