jopi-toolkit 3.0.10 → 3.0.12
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/dist/jk_fs/jBundler_ifServer.d.ts +1 -1
- package/package.json +3 -3
- package/src/jk_app/common.js +0 -442
- package/src/jk_events/index.js +0 -213
- package/src/jk_fs/index.js +0 -2
- package/src/jk_fs/jBundler_ifServer.js +0 -552
- package/src/jk_thread/common.js +0 -7
- package/src/jk_tools/common.js +0 -101
- package/src/jk_tools/index.js +0 -1
- package/src/jk_tools/jBundler_ifServer.js +0 -167
- package/src/jk_translate/index.js +0 -56
- package/src/jk_what/jBundler_ifServer.js +0 -5
|
@@ -75,7 +75,7 @@ export declare const join: (...paths: string[]) => string;
|
|
|
75
75
|
export declare const resolve: (...paths: string[]) => string;
|
|
76
76
|
export declare const dirname: (path: string) => string;
|
|
77
77
|
export declare const extname: (path: string) => string;
|
|
78
|
-
export declare const sep: "
|
|
78
|
+
export declare const sep: "\\" | "/";
|
|
79
79
|
export declare const isAbsolute: (path: string) => boolean;
|
|
80
80
|
export declare const normalize: (path: string) => string;
|
|
81
81
|
export declare const basename: (path: string, suffix?: string) => string;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.0.
|
|
2
|
+
"version": "3.0.12",
|
|
3
3
|
"name": "jopi-toolkit",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/johanpiquet/jopi-toolkit",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"mime-types": "^3.0.1",
|
|
37
37
|
"ws": "^8.18.3"
|
|
38
38
|
},
|
|
39
|
-
"publishedDate": "12/
|
|
40
|
-
"publicPublishedDate": "12/
|
|
39
|
+
"publishedDate": "12/9/2025",
|
|
40
|
+
"publicPublishedDate": "12/9/2025",
|
|
41
41
|
"exports": {
|
|
42
42
|
"./jk_schema": {
|
|
43
43
|
"bun": "./src/jk_schemas/index.ts",
|
package/src/jk_app/common.js
DELETED
|
@@ -1,442 +0,0 @@
|
|
|
1
|
-
// noinspection JSUnusedGlobalSymbols
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
39
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
40
|
-
if (ar || !(i in from)) {
|
|
41
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
42
|
-
ar[i] = from[i];
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
46
|
-
};
|
|
47
|
-
import * as jk_thread from "jopi-toolkit/jk_thread";
|
|
48
|
-
import * as jk_fs from "jopi-toolkit/jk_fs";
|
|
49
|
-
import * as jk_timer from "jopi-toolkit/jk_timer";
|
|
50
|
-
import { isBunJS, isNodeJS } from "jopi-toolkit/jk_what";
|
|
51
|
-
import { isUsingWorker } from "jopi-toolkit/jk_thread";
|
|
52
|
-
function execListeners(listeners) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
-
var list, _i, list_1, listener, res, e_1;
|
|
55
|
-
return __generator(this, function (_a) {
|
|
56
|
-
switch (_a.label) {
|
|
57
|
-
case 0:
|
|
58
|
-
list = __spreadArray([], listeners, true);
|
|
59
|
-
listeners.splice(0);
|
|
60
|
-
_i = 0, list_1 = list;
|
|
61
|
-
_a.label = 1;
|
|
62
|
-
case 1:
|
|
63
|
-
if (!(_i < list_1.length)) return [3 /*break*/, 7];
|
|
64
|
-
listener = list_1[_i];
|
|
65
|
-
_a.label = 2;
|
|
66
|
-
case 2:
|
|
67
|
-
_a.trys.push([2, 5, , 6]);
|
|
68
|
-
res = listener();
|
|
69
|
-
if (!(res instanceof Promise)) return [3 /*break*/, 4];
|
|
70
|
-
return [4 /*yield*/, res];
|
|
71
|
-
case 3:
|
|
72
|
-
_a.sent();
|
|
73
|
-
_a.label = 4;
|
|
74
|
-
case 4: return [3 /*break*/, 6];
|
|
75
|
-
case 5:
|
|
76
|
-
e_1 = _a.sent();
|
|
77
|
-
console.error(e_1);
|
|
78
|
-
return [3 /*break*/, 6];
|
|
79
|
-
case 6:
|
|
80
|
-
_i++;
|
|
81
|
-
return [3 /*break*/, 1];
|
|
82
|
-
case 7: return [2 /*return*/];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
var gOnServerSideReady = [];
|
|
88
|
-
var gOnAppExiting = [];
|
|
89
|
-
var gOnAppExited = [];
|
|
90
|
-
var gOnAppStart = [];
|
|
91
|
-
var gIsServerSideReady = !(isNodeJS || isBunJS);
|
|
92
|
-
var gIsHotReload = globalThis.jopiHotReload !== undefined;
|
|
93
|
-
var gIsAppStarted = false;
|
|
94
|
-
if (gIsHotReload) {
|
|
95
|
-
execListeners(globalThis.jopiHotReload.onHotReload).then();
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
globalThis.jopiHotReload = {
|
|
99
|
-
onHotReload: [],
|
|
100
|
-
memory: {}
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
var gOnHotReload = globalThis.jopiHotReload.onHotReload;
|
|
104
|
-
var gMemory = globalThis.jopiHotReload.memory;
|
|
105
|
-
export function onServerSideReady(listener) {
|
|
106
|
-
if (gIsServerSideReady)
|
|
107
|
-
listener();
|
|
108
|
-
else
|
|
109
|
-
gOnServerSideReady.push(listener);
|
|
110
|
-
}
|
|
111
|
-
export function waitServerSideReady() {
|
|
112
|
-
if (gIsServerSideReady) {
|
|
113
|
-
return Promise.resolve();
|
|
114
|
-
}
|
|
115
|
-
return new Promise(function (r) {
|
|
116
|
-
onServerSideReady(r);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
export function declareServerSideReady() {
|
|
120
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
121
|
-
return __generator(this, function (_a) {
|
|
122
|
-
switch (_a.label) {
|
|
123
|
-
case 0:
|
|
124
|
-
gIsServerSideReady = true;
|
|
125
|
-
return [4 /*yield*/, execListeners(gOnServerSideReady)];
|
|
126
|
-
case 1:
|
|
127
|
-
_a.sent();
|
|
128
|
-
return [2 /*return*/];
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
export function onAppStart(listener) {
|
|
134
|
-
if (gIsAppStarted)
|
|
135
|
-
listener();
|
|
136
|
-
else
|
|
137
|
-
gOnAppStart.push(listener);
|
|
138
|
-
}
|
|
139
|
-
export function onAppExiting(listener) {
|
|
140
|
-
if (gIsExited)
|
|
141
|
-
listener();
|
|
142
|
-
else
|
|
143
|
-
gOnAppExiting.push(listener);
|
|
144
|
-
}
|
|
145
|
-
export function onAppExited(listener) {
|
|
146
|
-
if (gIsExited)
|
|
147
|
-
listener();
|
|
148
|
-
else
|
|
149
|
-
gOnAppExited.push(listener);
|
|
150
|
-
}
|
|
151
|
-
export function declareAppStarted() {
|
|
152
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
153
|
-
return __generator(this, function (_a) {
|
|
154
|
-
switch (_a.label) {
|
|
155
|
-
case 0:
|
|
156
|
-
gIsAppStarted = true;
|
|
157
|
-
return [4 /*yield*/, execListeners(gOnAppStart)];
|
|
158
|
-
case 1:
|
|
159
|
-
_a.sent();
|
|
160
|
-
return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
export function declareAppExiting() {
|
|
166
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
167
|
-
return __generator(this, function (_a) {
|
|
168
|
-
switch (_a.label) {
|
|
169
|
-
case 0:
|
|
170
|
-
if (gIsExited)
|
|
171
|
-
return [2 /*return*/];
|
|
172
|
-
gIsExited = true;
|
|
173
|
-
if (!isUsingWorker()) return [3 /*break*/, 2];
|
|
174
|
-
// Wait 1 sec, which allows the worker to correctly initialize.
|
|
175
|
-
return [4 /*yield*/, jk_timer.tick(1000)];
|
|
176
|
-
case 1:
|
|
177
|
-
// Wait 1 sec, which allows the worker to correctly initialize.
|
|
178
|
-
_a.sent();
|
|
179
|
-
_a.label = 2;
|
|
180
|
-
case 2:
|
|
181
|
-
gIsAppStarted = false;
|
|
182
|
-
return [4 /*yield*/, execListeners(gOnAppExiting)];
|
|
183
|
-
case 3:
|
|
184
|
-
_a.sent();
|
|
185
|
-
if (!isUsingWorker()) return [3 /*break*/, 5];
|
|
186
|
-
// Allows to worker to correctly stop their activity.
|
|
187
|
-
return [4 /*yield*/, jk_timer.tick(100)];
|
|
188
|
-
case 4:
|
|
189
|
-
// Allows to worker to correctly stop their activity.
|
|
190
|
-
_a.sent();
|
|
191
|
-
_a.label = 5;
|
|
192
|
-
case 5:
|
|
193
|
-
if (!!jk_thread.isMainThread) return [3 /*break*/, 7];
|
|
194
|
-
// Allows to worker to correctly stop their activity.
|
|
195
|
-
return [4 /*yield*/, jk_timer.tick(50)];
|
|
196
|
-
case 6:
|
|
197
|
-
// Allows to worker to correctly stop their activity.
|
|
198
|
-
_a.sent();
|
|
199
|
-
_a.label = 7;
|
|
200
|
-
case 7: return [4 /*yield*/, execListeners(gOnAppExited)];
|
|
201
|
-
case 8:
|
|
202
|
-
_a.sent();
|
|
203
|
-
return [2 /*return*/];
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
export function executeApp(app) {
|
|
209
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
210
|
-
var res;
|
|
211
|
-
return __generator(this, function (_a) {
|
|
212
|
-
switch (_a.label) {
|
|
213
|
-
case 0: return [4 /*yield*/, waitServerSideReady()];
|
|
214
|
-
case 1:
|
|
215
|
-
_a.sent();
|
|
216
|
-
declareAppStarted();
|
|
217
|
-
_a.label = 2;
|
|
218
|
-
case 2:
|
|
219
|
-
_a.trys.push([2, , 5, 6]);
|
|
220
|
-
res = app();
|
|
221
|
-
if (!(res instanceof Promise)) return [3 /*break*/, 4];
|
|
222
|
-
return [4 /*yield*/, res];
|
|
223
|
-
case 3:
|
|
224
|
-
_a.sent();
|
|
225
|
-
_a.label = 4;
|
|
226
|
-
case 4: return [3 /*break*/, 6];
|
|
227
|
-
case 5:
|
|
228
|
-
declareAppExiting();
|
|
229
|
-
return [7 /*endfinally*/];
|
|
230
|
-
case 6: return [2 /*return*/];
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
//endregion
|
|
236
|
-
//region Hot-reload
|
|
237
|
-
export function onHotReload(listener) {
|
|
238
|
-
gOnHotReload.push(listener);
|
|
239
|
-
}
|
|
240
|
-
export function keepOnHotReload(key, provider) {
|
|
241
|
-
var current = gMemory[key];
|
|
242
|
-
if (current !== undefined)
|
|
243
|
-
return current;
|
|
244
|
-
return gMemory[key] = provider();
|
|
245
|
-
}
|
|
246
|
-
export function clearHotReloadKey(key) {
|
|
247
|
-
delete (gMemory[key]);
|
|
248
|
-
}
|
|
249
|
-
//endregion
|
|
250
|
-
//region Temp dir
|
|
251
|
-
export function getTempDir() {
|
|
252
|
-
if (!gTempDir) {
|
|
253
|
-
gTempDir = jk_fs.resolve(process.cwd(), "temp");
|
|
254
|
-
}
|
|
255
|
-
return gTempDir;
|
|
256
|
-
}
|
|
257
|
-
var gIsExited = false;
|
|
258
|
-
var gTempDir;
|
|
259
|
-
//endregion
|
|
260
|
-
//region Resolving
|
|
261
|
-
export function findNodePackageDir(packageName, useLinuxPathFormat) {
|
|
262
|
-
if (useLinuxPathFormat === void 0) { useLinuxPathFormat = true; }
|
|
263
|
-
var currentDir = jk_fs.dirname(findPackageJson());
|
|
264
|
-
while (true) {
|
|
265
|
-
var packagePath = jk_fs.join(currentDir, 'node_modules', packageName);
|
|
266
|
-
if (jk_fs.isDirectorySync(packagePath)) {
|
|
267
|
-
if (useLinuxPathFormat)
|
|
268
|
-
return jk_fs.win32ToLinuxPath(packagePath);
|
|
269
|
-
return packagePath;
|
|
270
|
-
}
|
|
271
|
-
var parentDir = jk_fs.dirname(currentDir);
|
|
272
|
-
// Reached root directory
|
|
273
|
-
if (parentDir === currentDir) {
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
currentDir = parentDir;
|
|
277
|
-
}
|
|
278
|
-
return undefined;
|
|
279
|
-
}
|
|
280
|
-
export function requireNodePackageDir(packageName, useLinuxPathFormat) {
|
|
281
|
-
if (useLinuxPathFormat === void 0) { useLinuxPathFormat = true; }
|
|
282
|
-
var pkgDir = findNodePackageDir(packageName, useLinuxPathFormat);
|
|
283
|
-
if (!pkgDir)
|
|
284
|
-
throw new Error("Package '" + packageName + "' not found");
|
|
285
|
-
return pkgDir;
|
|
286
|
-
}
|
|
287
|
-
export function findPackageJsonDir(searchFromDir) {
|
|
288
|
-
if (searchFromDir === void 0) { searchFromDir = getCodeSourceDirHint(); }
|
|
289
|
-
var pkgJsonPath = findPackageJson(searchFromDir);
|
|
290
|
-
return jk_fs.dirname(pkgJsonPath);
|
|
291
|
-
}
|
|
292
|
-
export function findPackageJson(searchFromDir) {
|
|
293
|
-
if (searchFromDir === void 0) { searchFromDir = getCodeSourceDirHint(); }
|
|
294
|
-
if (!searchFromDir && (gPackageJsonPath !== undefined))
|
|
295
|
-
return gPackageJsonPath;
|
|
296
|
-
var currentDir = searchFromDir;
|
|
297
|
-
while (true) {
|
|
298
|
-
var packagePath = jk_fs.join(currentDir, 'package.json');
|
|
299
|
-
if (jk_fs.isFileSync(packagePath))
|
|
300
|
-
return gPackageJsonPath = packagePath;
|
|
301
|
-
var parentDir = jk_fs.dirname(currentDir);
|
|
302
|
-
// Reached root directory
|
|
303
|
-
if (parentDir === currentDir)
|
|
304
|
-
break;
|
|
305
|
-
currentDir = parentDir;
|
|
306
|
-
}
|
|
307
|
-
throw "No package.json found.";
|
|
308
|
-
}
|
|
309
|
-
//
|
|
310
|
-
var gPackageJsonPath;
|
|
311
|
-
export function setApplicationMainFile(applicationMainFile) {
|
|
312
|
-
gApplicationMainFile = applicationMainFile;
|
|
313
|
-
gCodeSourceDirHint = jk_fs.dirname(applicationMainFile);
|
|
314
|
-
}
|
|
315
|
-
export function getApplicationMainFile() {
|
|
316
|
-
return gApplicationMainFile;
|
|
317
|
-
}
|
|
318
|
-
export function getCodeSourceDirHint() {
|
|
319
|
-
if (!gCodeSourceDirHint)
|
|
320
|
-
return process.cwd();
|
|
321
|
-
return gCodeSourceDirHint;
|
|
322
|
-
}
|
|
323
|
-
export function getSourceCodeDir() {
|
|
324
|
-
if (gSourceCodeDir)
|
|
325
|
-
return gSourceCodeDir;
|
|
326
|
-
var pkgJsonPath = findPackageJson();
|
|
327
|
-
var dirName = jk_fs.join(jk_fs.dirname(pkgJsonPath), "src");
|
|
328
|
-
if (jk_fs.isDirectorySync(dirName)) {
|
|
329
|
-
return gSourceCodeDir = dirName;
|
|
330
|
-
}
|
|
331
|
-
return gSourceCodeDir = jk_fs.dirname(pkgJsonPath);
|
|
332
|
-
}
|
|
333
|
-
export function getCompiledCodeDir() {
|
|
334
|
-
if (gCompiledSourcesDir)
|
|
335
|
-
return gCompiledSourcesDir;
|
|
336
|
-
var sourceCodeDir = getSourceCodeDir();
|
|
337
|
-
if (!sourceCodeDir.endsWith("src")) {
|
|
338
|
-
return gCompiledSourcesDir = sourceCodeDir;
|
|
339
|
-
}
|
|
340
|
-
// This means that it's Bun.js, and it directly uses the TypeScript version.
|
|
341
|
-
if (gApplicationMainFile && isBunJS && gApplicationMainFile.startsWith(sourceCodeDir)) {
|
|
342
|
-
return gCompiledSourcesDir = sourceCodeDir;
|
|
343
|
-
}
|
|
344
|
-
var pkgJsonPath = findPackageJson();
|
|
345
|
-
var rootDir = jk_fs.dirname(pkgJsonPath);
|
|
346
|
-
for (var _i = 0, _a = ["dist", "build", "out"]; _i < _a.length; _i++) {
|
|
347
|
-
var toTest = _a[_i];
|
|
348
|
-
if (jk_fs.isDirectorySync(jk_fs.join(rootDir, toTest))) {
|
|
349
|
-
return gCompiledSourcesDir = jk_fs.join(rootDir, toTest);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
// No output dir? Assume we compiled on the same dir.
|
|
353
|
-
return rootDir;
|
|
354
|
-
}
|
|
355
|
-
export function getCompiledFilePathFor(sourceFilePath) {
|
|
356
|
-
var compiledCodeDir = getCompiledCodeDir();
|
|
357
|
-
var sourceCodeDir = getSourceCodeDir();
|
|
358
|
-
if (!sourceFilePath.startsWith(sourceCodeDir)) {
|
|
359
|
-
throw new Error("jopi-loader - The source file must be in the source code directory: " + sourceFilePath);
|
|
360
|
-
}
|
|
361
|
-
var filePath = sourceFilePath.substring(sourceCodeDir.length);
|
|
362
|
-
if (isNodeJS && !filePath.endsWith(".js")) {
|
|
363
|
-
var idx = filePath.lastIndexOf(".");
|
|
364
|
-
if (idx !== -1)
|
|
365
|
-
filePath = filePath.substring(0, idx) + ".js";
|
|
366
|
-
}
|
|
367
|
-
return jk_fs.join(compiledCodeDir, filePath);
|
|
368
|
-
}
|
|
369
|
-
export function getSourcesCodePathFor(compiledFilePath) {
|
|
370
|
-
var compiledCodeDir = getCompiledCodeDir();
|
|
371
|
-
var sourceCodeDir = getSourceCodeDir();
|
|
372
|
-
if (!compiledFilePath.startsWith(compiledCodeDir)) {
|
|
373
|
-
throw new Error("jopi-loader - The compiled file must be in the compiled code directory: " + compiledFilePath);
|
|
374
|
-
}
|
|
375
|
-
var filePath = jk_fs.join(sourceCodeDir, compiledFilePath.substring(compiledCodeDir.length));
|
|
376
|
-
var idx = filePath.lastIndexOf(".");
|
|
377
|
-
if (idx !== -1)
|
|
378
|
-
filePath = filePath.substring(0, idx);
|
|
379
|
-
if (jk_fs.isFileSync(filePath + ".tsx")) {
|
|
380
|
-
return filePath + ".tsx";
|
|
381
|
-
}
|
|
382
|
-
if (jk_fs.isFileSync(filePath + ".ts")) {
|
|
383
|
-
return filePath + ".ts";
|
|
384
|
-
}
|
|
385
|
-
return filePath + ".js";
|
|
386
|
-
}
|
|
387
|
-
export function requireSourceOf(scriptPath) {
|
|
388
|
-
var src = searchSourceOf(scriptPath);
|
|
389
|
-
if (!src)
|
|
390
|
-
throw new Error("Cannot find source of " + scriptPath);
|
|
391
|
-
return src;
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Search the source of the component if it's a JavaScript and not a TypeScript.
|
|
395
|
-
* Why? Because EsBuild doesn't work well on already transpiled code.
|
|
396
|
-
*/
|
|
397
|
-
export function searchSourceOf(scriptPath) {
|
|
398
|
-
function tryResolve(filePath, outDir) {
|
|
399
|
-
var out = jk_fs.sep + outDir + jk_fs.sep;
|
|
400
|
-
var idx = filePath.lastIndexOf(out);
|
|
401
|
-
if (idx !== -1) {
|
|
402
|
-
filePath = filePath.slice(0, idx) + jk_fs.sep + "src" + jk_fs.sep + filePath.slice(idx + out.length);
|
|
403
|
-
if (jk_fs.isFileSync(filePath))
|
|
404
|
-
return filePath;
|
|
405
|
-
}
|
|
406
|
-
return undefined;
|
|
407
|
-
}
|
|
408
|
-
var scriptExt = jk_fs.extname(scriptPath);
|
|
409
|
-
if ((scriptExt === ".ts") || (scriptExt === ".tsx")) {
|
|
410
|
-
// Is already the source.
|
|
411
|
-
return scriptPath;
|
|
412
|
-
}
|
|
413
|
-
var originalScriptPath = scriptPath;
|
|
414
|
-
var isJavascript = (scriptPath.endsWith(".js") || (scriptPath.endsWith(".jsx")));
|
|
415
|
-
if (isJavascript) {
|
|
416
|
-
// Remove his extension.
|
|
417
|
-
scriptPath = scriptPath.slice(0, -scriptExt.length);
|
|
418
|
-
}
|
|
419
|
-
var tryDirs = ["dist", "build"];
|
|
420
|
-
for (var _i = 0, tryDirs_1 = tryDirs; _i < tryDirs_1.length; _i++) {
|
|
421
|
-
var toTry = tryDirs_1[_i];
|
|
422
|
-
if (isJavascript) {
|
|
423
|
-
var found = tryResolve(scriptPath + ".tsx", toTry);
|
|
424
|
-
if (found)
|
|
425
|
-
return found;
|
|
426
|
-
found = tryResolve(scriptPath + ".ts", toTry);
|
|
427
|
-
if (found)
|
|
428
|
-
return found;
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
var found = tryResolve(scriptPath, toTry);
|
|
432
|
-
if (found)
|
|
433
|
-
return found;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
return originalScriptPath;
|
|
437
|
-
}
|
|
438
|
-
var gSourceCodeDir;
|
|
439
|
-
var gCodeSourceDirHint;
|
|
440
|
-
var gApplicationMainFile;
|
|
441
|
-
var gCompiledSourcesDir;
|
|
442
|
-
//endregion
|
package/src/jk_events/index.js
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
import { PriorityLevel as EventPriority } from "jopi-toolkit/jk_tools";
|
|
38
|
-
// Warning: it's export.
|
|
39
|
-
export { PriorityLevel as EventPriority } from "jopi-toolkit/jk_tools";
|
|
40
|
-
var EventGroup = /** @class */ (function () {
|
|
41
|
-
function EventGroup() {
|
|
42
|
-
this.listenersFor = {};
|
|
43
|
-
this.providers = {};
|
|
44
|
-
}
|
|
45
|
-
EventGroup.prototype.newEventGroup = function () {
|
|
46
|
-
return new EventGroup();
|
|
47
|
-
};
|
|
48
|
-
EventGroup.prototype.enableEventSpying = function (spy) {
|
|
49
|
-
this.evenSpy = spy;
|
|
50
|
-
};
|
|
51
|
-
EventGroup.prototype.removeListener = function (eventName, listener) {
|
|
52
|
-
var events = this.listenersFor[eventName];
|
|
53
|
-
if (events)
|
|
54
|
-
events.remove(listener);
|
|
55
|
-
};
|
|
56
|
-
EventGroup.prototype.sendEvent = function (eventName, e) {
|
|
57
|
-
if (this.evenSpy)
|
|
58
|
-
this.evenSpy(eventName, e);
|
|
59
|
-
var events = this.listenersFor[eventName];
|
|
60
|
-
if (!events)
|
|
61
|
-
return;
|
|
62
|
-
if (events.value) {
|
|
63
|
-
var values = events.value;
|
|
64
|
-
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
65
|
-
var listener = values_1[_i];
|
|
66
|
-
listener(e, eventName);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
EventGroup.prototype.sendAsyncEvent = function (eventName, e) {
|
|
71
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
72
|
-
var events, provider, listeners, _i, listeners_1, listener, values, _a, values_2, listener, r;
|
|
73
|
-
return __generator(this, function (_b) {
|
|
74
|
-
switch (_b.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
if (eventName[0] !== '@') {
|
|
77
|
-
throw new Error("Async events ".concat(eventName, " must start with @"));
|
|
78
|
-
}
|
|
79
|
-
if (this.evenSpy)
|
|
80
|
-
this.evenSpy(eventName, e);
|
|
81
|
-
events = this.listenersFor[eventName];
|
|
82
|
-
if (!!events) return [3 /*break*/, 3];
|
|
83
|
-
provider = this.providers[eventName];
|
|
84
|
-
events = new PriorityArray();
|
|
85
|
-
if (!provider) return [3 /*break*/, 2];
|
|
86
|
-
return [4 /*yield*/, provider()];
|
|
87
|
-
case 1:
|
|
88
|
-
listeners = _b.sent();
|
|
89
|
-
for (_i = 0, listeners_1 = listeners; _i < listeners_1.length; _i++) {
|
|
90
|
-
listener = listeners_1[_i];
|
|
91
|
-
events.add(EventPriority.default, listener);
|
|
92
|
-
}
|
|
93
|
-
_b.label = 2;
|
|
94
|
-
case 2:
|
|
95
|
-
this.listenersFor[eventName] = events;
|
|
96
|
-
_b.label = 3;
|
|
97
|
-
case 3:
|
|
98
|
-
if (!events.value) return [3 /*break*/, 7];
|
|
99
|
-
values = events.value;
|
|
100
|
-
_a = 0, values_2 = values;
|
|
101
|
-
_b.label = 4;
|
|
102
|
-
case 4:
|
|
103
|
-
if (!(_a < values_2.length)) return [3 /*break*/, 7];
|
|
104
|
-
listener = values_2[_a];
|
|
105
|
-
r = listener(e, eventName);
|
|
106
|
-
if (!(r instanceof Promise)) return [3 /*break*/, 6];
|
|
107
|
-
return [4 /*yield*/, r];
|
|
108
|
-
case 5:
|
|
109
|
-
_b.sent();
|
|
110
|
-
_b.label = 6;
|
|
111
|
-
case 6:
|
|
112
|
-
_a++;
|
|
113
|
-
return [3 /*break*/, 4];
|
|
114
|
-
case 7: return [2 /*return*/];
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
};
|
|
119
|
-
EventGroup.prototype.addListener = function (eventName, priorityOrListener, listener) {
|
|
120
|
-
var priority;
|
|
121
|
-
var actualListener;
|
|
122
|
-
if (typeof priorityOrListener === 'function') {
|
|
123
|
-
// Cas où priority n'est pas fournie, priorityOrListener est le listener
|
|
124
|
-
priority = EventPriority.default;
|
|
125
|
-
actualListener = priorityOrListener;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// Cas où priority est fournie
|
|
129
|
-
priority = priorityOrListener;
|
|
130
|
-
actualListener = listener;
|
|
131
|
-
}
|
|
132
|
-
var events = this.listenersFor[eventName];
|
|
133
|
-
if (!events)
|
|
134
|
-
this.listenersFor[eventName] = events = new PriorityArray();
|
|
135
|
-
events.add(priority, actualListener);
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* For async events, allow loading some elements (import)
|
|
139
|
-
* only when the event is emitted for the time.
|
|
140
|
-
*/
|
|
141
|
-
EventGroup.prototype.addProvider = function (eventName, provider) {
|
|
142
|
-
this.providers[eventName] = provider;
|
|
143
|
-
};
|
|
144
|
-
return EventGroup;
|
|
145
|
-
}());
|
|
146
|
-
export { EventGroup };
|
|
147
|
-
//region PriorityArray
|
|
148
|
-
/**
|
|
149
|
-
* Allows building an array which entries are sorted by priority.
|
|
150
|
-
*/
|
|
151
|
-
var PriorityArray = /** @class */ (function () {
|
|
152
|
-
function PriorityArray() {
|
|
153
|
-
this.entries = [];
|
|
154
|
-
}
|
|
155
|
-
PriorityArray.prototype.add = function (priority, value) {
|
|
156
|
-
this.build = undefined;
|
|
157
|
-
this.entries.push({ priority: priority, value: value });
|
|
158
|
-
};
|
|
159
|
-
PriorityArray.prototype.remove = function (value) {
|
|
160
|
-
this.build = undefined;
|
|
161
|
-
this.entries = this.entries.filter(function (e) { return e.value !== value; });
|
|
162
|
-
};
|
|
163
|
-
Object.defineProperty(PriorityArray.prototype, "value", {
|
|
164
|
-
get: function () {
|
|
165
|
-
if (this.build) {
|
|
166
|
-
return this.build;
|
|
167
|
-
}
|
|
168
|
-
return this.build = this.entries
|
|
169
|
-
.sort(function (a, b) { return Number(a.priority) - Number(b.priority); })
|
|
170
|
-
.map(function (e) { return e.value; });
|
|
171
|
-
},
|
|
172
|
-
enumerable: false,
|
|
173
|
-
configurable: true
|
|
174
|
-
});
|
|
175
|
-
return PriorityArray;
|
|
176
|
-
}());
|
|
177
|
-
var StaticEventImpl = /** @class */ (function () {
|
|
178
|
-
function StaticEventImpl(eventName, eventItems) {
|
|
179
|
-
this.eventName = eventName;
|
|
180
|
-
this.eventItems = eventItems;
|
|
181
|
-
}
|
|
182
|
-
StaticEventImpl.prototype.send = function (data) {
|
|
183
|
-
for (var _i = 0, _a = this.eventItems; _i < _a.length; _i++) {
|
|
184
|
-
var listener = _a[_i];
|
|
185
|
-
listener(data, this.eventName);
|
|
186
|
-
}
|
|
187
|
-
return data;
|
|
188
|
-
};
|
|
189
|
-
StaticEventImpl.prototype.addListener = function (listener) {
|
|
190
|
-
var _this = this;
|
|
191
|
-
this.eventItems.push(listener);
|
|
192
|
-
return function () {
|
|
193
|
-
var idx = _this.eventItems.indexOf(listener);
|
|
194
|
-
if (idx >= 0)
|
|
195
|
-
_this.eventItems.splice(idx, 1);
|
|
196
|
-
};
|
|
197
|
-
};
|
|
198
|
-
return StaticEventImpl;
|
|
199
|
-
}());
|
|
200
|
-
export function createStaticEvent(eventName, eventItems) {
|
|
201
|
-
return new StaticEventImpl(eventName, eventItems);
|
|
202
|
-
}
|
|
203
|
-
export var defaultEventGroup = new EventGroup();
|
|
204
|
-
export function newEventGroup() {
|
|
205
|
-
return new EventGroup();
|
|
206
|
-
}
|
|
207
|
-
export var enableEventSpying = defaultEventGroup.enableEventSpying.bind(defaultEventGroup);
|
|
208
|
-
export var removeListener = defaultEventGroup.removeListener.bind(defaultEventGroup);
|
|
209
|
-
export var sendEvent = defaultEventGroup.sendEvent.bind(defaultEventGroup);
|
|
210
|
-
export var sendAsyncEvent = defaultEventGroup.sendAsyncEvent.bind(defaultEventGroup);
|
|
211
|
-
export function addListener(eventName, priorityOrListener, listener) {
|
|
212
|
-
defaultEventGroup.addListener(eventName, priorityOrListener, listener);
|
|
213
|
-
}
|
package/src/jk_fs/index.js
DELETED