Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ngtools/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"peerDependencies": {
"@angular/compiler-cli": "^14.0.0 || ^14.0.0-next",
"typescript": "~4.6.2",
"webpack": "^5.30.0"
"webpack": "^5.54.0"
},
"devDependencies": {
"@angular-devkit/core": "0.0.0-PLACEHOLDER",
Expand Down
7 changes: 5 additions & 2 deletions packages/ngtools/webpack/src/ivy/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import type { CompilerHost, CompilerOptions, NgtscProgram } from '@angular/compiler-cli';
import { strict as assert } from 'assert';
import { createHash } from 'crypto';
import * as ts from 'typescript';
import type { Compilation, Compiler, Module, NormalModule } from 'webpack';
import { NgccProcessor } from '../ngcc_processor';
Expand Down Expand Up @@ -107,6 +106,7 @@ export class AngularWebpackPlugin {
private builder?: ts.EmitAndSemanticDiagnosticsBuilderProgram;
private sourceFileCache?: SourceFileCache;
private webpackCache?: ReturnType<Compilation['getCache']>;
private webpackCreateHash?: Compiler['webpack']['util']['createHash'];
private readonly fileDependencies = new Map<string, Set<string>>();
private readonly requiredFilesToEmit = new Set<string>();
private readonly requiredFilesToEmitCache = new Map<string, EmitFileResult | undefined>();
Expand Down Expand Up @@ -141,6 +141,7 @@ export class AngularWebpackPlugin {
// eslint-disable-next-line max-lines-per-function
apply(compiler: Compiler): void {
const { NormalModuleReplacementPlugin, util } = compiler.webpack;
this.webpackCreateHash = util.createHash;

// Setup file replacements with webpack
for (const [key, value] of Object.entries(this.pluginOptions.fileReplacements)) {
Expand Down Expand Up @@ -745,9 +746,11 @@ export class AngularWebpackPlugin {
filePath: string,
content: string,
): Promise<FileEmitHistoryItem> {
assert.ok(this.webpackCreateHash, 'File emitter is used prior to Webpack compilation');

const historyData: FileEmitHistoryItem = {
length: content.length,
hash: createHash('md5').update(content).digest(),
hash: this.webpackCreateHash('xxhash64').update(content).digest() as Uint8Array,
};

if (this.webpackCache) {
Expand Down
18 changes: 14 additions & 4 deletions packages/ngtools/webpack/src/resource_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* found in the LICENSE file at https://angular.io/license
*/

import { createHash } from 'crypto';
import * as path from 'path';
import * as vm from 'vm';
import type { Asset, Compilation } from 'webpack';
Expand Down Expand Up @@ -100,6 +99,7 @@ export class WebpackResourceLoader {
this._reverseDependencies.set(file, new Set(resources));
}

// eslint-disable-next-line max-lines-per-function
private async _compile(
filePath?: string,
data?: string,
Expand All @@ -111,6 +111,16 @@ export class WebpackResourceLoader {
throw new Error('WebpackResourceLoader cannot be used without parentCompilation');
}

const { context, webpack } = this._parentCompilation.compiler;
const {
EntryPlugin,
NormalModule,
library,
node,
sources,
util: { createHash },
} = webpack;

const getEntry = (): string => {
if (filePath) {
return `${filePath}?${NG_COMPONENT_RESOURCE_QUERY}`;
Expand All @@ -122,7 +132,9 @@ export class WebpackResourceLoader {
);
} else if (data) {
// Create a special URL for reading the resource from memory
return `angular-resource:${resourceType},${createHash('md5').update(data).digest('hex')}`;
return `angular-resource:${resourceType},${createHash('xxhash64')
.update(data)
.digest('hex')}`;
}

throw new Error(`"filePath", "resourceType" or "data" must be specified.`);
Expand Down Expand Up @@ -150,8 +162,6 @@ export class WebpackResourceLoader {
},
};

const { context, webpack } = this._parentCompilation.compiler;
const { EntryPlugin, NormalModule, library, node, sources } = webpack;
const childCompiler = this._parentCompilation.createChildCompiler(
'angular-compiler:resource',
outputOptions,
Expand Down