Skip to content

Commit 18eaebb

Browse files
Nima21claude
andcommitted
fix: exclude generated JS files from ESLint and format them
- Added scripts/prepare.js and scripts/post-build.js to ESLint ignore list - Formatted post-build.js with Prettier - Fixes check-format workflow failures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent cbd6555 commit 18eaebb

File tree

2 files changed

+79
-56
lines changed

2 files changed

+79
-56
lines changed

eslint.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import tseslint from 'typescript-eslint';
1414
import localPlugin from './scripts/eslint_rules/local-plugin.js';
1515

1616
export default defineConfig([
17-
globalIgnores(['**/node_modules', '**/build/']),
17+
globalIgnores(['**/node_modules', '**/build/', 'scripts/prepare.js', 'scripts/post-build.js']),
1818
importPlugin.flatConfigs.typescript,
1919
{
2020
languageOptions: {

scripts/post-build.js

Lines changed: 78 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
*/
66
import * as fs from 'node:fs';
77
import * as path from 'node:path';
8-
import tsConfig from '../tsconfig.json' with { type: 'json' };
8+
import tsConfig from '../tsconfig.json' with {type: 'json'};
99
const 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
*/
1515
function 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
*/
2424
function 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
*/
3636
function 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
}
5153
function 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 = `
5963
export 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 = `
130138
export function getChromeVersion() { return ''; };
131139
export 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 = /self\.Protocol = self\.Protocol \|\| \{\};/;
140-
const registerCommands = /InspectorBackendCommands\.registerCommands\(InspectorBackend\.inspectorBackend\);/;
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 = /self\.Protocol = self\.Protocol \|\| \{\};/;
152+
const registerCommands =
153+
/InspectorBackendCommands\.registerCommands\(InspectorBackend\.inspectorBackend\);/;
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
}
149172
main();

0 commit comments

Comments
 (0)