@rushstack/webpack5-localization-plugin 0.11.26 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"trueHashes.js","sourceRoot":"","sources":["../src/trueHashes.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,oEAAoD;AAGpD,+DAAuD;AAgBvD,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,OAAO,CAAC,QAAyB,EAAE,EAAE;QACnC,MAAM,IAAI,GAAgB,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,CAAC;QACpE,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,gBAAgB,CAAC,CAAC;IACxF,CAAC,CAAC;AACJ,CAAC;AAVD,0CAUC;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,MAAM,iBAAiB,GAAe,IAAI,GAAG,EAAE,CAAC;IAChD,MAAM,WAAW,GAAe,IAAI,GAAG,EAAE,CAAC;IAE1C,KAAK,MAAM,KAAK,IAAI,WAAW,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC,IAAA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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;AAhQD,8CAgQC","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';\nimport { chunkIsJs } from './utilities/chunkUtilities';\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 const unprocessedChunks: Set<Chunk> = new Set();\n const nonJsChunks: Set<Chunk> = new Set();\n\n for (const chunk of compilation.chunks) {\n if (!chunkIsJs(chunk, compilation.chunkGraph)) {\n nonJsChunks.add(chunk);\n } else {\n unprocessedChunks.add(chunk);\n }\n }\n\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 if (!nonJsChunks.has(asyncChunk)) {\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 if (!unprocessedChunks.has(asyncChunk)) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Found an async chunk that was not included in the compilation: ${asyncChunk.id} ` +\n `(reason: ${asyncChunk.chunkReason}).`\n )\n );\n }\n }\n }\n }\n }\n\n const hashReplacementsByChunk: Map<Chunk, IHashReplacement> = new Map();\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\n compilation.renameAsset(jsAssetName, newJsFilename);\n\n if (locale) {\n const filesForChunkName: Record<string, string> | undefined = chunk.name\n ? filesByChunkName?.get(chunk.name)\n : undefined;\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;AAGpD,+DAAuD;AAgBvD,SAAgB,eAAe,CAAC,EAAE,WAAW,EAAE,WAAW,EAA2B;IACnF,MAAM,EAAE,YAAY,GAAG,KAAK,EAAE,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C,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;AAhQD,8CAgQC","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';\nimport { chunkIsJs } from './utilities/chunkUtilities';\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 const unprocessedChunks: Set<Chunk> = new Set();\n const nonJsChunks: Set<Chunk> = new Set();\n\n for (const chunk of compilation.chunks) {\n if (!chunkIsJs(chunk, compilation.chunkGraph)) {\n nonJsChunks.add(chunk);\n } else {\n unprocessedChunks.add(chunk);\n }\n }\n\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 if (!nonJsChunks.has(asyncChunk)) {\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 if (!unprocessedChunks.has(asyncChunk)) {\n compilation.errors.push(\n new thisWebpack.WebpackError(\n `Found an async chunk that was not included in the compilation: ${asyncChunk.id} ` +\n `(reason: ${asyncChunk.chunkReason}).`\n )\n );\n }\n }\n }\n }\n }\n\n const hashReplacementsByChunk: Map<Chunk, IHashReplacement> = new Map();\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(), (hashToReplace) =>\n 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 = new thisWebpack.sources.CachedSource(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\n compilation.renameAsset(jsAssetName, newJsFilename);\n\n if (locale) {\n const filesForChunkName: Record<string, string> | undefined = chunk.name\n ? filesByChunkName?.get(chunk.name)\n : undefined;\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"]}
@@ -7,6 +7,6 @@ export declare const RESOURCE_FILE_NAME_REGEXP: RegExp;
7
7
  export declare const STRING_PLACEHOLDER_LABEL: 'A';
8
8
  export declare const LOCALE_NAME_PLACEHOLDER_LABEL: 'B';
9
9
  export declare const JSONP_PLACEHOLDER_LABEL: 'C';
