[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update to latest chrome-devtools-frontend #15137

Merged
merged 2 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 17 additions & 42 deletions build/build-cdt-lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,65 +34,31 @@ const modifications = [
'const Common = require(\'../Common.js\');',
'const Platform = require(\'../Platform.js\');',
'%sourceFilePrinted%',
'module.exports = TextSourceMap;',
'module.exports = SourceMap;',
'SourceMap.parseSourceMap = parseSourceMap;',
].join('\n'),
rawCodeToReplace: {
/* Original:

let url = Common.ParsedURL.ParsedURL.completeURL(this.#baseURL, href) || href;
const source = sourceMap.sourcesContent && sourceMap.sourcesContent[i];
if (url === this.#compiledURLInternal && source) {
url = Common.ParsedURL.ParsedURL.concatenate(url, '? [sm]');
}
if (this.#sourceInfos.has(url)) {
continue;
}
this.#sourceInfos.set(url, new TextSourceMap.SourceInfo(source || null, null));
sourcesList.push(url);
----
If a source file is the same as the compiled url and there is a sourcesContent,
then `entry.sourceURL` (what is returned from .mappings) will have `? [sm]` appended.
This is useful in DevTools - to show that a sources panel tab not a real network resource -
but for us it is not wanted. The sizing function uses `entry.sourceURL` to index the byte
counts, and is further used in the details to specify a file within a source map.
*/
[`url = Common.ParsedURL.ParsedURL.concatenate(url, '? [sm]');`]: '',
// Use normal console.warn so we don't need to import CDT's logger.
'Common.Console.Console.instance().warn': 'console.warn',
// Similar to the reason for removing `url += Common.UIString('? [sm]')`.
// The entries in `.mappings` should not have their url property modified.
// The sizing function uses `entry.sourceURL` to index the byte
// counts, and is further used in the details to specify a file within a source map.
'Common.ParsedURL.ParsedURL.completeURL(this.#baseURL, href)': `''`,
// Replace i18n function with a very simple templating function.
'i18n.i18n.getLocalizedString.bind(undefined, str_)': (
/** @param {string} template @param {object} vars */
function(template, vars) {
let result = template;
for (const [key, value] of Object.entries(vars)) {
result = result.replace(new RegExp('{' + key + '}'), value);
}
return result;
}).toString(),
// Add some types.
// eslint-disable-next-line max-len
'mappings(): SourceMapEntry[] {': '/** @return {Array<{lineNumber: number, columnNumber: number, sourceURL?: string, sourceLineNumber: number, sourceColumnNumber: number, name?: string, lastColumnNumber?: number}>} */\nmappings(): SourceMapEntry[] {',
},
classesToRemove: [],
methodsToRemove: [
// Not needed.
'compatibleForURL',
'load',
// Not needed.
'sourceContentProvider',
'reverseMapTextRanges',
],
variablesToRemove: [
'Common',
'CompilerSourceMappingContentProvider_js_1',
'i18n',
'i18nString',
'PageResourceLoader_js_1',
'Platform',
'str_',
'TextUtils',
'UIStrings',
],
},
{
Expand Down Expand Up @@ -233,15 +199,24 @@ function doModification(modification) {
sourceFilePrinted += printer.printNode(ts.EmitHint.Unspecified, node, sourceFile) + '\n';
});

const content = modification.template.replace('%sourceFilePrinted%', () => sourceFilePrinted);
writeGeneratedFile(modification.output, content);
}

/**
* @param {string} outputPath
* @param {string} contents
*/
function writeGeneratedFile(outputPath, contents) {
const modifiedFile = [
'// @ts-nocheck\n',
'// generated by yarn build-cdt-lib\n',
'/* eslint-disable */\n',
'"use strict";\n',
modification.template.replace('%sourceFilePrinted%', () => sourceFilePrinted),
contents,
].join('');

fs.writeFileSync(modification.output, modifiedFile);
fs.writeFileSync(outputPath, modifiedFile);
}

