pathlra-aliaser 4.6.9 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/5ety ADDED
@@ -0,0 +1,343 @@
1
+
2
+
3
+
4
+ # Ultra-Fast, Zero-Dependency Path Alias Resolver for Node.js
5
+ `Developed by hub-mgv ❤️`
6
+
7
+
8
+
9
+ # pathlra-aliaser
10
+
11
+
12
+
13
+ Ultra-Fast, Zero-Dependency Path Alias Resolver for Node.js
14
+
15
+
16
+
17
+ Engineered for sub-millisecond resolution, extreme performance, and seamless integration with zero runtime overhead in production
18
+
19
+
20
+
21
+ ---
22
+
23
+
24
+
25
+ ## Why pathlra-aliaser?
26
+
27
+
28
+
29
+ Most alias tools are slow, bloated, or force you to manage paths in JavaScript files.
30
+
31
+
32
+
33
+ `pathlra-aliaser` is a high-performance module loader enhancer built for speed, stability, and minimal memory footprint It safely patches Node.js’s module resolution system, enabling clean, readable imports like:
34
+
35
+
36
+
37
+ ```js
38
+
39
+ const db = require("@services/database");
40
+
41
+ ```
42
+
43
+
44
+
45
+ without any build step, transpilation, or runtime penalty
46
+
47
+
48
+
49
+ ---
50
+
51
+
52
+
53
+ ## Key Features
54
+
55
+
56
+
57
+ - _Sub-millisecond_ resolution: Resolves aliases in <0.1ms even under heavy load.
58
+ - Adaptive strategy engine:
59
+ - Linear scan for ≤100 aliases
60
+ - Radix tree for ≥100 aliases
61
+ - Optimized LRU cache: Batch eviction (10% at a time) to avoid GC spikes.
62
+ - Package.json-first design: Aliases live only in package.json.
63
+ - Dynamic alias support: Programmatic runtime path generation.
64
+ - Custom module directories: Extend require() to search in non-standard folders.
65
+ - Zero dependencies: Pure Node.js, fully compatible with `"use strict"`.
66
+ - Minimal memory footprint: Optimized data structures and memory-aware algorithms.
67
+ - Hot-reload support (optional) for development.
68
+ - Verbose/debug mode for tracing resolution steps.
69
+ - TypeScript paths auto-generation.
70
+ - Friendly error messages & config validation.
71
+ - Default presets: `@root`, `@src` for plug-and-play.
72
+
73
+
74
+
75
+ ---
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+ ## How It Works
93
+
94
+
95
+
96
+ - Initialization: Scans `package.json` for keys starting with `path_aliaser`.
97
+ - Alias Registration: Loads all alias → target mappings.
98
+ - Strategy Selection:
99
+ - `<100 aliases → linear scan`
100
+ - `≥100 aliases → radix tree for O(k) prefix lookups`
101
+ - Module Patching: Overrides Node.js’s resolver functions.
102
+ - Caching: Uses high-efficiency LRU cache with batch eviction.
103
+ - Path Propagation: Custom module directories injected into all active module paths.
104
+
105
+
106
+
107
+ All happens once at startup with near-zero runtime cost.
108
+
109
+
110
+
111
+ ---
112
+ ## Feature & Performance Comparison: `pathlra-aliaser` vs Top Alternatives
113
+
114
+ | Feature / Capability | **`pathlra-aliaser`** ✅ | **`module-alias`** | **`tsconfig-paths`** | **`babel-plugin-module-resolver`** |
115
+ |----------------------|--------------------------|--------------------|------------------------|------------------------------------|
116
+ | **Pure Node.js (no build step)** | ✅ Yes | ✅ Yes | ⚠️ Only with `ts-node` | ❌ Requires Babel transpilation |
117
+ | **Zero Dependencies** | ✅ Yes | ✅ Yes | ❌ Needs TypeScript | ❌ Needs Babel + plugins |
118
+ | **Sub-millisecond Resolution** | ✅ **<0.1ms** (adaptive) | ❌ ~0.3–1ms (linear only) | ⚠️ Slower (TS overhead) | N/A (build-time only) |
119
+ | **Smart Resolution Strategy** | ✅ **Radix Tree (≥100 aliases)** + Linear (<100) | ❌ Linear scan only (`O(n)`) | ❌ Regex-based matching | N/A |
120
+ | **LRU Caching with Batch Eviction** | ✅ Yes (10k entries, 10% batch) | ❌ No cache | ⚠️ Limited caching | N/A |
121
+ | **Dynamic Aliases (Handler Functions)** | ✅ Yes + **type validation** | ✅ Yes (no validation) | ❌ No | ❌ No |
122
+ | **Hot-Reload Support** | ✅ Optional (dev-only) | ❌ No | ⚠️ Via `ts-node-dev` | ❌ No |
123
+ | **TypeScript Paths Auto-Gen** | ✅ Built-in `_internal.generateTSConfig()` | ❌ No | N/A (it *is* TS) | ❌ Manual sync needed |
124
+ | **Security: Path Traversal Protection** | ✅ Blocks `..`, `~`, `\0` | ❌ **Vulnerable** | ⚠️ Depends on config | N/A |
125
+ | **Memory Optimization** | ✅ **Minimal Mode** (<10 aliases → 1k cache) | ❌ Fixed overhead | ❌ High TS memory use | N/A |
126
+ | **Config via `package.json`** | ✅ Any key starting with `path_aliaser` | ✅ `_moduleAliases` only | ❌ `tsconfig.json` only | ❌ `.babelrc` / `babel.config.js` |
127
+ | **Custom Module Directories** | ✅ `_moduleDirectories` + `ap()` | ✅ `_moduleDirectories` | ❌ No | ❌ No |
128
+ | **Debug/Verbose Mode** | ✅ Full resolution tracing | ❌ No | ⚠️ Limited logs | ❌ No |
129
+ | **ESM Support** | ✅ Via patched resolver | ✅ Partial (Node ≥14.6+) | ✅ With `ts-node` | ✅ If Babel configured |
130
+ | **Works in Jest** | ⚠️ Same as `module-alias` (needs `moduleNameMapper`) | ⚠️ Requires Jest config | ✅ With `ts-jest` | ✅ If Babel used in Jest |
131
+ | **Production-Ready Performance** | ✅ **8.7x faster @ 1k aliases**, 60% less RAM | ❌ Degrades with scale | ❌ Not for pure JS projects | ❌ Build-only |
132
+ | **Default Presets** | ✅ `@root`, `@src` auto-applied | ❌ None | ❌ None | ❌ None |
133
+ | **Friendly Error Messages** | ✅ Clear, actionable errors | ⚠️ Generic errors | ⚠️ TS cryptic errors | ⚠️ Babel errors |
134
+
135
+
136
+
137
+
138
+ ## Installation
139
+
140
+
141
+
142
+ ```bash
143
+
144
+ npm install pathlra-aliaser
145
+
146
+ ```
147
+
148
+
149
+
150
+ ---
151
+
152
+
153
+
154
+ ## Configuration via `package.json`
155
+
156
+
157
+
158
+ ```json
159
+
160
+ {
161
+
162
+ "name": "name",
163
+ "version": "4",
164
+ "main": "index.js",
165
+ "dependencies": {
166
+ "pathlra-aliaser": "^3.6.7"
167
+
168
+ },
169
+ "path_aliaser": {
170
+ "@products": "./routes/products.js",
171
+ "@users": "./routes/users.js",
172
+ "@logger": "./utils/logger.js"
173
+ },
174
+ "_moduleDirectories": ["node_modules", "custom_libs"],
175
+ "scripts": {
176
+ "test": "echo "Error: no test specified" && exit 1"
177
+
178
+ },
179
+ "license": "ISC",
180
+ "description": "High-performance path alias resolver for Node.js with LRU caching and radix-tree optimization"
181
+
182
+ }
183
+
184
+ ```
185
+
186
+
187
+
188
+ _Paths are relative to the project root._
189
+
190
+ `_moduleDirectories` extends Node.js’s search paths safely.
191
+
192
+
193
+
194
+ ---
195
+
196
+
197
+
198
+ ## Example Usage
199
+
200
+
201
+
202
+ ```js
203
+
204
+ "use strict";
205
+ require("pathlra-aliaser")(); // Must be called BEFORE any aliased requires
206
+ const logger = require("@utils/logger");
207
+ const User = require("@models/User");
208
+
209
+ ```
210
+
211
+
212
+
213
+ ---
214
+
215
+
216
+
217
+ ## Advanced Features
218
+
219
+
220
+
221
+ **Dynamic Aliases:**
222
+
223
+
224
+
225
+ ```js
226
+
227
+ const aliaser = require("pathlra-aliaser");
228
+ aliaser.aa("@dynamic", () => "./runtime/path");
229
+
230
+ ```
231
+
232
+
233
+
234
+ **Add Custom Module Directory:**
235
+
236
+
237
+
238
+ ```js
239
+
240
+ aliaser.ap("./internal_modules");
241
+
242
+ ```
243
+
244
+
245
+
246
+ **Bulk Alias Registration:**
247
+
248
+
249
+
250
+ ```js
251
+
252
+ aliaser.addAliases({ "@core": "./src/core" });
253
+
254
+ ```
255
+
256
+
257
+
258
+ ---
259
+
260
+
261
+
262
+ ## Performance & Benchmarks
263
+
264
+
265
+
266
+ - Cache: 10,000 entries by default
267
+ - Eviction: 10% of least-used entries per batch
268
+ - Memory usage: <2 MB with 1,000+ aliases
269
+
270
+
271
+
272
+ **Benchmarks vs module-alias:**
273
+
274
+
275
+
276
+ - 3.2x faster (10 aliases)
277
+ - 8.7x faster (1,000 aliases)
278
+ - 60% lower memory usage under load
279
+
280
+
281
+
282
+ ---
283
+
284
+
285
+
286
+ ## Ideal For
287
+
288
+
289
+
290
+ - Large-scale Node.js applications
291
+ - Microservices
292
+ - Performance-critical systems
293
+ - Long-running processes
294
+ - Teams enforcing standardized path conventions
295
+
296
+
297
+
298
+ **Not for:** Frontend bundling, TypeScript-only projects (unless with ts-node), or projects preferring config files over package.json.
299
+
300
+
301
+
302
+ ---
303
+
304
+
305
+
306
+ ## Common Misconceptions
307
+
308
+
309
+
310
+ - “I need to call `aa()` for every alias.” → No, `package.json` is enough.
311
+ - “It modifies global behavior unsafely” → Only patches Node.js resolver safely.
312
+ - “It slows down my app.” → Benchmarks show faster resolution than manual paths after warm-up.
313
+
314
+
315
+
316
+ ---
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
+ ## License
337
+ MIT © hub-mgv
338
+ Engineered for speed. Built for scale. Designed to disappear.
339
+ `pathlra-aliaser`: where path resolution becomes invisible.
340
+
341
+
342
+
343
+ طيب وظبط لي دوت وكلل الماركت الماركت شويه يعني ما تظهرش دايما ان احنا افضل من الكل والكل مجرد ضعفه كده لا قلل شويه الماركه عشان مثلا ما يكونش تكبر او حاجه ارفعوا ملف README.md ارفعه لي في ملف zip مش موقع
package/README.md CHANGED
@@ -1,289 +1,208 @@
1
-
2
-
3
-
4
- # Developed by hub-mgv ❤️❤️❤️
5
-
6
-
7
-
8
1
  # pathlra-aliaser
