primate 0.29.5 → 0.29.7

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": "primate",
3
- "version": "0.29.5",
3
+ "version": "0.29.7",
4
4
  "description": "Polymorphic development platform",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
package/src/app.js CHANGED
@@ -238,8 +238,8 @@ export default async (log, root, config) => {
238
238
  const dependency = File.resolve().join(...path);
239
239
  const target = File.join(this.runpath(client), this.library, ...parts);
240
240
  await dependency.copy(target);
241
- this.importmaps = {
242
- ...valmap(exports, value => File.join(root, this.library, value).path),
241
+ this.importmaps = { ...valmap(exports, value =>
242
+ File.join(root, this.library, value).normalize()),
243
243
  ...this.importmaps };
244
244
  },
245
245
  };
@@ -3,15 +3,14 @@ import { from, valmap } from "rcompat/object";
3
3
  import { tryreturn } from "rcompat/async";
4
4
  import errors from "../errors.js";
5
5
 
6
- const deslash = url => url.replaceAll(/(?<!http:)\/{2,}/gu, _ => "/");
7
-
8
6
  const parse_body = (request, url) =>
9
7
  tryreturn(async _ => await Body.parse(request) ?? {})
10
8
  .orelse(error => errors.MismatchedBody.throw(url.pathname, error.message));
11
9
 
12
10
  export default dispatch => async original => {
13
11
  const { headers } = original;
14
- const url = new URL(deslash(globalThis.decodeURIComponent(original.url)));
12
+
13
+ const url = new URL(globalThis.decodeURIComponent(original.url));
15
14
  const cookies = headers.get("cookie");
16
15
  const body = await parse_body(original, url);
17
16
 
@@ -16,7 +16,7 @@ const post = async app => {
16
16
  type: "module",
17
17
  });
18
18
 
19
- const imports = { ...app.importmaps, app: src.path };
19
+ const imports = { ...app.importmaps, app: src.normalize() };
20
20
  const type = "importmap";
21
21
  await app.publish({ inline: true, code: stringify({ imports }), type });
22
22
  }
@@ -39,9 +39,11 @@ export default app => {
39
39
  is_method({ route, method, pathname }));
40
40
 
41
41
  const index = path => `${location.routes}${path === "/" ? "/index" : path}`;
42
+ // remove excess slashes
43
+ const deslash = url => url.replaceAll(/\/{2,}/gu, _ => "/");
42
44
 
43
45
  return ({ original: { method }, url }) => {
44
- const pathname = deroot(url.pathname);
46
+ const pathname = deroot(deslash(url.pathname));
45
47
  const route = find(method, pathname) ?? errors.NoRouteToPath
46
48
  .throw(method.toLowerCase(), pathname, index(pathname));
47
49
  return { ...route, path: to_path(route, pathname) };
@@ -1,11 +1,14 @@
1
1
  import { tryreturn } from "rcompat/sync";
2
2
  import { from } from "rcompat/object";
3
+ import { File } from "rcompat/fs";
3
4
  import { default as fs, doubled } from "./common.js";
4
5
  import * as get from "./routes/exports.js";
5
6
  import errors from "../errors.js";
6
7
 
8
+ const { separator } = File;
9
+
7
10
  const make = path => {
8
- const double = doubled(path.split("/")
11
+ const double = doubled(path.split(separator)
9
12
  .filter(part => part.startsWith("{") && part.endsWith("}"))
10
13
  .map(part => part.slice(1, part.indexOf("="))));
11
14
  double && errors.DoublePathParameter.throw(double, path);
@@ -17,7 +20,8 @@ const make = path => {
17
20
  return `(?<${param}>[^/]{1,}?)`;
18
21
  }).orelse(_ => errors.InvalidPathParameter.throw(named, path)));
19
22
 
20
- return new RegExp(`^/${route}$`, "u");
23
+ // normalize to unix
24
+ return new RegExp(`^/${route.replaceAll(separator, "/")}$`, "u");
21
25
  };
22
26
 
23
27
  export default async (app, load = fs) => {
@@ -38,7 +42,7 @@ export default async (app, load = fs) => {
38
42
  return Object.entries(route).map(([method, handler]) => ({
39
43
  method,
40
44
  handler,
41
- pathname: make(path.endsWith("/") ? path.slice(0, -1) : path),
45
+ pathname: make(path.endsWith(separator) ? path.slice(0, -1) : path),
42
46
  guards: routes.guards.filter(filtered).map(([, guard]) => guard.default),
43
47
  errors: routes.errors.filter(filtered).map(([, error]) => error.default),
44
48
  layouts: routes.layouts.filter(filtered).map(([, layout]) => layout),