Skip to content

Commit 17df9fb

Browse files
authored
Perlocale tweaks (#322)
* Fix handling of lazy loaded modules, add stats Also add collision detection * fix registry URL * remove appdynamics
1 parent e0004f1 commit 17df9fb

File tree

3 files changed

+53
-26
lines changed

3 files changed

+53
-26
lines changed

packages/react-scripts/layout/views/layout.ejs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,7 @@
1818
<link rel="manifest" href="<%= typeof appPathOverride !== 'undefined' ? appPathOverride : appPath('') %>/manifest.json" type="application/manifest+json" crossorigin="use-credentials" />
1919

2020
<!-- Resource Hints -->
21-
<link rel="preconnect" href="//edge.fscdn.org" crossorigin />
22-
23-
<% if (feature('appdynamicsFt') || process.env.APPDYNAMICS_ENABLED !== 'false') { %>
24-
<script charset='UTF-8'>
25-
window['adrum-start-time'] = new Date().getTime();
26-
(function(config){
27-
config.appKey = '<%= process.env.APPDYNAMICS_EUM_KEY %>';
28-
config.adrumExtUrlHttps = 'https://cdn.appdynamics.com';
29-
config.beaconUrlHttps = 'https://col.eum-appdynamics.com';
30-
config.xd = {enable : true};
31-
config.spa = {
32-
"spa2": true
33-
};
34-
})(window['adrum-config'] || (window['adrum-config'] = {}));
35-
</script>
36-
<script src='https://cdn.appdynamics.com/adrum/adrum-latest.js' type='text/javascript' charset='UTF-8'></script>
37-
<% } else if (feature('luxFt') || process.env.LUX_ENABLED === 'true') { %>
38-
<script>
39-
LUX=(function(){var a=("undefined"!==typeof(LUX)&&"undefined"!==typeof(LUX.gaMarks)?LUX.gaMarks:[]);var d=("undefined"!==typeof(LUX)&&"undefined"!==typeof(LUX.gaMeasures)?LUX.gaMeasures:[]);var j="LUX_start";var k=window.performance;var l=("undefined"!==typeof(LUX)&&LUX.ns?LUX.ns:(Date.now?Date.now():+(new Date())));if(k&&k.timing&&k.timing.navigationStart){l=k.timing.navigationStart}function f(){if(k&&k.now){return k.now()}var o=Date.now?Date.now():+(new Date());return o-l}function b(n){if(k){if(k.mark){return k.mark(n)}else{if(k.webkitMark){return k.webkitMark(n)}}}a.push({name:n,entryType:"mark",startTime:f(),duration:0});return}function m(p,t,n){if("undefined"===typeof(t)&&h(j)){t=j}if(k){if(k.measure){if(t){if(n){return k.measure(p,t,n)}else{return k.measure(p,t)}}else{return k.measure(p)}}else{if(k.webkitMeasure){return k.webkitMeasure(p,t,n)}}}var r=0,o=f();if(t){var s=h(t);if(s){r=s.startTime}else{if(k&&k.timing&&k.timing[t]){r=k.timing[t]-k.timing.navigationStart}else{return}}}if(n){var q=h(n);if(q){o=q.startTime}else{if(k&&k.timing&&k.timing[n]){o=k.timing[n]-k.timing.navigationStart}else{return}}}d.push({name:p,entryType:"measure",startTime:r,duration:(o-r)});return}function h(n){return c(n,g())}function c(p,o){for(i=o.length-1;i>=0;i--){var n=o[i];if(p===n.name){return n}}return undefined}function g(){if(k){if(k.getEntriesByType){return k.getEntriesByType("mark")}else{if(k.webkitGetEntriesByType){return k.webkitGetEntriesByType("mark")}}}return a}return{mark:b,measure:m,gaMarks:a,gaMeasures:d}})();LUX.ns=(Date.now?Date.now():+(new Date()));LUX.ac=[];LUX.cmd=function(a){LUX.ac.push(a)};LUX.init=function(){LUX.cmd(["init"])};LUX.send=function(){LUX.cmd(["send"])};LUX.addData=function(a,b){LUX.cmd(["addData",a,b])};LUX_ae=[];window.addEventListener("error",function(a){LUX_ae.push(a)});LUX_al=[];if("function"===typeof(PerformanceObserver)&&"function"===typeof(PerformanceLongTaskTiming)){var LongTaskObserver=new PerformanceObserver(function(c){var b=c.getEntries();for(var a=0;a<b.length;a++){var d=b[a];LUX_al.push(d)}});try{LongTaskObserver.observe({type:["longtask"]})}catch(e){}};
40-
</script>
41-
<script src="https://cdn.speedcurve.com/js/lux.js?id=371286048" async defer crossorigin="anonymous"></script>
42-
<% } %>
21+
<link rel="preconnect" href="https://edge.fscdn.org" crossorigin />
4322

4423
<script>
4524
window.SERVER_DATA = {};

packages/react-scripts/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fs/react-scripts",
3-
"version": "7.0.0-beta.0",
3+
"version": "7.0.0-beta.1",
44
"upstreamVersion": "4.0.3",
55
"description": "Configuration and scripts for Create React App.",
66
"repository": {
@@ -167,6 +167,6 @@
167167
]
168168
},
169169
"publishConfig": {
170-
"registry": "https://familysearch.jfrog.io/familysearch/api/npm/fs-npm-prod-virtual/"
170+
"registry": "https://familysearch.jfrog.io/artifactory/api/npm/fs-npm-prod-virtual/"
171171
}
172172
}

