Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
fix: Adds node_modules to the .gitignore file (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
imrishabh18 authored Jun 26, 2024
1 parent 5264156 commit c0af27c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/util/get-all-package-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import ignore from "ignore"
export const getAllPackageFiles = async (
ctx: AppContext
): Promise<Array<string>> => {
await ensureNodeModulesIgnored();

const gitignore = await fs
.readFile("./.gitignore")
.then((b) => b.toString().split("\n").filter(Boolean))
Expand All @@ -33,3 +35,23 @@ export const getAllPackageFiles = async (

return Glob.globSync("**/*.{ts,tsx,md}", {}).filter((fp) => !ig.ignores(fp))
}

/**
* Ensure 'node_modules/' is in .gitignore
*/
const ensureNodeModulesIgnored = async () => {
const gitignorePath = './.gitignore';

try {
const gitignore = await fs.readFile(gitignorePath, 'utf8');
if (!gitignore.includes('node_modules/')) {
await fs.appendFile(gitignorePath, '\nnode_modules/\n');
}
} catch (err) {
if (err.code === 'ENOENT') {
await fs.writeFile(gitignorePath, 'node_modules/\n');
} else {
console.error('Error while updating .gitignore:', err);
}
}
}

0 comments on commit c0af27c

Please sign in to comment.