9
2
 
10
-
11
-
12
- Ultra-Fast, Zero-Dependency Path Alias Resolver for Node.js
3
+ High-performance path alias resolver for Node.js, with a focus on speed, safety, and predictable behavior.
13
4
 
14
-
5
+ Designed to provide fast alias resolution in large codebases, using built-in caching and zero external dependencies.
15
6
 
16
- Engineered for sub-millisecond resolution, extreme performance, and seamless integration with zero runtime overhead in production
17
-
18
-
7
+ Works with CommonJS out of the box and requires no code changes beyond a simple initialization call.
19
8
 
20
9
  ---
21
10
 
22
-
23
-
24
11
  ## Why pathlra-aliaser?
25
12
 
26
-
27
-
28
- Most alias tools are slow, bloated, or force you to manage paths in JavaScript files.
29
-
30
-
13
+ `pathlra-aliaser` is a path alias resolver and module loader enhancement for Node.js.
31
14
 
32
- `pathlra-aliaser` is a high-performance module loader enhancer built for speed, stability, and minimal memory footprint It safely patches Node.js’s module resolution system, enabling clean, readable imports like:
15
+ It is designed to balance performance, correctness, and simplicity. Instead of introducing additional configuration files,
16
+ build steps, or runtime layers, it integrates directly with Node.js’s module resolution mechanism while preserving its
17
+ expected behavior.
33
18
 
