owebjs 1.4.9-dev → 1.5.1-dev
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/avatar.png +0 -0
- package/dist/utils/walk.js +20 -14
- package/dist/uwebsocket/response.js +13 -13
- package/package.json +1 -1
package/avatar.png
CHANGED
|
Binary file
|
package/dist/utils/walk.js
CHANGED
|
@@ -2,9 +2,10 @@ import {
|
|
|
2
2
|
__name
|
|
3
3
|
} from "../chunk-SHUYVCID.js";
|
|
4
4
|
import { readdirSync, statSync } from "node:fs";
|
|
5
|
-
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { mergePaths } from './utils.js';
|
|
8
|
+
import { warn } from './logger.js';
|
|
8
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
10
|
const isParentOrGrandparent = /* @__PURE__ */ __name((parentFolderPath, childFolderPath) => {
|
|
10
11
|
if (childFolderPath.startsWith(parentFolderPath)) {
|
|
@@ -56,8 +57,8 @@ const walk = /* @__PURE__ */ __name(async (directory, tree = [], fallbackDir) =>
|
|
|
56
57
|
hooks
|
|
57
58
|
].flat();
|
|
58
59
|
let scopingSort = copyHooks.sort((a, b) => b.length - a.length);
|
|
59
|
-
const scopeIndex = scopingSort.findIndex((
|
|
60
|
-
const lastdir =
|
|
60
|
+
const scopeIndex = scopingSort.findIndex((pathstr) => {
|
|
61
|
+
const lastdir = pathstr.split(path.sep).at(-1);
|
|
61
62
|
return lastdir.startsWith("(") && lastdir.endsWith(")");
|
|
62
63
|
});
|
|
63
64
|
let useHook = [];
|
|
@@ -68,24 +69,29 @@ const walk = /* @__PURE__ */ __name(async (directory, tree = [], fallbackDir) =>
|
|
|
68
69
|
useHook = hooks;
|
|
69
70
|
}
|
|
70
71
|
const hooksImport = useHook.map((hookPath) => {
|
|
72
|
+
let targetFile = "";
|
|
71
73
|
if (fallbackDir) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
let finalPath = normalizedRel;
|
|
76
|
-
if (!normalizedRel.startsWith(normalizedFallback)) {
|
|
77
|
-
finalPath = path.posix.join(normalizedFallback, normalizedRel);
|
|
74
|
+
let rootWalkDir = directoryResolve;
|
|
75
|
+
for (let i = 0; i < tree.length; i++) {
|
|
76
|
+
rootWalkDir = path.dirname(rootWalkDir);
|
|
78
77
|
}
|
|
79
|
-
|
|
78
|
+
const relHook = path.relative(rootWalkDir, hookPath);
|
|
79
|
+
const targetDir = path.join(process.cwd(), fallbackDir, relHook);
|
|
80
|
+
targetFile = path.join(targetDir, "_hooks.js");
|
|
80
81
|
} else {
|
|
81
|
-
|
|
82
|
+
targetFile = path.join(hookPath, "_hooks.js");
|
|
82
83
|
}
|
|
84
|
+
return pathToFileURL(targetFile).href;
|
|
83
85
|
});
|
|
84
86
|
const hookFunctions = [];
|
|
85
87
|
for (const importPath of hooksImport) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
88
|
+
try {
|
|
89
|
+
const imp = await import(importPath);
|
|
90
|
+
if (imp?.default) {
|
|
91
|
+
hookFunctions.push(imp.default);
|
|
92
|
+
}
|
|
93
|
+
} catch (e) {
|
|
94
|
+
warn(`Failed to load hook from ${importPath}. Make sure the file exists.`);
|
|
89
95
|
}
|
|
90
96
|
}
|
|
91
97
|
results.push({
|
|
@@ -71,8 +71,10 @@ class HttpResponse extends Writable {
|
|
|
71
71
|
//@ts-ignore
|
|
72
72
|
write(data) {
|
|
73
73
|
if (this.finished) return;
|
|
74
|
-
this.
|
|
75
|
-
|
|
74
|
+
this.res.cork(() => {
|
|
75
|
+
this._flushHeaders();
|
|
76
|
+
this.res.write(data);
|
|
77
|
+
});
|
|
76
78
|
}
|
|
77
79
|
writeHead(statusCode) {
|
|
78
80
|
if (this.finished) return;
|
|
@@ -93,17 +95,15 @@ class HttpResponse extends Writable {
|
|
|
93
95
|
//@ts-ignore
|
|
94
96
|
end(data) {
|
|
95
97
|
if (this.finished) return;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
return doWrite();
|
|
98
|
+
this.res.cork(() => {
|
|
99
|
+
this._flushHeaders();
|
|
100
|
+
this.finished = true;
|
|
101
|
+
if (!data) {
|
|
102
|
+
this.res.end();
|
|
103
|
+
} else {
|
|
104
|
+
this.res.end(data);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
107
|
}
|
|
108
108
|
getRaw() {
|
|
109
109
|
return this.res;
|