Skip to content

Commit 75010ca

Browse files
committed
Merge branch 'main' of github.com:SocketDev/socket-cli into martin/rea-228-the-reachability-analysis-ignores-targets
2 parents 1fd87c4 + 4a84072 commit 75010ca

File tree

646 files changed

+48892
-14007
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

646 files changed

+48892
-14007
lines changed

.config/README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Shared Configuration
2+
3+
This directory contains shared configuration files for the socket-cli monorepo. All packages should extend these base configurations to ensure consistency and reduce duplication.
4+
5+
## Files
6+
7+
### TypeScript Configurations
8+
9+
- **`tsconfig.base.json`** - Base TypeScript configuration with strict type checking
10+
- ES2024 target
11+
- Strict mode with exactOptionalPropertyTypes
12+
- noUncheckedIndexedAccess for safer array/object access
13+
- Designed for @typescript/native-preview compatibility
14+
15+
- **`tsconfig.build.json`** - Extends base config for build outputs
16+
- Enables declaration generation
17+
- Enables composite/incremental builds
18+
- Use for packages that need to emit .d.ts files
19+
20+
- **`tsconfig.test.json`** - Extends base config for test files
21+
- Relaxes noUnusedLocals/noUnusedParameters for test code
22+
- Use in test-specific tsconfig files
23+
24+
### Vitest Configuration
25+
26+
- **`vitest.config.base.mts`** - Base Vitest test configuration
27+
- Node environment
28+
- Thread pool with optimal settings
29+
- Coverage configuration with v8 provider
30+
- isolate: false for performance (see comments for rationale)
31+
- Packages should extend and merge with this config
32+
33+
### ESLint Configuration
34+
35+
- **`eslint.config.mjs`** - Flat config ESLint setup
36+
- TypeScript support with @typescript-eslint
37+
- Import ordering with eslint-plugin-import-x
38+
- Node.js plugin rules
39+
- Biome and .gitignore pattern integration
40+
- Sort destructured keys enforcement
41+
42+
### Build Utilities
43+
44+
- **`esbuild-inject-import-meta.mjs`** - Polyfill for import.meta.url in CommonJS
45+
- Used with esbuild's inject option
46+
- Converts __filename to file:// URL format
47+
48+
## Usage
49+
50+
### TypeScript - Package Config
51+
52+
Packages should extend the base config and specify their own include/exclude:
53+
54+
```json
55+
{
56+
"extends": "../../.config/tsconfig.base.json",
57+
"include": ["src/**/*.mts", "src/**/*.d.ts"],
58+
"exclude": [
59+
"src/**/*.test.mts",
60+
"dist/**",
61+
"node_modules/**"
62+
]
63+
}
64+
```
65+
66+
### TypeScript - Type Checking Config
67+
68+
For type checking with custom paths (like packages/cli):
69+
70+
```json
71+
{
72+
"extends": "./tsconfig.base.json",
73+
"compilerOptions": {
74+
"paths": {
75+
"@socketsecurity/lib": ["../../socket-lib/dist/index.d.ts"]
76+
}
77+
},
78+
"include": ["../src/**/*.mts"],
79+
"exclude": ["../src/**/*.test.mts"]
80+
}
81+
```
82+
83+
### Vitest - Package Config
84+
85+
Packages should merge the base config with their specific settings:
86+
87+
```typescript
88+
import { defineConfig, mergeConfig } from 'vitest/config'
89+
import baseConfig from '../../.config/vitest.config.base.mts'
90+
91+
export default mergeConfig(
92+
baseConfig,
93+
defineConfig({
94+
test: {
95+
include: [
96+
'test/**/*.test.{mts,ts}',
97+
'src/**/*.test.{mts,ts}',
98+
],
99+
setupFiles: ['./test/setup.mts'],
100+
// Override coverage thresholds if needed
101+
coverage: {
102+
thresholds: {
103+
lines: 80,
104+
functions: 80,
105+
branches: 80,
106+
statements: 80,
107+
},
108+
},
109+
},
110+
})
111+
)
112+
```
113+
114+
### Vitest - Simple Package Config
115+
116+
For packages with minimal test config needs:
117+
118+
```typescript
119+
import { defineConfig, mergeConfig } from 'vitest/config'
120+
import baseConfig from '../../.config/vitest.config.base.mts'
121+
122+
export default mergeConfig(
123+
baseConfig,
124+
defineConfig({
125+
test: {
126+
testTimeout: 120000, // Override for long-running tests
127+
},
128+
})
129+
)
130+
```
131+
132+
### ESLint
133+
134+
The root ESLint config is already set up to work across the entire monorepo. No per-package ESLint configs are needed unless you have package-specific rules.
135+
136+
### esbuild
137+
138+
Use the import.meta polyfill in esbuild configs:
139+
140+
```javascript
141+
import path from 'node:path'
142+
import { fileURLToPath } from 'node:url'
143+
144+
const __dirname = path.dirname(fileURLToPath(import.meta.url))
145+
146+
export default {
147+
// ... other config
148+
inject: [path.join(__dirname, '../../.config/esbuild-inject-import-meta.mjs')],
149+
}
150+
```
151+
152+
## Benefits
153+
154+
1. **Single source of truth** - All shared settings in one place
155+
2. **Consistency** - All packages use the same base configuration
156+
3. **Easy maintenance** - Update once, applies everywhere
157+
4. **Reduced duplication** - Packages only specify what's unique
158+
5. **Better defaults** - Proven settings with documented rationale
159+
160+
## Migration
161+
162+
To migrate a package to use shared configs:
163+
164+
1. Update tsconfig.json to extend from `../../.config/tsconfig.base.json`
165+
2. Update vitest.config.mts to merge with `../../.config/vitest.config.base.mts`
166+
3. Remove duplicate configuration options
167+
4. Keep only package-specific overrides
168+
5. Test that builds and tests still work
169+
170+
See the documentation in docs/ for detailed migration guides.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Polyfill for import.meta.url in CommonJS bundles.
3+
* This file is injected by esbuild's inject option.
4+
*/
5+
6+
// Convert __filename to file:// URL format.
7+
export const __importMetaUrl =
8+
typeof __filename !== 'undefined'
9+
? `file://${__filename.replace(/\\/g, '/')}`
10+
: 'file:///unknown'

0 commit comments

Comments
 (0)