-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathignore.js
145 lines (126 loc) · 2.97 KB
/
ignore.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const fs = require('fs');
const path = require('path');
const skipContentFiles = [
// Config and lock files
'package-lock.json',
'yarn.lock',
'.prettierrc',
'.eslintrc',
'.eslintrc.js',
'.eslintrc.json',
'.babelrc',
'.babelrc.js',
'.babelrc.json',
'tsconfig.json',
'webpack.config.js',
'jest.config.js',
'.env',
'.env.local',
'.env.development',
'.env.production',
'.env.test',
'composer.lock'
];
const skipTraversalFolders = [
// Common folders
'node_modules',
'vendor',
'.git',
'.idea',
'.vscode',
'.vs',
'dist',
'build',
'coverage',
// Symfony specific folders
'var/cache',
'var/log',
'var/sessions',
'var/tmp',
'public/bundles',
// Laravel specific folders
'storage/app',
'storage/framework/cache',
'storage/framework/sessions',
'storage/framework/testing',
'storage/framework/views',
'storage/logs',
'bootstrap/cache',
'public/storage',
// JavaScript framework folders
'.next',
'.nuxt',
'out',
'.svelte-kit',
'.angular',
// Build and cache directories
'.cache',
'.parcel-cache',
'.webpack',
'.turbo',
'.vite',
'temp',
'tmp',
'cache',
'.phpunit.cache',
'.php-cs-fixer.cache',
// Test folders
'.nyc_output',
'cypress/videos',
'cypress/screenshots',
'.cypress-cache',
// Dependencies and builds
'public/build',
'public/hot',
'public/css',
'public/js',
'public/mix-manifest.json'
];
const skipContentExtensions = [
// Images
'jpg', 'jpeg', 'png', 'gif', 'bmp', 'tiff', 'webp', 'svg', 'ico', 'psd', 'ai', 'eps', 'raw', 'xcf',
// Known binary extensions
'exe', 'dll', 'so', 'dylib', 'bin', 'obj',
'db', 'sqlite', 'sqlite3', 'mdb',
'zip', 'tar', 'gz', '7z', 'rar',
'pdf', 'doc', 'docx', 'xls', 'xlsx',
'ttf', 'otf', 'woff', 'woff2'
];
function isBinaryFile(filePath) {
try {
const buffer = Buffer.alloc(512);
const fd = fs.openSync(filePath, 'r');
const bytesRead = fs.readSync(fd, buffer, 0, 512, 0);
fs.closeSync(fd);
for (let i = 0; i < bytesRead; i++) {
if (buffer[i] === 0) return true;
}
return false;
} catch (error) {
console.error(`Error checking binary file ${filePath}:`, error.message);
return false;
}
}
function shouldSkipTraversal(filepath) {
const normalizedPath = filepath.replace(/\\/g, '/');
return skipTraversalFolders.some(pattern => {
const regexPattern = pattern.includes('/')
? pattern.replace(/\//g, '[/\\\\]')
: `(^|[/\\\\])${pattern}($|[/\\\\])`;
return new RegExp(regexPattern).test(normalizedPath);
});
}
function shouldSkipContent(filepath) {
const basename = path.basename(filepath);
const extension = path.extname(filepath).toLowerCase().replace('.', '');
return skipContentFiles.includes(basename) ||
skipContentExtensions.includes(extension) ||
isBinaryFile(filepath);
}
module.exports = {
shouldSkipTraversal,
shouldSkipContent,
skipContentFiles,
skipTraversalFolders,
skipContentExtensions
};