|
6 | 6 | * found in the LICENSE file at https://angular.io/license
|
7 | 7 | */
|
8 | 8 | import { Path, dirname, getSystemPath, normalize, resolve, virtualFs } from '@angular-devkit/core';
|
9 |
| -import { NodeJsSyncHost } from '@angular-devkit/core/node'; |
10 | 9 | import { ChildProcess, ForkOptions, fork } from 'child_process';
|
11 | 10 | import * as fs from 'fs';
|
12 | 11 | import * as path from 'path';
|
@@ -58,6 +57,7 @@ import {
|
58 | 57 | NodeWatchFileSystemInterface,
|
59 | 58 | NormalModuleFactoryRequest,
|
60 | 59 | } from './webpack';
|
| 60 | +import { WebpackInputHost } from './webpack-input-host'; |
61 | 61 |
|
62 | 62 | const treeKill = require('tree-kill');
|
63 | 63 |
|
@@ -289,48 +289,6 @@ export class AngularCompilerPlugin {
|
289 | 289 | this._contextElementDependencyConstructor = options.contextElementDependencyConstructor
|
290 | 290 | || require('webpack/lib/dependencies/ContextElementDependency');
|
291 | 291 |
|
292 |
| - |
293 |
| - let host: virtualFs.Host<fs.Stats> = options.host || new NodeJsSyncHost(); |
294 |
| - if (options.hostReplacementPaths) { |
295 |
| - if (typeof options.hostReplacementPaths == 'function') { |
296 |
| - const replacementResolver = options.hostReplacementPaths; |
297 |
| - host = new class extends virtualFs.ResolverHost<fs.Stats> { |
298 |
| - _resolve(path: Path) { |
299 |
| - return normalize(replacementResolver(getSystemPath(path))); |
300 |
| - } |
301 |
| - }(host); |
302 |
| - } else { |
303 |
| - const aliasHost = new virtualFs.AliasHost(host); |
304 |
| - for (const from in options.hostReplacementPaths) { |
305 |
| - aliasHost.aliases.set(normalize(from), normalize(options.hostReplacementPaths[from])); |
306 |
| - } |
307 |
| - host = aliasHost; |
308 |
| - } |
309 |
| - } |
310 |
| - |
311 |
| - // Create the webpack compiler host. |
312 |
| - const webpackCompilerHost = new WebpackCompilerHost( |
313 |
| - this._compilerOptions, |
314 |
| - this._basePath, |
315 |
| - host, |
316 |
| - ); |
317 |
| - webpackCompilerHost.enableCaching(); |
318 |
| - |
319 |
| - // Create and set a new WebpackResourceLoader. |
320 |
| - this._resourceLoader = new WebpackResourceLoader(); |
321 |
| - webpackCompilerHost.setResourceLoader(this._resourceLoader); |
322 |
| - |
323 |
| - // Use the WebpackCompilerHost with a resource loader to create an AngularCompilerHost. |
324 |
| - this._compilerHost = createCompilerHost({ |
325 |
| - options: this._compilerOptions, |
326 |
| - tsHost: webpackCompilerHost, |
327 |
| - }) as CompilerHost & WebpackCompilerHost; |
328 |
| - |
329 |
| - // Resolve mainPath if provided. |
330 |
| - if (options.mainPath) { |
331 |
| - this._mainPath = this._compilerHost.resolve(options.mainPath); |
332 |
| - } |
333 |
| - |
334 | 292 | // Use entryModule if available in options, otherwise resolve it from mainPath after program
|
335 | 293 | // creation.
|
336 | 294 | if (this._options.entryModule) {
|
@@ -621,28 +579,61 @@ export class AngularCompilerPlugin {
|
621 | 579 | watchFileSystem: NodeWatchFileSystemInterface,
|
622 | 580 | };
|
623 | 581 |
|
624 |
| - const inputDecorator = new VirtualFileSystemDecorator( |
| 582 | + let host: virtualFs.Host<fs.Stats> = this._options.host || new WebpackInputHost( |
625 | 583 | compilerWithFileSystems.inputFileSystem,
|
626 |
| - this._compilerHost, |
627 | 584 | );
|
628 |
| - compilerWithFileSystems.inputFileSystem = inputDecorator; |
629 | 585 |
|
630 | 586 | let replacements: Map<Path, Path> | ((path: Path) => Path) | undefined;
|
631 | 587 | if (this._options.hostReplacementPaths) {
|
632 |
| - if (typeof this._options.hostReplacementPaths === 'function') { |
| 588 | + if (typeof this._options.hostReplacementPaths == 'function') { |
633 | 589 | const replacementResolver = this._options.hostReplacementPaths;
|
634 | 590 | replacements = path => normalize(replacementResolver(getSystemPath(path)));
|
| 591 | + host = new class extends virtualFs.ResolverHost<fs.Stats> { |
| 592 | + _resolve(path: Path) { |
| 593 | + return normalize(replacementResolver(getSystemPath(path))); |
| 594 | + } |
| 595 | + }(host); |
635 | 596 | } else {
|
636 | 597 | replacements = new Map();
|
637 |
| - for (const replace in this._options.hostReplacementPaths) { |
638 |
| - replacements.set( |
639 |
| - normalize(replace), |
640 |
| - normalize(this._options.hostReplacementPaths[replace]), |
641 |
| - ); |
| 598 | + const aliasHost = new virtualFs.AliasHost(host); |
| 599 | + for (const from in this._options.hostReplacementPaths) { |
| 600 | + const normalizedFrom = normalize(from); |
| 601 | + const normalizedWith = normalize(this._options.hostReplacementPaths[from]); |
| 602 | + aliasHost.aliases.set(normalizedFrom, normalizedWith); |
| 603 | + replacements.set(normalizedFrom, normalizedWith); |
642 | 604 | }
|
| 605 | + host = aliasHost; |
643 | 606 | }
|
644 | 607 | }
|
645 | 608 |
|
| 609 | + // Create the webpack compiler host. |
| 610 | + const webpackCompilerHost = new WebpackCompilerHost( |
| 611 | + this._compilerOptions, |
| 612 | + this._basePath, |
| 613 | + host, |
| 614 | + ); |
| 615 | + webpackCompilerHost.enableCaching(); |
| 616 | + |
| 617 | + // Create and set a new WebpackResourceLoader. |
| 618 | + this._resourceLoader = new WebpackResourceLoader(); |
| 619 | + webpackCompilerHost.setResourceLoader(this._resourceLoader); |
| 620 | + |
| 621 | + // Use the WebpackCompilerHost with a resource loader to create an AngularCompilerHost. |
| 622 | + this._compilerHost = createCompilerHost({ |
| 623 | + options: this._compilerOptions, |
| 624 | + tsHost: webpackCompilerHost, |
| 625 | + }) as CompilerHost & WebpackCompilerHost; |
| 626 | + |
| 627 | + // Resolve mainPath if provided. |
| 628 | + if (this._options.mainPath) { |
| 629 | + this._mainPath = this._compilerHost.resolve(this._options.mainPath); |
| 630 | + } |
| 631 | + |
| 632 | + const inputDecorator = new VirtualFileSystemDecorator( |
| 633 | + compilerWithFileSystems.inputFileSystem, |
| 634 | + this._compilerHost, |
| 635 | + ); |
| 636 | + compilerWithFileSystems.inputFileSystem = inputDecorator; |
646 | 637 | compilerWithFileSystems.watchFileSystem = new VirtualWatchFileSystemDecorator(
|
647 | 638 | inputDecorator,
|
648 | 639 | replacements,
|
|
0 commit comments