owebjs 1.5.0-dev → 1.5.2-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/dist/utils/assignRoutes.js +2 -2
- package/dist/utils/walk.js +20 -14
- package/package.json +1 -1
|
@@ -265,10 +265,10 @@ function inner(oweb, route) {
|
|
|
265
265
|
}, "corkedOp");
|
|
266
266
|
corkedOp(() => {
|
|
267
267
|
res.raw.writeHead(200, {
|
|
268
|
+
...res.getHeaders(),
|
|
268
269
|
"Content-Type": "text/event-stream",
|
|
269
270
|
"Cache-Control": "no-cache",
|
|
270
|
-
Connection: "keep-alive"
|
|
271
|
-
"Access-Control-Allow-Origin": "*"
|
|
271
|
+
Connection: "keep-alive"
|
|
272
272
|
});
|
|
273
273
|
if (res.raw.flushHeaders) {
|
|
274
274
|
res.raw.flushHeaders();
|
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({
|