55 */
66import * as fs from 'node:fs' ;
77import * as path from 'node:path' ;
8- import tsConfig from '../tsconfig.json' with { type : 'json' } ;
8+ import tsConfig from '../tsconfig.json' with { type : 'json' } ;
99const BUILD_DIR = path . join ( process . cwd ( ) , 'build' ) ;
1010/**
1111 * Writes content to a file.
1212 * @param filePath The path to the file.
1313 * @param content The content to write.
1414 */
1515function writeFile ( filePath , content ) {
16- fs . writeFileSync ( filePath , content , 'utf-8' ) ;
16+ fs . writeFileSync ( filePath , content , 'utf-8' ) ;
1717}
1818/**
1919 * Replaces content in a file.
@@ -22,40 +22,44 @@ function writeFile(filePath, content) {
2222 * @param replace The string to replace with.
2323 */
2424function sed ( filePath , find , replace ) {
25- if ( ! fs . existsSync ( filePath ) ) {
26- console . warn ( `File not found for sed operation: ${ filePath } ` ) ;
27- return ;
28- }
29- const content = fs . readFileSync ( filePath , 'utf-8' ) ;
30- const newContent = content . replace ( find , replace ) ;
31- fs . writeFileSync ( filePath , newContent , 'utf-8' ) ;
25+ if ( ! fs . existsSync ( filePath ) ) {
26+ console . warn ( `File not found for sed operation: ${ filePath } ` ) ;
27+ return ;
28+ }
29+ const content = fs . readFileSync ( filePath , 'utf-8' ) ;
30+ const newContent = content . replace ( find , replace ) ;
31+ fs . writeFileSync ( filePath , newContent , 'utf-8' ) ;
3232}
3333/**
3434 * Ensures that licenses for third party files we use gets copied into the build/ dir.
3535 */
3636function copyThirdPartyLicenseFiles ( ) {
37- const thirdPartyDirectories = tsConfig . include . filter ( location => {
38- return location . includes ( 'node_modules/chrome-devtools-frontend/front_end/third_party' ) ;
39- } ) ;
40- for ( const thirdPartyDir of thirdPartyDirectories ) {
41- const fullPath = path . join ( process . cwd ( ) , thirdPartyDir ) ;
42- const licenseFile = path . join ( fullPath , 'LICENSE' ) ;
43- if ( ! fs . existsSync ( licenseFile ) ) {
44- console . error ( 'No LICENSE for' , path . basename ( thirdPartyDir ) ) ;
45- }
46- const destinationDir = path . join ( BUILD_DIR , thirdPartyDir ) ;
47- const destinationFile = path . join ( destinationDir , 'LICENSE' ) ;
48- fs . copyFileSync ( licenseFile , destinationFile ) ;
37+ const thirdPartyDirectories = tsConfig . include . filter ( location => {
38+ return location . includes (
39+ 'node_modules/chrome-devtools-frontend/front_end/third_party' ,
40+ ) ;
41+ } ) ;
42+ for ( const thirdPartyDir of thirdPartyDirectories ) {
43+ const fullPath = path . join ( process . cwd ( ) , thirdPartyDir ) ;
44+ const licenseFile = path . join ( fullPath , 'LICENSE' ) ;
45+ if ( ! fs . existsSync ( licenseFile ) ) {
46+ console . error ( 'No LICENSE for' , path . basename ( thirdPartyDir ) ) ;
4947 }
48+ const destinationDir = path . join ( BUILD_DIR , thirdPartyDir ) ;
49+ const destinationFile = path . join ( destinationDir , 'LICENSE' ) ;
50+ fs . copyFileSync ( licenseFile , destinationFile ) ;
51+ }
5052}
5153function main ( ) {
52- const devtoolsThirdPartyPath = 'node_modules/chrome-devtools-frontend/front_end/third_party' ;
53- const devtoolsFrontEndCorePath = 'node_modules/chrome-devtools-frontend/front_end/core' ;
54- // Create i18n mock
55- const i18nDir = path . join ( BUILD_DIR , devtoolsFrontEndCorePath , 'i18n' ) ;
56- fs . mkdirSync ( i18nDir , { recursive : true } ) ;
57- const i18nFile = path . join ( i18nDir , 'i18n.js' ) ;
58- const i18nContent = `
54+ const devtoolsThirdPartyPath =
55+ 'node_modules/chrome-devtools-frontend/front_end/third_party' ;
56+ const devtoolsFrontEndCorePath =
57+ 'node_modules/chrome-devtools-frontend/front_end/core' ;
58+ // Create i18n mock
59+ const i18nDir = path . join ( BUILD_DIR , devtoolsFrontEndCorePath , 'i18n' ) ;
60+ fs . mkdirSync ( i18nDir , { recursive : true } ) ;
61+ const i18nFile = path . join ( i18nDir , 'i18n.js' ) ;
62+ const i18nContent = `
5963export const i18n = {
6064 registerUIStrings: () => {},
6165 getLocalizedString: (_, str) => {
@@ -115,35 +119,54 @@ export const ByteUtilities = {
115119 return parts.map(part => part.value).join('');
116120 }
117121};` ;
118- writeFile ( i18nFile , i18nContent ) ;
119- // Create codemirror.next mock.
120- const codeMirrorDir = path . join ( BUILD_DIR , devtoolsThirdPartyPath , 'codemirror.next' ) ;
121- fs . mkdirSync ( codeMirrorDir , { recursive : true } ) ;
122- const codeMirrorFile = path . join ( codeMirrorDir , 'codemirror.next.js' ) ;
123- const codeMirrorContent = `export default {}` ;
124- writeFile ( codeMirrorFile , codeMirrorContent ) ;
125- // Create root mock
126- const rootDir = path . join ( BUILD_DIR , devtoolsFrontEndCorePath , 'root' ) ;
127- fs . mkdirSync ( rootDir , { recursive : true } ) ;
128- const runtimeFile = path . join ( rootDir , 'Runtime.js' ) ;
129- const runtimeContent = `
122+ writeFile ( i18nFile , i18nContent ) ;
123+ // Create codemirror.next mock.
124+ const codeMirrorDir = path . join (
125+ BUILD_DIR ,
126+ devtoolsThirdPartyPath ,
127+ 'codemirror.next' ,
128+ ) ;
129+ fs . mkdirSync ( codeMirrorDir , { recursive : true } ) ;
130+ const codeMirrorFile = path . join ( codeMirrorDir , 'codemirror.next.js' ) ;
131+ const codeMirrorContent = `export default {}` ;
132+ writeFile ( codeMirrorFile , codeMirrorContent ) ;
133+ // Create root mock
134+ const rootDir = path . join ( BUILD_DIR , devtoolsFrontEndCorePath , 'root' ) ;
135+ fs . mkdirSync ( rootDir , { recursive : true } ) ;
136+ const runtimeFile = path . join ( rootDir , 'Runtime.js' ) ;
137+ const runtimeContent = `
130138export function getChromeVersion() { return ''; };
131139export const hostConfig = {};
132140 ` ;
133- writeFile ( runtimeFile , runtimeContent ) ;
134- // Update protocol_client to remove:
135- // 1. self.Protocol assignment
136- // 2. Call to register backend commands.
137- const protocolClientDir = path . join ( BUILD_DIR , devtoolsFrontEndCorePath , 'protocol_client' ) ;
138- const clientFile = path . join ( protocolClientDir , 'protocol_client.js' ) ;
139- const globalAssignment = / s e l f \. P r o t o c o l = s e l f \. P r o t o c o l \| \| \{ \} ; / ;
140- const registerCommands = / I n s p e c t o r B a c k e n d C o m m a n d s \. r e g i s t e r C o m m a n d s \( I n s p e c t o r B a c k e n d \. i n s p e c t o r B a c k e n d \) ; / ;
141- sed ( clientFile , globalAssignment , '' ) ;
142- sed ( clientFile , registerCommands , '' ) ;
143- const devtoolsLicensePath = path . join ( 'node_modules' , 'chrome-devtools-frontend' , 'LICENSE' ) ;
144- const devtoolsLicenseFileSource = path . join ( process . cwd ( ) , devtoolsLicensePath ) ;
145- const devtoolsLicenseFileDestination = path . join ( BUILD_DIR , devtoolsLicensePath ) ;
146- fs . copyFileSync ( devtoolsLicenseFileSource , devtoolsLicenseFileDestination ) ;
147- copyThirdPartyLicenseFiles ( ) ;
141+ writeFile ( runtimeFile , runtimeContent ) ;
142+ // Update protocol_client to remove:
143+ // 1. self.Protocol assignment
144+ // 2. Call to register backend commands.
145+ const protocolClientDir = path . join (
146+ BUILD_DIR ,
147+ devtoolsFrontEndCorePath ,
148+ 'protocol_client' ,
149+ ) ;
150+ const clientFile = path . join ( protocolClientDir , 'protocol_client.js' ) ;
151+ const globalAssignment = / s e l f \. P r o t o c o l = s e l f \. P r o t o c o l \| \| \{ \} ; / ;
152+ const registerCommands =
153+ / I n s p e c t o r B a c k e n d C o m m a n d s \. r e g i s t e r C o m m a n d s \( I n s p e c t o r B a c k e n d \. i n s p e c t o r B a c k e n d \) ; / ;
154+ sed ( clientFile , globalAssignment , '' ) ;
155+ sed ( clientFile , registerCommands , '' ) ;
156+ const devtoolsLicensePath = path . join (
157+ 'node_modules' ,
158+ 'chrome-devtools-frontend' ,
159+ 'LICENSE' ,
160+ ) ;
161+ const devtoolsLicenseFileSource = path . join (
162+ process . cwd ( ) ,
163+ devtoolsLicensePath ,
164+ ) ;
165+ const devtoolsLicenseFileDestination = path . join (
166+ BUILD_DIR ,
167+ devtoolsLicensePath ,
168+ ) ;
169+ fs . copyFileSync ( devtoolsLicenseFileSource , devtoolsLicenseFileDestination ) ;
170+ copyThirdPartyLicenseFiles ( ) ;
148171}
149172main ( ) ;
0 commit comments