Skip to main content

sherlock_io/patterns/
nodejs.rs

1use regex::Regex;
2
3pub struct NodejsPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl NodejsPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // Package dependencies
13            Regex::new(r"node_modules").unwrap(),
14            
15            // Lock files
16            Regex::new(r"package-lock\.json").unwrap(),
17            Regex::new(r"yarn\.lock").unwrap(),
18            Regex::new(r"pnpm-lock\.yaml").unwrap(),
19            Regex::new(r"bun\.lockb").unwrap(),
20            
21            // Package manager directories
22            Regex::new(r"\.npm/").unwrap(),
23            Regex::new(r"\.yarn/").unwrap(),
24            Regex::new(r"\.pnpm-store/").unwrap(),
25            Regex::new(r"\.bun/").unwrap(),
26            
27            // Build outputs
28            Regex::new(r"dist/").unwrap(),
29            Regex::new(r"build/").unwrap(),
30            Regex::new(r"out/").unwrap(),
31            Regex::new(r"lib/").unwrap(),
32            Regex::new(r"esm/").unwrap(),
33            Regex::new(r"cjs/").unwrap(),
34            Regex::new(r"umd/").unwrap(),
35            
36            // Framework specific outputs
37            Regex::new(r"\.next/").unwrap(),
38            Regex::new(r"\.nuxt/").unwrap(),
39            Regex::new(r"\.output/").unwrap(),
40            Regex::new(r"\.svelte-kit/").unwrap(),
41            Regex::new(r"\.astro/").unwrap(),
42            Regex::new(r"\.remix/").unwrap(),
43            
44            // Deployment directories
45            Regex::new(r"\.vercel/").unwrap(),
46            Regex::new(r"\.netlify/").unwrap(),
47            Regex::new(r"\.firebase/").unwrap(),
48            
49            // Generated files
50            Regex::new(r"\.d\.ts\.map$").unwrap(),
51            Regex::new(r"\.js\.map$").unwrap(),
52            Regex::new(r"\.min\.js$").unwrap(),
53            Regex::new(r"\.min\.css$").unwrap(),
54            
55            // Compiled TypeScript
56            Regex::new(r"\.tsbuildinfo").unwrap(),
57            
58            // Electron
59            Regex::new(r"app\.asar").unwrap(),
60            Regex::new(r"electron-builder\.env").unwrap(),
61        ];
62
63        let cache_patterns = vec![
64            // Package manager caches
65            Regex::new(r"\.npm").unwrap(),
66            Regex::new(r"\.yarn").unwrap(),
67            Regex::new(r"\.pnpm").unwrap(),
68            Regex::new(r"\.bun").unwrap(),
69            Regex::new(r"node_modules/\.cache").unwrap(),
70            
71            // Build tool caches
72            Regex::new(r"\.next/").unwrap(),
73            Regex::new(r"\.nuxt/").unwrap(),
74            Regex::new(r"\.vite/").unwrap(),
75            Regex::new(r"\.turbo/").unwrap(),
76            Regex::new(r"\.webpack/").unwrap(),
77            Regex::new(r"\.rollup\.cache/").unwrap(),
78            Regex::new(r"\.parcel-cache/").unwrap(),
79            Regex::new(r"\.swc/").unwrap(),
80            Regex::new(r"\.esbuild/").unwrap(),
81            
82            // TypeScript caches
83            Regex::new(r"\.tscache/").unwrap(),
84            Regex::new(r"tsconfig\.tsbuildinfo").unwrap(),
85            
86            // Testing caches
87            Regex::new(r"\.jest/").unwrap(),
88            Regex::new(r"\.vitest/").unwrap(),
89            Regex::new(r"\.playwright/").unwrap(),
90            Regex::new(r"\.cypress/").unwrap(),
91            Regex::new(r"coverage/").unwrap(),
92            Regex::new(r"\.nyc_output/").unwrap(),
93            
94            // Linting and formatting caches
95            Regex::new(r"\.eslintcache").unwrap(),
96            Regex::new(r"\.prettiercache").unwrap(),
97            Regex::new(r"\.stylelintcache").unwrap(),
98            
99            // Framework specific caches
100            Regex::new(r"\.angular/").unwrap(),
101            Regex::new(r"\.ember-cli/").unwrap(),
102            Regex::new(r"\.storybook-cache/").unwrap(),
103            
104            // Development server caches
105            Regex::new(r"\.cache/").unwrap(),
106            Regex::new(r"\.tmp/").unwrap(),
107            Regex::new(r"tmp/").unwrap(),
108            
109            // Serverless caches
110            Regex::new(r"\.serverless/").unwrap(),
111            Regex::new(r"\.serverless_nextjs/").unwrap(),
112            
113            // Electron caches
114            Regex::new(r"\.electron/").unwrap(),
115            Regex::new(r"electron-builder-cache/").unwrap(),
116        ];
117
118        let extensions = vec![
119            // JavaScript variants
120            "js".to_string(), "mjs".to_string(), "cjs".to_string(),
121            
122            // TypeScript
123            "ts".to_string(), "tsx".to_string(), "d.ts".to_string(),
124            
125            // React
126            "jsx".to_string(),
127            
128            // Configuration and data
129            "json".to_string(), "json5".to_string(),
130            
131            // Modern JavaScript
132            "es6".to_string(), "es".to_string(),
133            
134            // Node.js specific
135            "node".to_string(),
136            
137            // Coffee Script (legacy but still used)
138            "coffee".to_string(),
139            
140            // LiveScript
141            "ls".to_string(),
142        ];
143
144        Self {
145            external_patterns,
146            cache_patterns,
147            extensions,
148        }
149    }
150
151    pub fn get_external_patterns(&self) -> &[Regex] {
152        &self.external_patterns
153    }
154
155    pub fn get_cache_patterns(&self) -> &[Regex] {
156        &self.cache_patterns
157    }
158
159    pub fn get_extensions(&self) -> &[String] {
160        &self.extensions
161    }
162
163    pub fn get_script_names() -> Vec<&'static str> {
164        vec![
165            // Package management
166            "package.json", "package-lock.json", "yarn.lock", "pnpm-lock.yaml",
167            "bun.lockb", "npm-shrinkwrap.json", ".nvmrc", ".node-version",
168            
169            // TypeScript configuration
170            "tsconfig.json", "tsconfig.build.json", "tsconfig.base.json",
171            "tsconfig.*.json", "jsconfig.json",
172            
173            // Build tools and bundlers
174            "webpack.config.js", "webpack.config.ts", "webpack.config.mjs",
175            "webpack.dev.js", "webpack.prod.js", "webpack.common.js",
176            "rollup.config.js", "rollup.config.ts", "rollup.config.mjs",
177            "vite.config.js", "vite.config.ts", "vite.config.mjs",
178            "esbuild.config.js", "esbuild.config.mjs",
179            "parcel.config.js", "parcel.config.json",
180            "turbo.json", "nx.json", "lerna.json",
181            
182            // Framework configurations
183            "next.config.js", "next.config.mjs", "next.config.ts",
184            "nuxt.config.js", "nuxt.config.ts",
185            "gatsby.config.js", "gatsby.config.ts", "gatsby-node.js",
186            "svelte.config.js", "svelte.config.ts",
187            "astro.config.js", "astro.config.ts", "astro.config.mjs",
188            "remix.config.js", "remix.config.ts",
189            "angular.json", ".angular-cli.json", "ng-package.json",
190            "ember-cli-build.js", ".ember-cli",
191            "vue.config.js", "vue.config.ts",
192            
193            // Testing frameworks
194            "jest.config.js", "jest.config.ts", "jest.config.mjs", "jest.config.json",
195            "vitest.config.js", "vitest.config.ts", "vitest.config.mjs",
196            "playwright.config.js", "playwright.config.ts",
197            "cypress.config.js", "cypress.config.ts", "cypress.json",
198            "karma.conf.js", "karma.conf.ts",
199            "mocha.opts", ".mocharc.json", ".mocharc.js",
200            "ava.config.js", "ava.config.mjs",
201            
202            // Linting and formatting
203            ".eslintrc", ".eslintrc.js", ".eslintrc.json", ".eslintrc.yaml",
204            ".prettierrc", ".prettierrc.js", ".prettierrc.json",
205            ".stylelintrc", ".stylelintrc.js", ".stylelintrc.json",
206            ".editorconfig", ".gitignore", ".gitattributes",
207            
208            // Babel
209            ".babelrc", ".babelrc.js", ".babelrc.json", "babel.config.js",
210            "babel.config.json", "babel.config.mjs",
211            
212            // PostCSS and CSS tools
213            "postcss.config.js", "postcss.config.mjs", "postcss.config.json",
214            "tailwind.config.js", "tailwind.config.ts", "tailwind.config.mjs",
215            "unocss.config.js", "unocss.config.ts",
216            
217            // Storybook
218            ".storybook/main.js", ".storybook/main.ts",
219            "storybook.config.js", "storybook.config.ts",
220            
221            // Serverless
222            "serverless.yml", "serverless.yaml", "serverless.js",
223            "serverless.ts", "now.json", "vercel.json",
224            
225            // Docker
226            "Dockerfile", "docker-compose.yml", "docker-compose.yaml",
227            ".dockerignore",
228            
229            // CI/CD
230            ".github/workflows/node.js.yml", ".github/workflows/ci.yml",
231            ".gitlab-ci.yml", "azure-pipelines.yml", "Jenkinsfile",
232            "bitbucket-pipelines.yml", "circle.yml", ".circleci/config.yml",
233            
234            // Deployment
235            "Procfile", "app.json", "app.yaml", "netlify.toml",
236            "_redirects", "_headers", "firebase.json", ".firebaserc",
237            
238            // Electron
239            "electron.js", "main.js", "preload.js", "renderer.js",
240            "forge.config.js", "electron-builder.json",
241            
242            // Monorepo tools
243            "rush.json", "pnpm-workspace.yaml", "workspace.json",
244            
245            // Environment and configuration
246            ".env", ".env.local", ".env.development", ".env.production",
247            ".env.test", ".env.example", "nodemon.json",
248            
249            // Documentation
250            "README.md", "CHANGELOG.md", "CONTRIBUTING.md",
251            "API.md", "docs/", "jsdoc.json",
252            
253            // License and legal
254            "LICENSE", "LICENSE.md", "COPYING", "COPYRIGHT",
255            
256            // Performance and monitoring
257            "lighthouse.config.js", "web-vitals.js",
258            
259            // GraphQL
260            "schema.graphql", "codegen.yml", "graphql.config.js",
261            
262            // Web standards
263            "manifest.json", "sw.js", "service-worker.js",
264            "workbox-config.js", "robots.txt", "sitemap.xml",
265        ]
266    }
267}