10
- export declare const LOCALE_NAME_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}__${typeof LOCALE_NAME_PLACEHOLDER_LABEL}_0`;
11
- export declare const JSONP_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}__${typeof JSONP_PLACEHOLDER_LABEL}_0`;
10
+ export declare const LOCALE_NAME_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}_${typeof LOCALE_NAME_PLACEHOLDER_LABEL}_`;
11
+ export declare const JSONP_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}_${typeof JSONP_PLACEHOLDER_LABEL}_`;
12
12
  //# sourceMappingURL=Constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/utilities/Constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,EAAE,UAAuB,CAAC;AAC5D,eAAO,MAAM,2BAA2B,EAAE,MAAuB,CAAC;AAClE,eAAO,MAAM,mCAAmC,EAAE,kBAAuC,CAAC;AAC1F,eAAO,MAAM,yCAAyC,EAAE,MAA+B,CAAC;AACxF,eAAO,MAAM,yBAAyB,EAAE,wDACkB,CAAC;AAE3D,eAAO,MAAM,yBAAyB,EAAE,MAAkD,CAAC;AAE3F,eAAO,MAAM,wBAAwB,EAAE,GAAS,CAAC;AACjD,eAAO,MAAM,6BAA6B,EAAE,GAAS,CAAC;AACtD,eAAO,MAAM,uBAAuB,EAAE,GAAS,CAAC;AAGhD,eAAO,MAAM,uBAAuB,EAAE,GAAG,OAAO,yBAAyB,KAAK,OAAO,6BAA6B,IAAyE,CAAC;AAG5L,eAAO,MAAM,iBAAiB,EAAE,GAAG,OAAO,yBAAyB,KAAK,OAAO,uBAAuB,IAAmE,CAAC"}
1
+ {"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../src/utilities/Constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,EAAE,UAAuB,CAAC;AAC5D,eAAO,MAAM,2BAA2B,EAAE,MAAuB,CAAC;AAClE,eAAO,MAAM,mCAAmC,EAAE,kBAAuC,CAAC;AAC1F,eAAO,MAAM,yCAAyC,EAAE,MAA+B,CAAC;AACxF,eAAO,MAAM,yBAAyB,EAAE,wDACkB,CAAC;AAE3D,eAAO,MAAM,yBAAyB,EAAE,MAAkD,CAAC;AAE3F,eAAO,MAAM,wBAAwB,EAAE,GAAS,CAAC;AACjD,eAAO,MAAM,6BAA6B,EAAE,GAAS,CAAC;AACtD,eAAO,MAAM,uBAAuB,EAAE,GAAS,CAAC;AAGhD,eAAO,MAAM,uBAAuB,EAAE,GAAG,OAAO,yBAAyB,IAAI,OAAO,6BAA6B,GAAsE,CAAC;AAGxL,eAAO,MAAM,iBAAiB,EAAE,GAAG,OAAO,yBAAyB,IAAI,OAAO,uBAAuB,GAAgE,CAAC"}
@@ -12,8 +12,8 @@ exports.RESOURCE_FILE_NAME_REGEXP = /\.(resx|resx\.json|loc\.json|resjson)$/i;
12
12
  exports.STRING_PLACEHOLDER_LABEL = 'A';
13
13
  exports.LOCALE_NAME_PLACEHOLDER_LABEL = 'B';
14
14
  exports.JSONP_PLACEHOLDER_LABEL = 'C';
15
- // _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9__B_0
16
- exports.LOCALE_NAME_PLACEHOLDER = `${exports.STRING_PLACEHOLDER_PREFIX}__${exports.LOCALE_NAME_PLACEHOLDER_LABEL}_0`;
17
- // _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9__C_0
18
- exports.JSONP_PLACEHOLDER = `${exports.STRING_PLACEHOLDER_PREFIX}__${exports.JSONP_PLACEHOLDER_LABEL}_0`;
15
+ // _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9_B_
16
+ exports.LOCALE_NAME_PLACEHOLDER = `${exports.STRING_PLACEHOLDER_PREFIX}_${exports.LOCALE_NAME_PLACEHOLDER_LABEL}_`;
17
+ // _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9_C_
18
+ exports.JSONP_PLACEHOLDER = `${exports.STRING_PLACEHOLDER_PREFIX}_${exports.JSONP_PLACEHOLDER_LABEL}_`;
19
19
  //# sourceMappingURL=Constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/utilities/Constants.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE9C,QAAA,qBAAqB,GAAe,UAAU,CAAC;AAC/C,QAAA,2BAA2B,GAAW,cAAc,CAAC;AACrD,QAAA,mCAAmC,GAAuB,kBAAkB,CAAC;AAC7E,QAAA,yCAAyC,GAAW,sBAAsB,CAAC;AAC3E,QAAA,yBAAyB,GACpC,wDAAwD,CAAC;AAE9C,QAAA,yBAAyB,GAAW,yCAAyC,CAAC;AAE9E,QAAA,wBAAwB,GAAQ,GAAG,CAAC;AACpC,QAAA,6BAA6B,GAAQ,GAAG,CAAC;AACzC,QAAA,uBAAuB,GAAQ,GAAG,CAAC;AAEhD,8DAA8D;AACjD,QAAA,uBAAuB,GAAqF,GAAG,iCAAyB,KAAK,qCAA6B,IAAI,CAAC;AAE5L,8DAA8D;AACjD,QAAA,iBAAiB,GAA+E,GAAG,iCAAyB,KAAK,+BAAuB,IAAI,CAAC","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 const LOCALE_FILENAME_TOKEN: '[locale]' = '[locale]';\nexport const LOCALE_FILENAME_TOKEN_REGEX: RegExp = /\\[locale\\]/gi;\nexport const NO_LOCALE_SOURCE_MAP_FILENAME_TOKEN: '[no-locale-file]' = '[no-locale-file]';\nexport const NO_LOCALE_SOURCE_MAP_FILENAME_TOKEN_REGEX: RegExp = /\\[no-locale-file\\]/gi;\nexport const STRING_PLACEHOLDER_PREFIX: '_LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9' =\n '_LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9';\n\nexport const RESOURCE_FILE_NAME_REGEXP: RegExp = /\\.(resx|resx\\.json|loc\\.json|resjson)$/i;\n\nexport const STRING_PLACEHOLDER_LABEL: 'A' = 'A';\nexport const LOCALE_NAME_PLACEHOLDER_LABEL: 'B' = 'B';\nexport const JSONP_PLACEHOLDER_LABEL: 'C' = 'C';\n\n// _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9__B_0\nexport const LOCALE_NAME_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}__${typeof LOCALE_NAME_PLACEHOLDER_LABEL}_0` = `${STRING_PLACEHOLDER_PREFIX}__${LOCALE_NAME_PLACEHOLDER_LABEL}_0`;\n\n// _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9__C_0\nexport const JSONP_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}__${typeof JSONP_PLACEHOLDER_LABEL}_0` = `${STRING_PLACEHOLDER_PREFIX}__${JSONP_PLACEHOLDER_LABEL}_0`;\n"]}
1
+ {"version":3,"file":"Constants.js","sourceRoot":"","sources":["../../src/utilities/Constants.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE9C,QAAA,qBAAqB,GAAe,UAAU,CAAC;AAC/C,QAAA,2BAA2B,GAAW,cAAc,CAAC;AACrD,QAAA,mCAAmC,GAAuB,kBAAkB,CAAC;AAC7E,QAAA,yCAAyC,GAAW,sBAAsB,CAAC;AAC3E,QAAA,yBAAyB,GACpC,wDAAwD,CAAC;AAE9C,QAAA,yBAAyB,GAAW,yCAAyC,CAAC;AAE9E,QAAA,wBAAwB,GAAQ,GAAG,CAAC;AACpC,QAAA,6BAA6B,GAAQ,GAAG,CAAC;AACzC,QAAA,uBAAuB,GAAQ,GAAG,CAAC;AAEhD,4DAA4D;AAC/C,QAAA,uBAAuB,GAAmF,GAAG,iCAAyB,IAAI,qCAA6B,GAAG,CAAC;AAExL,4DAA4D;AAC/C,QAAA,iBAAiB,GAA6E,GAAG,iCAAyB,IAAI,+BAAuB,GAAG,CAAC","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 const LOCALE_FILENAME_TOKEN: '[locale]' = '[locale]';\nexport const LOCALE_FILENAME_TOKEN_REGEX: RegExp = /\\[locale\\]/gi;\nexport const NO_LOCALE_SOURCE_MAP_FILENAME_TOKEN: '[no-locale-file]' = '[no-locale-file]';\nexport const NO_LOCALE_SOURCE_MAP_FILENAME_TOKEN_REGEX: RegExp = /\\[no-locale-file\\]/gi;\nexport const STRING_PLACEHOLDER_PREFIX: '_LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9' =\n '_LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9';\n\nexport const RESOURCE_FILE_NAME_REGEXP: RegExp = /\\.(resx|resx\\.json|loc\\.json|resjson)$/i;\n\nexport const STRING_PLACEHOLDER_LABEL: 'A' = 'A';\nexport const LOCALE_NAME_PLACEHOLDER_LABEL: 'B' = 'B';\nexport const JSONP_PLACEHOLDER_LABEL: 'C' = 'C';\n\n// _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9_B_\nexport const LOCALE_NAME_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}_${typeof LOCALE_NAME_PLACEHOLDER_LABEL}_` = `${STRING_PLACEHOLDER_PREFIX}_${LOCALE_NAME_PLACEHOLDER_LABEL}_`;\n\n// _LOCALIZED_STRING_f12dy0i7_n4bo_dqwj_39gf_sasqehjmihz9_C_\nexport const JSONP_PLACEHOLDER: `${typeof STRING_PLACEHOLDER_PREFIX}_${typeof JSONP_PLACEHOLDER_LABEL}_` = `${STRING_PLACEHOLDER_PREFIX}_${JSONP_PLACEHOLDER_LABEL}_`;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/webpack5-localization-plugin",
3
- "version": "0.11.26",
3
+ "version": "0.12.0",
4
4
  "description": "This plugin facilitates localization with Webpack.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "dist/webpack5-localization-plugin.d.ts",