Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@ngtools/webpack): ensure plugin provided Webpack instance is used #21089

Merged
merged 1 commit into from Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/src/inline-data-loader.ts
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import { Compilation, LoaderContext } from 'webpack';
import type { Compilation, LoaderContext } from 'webpack';

export const InlineAngularResourceSymbol = Symbol();

Expand Down
1 change: 0 additions & 1 deletion packages/ngtools/webpack/src/ivy/cache.ts
Expand Up @@ -7,7 +7,6 @@
*/

import * as ts from 'typescript';
import { normalizePath } from './paths';

export class SourceFileCache extends Map<string, ts.SourceFile> {
private readonly angularDiagnostics = new Map<ts.SourceFile, ts.Diagnostic[]>();
Expand Down
11 changes: 3 additions & 8 deletions packages/ngtools/webpack/src/ivy/plugin.ts
Expand Up @@ -10,14 +10,7 @@ import { CompilerHost, CompilerOptions, readConfiguration } from '@angular/compi
import { NgtscProgram } from '@angular/compiler-cli/src/ngtsc/program';
import { createHash } from 'crypto';
import * as ts from 'typescript';
import {
Compilation,
Compiler,
Module,
NormalModule,
NormalModuleReplacementPlugin,
util,
} from 'webpack';
import type { Compilation, Compiler, Module, NormalModule } from 'webpack';
import { NgccProcessor } from '../ngcc_processor';
import { TypeScriptPathsPlugin } from '../paths-plugin';
import { WebpackResourceLoader } from '../resource_loader';
Expand Down Expand Up @@ -120,6 +113,8 @@ export class AngularWebpackPlugin {
}

apply(compiler: Compiler): void {
const { NormalModuleReplacementPlugin, util } = compiler.webpack;

// Setup file replacements with webpack
for (const [key, value] of Object.entries(this.pluginOptions.fileReplacements)) {
new NormalModuleReplacementPlugin(
Expand Down
7 changes: 4 additions & 3 deletions packages/ngtools/webpack/src/resource_loader.ts
Expand Up @@ -9,7 +9,7 @@
import { createHash } from 'crypto';
import * as path from 'path';
import * as vm from 'vm';
import { Asset, Compilation, EntryPlugin, NormalModule, library, node, sources } from 'webpack';
import type { Asset, Compilation } from 'webpack';
import {
CompilationWithInlineAngularResource,
InlineAngularResourceSymbol,
Expand Down Expand Up @@ -142,7 +142,8 @@ export class WebpackResourceLoader {
},
};

const context = this._parentCompilation.compiler.context;
const { context, webpack } = this._parentCompilation.compiler;
const { EntryPlugin, NormalModule, library, node, sources } = webpack;
const childCompiler = this._parentCompilation.createChildCompiler(
'angular-compiler:resource',
outputOptions,
Expand Down Expand Up @@ -204,7 +205,7 @@ export class WebpackResourceLoader {
let finalMap: string | undefined;
childCompiler.hooks.compilation.tap('angular-compiler', (childCompilation) => {
childCompilation.hooks.processAssets.tap(
{ name: 'angular-compiler', stage: Compilation.PROCESS_ASSETS_STAGE_REPORT },
{ name: 'angular-compiler', stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT },
() => {
finalContent = childCompilation.assets[outputFilePath]?.source().toString();
finalMap = childCompilation.assets[outputFilePath + '.map']?.source().toString();
Expand Down
6 changes: 3 additions & 3 deletions packages/ngtools/webpack/src/webpack-diagnostics.ts
Expand Up @@ -6,12 +6,12 @@
* found in the LICENSE file at https://angular.io/license
*/

import { Compilation, WebpackError } from 'webpack';
import type { Compilation } from 'webpack';

export function addWarning(compilation: Compilation, message: string): void {
compilation.warnings.push(new WebpackError(message));
compilation.warnings.push(new compilation.compiler.webpack.WebpackError(message));
}

export function addError(compilation: Compilation, message: string): void {
compilation.errors.push(new WebpackError(message));
compilation.errors.push(new compilation.compiler.webpack.WebpackError(message));
}