packages/react-scripts/scripts/coalesceLocales.js

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path');
55
const fs = require('fs');
66
const rimraf = require('rimraf');
77
const chokidar = require('chokidar');
8+
const _ = require('lodash')
89

910
exports.coalesceLocales = paths => {
1011
console.time('per-locale coalesce');
@@ -22,30 +23,69 @@ exports.coalesceLocales = paths => {
2223
directory: paths.appPath,
2324
tsConfig: index.includes('.tsx') && `${paths.appPath}/tsconfig.json`,
2425
noTypeDefinitions: true, // optional
26+
detective: {
27+
es6: {
28+
mixedImports: true
29+
}
30+
},
2531
nodeModulesConfig: {
2632
entry: 'module',
2733
},
28-
filter: p => p.includes('src') || p.includes('@fs'),
34+
filter: p => p.includes(paths.appSrc) || p.includes('@fs'),
2935
});
3036
const realList = list.filter(p => p.includes('locales/index.js'));
3137
const allLocales = {};
38+
const collisionReport = {
39+
collisions: [],
40+
potentialCollisions: [],
41+
}
42+
const statsReport = {
43+
namespaces: new Set(),
44+
locales: new Set(),
45+
keys: new Set(),
46+
}
3247
realList.forEach(p => {
3348
const dir = path.dirname(p);
34-
const locales = fs.readdirSync(dir).filter(d => !d.includes('.'));
49+
// console.log('dir', dir)
50+
const locales = fs.readdirSync(dir).filter(d => !d.includes('.') && d !== 'dist');
3551
locales.forEach(locale => {
52+
statsReport.locales.add(locale)
3653
const namespaces = fs
3754
.readdirSync(path.join(dir, locale))
3855
.map(d => d.split('.')[0]);
3956
allLocales[locale] = allLocales[locale] || {};
4057
namespaces.forEach(ns => {
58+
statsReport.namespaces.add(ns)
4159
const strings = jsonfile.readFileSync(
4260
`${path.join(dir, locale, ns)}.json`
4361
);
4462
allLocales[locale][ns] = allLocales[locale][ns] || {};
63+
// console.log('strings', Object.keys(strings))
64+
// console.log('allLocales', Object.keys(allLocales[locale][ns]||{}))
65+
Object.keys(strings).map(key => statsReport.keys.add(key))
66+
const collisions = _.intersection(Object.keys(allLocales[locale][ns]), Object.keys(strings))
67+
if (collisions && collisions.length>0) {
68+
collisions.forEach(collisionKey => {
69+
if (allLocales[locale][ns][collisionKey] !== strings[collisionKey]) {
70+
collisionReport.collisions.push({key:collisionKey,locale,ns,oldValue: allLocales[locale][ns][collisionKey], newValue: strings[collisionKey]})
71+
// console.error(`COLLISION: key=${collisionKey} locale=${locale} namespace=${ns} "${strings[collisionKey]}" overrides "${allLocales[locale][ns][collisionKey]}"`)
72+
} else {
73+
collisionReport.potentialCollisions.push({key:collisionKey,locale,ns,oldValue: allLocales[locale][ns][collisionKey], newValue: strings[collisionKey]})
74+
}
75+
})
76+
}
4577
allLocales[locale][ns] = { ...allLocales[locale][ns], ...strings };
4678
});
4779
});
4880
});
81+
if (collisionReport.potentialCollisions.length > 0) {
82+
console.warn(`WARNING: The following ${collisionReport.potentialCollisions.length} potential collisions were detected when coalescing locales, the values were the same, but could diverge in the future:`)
83+
collisionReport.potentialCollisions.forEach(({ key, locale, ns, newValue }) => console.warn(`\tkey=${key} namespace=${ns} locale=${locale} value="${newValue}"`))
84+
}
85+
if (collisionReport.collisions.length > 0) {
86+
console.error(`ERROR: The following ${collisionReport.collisions.length} collisions were detected when coalescing locales:`, collisionReport.collisions)
87+
collisionReport.collisions.forEach(({ key, locale, ns, newValue, oldValue }) => console.error(`\tkey=${key} namespace=${ns} locale=${locale} newValue="${newValue}" oldValue="${oldValue}"`))
88+
}
4989
Object.keys(allLocales).forEach(locale => {
5090
fs.mkdirSync(path.join(builtLocalesDir, locale));
5191
Object.keys(allLocales[locale]).forEach(namespace => {
@@ -57,6 +97,14 @@ exports.coalesceLocales = paths => {
5797
});
5898

5999
console.timeEnd('per-locale coalesce');
100+
101+
console.log(`Locales Stats`, {
102+
namespaces: statsReport.namespaces,
103+
locales: statsReport.locales,
104+
keys: statsReport.keys.size,
105+
})
106+
// console.dir(allLocales)
107+
// throw new Error('boom')
60108
};
61109

62110
exports.watchCoalesce = paths => {

0 commit comments

Comments
 (0)