MCPcopy Create free account
hub / github.com/webpack/webpack-cli / resolveFromCwd

Function resolveFromCwd

test/external-command/my-loader.mjs:10–22  ·  view source on GitHub ↗

* Resolves a bare specifier from the `node_modules` directory of the current working directory. * @param {string} specifier module specifier * @param {Error & { code?: string }} err error thrown by the next resolve hook * @returns {{ url: string, shortCircuit: boolean }} resolution result

(specifier, err)

Source from the content-addressed store, hash-verified

8 * @returns {{ url: string, shortCircuit: boolean }} resolution result
9 */
10function resolveFromCwd(specifier, err) {
11 if (err.code === "ERR_MODULE_NOT_FOUND" && !specifier.startsWith(".")) {
12 const baseDir = join(process.cwd(), "node_modules/");
13 const resolved = join(baseDir, specifier, "index.js");
14
15 return {
16 url: pathToFileURL(resolved).href,
17 shortCircuit: true,
18 };
19 }
20
21 throw err;
22}
23
24// Asynchronous hook, used with `module.register()`
25export async function resolve(specifier, context, nextResolve) {

Callers 2

resolveFunction · 0.85
resolveSyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected