Skip to content

Commit

Permalink
Merge pull request #3500 from dmichon-msft/localization-plugin-portab…
Browse files Browse the repository at this point in the history
…le-resolution

[localization-plugin-5] Fix unit tests on Windows
  • Loading branch information
dmichon-msft authored Jun 28, 2022
2 parents 3bf6c80 + f34d2b2 commit 68306a8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@rushstack/webpack5-localization-plugin",
"comment": "Ensure localization file path resolution can handle a UNIX file system on a Windows host, as is used by the unit tests.",
"type": "patch"
}
],
"packageName": "@rushstack/webpack5-localization-plugin"
}
7 changes: 5 additions & 2 deletions webpack/localization-plugin-5/src/LocalizationPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,9 @@ export class LocalizationPlugin implements WebpackPluginInstance {
// END options.localizedData.passthroughLocale

// START options.localizedData.translatedStrings
const resolveRelativeToContext: (relative: string) => string = (
configuration.context?.startsWith('/') ? path.posix.resolve : path.resolve
).bind(0, configuration.context!);
const { translatedStrings } = localizedData;
this._resolvedTranslatedStringsFromOptions.clear();
if (translatedStrings) {
Expand All @@ -606,7 +609,7 @@ export class LocalizationPlugin implements WebpackPluginInstance {
this._resolvedTranslatedStringsFromOptions.set(localeName, resolvedFromOptionsForLocale);

for (const [locFilePath, locFileDataFromOptions] of Object.entries(locale)) {
const normalizedLocFilePath: string = path.resolve(configuration.context!, locFilePath);
const normalizedLocFilePath: string = resolveRelativeToContext(locFilePath);

if (resolvedFromOptionsForLocale.has(normalizedLocFilePath)) {
errors.push(
Expand All @@ -620,7 +623,7 @@ export class LocalizationPlugin implements WebpackPluginInstance {

const normalizedLocFileDataFromOptions: ILocaleFileData =
typeof locFileDataFromOptions === 'string'
? path.resolve(configuration.context!, locFileDataFromOptions)
? resolveRelativeToContext(locFileDataFromOptions)
: locFileDataFromOptions;

resolvedFromOptionsForLocale.set(normalizedLocFilePath, normalizedLocFileDataFromOptions);
Expand Down

0 comments on commit 68306a8

Please sign in to comment.