owebjs 1.5.0-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.
Files changed (2) hide show
  1. package/dist/utils/walk.js +20 -14
  2. package/package.json +1 -1
@@ -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((path2) => {
60
- const lastdir = path2.split("\\").at(-1);
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
- const relativeToRoot = path.relative(process.cwd(), hookPath);
73
- const normalizedFallback = fallbackDir.replace(/\\/g, "/").replace(/\/$/, "");
74
- const normalizedRel = relativeToRoot.replace(/\\/g, "/");
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
- return new URL(`file://${path.join(process.cwd(), finalPath)}`).pathname + "/_hooks.js";
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
- return new URL(hookPath, `file://${__dirname}`).pathname.replaceAll("\\", "/") + "/_hooks.js";
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
- const imp = await import(importPath);
87
- if (imp?.default) {
88
- hookFunctions.push(imp.default);
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({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owebjs",
3
- "version": "1.5.0-dev",
3
+ "version": "1.5.1-dev",
4
4
  "description": "A flexible and modern web framework built on top of Fastify",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",