Skip to content

Commit b033df3

Browse files
core: use refPath and relPath names when suitable
1 parent cb39ff7 commit b033df3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/tools.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,22 @@ export async function loadModuleInternal(pathCx : PathContext, options : Options
297297
* Create a cjs module
298298
* @internal
299299
*/
300-
export function createModule(filename : string, source : string, options : Options) : Module {
300+
export function createModule(refPath : string, source : string, options : Options) : Module {
301301

302302
const { moduleCache, pathHandlers: { resolve }, getResource } = options;
303303

304-
const require = function(path : string) {
304+
const require = function(relPath : string) {
305305

306-
const { id } = getResource({ refPath: filename, relPath: path }, options);
306+
const { id } = getResource({ refPath, relPath }, options);
307307
if ( id in moduleCache )
308308
return moduleCache[id];
309309

310310
throw new Error(`${ id } not found in moduleCache`);
311311
}
312312

313-
const import_ = async function(path : string) {
313+
const import_ = async function(relPath : string) {
314314

315-
return await loadModuleInternal({ refPath: filename, relPath: path }, options);
315+
return await loadModuleInternal({ refPath, relPath }, options);
316316
}
317317

318318
const module = {
@@ -321,7 +321,7 @@ export function createModule(filename : string, source : string, options : Optio
321321

322322
// see https://github.com/nodejs/node/blob/a46b21f556a83e43965897088778ddc7d46019ae/lib/internal/modules/cjs/loader.js#L195-L198
323323
// see https://github.com/nodejs/node/blob/a46b21f556a83e43965897088778ddc7d46019ae/lib/internal/modules/cjs/loader.js#L1102
324-
Function('exports', 'require', 'module', '__filename', '__dirname', 'import_', source).call(module.exports, module.exports, require, module, filename, resolve({ refPath: filename, relPath: '.' }), import_);
324+
Function('exports', 'require', 'module', '__filename', '__dirname', 'import_', source).call(module.exports, module.exports, require, module, refPath, resolve({ refPath, relPath: '.' }), import_);
325325

326326
return module;
327327
}
@@ -348,9 +348,9 @@ export async function createJSModule(source : string, moduleSourceType : boolean
348348
* Just load and cache given dependencies.
349349
* @internal
350350
*/
351-
export async function loadDeps(filename : string, deps : string[], options : Options) : Promise<void> {
351+
export async function loadDeps(refPath : string, deps : string[], options : Options) : Promise<void> {
352352

353-
await Promise.all(deps.map(dep => loadModuleInternal({ refPath: filename, relPath: dep }, options)))
353+
await Promise.all(deps.map(relPath => loadModuleInternal({ refPath, relPath }, options)))
354354
}
355355

356356

0 commit comments

Comments
 (0)