From f564e36bbe1f00bf056db49348dd25f25dd71052 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Mon, 30 Dec 2019 16:01:53 -0800 Subject: [PATCH] Update for node v13 Refer to EventEmitter as events.EventEmitter instead of NodeJS.EventEmitter --- base/base_footer.ts | 16 ++++++++++------ base/base_header.ts | 3 +++ src/index.ts | 15 +++++++-------- src/module-declaration.ts | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/base/base_footer.ts b/base/base_footer.ts index 07a3fc7..8f1ec45 100644 --- a/base/base_footer.ts +++ b/base/base_footer.ts @@ -1,6 +1,3 @@ -declare module 'electron' { - export = Electron; -} interface NodeRequireFunction { (moduleName: 'electron'): typeof Electron; @@ -13,11 +10,18 @@ interface File { path: string; } +interface Document { + createElement(tagName: 'webview'): Electron.WebviewTag; +} + +} + +declare module 'electron' { + export = Electron; +} + declare module 'original-fs' { import * as fs from 'fs'; export = fs; } -interface Document { - createElement(tagName: 'webview'): Electron.WebviewTag; -} \ No newline at end of file diff --git a/base/base_header.ts b/base/base_header.ts index 4426007..a41d446 100644 --- a/base/base_header.ts +++ b/base/base_header.ts @@ -4,5 +4,8 @@ // Definitions: https://github.com/electron/electron-typescript-definitions /// +import events = require('events'); type GlobalEvent = Event; + +declare global { diff --git a/src/index.ts b/src/index.ts index 992c70c..9f9cd1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import { ParsedDocumentationResult } from '@electron/docs-parser'; import { DynamicParamInterfaces } from './dynamic-param-interfaces'; // takes the predefined header and footer and wraps them around the generated files -const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string) => { +const wrapWithHeaderAndFooter = (outputLines: string[], nodeJSOverride: string[], electronVersion: string) => { const newOutputLines: string[] = []; utils.extendArray( newOutputLines, @@ -19,7 +19,7 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string) .split(/\r?\n/), ); - newOutputLines.push('declare namespace Electron {'); + newOutputLines.push('namespace Electron {'); utils.extendArray( newOutputLines, fs @@ -30,6 +30,7 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string) outputLines.slice(1).forEach(l => newOutputLines.push(`${_.trimEnd(` ${l}`)}`)); utils.extendArray(newOutputLines, ['}', '']); + utils.extendArray(newOutputLines, nodeJSOverride); utils.extendArray( newOutputLines, @@ -41,8 +42,8 @@ const wrapWithHeaderAndFooter = (outputLines: string[], electronVersion: string) return newOutputLines; }; -const appendNodeJSOverride = (outputLines: string[]) => { - utils.extendArray(outputLines, ['', 'declare namespace NodeJS {']); +const createNodeJSOverride = () => { + let outputLines = ['', 'namespace NodeJS {', ' interface ReadableStream {}']; const processAPI = getModuleDeclarations().Process; processAPI.push('}'); @@ -61,7 +62,7 @@ const appendNodeJSOverride = (outputLines: string[]) => { utils.extendArray(outputLines, ['}']); - return outputLines.join('\n'); + return outputLines; }; interface GenerateOptions { @@ -102,7 +103,5 @@ export async function generateDefinitions({ electronApi: API }: GenerateOptions) DynamicParamInterfaces.flushParamInterfaces(API, addToOutput); - const electronOutput = wrapWithHeaderAndFooter(outputLines, API[0].version); - - return appendNodeJSOverride(electronOutput); + return wrapWithHeaderAndFooter(outputLines, createNodeJSOverride(), API[0].version).join('\n'); } diff --git a/src/module-declaration.ts b/src/module-declaration.ts index 0ca5ab3..462b998 100644 --- a/src/module-declaration.ts +++ b/src/module-declaration.ts @@ -44,7 +44,7 @@ export const generateModuleDeclaration = ( `${isClass ? 'class' : 'interface'} ${_.upperFirst( module.name, )} extends ${module.extends || - (module.name === 'remote' ? 'MainInterface' : 'NodeJS.EventEmitter')} {`, + (module.name === 'remote' ? 'MainInterface' : 'events.EventEmitter')} {`, ); moduleAPI.push('', `// Docs: ${module.websiteUrl}`, ''); } else {