-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathpost-build.ts
More file actions
152 lines (134 loc) · 4.67 KB
/
post-build.ts
File metadata and controls
152 lines (134 loc) · 4.67 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
141
142
143
144
145
146
147
148
149
150
151
152
/**
* @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 {}`;
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 const hostConfig = {};
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);
copyDevToolsDescriptionFiles();
copySnapshotFiles();
}
function copySnapshotFiles() {
const testsDir = path.join(process.cwd(), 'tests');
const buildTestsDir = path.join(BUILD_DIR, 'tests');
if (!fs.existsSync(buildTestsDir)) {
fs.mkdirSync(buildTestsDir, {recursive: true});
}
const files = fs.readdirSync(testsDir);
for (const file of files) {
if (file.endsWith('.snapshot')) {
fs.copyFileSync(
path.join(testsDir, file),
path.join(buildTestsDir, file),
);
}
}
// Also handle subdirectories if needed, but for now we only have snapshots in the root of tests/
// Wait, let's check tools/
const toolsTestsDir = path.join(testsDir, 'tools');
const buildToolsTestsDir = path.join(buildTestsDir, 'tools');
if (fs.existsSync(toolsTestsDir)) {
if (!fs.existsSync(buildToolsTestsDir)) {
fs.mkdirSync(buildToolsTestsDir, {recursive: true});
}
const toolsFiles = fs.readdirSync(toolsTestsDir);
for (const file of toolsFiles) {
if (file.endsWith('.snapshot')) {
fs.copyFileSync(
path.join(toolsTestsDir, file),
path.join(buildToolsTestsDir, file),
);
}
}
}
}
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();