34
-
19
+ Internally, the resolver applies adaptive lookup strategies and caching to keep alias resolution efficient as projects
20
+ grow. This makes it suitable for larger codebases that want cleaner and more readable import paths, without relying on
21
+ deep relative paths or additional runtime dependencies.
35
22
 
36
23
  ```js
37
-
38
- const db = require("@services/database");
39
-
24
+ const db = require("@services/database");
40
25
  ```
41
26
 
42
-
43
-
44
- without any build step, transpilation, or runtime penalty
45
-
46
-
27
+ No build step or transpilation is required.
47
28
 
48
29
  ---
49
30
 
50
-
51
-
52
31
  ## Key Features
53
32
 
54
-
55
-
56
- - _Sub-millisecond_ resolution: Resolves aliases in <0.1ms even under heavy load.
57
- - Adaptive strategy engine:
58
- - Linear scan for ≤100 aliases
59
- - Radix tree for ≥100 aliases
60
- - Optimized LRU cache: Batch eviction (10% at a time) to avoid GC spikes.
61
- - Package.json-first design: Aliases live only in package.json.
62
- - Dynamic alias support: Programmatic runtime path generation.
63
- - Custom module directories: Extend require() to search in non-standard folders.
64
- - Zero dependencies: Pure Node.js, fully compatible with `"use strict"`.
65
- - Minimal memory footprint: Optimized data structures and memory-aware algorithms.
66
- - Hot-reload support (optional) for development.
67
- - Verbose/debug mode for tracing resolution steps.
68
- - TypeScript paths auto-generation.
69
- - Friendly error messages & config validation.
70
- - Default presets: `@root`, `@src` for plug-and-play.
71
-
72
-
73
-
74
- ---
75
-
76
-
33
+ - Sub-millisecond alias resolution in typical usage scenarios
34
+ - Adaptive resolution strategy:
35
+ - Linear scan for smaller alias sets (≤100)
36
+ - Radix tree lookup for larger configurations (>100)
37
+ - LRU cache with batch-based eviction to reduce GC pressure
38
+ - Aliases configured directly in `package.json`
39
+ - Support for dynamic, runtime-generated aliases
40
+ - Optional custom module directories
41
+ - Zero external dependencies (pure Node.js)
42
+ - Small and predictable memory footprint
43
+ - Optional hot-reload support for development environments
44
+ - Debug and verbose modes for tracing resolution behavior
45
+ - Helper for generating TypeScript path mappings
46
+ - Configuration validation with clear error messages
47
+ - Built-in presets such as `@root` and `@src`
77
48
 
78
49
  ## How It Works
79
50
 
80
-
51
+ - Initialization: Reads alias definitions from `package.json` keys starting with `path_aliaser`
52
+ - Registration: Builds internal alias-to-path mappings
53
+ - Strategy selection:
54
+ - Fewer aliases use a simple linear scan
55
+ - Larger sets switch to a radix-tree-based lookup
56
+ - Module patching: Hooks into Node.js module resolution
57
+ - Caching: Stores resolved paths using an LRU cache
58
+ - Path propagation: Injects custom module directories when configured
81
59
 
82
- - Initialization: Scans `package.json` for keys starting with `path_aliaser`.
83
- - Alias Registration: Loads all alias → target mappings.
84
- - Strategy Selection:
85
- - `<100 aliases → linear scan`
86
- - `≥100 aliases → radix tree for O(k) prefix lookups`
87
- - Module Patching: Overrides Node.js’s resolver functions.
88
- - Caching: Uses high-efficiency LRU cache with batch eviction.
89
- - Path Propagation: Custom module directories injected into all active module paths.
90
-
91
-
92
-
93
- All happens once at startup with near-zero runtime cost.
94
-
95
-
60
+ All setup is performed once at startup.
96
61
 
97
62
  ---
98
63
 
99
-
100
-
101
64
  ## Installation
102
65
 
103
-
104
-
105
66
  ```bash
106
-
107
- npm install pathlra-aliaser
108
-
67
+ npm install pathlra-aliaser
109
68
  ```
110
69
 
111
-
112
-
113
70
  ---
114
71
 
115
-
116
-
117
72
  ## Configuration via `package.json`
118
73
 
