aboutsummaryrefslogtreecommitdiffstats
path: root/loader.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2023-12-19 12:43:16 -0800
committerAdam Soltys <[email protected]>2023-12-20 14:39:08 -0800
commit337ca8c555f188d64c9f065972d443377adf042f (patch)
tree80dddebc6d1b9fa38bb3ff879602156db5f450a8 /loader.js
parent5b9cf9b2ea872849c3e53a61b72fd6b9107183e3 (diff)
downloadcoinos-server-337ca8c555f188d64c9f065972d443377adf042f.tar.gz
coinos-server-337ca8c555f188d64c9f065972d443377adf042f.zip
node 21
Diffstat (limited to 'loader.js')
-rw-r--r--loader.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/loader.js b/loader.js
index 7deda005..e8f5036e 100644
--- a/loader.js
+++ b/loader.js
@@ -1,8 +1,22 @@
import path from 'path'
import fs from 'fs'
-export function resolve (specifier, parentModuleURL, defaultResolver) {
- specifier = specifier.replace(/^\$/, path.resolve('.') + "/")
- specifier = fs.existsSync(specifier) && fs.lstatSync(specifier).isDirectory() ? `${specifier}/index` : specifier
- return defaultResolver(specifier, parentModuleURL)
+export function resolve (specifier, context, nextResolve) {
+ const { parentURL = null } = context;
+
+ if (specifier.startsWith('$')) {
+ if (specifier.startsWith('$config')) {
+ specifier = 'file://' + path.resolve('.') + "/config.js";
+ }
+ else if (specifier.startsWith('$')) {
+ specifier = specifier.replace(/^\$/, 'file://' + path.resolve('.') + '/') + '.js';
+ }
+
+ return {
+ shortCircuit: true,
+ url: new URL(specifier).href
+ };
+ }
+
+ return nextResolve(specifier, context)
}