Skip to content

Commit 24c18c8

Browse files
committed
chore: remove dead #* path aliases and redundant /index exports
The #constants/#env/#lib/#packages/#types/#utils aliases were defined in tsconfig.external-aliases.json and wired through esbuild, vitest, and a dedicated fix script — but zero src/ files actually used them. Dead plumbing that added indirection without saving keystrokes. Also drop duplicate `./themes/index` and `./links/index` exports (identical targets to `./themes` and `./links`). Update the generator to stop emitting `dir/index` subpaths for index files.
1 parent c0c9489 commit 24c18c8

File tree

8 files changed

+20
-267
lines changed

8 files changed

+20
-267
lines changed

.config/esbuild.config.mts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -198,55 +198,6 @@ function createPathShorteningPlugin() {
198198
}
199199
}
200200

201-
/**
202-
* Plugin to resolve internal path aliases (#lib/*, #constants/*, etc.) to relative paths
203-
*/
204-
function createPathAliasPlugin() {
205-
return {
206-
name: 'internal-path-aliases',
207-
setup(build) {
208-
// Map of path aliases to their actual directories
209-
const pathAliases = {
210-
'#lib/': srcPath,
211-
'#constants/': path.join(srcPath, 'constants'),
212-
'#env/': path.join(srcPath, 'env'),
213-
'#packages/': path.join(srcPath, 'packages'),
214-
'#utils/': path.join(srcPath, 'utils'),
215-
'#types': path.join(srcPath, 'types'),
216-
}
217-
218-
// Intercept imports for path aliases
219-
for (const [alias, basePath] of Object.entries(pathAliases)) {
220-
const isExact = !alias.endsWith('/')
221-
const filter = isExact
222-
? new RegExp(`^${alias.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}$`)
223-
: new RegExp(`^${alias.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`)
224-
225-
build.onResolve({ filter }, args => {
226-
// Calculate the subpath after the alias
227-
const subpath = isExact ? '' : args.path.slice(alias.length)
228-
const targetPath = subpath ? path.join(basePath, subpath) : basePath
229-
230-
// Calculate relative path from the importing file to the target
231-
const importer = args.importer || srcPath
232-
const importerDir = path.dirname(importer)
233-
let relativePath = path.relative(importerDir, targetPath)
234-
235-
// Ensure relative paths start with ./ or ../
236-
if (!relativePath.startsWith('.')) {
237-
relativePath = `./${relativePath}`
238-
}
239-
240-
// Normalize to forward slashes for consistency
241-
relativePath = relativePath.replace(/\\/g, '/')
242-
243-
return { path: relativePath, external: true }
244-
})
245-
}
246-
},
247-
}
248-
}
249-
250201
// Build configuration for CommonJS output
251202
export const buildConfig = {
252203
entryPoints,
@@ -266,10 +217,8 @@ export const buildConfig = {
266217
metafile: true,
267218
logLevel: 'info',
268219

269-
// Use plugins for path shortening and aliases
270-
plugins: [createPathShorteningPlugin(), createPathAliasPlugin()].filter(
271-
Boolean,
272-
),
220+
// Use plugins for path shortening
221+
plugins: [createPathShorteningPlugin()].filter(Boolean),
273222

274223
// Note: Cannot use "external" with bundle: false.
275224
// esbuild automatically treats all imports as external when not bundling.

.config/tsconfig.external-aliases.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
"compilerOptions": {
44
"declarationMap": false,
55
"paths": {
6-
"#constants/*": ["../src/constants/*"],
7-
"#env/*": ["../src/env/*"],
8-
"#lib/*": ["../src/*"],
9-
"#packages/*": ["../src/packages/*"],
10-
"#types": ["../src/types"],
11-
"#utils/*": ["../src/utils/*"],
126
"cacache": ["../src/external/cacache"],
137
"make-fetch-happen": ["../src/external/make-fetch-happen"],
148
"fast-sort": ["../src/external/fast-sort"],

.config/vitest.config.isolated.mts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ const vitestConfigIsolated = defineConfig({
1919
preserveSymlinks: false,
2020
extensions: ['.mts', '.ts', '.mjs', '.js', '.json'],
2121
alias: {
22-
'#env/ci': path.resolve(projectRoot, 'src/env/ci.ts'),
23-
'#env': path.resolve(projectRoot, 'src/env'),
24-
'#constants': path.resolve(projectRoot, 'src/constants'),
25-
'#lib': path.resolve(projectRoot, 'src/lib'),
26-
'#packages': path.resolve(projectRoot, 'src/lib/packages'),
27-
'#types': path.resolve(projectRoot, 'src/types.ts'),
28-
'#utils': path.resolve(projectRoot, 'src/utils'),
2922
cacache: path.resolve(projectRoot, 'src/external/cacache'),
3023
'make-fetch-happen': path.resolve(
3124
projectRoot,

CLAUDE.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ Color the icon only, not the message. Use `yoctocolors-cjs` (not the ESM `yoctoc
143143

144144
Core infrastructure library for Socket.dev security tools.
145145

146-
**Path aliases** (from `.config/tsconfig.external-aliases.json`): `#constants/*`, `#env/*`, `#lib/*`, `#packages/*`, `#types`, `#utils/*` — all map to `src/` subdirectories. Always use aliases for internal imports (never relative paths).
146+
**Internal imports**: Use relative paths (e.g., `'../constants/packages'`). Path aliases are intentionally avoided — they add indirection without saving keystrokes and mask structural coupling.
147+
148+
**Vendored externals**: `cacache`, `make-fetch-happen`, `fast-sort`, `pacote`, `adm-zip`, `tar-fs`, `picomatch` are vendored in `src/external/` and remapped via `tsconfig.json` `paths`. Always import these by their bare package name; the tsconfig resolves them to the vendored copy.
147149

148150
### Commands
149151

@@ -199,7 +201,7 @@ Core infrastructure library for Socket.dev security tools.
199201
1. Node.js built-ins (with `node:` prefix)
200202
2. External dependencies
201203
3. `@socketsecurity/*` packages
202-
4. Internal path aliases (`#constants/*`, `#env/*`, `#lib/*`, etc.)
204+
4. Internal relative paths (`../constants/*`, `../env/*`, etc.)
203205
5. Type imports (separate)
204206

205207
Blank lines between groups, alphabetical within groups.
@@ -237,7 +239,7 @@ Custom optimized pipeline in `.github/workflows/ci.yml`: separate lint job (runs
237239

238240
### Environment Variables
239241

240-
Access via typed getter functions in `src/env/`. Each module exports a pure getter. Test rewiring via `#env/rewire` (`setEnv`, `clearEnv`, `resetEnv`) without modifying `process.env`.
242+
Access via typed getter functions in `src/env/`. Each module exports a pure getter. Test rewiring via `src/env/rewire.ts` (`setEnv`, `clearEnv`, `resetEnv`) without modifying `process.env`.
241243

242244
### Working Directory
243245

package.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,6 @@
415415
"types": "./dist/links/index.d.ts",
416416
"default": "./dist/links/index.js"
417417
},
418-
"./links/index": {
419-
"types": "./dist/links/index.d.ts",
420-
"default": "./dist/links/index.js"
421-
},
422418
"./logger": {
423419
"types": "./dist/logger.d.ts",
424420
"default": "./dist/logger.js"
@@ -631,10 +627,6 @@
631627
"types": "./dist/themes/context.d.ts",
632628
"default": "./dist/themes/context.js"
633629
},
634-
"./themes/index": {
635-
"types": "./dist/themes/index.d.ts",
636-
"default": "./dist/themes/index.js"
637-
},
638630
"./themes/themes": {
639631
"types": "./dist/themes/themes.d.ts",
640632
"default": "./dist/themes/themes.js"

scripts/fix/generate-package-exports.mts

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -102,31 +102,26 @@ async function main(): Promise<void> {
102102
if (ext === EXT_JSON) {
103103
jsonExports[`./${exportPath}`] = filePath
104104
} else {
105-
const extLessExportPath = `./${exportPath.slice(0, -ext.length)}`
106105
const isDts = ext === EXT_DTS
107-
if (o[extLessExportPath]) {
108-
o[extLessExportPath][isDts ? 'types' : 'default'] = filePath
106+
const basename = path.basename(exportPath, ext)
107+
// For index files, expose only the directory path (e.g., './themes'),
108+
// not the redundant './themes/index' form.
109+
let publicPath: string
110+
if (basename === 'index') {
111+
const dirname = path.dirname(exportPath)
112+
publicPath = dirname === '.' ? '.' : `./${dirname}`
113+
} else {
114+
publicPath = `./${exportPath.slice(0, -ext.length)}`
115+
}
116+
if (o[publicPath]) {
117+
o[publicPath][isDts ? 'types' : 'default'] = filePath
109118
} else {
110-
o[extLessExportPath] = {
119+
o[publicPath] = {
111120
// Order is significant. Default should be specified last.
112121
types: isDts ? filePath : undefined,
113122
default: isDts ? undefined : filePath,
114123
}
115124
}
116-
const basename = path.basename(exportPath, ext)
117-
if (basename === 'index') {
118-
const dirname = path.dirname(exportPath)
119-
const dirPath = dirname === '.' ? dirname : `./${dirname}`
120-
if (o[dirPath]) {
121-
o[dirPath][isDts ? 'types' : 'default'] = filePath
122-
} else {
123-
o[dirPath] = {
124-
// Order is significant. Default should be specified last.
125-
types: isDts ? filePath : undefined,
126-
default: isDts ? undefined : filePath,
127-
}
128-
}
129-
}
130125
}
131126
return o
132127
}, {})

scripts/fix/main.mts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ async function main(): Promise<void> {
3636
args: ['scripts/fix/generate-package-exports.mts', ...fixArgs],
3737
command: 'node',
3838
},
39-
{
40-
args: ['scripts/fix/path-aliases.mts', ...fixArgs],
41-
command: 'node',
42-
},
4339
{
4440
args: ['scripts/fix/external-imports.mts', ...fixArgs],
4541
command: 'node',

scripts/fix/path-aliases.mts

Lines changed: 0 additions & 168 deletions
This file was deleted.

0 commit comments

Comments
 (0)