119
-
120
-
121
74
  ```json
122
-
123
75
  {
124
-
125
- "name": "name",
126
- "version": "4",
127
- "main": "index.js",
128
- "dependencies": {
129
- "pathlra-aliaser": "^3.6.7"
130
-
131
- },
132
- "path_aliaser": {
133
- "@products": "./routes/products.js",
134
- "@users": "./routes/users.js",
135
- "@logger": "./utils/logger.js"
136
- },
137
- "_moduleDirectories": ["node_modules", "custom_libs"],
138
- "scripts": {
139
- "test": "echo "Error: no test specified" && exit 1"
140
-
141
- },
142
- "license": "ISC",
143
- "description": "High-performance path alias resolver for Node.js with LRU caching and radix-tree optimization"
144
-
76
+ "dependencies": {
77
+ "pathlra-aliaser": "^3.6.7"
78
+ },
79
+ "path_aliaser": {
80
+ "@products": "./routes/products.js",
81
+ "@users": "./routes/users.js",
82
+ "@logger": "./utils/logger.js"
83
+ },
84
+ "_moduleDirectories": ["node_modules", "custom_libs"]
145
85
  }
146
-
147
86
  ```
148
87
 
149
-
150
-
151
- _Paths are relative to the project root._
152
-
153
- `_moduleDirectories` extends Node.js’s search paths safely.
88
+ Paths are resolved relative to the project root.
154
89
 
155
-
90
+ `_moduleDirectories` extends Node.js’s module search paths in a controlled manner.
156
91
 
157
92
  ---
158
93
 
159
-
160
-
161
94
  ## Example Usage
162
95
 
163
-
164
-
165
96
  ```js
166
-
167
97
  "use strict";
168
- require("pathlra-aliaser")(); // Must be called BEFORE any aliased requires
169
- const logger = require("@utils/logger");
170
- const User = require("@models/User");
171
98
 
172
- ```
99
+ require("pathlra-aliaser")(); // Must be called before aliased requires
173
100
 
174
-
101
+ const logger = require("@utils/logger");
102
+ const User = require("@models/User");
103
+ ```
175
104
 
176
105
  ---
177
106
 
178
-
179
-
180
107
  ## Advanced Features
181
108
 
182
-
183
-
184
- **Dynamic Aliases:**
185
-
186
-
109
+ ### Dynamic Aliases
187
110
 
188
111
  ```js
112
+ const aliaser = require("pathlra-aliaser");
189
113
 
190
- const aliaser = require("pathlra-aliaser");
191
- aliaser.aa("@dynamic", () => "./runtime/path");
192
-
114
+ aliaser.aa("@dynamic", () => "./runtime/path");
193
115
  ```
194
116
 
195
-
196
-
197
- **Add Custom Module Directory:**
198
-
199
-
117
+ ### Add a Custom Module Directory
200
118
 
201
119
  ```js
202
-
203
120
  aliaser.ap("./internal_modules");
204
-
205
121
  ```
206
122
 
207
-
208
-
209
- **Bulk Alias Registration:**
210
-
211
-
123
+ ### Bulk Alias Registration
212
124
 
213
125
  ```js
126
+ aliaser.addAliases({
127
+ "@core": "./src/core"
128
+ });
129
+ ```
214
130
 
215
- aliaser.addAliases({ "@core": "./src/core" });
131
+ ---
216
132
 
217
- ```
133
+ ## Performance & Benchmarks
218
134
 
219
-
135
+ - Default cache size: 10,000 entries
136
+ - Eviction strategy: Batch removal of least-used entries
137
+ - Typical memory usage: <2 MB with large alias sets
138
+
139
+ Benchmark results depend on workload and project structure.
220
140
 
221
141
  ---
222
142
 
223
-
143
+ ## Ideal For
224
144
 
225
- ## Performance & Benchmarks
145
+ - Medium to large Node.js applications
146
+ - Microservices and modular architectures
147
+ - Long-running backend processes
148
+ - Teams that want consistent import conventions
226
149
 
227
-
150
+ **Not intended for:** frontend bundling workflows, build-time-only aliasing, or projects that avoid `package.json` configuration.
228
151
 
229
- - Cache: 10,000 entries by default
230
- - Eviction: 10% of least-used entries per batch
231
- - Memory usage: <2 MB with 1,000+ aliases
152
+ ---
232
153
 
233
-
154
+ ## Common Misconceptions
234
155
 
235
- **Benchmarks vs module-alias:**
156
+ - “I need to register every alias manually.” → Aliases can be defined entirely in `package.json`.
157
+ - “It replaces Node.js behavior unsafely.” → It integrates with the resolver while preserving expected semantics.
158
+ - “It adds noticeable runtime overhead.” → Resolution is cached and designed to remain efficient after warm-up.
236
159
 
237
-
160
+ ---
238
161
 
239
- - 3.2x faster (10 aliases)
240
- - 8.7x faster (1,000 aliases)
241
- - 60% lower memory usage under load
242
162
 
243
-
244
163
 
245
- ---
246
164
 
247
-
248
165
 
249
- ## Ideal For
250
166
 
251
-
252
167
 
253
- - Large-scale Node.js applications
254
- - Microservices
255
- - Performance-critical systems
256
- - Long-running processes
257
- - Teams enforcing standardized path conventions
168
+ ## Feature & Performance Comparison: `pathlra-aliaser` vs Top Alternatives
258
169
 
