Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions types/node/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,13 @@ interface NodeRequireFunction {
(id: string): any;
}

interface NodeRequireCache {
[path: string]: NodeModule;
}

interface NodeRequire extends NodeRequireFunction {
resolve: RequireResolve;
cache: any;
cache: NodeRequireCache;
/**
* @deprecated
*/
Expand Down Expand Up @@ -1134,8 +1138,8 @@ declare namespace NodeJS {
/**
* @deprecated Deprecated since: v12.2.0. Please use createRequire() instead.
*/
static createRequireFromPath(path: string): NodeRequireFunction;
static createRequire(path: string): NodeRequireFunction;
static createRequireFromPath(path: string): NodeRequire;
static createRequire(path: string): NodeRequire;
static builtinModules: string[];

static Module: typeof Module;
Expand Down
18 changes: 17 additions & 1 deletion types/node/node-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,23 @@ import moduleModule = require('module');
let paths: string[] = module.paths;
paths = m1.paths;

moduleModule.createRequireFromPath('./test')('test');
const customRequire1 = moduleModule.createRequireFromPath('./test');
const customRequire2 = moduleModule.createRequire('./test');

customRequire1('test');
customRequire2('test');

const resolved1: string = customRequire1.resolve('test');
const resolved2: string = customRequire2.resolve('test');

const paths1: string[] | null = customRequire1.resolve.paths('test');
const paths2: string[] | null = customRequire2.resolve.paths('test');

const cachedModule1: Module = customRequire1.cache['/path/to/module.js'];
const cachedModule2: Module = customRequire2.cache['/path/to/module.js'];

const main1: Module | undefined = customRequire1.main;
const main2: Module | undefined = customRequire2.main;
}

/////////////////////////////////////////////////////////
Expand Down