misc: convert shared to ES modules
This commit is contained in:
Родитель
55ca639724
Коммит
b7658eb73b
|
@ -121,7 +121,7 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
|
|||
|
||||
// Don't include locales in DevTools.
|
||||
if (isDevtools(entryPath)) {
|
||||
shimsObj['./locales.js'] = 'export default {}';
|
||||
shimsObj['./locales.js'] = 'export const locales = {};';
|
||||
}
|
||||
|
||||
for (const modulePath of modulesToIgnore) {
|
||||
|
@ -186,6 +186,7 @@ async function buildBundle(entryPath, distPath, opts = {minify: true}) {
|
|||
`,
|
||||
}),
|
||||
rollupPlugins.json(),
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: false}),
|
||||
rollupPlugins.commonjs({
|
||||
// https://github.com/rollup/plugins/issues/922
|
||||
|
|
|
@ -39,6 +39,7 @@ async function buildReportGenerator() {
|
|||
}),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.nodeResolve(),
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
|
||||
],
|
||||
});
|
||||
|
|
|
@ -31,6 +31,7 @@ async function buildReportGenerator() {
|
|||
const bundle = await rollup({
|
||||
input: 'report/generator/report-generator.js',
|
||||
plugins: [
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
|
||||
rollupPlugins.shim({
|
||||
[`${LH_ROOT}/report/generator/flow-report-assets.js`]: 'export default {}',
|
||||
|
|
|
@ -10,7 +10,7 @@ import esMain from 'es-main';
|
|||
import * as rollupPlugins from './rollup-plugins.js';
|
||||
import {LH_ROOT} from '../root.js';
|
||||
import {getIcuMessageIdParts} from '../shared/localization/format.js';
|
||||
import locales from '../shared/localization/locales.js';
|
||||
import {locales} from '../shared/localization/locales.js';
|
||||
import {UIStrings as FlowUIStrings} from '../flow-report/src/i18n/ui-strings.js';
|
||||
|
||||
/**
|
||||
|
@ -58,13 +58,11 @@ async function buildFlowReport() {
|
|||
const bundle = await rollup({
|
||||
input: 'flow-report/clients/standalone.ts',
|
||||
plugins: [
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: true}),
|
||||
rollupPlugins.replace({
|
||||
'__dirname': '""',
|
||||
}),
|
||||
rollupPlugins.shim({
|
||||
[`${LH_ROOT}/flow-report/src/i18n/localized-strings`]: buildFlowStrings(),
|
||||
[`${LH_ROOT}/shared/localization/locales.js`]: 'export default {}',
|
||||
[`${LH_ROOT}/flow-report/src/i18n/localized-strings.js`]: buildFlowStrings(),
|
||||
[`${LH_ROOT}/shared/localization/locales.js`]: 'export const locales = {}',
|
||||
'fs': 'export default {}',
|
||||
}),
|
||||
rollupPlugins.nodeResolve(),
|
||||
|
@ -141,6 +139,7 @@ async function buildUmdBundle() {
|
|||
const bundle = await rollup({
|
||||
input: 'report/clients/bundle.js',
|
||||
plugins: [
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.inlineFs({verbose: true}),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.terser({
|
||||
|
@ -150,7 +149,7 @@ async function buildUmdBundle() {
|
|||
}),
|
||||
// Shim this empty to ensure the bundle isn't 10MB
|
||||
rollupPlugins.shim({
|
||||
[`${LH_ROOT}/shared/localization/locales.js`]: 'export default {}',
|
||||
[`${LH_ROOT}/shared/localization/locales.js`]: 'export const locales = {}',
|
||||
'fs': 'export default {}',
|
||||
}),
|
||||
rollupPlugins.nodeResolve({preferBuiltins: true}),
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import swapLocale from '../shared/localization/swap-locale.js';
|
||||
import swapFlowLocale from '../shared/localization/swap-flow-locale.js';
|
||||
import {swapLocale} from '../shared/localization/swap-locale.js';
|
||||
import {swapFlowLocale} from '../shared/localization/swap-flow-locale.js';
|
||||
import ReportGenerator from '../report/generator/report-generator.js';
|
||||
import {defaultSettings} from '../core/config/constants.js';
|
||||
import lighthouse from '../core/index.js';
|
||||
|
|
|
@ -9,7 +9,7 @@ import {createRequire} from 'module';
|
|||
import {GhPagesApp} from './gh-pages-app.js';
|
||||
import {LH_ROOT} from '../root.js';
|
||||
import {getIcuMessageIdParts} from '../shared/localization/format.js';
|
||||
import locales from '../shared/localization/locales.js';
|
||||
import {locales} from '../shared/localization/locales.js';
|
||||
import {UIStrings} from '../treemap/app/src/util.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
|
|
@ -18,6 +18,7 @@ async function buildReportGenerator() {
|
|||
const bundle = await rollup({
|
||||
input: 'report/generator/report-generator.js',
|
||||
plugins: [
|
||||
rollupPlugins.removeModuleDirCalls(),
|
||||
rollupPlugins.shim({
|
||||
[`${LH_ROOT}/report/generator/flow-report-assets.js`]: 'export default {}',
|
||||
}),
|
||||
|
@ -54,7 +55,8 @@ async function main() {
|
|||
{path: require.resolve('pako/dist/pako_inflate.js')},
|
||||
{path: 'src/main.js', rollup: true, rollupPlugins: [
|
||||
rollupPlugins.shim({
|
||||
'./locales.js': 'export default {}',
|
||||
'./locales.js': 'export const locales = {};',
|
||||
'module': 'export const createRequire = () => {throw new Error}',
|
||||
}),
|
||||
rollupPlugins.typescript({
|
||||
tsconfig: 'flow-report/tsconfig.json',
|
||||
|
@ -66,11 +68,6 @@ async function main() {
|
|||
declarationMap: false,
|
||||
}),
|
||||
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
|
||||
rollupPlugins.replace({
|
||||
values: {
|
||||
'__dirname': '""',
|
||||
},
|
||||
}),
|
||||
rollupPlugins.commonjs(),
|
||||
rollupPlugins.nodePolyfills(),
|
||||
rollupPlugins.nodeResolve({preferBuiltins: true}),
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
import locales from '../../shared/localization/locales.js';
|
||||
import {locales} from '../../shared/localization/locales.js';
|
||||
|
||||
function listLocales() {
|
||||
const localesList = Object.keys(locales);
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
import legacyDefaultConfig from './legacy-default-config.js';
|
||||
import * as constants from './constants.js';
|
||||
import format from '../../shared/localization/format.js';
|
||||
import * as format from '../../shared/localization/format.js';
|
||||
import * as validation from './../fraggle-rock/config/validation.js';
|
||||
import log from 'lighthouse-logger';
|
||||
import path from 'path';
|
||||
|
|
|
@ -17,7 +17,7 @@ import * as emulation from '../../lib/emulation.js';
|
|||
import {defaultNavigationConfig} from '../../config/constants.js';
|
||||
import {initializeConfig} from '../config/config.js';
|
||||
import {getBaseArtifacts, finalizeArtifacts} from './base-artifacts.js';
|
||||
import format from '../../../shared/localization/format.js';
|
||||
import * as format from '../../../shared/localization/format.js';
|
||||
import {LighthouseError} from '../../lib/lh-error.js';
|
||||
import URL from '../../lib/url-shim.js';
|
||||
import {getPageLoadError} from '../../lib/navigation-error.js';
|
||||
|
|
|
@ -10,7 +10,7 @@ import NetworkRecords from '../computed/network-records.js';
|
|||
import {getPageLoadError} from '../lib/navigation-error.js';
|
||||
import * as emulation from '../lib/emulation.js';
|
||||
import * as constants from '../config/constants.js';
|
||||
import format from '../../shared/localization/format.js';
|
||||
import * as format from '../../shared/localization/format.js';
|
||||
import {getBenchmarkIndex, getEnvironmentWarnings} from './driver/environment.js';
|
||||
import * as prepare from './driver/prepare.js';
|
||||
import * as storage from './driver/storage.js';
|
||||
|
|
|
@ -11,7 +11,7 @@ import {GatherRunner} from './gather/gather-runner.js';
|
|||
import {ReportScoring} from './scoring.js';
|
||||
import {Audit} from './audits/audit.js';
|
||||
import log from 'lighthouse-logger';
|
||||
import format from '../shared/localization/format.js';
|
||||
import * as format from '../shared/localization/format.js';
|
||||
import * as stackPacks from './lib/stack-packs.js';
|
||||
import * as assetSaver from './lib/asset-saver.js';
|
||||
import fs from 'fs';
|
||||
|
|
|
@ -21,7 +21,7 @@ import path from 'path';
|
|||
import colors from 'colors';
|
||||
|
||||
import LegacyJavascript from '../../audits/byte-efficiency/legacy-javascript.js';
|
||||
import format from '../../../shared/localization/format.js';
|
||||
import * as format from '../../../shared/localization/format.js';
|
||||
import {LH_ROOT} from '../../../root.js';
|
||||
import {readJson} from '../../test/test-utils.js';
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ import axeCore from 'axe-core';
|
|||
|
||||
import AxeAudit from '../../../audits/accessibility/axe-audit.js';
|
||||
import Accesskeys from '../../../audits/accessibility/accesskeys.js';
|
||||
import format from '../../../../shared/localization/format.js';
|
||||
import * as format from '../../../../shared/localization/format.js';
|
||||
|
||||
describe('Accessibility: axe-audit', () => {
|
||||
describe('audit()', () => {
|
||||
|
|
|
@ -16,7 +16,7 @@ import * as constants from '../../config/constants.js';
|
|||
import {Gatherer} from '../../gather/gatherers/gatherer.js';
|
||||
import {Audit} from '../../audits/audit.js';
|
||||
import * as i18n from '../../lib/i18n/i18n.js';
|
||||
import format from '../../../shared/localization/format.js';
|
||||
import * as format from '../../../shared/localization/format.js';
|
||||
import {getModuleDirectory, getModulePath} from '../../../esm-utils.js';
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
|
|
|
@ -11,7 +11,7 @@ import * as constants from '../../../config/constants.js';
|
|||
import BaseGatherer from '../../../fraggle-rock/gather/base-gatherer.js';
|
||||
import {initializeConfig, getConfigDisplayString} from '../../../fraggle-rock/config/config.js';
|
||||
import {LH_ROOT} from '../../../../root.js';
|
||||
import format from '../../../../shared/localization/format.js';
|
||||
import * as format from '../../../../shared/localization/format.js';
|
||||
import defaultConfig from '../../../config/default-config.js';
|
||||
|
||||
const {nonSimulatedPassConfigOverrides} = constants;
|
||||
|
|
|
@ -5,15 +5,16 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
import fs from 'fs';
|
||||
import IntlMessageFormat from 'intl-messageformat';
|
||||
import {getModuleDirectory} from '../../esm-utils.js';
|
||||
import {isObjectOfUnknownValues, isObjectOrArrayOfUnknownValues} from '../type-verifiers.js';
|
||||
import {locales} from './locales.js';
|
||||
|
||||
const MessageFormat = require('intl-messageformat');
|
||||
const {isObjectOfUnknownValues, isObjectOrArrayOfUnknownValues} = require('../type-verifiers.js');
|
||||
const moduleDir = getModuleDirectory(import.meta);
|
||||
|
||||
/** Contains available locales with messages. May be an empty object if bundled. */
|
||||
/** @type {import('./locales')} */
|
||||
// @ts-expect-error TODO(esmodules): remove when file is es modules.
|
||||
const LOCALE_MESSAGES = require('./locales.js').default || require('./locales.js');
|
||||
const LOCALE_MESSAGES = locales;
|
||||
|
||||
const DEFAULT_LOCALE = 'en-US';
|
||||
|
||||
|
@ -23,7 +24,7 @@ const DEFAULT_LOCALE = 'en-US';
|
|||
* These locales are considered the "canonical" locales. We support other locales which
|
||||
* are simply aliases to one of these. ex: es-AR (alias) -> es-419 (canonical)
|
||||
*/
|
||||
const CANONICAL_LOCALES = fs.readdirSync(__dirname + '/locales/')
|
||||
const CANONICAL_LOCALES = fs.readdirSync(moduleDir + '/locales/')
|
||||
.filter(basename => basename.endsWith('.json') && !basename.endsWith('.ctc.json'))
|
||||
.map(locale => locale.replace('.json', ''))
|
||||
.sort();
|
||||
|
@ -95,7 +96,7 @@ function collectAllCustomElementsFromICU(icuElements, seenElementsById = new Map
|
|||
* Returns a copy of the `values` object, with the values formatted based on how
|
||||
* they will be used in their icuMessage, e.g. KB or milliseconds. The original
|
||||
* object is unchanged.
|
||||
* @param {MessageFormat.IntlMessageFormat} messageFormatter
|
||||
* @param {IntlMessageFormat} messageFormatter
|
||||
* @param {Readonly<Record<string, string | number>>} values
|
||||
* @param {string} lhlMessage Used for clear error logging.
|
||||
* @return {Record<string, string | number>}
|
||||
|
@ -177,10 +178,7 @@ function formatMessage(message, values, locale) {
|
|||
// When using accented english, force the use of a different locale for number formatting.
|
||||
const localeForMessageFormat = (locale === 'en-XA' || locale === 'en-XL') ? 'de-DE' : locale;
|
||||
|
||||
// This package is not correctly bundled by Rollup.
|
||||
/** @type {typeof MessageFormat.IntlMessageFormat} */
|
||||
const MessageFormatCtor = MessageFormat.IntlMessageFormat || MessageFormat;
|
||||
const formatter = new MessageFormatCtor(message, localeForMessageFormat, formats);
|
||||
const formatter = new IntlMessageFormat(message, localeForMessageFormat, formats);
|
||||
|
||||
// Preformat values for the message format like KB and milliseconds.
|
||||
const valuesForMessageFormat = _preformatValues(formatter, values, message);
|
||||
|
@ -443,7 +441,7 @@ function getIcuMessageIdParts(i18nMessageId) {
|
|||
return {filename, key};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
DEFAULT_LOCALE,
|
||||
_formatPathAsString,
|
||||
collectAllCustomElementsFromICU,
|
||||
|
|
|
@ -5,5 +5,10 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
module.exports.swapLocale = require('./swap-locale.js');
|
||||
module.exports.format = require('./format.js');
|
||||
import * as format from './format.js';
|
||||
import {swapLocale} from './swap-locale.js';
|
||||
|
||||
export {
|
||||
swapLocale,
|
||||
format,
|
||||
};
|
||||
|
|
|
@ -22,61 +22,64 @@
|
|||
|
||||
// TODO(paulirish): Centralize locale inheritance (combining this & i18n.lookupLocale()), adopt cldr parentLocale rules.
|
||||
|
||||
import fs from 'fs';
|
||||
import {getModuleDirectory} from '../../esm-utils.js';
|
||||
|
||||
/** @typedef {import('../../types/lhr/settings').Locale} Locale */
|
||||
/** @typedef {Record<string, {message: string}>} LhlMessages */
|
||||
|
||||
const fs = require('fs');
|
||||
const moduleDir = getModuleDirectory(import.meta);
|
||||
|
||||
/** @type {Record<string, LhlMessages>} */
|
||||
const files = {
|
||||
'ar': JSON.parse(fs.readFileSync(`${__dirname}/locales/ar.json`, 'utf8')),
|
||||
'ar-XB': JSON.parse(fs.readFileSync(`${__dirname}/locales/ar-XB.json`, 'utf8')),
|
||||
'bg': JSON.parse(fs.readFileSync(`${__dirname}/locales/bg.json`, 'utf8')),
|
||||
'ca': JSON.parse(fs.readFileSync(`${__dirname}/locales/ca.json`, 'utf8')),
|
||||
'cs': JSON.parse(fs.readFileSync(`${__dirname}/locales/cs.json`, 'utf8')),
|
||||
'da': JSON.parse(fs.readFileSync(`${__dirname}/locales/da.json`, 'utf8')),
|
||||
'de': JSON.parse(fs.readFileSync(`${__dirname}/locales/de.json`, 'utf8')),
|
||||
'el': JSON.parse(fs.readFileSync(`${__dirname}/locales/el.json`, 'utf8')),
|
||||
'en-GB': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-GB.json`, 'utf8')),
|
||||
'en-US': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-US.json`, 'utf8')),
|
||||
'en-XA': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-XA.json`, 'utf8')),
|
||||
'en-XL': JSON.parse(fs.readFileSync(`${__dirname}/locales/en-XL.json`, 'utf8')),
|
||||
'es': JSON.parse(fs.readFileSync(`${__dirname}/locales/es.json`, 'utf8')),
|
||||
'es-419': JSON.parse(fs.readFileSync(`${__dirname}/locales/es-419.json`, 'utf8')),
|
||||
'fi': JSON.parse(fs.readFileSync(`${__dirname}/locales/fi.json`, 'utf8')),
|
||||
'fil': JSON.parse(fs.readFileSync(`${__dirname}/locales/fil.json`, 'utf8')),
|
||||
'fr': JSON.parse(fs.readFileSync(`${__dirname}/locales/fr.json`, 'utf8')),
|
||||
'he': JSON.parse(fs.readFileSync(`${__dirname}/locales/he.json`, 'utf8')),
|
||||
'hi': JSON.parse(fs.readFileSync(`${__dirname}/locales/hi.json`, 'utf8')),
|
||||
'hr': JSON.parse(fs.readFileSync(`${__dirname}/locales/hr.json`, 'utf8')),
|
||||
'hu': JSON.parse(fs.readFileSync(`${__dirname}/locales/hu.json`, 'utf8')),
|
||||
'id': JSON.parse(fs.readFileSync(`${__dirname}/locales/id.json`, 'utf8')),
|
||||
'it': JSON.parse(fs.readFileSync(`${__dirname}/locales/it.json`, 'utf8')),
|
||||
'ja': JSON.parse(fs.readFileSync(`${__dirname}/locales/ja.json`, 'utf8')),
|
||||
'ko': JSON.parse(fs.readFileSync(`${__dirname}/locales/ko.json`, 'utf8')),
|
||||
'lt': JSON.parse(fs.readFileSync(`${__dirname}/locales/lt.json`, 'utf8')),
|
||||
'lv': JSON.parse(fs.readFileSync(`${__dirname}/locales/lv.json`, 'utf8')),
|
||||
'nl': JSON.parse(fs.readFileSync(`${__dirname}/locales/nl.json`, 'utf8')),
|
||||
'no': JSON.parse(fs.readFileSync(`${__dirname}/locales/no.json`, 'utf8')),
|
||||
'pl': JSON.parse(fs.readFileSync(`${__dirname}/locales/pl.json`, 'utf8')),
|
||||
'pt': JSON.parse(fs.readFileSync(`${__dirname}/locales/pt.json`, 'utf8')),
|
||||
'pt-PT': JSON.parse(fs.readFileSync(`${__dirname}/locales/pt-PT.json`, 'utf8')),
|
||||
'ro': JSON.parse(fs.readFileSync(`${__dirname}/locales/ro.json`, 'utf8')),
|
||||
'ru': JSON.parse(fs.readFileSync(`${__dirname}/locales/ru.json`, 'utf8')),
|
||||
'sk': JSON.parse(fs.readFileSync(`${__dirname}/locales/sk.json`, 'utf8')),
|
||||
'sl': JSON.parse(fs.readFileSync(`${__dirname}/locales/sl.json`, 'utf8')),
|
||||
'sr': JSON.parse(fs.readFileSync(`${__dirname}/locales/sr.json`, 'utf8')),
|
||||
'sr-Latn': JSON.parse(fs.readFileSync(`${__dirname}/locales/sr-Latn.json`, 'utf8')),
|
||||
'sv': JSON.parse(fs.readFileSync(`${__dirname}/locales/sv.json`, 'utf8')),
|
||||
'ta': JSON.parse(fs.readFileSync(`${__dirname}/locales/ta.json`, 'utf8')),
|
||||
'te': JSON.parse(fs.readFileSync(`${__dirname}/locales/te.json`, 'utf8')),
|
||||
'th': JSON.parse(fs.readFileSync(`${__dirname}/locales/th.json`, 'utf8')),
|
||||
'tr': JSON.parse(fs.readFileSync(`${__dirname}/locales/tr.json`, 'utf8')),
|
||||
'uk': JSON.parse(fs.readFileSync(`${__dirname}/locales/uk.json`, 'utf8')),
|
||||
'vi': JSON.parse(fs.readFileSync(`${__dirname}/locales/vi.json`, 'utf8')),
|
||||
'zh': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh.json`, 'utf8')),
|
||||
'zh-HK': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh-HK.json`, 'utf8')),
|
||||
'zh-TW': JSON.parse(fs.readFileSync(`${__dirname}/locales/zh-TW.json`, 'utf8')),
|
||||
'ar': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ar.json`, 'utf8')),
|
||||
'ar-XB': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ar-XB.json`, 'utf8')),
|
||||
'bg': JSON.parse(fs.readFileSync(`${moduleDir}/locales/bg.json`, 'utf8')),
|
||||
'ca': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ca.json`, 'utf8')),
|
||||
'cs': JSON.parse(fs.readFileSync(`${moduleDir}/locales/cs.json`, 'utf8')),
|
||||
'da': JSON.parse(fs.readFileSync(`${moduleDir}/locales/da.json`, 'utf8')),
|
||||
'de': JSON.parse(fs.readFileSync(`${moduleDir}/locales/de.json`, 'utf8')),
|
||||
'el': JSON.parse(fs.readFileSync(`${moduleDir}/locales/el.json`, 'utf8')),
|
||||
'en-GB': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-GB.json`, 'utf8')),
|
||||
'en-US': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-US.json`, 'utf8')),
|
||||
'en-XA': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-XA.json`, 'utf8')),
|
||||
'en-XL': JSON.parse(fs.readFileSync(`${moduleDir}/locales/en-XL.json`, 'utf8')),
|
||||
'es': JSON.parse(fs.readFileSync(`${moduleDir}/locales/es.json`, 'utf8')),
|
||||
'es-419': JSON.parse(fs.readFileSync(`${moduleDir}/locales/es-419.json`, 'utf8')),
|
||||
'fi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fi.json`, 'utf8')),
|
||||
'fil': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fil.json`, 'utf8')),
|
||||
'fr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/fr.json`, 'utf8')),
|
||||
'he': JSON.parse(fs.readFileSync(`${moduleDir}/locales/he.json`, 'utf8')),
|
||||
'hi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hi.json`, 'utf8')),
|
||||
'hr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hr.json`, 'utf8')),
|
||||
'hu': JSON.parse(fs.readFileSync(`${moduleDir}/locales/hu.json`, 'utf8')),
|
||||
'id': JSON.parse(fs.readFileSync(`${moduleDir}/locales/id.json`, 'utf8')),
|
||||
'it': JSON.parse(fs.readFileSync(`${moduleDir}/locales/it.json`, 'utf8')),
|
||||
'ja': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ja.json`, 'utf8')),
|
||||
'ko': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ko.json`, 'utf8')),
|
||||
'lt': JSON.parse(fs.readFileSync(`${moduleDir}/locales/lt.json`, 'utf8')),
|
||||
'lv': JSON.parse(fs.readFileSync(`${moduleDir}/locales/lv.json`, 'utf8')),
|
||||
'nl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/nl.json`, 'utf8')),
|
||||
'no': JSON.parse(fs.readFileSync(`${moduleDir}/locales/no.json`, 'utf8')),
|
||||
'pl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pl.json`, 'utf8')),
|
||||
'pt': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pt.json`, 'utf8')),
|
||||
'pt-PT': JSON.parse(fs.readFileSync(`${moduleDir}/locales/pt-PT.json`, 'utf8')),
|
||||
'ro': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ro.json`, 'utf8')),
|
||||
'ru': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ru.json`, 'utf8')),
|
||||
'sk': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sk.json`, 'utf8')),
|
||||
'sl': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sl.json`, 'utf8')),
|
||||
'sr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sr.json`, 'utf8')),
|
||||
'sr-Latn': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sr-Latn.json`, 'utf8')),
|
||||
'sv': JSON.parse(fs.readFileSync(`${moduleDir}/locales/sv.json`, 'utf8')),
|
||||
'ta': JSON.parse(fs.readFileSync(`${moduleDir}/locales/ta.json`, 'utf8')),
|
||||
'te': JSON.parse(fs.readFileSync(`${moduleDir}/locales/te.json`, 'utf8')),
|
||||
'th': JSON.parse(fs.readFileSync(`${moduleDir}/locales/th.json`, 'utf8')),
|
||||
'tr': JSON.parse(fs.readFileSync(`${moduleDir}/locales/tr.json`, 'utf8')),
|
||||
'uk': JSON.parse(fs.readFileSync(`${moduleDir}/locales/uk.json`, 'utf8')),
|
||||
'vi': JSON.parse(fs.readFileSync(`${moduleDir}/locales/vi.json`, 'utf8')),
|
||||
'zh': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh.json`, 'utf8')),
|
||||
'zh-HK': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh-HK.json`, 'utf8')),
|
||||
'zh-TW': JSON.parse(fs.readFileSync(`${moduleDir}/locales/zh-TW.json`, 'utf8')),
|
||||
};
|
||||
|
||||
// The keys within this const must exactly match the LH.Locale type in externs.d.ts
|
||||
|
@ -172,4 +175,4 @@ const locales = {
|
|||
'zh-TW': files['zh-TW'], // aka zh-Hant, zh-Hant-TW, Traditional Chinese
|
||||
};
|
||||
|
||||
module.exports = locales;
|
||||
export {locales};
|
||||
|
|
|
@ -5,16 +5,20 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const swapLocale = require('./swap-locale.js');
|
||||
import {swapLocale} from './swap-locale.js';
|
||||
|
||||
/**
|
||||
* @param {LH.FlowResult} flowResult
|
||||
* @param {LH.Locale} locale
|
||||
*/
|
||||
module.exports = function swapFlowLocale(flowResult, locale) {
|
||||
function swapFlowLocale(flowResult, locale) {
|
||||
const localizedFlowResult = JSON.parse(JSON.stringify(flowResult));
|
||||
localizedFlowResult.steps = flowResult.steps.map(step => {
|
||||
return {...step, lhr: swapLocale(step.lhr, locale).lhr};
|
||||
});
|
||||
return localizedFlowResult;
|
||||
}
|
||||
|
||||
export {
|
||||
swapFlowLocale,
|
||||
};
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const _set = require('lodash/set.js');
|
||||
const _get = require('lodash/get.js');
|
||||
import _set from 'lodash/set.js';
|
||||
import _get from 'lodash/get.js';
|
||||
|
||||
const format = require('./format.js');
|
||||
import * as format from './format.js';
|
||||
|
||||
/**
|
||||
* @fileoverview Use the lhr.i18n.icuMessagePaths object to change locales.
|
||||
|
@ -110,4 +110,4 @@ function swapLocale(lhr, requestedLocale) {
|
|||
};
|
||||
}
|
||||
|
||||
module.exports = swapLocale;
|
||||
export {swapLocale};
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"type": "commonjs",
|
||||
"//": "Preserve commonjs in this directory. Temporary file until converted to type: module"
|
||||
}
|
|
@ -3,6 +3,7 @@
|
|||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
module.exports = {
|
||||
env: {
|
||||
|
|
|
@ -5,18 +5,16 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
import path from 'path';
|
||||
|
||||
const format = require('../../localization/format.js');
|
||||
const locales = require('../../localization/locales.js');
|
||||
import * as i18n from '../../../core/lib/i18n/i18n.js';
|
||||
import * as constants from '../../../core/config/constants.js';
|
||||
import * as format from '../../localization/format.js';
|
||||
import {locales} from '../../localization/locales.js';
|
||||
import {getModuleDirectory, getModulePath} from '../../../esm-utils.js';
|
||||
|
||||
// TODO(esmodules): remove when shared/ is esm
|
||||
let i18n;
|
||||
let constants;
|
||||
before(async () => {
|
||||
i18n = await import('../../../core/lib/i18n/i18n.js');
|
||||
constants = await import('../../../core/config/constants.js');
|
||||
});
|
||||
const moduleDir = getModuleDirectory(import.meta);
|
||||
const modulePath = getModulePath(import.meta);
|
||||
|
||||
describe('format', () => {
|
||||
describe('DEFAULT_LOCALE', () => {
|
||||
|
@ -83,7 +81,7 @@ describe('format', () => {
|
|||
|
||||
describe('#replaceIcuMessages', () => {
|
||||
it('replaces the references in the LHR', () => {
|
||||
const fakeFile = path.join(__dirname, 'fake-file-number-2.js');
|
||||
const fakeFile = path.join(moduleDir, 'fake-file-number-2.js');
|
||||
const UIStrings = {aString: 'different {x}!'};
|
||||
const formatter = i18n.createIcuMessageFn(fakeFile, UIStrings);
|
||||
|
||||
|
@ -115,14 +113,14 @@ describe('format', () => {
|
|||
describe('#getFormatted', () => {
|
||||
it('returns the formatted string', () => {
|
||||
const UIStrings = {testMessage: 'happy test'};
|
||||
const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
const formattedStr = format.getFormatted(str_(UIStrings.testMessage), 'en');
|
||||
expect(formattedStr).toEqual('happy test');
|
||||
});
|
||||
|
||||
it('returns the formatted string with replacements', () => {
|
||||
const UIStrings = {testMessage: 'replacement test ({errorCode})'};
|
||||
const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
const formattedStr = format.getFormatted(str_(UIStrings.testMessage,
|
||||
{errorCode: 'BOO'}), 'en');
|
||||
expect(formattedStr).toEqual('replacement test (BOO)');
|
||||
|
@ -131,7 +129,7 @@ describe('format', () => {
|
|||
it('throws an error for invalid locales', () => {
|
||||
// Populate a string to try to localize to a bad locale.
|
||||
const UIStrings = {testMessage: 'testy test'};
|
||||
const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
|
||||
expect(_ => format.getFormatted(str_(UIStrings.testMessage), 'still-not-a-locale'))
|
||||
.toThrow(`Unsupported locale 'still-not-a-locale'`);
|
||||
|
@ -141,7 +139,7 @@ describe('format', () => {
|
|||
const UIStrings = {
|
||||
testMessage: 'needs {count, number, bytes}KB test {str} in {timeInMs, number, seconds}s',
|
||||
};
|
||||
const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
|
||||
const replacements = {
|
||||
count: 2555,
|
||||
|
@ -172,8 +170,7 @@ describe('format', () => {
|
|||
|
||||
describe('#registerLocaleData', () => {
|
||||
// Store original locale data so we can restore at the end
|
||||
const moduleLocales = require('../../localization/locales.js');
|
||||
const clonedLocales = JSON.parse(JSON.stringify(moduleLocales));
|
||||
const clonedLocales = JSON.parse(JSON.stringify(locales));
|
||||
|
||||
it('installs new locale strings', () => {
|
||||
const localeData = {
|
||||
|
@ -184,7 +181,7 @@ describe('format', () => {
|
|||
format.registerLocaleData('en-XZ', localeData);
|
||||
|
||||
const UIStrings = {testString: 'en-US string!'};
|
||||
const str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
const str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
const formattedStr = format.getFormatted(str_(UIStrings.testString), 'en-XZ');
|
||||
expect(formattedStr).toEqual('en-XZ cuerda!');
|
||||
});
|
||||
|
@ -217,7 +214,7 @@ describe('format', () => {
|
|||
expect(newFailureTitle).toEqual('Does not use HTTPS');
|
||||
|
||||
// Restore overwritten strings to avoid messing with other tests
|
||||
moduleLocales['es-419'] = clonedLocales['es-419'];
|
||||
locales['es-419'] = clonedLocales['es-419'];
|
||||
const title = format.getFormatted(str_(UIStrings.title), 'es-419');
|
||||
expect(title).toEqual('Usa HTTPS');
|
||||
});
|
||||
|
@ -324,7 +321,7 @@ describe('format', () => {
|
|||
|
||||
let str_;
|
||||
before(() => {
|
||||
str_ = i18n.createIcuMessageFn(__filename, UIStrings);
|
||||
str_ = i18n.createIcuMessageFn(modulePath, UIStrings);
|
||||
});
|
||||
|
||||
it('formats a basic message', () => {
|
||||
|
|
|
@ -5,8 +5,8 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const locales = require('../../localization/locales.js');
|
||||
const assert = require('assert').strict;
|
||||
import {locales} from '../../localization/locales.js';
|
||||
import {strict as assert} from 'assert';
|
||||
|
||||
describe('locales', () => {
|
||||
it('has only canonical (or expected-deprecated) language tags', () => {
|
||||
|
|
|
@ -5,9 +5,10 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const swapLocale = require('../../localization/swap-locale.js');
|
||||
import {swapLocale} from '../../localization/swap-locale.js';
|
||||
import {readJson} from '../../../core/test/test-utils.js';
|
||||
|
||||
const lhr = require('../../../core/test/results/sample_v2.json');
|
||||
const lhr = readJson('core/test/results/sample_v2.json');
|
||||
|
||||
describe('swap-locale', () => {
|
||||
it('does not mutate the original lhr', () => {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
"include": [
|
||||
"**/*.js",
|
||||
"types/**/*.d.ts",
|
||||
"../esm-utils.js",
|
||||
],
|
||||
"exclude": [
|
||||
"test/**/*.js",
|
||||
|
|
|
@ -29,7 +29,7 @@ function isObjectOrArrayOfUnknownValues(val) {
|
|||
return typeof val === 'object' && val !== null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
export {
|
||||
isObjectOfUnknownValues,
|
||||
isObjectOrArrayOfUnknownValues,
|
||||
};
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
"core/test/lib/tracehouse/main-thread-tasks-test.js",
|
||||
"core/test/lib/tracehouse/task-summary-test.js",
|
||||
"core/test/lib/tracehouse/trace-processor-test.js",
|
||||
"core/test/lib/traces/metric-trace-events-test.js",
|
||||
"core/test/lib/traces/metrics-trace-events-test.js",
|
||||
"core/test/lib/url-shim-test.js",
|
||||
"core/test/network-records-to-devtools-log-test.js",
|
||||
"core/test/runner-test.js",
|
||||
|
|
Загрузка…
Ссылка в новой задаче