From 45c5bcd85453cc195ed09a2e03c3f2e3d0fc4f39 Mon Sep 17 00:00:00 2001 From: Flarna Date: Fri, 28 Oct 2016 16:13:14 +0200 Subject: [PATCH] Add process.mainModule, improve NodeModule (#12257) * Add process.mainModule, improve NodeModule Add mainModule in process. See https://nodejs.org/dist/latest-v6.x/docs/api/process.html#process_process_mainmodule improve require.main see https://nodejs.org/dist/latest-v6.x/docs/api/modules.html#modules_accessing_the_main_module improve NodeModule see https://nodejs.org/dist/latest-v6.x/docs/api/modules.html#modules_module_children and https://nodejs.org/dist/latest-v6.x/docs/api/modules.html#modules_module_parent * Correct require.main and NodeModule --- node/node-4-tests.ts | 17 +++++++++++++++++ node/node-4.d.ts | 7 ++++--- node/node-tests.ts | 17 +++++++++++++++++ node/node.d.ts | 7 ++++--- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/node/node-4-tests.ts b/node/node-4-tests.ts index 26e201c910..f21c3b58f8 100644 --- a/node/node-4-tests.ts +++ b/node/node-4-tests.ts @@ -24,6 +24,19 @@ import * as string_decoder from "string_decoder"; // Specifically test buffer module regression. import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer"; +////////////////////////////////////////////////////////// +/// Global Tests : https://nodejs.org/api/global.html /// +////////////////////////////////////////////////////////// +namespace global_tests { + { + let x: NodeModule; + let y: NodeModule; + x.children.push(y); + x.parent = require.main; + require.main = y; + } +} + ////////////////////////////////////////////////////////// /// Assert Tests : https://nodejs.org/api/assert.html /// ////////////////////////////////////////////////////////// @@ -922,6 +935,10 @@ namespace process_tests { var _p: NodeJS.Process = process; _p = p; } + { + var module: NodeModule; + module = process.mainModule; + } } /////////////////////////////////////////////////////////// diff --git a/node/node-4.d.ts b/node/node-4.d.ts index feee10f12d..bd6196d17c 100644 --- a/node/node-4.d.ts +++ b/node/node-4.d.ts @@ -52,7 +52,7 @@ interface NodeRequire extends NodeRequireFunction { resolve(id:string): string; cache: any; extensions: any; - main: any; + main: NodeModule; } declare var require: NodeRequire; @@ -63,8 +63,8 @@ interface NodeModule { id: string; filename: string; loaded: boolean; - parent: any; - children: any[]; + parent: NodeModule; + children: NodeModule[]; } declare var module: NodeModule; @@ -339,6 +339,7 @@ declare namespace NodeJS { title: string; arch: string; platform: string; + mainModule?: NodeModule; memoryUsage(): MemoryUsage; nextTick(callback: Function): void; umask(mask?: number): number; diff --git a/node/node-tests.ts b/node/node-tests.ts index b98b23ad69..0025505e67 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -27,6 +27,19 @@ import * as repl from "repl"; // Specifically test buffer module regression. import {Buffer as ImportedBuffer, SlowBuffer as ImportedSlowBuffer} from "buffer"; +////////////////////////////////////////////////////////// +/// Global Tests : https://nodejs.org/api/global.html /// +////////////////////////////////////////////////////////// +namespace global_tests { + { + let x: NodeModule; + let y: NodeModule; + x.children.push(y); + x.parent = require.main; + require.main = y; + } +} + ////////////////////////////////////////////////////////// /// Assert Tests : https://nodejs.org/api/assert.html /// ////////////////////////////////////////////////////////// @@ -1554,6 +1567,10 @@ namespace process_tests { { assert(process.argv[0] === process.argv0); } + { + var module: NodeModule; + module = process.mainModule; + } } /////////////////////////////////////////////////////////// diff --git a/node/node.d.ts b/node/node.d.ts index fe56ba851a..61132b9232 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -52,7 +52,7 @@ interface NodeRequire extends NodeRequireFunction { resolve(id: string): string; cache: any; extensions: any; - main: any; + main: NodeModule; } declare var require: NodeRequire; @@ -63,8 +63,8 @@ interface NodeModule { id: string; filename: string; loaded: boolean; - parent: any; - children: any[]; + parent: NodeModule; + children: NodeModule[]; } declare var module: NodeModule; @@ -372,6 +372,7 @@ declare namespace NodeJS { title: string; arch: string; platform: string; + mainModule?: NodeModule; memoryUsage(): MemoryUsage; nextTick(callback: Function, ...args: any[]): void; umask(mask?: number): number;