jopi-node-space 0.0.7 → 0.0.14
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/README.md +14 -14
- package/dist/__global.d.ts +83 -4
- package/dist/_app.js +10 -8
- package/dist/_app.js.map +1 -1
- package/dist/_compress_s.d.ts +1 -0
- package/dist/_compress_s.js +17 -0
- package/dist/_compress_s.js.map +1 -0
- package/dist/_crypto_s.d.ts +1 -0
- package/dist/_crypto_s.js +19 -0
- package/dist/_crypto_s.js.map +1 -0
- package/dist/_fs_s.js +100 -15
- package/dist/_fs_s.js.map +1 -1
- package/dist/_os_s.d.ts +1 -0
- package/dist/_os_s.js +43 -0
- package/dist/_os_s.js.map +1 -0
- package/dist/_process.js +1 -1
- package/dist/_process_s.js +4 -2
- package/dist/_process_s.js.map +1 -1
- package/dist/_stream_s.d.ts +1 -0
- package/dist/_stream_s.js +28 -0
- package/dist/_stream_s.js.map +1 -0
- package/dist/_term.js +12 -5
- package/dist/_term.js.map +1 -1
- package/dist/_thread_s.d.ts +1 -1
- package/dist/_thread_s.js +5 -4
- package/dist/_thread_s.js.map +1 -1
- package/dist/_timer.js +56 -1
- package/dist/_timer.js.map +1 -1
- package/dist/_webSocket.d.ts +1 -0
- package/dist/_webSocket.js +24 -0
- package/dist/_webSocket.js.map +1 -0
- package/dist/_webSocket_s.d.ts +1 -0
- package/dist/_webSocket_s.js +25 -0
- package/dist/_webSocket_s.js.map +1 -0
- package/dist/common.d.ts +1 -1
- package/dist/common.js +13 -5
- package/dist/common.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -35
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +7 -0
- package/dist/internal.js.map +1 -1
- package/dist/jopi-node-space-browser.js +39 -0
- package/dist/jopi-node-space-browser.js.map +1 -0
- package/dist/jopi-node-space-server.d.ts +1 -0
- package/dist/jopi-node-space-server.js +34 -0
- package/dist/jopi-node-space-server.js.map +1 -0
- package/package.json +23 -15
- package/src/__global.ts +111 -4
- package/src/_app.ts +14 -9
- package/src/_compress_s.ts +20 -0
- package/src/_crypto_s.ts +23 -0
- package/src/_fs_s.ts +100 -18
- package/src/_os_s.ts +46 -0
- package/src/_process.ts +1 -1
- package/src/_process_s.ts +7 -2
- package/src/_stream_s.ts +38 -0
- package/src/_term.ts +16 -5
- package/src/_thread_s.ts +7 -4
- package/src/_timer.ts +76 -7
- package/src/_webSocket.ts +28 -0
- package/src/_webSocket_s.ts +26 -0
- package/src/common.ts +16 -6
- package/src/index.ts +5 -34
- package/src/internal.ts +8 -0
- package/src/jopi-node-space-browser.ts +43 -0
- package/src/jopi-node-space-server.ts +40 -0
- package/bun.lock +0 -35
- package/dist/browser.d.ts +0 -1
- package/dist/browser.js +0 -29
- package/dist/browser.js.map +0 -1
- package/dist/serverSide.js +0 -9
- package/dist/serverSide.js.map +0 -1
- package/src/browser.ts +0 -30
- package/src/serverSide.ts +0 -10
- package/tsconfig.json +0 -33
- /package/dist/{serverSide.d.ts → jopi-node-space-browser.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -2,23 +2,23 @@
|
|
|
2
2
|
|
|
3
3
|
### Server Side or Browser Side
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The primary role of Jopi NodeSpace is to enable the creation of libraries whose source code is the same for both server and browser.
|
|
6
6
|
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* It automatically detects whether we are on the server side or browser side.
|
|
8
|
+
* It helps bridge certain gaps between server/browser functionality, particularly regarding WebWorkers.
|
|
9
|
+
* It provides unified access to environment variables, whether on browser or server (process.env).
|
|
10
|
+
* It allows access to server functionality without having to add dependencies.
|
|
11
11
|
|
|
12
|
-
> NodeSpace
|
|
13
|
-
>
|
|
14
|
-
|
|
12
|
+
> NodeSpace includes file access functionalities and various server elements.
|
|
13
|
+
> These only work when we are on the server side, however, they eliminate the need for *imports*
|
|
14
|
+
which are incompatible with bundlers (e.g., ViteJS).
|
|
15
15
|
|
|
16
16
|
### Packed with common tools
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
The second objective of Jopi NodeSpace is to provide common tools for both Node.js and Bun.js, acting as a compatibility layer.
|
|
19
19
|
|
|
20
|
-
*
|
|
21
|
-
* Hot-Reload:
|
|
22
|
-
*
|
|
23
|
-
* Logs:
|
|
24
|
-
* User:
|
|
20
|
+
* Application lifecycle: ability to attach listeners to be notified when the application exits.
|
|
21
|
+
* Hot-Reload: detection and management of hot-reload (a bun.js feature).
|
|
22
|
+
* Extension points: allows creating an extensible application.
|
|
23
|
+
* Logs: includes logging functionalities (based on jopi-logs).
|
|
24
|
+
* User: includes functionalities to obtain information about the current user (app side).
|
package/dist/__global.d.ts
CHANGED
|
@@ -10,14 +10,47 @@ export interface NodeSpaceType {
|
|
|
10
10
|
what: WhatInfos;
|
|
11
11
|
thread: ThreadImpl;
|
|
12
12
|
process: ProcessImpl;
|
|
13
|
+
os: OsImpl;
|
|
13
14
|
timer: TimerImpl;
|
|
14
15
|
app: AppImpl;
|
|
15
16
|
extensionPoints: ExtensionPointImpl;
|
|
16
17
|
term: TerminalImpl;
|
|
18
|
+
webSocket: WebSocketImpl;
|
|
17
19
|
fs: FileSystemImpl;
|
|
20
|
+
crypto: CryptoImpl;
|
|
21
|
+
compress: CompressImpl;
|
|
22
|
+
stream: StreamImpl;
|
|
18
23
|
applyDefaults<T>(source: T | undefined, defaults: T): T;
|
|
19
24
|
getErrorMessage(e: unknown): string;
|
|
20
25
|
}
|
|
26
|
+
export interface WebSocketImpl {
|
|
27
|
+
/**
|
|
28
|
+
* Open a connection to a server.
|
|
29
|
+
* The url must be of the type "ws://host-name:optionalPort/optionalPath".
|
|
30
|
+
* Ex: "ws://127.0.0.1:3000/my-end-point".
|
|
31
|
+
*/
|
|
32
|
+
openConnection(wsUrl: string, protocol?: string | string[]): Promise<WebSocket>;
|
|
33
|
+
/**
|
|
34
|
+
* Is called when the socket is closed.
|
|
35
|
+
*/
|
|
36
|
+
sendMessage(socket: WebSocket, msg: string | Buffer | Uint8Array | ArrayBuffer): void;
|
|
37
|
+
/**
|
|
38
|
+
* Send a text message through this webSocket.
|
|
39
|
+
*/
|
|
40
|
+
onMessage(socket: WebSocket, listener: ((msg: string | Buffer) => void)): void;
|
|
41
|
+
/**
|
|
42
|
+
* Add a listener which is called when the socket receives a message.
|
|
43
|
+
*/
|
|
44
|
+
onClosed(socket: WebSocket, listener: () => void): void;
|
|
45
|
+
/**
|
|
46
|
+
* Add a listener which is called when an error occurs.
|
|
47
|
+
*/
|
|
48
|
+
onError(socket: WebSocket, listener: () => void): void;
|
|
49
|
+
}
|
|
50
|
+
export interface CompressImpl {
|
|
51
|
+
gunzipSync(data: Uint8Array | string): Uint8Array;
|
|
52
|
+
gzipSync(data: Uint8Array | string): Uint8Array;
|
|
53
|
+
}
|
|
21
54
|
export interface HotReloadType {
|
|
22
55
|
onHotReload: Listener[];
|
|
23
56
|
memory: {
|
|
@@ -46,6 +79,10 @@ export interface ProcessImpl {
|
|
|
46
79
|
};
|
|
47
80
|
isProduction: boolean;
|
|
48
81
|
}
|
|
82
|
+
export interface OsImpl {
|
|
83
|
+
exec(command: string): Promise<void>;
|
|
84
|
+
which(toolName: string): Promise<string | null>;
|
|
85
|
+
}
|
|
49
86
|
export type TimerCallback = () => void | boolean | Promise<void | boolean>;
|
|
50
87
|
export interface TimerImpl {
|
|
51
88
|
ONE_SECOND: number;
|
|
@@ -55,6 +92,7 @@ export interface TimerImpl {
|
|
|
55
92
|
tick: (delayMs: number) => Promise<void>;
|
|
56
93
|
newInterval: (durationInMs: number, callback: TimerCallback) => void;
|
|
57
94
|
deferred: (callback: () => void) => void;
|
|
95
|
+
chrono(mustSaveMeasures: boolean): Chrono;
|
|
58
96
|
}
|
|
59
97
|
export interface FileState {
|
|
60
98
|
size: number;
|
|
@@ -65,17 +103,30 @@ export interface FileState {
|
|
|
65
103
|
isFile: () => boolean;
|
|
66
104
|
isSymbolicLink: () => boolean;
|
|
67
105
|
}
|
|
106
|
+
export interface StreamImpl {
|
|
107
|
+
teeResponse(response: Response): Promise<[ReadableStream, Response]>;
|
|
108
|
+
}
|
|
68
109
|
export interface FileSystemImpl {
|
|
69
|
-
mkDir: (dirPath: string) => Promise<
|
|
110
|
+
mkDir: (dirPath: string) => Promise<void>;
|
|
111
|
+
rmDir: (dirPath: string) => Promise<void>;
|
|
70
112
|
fileURLToPath: (url: string) => string;
|
|
71
113
|
pathToFileURL: (fsPath: string) => URL;
|
|
72
114
|
getMimeTypeFromName: (fileName: string) => string;
|
|
73
115
|
getFileSize: (filePath: string) => Promise<number>;
|
|
74
|
-
getFileStat: (filePath: string) => Promise<FileState>;
|
|
75
|
-
writeResponseToFile: (response: Response, filePath: string) => Promise<void>;
|
|
116
|
+
getFileStat: (filePath: string) => Promise<FileState | undefined>;
|
|
117
|
+
writeResponseToFile: (response: Response, filePath: string, createDir?: boolean) => Promise<void>;
|
|
76
118
|
createResponseFromFile: (filePath: string, status?: number, headers?: {
|
|
77
119
|
[key: string]: string;
|
|
78
120
|
} | Headers) => Response;
|
|
121
|
+
unlink(filePath: string): Promise<void>;
|
|
122
|
+
writeTextToFile(filePath: string, text: string, createDir?: boolean): Promise<void>;
|
|
123
|
+
readTextFromFile(filePath: string): Promise<string>;
|
|
124
|
+
readTextSyncFromFile(filePath: string): string;
|
|
125
|
+
isFile(filePath: string): Promise<boolean>;
|
|
126
|
+
isDirectory(dirPath: string): Promise<boolean>;
|
|
127
|
+
readFileToBytes(filePath: string): Promise<Uint8Array>;
|
|
128
|
+
nodeStreamToWebStream(nodeStream: NodeJS.ReadableStream): ReadableStream;
|
|
129
|
+
webStreamToNodeStream(webStream: ReadableStream): NodeJS.ReadableStream;
|
|
79
130
|
}
|
|
80
131
|
export interface AppImpl {
|
|
81
132
|
onServerSideReady(listener: Listener): void;
|
|
@@ -117,7 +168,7 @@ export interface TerminalImpl {
|
|
|
117
168
|
/**
|
|
118
169
|
* Build a console.log function that uses the colors provided in params.
|
|
119
170
|
*/
|
|
120
|
-
buildLogger: (...colors: string[]) =>
|
|
171
|
+
buildLogger: (...colors: string[]) => TermLogger;
|
|
121
172
|
/**
|
|
122
173
|
* Build a console.log function that uses the colors provided in params.
|
|
123
174
|
*/
|
|
@@ -130,6 +181,12 @@ export interface TerminalImpl {
|
|
|
130
181
|
* Write a temporary message, which are replaced each time by the next temp message.
|
|
131
182
|
*/
|
|
132
183
|
consoleLogTemp: (isTemp: boolean, ...args: unknown[]) => void;
|
|
184
|
+
logRed: TermLogger;
|
|
185
|
+
logBgRed: TermLogger;
|
|
186
|
+
logGreen: TermLogger;
|
|
187
|
+
logBgGreen: TermLogger;
|
|
188
|
+
logBlue: TermLogger;
|
|
189
|
+
logBgBlue: TermLogger;
|
|
133
190
|
T_RESET: string;
|
|
134
191
|
T_BOLD: string;
|
|
135
192
|
T_UNDERLINE: string;
|
|
@@ -153,3 +210,25 @@ export interface TerminalImpl {
|
|
|
153
210
|
B_CYAN: string;
|
|
154
211
|
B_WHITE: string;
|
|
155
212
|
}
|
|
213
|
+
export interface CryptoImpl {
|
|
214
|
+
fastHash(text: string): string;
|
|
215
|
+
md5(text: string): string;
|
|
216
|
+
}
|
|
217
|
+
export type TermLogger = (...args: any[]) => void;
|
|
218
|
+
export interface Chrono {
|
|
219
|
+
lastMeasure?: ChronoMeasure;
|
|
220
|
+
allMeasures: ChronoMeasure[];
|
|
221
|
+
start(label: string, printTitle?: string): void;
|
|
222
|
+
start_withLimit(limit_ms: number, label: string, printTitle?: string): void;
|
|
223
|
+
end(): void;
|
|
224
|
+
onMeasureDone(handler: null | ((measure: ChronoMeasure) => void)): void;
|
|
225
|
+
}
|
|
226
|
+
export interface ChronoMeasure {
|
|
227
|
+
label?: string;
|
|
228
|
+
title?: string;
|
|
229
|
+
logIfMoreThan_ms?: number;
|
|
230
|
+
startTime_ms: number;
|
|
231
|
+
endTime_ms: number;
|
|
232
|
+
elapsedTime_ms: number;
|
|
233
|
+
elapsedTime_sec: string;
|
|
234
|
+
}
|
package/dist/_app.js
CHANGED
|
@@ -7,7 +7,7 @@ export function init_nodeSpaceApp() {
|
|
|
7
7
|
const onAppStart = [];
|
|
8
8
|
let isServerSideReady = !(isNodeJs() || isBunJs());
|
|
9
9
|
let isHotReload = globalThis.jopiHotReload !== undefined;
|
|
10
|
-
let
|
|
10
|
+
let gIsAppStarted = false;
|
|
11
11
|
if (isHotReload) {
|
|
12
12
|
execListeners(globalThis.jopiHotReload.onHotReload).then();
|
|
13
13
|
}
|
|
@@ -39,33 +39,36 @@ export function init_nodeSpaceApp() {
|
|
|
39
39
|
await execListeners(onServerSideReady);
|
|
40
40
|
},
|
|
41
41
|
onAppStart: (listener) => {
|
|
42
|
-
if (
|
|
42
|
+
if (gIsAppStarted)
|
|
43
43
|
listener();
|
|
44
44
|
else
|
|
45
45
|
onAppStart.push(listener);
|
|
46
46
|
},
|
|
47
47
|
onAppExiting: (listener) => {
|
|
48
|
-
if (
|
|
48
|
+
if (gIsExited)
|
|
49
49
|
listener();
|
|
50
50
|
else
|
|
51
51
|
onAppExiting.push(listener);
|
|
52
52
|
},
|
|
53
53
|
onAppExited: (listener) => {
|
|
54
|
-
if (
|
|
54
|
+
if (gIsExited)
|
|
55
55
|
listener();
|
|
56
56
|
else
|
|
57
57
|
onAppExited.push(listener);
|
|
58
58
|
},
|
|
59
59
|
declareAppStarted: async () => {
|
|
60
|
-
|
|
60
|
+
gIsAppStarted = true;
|
|
61
61
|
await execListeners(onAppStart);
|
|
62
62
|
},
|
|
63
63
|
declareAppExiting: async () => {
|
|
64
|
+
if (gIsExited)
|
|
65
|
+
return;
|
|
66
|
+
gIsExited = true;
|
|
64
67
|
if (isUsingWorker()) {
|
|
65
68
|
// Wait 1 sec, which allows the worker to correctly initialize.
|
|
66
69
|
await NodeSpace.timer.tick(1000);
|
|
67
70
|
}
|
|
68
|
-
|
|
71
|
+
gIsAppStarted = false;
|
|
69
72
|
await execListeners(onAppExiting);
|
|
70
73
|
if (isUsingWorker()) {
|
|
71
74
|
// Allows to worker to correctly stop their activity.
|
|
@@ -75,8 +78,6 @@ export function init_nodeSpaceApp() {
|
|
|
75
78
|
// Allows to worker to correctly stop their activity.
|
|
76
79
|
await NodeSpace.timer.tick(50);
|
|
77
80
|
}
|
|
78
|
-
if (onAppExited.length)
|
|
79
|
-
debugger;
|
|
80
81
|
await execListeners(onAppExited);
|
|
81
82
|
},
|
|
82
83
|
executeApp: async (app) => {
|
|
@@ -105,4 +106,5 @@ export function init_nodeSpaceApp() {
|
|
|
105
106
|
}
|
|
106
107
|
};
|
|
107
108
|
}
|
|
109
|
+
let gIsExited = false;
|
|
108
110
|
//# sourceMappingURL=_app.js.map
|
package/dist/_app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_app.js","sourceRoot":"","sources":["../src/_app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAG5C,MAAM,UAAU,iBAAiB;IAC7B,MAAM,iBAAiB,GAAe,EAAE,CAAC;IACzC,MAAM,YAAY,GAAe,EAAE,CAAC;IACpC,MAAM,WAAW,GAAe,EAAE,CAAC;IACnC,MAAM,UAAU,GAAe,EAAE,CAAC;IAClC,IAAI,iBAAiB,GAAG,CAAC,CAAC,QAAQ,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC;IAEnD,IAAI,WAAW,GAAG,UAAU,CAAC,aAAa,KAAK,SAAS,CAAC;IACzD,IAAI,
|
|
1
|
+
{"version":3,"file":"_app.js","sourceRoot":"","sources":["../src/_app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AAG5C,MAAM,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CAAC,WAAW,CAAC,CAAC;QACrC,CAAC;QAED,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACtB,MAAM,SAAS,CAAC,GAAG,CAAC,mBAAmB,EAAE,CAAC;YAC1C,SAAS,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;YAElC,IAAI,CAAC;gBACD,MAAM,GAAG,GAAG,GAAG,EAAE,CAAC;gBAClB,IAAI,GAAG,YAAY,OAAO;oBAAE,MAAM,GAAG,CAAC;YAC1C,CAAC;oBACO,CAAC;gBACL,SAAS,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;YACtC,CAAC;QACL,CAAC;QAED,WAAW,CAAC,QAAkB;YAC1B,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAED,eAAe,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAC/B,IAAI,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YAC1B,IAAI,OAAO,KAAG,SAAS;gBAAE,OAAO,OAAO,CAAC;YACxC,OAAO,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,EAAE,CAAC;QACpC,CAAC;QAED,iBAAiB,EAAE,CAAC,GAAG,EAAE,EAAE;YACvB,OAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACxB,CAAC;KACJ,CAAC;AACN,CAAC;AAED,IAAI,SAAS,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function patch_compress(): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isBunJs } from "./common.js";
|
|
2
|
+
import { merge } from "./internal.js";
|
|
3
|
+
import { gunzipSync, gzipSync } from "node:zlib";
|
|
4
|
+
export function patch_compress() {
|
|
5
|
+
const myCompress = {
|
|
6
|
+
gunzipSync: data => gunzipSync(Buffer.from(data)),
|
|
7
|
+
gzipSync: data => gzipSync(Buffer.from(data))
|
|
8
|
+
};
|
|
9
|
+
if (isBunJs()) {
|
|
10
|
+
//@ts-ignore Accepting function signature
|
|
11
|
+
myCompress.gunzipSync = Bun.gunzipSync;
|
|
12
|
+
//@ts-ignore Accepting function signature
|
|
13
|
+
myCompress.gzipSync = Bun.gzipSync;
|
|
14
|
+
}
|
|
15
|
+
merge(NodeSpace.compress, myCompress);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=_compress_s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_compress_s.js","sourceRoot":"","sources":["../src/_compress_s.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AACpC,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAC;AAE/C,MAAM,UAAU,cAAc;IAC1B,MAAM,UAAU,GAAiB;QAC7B,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACjD,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAChD,CAAC;IAEF,IAAI,OAAO,EAAE,EAAE,CAAC;QACZ,yCAAyC;QACzC,UAAU,CAAC,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC;QACvC,yCAAyC;QACzC,UAAU,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function patch_crypto(): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { merge } from "./internal.js";
|
|
2
|
+
import crypto from "node:crypto";
|
|
3
|
+
import { isBunJs } from "./common.js";
|
|
4
|
+
export function patch_crypto() {
|
|
5
|
+
const myCrypto = {
|
|
6
|
+
md5(text) {
|
|
7
|
+
return crypto.createHash('md5').update(text).digest('hex');
|
|
8
|
+
},
|
|
9
|
+
fastHash(text) {
|
|
10
|
+
return crypto.createHash('sha256').update(text).digest('hex');
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
if (isBunJs()) {
|
|
14
|
+
myCrypto.fastHash = t => Bun.hash(t).toString();
|
|
15
|
+
myCrypto.md5 = t => Bun.MD5.hash(t, "hex");
|
|
16
|
+
}
|
|
17
|
+
merge(NodeSpace.crypto, myCrypto);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=_crypto_s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_crypto_s.js","sourceRoot":"","sources":["../src/_crypto_s.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AACpC,OAAO,MAAM,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC,MAAM,UAAU,YAAY;IACxB,MAAM,QAAQ,GAAe;QACzB,GAAG,CAAC,IAAY;YACZ,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/D,CAAC;QAED,QAAQ,CAAC,IAAY;YACjB,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAClE,CAAC;KACJ,CAAC;IAEF,IAAI,OAAO,EAAE,EAAE,CAAC;QACZ,QAAQ,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QAChD,QAAQ,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AACtC,CAAC"}
|
package/dist/_fs_s.js
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
+
import fss from "node:fs";
|
|
2
3
|
import { fileURLToPath } from "url";
|
|
3
4
|
import { isBunJs } from "./common.js";
|
|
4
5
|
import { pathToFileURL } from "node:url";
|
|
5
6
|
import { lookup } from "mime-types";
|
|
7
|
+
import { Readable } from "node:stream";
|
|
6
8
|
import { createReadStream } from "node:fs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
import { merge } from "./internal.js";
|
|
10
|
+
import path from "node:path";
|
|
11
|
+
//region Node.js adapter
|
|
12
|
+
class WebToNodeReadableStreamAdapter extends Readable {
|
|
13
|
+
constructor(webStream) {
|
|
14
|
+
super();
|
|
15
|
+
this.webStreamReader = webStream.getReader();
|
|
16
|
+
}
|
|
17
|
+
_read() {
|
|
18
|
+
this.webStreamReader.read().then(({ done, value }) => {
|
|
19
|
+
if (done) {
|
|
20
|
+
this.push(null);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const buffer = Buffer.from(value);
|
|
24
|
+
if (!this.push(buffer))
|
|
25
|
+
this.webStreamReader.cancel().then();
|
|
26
|
+
}).catch(err => {
|
|
27
|
+
this.destroy(err);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
_destroy(err, callback) {
|
|
31
|
+
this.webStreamReader.cancel().finally(() => { callback(err); });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
async function writeResponseToFile(response, filePath, createDir = true) {
|
|
35
|
+
if (createDir)
|
|
36
|
+
await mkDirRec(path.dirname(filePath));
|
|
9
37
|
const bufferDonnees = await response.arrayBuffer();
|
|
10
38
|
const bufferNode = Buffer.from(bufferDonnees);
|
|
11
39
|
await fs.writeFile(filePath, bufferNode);
|
|
@@ -19,17 +47,29 @@ function nodeStreamToWebStream(nodeStream) {
|
|
|
19
47
|
}
|
|
20
48
|
});
|
|
21
49
|
}
|
|
50
|
+
function webStreamToNodeStream(webStream) {
|
|
51
|
+
return new WebToNodeReadableStreamAdapter(webStream);
|
|
52
|
+
}
|
|
22
53
|
function createResponseFromFile(filePath, status = 200, headers) {
|
|
23
54
|
const nodeReadStream = createReadStream(filePath);
|
|
24
55
|
const webReadableStream = nodeStreamToWebStream(nodeReadStream);
|
|
25
56
|
return new Response(webReadableStream, { status: status, headers: headers });
|
|
26
57
|
}
|
|
27
58
|
async function getFileSize(filePath) {
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
try {
|
|
60
|
+
return (await fs.stat(filePath)).size;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return 0;
|
|
64
|
+
}
|
|
30
65
|
}
|
|
31
|
-
function getFileStat(filePath) {
|
|
32
|
-
|
|
66
|
+
async function getFileStat(filePath) {
|
|
67
|
+
try {
|
|
68
|
+
return await fs.stat(filePath);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
33
73
|
}
|
|
34
74
|
//endregion
|
|
35
75
|
function getMimeTypeFromName(fileName) {
|
|
@@ -38,24 +78,69 @@ function getMimeTypeFromName(fileName) {
|
|
|
38
78
|
return "";
|
|
39
79
|
return found;
|
|
40
80
|
}
|
|
81
|
+
async function mkDirRec(dirPath) {
|
|
82
|
+
try {
|
|
83
|
+
await fs.mkdir(dirPath, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
}
|
|
87
|
+
async function rmDirRec(dirPath) {
|
|
88
|
+
try {
|
|
89
|
+
await fs.rm(dirPath, { recursive: true, force: true });
|
|
90
|
+
}
|
|
91
|
+
catch { }
|
|
92
|
+
}
|
|
93
|
+
async function writeTextToFile(filePath, text, createDir = true) {
|
|
94
|
+
if (createDir)
|
|
95
|
+
await mkDirRec(path.dirname(filePath));
|
|
96
|
+
await fs.writeFile(filePath, text, { encoding: 'utf8', flag: 'w' });
|
|
97
|
+
}
|
|
98
|
+
function readTextFromFile(filePath) {
|
|
99
|
+
return fs.readFile(filePath, 'utf8');
|
|
100
|
+
}
|
|
101
|
+
function readTextSyncFromFile(filePath) {
|
|
102
|
+
return fss.readFileSync(filePath, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
async function isFile(filePath) {
|
|
105
|
+
const stats = await getFileStat(filePath);
|
|
106
|
+
if (!stats)
|
|
107
|
+
return false;
|
|
108
|
+
return stats.isFile();
|
|
109
|
+
}
|
|
110
|
+
async function isDirectory(filePath) {
|
|
111
|
+
const stats = await getFileStat(filePath);
|
|
112
|
+
if (!stats)
|
|
113
|
+
return false;
|
|
114
|
+
return stats.isDirectory();
|
|
115
|
+
}
|
|
116
|
+
async function readFileToBytes(filePath) {
|
|
117
|
+
const buffer = await fs.readFile(filePath);
|
|
118
|
+
return new Uint8Array(buffer);
|
|
119
|
+
}
|
|
41
120
|
export function patch_fs() {
|
|
42
|
-
|
|
43
|
-
mkDir:
|
|
121
|
+
const myFS = {
|
|
122
|
+
mkDir: mkDirRec,
|
|
123
|
+
rmDir: rmDirRec,
|
|
44
124
|
fileURLToPath: (url) => fileURLToPath(url),
|
|
45
125
|
pathToFileURL: (fsPath) => pathToFileURL(fsPath),
|
|
126
|
+
unlink: (filePath) => fs.unlink(filePath),
|
|
46
127
|
getFileSize,
|
|
47
128
|
getMimeTypeFromName,
|
|
48
129
|
writeResponseToFile,
|
|
49
130
|
createResponseFromFile,
|
|
50
|
-
getFileStat
|
|
131
|
+
getFileStat,
|
|
132
|
+
readFileToBytes,
|
|
133
|
+
nodeStreamToWebStream, webStreamToNodeStream,
|
|
134
|
+
writeTextToFile, readTextFromFile, readTextSyncFromFile,
|
|
135
|
+
isFile, isDirectory
|
|
51
136
|
};
|
|
52
137
|
if (isBunJs()) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
};
|
|
138
|
+
myFS.fileURLToPath = (url) => Bun.fileURLToPath(url);
|
|
139
|
+
myFS.pathToFileURL = (fsPath) => Bun.pathToFileURL(fsPath);
|
|
140
|
+
myFS.writeResponseToFile = async (r, p) => { await Bun.file(p).write(r); };
|
|
141
|
+
myFS.createResponseFromFile = (filePath, status, headers) => new Response(Bun.file(filePath), { status, headers });
|
|
142
|
+
myFS.readFileToBytes = async (filePath) => Bun.file(filePath).bytes();
|
|
59
143
|
}
|
|
144
|
+
merge(NodeSpace.fs, myFS);
|
|
60
145
|
}
|
|
61
146
|
//# sourceMappingURL=_fs_s.js.map
|
package/dist/_fs_s.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_fs_s.js","sourceRoot":"","sources":["../src/_fs_s.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"_fs_s.js","sourceRoot":"","sources":["../src/_fs_s.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,GAAG,MAAM,SAAS,CAAC;AAC1B,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAC;AAClC,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,aAAa,CAAC;AACrC,OAAO,EAAC,gBAAgB,EA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AM,EAAE,WAAW;KACtB,CAAC;IAEF,IAAI,OAAO,EAAE,EAAE,CAAC;QACZ,IAAI,CAAC,aAAa,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QACrD,IAAI,CAAC,aAAa,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,mBAAmB,GAAG,KAAK,EAAE,CAAW,EAAE,CAAS,EAAE,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QAC5F,IAAI,CAAC,sBAAsB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAC,MAAM,EAAE,OAAO,EAAC,CAAC,CAAC;QACjH,IAAI,CAAC,eAAe,GAAG,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,CAAC;IAC1E,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/_os_s.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function patch_os(): void;
|
package/dist/_os_s.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { merge } from "./internal.js";
|
|
2
|
+
import { exec } from "node:child_process";
|
|
3
|
+
import { env } from "node:process";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
import * as fs from "node:fs/promises";
|
|
6
|
+
import { isBunJs } from "./common.js";
|
|
7
|
+
async function which(command) {
|
|
8
|
+
const pathArray = (env.PATH || '').split(process.platform === 'win32' ? ';' : ':');
|
|
9
|
+
const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat'] : [''];
|
|
10
|
+
for (const dir of pathArray) {
|
|
11
|
+
for (const ext of extensions) {
|
|
12
|
+
const fullPath = path.join(dir, command + ext);
|
|
13
|
+
try {
|
|
14
|
+
const stats = await fs.stat(fullPath);
|
|
15
|
+
if (stats.isFile())
|
|
16
|
+
return fullPath;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
function doExec(command) {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
exec(command, (error) => { if (error)
|
|
27
|
+
reject(error);
|
|
28
|
+
else
|
|
29
|
+
resolve(); });
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
export function patch_os() {
|
|
33
|
+
const myImpl = {
|
|
34
|
+
exec: doExec,
|
|
35
|
+
which
|
|
36
|
+
};
|
|
37
|
+
if (isBunJs()) {
|
|
38
|
+
//TODO: Bun is sync, can be a problem?
|
|
39
|
+
myImpl.which = (toolName) => Promise.resolve(Bun.which(toolName));
|
|
40
|
+
}
|
|
41
|
+
merge(NodeSpace.os, myImpl);
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=_os_s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_os_s.js","sourceRoot":"","sources":["../src/_os_s.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AACpC,OAAO,EAAC,IAAI,EAAC,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAC,GAAG,EAAC,MAAM,cAAc,CAAC;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC,KAAK,UAAU,KAAK,CAAC,OAAe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KAAK,GAAG,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;AAChC,CAAC"}
|
package/dist/_process.js
CHANGED
package/dist/_process_s.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { merge } from "./internal.js";
|
|
1
2
|
export function patch_process() {
|
|
2
|
-
|
|
3
|
+
const myProcess = {
|
|
3
4
|
argv: process.argv,
|
|
4
5
|
env: process.env,
|
|
5
|
-
isProduction: process.env.NODE_ENV === 'production'
|
|
6
|
+
isProduction: process.env.NODE_ENV === 'production',
|
|
6
7
|
};
|
|
8
|
+
merge(NodeSpace.process, myProcess);
|
|
7
9
|
}
|
|
8
10
|
//# sourceMappingURL=_process_s.js.map
|
package/dist/_process_s.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_process_s.js","sourceRoot":"","sources":["../src/_process_s.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"_process_s.js","sourceRoot":"","sources":["../src/_process_s.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,MAAM,UAAU,aAAa;IACzB,MAAM,SAAS,GAAgB;QAC3B,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,GAAG,EAAE,OAAO,CAAC,GAAgC;QAC7C,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;KACtD,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function patch_stream(): void;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isBunJs } from "./common.js";
|
|
2
|
+
import { merge } from "./internal.js";
|
|
3
|
+
async function teeResponse(response) {
|
|
4
|
+
// Actually response.body.tee is ko with node.js, we can't use it.
|
|
5
|
+
const bodyArrayBuffer = await response.arrayBuffer();
|
|
6
|
+
let headers = new Headers(response.headers);
|
|
7
|
+
// Sometimes the content length becomes invalid, it's why we need to update it.
|
|
8
|
+
headers.set("content-length", bodyArrayBuffer.byteLength.toString());
|
|
9
|
+
// TODO: is it possible to avoid loading in memory?
|
|
10
|
+
const blob1 = new Blob([bodyArrayBuffer]);
|
|
11
|
+
const blob2 = new Blob([bodyArrayBuffer]);
|
|
12
|
+
response = new Response(blob2.stream(), { status: response.status, headers });
|
|
13
|
+
return [blob1.stream(), response];
|
|
14
|
+
}
|
|
15
|
+
export function patch_stream() {
|
|
16
|
+
const myStream = {
|
|
17
|
+
teeResponse
|
|
18
|
+
};
|
|
19
|
+
if (isBunJs()) {
|
|
20
|
+
myStream.teeResponse = r => {
|
|
21
|
+
const [b1, b2] = r.body.tee();
|
|
22
|
+
// The old response body is consumed. So we must rebuild the response.
|
|
23
|
+
return Promise.resolve([b1, new Response(b2, { status: r.status, headers: r.headers })]);
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
merge(NodeSpace.stream, myStream);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=_stream_s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_stream_s.js","sourceRoot":"","sources":["../src/_stream_s.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAC,KAAK,EAAC,MAAM,eAAe,CAAC;AAEpC,KAAK,UAAU,WAAW,CAAC,QAAkB;IACzC,kEAAkE;IAClE,MAAM,eAAe,GAAgB,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;IAElE,IAAI,OAAO,GAAG,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAE5C,+EAA+E;IAC/E,OAAO,CAAC,GA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