@devscholar/node-ps1-dotnet 0.0.2 → 0.0.4
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/AGENTS.md +2 -0
- package/README.md +1 -1
- package/__tests__/basic.test.ts +0 -1
- package/__tests__/dotnet-console.test.ts +0 -1
- package/__tests__/dotnet-enums.test.ts +0 -1
- package/__tests__/dotnet-io.test.ts +0 -1
- package/__tests__/dotnet-misc.test.ts +0 -1
- package/__tests__/dotnet-runtime.test.ts +0 -1
- package/__tests__/dotnet-task.test.ts +0 -1
- package/__tests__/gui-events.test.ts +0 -1
- package/__tests__/ipc.test.ts +6 -7
- package/__tests__/winforms.test.ts +0 -1
- package/__tests__/wpf.test.ts +0 -1
- package/package.json +15 -14
- package/scripts/PsBridge/Reflection.cs +19 -0
- package/src/index.ts +15 -5
- package/src/namespace.ts +2 -2
- package/src/proxy.ts +1 -1
- package/src/state.ts +1 -1
- package/test-utils.ts +0 -2
- package/vitest.config.js +31 -0
- package/vitest.setup.js +1 -0
- package/jest.config.js +0 -31
- package/types/index.d.ts +0 -17
- package/types/ipc.d.ts +0 -17
- package/types/namespace.d.ts +0 -2
- package/types/proxy.d.ts +0 -16
- package/types/state.d.ts +0 -16
- package/types/types.d.ts +0 -21
- package/types/utils.d.ts +0 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
When using TypeScript in Node, you must run TS with the `--experimental-transform-types` flag; other methods like `tsx` are not allowed, and building and transpilation are not allowed, except Vite. The test framework should be Vitest, not Jest. ESM must be used instead of require.
|
|
2
|
+
allowImportingTsExtensions should be true in tsconfig.json. (If this file exists)
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
⚠️ This project is still in pre-alpha stage, and API is subject to change.
|
|
4
4
|
|
|
5
|
-
This is a project that mimics the [Node API for .NET](https://github.com/microsoft/node-api-dotnet), aiming to utilize the built-in PowerShell 5.1 in Windows to replace the full high-version .NET runtime, thereby reducing the program's size. Since this project uses IPC instead of C++ Addon, it is compatible not only with Node but also with Deno and Bun.
|
|
5
|
+
This is a project that mimics the [Node API for .NET](https://github.com/microsoft/node-api-dotnet), aiming to utilize the built-in PowerShell 5.1 in Windows to replace the full high-version .NET runtime, thereby reducing the program's size. Since this project uses IPC instead of C++ Addon, it is compatible not only with Node but also with Deno and Bun.
|
|
6
6
|
|
|
7
7
|
# Requirements
|
|
8
8
|
|
package/__tests__/basic.test.ts
CHANGED
package/__tests__/ipc.test.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { jest } from '@jest/globals';
|
|
2
1
|
|
|
3
2
|
describe('IpcSync', () => {
|
|
4
3
|
let IpcSync: any;
|
|
@@ -11,14 +10,14 @@ describe('IpcSync', () => {
|
|
|
11
10
|
|
|
12
11
|
beforeEach(() => {
|
|
13
12
|
mockFs = {
|
|
14
|
-
openSync:
|
|
15
|
-
readSync:
|
|
16
|
-
closeSync:
|
|
13
|
+
openSync: vi.fn(),
|
|
14
|
+
readSync: vi.fn(),
|
|
15
|
+
closeSync: vi.fn(),
|
|
17
16
|
};
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
it('should create an instance with pipe name and callback', () => {
|
|
21
|
-
const onEvent =
|
|
20
|
+
const onEvent = vi.fn();
|
|
22
21
|
const ipc = new IpcSync('test_pipe', onEvent);
|
|
23
22
|
|
|
24
23
|
expect(ipc).toBeDefined();
|
|
@@ -26,7 +25,7 @@ describe('IpcSync', () => {
|
|
|
26
25
|
});
|
|
27
26
|
|
|
28
27
|
it('should have connect, send, and close methods', () => {
|
|
29
|
-
const onEvent =
|
|
28
|
+
const onEvent = vi.fn();
|
|
30
29
|
const ipc = new IpcSync('test_pipe', onEvent);
|
|
31
30
|
|
|
32
31
|
expect(typeof ipc.connect).toBe('function');
|
|
@@ -35,7 +34,7 @@ describe('IpcSync', () => {
|
|
|
35
34
|
});
|
|
36
35
|
|
|
37
36
|
it('should throw error when connecting to nonexistent pipe', () => {
|
|
38
|
-
const onEvent =
|
|
37
|
+
const onEvent = vi.fn();
|
|
39
38
|
const ipc = new IpcSync('nonexistent_pipe_12345', onEvent);
|
|
40
39
|
|
|
41
40
|
expect(() => ipc.connect()).toThrow();
|
package/__tests__/wpf.test.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devscholar/node-ps1-dotnet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "Node.js to .NET interop via IPC",
|
|
5
|
-
"main": "./
|
|
5
|
+
"main": "./src/index.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
-
".": "./
|
|
8
|
+
".": "./src/index.ts"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"test": "
|
|
12
|
-
"test:watch": "
|
|
13
|
-
"test:coverage": "
|
|
11
|
+
"test": "vitest run",
|
|
12
|
+
"test:watch": "vitest",
|
|
13
|
+
"test:coverage": "vitest run --coverage",
|
|
14
14
|
"build": "tsc"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"dotnet",
|
|
18
18
|
"winforms",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
19
|
+
"wpf",
|
|
20
|
+
"webview2",
|
|
21
|
+
"netfx",
|
|
22
|
+
"deno",
|
|
23
|
+
"bun",
|
|
24
|
+
"gui"
|
|
22
25
|
],
|
|
23
26
|
"author": "",
|
|
24
|
-
"license": "
|
|
27
|
+
"license": "MIT",
|
|
25
28
|
"devDependencies": {
|
|
26
|
-
"@types/jest": "^30.0.0",
|
|
27
29
|
"@types/node": "^25.0.10",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"typescript": "^5.9.3"
|
|
30
|
+
"typescript": "^5.9.3",
|
|
31
|
+
"vitest": "^3.0.0"
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -647,6 +647,25 @@ public static class Reflection
|
|
|
647
647
|
return Protocol.ConvertToProtocol(asm);
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
if (action == "LoadFrom")
|
|
651
|
+
{
|
|
652
|
+
var filePath = cmd["filePath"].ToString();
|
|
653
|
+
if (!File.Exists(filePath))
|
|
654
|
+
{
|
|
655
|
+
throw new Exception("File not found: " + filePath);
|
|
656
|
+
}
|
|
657
|
+
Assembly asm = null;
|
|
658
|
+
try
|
|
659
|
+
{
|
|
660
|
+
asm = Assembly.LoadFrom(filePath);
|
|
661
|
+
}
|
|
662
|
+
catch (Exception ex)
|
|
663
|
+
{
|
|
664
|
+
throw new Exception("Failed to load assembly from file: " + ex.Message);
|
|
665
|
+
}
|
|
666
|
+
return Protocol.ConvertToProtocol(asm);
|
|
667
|
+
}
|
|
668
|
+
|
|
650
669
|
if (action == "Release")
|
|
651
670
|
{
|
|
652
671
|
Protocol.RemoveBridgeObject(cmd["targetId"].ToString());
|
package/src/index.ts
CHANGED
|
@@ -2,11 +2,11 @@ import * as fs from 'node:fs';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import * as cp from 'node:child_process';
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import { getPowerShellPath } from './utils.
|
|
6
|
-
import { IpcSync } from './ipc.
|
|
7
|
-
import { getIpc, setIpc, getProc, setProc, getInitialized, setInitialized, getCachedRuntimeInfo, setCachedRuntimeInfo } from './state.
|
|
8
|
-
import { callbackRegistry, createProxyWithInlineProps, createProxy, setNodePs1Dotnet } from './proxy.
|
|
9
|
-
import { createNamespaceProxy, createExportNamespaceProxy } from './namespace.
|
|
5
|
+
import { getPowerShellPath } from './utils.ts';
|
|
6
|
+
import { IpcSync } from './ipc.ts';
|
|
7
|
+
import { getIpc, setIpc, getProc, setProc, getInitialized, setInitialized, getCachedRuntimeInfo, setCachedRuntimeInfo } from './state.ts';
|
|
8
|
+
import { callbackRegistry, createProxyWithInlineProps, createProxy, setNodePs1Dotnet } from './proxy.ts';
|
|
9
|
+
import { createNamespaceProxy, createExportNamespaceProxy } from './namespace.ts';
|
|
10
10
|
|
|
11
11
|
export const __filename = fileURLToPath(import.meta.url);
|
|
12
12
|
export const __dirname = path.dirname(__filename);
|
|
@@ -136,6 +136,13 @@ export const node_ps1_dotnet = {
|
|
|
136
136
|
return createProxy(res);
|
|
137
137
|
},
|
|
138
138
|
|
|
139
|
+
_loadFrom(filePath: string): any {
|
|
140
|
+
doInitialize();
|
|
141
|
+
const ipc = getIpc();
|
|
142
|
+
const res = ipc!.send({ action: 'LoadFrom', filePath });
|
|
143
|
+
return createProxy(res);
|
|
144
|
+
},
|
|
145
|
+
|
|
139
146
|
_getRuntimeInfo(): { frameworkMoniker: string; runtimeVersion: string } {
|
|
140
147
|
if (getCachedRuntimeInfo()) return getCachedRuntimeInfo()!;
|
|
141
148
|
doInitialize();
|
|
@@ -159,6 +166,9 @@ const dotnetProxy = new Proxy(function() {} as any, {
|
|
|
159
166
|
if (prop === 'load') return (assemblyNameOrFilePath: string) => {
|
|
160
167
|
node_ps1_dotnet._loadAssembly(assemblyNameOrFilePath);
|
|
161
168
|
};
|
|
169
|
+
if (prop === 'loadFrom') return (filePath: string) => {
|
|
170
|
+
node_ps1_dotnet._loadFrom(filePath);
|
|
171
|
+
};
|
|
162
172
|
if (prop === 'frameworkMoniker') {
|
|
163
173
|
return node_ps1_dotnet._getRuntimeInfo().frameworkMoniker;
|
|
164
174
|
}
|
package/src/namespace.ts
CHANGED
package/src/proxy.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getIpc, setIpc, getProc, setProc, getInitialized, setInitialized, getCachedRuntimeInfo, setCachedRuntimeInfo } from './state.
|
|
1
|
+
import { getIpc, setIpc, getProc, setProc, getInitialized, setInitialized, getCachedRuntimeInfo, setCachedRuntimeInfo } from './state.ts';
|
|
2
2
|
|
|
3
3
|
export let node_ps1_dotnetGetter: (() => any) | null = null;
|
|
4
4
|
|
package/src/state.ts
CHANGED
package/test-utils.ts
CHANGED
package/vitest.config.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config';
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
test: {
|
|
5
|
+
globals: true,
|
|
6
|
+
environment: 'node',
|
|
7
|
+
setupFiles: ['./vitest.setup.js'],
|
|
8
|
+
onUnhandledError: (unhandledErr, afterNext) => {
|
|
9
|
+
if (unhandledErr.message?.includes('process.exit unexpectedly called')) {
|
|
10
|
+
afterNext();
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
console.error('Unhandled error:', unhandledErr);
|
|
14
|
+
},
|
|
15
|
+
include: [
|
|
16
|
+
'__tests__/**/*.ts',
|
|
17
|
+
'**/?(*.)+(spec|test).ts',
|
|
18
|
+
],
|
|
19
|
+
exclude: [
|
|
20
|
+
'**/node_modules/**',
|
|
21
|
+
'**/dist/**',
|
|
22
|
+
],
|
|
23
|
+
coverage: {
|
|
24
|
+
provider: 'v8',
|
|
25
|
+
reporter: ['text', 'lcov', 'html'],
|
|
26
|
+
include: ['src/**/*.ts'],
|
|
27
|
+
exclude: ['src/**/*.d.ts'],
|
|
28
|
+
},
|
|
29
|
+
testTimeout: 30000,
|
|
30
|
+
},
|
|
31
|
+
});
|
package/vitest.setup.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
process.exit = () => {};
|
package/jest.config.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
preset: 'ts-jest/presets/default-esm',
|
|
3
|
-
testEnvironment: 'node',
|
|
4
|
-
extensionsToTreatAsEsm: ['.ts'],
|
|
5
|
-
moduleNameMapper: {
|
|
6
|
-
'^(\\.{1,2}/.*)\\.js$': '$1',
|
|
7
|
-
},
|
|
8
|
-
transform: {
|
|
9
|
-
'^.+\\.ts$': [
|
|
10
|
-
'ts-jest',
|
|
11
|
-
{
|
|
12
|
-
useESM: true,
|
|
13
|
-
tsconfig: {
|
|
14
|
-
module: 'ESNext',
|
|
15
|
-
moduleResolution: 'bundler',
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
},
|
|
20
|
-
testMatch: [
|
|
21
|
-
'**/__tests__/**/*.ts',
|
|
22
|
-
'**/?(*.)+(spec|test).ts',
|
|
23
|
-
],
|
|
24
|
-
collectCoverageFrom: [
|
|
25
|
-
'src/**/*.ts',
|
|
26
|
-
'!src/**/*.d.ts',
|
|
27
|
-
],
|
|
28
|
-
coverageDirectory: 'coverage',
|
|
29
|
-
coverageReporters: ['text', 'lcov', 'html'],
|
|
30
|
-
testTimeout: 30000,
|
|
31
|
-
};
|
package/types/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export declare const __filename: string;
|
|
2
|
-
export declare const __dirname: string;
|
|
3
|
-
export declare const node_ps1_dotnet: {
|
|
4
|
-
_load(typeName: string): any;
|
|
5
|
-
_release(id: string): void;
|
|
6
|
-
_close(): void;
|
|
7
|
-
_getAssembly(assemblyName: string): any;
|
|
8
|
-
_loadAssembly(assemblyName: string): any;
|
|
9
|
-
_getRuntimeInfo(): {
|
|
10
|
-
frameworkMoniker: string;
|
|
11
|
-
runtimeVersion: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
declare const dotnetProxy: any;
|
|
15
|
-
export default dotnetProxy;
|
|
16
|
-
export declare function getSystem(): any;
|
|
17
|
-
export declare const System: any;
|
package/types/ipc.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ProtocolResponse, CommandRequest } from './types.ts';
|
|
2
|
-
export declare class IpcSync {
|
|
3
|
-
private pipeName;
|
|
4
|
-
private onEvent;
|
|
5
|
-
fd: number;
|
|
6
|
-
private exited;
|
|
7
|
-
private readBuffer;
|
|
8
|
-
private resultBuffer;
|
|
9
|
-
private bufferOffset;
|
|
10
|
-
private bufferLength;
|
|
11
|
-
constructor(pipeName: string, onEvent: (msg: ProtocolResponse) => any);
|
|
12
|
-
private readLineSync;
|
|
13
|
-
private tryConnect;
|
|
14
|
-
connect(): void;
|
|
15
|
-
send(cmd: CommandRequest): ProtocolResponse;
|
|
16
|
-
close(): void;
|
|
17
|
-
}
|
package/types/namespace.d.ts
DELETED
package/types/proxy.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare let node_ps1_dotnetGetter: (() => any) | null;
|
|
2
|
-
export declare function setNodePs1Dotnet(fn: () => any): void;
|
|
3
|
-
export declare function getNodePs1Dotnet(): any;
|
|
4
|
-
export declare const callbackRegistry: Map<string, Function>;
|
|
5
|
-
export declare const typeMetadataCache: Map<string, Map<string, string>>;
|
|
6
|
-
export declare const globalTypeCache: Map<string, Map<string, string>>;
|
|
7
|
-
export declare const pendingInspectRequests: Map<string, string[]>;
|
|
8
|
-
export declare const pendingInspectTimeout: Map<string, NodeJS.Timeout>;
|
|
9
|
-
export declare const typeNameCache: Map<string, string>;
|
|
10
|
-
export declare const LARGE_ARRAY_THRESHOLD = 50;
|
|
11
|
-
export declare function getObjectTypeName(id: string): string | null;
|
|
12
|
-
export declare function getTypeMembers(typeName: string, memberNames: string[]): Map<string, string> | null;
|
|
13
|
-
export declare function ensureMemberTypeCached(id: string, memberName: string, memberCache: Map<string, string>): void;
|
|
14
|
-
export declare function createLazyArray(arr: any[]): any;
|
|
15
|
-
export declare function createProxyWithInlineProps(meta: any): any;
|
|
16
|
-
export declare function createProxy(meta: any): any;
|
package/types/state.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { IpcSync } from './ipc.js';
|
|
2
|
-
import * as cp from 'node:child_process';
|
|
3
|
-
export declare function getIpc(): IpcSync;
|
|
4
|
-
export declare function getProc(): cp.ChildProcess;
|
|
5
|
-
export declare function getInitialized(): boolean;
|
|
6
|
-
export declare function getCachedRuntimeInfo(): {
|
|
7
|
-
frameworkMoniker: string;
|
|
8
|
-
runtimeVersion: string;
|
|
9
|
-
};
|
|
10
|
-
export declare function setIpc(val: IpcSync | null): void;
|
|
11
|
-
export declare function setProc(val: cp.ChildProcess | null): void;
|
|
12
|
-
export declare function setInitialized(val: boolean): void;
|
|
13
|
-
export declare function setCachedRuntimeInfo(val: {
|
|
14
|
-
frameworkMoniker: string;
|
|
15
|
-
runtimeVersion: string;
|
|
16
|
-
} | null): void;
|
package/types/types.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export interface ProtocolResponse {
|
|
2
|
-
type: string;
|
|
3
|
-
value?: any;
|
|
4
|
-
id?: string;
|
|
5
|
-
message?: string;
|
|
6
|
-
args?: any[];
|
|
7
|
-
callbackId?: string;
|
|
8
|
-
memberType?: 'property' | 'method';
|
|
9
|
-
assemblyName?: string;
|
|
10
|
-
assemblyVersion?: string;
|
|
11
|
-
frameworkMoniker?: string;
|
|
12
|
-
runtimeVersion?: string;
|
|
13
|
-
resolvedPath?: string;
|
|
14
|
-
props?: Record<string, any>;
|
|
15
|
-
typeName?: string;
|
|
16
|
-
members?: Record<string, string>;
|
|
17
|
-
}
|
|
18
|
-
export interface CommandRequest {
|
|
19
|
-
action: string;
|
|
20
|
-
[key: string]: any;
|
|
21
|
-
}
|
package/types/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getPowerShellPath(): string;
|