@zerotal/core 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerotal/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
5
  "maturity": "stable",
6
6
  "private": false,
@@ -42,6 +42,7 @@ import { isProdLike } from "../support/env.ts";
42
42
  import { appKeyStrengthWarning } from "../support/appKey.ts";
43
43
  import { runBootDoctor } from "./BootDoctor.ts";
44
44
  import { runConfigValidators } from "../config/validation.ts";
45
+ import { pathToFileURL } from "node:url";
45
46
  import { currentApp, defaultApp, setDefaultApp } from "./currentApp.ts";
46
47
  import type { ConfigValidator, RegisteredConfigValidator } from "../config/validation.ts";
47
48
 
@@ -1040,7 +1041,7 @@ export class Application {
1040
1041
 
1041
1042
  private async _loadRoutes(): Promise<void> {
1042
1043
  for (const { file, prefix, middleware } of this._routeGroups) {
1043
- await Router.groupAsync({ prefix, middleware }, () => import(file));
1044
+ await Router.groupAsync({ prefix, middleware }, () => import(_toImportable(file)));
1044
1045
  }
1045
1046
  }
1046
1047
 
@@ -1669,3 +1670,26 @@ export class Application {
1669
1670
  };
1670
1671
  }
1671
1672
  }
1673
+
1674
+ /**
1675
+ * Make a route-file path safe to hand to `import()`.
1676
+ *
1677
+ * `routing({ web: `${import.meta.dir}/../routes/index.ts` })` is the documented
1678
+ * way to point at a routes file, and on Windows that produces `C:\…\routes\…`.
1679
+ * Passed straight to `import()` the drive letter reads as a URL protocol, so the
1680
+ * module never loads and every route 404s with nothing logged. A `file://` URL
1681
+ * removes the ambiguity.
1682
+ *
1683
+ * Bare specifiers are left alone — someone may legitimately point at a package.
1684
+ */
1685
+ function _toImportable(file: string): string {
1686
+ // Character checks rather than a regex: the separator can be either slash on
1687
+ // Windows, and an escaped one inside a character class is the kind of detail
1688
+ // that silently matches half of what it should.
1689
+ const sep = file[2];
1690
+ const isWindowsPath = file.length > 2 && file[1] === ":" && (sep === "\\" || sep === "/");
1691
+ const isPosixPath = file.startsWith("/");
1692
+
1693
+ if (!isWindowsPath && !isPosixPath) return file;
1694
+ return pathToFileURL(file).href;
1695
+ }