-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathpost-build.ts
More file actions
140 lines (125 loc) · 4.63 KB
/
post-build.ts
File metadata and controls
140 lines (125 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import * as fs from 'node:fs';
import * as path from 'node:path';
const BUILD_DIR = path.join(process.cwd(), 'build');
/**
* Writes content to a file.
* @param filePath The path to the file.
* @param content The content to write.
*/
function writeFile(filePath: string, content: string): void {
fs.writeFileSync(filePath, content, 'utf-8');
}
function main(): void {
const devtoolsThirdPartyPath =
'node_modules/chrome-devtools-frontend/front_end/third_party';
const devtoolsFrontEndCorePath =
'node_modules/chrome-devtools-frontend/front_end/core';
// Create i18n mock
const i18nDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'i18n');
fs.mkdirSync(i18nDir, {recursive: true});
const localesFile = path.join(i18nDir, 'locales.js');
const localesContent = `
export const LOCALES = [
'en-US',
];
export const BUNDLED_LOCALES = [
'en-US',
];
export const DEFAULT_LOCALE = 'en-US';
export const REMOTE_FETCH_PATTERN = '@HOST@/remote/serve_file/@VERSION@/core/i18n/locales/@LOCALE@.json';
export const LOCAL_FETCH_PATTERN = './locales/@LOCALE@.json';`;
writeFile(localesFile, localesContent);
// Create codemirror.next mock.
const codeMirrorDir = path.join(
BUILD_DIR,
devtoolsThirdPartyPath,
'codemirror.next',
);
fs.mkdirSync(codeMirrorDir, {recursive: true});
const codeMirrorFile = path.join(codeMirrorDir, 'codemirror.next.js');
const codeMirrorContent = `
export default {};
export const cssStreamParser = () => Promise.resolve({ startState: () => ({}) });
export class StringStream { constructor() {} }
export const css = { cssLanguage: { parser: { parse: () => ({ topNode: { getChild: () => null } }) } } };
`;
writeFile(codeMirrorFile, codeMirrorContent);
// Create root mock
const rootDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'root');
fs.mkdirSync(rootDir, {recursive: true});
const runtimeFile = path.join(rootDir, 'Runtime.js');
const runtimeContent = `
export function getChromeVersion() { return ''; };
export function getRemoteBase() { return null; };
export const hostConfig = {};
export const GdpProfilesEnterprisePolicyValue = {
ENABLED: 0,
ENABLED_WITHOUT_BADGES: 1,
DISABLED: 2,
};
export const Runtime = {
isDescriptorEnabled: () => true,
queryParam: () => null,
}
export const experiments = {
isEnabled: () => false,
}
export const ExperimentName = {
ALL: '*',
CAPTURE_NODE_CREATION_STACKS: 'capture-node-creation-stacks',
LIVE_HEAP_PROFILE: 'live-heap-profile',
PROTOCOL_MONITOR: 'protocol-monitor',
SAMPLING_HEAP_PROFILER_TIMELINE: 'sampling-heap-profiler-timeline',
SHOW_OPTION_TO_EXPOSE_INTERNALS_IN_HEAP_SNAPSHOT: 'show-option-to-expose-internals-in-heap-snapshot',
TIMELINE_INVALIDATION_TRACKING: 'timeline-invalidation-tracking',
TIMELINE_SHOW_ALL_EVENTS: 'timeline-show-all-events',
TIMELINE_V8_RUNTIME_CALL_STATS: 'timeline-v8-runtime-call-stats',
APCA: 'apca',
FONT_EDITOR: 'font-editor',
FULL_ACCESSIBILITY_TREE: 'full-accessibility-tree',
CONTRAST_ISSUES: 'contrast-issues',
EXPERIMENTAL_COOKIE_FEATURES: 'experimental-cookie-features',
INSTRUMENTATION_BREAKPOINTS: 'instrumentation-breakpoints',
AUTHORED_DEPLOYED_GROUPING: 'authored-deployed-grouping',
JUST_MY_CODE: 'just-my-code',
USE_SOURCE_MAP_SCOPES: 'use-source-map-scopes',
TIMELINE_SHOW_POST_MESSAGE_EVENTS: 'timeline-show-postmessage-events',
TIMELINE_DEBUG_MODE: 'timeline-debug-mode',
}
`;
writeFile(runtimeFile, runtimeContent);
// Copy missing CodeMirror .mjs files that tsc ignores due to .d.mts renames
const codemirrorDir = path.join(BUILD_DIR, devtoolsThirdPartyPath, 'codemirror');
const codemirrorSrcDir = path.join(process.cwd(), 'node_modules', 'chrome-devtools-frontend', 'front_end', 'third_party', 'codemirror');
const filesToCopy = [
'package/addon/runmode/runmode-standalone.mjs',
'package/mode/css/css.mjs',
'package/mode/javascript/javascript.mjs',
'package/mode/xml/xml.mjs',
];
for (const file of filesToCopy) {
const src = path.join(codemirrorSrcDir, file);
const dest = path.join(codemirrorDir, file);
fs.mkdirSync(path.dirname(dest), {recursive: true});
fs.copyFileSync(src, dest);
}
copyDevToolsDescriptionFiles();
}
function copyDevToolsDescriptionFiles() {
const devtoolsIssuesDescriptionPath =
'node_modules/chrome-devtools-frontend/front_end/models/issues_manager/descriptions';
const sourceDir = path.join(process.cwd(), devtoolsIssuesDescriptionPath);
const destDir = path.join(
BUILD_DIR,
'src',
'third_party',
'issue-descriptions',
);
fs.cpSync(sourceDir, destDir, {recursive: true});
}
main();