Skip to content

Commit a5c40d1

Browse files
authored
chore: remove i18n mocks (#576)
i18n can now run in node.js.
1 parent 08e9a9f commit a5c40d1

File tree

4 files changed

+31
-65
lines changed

4 files changed

+31
-65
lines changed

scripts/post-build.ts

Lines changed: 14 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -53,69 +53,22 @@ function main(): void {
5353

5454
// Create i18n mock
5555
const i18nDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'i18n');
56-
fs.mkdirSync(i18nDir, {recursive: true});
57-
const i18nFile = path.join(i18nDir, 'i18n.js');
58-
const i18nContent = `
59-
export const i18n = {
60-
registerUIStrings: () => {},
61-
getLocalizedString: (_, str) => {
62-
// So that the string passed in gets output verbatim.
63-
return str;
64-
},
65-
lockedLazyString: () => {},
66-
getLazilyComputedLocalizedString: () => ()=>{},
67-
};
68-
69-
// TODO(jacktfranklin): once the DocumentLatency insight does not depend on
70-
// this method, we can remove this stub.
71-
export const TimeUtilities = {
72-
millisToString(x) {
73-
const separator = '\xA0';
74-
const formatter = new Intl.NumberFormat('en-US', {
75-
style: 'unit',
76-
unitDisplay: 'narrow',
77-
minimumFractionDigits: 0,
78-
maximumFractionDigits: 1,
79-
unit: 'millisecond',
80-
});
81-
82-
const parts = formatter.formatToParts(x);
83-
for (const part of parts) {
84-
if (part.type === 'literal') {
85-
if (part.value === ' ') {
86-
part.value = separator;
87-
}
88-
}
89-
}
56+
const localesFile = path.join(i18nDir, 'locales.js');
57+
const localesContent = `
58+
export const LOCALES = [
59+
'en-US',
60+
];
9061
91-
return parts.map(part => part.value).join('');
92-
}
93-
};
94-
95-
// TODO(jacktfranklin): once the ImageDelivery insight does not depend on this method, we can remove this stub.
96-
export const ByteUtilities = {
97-
bytesToString(x) {
98-
const separator = '\xA0';
99-
const formatter = new Intl.NumberFormat('en-US', {
100-
style: 'unit',
101-
unit: 'kilobyte',
102-
unitDisplay: 'narrow',
103-
minimumFractionDigits: 1,
104-
maximumFractionDigits: 1,
105-
});
106-
const parts = formatter.formatToParts(x / 1000);
107-
for (const part of parts) {
108-
if (part.type === 'literal') {
109-
if (part.value === ' ') {
110-
part.value = separator;
111-
}
112-
}
113-
}
62+
export const BUNDLED_LOCALES = [
63+
'en-US',
64+
];
11465
115-
return parts.map(part => part.value).join('');
116-
}
117-
};`;
118-
writeFile(i18nFile, i18nContent);
66+
export const DEFAULT_LOCALE = 'en-US';
67+
68+
export const REMOTE_FETCH_PATTERN = '@HOST@/remote/serve_file/@VERSION@/core/i18n/locales/@LOCALE@.json';
69+
70+
export const LOCAL_FETCH_PATTERN = './locales/@LOCALE@.json';`;
71+
writeFile(localesFile, localesContent);
11972

12073
// Create codemirror.next mock.
12174
const codeMirrorDir = path.join(

src/DevtoolsUtils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
type Issue,
99
type IssuesManagerEventTypes,
1010
Common,
11+
I18n,
1112
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
1213

1314
export function extractUrlLikeFromDevToolsTitle(
@@ -67,3 +68,13 @@ export class FakeIssuesManager extends Common.ObjectWrapper
6768
return [];
6869
}
6970
}
71+
72+
I18n.DevToolsLocale.DevToolsLocale.instance({
73+
create: true,
74+
data: {
75+
navigatorLanguage: 'en-US',
76+
settingLanguage: 'en-US',
77+
lookupClosestDevToolsLocale: l => l,
78+
},
79+
});
80+
I18n.i18n.registerLocaleDataForTest('en-US', {});

tests/trace-processing/parse.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
parseRawTraceBuffer,
1212
} from '../../src/trace-processing/parse.js';
1313

14+
import '../../src/DevtoolsUtils.js';
15+
1416
import {loadTraceAsBuffer} from './fixtures/load.js';
1517

1618
describe('Trace parsing', async () => {

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"tests/**/*.ts",
2929
"node_modules/chrome-devtools-frontend/front_end/core/common",
3030
"node_modules/chrome-devtools-frontend/front_end/core/host",
31+
"node_modules/chrome-devtools-frontend/front_end/core/i18n",
3132
"node_modules/chrome-devtools-frontend/front_end/core/platform",
3233
"node_modules/chrome-devtools-frontend/front_end/core/protocol_client",
3334
"node_modules/chrome-devtools-frontend/front_end/core/root",
@@ -57,14 +58,13 @@
5758
"node_modules/chrome-devtools-frontend/front_end/models/trace",
5859
"node_modules/chrome-devtools-frontend/front_end/models/workspace",
5960
"node_modules/chrome-devtools-frontend/front_end/panels/issues/IssueAggregator.ts",
61+
"node_modules/chrome-devtools-frontend/front_end/third_party/i18n",
62+
"node_modules/chrome-devtools-frontend/front_end/third_party/intl-messageformat",
6063
"node_modules/chrome-devtools-frontend/front_end/third_party/legacy-javascript",
6164
"node_modules/chrome-devtools-frontend/front_end/third_party/marked",
6265
"node_modules/chrome-devtools-frontend/front_end/third_party/source-map-scopes-codec",
6366
"node_modules/chrome-devtools-frontend/front_end/third_party/third-party-web",
64-
"node_modules/chrome-devtools-frontend/mcp/mcp.ts",
65-
"node_modules/chrome-devtools-frontend/front_end/models/issues_manager",
66-
"node_modules/chrome-devtools-frontend/front_end/third_party/marked",
67-
"node_modules/chrome-devtools-frontend/front_end/panels/issues/IssueAggregator.ts"
67+
"node_modules/chrome-devtools-frontend/mcp/mcp.ts"
6868
],
6969
"exclude": ["node_modules/chrome-devtools-frontend/**/*.test.ts"]
7070
}

0 commit comments

Comments
 (0)