@arcticnotes/node-wsh 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/node/node-wsh.js +22 -3
- package/package.json +5 -2
- package/test/test.js +0 -20
package/lib/node/node-wsh.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import EventEmitter from 'node:events';
|
|
1
2
|
import PATH from 'node:path';
|
|
2
3
|
import { Syncline} from "@arcticnotes/syncline";
|
|
3
4
|
|
|
@@ -7,7 +8,7 @@ const SCRIPT_FILE = PATH.join( PATH.dirname( import.meta.dirname), 'wsh', 'host.
|
|
|
7
8
|
const PROXY = Symbol();
|
|
8
9
|
const TRACE_REF = 1;
|
|
9
10
|
|
|
10
|
-
export class WindowsScriptingHost {
|
|
11
|
+
export class WindowsScriptingHost extends EventEmitter {
|
|
11
12
|
|
|
12
13
|
static async connect( options = {}) {
|
|
13
14
|
const command = options.command || COMMAND;
|
|
@@ -24,15 +25,25 @@ export class WindowsScriptingHost {
|
|
|
24
25
|
#Enumerator;
|
|
25
26
|
|
|
26
27
|
constructor( syncline, options) {
|
|
28
|
+
super();
|
|
27
29
|
this.#syncline = syncline;
|
|
28
30
|
this.#syncline.on( 'stderr', line => console.log( 'wsh:', line));
|
|
29
31
|
this.#syncline.on( 'stdout', line => console.log( 'wsh:', line));
|
|
30
|
-
this.#proxies = new Proxies( syncline, options);
|
|
32
|
+
this.#proxies = new Proxies( syncline, options, this);
|
|
31
33
|
this.#WScript = this.#proxies.getOrCreateObject( 0);
|
|
32
34
|
this.#GetObject = this.#proxies.getOrCreateFunction( 1);
|
|
33
35
|
this.#Enumerator = this.#proxies.getOrCreateFunction( 2);
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
get remoteObjects() {
|
|
39
|
+
const proxies = this.#proxies;
|
|
40
|
+
return {
|
|
41
|
+
get count() {
|
|
42
|
+
return proxies.count;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
get WScript() {
|
|
37
48
|
return this.#WScript;
|
|
38
49
|
}
|
|
@@ -54,6 +65,7 @@ class Proxies {
|
|
|
54
65
|
|
|
55
66
|
#syncline;
|
|
56
67
|
#trace;
|
|
68
|
+
#eventEmitter;
|
|
57
69
|
#finalizer = new FinalizationRegistry( this.#finalized.bind( this));
|
|
58
70
|
#ref2proxy = new Map();
|
|
59
71
|
#proxy2ref = new Map();
|
|
@@ -110,9 +122,14 @@ class Proxies {
|
|
|
110
122
|
},
|
|
111
123
|
};
|
|
112
124
|
|
|
113
|
-
constructor( syncline, options) {
|
|
125
|
+
constructor( syncline, options, eventEmitter) {
|
|
114
126
|
this.#syncline = syncline;
|
|
115
127
|
this.#trace = options.trace;
|
|
128
|
+
this.#eventEmitter = eventEmitter;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
get count() {
|
|
132
|
+
return this.#ref2proxy.size;
|
|
116
133
|
}
|
|
117
134
|
|
|
118
135
|
getOrCreateObject( ref) {
|
|
@@ -134,6 +151,7 @@ class Proxies {
|
|
|
134
151
|
this.#ref2proxy.set( ref, newProxy);
|
|
135
152
|
this.#proxy2ref.set( newProxy, ref);
|
|
136
153
|
this.#finalizer.register( newProxy, ref);
|
|
154
|
+
this.#eventEmitter.emit( 'ref', ref, newProxy);
|
|
137
155
|
return newProxy;
|
|
138
156
|
}
|
|
139
157
|
|
|
@@ -150,6 +168,7 @@ class Proxies {
|
|
|
150
168
|
default:
|
|
151
169
|
console.log( `unknown response: ${ output[ 0]}`);
|
|
152
170
|
}
|
|
171
|
+
this.#eventEmitter.emit( 'unref', ref);
|
|
153
172
|
}
|
|
154
173
|
|
|
155
174
|
#encode( decoded) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcticnotes/node-wsh",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.8",
|
|
4
4
|
"description": "A Node.js package that runs Windows Scripting Host (WSH) as a child process and exposes the resources from the WSH world to the Node.js world",
|
|
5
5
|
"author": "Paul <paul@arcticnotes.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,5 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@arcticnotes/syncline": "0.0.3"
|
|
25
|
-
}
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"/lib/"
|
|
28
|
+
]
|
|
26
29
|
}
|
package/test/test.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import ASSERT from 'node:assert/strict';
|
|
2
|
-
import TEST from 'node:test';
|
|
3
|
-
import { WindowsScriptingHost} from '@arcticnotes/node-wsh';
|
|
4
|
-
|
|
5
|
-
TEST( 'smoke-test', async() => {
|
|
6
|
-
const wsh = await WindowsScriptingHost.connect();
|
|
7
|
-
try {
|
|
8
|
-
const { WScript, GetObject, Enumerator} = wsh;
|
|
9
|
-
console.log( WScript.Version);
|
|
10
|
-
ASSERT.equal( typeof WScript.Version, 'string');
|
|
11
|
-
const procs = GetObject( "winmgmts:\\\\.\\root\\cimv2").ExecQuery( 'SELECT ProcessId, Name FROM Win32_Process');
|
|
12
|
-
for( const enumerator = new Enumerator( procs); !enumerator.atEnd(); enumerator.moveNext()) {
|
|
13
|
-
console.log( `${ enumerator.item().ProcessId}: ${ enumerator.item().Name}`);
|
|
14
|
-
ASSERT.equal( typeof enumerator.item().ProcessId, 'number');
|
|
15
|
-
ASSERT.equal( typeof enumerator.item().Name, 'string');
|
|
16
|
-
}
|
|
17
|
-
} finally {
|
|
18
|
-
await wsh.disconnect();
|
|
19
|
-
}
|
|
20
|
-
});
|