From e38672cd3e38f759708d7bd5a3a520559f431d33 Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Sun, 4 Feb 2018 18:13:44 -0500 Subject: [PATCH 1/7] Updated require.resolve The official `require.resolve` docs say that it now accepts a second argument, an object with a paths property is an array which I think is comprised of strings. --- types/node/index.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 38f043554b..5d4a3d54c3 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -118,12 +118,17 @@ interface NodeRequireFunction { } interface NodeRequire extends NodeRequireFunction { - resolve(id: string): string; + resolve: RequireResolve; cache: any; extensions: NodeExtensions; main: NodeModule | undefined; } +interface RequireResolve { + (id: string, options?: { paths: string[]; }): string; + paths(request: string): string[]; +} + interface NodeExtensions { '.js': (m: NodeModule, filename: string) => any; '.json': (m: NodeModule, filename: string) => any; From aa6b62b81fae34eddf363ea1de270ccbfed7b170 Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Sun, 4 Feb 2018 18:46:17 -0500 Subject: [PATCH 2/7] A bit of backporting It was added in 8.9 after all... --- types/node/v8/index.d.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 18ba96575d..98d6b10e2d 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -116,12 +116,17 @@ interface NodeRequireFunction { } interface NodeRequire extends NodeRequireFunction { - resolve(id: string): string; + resolve: RequireResolve; cache: any; extensions: NodeExtensions; main: NodeModule | undefined; } +interface RequireResolve { + (id: string, options?: { paths: string[]; }): string; + paths(request: string): string[]; +} + interface NodeExtensions { '.js': (m: NodeModule, filename: string) => any; '.json': (m: NodeModule, filename: string) => any; From b86955ac31118d1a476f16d7d958e2b83bdaae65 Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:13:51 -0500 Subject: [PATCH 3/7] Update require.resolve.paths type I'm not too familiar with the strict null checks, sorry. --- types/node/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 5d4a3d54c3..8c002ed5e3 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -126,7 +126,7 @@ interface NodeRequire extends NodeRequireFunction { interface RequireResolve { (id: string, options?: { paths: string[]; }): string; - paths(request: string): string[]; + paths(request: string): string[] | null; } interface NodeExtensions { From 8c8d986e3b66246035a053051220286f57e9a585 Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:16:15 -0500 Subject: [PATCH 4/7] Update require.resolve.paths type I've also changed the version in the header, as this bit wasn't added until 8.9.x. I hope that's okay. --- types/node/v8/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index 98d6b10e2d..d2c9d822ba 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Node.js 8.5.x +// Type definitions for Node.js 8.9.x // Project: http://nodejs.org/ // Definitions by: Microsoft TypeScript // DefinitelyTyped @@ -124,7 +124,7 @@ interface NodeRequire extends NodeRequireFunction { interface RequireResolve { (id: string, options?: { paths: string[]; }): string; - paths(request: string): string[]; + paths(request: string): string[] | null; } interface NodeExtensions { From b29ebabcb860dd8c4482a79c4a1fa860a0437e4a Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:29:26 -0500 Subject: [PATCH 5/7] Made paths property optional Granted, I can't imagine any reason you wouldn't have it, but you don't have to! --- types/node/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 8c002ed5e3..72a9d5085c 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -125,7 +125,7 @@ interface NodeRequire extends NodeRequireFunction { } interface RequireResolve { - (id: string, options?: { paths: string[]; }): string; + (id: string, options?: { paths?: string[]; }): string; paths(request: string): string[] | null; } From 91fcfae67f771fcb8e337db89a3d879477dc1593 Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:30:33 -0500 Subject: [PATCH 6/7] Made paths property optional I'm making a lot of seemingly duplicate commits here, aren't I? --- types/node/v8/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node/v8/index.d.ts b/types/node/v8/index.d.ts index d2c9d822ba..fb80321e0c 100644 --- a/types/node/v8/index.d.ts +++ b/types/node/v8/index.d.ts @@ -123,7 +123,7 @@ interface NodeRequire extends NodeRequireFunction { } interface RequireResolve { - (id: string, options?: { paths: string[]; }): string; + (id: string, options?: { paths?: string[]; }): string; paths(request: string): string[] | null; } From a6a051d44838a32fe7f81ded506eb8dc8a1b22fe Mon Sep 17 00:00:00 2001 From: glmdgrielson <32415403+glmdgrielson@users.noreply.github.com> Date: Mon, 5 Feb 2018 09:52:01 -0500 Subject: [PATCH 7/7] Removed whitespace Stupid auto-indent... --- types/node/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/node/index.d.ts b/types/node/index.d.ts index 72a9d5085c..3741468c4f 100644 --- a/types/node/index.d.ts +++ b/types/node/index.d.ts @@ -128,7 +128,7 @@ interface RequireResolve { (id: string, options?: { paths?: string[]; }): string; paths(request: string): string[] | null; } - + interface NodeExtensions { '.js': (m: NodeModule, filename: string) => any; '.json': (m: NodeModule, filename: string) => any;