modifications.forEach(doModification);
66 changes: 28 additions & 38 deletions build/build-cdt-strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ function doReplacement(text, searchValue, replaceValue) {
return newValue;
}

/**
* @param {string} text
* @param {[string|RegExp, string][]} replacements
*/
function doReplacements(text, replacements) {
for (const replacement of replacements) {
text = doReplacement(text, replacement[0], replacement[1]);
}
return text;
}

/**
* @param {string} text
* @param {string} startPattern
Expand All @@ -31,11 +42,8 @@ function extract(text, startPattern, endPattern, replacements = []) {
const endIndex = text.indexOf(endPattern, startIndex);
if (endIndex === -1) throw new Error(`could not find: ${endPattern}`);

let subText = text.substring(startIndex, endIndex + endPattern.length);
for (const replacement of replacements) {
subText = doReplacement(subText, replacement[0], replacement[1]);
}
return subText;
const subText = text.substring(startIndex, endIndex + endPattern.length);
return doReplacements(subText, replacements);
}

/**
Expand All @@ -59,39 +67,21 @@ ${extraCode}`.trimStart();
// core/lib/deprecations-strings.js
{
// eslint-disable-next-line max-len
const inFile = `${LH_ROOT}/node_modules/chrome-devtools-frontend/front_end/models/issues_manager/DeprecationIssue.ts`;
const outFile = `${LH_ROOT}/core/lib/deprecations-strings.js`;

const input = fs.readFileSync(inFile, 'utf-8');

const uiStringsDeclare = extract(input, 'const UIStrings', '};', [
// Some patterns are supported in DevTools UIStrings, but not ours.
[/\\\\/g, ''],
[`\\'plan-b\\'`, 'plan-b'],
]);
const getDescriptionDeclare =
extract(input, 'getDescription(): MarkdownIssueDescription', '});\n }', [
['getDescription(): MarkdownIssueDescription', 'function getDescription(issueDetails)'],
['this.#issueDetails', 'issueDetails'],
[`let messageFunction = (): string => '';`, `let message;`],
[/messageFunction/g, 'message'],
[/i18nLazyString/g, 'str_'],
['resolveLazyDescription', ''],
['links,', 'links, message,'],
[/Protocol\.Audits\.DeprecationIssueType\.(\w+)/g, `'$1'`],
]);

const extraCode = `
/**
* @param {LH.Crdp.Audits.DeprecationIssueDetails} issueDetails
*/
${getDescriptionDeclare}

export {
getDescription as getIssueDetailDescription,
UIStrings,
};`;
fs.writeFileSync(outFile, createStringsModule(uiStringsDeclare, extraCode));
const uiStringsFile = `${LH_ROOT}/node_modules/chrome-devtools-frontend/front_end/generated/Deprecation.ts`;
const generatedDeprecationSourceText = [
'// auto-generated by build/build-cdt-strings.js\n',
'/* eslint-disable */\n',
doReplacements(fs.readFileSync(uiStringsFile, 'utf-8'), [
[': Partial<Record<string, DeprecationDescriptor>>', ''],
['export interface DeprecationDescriptor {', ''],
[' milestone?: number;', ''],
[' chromeStatusFeature?: number;\n}', ''],
// Some patterns are supported in DevTools UIStrings, but not ours.
[/\\\\/g, ''],
[`{imageOrientation: 'from-image'}`, `\\\\{imageOrientation: 'from-image'\\\\}`],
]),
].join('');
fs.writeFileSync(`${LH_ROOT}/core/lib/deprecations-strings.js`, generatedDeprecationSourceText);
}

// core/lib/bf-cache-strings.js
Expand Down
2 changes: 1 addition & 1 deletion core/audits/deprecations.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import {Audit} from './audit.js';
import {JSBundles} from '../computed/js-bundles.js';
import * as i18n from '../lib/i18n/i18n.js';
import {getIssueDetailDescription} from '../lib/deprecations-strings.js';
import {getIssueDetailDescription} from '../lib/deprecation-description.js';

/* eslint-disable max-len */
const UIStrings = {
Expand Down
Loading
Loading