forked from rockcarver/frodo-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement recommendations in nodejs/node#44859
- Loading branch information
Showing
5 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env node | ||
import { spawn } from 'node:child_process'; | ||
import { createRequire } from 'module'; | ||
|
||
const require = createRequire(import.meta.url); | ||
|
||
const launchArgs = [ | ||
'--no-warnings', | ||
'--enable-source-maps', | ||
'--experimental-loader', | ||
require.resolve('./loader.js'), | ||
require.resolve('./app.js'), | ||
]; | ||
const frodoArgs = process.argv.slice(2); | ||
|
||
spawn(process.execPath, [...launchArgs, ...frodoArgs], { | ||
stdio: 'inherit', | ||
shell: false, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { builtinModules } from 'node:module'; | ||
import { dirname } from 'path'; | ||
import { cwd } from 'process'; | ||
import { fileURLToPath, pathToFileURL } from 'url'; | ||
import { promisify } from 'util'; | ||
|
||
import resolveCallback from 'resolve/async.js'; | ||
|
||
const resolveAsync = promisify(resolveCallback); | ||
|
||
const baseURL = pathToFileURL(cwd() + '/').href; | ||
|
||
export async function resolve(specifier, context, next) { | ||
const { parentURL = baseURL } = context; | ||
|
||
if (specifier.startsWith('node:') || builtinModules.includes(specifier)) { | ||
return next(specifier, context); | ||
} | ||
|
||
// `resolveAsync` works with paths, not URLs | ||
if (specifier.startsWith('file://')) { | ||
specifier = fileURLToPath(specifier); | ||
} | ||
const parentPath = fileURLToPath(parentURL); | ||
|
||
let url; | ||
try { | ||
const resolution = await resolveAsync(specifier, { | ||
basedir: dirname(parentPath), | ||
// For whatever reason, --experimental-specifier-resolution=node doesn't search for .mjs extensions | ||
// but it does search for index.mjs files within directories | ||
extensions: ['.js', '.json', '.node', '.mjs'], | ||
}); | ||
url = pathToFileURL(resolution).href; | ||
} catch (error) { | ||
if (error.code === 'MODULE_NOT_FOUND') { | ||
// Match Node's error code | ||
error.code = 'ERR_MODULE_NOT_FOUND'; | ||
} | ||
throw error; | ||
} | ||
|
||
return next(url, context); | ||
} |