refactor: Store default ignore patterns in a separate file#28
Open
maharajamihir wants to merge 1 commit intomainfrom
Open
refactor: Store default ignore patterns in a separate file#28maharajamihir wants to merge 1 commit intomainfrom
maharajamihir wants to merge 1 commit intomainfrom
Conversation
Refactors the way default .crowdcodeignore patterns are handled. Instead of a hardcoded array in extension.ts, the patterns are now stored in `src/defaults/crowdcodeignore.default`. Changes: - Added `src/defaults/crowdcodeignore.default` with the standard patterns. - Modified `extension.ts` to read from this file when creating a new `.crowdcode/.crowdcodeignore` in the user's workspace. It checks for the file in the packaged location (`out/defaults/`) first, then falls back to the source location (`src/defaults/`) for development. - Added `copy-webpack-plugin` to development dependencies. - Updated `webpack.config.js` to use `CopyWebpackPlugin` to ensure `crowdcodeignore.default` is copied to `out/defaults/` during packaging. - Commented out `.vscode/` from the default ignore list, allowing users to add it manually if their specific project's .vscode dir contains sensitive information. This makes the default patterns more maintainable and keeps `extension.ts` cleaner.
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the handling of default ignore patterns by moving them into a separate defaults file and updating related logic. Key changes include:
- Adding the default ignore patterns file and copying it in the webpack build process.
- Updating utilities and extension activation to load and watch the .crowdcodeignore file.
- Modifying recording logic to respect the ignore rules.
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| webpack.config.js | Added CopyWebpackPlugin configuration to copy the default ignore file. |
| src/utilities.ts | Renamed variables to avoid conflicts and added functions for ignore patterns. |
| src/recording.ts | Integrated ignore pattern checks into recording startup and tab event logic. |
| src/extension.ts | Added file watchers for .crowdcodeignore changes and created the file if missing. |
| src/defaults/crowdcodeignore.default | Introduced the new default ignore patterns file with updated content. |
| package.json | Added necessary dependencies (copy-webpack-plugin and picomatch). |
Comments suppressed due to low confidence (1)
src/extension.ts:97
- [nitpick] Consider supporting multiple workspace folders instead of only using the first one to improve multi-root workspace compatibility.
if (vscode.workspace.workspaceFolders) {
| return | ||
| } | ||
| // Check if the file should be ignored BEFORE attempting to read its content | ||
| if (isPathIgnored(editor.document.uri.fsPath)) { |
There was a problem hiding this comment.
[nitpick] The ignored file check is performed twice; consider consolidating this logic to avoid redundancy.
Suggested change
| if (isPathIgnored(editor.document.uri.fsPath)) { | |
| const isIgnored = isPathIgnored(editor.document.uri.fsPath) | |
| if (isIgnored) { |
Comment on lines
+154
to
+164
| if (fs.existsSync(defaultIgnoreSourcePath)) { | ||
| defaultPatternsContent = fs.readFileSync(defaultIgnoreSourcePath, 'utf-8'); | ||
| } else if (fs.existsSync(devDefaultIgnoreSourcePath)) { | ||
| logToOutput('Using dev default ignore path.', 'info'); | ||
| defaultPatternsContent = fs.readFileSync(devDefaultIgnoreSourcePath, 'utf-8'); | ||
| } else { | ||
| logToOutput('Default ignore patterns file not found at expected locations. Creating an empty .crowdcodeignore.', 'warn'); | ||
| // Create a minimal .crowdcodeignore if defaults are missing, so the file watcher still works. | ||
| defaultPatternsContent = '# Default patterns could not be loaded. Please add your ignore patterns here.\n'; | ||
| } | ||
| fs.writeFileSync(ignoreFilePath, defaultPatternsContent); |
There was a problem hiding this comment.
[nitpick] Consider using asynchronous file reading (fs.promises.readFile) instead of synchronous fs.readFileSync to avoid blocking during extension activation.
Suggested change
| if (fs.existsSync(defaultIgnoreSourcePath)) { | |
| defaultPatternsContent = fs.readFileSync(defaultIgnoreSourcePath, 'utf-8'); | |
| } else if (fs.existsSync(devDefaultIgnoreSourcePath)) { | |
| logToOutput('Using dev default ignore path.', 'info'); | |
| defaultPatternsContent = fs.readFileSync(devDefaultIgnoreSourcePath, 'utf-8'); | |
| } else { | |
| logToOutput('Default ignore patterns file not found at expected locations. Creating an empty .crowdcodeignore.', 'warn'); | |
| // Create a minimal .crowdcodeignore if defaults are missing, so the file watcher still works. | |
| defaultPatternsContent = '# Default patterns could not be loaded. Please add your ignore patterns here.\n'; | |
| } | |
| fs.writeFileSync(ignoreFilePath, defaultPatternsContent); | |
| if (await fs.promises.access(defaultIgnoreSourcePath).then(() => true).catch(() => false)) { | |
| defaultPatternsContent = await fs.promises.readFile(defaultIgnoreSourcePath, 'utf-8'); | |
| } else if (await fs.promises.access(devDefaultIgnoreSourcePath).then(() => true).catch(() => false)) { | |
| logToOutput('Using dev default ignore path.', 'info'); | |
| defaultPatternsContent = await fs.promises.readFile(devDefaultIgnoreSourcePath, 'utf-8'); | |
| } else { | |
| logToOutput('Default ignore patterns file not found at expected locations. Creating an empty .crowdcodeignore.', 'warn'); | |
| // Create a minimal .crowdcodeignore if defaults are missing, so the file watcher still works. | |
| defaultPatternsContent = '# Default patterns could not be loaded. Please add your ignore patterns here.\n'; | |
| } | |
| await fs.promises.writeFile(ignoreFilePath, defaultPatternsContent); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactors the way default .crowdcodeignore patterns are handled. Instead of a hardcoded array in extension.ts, the patterns are now stored in
src/defaults/crowdcodeignore.default.Changes:
src/defaults/crowdcodeignore.defaultwith the standard patterns.extension.tsto read from this file when creating a new.crowdcode/.crowdcodeignorein the user's workspace. It checks for the file in the packaged location (out/defaults/) first, then falls back to the source location (src/defaults/) for development.copy-webpack-pluginto development dependencies.webpack.config.jsto useCopyWebpackPluginto ensurecrowdcodeignore.defaultis copied toout/defaults/during packaging..vscode/from the default ignore list, allowing users to add it manually if their specific project's .vscode dir contains sensitive information.This makes the default patterns more maintainable and keeps
extension.tscleaner.