diff --git a/common/changes/@rushstack/webpack5-localization-plugin/localization-plugin-portable-resolution_2022-06-27-21-45.json b/common/changes/@rushstack/webpack5-localization-plugin/localization-plugin-portable-resolution_2022-06-27-21-45.json new file mode 100644 index 00000000000..7b9123cea7a --- /dev/null +++ b/common/changes/@rushstack/webpack5-localization-plugin/localization-plugin-portable-resolution_2022-06-27-21-45.json @@ -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" +} \ No newline at end of file diff --git a/webpack/localization-plugin-5/src/LocalizationPlugin.ts b/webpack/localization-plugin-5/src/LocalizationPlugin.ts index 09514ba3bfc..f925d641876 100644 --- a/webpack/localization-plugin-5/src/LocalizationPlugin.ts +++ b/webpack/localization-plugin-5/src/LocalizationPlugin.ts @@ -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) { @@ -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( @@ -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);