@rushstack/webpack5-localization-plugin 0.7.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tsdoc-metadata.json +1 -1
- package/dist/webpack5-localization-plugin.d.ts +25 -0
- package/lib/TrueHashPlugin.d.ts +24 -0
- package/lib/TrueHashPlugin.d.ts.map +1 -0
- package/lib/TrueHashPlugin.js +31 -0
- package/lib/TrueHashPlugin.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/trueHashes.d.ts.map +1 -1
- package/lib/trueHashes.js +8 -7
- package/lib/trueHashes.js.map +1 -1
- package/package.json +1 -1
package/dist/tsdoc-metadata.json
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
|
1
3
|
import type { Chunk } from 'webpack';
|
2
4
|
import type { Compiler } from 'webpack';
|
3
5
|
import { ILocalizationFile } from '@rushstack/localization-utilities';
|
@@ -238,6 +240,20 @@ export declare interface _IStringPlaceholder {
|
|
238
240
|
stringName: string;
|
239
241
|
}
|
240
242
|
|
243
|
+
/**
|
244
|
+
* @public
|
245
|
+
*/
|
246
|
+
export declare interface ITrueHashPluginOptions {
|
247
|
+
/**
|
248
|
+
* A function that takes the contents of a file and returns a hash.
|
249
|
+
*/
|
250
|
+
hashFunction?: (contents: string | Buffer) => string;
|
251
|
+
/**
|
252
|
+
* Optionally override the process assets stage for this plugin.
|
253
|
+
*/
|
254
|
+
stageOverride?: number;
|
255
|
+
}
|
256
|
+
|
241
257
|
/**
|
242
258
|
* This plugin facilitates localization in webpack.
|
243
259
|
*
|
@@ -288,4 +304,13 @@ export declare class LocalizationPlugin implements WebpackPluginInstance {
|
|
288
304
|
private _initializeAndValidateOptions;
|
289
305
|
}
|
290
306
|
|
307
|
+
/**
|
308
|
+
* @public
|
309
|
+
*/
|
310
|
+
export declare class TrueHashPlugin implements WebpackPluginInstance {
|
311
|
+
private readonly _options;
|
312
|
+
constructor(options?: ITrueHashPluginOptions);
|
313
|
+
apply(compiler: Compiler): void;
|
314
|
+
}
|
315
|
+
|
291
316
|
export { }
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/// <reference types="node" />
|
2
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
3
|
+
/**
|
4
|
+
* @public
|
5
|
+
*/
|
6
|
+
export interface ITrueHashPluginOptions {
|
7
|
+
/**
|
8
|
+
* A function that takes the contents of a file and returns a hash.
|
9
|
+
*/
|
10
|
+
hashFunction?: (contents: string | Buffer) => string;
|
11
|
+
/**
|
12
|
+
* Optionally override the process assets stage for this plugin.
|
13
|
+
*/
|
14
|
+
stageOverride?: number;
|
15
|
+
}
|
16
|
+
/**
|
17
|
+
* @public
|
18
|
+
*/
|
19
|
+
export declare class TrueHashPlugin implements WebpackPluginInstance {
|
20
|
+
private readonly _options;
|
21
|
+
constructor(options?: ITrueHashPluginOptions);
|
22
|
+
apply(compiler: Compiler): void;
|
23
|
+
}
|
24
|
+
//# sourceMappingURL=TrueHashPlugin.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TrueHashPlugin.d.ts","sourceRoot":"","sources":["../src/TrueHashPlugin.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAe,QAAQ,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAM5E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;IAErD;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,cAAe,YAAW,qBAAqB;IAC1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;gBAE/B,OAAO,GAAE,sBAA2B;IAIhD,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;CAqBvC"}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
3
|
+
// See LICENSE in the project root for license information.
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
+
exports.TrueHashPlugin = void 0;
|
6
|
+
const trueHashes_1 = require("./trueHashes");
|
7
|
+
const PLUGIN_NAME = 'true-hash';
|
8
|
+
/**
|
9
|
+
* @public
|
10
|
+
*/
|
11
|
+
class TrueHashPlugin {
|
12
|
+
constructor(options = {}) {
|
13
|
+
this._options = options;
|
14
|
+
}
|
15
|
+
apply(compiler) {
|
16
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
17
|
+
const { webpack: thisWebpack } = compiler;
|
18
|
+
const { hashFunction, stageOverride = thisWebpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE } = this._options;
|
19
|
+
const hashFn = hashFunction !== null && hashFunction !== void 0 ? hashFunction : (0, trueHashes_1.getHashFunction)({
|
20
|
+
thisWebpack,
|
21
|
+
compilation
|
22
|
+
});
|
23
|
+
compilation.hooks.processAssets.tap({
|
24
|
+
name: PLUGIN_NAME,
|
25
|
+
stage: stageOverride
|
26
|
+
}, () => (0, trueHashes_1.updateAssetHashes)({ thisWebpack, compilation, hashFn }));
|
27
|
+
});
|
28
|
+
}
|
29
|
+
}
|
30
|
+
exports.TrueHashPlugin = TrueHashPlugin;
|
31
|
+
//# sourceMappingURL=TrueHashPlugin.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"TrueHashPlugin.js","sourceRoot":"","sources":["../src/TrueHashPlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D,6CAA+E;AAE/E,MAAM,WAAW,GAAgB,WAAW,CAAC;AAiB7C;;GAEG;AACH,MAAa,cAAc;IAGzB,YAAmB,UAAkC,EAAE;QACrD,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,QAAkB;QAC7B,QAAQ,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,WAAwB,EAAE,EAAE;YAC3E,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,QAAQ,CAAC;YAC1C,MAAM,EAAE,YAAY,EAAE,aAAa,GAAG,WAAW,CAAC,WAAW,CAAC,8BAA8B,EAAE,GAC5F,IAAI,CAAC,QAAQ,CAAC;YAChB,MAAM,MAAM,GACV,YAAY,aAAZ,YAAY,cAAZ,YAAY,GACZ,IAAA,4BAAe,EAAC;gBACd,WAAW;gBACX,WAAW;aACZ,CAAC,CAAC;YAEL,WAAW,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,CACjC;gBACE,IAAI,EAAE,WAAW;gBACjB,KAAK,EAAE,aAAa;aACrB,EACD,GAAG,EAAE,CAAC,IAAA,8BAAiB,EAAC,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,CAC9D,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA5BD,wCA4BC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';\n\nimport { type HashFn, getHashFunction, updateAssetHashes } from './trueHashes';\n\nconst PLUGIN_NAME: 'true-hash' = 'true-hash';\n\n/**\n * @public\n */\nexport interface ITrueHashPluginOptions {\n /**\n * A function that takes the contents of a file and returns a hash.\n */\n hashFunction?: (contents: string | Buffer) => string;\n\n /**\n * Optionally override the process assets stage for this plugin.\n */\n stageOverride?: number;\n}\n\n/**\n * @public\n */\nexport class TrueHashPlugin implements WebpackPluginInstance {\n private readonly _options: ITrueHashPluginOptions;\n\n public constructor(options: ITrueHashPluginOptions = {}) {\n this._options = options;\n }\n\n public apply(compiler: Compiler): void {\n compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation: Compilation) => {\n const { webpack: thisWebpack } = compiler;\n const { hashFunction, stageOverride = thisWebpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE } =\n this._options;\n const hashFn: HashFn =\n hashFunction ??\n getHashFunction({\n thisWebpack,\n compilation\n });\n\n compilation.hooks.processAssets.tap(\n {\n name: PLUGIN_NAME,\n stage: stageOverride\n },\n () => updateAssetHashes({ thisWebpack, compilation, hashFn })\n );\n });\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { LocalizationPlugin, type IStringPlaceholder as _IStringPlaceholder } from './LocalizationPlugin';
|
2
|
+
export { TrueHashPlugin, type ITrueHashPluginOptions } from './TrueHashPlugin';
|
2
3
|
export { IDefaultLocaleOptions, ILocaleData, ILocaleElementMap, ILocaleFileData, ILocaleFileObject, ILocalizationPluginOptions, ILocalizationStats, ILocalizationStatsChunkGroup, ILocalizationStatsEntrypoint, ILocalizationStatsOptions, ILocalizedData, ILocalizedStrings, IPassthroughLocaleOptions, IPseudolocalesOptions, IResolvedMissingTranslations } from './interfaces';
|
3
4
|
export { ILocalizedWebpackChunk } from './webpackInterfaces';
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,IAAI,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,KAAK,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,0BAA0B,EAC1B,kBAAkB,EAClB,4BAA4B,EAC5B,4BAA4B,EAC5B,yBAAyB,EACzB,cAAc,EACd,iBAAiB,EACjB,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
3
3
|
// See LICENSE in the project root for license information.
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
-
exports.LocalizationPlugin = void 0;
|
5
|
+
exports.TrueHashPlugin = exports.LocalizationPlugin = void 0;
|
6
6
|
var LocalizationPlugin_1 = require("./LocalizationPlugin");
|
7
7
|
Object.defineProperty(exports, "LocalizationPlugin", { enumerable: true, get: function () { return LocalizationPlugin_1.LocalizationPlugin; } });
|
8
|
+
var TrueHashPlugin_1 = require("./TrueHashPlugin");
|
9
|
+
Object.defineProperty(exports, "TrueHashPlugin", { enumerable: true, get: function () { return TrueHashPlugin_1.TrueHashPlugin; } });
|
8
10
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAA0G;AAAjG,wHAAA,kBAAkB,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport { LocalizationPlugin, type IStringPlaceholder as _IStringPlaceholder } from './LocalizationPlugin';\n\nexport {\n IDefaultLocaleOptions,\n ILocaleData,\n ILocaleElementMap,\n ILocaleFileData,\n ILocaleFileObject,\n ILocalizationPluginOptions,\n ILocalizationStats,\n ILocalizationStatsChunkGroup,\n ILocalizationStatsEntrypoint,\n ILocalizationStatsOptions,\n ILocalizedData,\n ILocalizedStrings,\n IPassthroughLocaleOptions,\n IPseudolocalesOptions,\n IResolvedMissingTranslations\n} from './interfaces';\
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2DAA0G;AAAjG,wHAAA,kBAAkB,OAAA;AAC3B,mDAA+E;AAAtE,gHAAA,cAAc,OAAA","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nexport { LocalizationPlugin, type IStringPlaceholder as _IStringPlaceholder } from './LocalizationPlugin';\nexport { TrueHashPlugin, type ITrueHashPluginOptions } from './TrueHashPlugin';\n\nexport {\n IDefaultLocaleOptions,\n ILocaleData,\n ILocaleElementMap,\n ILocaleFileData,\n ILocaleFileObject,\n ILocalizationPluginOptions,\n ILocalizationStats,\n ILocalizationStatsChunkGroup,\n ILocalizationStatsEntrypoint,\n ILocalizationStatsOptions,\n ILocalizedData,\n ILocalizedStrings,\n IPassthroughLocaleOptions,\n IPseudolocalesOptions,\n IResolvedMissingTranslations\n} from './interfaces';\nexport { ILocalizedWebpackChunk } from './webpackInterfaces';\n"]}
|
package/lib/trueHashes.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"trueHashes.d.ts","sourceRoot":"","sources":["../src/trueHashes.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,WAAW,
|
1
|
+
{"version":3,"file":"trueHashes.d.ts","sourceRoot":"","sources":["../src/trueHashes.ts"],"names":[],"mappings":";AAGA,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,WAAW,EAA+B,MAAM,SAAS,CAAC;AAY5F,MAAM,MAAM,MAAM,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,KAAK,MAAM,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC,WAAW,EAAE,OAAO,OAAO,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED,wBAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,EAAE,uBAAuB,GAAG,MAAM,CAU7F;AAED,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,OAAO,OAAO,CAAC;IAC5B,WAAW,EAAE,WAAW,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACxD;AAOD,wBAAgB,iBAAiB,CAAC,EAChC,WAAW,EACX,WAAW,EACX,MAAM,EACN,gBAAgB,EACjB,EAAE,yBAAyB,GAAG,IAAI,CAoOlC"}
|
package/lib/trueHashes.js
CHANGED
@@ -5,13 +5,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.updateAssetHashes = exports.getHashFunction = void 0;
|
6
6
|
const node_core_library_1 = require("@rushstack/node-core-library");
|
7
7
|
function getHashFunction({ thisWebpack, compilation }) {
|
8
|
-
const { hashFunction = 'md5', hashDigest = 'hex', hashDigestLength } = compilation.outputOptions;
|
9
|
-
return (contents) =>
|
10
|
-
.createHash(hashFunction)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
.slice(0, hashDigestLength);
|
8
|
+
const { hashFunction = 'md5', hashDigest = 'hex', hashDigestLength, hashSalt } = compilation.outputOptions;
|
9
|
+
return (contents) => {
|
10
|
+
const hash = thisWebpack.util.createHash(hashFunction);
|
11
|
+
if (hashSalt) {
|
12
|
+
hash.update(hashSalt, 'utf-8');
|
13
|
+
}
|
14
|
+
return hash.update(contents).digest(hashDigest).toString().slice(0, hashDigestLength);
|
15
|
+
};
|
15
16
|
}
|
16
17
|
exports.getHashFunction = getHashFunction;
|
17
18
|
function updateAssetHashes({ thisWebpack, compilation, hashFn, filesByChunkName }) {
|
package/lib/trueHashes.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"trueHashes.js","sourceRoot":"","sources":["../src/trueHashes.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAAoD;AAgBpD,SAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,WAAW,EAA2B;IACnF,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,gBAAgB,EAAE,GAAG,WAAW,CAAC,aAAa,CAAC;IACjG,OAAO,CAAC,QAAyB,EAAE,EAAE,CACnC,WAAW,CAAC,IAAI;SACb,UAAU,CAAC,YAAY,CAAC;SACxB,MAAM,CAAC,QAAQ,CAAC;SAChB,MAAM,CAAC,UAAU,CAAC;SAClB,QAAQ,EAAE;SACV,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;AAClC,CAAC;AATD,0CASC;AAcD,SAAgB,iBAAiB,CAAC,EAChC,WAAW,EACX,WAAW,EACX,MAAM,EACN,gBAAgB,EACU;;IAC1B,MAAM,8BAA8B,GAA2B,IAAI,GAAG,EAAE,CAAC;IACzE,MAAM,mBAAmB,GAA2B,IAAI,GAAG,EAAE,CAAC;IAC9D,MAAM,iBAAiB,GAA2B,IAAI,GAAG,EAAE,CAAC;IAC5D,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,uBAAuB,GAA2B,8BAA8B,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAChG,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;YACpC,8BAA8B,CAAC,GAAG,CAAC,KAAK,EAAE,uBAAuB,CAAC,CAAC;QACrE,CAAC;QAED,IAAI,YAAY,GAA2B,mBAAmB,CAAC,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MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { default as webpack, Compilation, Chunk, Asset, sources } from 'webpack';\nimport { Text } from '@rushstack/node-core-library';\n\nimport type { ILocalizedWebpackChunk } from './webpackInterfaces';\n\ninterface IHashReplacement {\n existingHash: string;\n trueHashByLocale: string | Record<string, string> | undefined;\n}\n\nexport type HashFn = (contents: string | Buffer) => string;\n\nexport interface IGetHashFunctionOptions {\n thisWebpack: typeof webpack;\n compilation: Compilation;\n}\n\nexport function getHashFunction({ thisWebpack, compilation }: IGetHashFunctionOptions): HashFn {\n const { hashFunction = 'md5', hashDigest = 'hex', hashDigestLength } = compilation.outputOptions;\n return (contents: string | Buffer) =>\n thisWebpack.util\n .createHash(hashFunction)\n .update(contents)\n .digest(hashDigest)\n .toString()\n .slice(0, hashDigestLength);\n}\n\nexport interface IUpdateAssetHashesOptions {\n thisWebpack: typeof webpack;\n compilation: Compilation;\n hashFn: HashFn;\n filesByChunkName?: Map<string, Record<string, string>>;\n}\n\ninterface IProcessChunkAssetResult {\n trueHash: string;\n newJsFilename: string;\n}\n\nexport function updateAssetHashes({\n thisWebpack,\n compilation,\n hashFn,\n filesByChunkName\n}: IUpdateAssetHashesOptions): void {\n const unprocessedDependenciesByChunk: Map<Chunk, Set<Chunk>> = new Map();\n const dependenciesByChunk: Map<Chunk, Set<Chunk>> = new Map();\n const dependentsByChunk: Map<Chunk, Set<Chunk>> = new Map();\n for (const chunk of compilation.chunks) {\n let unprocessedDependencies: Set<Chunk> | undefined = unprocessedDependenciesByChunk.get(chunk);\n if (!unprocessedDependencies) {\n unprocessedDependencies = new Set();\n unprocessedDependenciesByChunk.set(chunk, unprocessedDependencies);\n }\n\n let dependencies: Set<Chunk> | undefined = dependenciesByChunk.get(chunk);\n if (!dependencies) {\n dependencies = new Set();\n dependenciesByChunk.set(chunk, dependencies);\n }\n\n if (chunk.hasRuntime()) {\n for (const asyncChunk of chunk.getAllAsyncChunks()) {\n unprocessedDependencies.add(asyncChunk);\n dependencies.add(asyncChunk);\n\n let dependents: Set<Chunk> | undefined = dependentsByChunk.get(asyncChunk);\n if (!dependents) {\n dependents = new Set();\n dependentsByChunk.set(asyncChunk, dependents);\n }\n\n dependents.add(chunk);\n }\n }\n }\n\n const hashReplacementsByChunk: Map<Chunk, IHashReplacement> = new Map();\n const unprocessedChunks: Set<Chunk> = new Set(compilation.chunks);\n let previousSize: number = -1;\n while (unprocessedChunks.size > 0) {\n const currentSize: number = unprocessedChunks.size;\n if (currentSize === previousSize) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Detected a cycle in the chunk dependencies. This should not be possible.`\n )\n );\n\n break;\n }\n\n previousSize = currentSize;\n\n for (const chunk of unprocessedChunks) {\n if (unprocessedDependenciesByChunk.get(chunk)?.size === 0) {\n // TODO: do we need to check if the chunk is rendered?\n if (!chunk.renderedHash) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find the hash for chunk ${chunk.id}.`)\n );\n } else {\n const existingHash: string = chunk.contentHash.javascript;\n const chunkDependencies: Set<Chunk> | undefined = dependenciesByChunk.get(chunk);\n if (!chunkDependencies) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find dependencies for chunk ${chunk.id}.`)\n );\n } else {\n function processChunkAsset(\n jsAssetName: string,\n locale: string | undefined\n ): IProcessChunkAssetResult | undefined {\n const asset: Readonly<Asset> | undefined = compilation.getAsset(jsAssetName);\n if (!asset) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find asset \"${jsAssetName}\" for chunk ${chunk.id}.`)\n );\n } else {\n let assetSource: sources.Source = asset.source;\n const assetName: string = asset.name;\n if (chunkDependencies!.size > 0) {\n const relevantHashReplacements: Map<string, string> = new Map();\n let hasAnyReplacements: boolean = false;\n for (const dependency of chunkDependencies!) {\n const asyncChunkHashReplacements: IHashReplacement | undefined =\n hashReplacementsByChunk.get(dependency);\n if (!asyncChunkHashReplacements) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Could not find hash replacements for chunk ${dependency.id}.`\n )\n );\n } else {\n const { existingHash: otherChunkExistingHash, trueHashByLocale } =\n asyncChunkHashReplacements;\n let replacementHash: string | undefined;\n if (typeof trueHashByLocale === 'object') {\n if (locale) {\n replacementHash = trueHashByLocale[locale];\n }\n } else {\n replacementHash = trueHashByLocale;\n }\n\n if (replacementHash) {\n if (relevantHashReplacements.has(otherChunkExistingHash)) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Found multiple replacements for hash ${otherChunkExistingHash} ` +\n `in chunk ${chunk.id}.`\n )\n );\n } else {\n relevantHashReplacements.set(otherChunkExistingHash, replacementHash);\n hasAnyReplacements = true;\n }\n }\n }\n }\n\n if (hasAnyReplacements) {\n const sourceString: string = assetSource.source().toString();\n const replaceSource: sources.ReplaceSource = new thisWebpack.sources.ReplaceSource(\n assetSource,\n assetName\n );\n\n const regexp: RegExp = new RegExp(\n Array.from(relevantHashReplacements.keys())\n .map((hashToReplace) => Text.escapeRegExp(hashToReplace))\n .join('|'),\n 'g'\n );\n let match: RegExpMatchArray | null;\n while ((match = regexp.exec(sourceString)) !== null) {\n const { 0: originalHash, index } = match;\n const matchStart: number = index!;\n const matchEnd: number = matchStart + originalHash.length - 1;\n const replacement: string = relevantHashReplacements.get(originalHash)!;\n replaceSource.replace(matchStart, matchEnd, replacement);\n }\n\n assetSource = replaceSource;\n compilation.updateAsset(jsAssetName, assetSource);\n }\n }\n\n if (jsAssetName.includes(existingHash)) {\n const trueHash: string = hashFn(assetSource.buffer());\n if (trueHash !== existingHash) {\n const newJsFilename: string = jsAssetName.replace(existingHash, trueHash);\n compilation.renameAsset(jsAssetName, newJsFilename);\n\n if (locale) {\n const filesForChunkName: Record<string, string> | undefined = filesByChunkName?.get(\n chunk.name\n );\n if (filesForChunkName) {\n filesForChunkName[locale] = newJsFilename;\n }\n }\n\n return {\n trueHash,\n newJsFilename\n };\n }\n }\n }\n }\n\n const localizedFiles: Record<string, string> | undefined = (chunk as ILocalizedWebpackChunk)\n .localizedFiles;\n if (localizedFiles) {\n const trueHashByLocale: Record<string, string> = {};\n hashReplacementsByChunk.set(chunk, {\n existingHash,\n trueHashByLocale\n });\n for (const [locale, jsAssetName] of Object.entries(localizedFiles)) {\n const processAssetResult: IProcessChunkAssetResult | undefined = processChunkAsset(\n jsAssetName,\n locale\n );\n if (processAssetResult) {\n const { trueHash, newJsFilename } = processAssetResult;\n trueHashByLocale[locale] = trueHash;\n localizedFiles[locale] = newJsFilename;\n }\n }\n } else {\n const assetNames: string[] = Array.from(chunk.files);\n let jsAssetName: string | undefined;\n for (const assetName of assetNames) {\n if (assetName.endsWith('.js')) {\n if (jsAssetName) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Found multiple .js assets for chunk ${chunk.id}.`)\n );\n } else {\n jsAssetName = assetName;\n }\n }\n }\n\n if (!jsAssetName) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find a .js asset for chunk ${chunk.id}.`)\n );\n } else {\n const { trueHash, newJsFilename } = processChunkAsset(jsAssetName, undefined) ?? {};\n hashReplacementsByChunk.set(chunk, { existingHash, trueHashByLocale: trueHash });\n if (newJsFilename) {\n chunk.files.delete(jsAssetName);\n chunk.files.add(newJsFilename);\n }\n }\n }\n }\n\n unprocessedChunks.delete(chunk);\n const dependents: Set<Chunk> | undefined = dependentsByChunk.get(chunk);\n if (dependents) {\n for (const dependent of dependents) {\n unprocessedDependenciesByChunk.get(dependent)?.delete(chunk);\n }\n }\n }\n }\n }\n }\n}\n"]}
|
1
|
+
{"version":3,"file":"trueHashes.js","sourceRoot":"","sources":["../src/trueHashes.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAAoD;AAkBpD,SAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,WAAW,EAA2B;IACnF,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,UAAU,GAAG,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,GAAG,WAAW,CAAC,aAAa,CAAC;IAC3G,OAA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IAAI,CACrB,IAAI,WAAW,CAAC,YAAY,CAAC,wCAAwC,KAAK,CAAC,EAAE,GAAG,CAAC,CAClF,CAAC;4BACJ,CAAC;iCAAM,CAAC;gCACN,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,GAAG,MAAA,iBAAiB,CAAC,WAAW,EAAE,SAAS,CAAC,mCAAI,EAAE,CAAC;gCACpF,uBAAuB,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,YAAY,EAAE,gBAAgB,EAAE,QAAQ,EAAE,CAAC,CAAC;gCACjF,IAAI,aAAa,EAAE,CAAC;oCAClB,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;oCAChC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;gCACjC,CAAC;4BACH,CAAC;wBACH,CAAC;oBACH,CAAC;oBAED,iBAAiB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAChC,MAAM,UAAU,GAA2B,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBACxE,IAAI,UAAU,EAAE,CAAC;wBACf,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;4BACnC,MAAA,8BAA8B,CAAC,GAAG,CAAC,SAAS,CAAC,0CAAE,MAAM,CAAC,KAAK,CAAC,CAAC;wBAC/D,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;AACH,CAAC;AAzOD,8CAyOC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { default as webpack, Compilation, Chunk, Asset, sources, util } from 'webpack';\nimport { Text } from '@rushstack/node-core-library';\n\nimport type { ILocalizedWebpackChunk } from './webpackInterfaces';\n\ninterface IHashReplacement {\n existingHash: string;\n trueHashByLocale: string | Record<string, string> | undefined;\n}\n\ntype WebpackHash = ReturnType<typeof util.createHash>;\n\nexport type HashFn = (contents: string | Buffer) => string;\n\nexport interface IGetHashFunctionOptions {\n thisWebpack: typeof webpack;\n compilation: Compilation;\n}\n\nexport function getHashFunction({ thisWebpack, compilation }: IGetHashFunctionOptions): HashFn {\n const { hashFunction = 'md5', hashDigest = 'hex', hashDigestLength, hashSalt } = compilation.outputOptions;\n return (contents: string | Buffer) => {\n const hash: WebpackHash = thisWebpack.util.createHash(hashFunction);\n if (hashSalt) {\n hash.update(hashSalt, 'utf-8');\n }\n\n return hash.update(contents).digest(hashDigest).toString().slice(0, hashDigestLength);\n };\n}\n\nexport interface IUpdateAssetHashesOptions {\n thisWebpack: typeof webpack;\n compilation: Compilation;\n hashFn: HashFn;\n filesByChunkName?: Map<string, Record<string, string>>;\n}\n\ninterface IProcessChunkAssetResult {\n trueHash: string;\n newJsFilename: string;\n}\n\nexport function updateAssetHashes({\n thisWebpack,\n compilation,\n hashFn,\n filesByChunkName\n}: IUpdateAssetHashesOptions): void {\n const unprocessedDependenciesByChunk: Map<Chunk, Set<Chunk>> = new Map();\n const dependenciesByChunk: Map<Chunk, Set<Chunk>> = new Map();\n const dependentsByChunk: Map<Chunk, Set<Chunk>> = new Map();\n for (const chunk of compilation.chunks) {\n let unprocessedDependencies: Set<Chunk> | undefined = unprocessedDependenciesByChunk.get(chunk);\n if (!unprocessedDependencies) {\n unprocessedDependencies = new Set();\n unprocessedDependenciesByChunk.set(chunk, unprocessedDependencies);\n }\n\n let dependencies: Set<Chunk> | undefined = dependenciesByChunk.get(chunk);\n if (!dependencies) {\n dependencies = new Set();\n dependenciesByChunk.set(chunk, dependencies);\n }\n\n if (chunk.hasRuntime()) {\n for (const asyncChunk of chunk.getAllAsyncChunks()) {\n unprocessedDependencies.add(asyncChunk);\n dependencies.add(asyncChunk);\n\n let dependents: Set<Chunk> | undefined = dependentsByChunk.get(asyncChunk);\n if (!dependents) {\n dependents = new Set();\n dependentsByChunk.set(asyncChunk, dependents);\n }\n\n dependents.add(chunk);\n }\n }\n }\n\n const hashReplacementsByChunk: Map<Chunk, IHashReplacement> = new Map();\n const unprocessedChunks: Set<Chunk> = new Set(compilation.chunks);\n let previousSize: number = -1;\n while (unprocessedChunks.size > 0) {\n const currentSize: number = unprocessedChunks.size;\n if (currentSize === previousSize) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Detected a cycle in the chunk dependencies. This should not be possible.`\n )\n );\n\n break;\n }\n\n previousSize = currentSize;\n\n for (const chunk of unprocessedChunks) {\n if (unprocessedDependenciesByChunk.get(chunk)?.size === 0) {\n // TODO: do we need to check if the chunk is rendered?\n if (!chunk.renderedHash) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find the hash for chunk ${chunk.id}.`)\n );\n } else {\n const existingHash: string = chunk.contentHash.javascript;\n const chunkDependencies: Set<Chunk> | undefined = dependenciesByChunk.get(chunk);\n if (!chunkDependencies) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find dependencies for chunk ${chunk.id}.`)\n );\n } else {\n function processChunkAsset(\n jsAssetName: string,\n locale: string | undefined\n ): IProcessChunkAssetResult | undefined {\n const asset: Readonly<Asset> | undefined = compilation.getAsset(jsAssetName);\n if (!asset) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find asset \"${jsAssetName}\" for chunk ${chunk.id}.`)\n );\n } else {\n let assetSource: sources.Source = asset.source;\n const assetName: string = asset.name;\n if (chunkDependencies!.size > 0) {\n const relevantHashReplacements: Map<string, string> = new Map();\n let hasAnyReplacements: boolean = false;\n for (const dependency of chunkDependencies!) {\n const asyncChunkHashReplacements: IHashReplacement | undefined =\n hashReplacementsByChunk.get(dependency);\n if (!asyncChunkHashReplacements) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Could not find hash replacements for chunk ${dependency.id}.`\n )\n );\n } else {\n const { existingHash: otherChunkExistingHash, trueHashByLocale } =\n asyncChunkHashReplacements;\n let replacementHash: string | undefined;\n if (typeof trueHashByLocale === 'object') {\n if (locale) {\n replacementHash = trueHashByLocale[locale];\n }\n } else {\n replacementHash = trueHashByLocale;\n }\n\n if (replacementHash) {\n if (relevantHashReplacements.has(otherChunkExistingHash)) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Found multiple replacements for hash ${otherChunkExistingHash} ` +\n `in chunk ${chunk.id}.`\n )\n );\n } else {\n relevantHashReplacements.set(otherChunkExistingHash, replacementHash);\n hasAnyReplacements = true;\n }\n }\n }\n }\n\n if (hasAnyReplacements) {\n const sourceString: string = assetSource.source().toString();\n const replaceSource: sources.ReplaceSource = new thisWebpack.sources.ReplaceSource(\n assetSource,\n assetName\n );\n\n const regexp: RegExp = new RegExp(\n Array.from(relevantHashReplacements.keys())\n .map((hashToReplace) => Text.escapeRegExp(hashToReplace))\n .join('|'),\n 'g'\n );\n let match: RegExpMatchArray | null;\n while ((match = regexp.exec(sourceString)) !== null) {\n const { 0: originalHash, index } = match;\n const matchStart: number = index!;\n const matchEnd: number = matchStart + originalHash.length - 1;\n const replacement: string = relevantHashReplacements.get(originalHash)!;\n replaceSource.replace(matchStart, matchEnd, replacement);\n }\n\n assetSource = replaceSource;\n compilation.updateAsset(jsAssetName, assetSource);\n }\n }\n\n if (jsAssetName.includes(existingHash)) {\n const trueHash: string = hashFn(assetSource.buffer());\n if (trueHash !== existingHash) {\n const newJsFilename: string = jsAssetName.replace(existingHash, trueHash);\n compilation.renameAsset(jsAssetName, newJsFilename);\n\n if (locale) {\n const filesForChunkName: Record<string, string> | undefined = filesByChunkName?.get(\n chunk.name\n );\n if (filesForChunkName) {\n filesForChunkName[locale] = newJsFilename;\n }\n }\n\n return {\n trueHash,\n newJsFilename\n };\n }\n }\n }\n }\n\n const localizedFiles: Record<string, string> | undefined = (chunk as ILocalizedWebpackChunk)\n .localizedFiles;\n if (localizedFiles) {\n const trueHashByLocale: Record<string, string> = {};\n hashReplacementsByChunk.set(chunk, {\n existingHash,\n trueHashByLocale\n });\n for (const [locale, jsAssetName] of Object.entries(localizedFiles)) {\n const processAssetResult: IProcessChunkAssetResult | undefined = processChunkAsset(\n jsAssetName,\n locale\n );\n if (processAssetResult) {\n const { trueHash, newJsFilename } = processAssetResult;\n trueHashByLocale[locale] = trueHash;\n localizedFiles[locale] = newJsFilename;\n }\n }\n } else {\n const assetNames: string[] = Array.from(chunk.files);\n let jsAssetName: string | undefined;\n for (const assetName of assetNames) {\n if (assetName.endsWith('.js')) {\n if (jsAssetName) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Found multiple .js assets for chunk ${chunk.id}.`)\n );\n } else {\n jsAssetName = assetName;\n }\n }\n }\n\n if (!jsAssetName) {\n compilation.errors.push(\n new thisWebpack.WebpackError(`Could not find a .js asset for chunk ${chunk.id}.`)\n );\n } else {\n const { trueHash, newJsFilename } = processChunkAsset(jsAssetName, undefined) ?? {};\n hashReplacementsByChunk.set(chunk, { existingHash, trueHashByLocale: trueHash });\n if (newJsFilename) {\n chunk.files.delete(jsAssetName);\n chunk.files.add(newJsFilename);\n }\n }\n }\n }\n\n unprocessedChunks.delete(chunk);\n const dependents: Set<Chunk> | undefined = dependentsByChunk.get(chunk);\n if (dependents) {\n for (const dependent of dependents) {\n unprocessedDependenciesByChunk.get(dependent)?.delete(chunk);\n }\n }\n }\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED