summaryrefslogtreecommitdiff
path: root/scripts/test/node-esm-loader.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/test/node-esm-loader.mjs')
-rw-r--r--scripts/test/node-esm-loader.mjs32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/test/node-esm-loader.mjs b/scripts/test/node-esm-loader.mjs
new file mode 100644
index 000000000..73ff47800
--- /dev/null
+++ b/scripts/test/node-esm-loader.mjs
@@ -0,0 +1,32 @@
+// originally lifted from https://nodejs.org/api/esm.html
+
+import path from 'path';
+import process from 'process';
+import Module from 'module';
+
+const builtins = Module.builtinModules;
+
+const baseURL = new URL('file://');
+baseURL.pathname = `${process.cwd()}/`;
+
+export function resolve(specifier, parentModuleURL = baseURL, defaultResolve) {
+ if (builtins.includes(specifier)) {
+ return {
+ url: specifier,
+ format: 'builtin'
+ };
+ }
+ // Resolve the 'spectest' module to our special module which has some builtins
+ if (specifier == 'spectest') {
+ const resolved = new URL('./scripts/test/spectest.js', parentModuleURL);
+ return {
+ url: resolved.href,
+ format: 'esm'
+ };
+ }
+ const resolved = new URL(specifier, parentModuleURL);
+ return {
+ url: resolved.href,
+ format: 'esm'
+ };
+}