Skip to content

Commit 7aa499f

Browse files
authored
Merge pull request microsoft#1758 from iclanton/ianc/loc-plugin-wrapup
[localization-plugin] Fix a few issues with localized asset path renaming.
2 parents 4655bf6 + 6d63954 commit 7aa499f

File tree

10 files changed

+35
-23
lines changed

10 files changed

+35
-23
lines changed

build-tests/localization-plugin-test-02/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"webpack-bundle-analyzer": "~3.6.0",
1919
"webpack-cli": "~3.3.2",
2020
"webpack-dev-server": "~3.9.0",
21-
"html-webpack-plugin": "~3.2.0"
21+
"html-webpack-plugin": "~3.2.0",
22+
"@types/lodash": "4.14.116",
23+
"lodash": "~4.17.15"
2224
}
2325
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import * as lodash from 'lodash';
2+
13
import * as strings from './strings2.loc.json';
24

35
export class ChunkWithStringsClass {
46
public doStuff(): void {
5-
console.log(strings.string1);
7+
console.log(lodash.escape(strings.string1));
68
}
79
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import * as lodash from 'lodash';
2+
13
export class ChunkWithoutStringsClass {
24
public doStuff(): void {
3-
console.log('STATIC STRING');
5+
console.log(lodash.escape('STATIC STRING'));
46
}
57
}

common/changes/@rushstack/localization-plugin/ianc-loc-plugin-prototype_2019-11-19-09-16.json renamed to common/changes/@rushstack/localization-plugin/ianc-publish-loc-package_2020-02-07-23-54.json

File renamed without changes.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it.
22
{
33
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json",
4-
"packages": [
5-
]
4+
"packages": []
65
}

common/config/rush/nonbrowser-approved-packages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@
452452
},
453453
{
454454
"name": "lodash",
455-
"allowedCategories": [ "libraries" ]
455+
"allowedCategories": [ "libraries", "tests" ]
456456
},
457457
{
458458
"name": "lodash.merge",

common/config/rush/pnpm-lock.yaml

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rush.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@
863863
"packageName": "@rushstack/localization-plugin",
864864
"projectFolder": "webpack/localization-plugin",
865865
"reviewCategory": "libraries",
866-
"shouldPublish": false
866+
"shouldPublish": true
867867
},
868868
{
869869
"packageName": "@microsoft/loader-raw-script",

webpack/localization-plugin/src/LocalizationPlugin.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ interface IExtendedChunk extends Webpack.compilation.Chunk {
5555
}
5656

5757
interface IAssetPathOptions {
58-
chunk: {};
58+
chunk: Webpack.compilation.Chunk;
5959
contentHashType: string;
6060
}
6161

@@ -194,10 +194,18 @@ export class LocalizationPlugin implements Webpack.Plugin {
194194
options.contentHashType === 'javascript' &&
195195
assetPath.match(Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX)
196196
) {
197-
return assetPath.replace(
198-
Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX,
199-
`" + ${Constants.JSONP_PLACEHOLDER} + "`
197+
// Does this look like an async chunk URL generator?
198+
if (typeof options.chunk.id === 'string' && options.chunk.id.match(/^\" \+/)) {
199+
return assetPath.replace(
200+
Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX,
201+
`" + ${Constants.JSONP_PLACEHOLDER} + "`
202+
);
203+
} else {
204+
return assetPath.replace(
205+
Constants.LOCALE_FILENAME_PLACEHOLDER_REGEX,
206+
Constants.LOCALE_NAME_PLACEHOLDER
200207
);
208+
}
201209
} else {
202210
return assetPath;
203211
}
@@ -307,7 +315,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
307315
}
308316

309317
if (EntityMarker.getMark(chunk)) {
310-
311318
processChunkJsFile((chunkFilename) => {
312319
if (chunkFilename.indexOf(Constants.LOCALE_NAME_PLACEHOLDER) === -1) {
313320
throw new Error(`Asset ${chunkFilename} is expected to be localized, but is missing a locale placeholder`);
@@ -356,10 +363,6 @@ export class LocalizationPlugin implements Webpack.Plugin {
356363
});
357364
} else {
358365
processChunkJsFile((chunkFilename) => {
359-
if (chunkFilename.indexOf(Constants.LOCALE_NAME_PLACEHOLDER) !== -1) {
360-
throw new Error(`Asset ${chunkFilename} is not expected to be localized, but has a locale placeholder`);
361-
}
362-
363366
const asset: IAsset = compilation.assets[chunkFilename];
364367

365368
const resultingAsset: IProcessAssetResult = AssetProcessor.processNonLocalizedAsset({

webpack/localization-plugin/src/TypingsGenerator.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,15 @@ export class TypingsGenerator {
8181
const locFilePaths: string[] = glob.sync(
8282
path.join('**', '*+(.resx|.loc.json)'),
8383
{
84-
root: this._options.srcFolder,
85-
absolute: true
84+
cwd: this._options.srcFolder,
85+
absolute: true,
86+
nosort: true,
87+
nodir: true
8688
}
8789
);
8890

8991
for (let locFilePath of locFilePaths) {
90-
locFilePath = path.resolve(locFilePath);
92+
locFilePath = path.resolve(this._options.srcFolder, locFilePath);
9193

9294
if (filesToIgnore.has(locFilePath)) {
9395
continue;

0 commit comments

Comments
 (0)