259
-
170
+ | Feature / Capability | **`pathlra-aliaser`** ✅ | **`module-alias`** | **`tsconfig-paths`** | **`babel-plugin-module-resolver`** |
171
+ |----------------------|--------------------------|--------------------|------------------------|------------------------------------|
172
+ | **Pure Node.js (no build step)** | ✅ Yes | ✅ Yes | ⚠️ Only with `ts-node` | ❌ Requires Babel transpilation |
173
+ | **Zero Dependencies** | ✅ Yes | ✅ Yes | ❌ Needs TypeScript | ❌ Needs Babel + plugins |
174
+ | **Sub-millisecond Resolution** | ✅ **<0.1ms** (adaptive) | ❌ ~0.3–1ms (linear only) | ⚠️ Slower (TS overhead) | N/A (build-time only) |
175
+ | **Smart Resolution Strategy** | ✅ **Radix Tree (≥100 aliases)** + Linear (<100) | ❌ Linear scan only (`O(n)`) | ❌ Regex-based matching | N/A |
176
+ | **LRU Caching with Batch Eviction** | ✅ Yes (10k entries, 10% batch) | ❌ No cache | ⚠️ Limited caching | N/A |
177
+ | **Dynamic Aliases (Handler Functions)** | ✅ Yes + **type validation** | ✅ Yes (no validation) | ❌ No | ❌ No |
178
+ | **Hot-Reload Support** | ✅ Optional (dev-only) | ❌ No | ⚠️ Via `ts-node-dev` | ❌ No |
179
+ | **TypeScript Paths Auto-Gen** | ✅ Built-in `_internal.generateTSConfig()` | ❌ No | N/A (it *is* TS) | ❌ Manual sync needed |
180
+ | **Security: Path Traversal Protection** | ✅ Blocks `..`, `~`, `\0` | ❌ **Vulnerable** | ⚠️ Depends on config | N/A |
181
+ | **Memory Optimization** | ✅ **Minimal Mode** (<10 aliases → 1k cache) | ❌ Fixed overhead | ❌ High TS memory use | N/A |
182
+ | **Config via `package.json`** | ✅ Any key starting with `path_aliaser` | ✅ `_moduleAliases` only | ❌ `tsconfig.json` only | ❌ `.babelrc` / `babel.config.js` |
183
+ | **Custom Module Directories** | ✅ `_moduleDirectories` + `ap()` | ✅ `_moduleDirectories` | ❌ No | ❌ No |
184
+ | **Debug/Verbose Mode** | ✅ Full resolution tracing | ❌ No | ⚠️ Limited logs | ❌ No |
185
+ | **ESM Support** | ✅ Via patched resolver | ✅ Partial (Node ≥14.6+) | ✅ With `ts-node` | ✅ If Babel configured |
186
+ | **Works in Jest** | ⚠️ Same as `module-alias` (needs `moduleNameMapper`) | ⚠️ Requires Jest config | ✅ With `ts-jest` | ✅ If Babel used in Jest |
187
+ | **Production-Ready Performance** | ✅ **8.7x faster @ 1k aliases**, 60% less RAM | ❌ Degrades with scale | ❌ Not for pure JS projects | ❌ Build-only |
188
+ | **Default Presets** | ✅ `@root`, `@src` auto-applied | ❌ None | ❌ None | ❌ None |
189
+ | **Friendly Error Messages** | ✅ Clear, actionable errors | ⚠️ Generic errors | ⚠️ TS cryptic errors | ⚠️ Babel errors |
260
190
 
261
- **Not for:** Frontend bundling, TypeScript-only projects (unless with ts-node), or projects preferring config files over package.json.
262
191
 
263
-
264
192
 
265
- ---
266
193
 
267
-
268
194
 
269
- ## Common Misconceptions
270
195
 
271
-
272
196
 
273
- - “I need to call `aa()` for every alias.” → No, `package.json` is enough.
274
- - “It modifies global behavior unsafely” → Only patches Node.js resolver safely.
275
- - “It slows down my app.” → Benchmarks show faster resolution than manual paths after warm-up.
276
197
 
277
-
278
198
 
279
- ---
280
199
 
281
-
282
200
 
201
+ ---
283
202
  ## License
284
- MIT © hub-mgv
285
- Engineered for speed. Built for scale. Designed to disappear.
286
- `pathlra-aliaser`: where path resolution becomes invisible.
287
203
 
204
+ MIT © hub-mgv
288
205
 
206
+ Built to be reliable, efficient, and unobtrusive.
289
207
 
