Skip to content

Commit 2359d33

Browse files
committed
refactor(config): implement optional external alias detection for TypeScript
The repository is now self-contained by default, with external repo aliases only used when detected. This matches the pattern already used by esbuild via get-local-package-aliases.mjs. Changes: - Created .config/tsconfig.check.json (self-contained, no external paths) - Created .config/tsconfig.external-aliases.json (extends check config with external paths) - Updated packages/cli/.config/tsconfig.check.json to remove external paths - Modified scripts/test.mjs to detect external repos and conditionally use external-aliases config The build automatically detects if ../socket-lib or ../socket-registry exist and uses the appropriate TypeScript configuration. This allows the repo to work standalone while supporting local cross-repo development when external repos are present.
1 parent dffc522 commit 2359d33

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

.config/tsconfig.check.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"typeRoots": ["../node_modules/@types"]
5+
},
6+
"include": [
7+
"../packages/cli/src/**/*.mts",
8+
"../packages/cli/*.config.mts",
9+
"../packages/cli/.config/*.mts"
10+
],
11+
"exclude": [
12+
"../packages/cli/**/*.tsx",
13+
"../packages/cli/**/*.d.mts",
14+
"../packages/cli/src/commands/analytics/output-analytics.mts",
15+
"../packages/cli/src/commands/audit-log/output-audit-log.mts",
16+
"../packages/cli/src/commands/threat-feed/output-threat-feed.mts",
17+
"../packages/cli/**/*.test.mts",
18+
"../packages/cli/src/test/**/*.mts",
19+
"../packages/cli/src/utils/test-mocks.mts",
20+
"../packages/cli/test/**/*.mts"
21+
]
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig.check.json",
3+
"compilerOptions": {
4+
"paths": {
5+
"@socketsecurity/lib": ["../socket-lib/dist/index.d.ts"],
6+
"@socketsecurity/lib/*": ["../socket-lib/dist/*"],
7+
"@socketsecurity/registry": [
8+
"../socket-registry/registry/dist/index.d.ts"
9+
],
10+
"@socketsecurity/registry/*": ["../socket-registry/registry/dist/*"]
11+
}
12+
}
13+
}

packages/cli/.config/tsconfig.check.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
22
"extends": "./tsconfig.base.json",
33
"compilerOptions": {
4-
"paths": {
5-
"@socketsecurity/lib": ["../../socket-lib/dist/index.d.ts"],
6-
"@socketsecurity/lib/*": ["../../socket-lib/dist/*"],
7-
"@socketsecurity/registry": [
8-
"../../socket-registry/registry/dist/index.d.ts"
9-
],
10-
"@socketsecurity/registry/*": ["../../socket-registry/registry/dist/*"]
11-
},
124
"typeRoots": ["../node_modules/@types"]
135
},
146
"include": ["../src/**/*.mts", "../*.config.mts", "./*.mts"],

scripts/test.mjs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,27 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
3737
const rootPath = path.resolve(__dirname, '..')
3838
const nodeModulesBinPath = path.join(rootPath, 'node_modules', '.bin')
3939

40+
/**
41+
* Detect if external repos exist for local development.
42+
* Matches the pattern used in get-local-package-aliases.mjs.
43+
*/
44+
function hasExternalRepos() {
45+
const libPath = path.join(rootPath, '..', 'socket-lib', 'package.json')
46+
const registryPath = path.join(rootPath, '..', 'socket-registry', 'registry', 'package.json')
47+
return existsSync(libPath) || existsSync(registryPath)
48+
}
49+
50+
/**
51+
* Get the appropriate TypeScript config based on external repo availability.
52+
* Uses external-aliases config when external repos are detected for development.
53+
*/
54+
function getTsConfigPath() {
55+
if (hasExternalRepos()) {
56+
return '.config/tsconfig.external-aliases.json'
57+
}
58+
return '.config/tsconfig.check.json'
59+
}
60+
4061
// Track running processes for cleanup
4162
const runningProcesses = new Set()
4263

@@ -167,10 +188,11 @@ async function runCheck() {
167188
logger.success('ESLint passed')
168189

169190
// Run TypeScript check
191+
const tsConfigPath = getTsConfigPath()
170192
spinner.start('Checking TypeScript...')
171193
exitCode = await runCommand(
172194
'tsgo',
173-
['--noEmit', '-p', '.config/tsconfig.check.json'],
195+
['--noEmit', '-p', tsConfigPath],
174196
{
175197
stdio: 'pipe',
176198
},
@@ -179,7 +201,7 @@ async function runCheck() {
179201
spinner.stop()
180202
logger.error('TypeScript check failed')
181203
// Re-run with output to show errors
182-
await runCommand('tsgo', ['--noEmit', '-p', '.config/tsconfig.check.json'])
204+
await runCommand('tsgo', ['--noEmit', '-p', tsConfigPath])
183205
return exitCode
184206
}
185207
spinner.stop()

0 commit comments

Comments
 (0)