Skip to content

Fix: clean monaco editor language support files#5

Open
ghanithan wants to merge 1 commit intomainfrom
clean_monaco
Open

Fix: clean monaco editor language support files#5
ghanithan wants to merge 1 commit intomainfrom
clean_monaco

Conversation

@ghanithan
Copy link
Owner

Pull Request

Description

Brief description of the changes in this PR.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New exercise (adds a new learning exercise)
  • Exercise improvement (enhances existing exercise)
  • Feature (new functionality for platform)
  • Documentation (updates to docs, README, etc.)
  • Refactoring (code cleanup, no functional changes)

Exercise Changes (if applicable)

  • Chapter:
  • Exercise ID:
  • Type: (Code Completion/Bug Fix/From Scratch/Code Review/Performance)
  • Difficulty: (Beginner/Intermediate/Advanced)

Testing Checklist

  • Exercise compiles without warnings
  • All tests pass (cargo test)
  • Clippy passes (cargo clippy)
  • Exercise is completable by target audience
  • Hints are helpful without giving away solution
  • Solution explanation is clear and educational
  • Rust Book references are accurate and relevant

Quality Checklist

  • Code follows project style guidelines
  • Comments are clear and helpful
  • Error messages are beginner-friendly
  • Exercise metadata is complete and accurate
  • No hardcoded solutions or shortcuts

Documentation Updates

  • Updated exercise list in README
  • Added/updated hints.md file
  • Updated chapter progress tracking
  • Added Rust Book references

Breaking Changes

Does this PR introduce any breaking changes?

  • Yes (describe below)
  • No

If yes, describe the breaking changes and migration path:

Additional Notes

Any additional context, screenshots, or information relevant to this PR.

Copilot AI review requested due to automatic review settings August 23, 2025 11:48
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements post-build cleanup functionality for Monaco Editor language support files to reduce bundle size. The changes configure Monaco Editor with specific language workers and add an automated cleanup script that removes unused language files after the build process.

  • Configures Monaco Editor plugin with specific language workers (JSON, TypeScript)
  • Adds post-build cleanup script to remove unnecessary Monaco language files
  • Updates build process to automatically run cleanup after Vite build

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
web/vite.config.js Configures Monaco Editor plugin with specific language workers and global API
web/scripts/cleanup-monaco.js Implements cleanup script to remove unused Monaco language files from build output
web/package.json Updates build command to run cleanup script automatically after Vite build

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +2 to +3
import pkg from 'vite-plugin-monaco-editor';
const monacoEditorPlugin = pkg.default || pkg;
Copy link

Copilot AI Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The import pattern with fallback logic suggests the plugin may export differently across versions. Consider using a more explicit import pattern or adding a comment explaining why this approach is needed.

Suggested change
import pkg from 'vite-plugin-monaco-editor';
const monacoEditorPlugin = pkg.default || pkg;

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +27
'rust-', // Rust language support
'javascript-', // JavaScript support
'typescript-', // TypeScript support
'css-', // CSS support
'html-', // HTML support
'markdown-', // Markdown support
'scss-', // SCSS support
'jsonMode-', // JSON mode (workers)
'cssMode-', // CSS mode (workers)
'htmlMode-', // HTML mode (workers)
Copy link

Copilot AI Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The keep patterns include many languages (rust, javascript, css, html, etc.) but the Vite config only specifies 'json' and 'typescript' workers. This inconsistency could result in keeping files for languages that aren't properly configured.

Suggested change
'rust-', // Rust language support
'javascript-', // JavaScript support
'typescript-', // TypeScript support
'css-', // CSS support
'html-', // HTML support
'markdown-', // Markdown support
'scss-', // SCSS support
'jsonMode-', // JSON mode (workers)
'cssMode-', // CSS mode (workers)
'htmlMode-', // HTML mode (workers)
'jsonMode-', // JSON mode (workers)

Copilot uses AI. Check for mistakes.
Comment on lines +43 to +72
files.forEach(file => {
const filePath = path.join(distAssetsDir, file);
const stats = fs.statSync(filePath);

if (!stats.isFile()) {
return;
}

// For JS files, check if we should keep them
if (file.endsWith('.js')) {
// Check if it matches any of our keep patterns
const shouldKeep = keepPatterns.some(pattern => file.startsWith(pattern));

if (!shouldKeep) {
totalSizeSaved += stats.size;
fs.unlinkSync(filePath);
console.log(`Removed: ${file} (${(stats.size / 1024).toFixed(2)} KB)`);
deletedCount++;
} else {
console.log(`Kept: ${file}`);
keptCount++;
}
}
// Non-JS files (CSS, fonts, etc) are always kept
});

console.log('\n=== Monaco Language Cleanup Complete ===');
console.log(`Files removed: ${deletedCount}`);
console.log(`Files kept: ${keptCount}`);
console.log(`Total size saved: ${(totalSizeSaved / 1024 / 1024).toFixed(2)} MB`); No newline at end of file
Copy link

Copilot AI Aug 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using synchronous file operations in a loop can be inefficient and block the event loop. Consider using fs.promises.unlink() with Promise.all() for better performance.

Suggested change
files.forEach(file => {
const filePath = path.join(distAssetsDir, file);
const stats = fs.statSync(filePath);
if (!stats.isFile()) {
return;
}
// For JS files, check if we should keep them
if (file.endsWith('.js')) {
// Check if it matches any of our keep patterns
const shouldKeep = keepPatterns.some(pattern => file.startsWith(pattern));
if (!shouldKeep) {
totalSizeSaved += stats.size;
fs.unlinkSync(filePath);
console.log(`Removed: ${file} (${(stats.size / 1024).toFixed(2)} KB)`);
deletedCount++;
} else {
console.log(`Kept: ${file}`);
keptCount++;
}
}
// Non-JS files (CSS, fonts, etc) are always kept
});
console.log('\n=== Monaco Language Cleanup Complete ===');
console.log(`Files removed: ${deletedCount}`);
console.log(`Files kept: ${keptCount}`);
console.log(`Total size saved: ${(totalSizeSaved / 1024 / 1024).toFixed(2)} MB`);
async function main() {
const unlinkPromises = [];
for (const file of files) {
const filePath = path.join(distAssetsDir, file);
const stats = fs.statSync(filePath);
if (!stats.isFile()) {
continue;
}
// For JS files, check if we should keep them
if (file.endsWith('.js')) {
// Check if it matches any of our keep patterns
const shouldKeep = keepPatterns.some(pattern => file.startsWith(pattern));
if (!shouldKeep) {
totalSizeSaved += stats.size;
// Use async unlink
unlinkPromises.push(
fs.promises.unlink(filePath).then(() => {
console.log(`Removed: ${file} (${(stats.size / 1024).toFixed(2)} KB)`);
deletedCount++;
})
);
} else {
console.log(`Kept: ${file}`);
keptCount++;
}
}
// Non-JS files (CSS, fonts, etc) are always kept
}
await Promise.all(unlinkPromises);
console.log('\n=== Monaco Language Cleanup Complete ===');
console.log(`Files removed: ${deletedCount}`);
console.log(`Files kept: ${keptCount}`);
console.log(`Total size saved: ${(totalSizeSaved / 1024 / 1024).toFixed(2)} MB`);
}
main().catch(err => {
console.error('Error during Monaco cleanup:', err);
process.exit(1);
});

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments