Skip to content

Commit 6024312

Browse files
authored
Merge pull request #274 from implausible/webpack/remove-dynamic-imports
Remove dynamic loading method `loadNative`
2 parents 3f5151d + e7ed10a commit 6024312

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

Diff for: src/conpty_console_list_agent.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
* single console attached to a process.
77
*/
88

9-
import { loadNative } from './utils';
9+
let getConsoleProcessList: any;
10+
try {
11+
getConsoleProcessList = require('../build/Release/conpty_console_list.node').getConsoleProcessList;
12+
} catch (err) {
13+
getConsoleProcessList = require('../build/Debug/conpty_console_list.node').getConsoleProcessList;
14+
}
1015

11-
const getConsoleProcessList = loadNative('conpty_console_list').getConsoleProcessList;
1216
const shellPid = parseInt(process.argv[2], 10);
1317
const consoleProcessList = getConsoleProcessList(shellPid);
1418
process.send({ consoleProcessList });

Diff for: src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ export function open(options: IPtyOpenOptions): ITerminal {
5050
* Expose the native API when not Windows, note that this is not public API and
5151
* could be removed at any time.
5252
*/
53-
export const native = (process.platform !== 'win32' ? require(path.join('..', 'build', 'Release', 'pty.node')) : null);
53+
export const native = (process.platform !== 'win32' ? require('../build/Release/pty.node') : null);

Diff for: src/unixTerminal.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ import * as net from 'net';
88
import { Terminal, DEFAULT_COLS, DEFAULT_ROWS } from './terminal';
99
import { IProcessEnv, IPtyForkOptions, IPtyOpenOptions } from './interfaces';
1010
import { ArgvOrCommandLine } from './types';
11-
import { assign, loadNative } from './utils';
11+
import { assign } from './utils';
1212

13-
const pty: IUnixNative = loadNative('pty');
13+
let pty: IUnixNative;
14+
try {
15+
pty = require('../build/Release/pty.node');
16+
} catch {
17+
pty = require('../build/Debug/pty.node');
18+
}
1419

1520
const DEFAULT_FILE = 'sh';
1621
const DEFAULT_NAME = 'xterm';

Diff for: src/utils.ts

-8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,3 @@ export function assign(target: any, ...sources: any[]): any {
99
sources.forEach(source => Object.keys(source).forEach(key => target[key] = source[key]));
1010
return target;
1111
}
12-
13-
export function loadNative(moduleName: string): any {
14-
try {
15-
return require(path.join('..', 'build', 'Release', `${moduleName}.node`));
16-
} catch {
17-
return require(path.join('..', 'build', 'Debug', `${moduleName}.node`));
18-
}
19-
}

Diff for: src/windowsPtyAgent.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as os from 'os';
88
import * as path from 'path';
99
import { Socket } from 'net';
1010
import { ArgvOrCommandLine } from './types';
11-
import { loadNative } from './utils';
1211
import { fork } from 'child_process';
1312

1413
let conptyNative: IConptyNative;
@@ -59,11 +58,19 @@ export class WindowsPtyAgent {
5958
}
6059
if (this._useConpty) {
6160
if (!conptyNative) {
62-
conptyNative = loadNative('conpty');
61+
try {
62+
conptyNative = require('../build/Release/conpty.node');
63+
} catch (err) {
64+
conptyNative = require('../build/Debug/conpty.node');
65+
}
6366
}
6467
} else {
6568
if (!winptyNative) {
66-
winptyNative = loadNative('pty');
69+
try {
70+
winptyNative = require('../build/Release/pty.node');
71+
} catch (err) {
72+
winptyNative = require('../build/Debug/pty.node');
73+
}
6774
}
6875
}
6976
this._ptyNative = this._useConpty ? conptyNative : winptyNative;

0 commit comments

Comments
 (0)