208
+ `pathlra-aliaser`: keeping path resolution simple.
package/index.html ADDED
@@ -0,0 +1,409 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>pathlra-aliaser - README.md</title>
7
+ <style>
8
+ body {
9
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
10
+ line-height: 1.6;
11
+ color: #24292e;
12
+ max-width: 900px;
13
+ margin: 0 auto;
14
+ padding: 2rem 1rem;
15
+ background-color: #ffffff;
16
+ }
17
+ h1, h2, h3 {
18
+ margin-top: 1.5em;
19
+ margin-bottom: 0.8em;
20
+ font-weight: 600;
21
+ }
22
+ h1 {
23
+ font-size: 2.25em;
24
+ border-bottom: 1px solid #eaecef;
25
+ padding-bottom: 0.3em;
26
+ }
27
+ h2 {
28
+ font-size: 1.75em;
29
+ border-bottom: 1px solid #eaecef;
30
+ padding-bottom: 0.3em;
31
+ }
32
+ h3 {
33
+ font-size: 1.375em;
34
+ }
35
+ p {
36
+ margin: 0.8em 0;
37
+ }
38
+ code {
39
+ background-color: rgba(27,31,35,0.05);
40
+ padding: 0.2em 0.4em;
41
+ border-radius: 6px;
42
+ font-family: SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
43
+ font-size: 0.9em;
44
+ }
45
+ pre {
46
+ background-color: #f6f8fa;
47
+ border-radius: 6px;
48
+ padding: 16px;
49
+ overflow: auto;
50
+ margin: 1rem 0;
51
+ }
52
+ pre code {
53
+ background: none;
54
+ padding: 0;
55
+ font-size: 0.95em;
56
+ }
57
+ table {
58
+ width: 100%;
59
+ border-collapse: collapse;
60
+ margin: 1rem 0;
61
+ }
62
+ th, td {
63
+ padding: 6px 13px;
64
+ border: 1px solid #dfe2e5;
65
+ text-align: left;
66
+ }
67
+ th {
68
+ background-color: #f6f8fa;
69
+ font-weight: 600;
70
+ }
71
+ tr:nth-child(even) {
72
+ background-color: #f6f8fa;
73
+ }
74
+ ul, ol {
75
+ padding-left: 2em;
76
+ margin: 0.8em 0;
77
+ }
78
+ li {
79
+ margin: 0.3em 0;
80
+ }
81
+ .highlight {
82
+ background-color: #fff8c5;
83
+ padding: 0.2em 0.4em;
84
+ border-radius: 4px;
85
+ }
86
+ .note {
87
+ background-color: #f0f8ff;
88
+ border-left: 4px solid #0366d6;
89
+ padding: 1em 1.2em;
90
+ margin: 1.5em 0;
91
+ }
92
+ .footer {
93
+ margin-top: 2rem;
94
+ padding-top: 1rem;
95
+ border-top: 1px solid #eaecef;
96
+ color: #6a737d;
97
+ font-size: 0.9em;
98
+ }
99
+ .badge {
100
+ display: inline-block;
101
+ padding: 0.25em 0.5em;
102
+ font-size: 0.8em;
103
+ font-weight: bold;
104
+ border-radius: 4px;
105
+ margin-right: 0.3em;
106
+ }
107
+ .success { background-color: #dafbe1; color: #22863a; }
108
+ .warning { background-color: #fff5b1; color: #9a6700; }
109
+ .danger { background-color: #ffe3e6; color: #d73a49; }
110
+ .info { background-color: #dbedff; color: #0366d6; }
111
+ </style>
112
+ </head>
113
+ <body>
114
+ <h1>Ultra-Fast, Zero-Dependency Path Alias Resolver for Node.js</h1>
115
+ <p><em>Developed by hub-mgv ❤️</em></p>
116
+
117
+ <h2>pathlra-aliaser</h2>
118
+ <p>Ultra-Fast, Zero-Dependency Path Alias Resolver for Node.js</p>
119
+ <p>Engineered for sub-millisecond resolution, extreme performance, and seamless integration with zero runtime overhead in production.</p>
120
+
121
+ <hr>
122
+
123
+ <h2>Why pathlra-aliaser?</h2>
124
+ <p>Most alias tools are slow, bloated, or force you to manage paths in JavaScript files.</p>
125
+ <p><code>pathlra-aliaser</code> is a high-performance module loader enhancer built for speed, stability, and minimal memory footprint. It safely patches Node.js’s module resolution system, enabling clean, readable imports like:</p>
126
+ <pre><code class="language-js">const db = require("@services/database");</code></pre>
127
+ <p>without any build step, transpilation, or runtime penalty.</p>
128
+
129
+ <hr>
130
+
131
+ <h2>Key Features</h2>
132
+ <ul>
133
+ <li><span class="highlight">Sub-millisecond resolution</span>: Resolves aliases in &lt;0.1ms even under heavy load.</li>
134
+ <li><strong>Adaptive strategy engine</strong>:
135
+ <ul>
136
+ <li>Linear scan for ≤100 aliases</li>
137
+ <li>Radix tree for ≥100 aliases</li>
138
+ </ul>
139
+ </li>
140
+ <li><strong>Optimized LRU cache</strong>: Batch eviction (10% at a time) to avoid GC spikes.</li>
141
+ <li><strong>Package.json-first design</strong>: Aliases live only in package.json.</li>
142
+ <li><strong>Dynamic alias support</strong>: Programmatic runtime path generation.</li>
143
+ <li><strong>Custom module directories</strong>: Extend require() to search in non-standard folders.</li>
144
+ <li><strong>Zero dependencies</strong>: Pure Node.js, fully compatible with <code>"use strict"</code>.</li>
145
+ <li><strong>Minimal memory footprint</strong>: Optimized data structures and memory-aware algorithms.</li>
146
+ <li><strong>Hot-reload support</strong> (optional) for development.</li>
147
+ <li><strong>Verbose/debug mode</strong> for tracing resolution steps.</li>
148
+ <li><strong>TypeScript paths auto-generation</strong>.</li>
149
+ <li><strong>Friendly error messages &amp; config validation</strong>.</li>
150
+ <li><strong>Default presets</strong>: <code>@root</code>, <code>@src</code> for plug-and-play.</li>
151
+ </ul>
152
+
153
+ <hr>
154
+
155
+ <h2>How It Works</h2>
156
+ <ul>
157
+ <li><strong>Initialization</strong>: Scans <code>package.json</code> for keys starting with <code>path_aliaser</code>.</li>
158
+ <li><strong>Alias Registration</strong>: Loads all alias → target mappings.</li>
159
+ <li><strong>Strategy Selection</strong>:
160
+ <ul>
161
+ <li>&lt;100 aliases → linear scan</li>
162
+ <li>≥100 aliases → radix tree for O(k) prefix lookups</li>
163
+ </ul>
164
+ </li>
165
+ <li><strong>Module Patching</strong>: Overrides Node.js’s resolver functions.</li>
166
+ <li><strong>Caching</strong>: Uses high-efficiency LRU cache with batch eviction.</li>
167
+ <li><strong>Path Propagation</strong>: Custom module directories injected into all active module paths.</li>
168
+ </ul>
169
+ <p>All happens once at startup with near-zero runtime cost.</p>
170
+
171
+ <hr>
172
+
173
+ <h2>Feature & Performance Comparison</h2>
174
+ <table>
175
+ <thead>
176
+ <tr>
177
+ <th>Feature / Capability</th>
178
+ <th>pathlra-aliaser</th>
179
+ <th>module-alias</th>
180
+ <th>tsconfig-paths</th>
181
+ <th>babel-plugin-module-resolver</th>
182
+ </tr>
183
+ </thead>
184
+ <tbody>
185
+ <tr>
186
+ <td>Pure Node.js (no build step)</td>
187
+ <td><span class="badge success">Yes</span></td>
188
+ <td><span class="badge success">Yes</span></td>
189
+ <td><span class="badge warning">Only with ts-node</span></td>
190
+ <td><span class="badge danger">Requires Babel</span></td>
191
+ </tr>
192
+ <tr>
193
+ <td>Zero Dependencies</td>
194
+ <td><span class="badge success">Yes</span></td>
195
+ <td><span class="badge success">Yes</span></td>
196
+ <td><span class="badge danger">Needs TypeScript</span></td>
197
+ <td><span class="badge danger">Needs Babel + plugins</span></td>
198
+ </tr>
199
+ <tr>
200
+ <td>Sub-millisecond Resolution</td>
201
+ <td><span class="badge success">&lt;0.1ms (adaptive)</span></td>
202
+ <td><span class="badge danger">~0.3–1ms (linear only)</span></td>
203
+ <td><span class="badge warning">Slower (TS overhead)</span></td>
204
+ <td>N/A (build-time only)</td>
205
+ </tr>
206
+ <tr>
207
+ <td>Smart Resolution Strategy</td>
208
+ <td><span class="badge success">Radix Tree (≥100) + Linear (&lt;100)</span></td>
209
+ <td><span class="badge danger">Linear scan only (O(n))</span></td>
210
+ <td><span class="badge danger">Regex-based matching</span></td>
211
+ <td>N/A</td>
212
+ </tr>
213
+ <tr>
214
+ <td>LRU Caching with Batch Eviction</td>
215
+ <td><span class="badge success">Yes (10k entries, 10% batch)</span></td>
216
+ <td><span class="badge danger">No cache</span></td>
217
+ <td><span class="badge warning">Limited caching</span></td>
218
+ <td>N/A</td>
219
+ </tr>
220
+ <tr>
221
+ <td>Dynamic Aliases (Handler Functions)</td>
222
+ <td><span class="badge success">Yes + type validation</span></td>
223
+ <td><span class="badge info">Yes (no validation)</span></td>
224
+ <td><span class="badge danger">No</span></td>
225
+ <td><span class="badge danger">No</span></td>
226
+ </tr>
227
+ <tr>
228
+ <td>Hot-Reload Support</td>
229
+ <td><span class="badge success">Optional (dev-only)</span></td>
230
+ <td><span class="badge danger">No</span></td>
231
+ <td><span class="badge warning">Via ts-node-dev</span></td>
232
+ <td><span class="badge danger">No</span></td>
233
+ </tr>
234
+ <tr>
235
+ <td>TypeScript Paths Auto-Gen</td>
236
+ <td><span class="badge success">Built-in</span></td>
237
+ <td><span class="badge danger">No</span></td>
238
+ <td>N/A (it <em>is</em> TS)</td>
239
+ <td><span class="badge danger">Manual sync needed</span></td>
240
+ </tr>
241
+ <tr>
242
+ <td>Security: Path Traversal Protection</td>
243
+ <td><span class="badge success">Blocks .., ~, \0</span></td>
244
+ <td><span class="badge danger">Vulnerable</span></td>
245
+ <td><span class="badge warning">Depends on config</span></td>
246
+ <td>N/A</td>
247
+ </tr>
248
+ <tr>
249
+ <td>Memory Optimization</td>
250
+ <td><span class="badge success">Minimal Mode (&lt;10 aliases → 1k cache)</span></td>
251
+ <td><span class="badge danger">Fixed overhead</span></td>
252
+ <td><span class="badge danger">High TS memory use</span></td>
253
+ <td>N/A</td>
254
+ </tr>
255
+ <tr>
256
+ <td>Config via package.json</td>
257
+ <td><span class="badge success">Any key starting with path_aliaser</span></td>
258
+ <td><span class="badge success">_moduleAliases only</span></td>
259
+ <td><span class="badge danger">tsconfig.json only</span></td>
260
+ <td><span class="badge danger">.babelrc / babel.config.js</span></td>
261
+ </tr>
262
+ <tr>
263
+ <td>Custom Module Directories</td>
264
+ <td><span class="badge success">_moduleDirectories + ap()</span></td>
265
+ <td><span class="badge success">_moduleDirectories</span></td>
266
+ <td><span class="badge danger">No</span></td>
267
+ <td><span class="badge danger">No</span></td>
268
+ </tr>
269
+ <tr>
270
+ <td>Debug/Verbose Mode</td>
271
+ <td><span class="badge success">Full resolution tracing</span></td>
272
+ <td><span class="badge danger">No</span></td>
273
+ <td><span class="badge warning">Limited logs</span></td>
274
+ <td><span class="badge danger">No</span></td>
275
+ </tr>
276
+ <tr>
277
+ <td>ESM Support</td>
278
+ <td><span class="badge success">Via patched resolver</span></td>
279
+ <td><span class="badge info">Partial (Node ≥14.6+)</span></td>
280
+ <td><span class="badge success">With ts-node</span></td>
281
+ <td><span class="badge success">If Babel configured</span></td>
282
+ </tr>
283
+ <tr>
284
+ <td>Works in Jest</td>
285
+ <td><span class="badge warning">Same as module-alias (needs moduleNameMapper)</span></td>
286
+ <td><span class="badge warning">Requires Jest config</span></td>
287
+ <td><span class="badge success">With ts-jest</span></td>
288
+ <td><span class="badge success">If Babel used in Jest</span></td>
289
+ </tr>
290
+ <tr>
291
+ <td>Production-Ready Performance</td>
292
+ <td><span class="badge success">8.7x faster @ 1k aliases, 60% less RAM</span></td>
293
+ <td><span class="badge danger">Degrades with scale</span></td>
294
+ <td><span class="badge danger">Not for pure JS projects</span></td>
295
+ <td><span class="badge danger">Build-only</span></td>
296
+ </tr>
297
+ <tr>
298
+ <td>Default Presets</td>
299
+ <td><span class="badge success">@root, @src auto-applied</span></td>
300
+ <td><span class="badge danger">None</span></td>
301
+ <td><span class="badge danger">None</span></td>
302
+ <td><span class="badge danger">None</span></td>
303
+ </tr>
304
+ <tr>
305
+ <td>Friendly Error Messages</td>
306
+ <td><span class="badge success">Clear, actionable errors</span></td>
307
+ <td><span class="badge warning">Generic errors</span></td>
308
+ <td><span class="badge warning">TS cryptic errors</span></td>
309
+ <td><span class="badge warning">Babel errors</span></td>
310
+ </tr>
311
+ </tbody>
312
+ </table>
313
+
314
+ <hr>
315
+
316
+ <h2>Installation</h2>
317
+ <pre><code class="language-bash">npm install pathlra-aliaser</code></pre>
318
+
319
+ <hr>
320
+
321
+ <h2>Configuration via package.json</h2>
322
+ <pre><code class="language-json">{
323
+ "name": "name",
324
+ "version": "4",
325
+ "main": "index.js",
326
+ "dependencies": {
327
+ "pathlra-aliaser": "^3.6.7"
328
+ },
329
+ "path_aliaser": {
330
+ "@products": "./routes/products.js",
331
+ "@users": "./routes/users.js",
332
+ "@logger": "./utils/logger.js"
333
+ },
334
+ "_moduleDirectories": ["node_modules", "custom_libs"],
335
+ "scripts": {
336
+ "test": "echo \"Error: no test specified\" && exit 1"
337
+ },
338
+ "license": "ISC",
339
+ "description": "High-performance path alias resolver for Node.js with LRU caching and radix-tree optimization"
340
+ }</code></pre>
341
+ <p><em>Paths are relative to the project root.</em></p>
342
+ <p><code>_moduleDirectories</code> extends Node.js’s search paths safely.</p>
343
+
344
+ <hr>
345
+
346
+ <h2>Example Usage</h2>
347
+ <pre><code class="language-js">"use strict";
348
+ require("pathlra-aliaser")(); // Must be called BEFORE any aliased requires
349
+ const logger = require("@utils/logger");
350
+ const User = require("@models/User");</code></pre>
351
+
352
+ <hr>
353
+
354
+ <h2>Advanced Features</h2>
355
+ <p><strong>Dynamic Aliases:</strong></p>
356
+ <pre><code class="language-js">const aliaser = require("pathlra-aliaser");
357
+ aliaser.aa("@dynamic", () => "./runtime/path");</code></pre>
358
+
359
+ <p><strong>Add Custom Module Directory:</strong></p>
360
+ <pre><code class="language-js">aliaser.ap("./internal_modules");</code></pre>
361
+
362
+ <p><strong>Bulk Alias Registration:</strong></p>
363
+ <pre><code class="language-js">aliaser.addAliases({ "@core": "./src/core" });</code></pre>
364
+
365
+ <hr>
366
+
367
+ <h2>Performance & Benchmarks</h2>
368
+ <ul>
369
+ <li>Cache: 10,000 entries by default</li>
370
+ <li>Eviction: 10% of least-used entries per batch</li>
371
+ <li>Memory usage: &lt;2 MB with 1,000+ aliases</li>
372
+ </ul>
373
+ <p><strong>Benchmarks vs module-alias:</strong></p>
374
+ <ul>
375
+ <li>3.2x faster (10 aliases)</li>
376
+ <li>8.7x faster (1,000 aliases)</li>
377
+ <li>60% lower memory usage under load</li>
378
+ </ul>
379
+
380
+ <hr>
381
+
382
+ <h2>Ideal For</h2>
383
+ <ul>
384
+ <li>Large-scale Node.js applications</li>
385
+ <li>Microservices</li>
386
+ <li>Performance-critical systems</li>
387
+ <li>Long-running processes</li>
388
+ <li>Teams enforcing standardized path conventions</li>
389
+ </ul>
390
+ <p><strong>Not for:</strong> Frontend bundling, TypeScript-only projects (unless with ts-node), or projects preferring config files over package.json.</p>
391
+
392
+ <hr>
393
+
394
+ <h2>Common Misconceptions</h2>
395
+ <ul>
396
+ <li>“I need to call <code>aa()</code> for every alias.” → No, <code>package.json</code> is enough.</li>
397
+ <li>“It modifies global behavior unsafely” → Only patches Node.js resolver safely.</li>
398
+ <li>“It slows down my app.” → Benchmarks show faster resolution than manual paths after warm-up.</li>
399
+ </ul>
400
+
401
+ <div class="footer">
402
+ <h2>License</h2>
403
+ <p>MIT © hub-mgv<br>
404
+ Engineered for speed. Built for scale. Designed to disappear.<br>
405
+ <code>pathlra-aliaser</code>: where path resolution becomes invisible.</p>
406
+ </div>
407
+ </body>
408
+ </html>
409
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pathlra-aliaser",
3
- "version": "4.6.9",
3
+ "version": "4.7.0",
4
4
  "description": "High-performance path alias resolver for Node.js with LRU caching and radix-tree optimization",
5
5
  "main": "test.js",
6
6
  "scripts": {
Binary file