mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-10-07 04:26:32 +08:00
This refactors away the cachedResources from an object map to a normal Map as defined in `Runtime.js`. The Map is used during boot time by setting the relevant stylesheet contents, which is included by `build_release_applications`. Moreover, it moves the `*_module.js` files into the `modules` array rather than scripts. This ensures that `*_module.js` files can use ES imports. In a follow-up CL, we can do additional cleanup in the Runtime to stop retrieving `resources` in `_loadResources`, as that should no longer be possible. (In both debug and non-debug we build the appropriate `_module.js` files) R=aerotwist@chromium.org,aerotwist@chromium.org Bug: 1058320 Change-Id: I89602b332360338f5914038f6cd505f75b531f8e Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2398829 Reviewed-by: Paul Lewis <aerotwist@chromium.org> Reviewed-by: Jack Franklin <jacktfranklin@chromium.org> Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
66 lines
2.0 KiB
JavaScript
66 lines
2.0 KiB
JavaScript
// Copyright 2020 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import * as Marked from '../marked/marked.js';
|
|
import * as Root from '../root/root.js';
|
|
import * as SDK from '../sdk/sdk.js';
|
|
|
|
import {createMarkdownView} from './MarkdownView_bridge.js';
|
|
|
|
/**
|
|
* @param {!SDK.Issue.MarkdownIssueDescription} description
|
|
* @return {!SDK.Issue.IssueDescription}
|
|
*/
|
|
export function createIssueDescriptionFromMarkdown(description) {
|
|
const rawMarkdown = getMarkdownFileContent(description.file);
|
|
return createIssueDescriptionFromRawMarkdown(rawMarkdown, description);
|
|
}
|
|
|
|
/**
|
|
* @param {string} filename
|
|
* @return {string}
|
|
*/
|
|
function getMarkdownFileContent(filename) {
|
|
const rawMarkdown = Root.Runtime.cachedResources.get(filename);
|
|
if (!rawMarkdown) {
|
|
throw new Error(`Markdown file ${filename} not found. Declare it as a resource in the module.json file`);
|
|
}
|
|
return rawMarkdown;
|
|
}
|
|
|
|
/**
|
|
* @param {string} markdown
|
|
* @param {!SDK.Issue.MarkdownIssueDescription} description
|
|
* @return {!SDK.Issue.IssueDescription}
|
|
*
|
|
* This function is exported separately for unit testing.
|
|
*/
|
|
export function createIssueDescriptionFromRawMarkdown(markdown, description) {
|
|
const markdownAst = Marked.Marked.lexer(markdown);
|
|
const title = findTitleFromMarkdownAst(markdownAst);
|
|
if (!title) {
|
|
throw new Error('Markdown issue descriptions must start with a heading');
|
|
}
|
|
|
|
const markdownComponent = createMarkdownView();
|
|
markdownComponent.data = {tokens: markdownAst.slice(1)};
|
|
return {
|
|
title,
|
|
message: () => markdownComponent,
|
|
issueKind: SDK.Issue.IssueKind.BreakingChange,
|
|
links: description.links
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @param {!Array<*>} markdownAst
|
|
* @return {?string}
|
|
*/
|
|
function findTitleFromMarkdownAst(markdownAst) {
|
|
if (markdownAst.length === 0 || markdownAst[0].type !== 'heading' || markdownAst[0].depth !== 1) {
|
|
return null;
|
|
}
|
|
return markdownAst[0].text;
|
|
}
|