primate 0.21.1 → 0.21.3

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.21.1",
3
+ "version": "0.21.3",
4
4
  "description": "Expressive, minimal and extensible web framework",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
package/src/app.js CHANGED
@@ -21,7 +21,7 @@ const fallback = (app, page) =>
21
21
 
22
22
  // use user-provided file or fall back to default
23
23
  const index = (app, page) =>
24
- tryreturn(_ => File.read(`${app.paths.pages.join(name)}`))
24
+ tryreturn(_ => File.read(`${app.paths.pages.join(page)}`))
25
25
  .orelse(_ => fallback(app, page));
26
26
 
27
27
  const encoder = new TextEncoder();
@@ -83,8 +83,8 @@ export default async (config, root, log) => {
83
83
  }));
84
84
  },
85
85
  headers() {
86
- const csp = Object.keys(http.csp).reduce((policy_string, key) =>
87
- `${policy_string}${key} ${http.csp[key]};`, "")
86
+ const csp = Object.keys(http.csp).reduce((policy, key) =>
87
+ `${policy}${key} ${http.csp[key]};`, "")
88
88
  .replace("script-src 'self'", `script-src 'self' ${
89
89
  app.assets
90
90
  .filter(({type}) => type !== "style")
@@ -141,16 +141,16 @@ export default async (config, root, log) => {
141
141
  this.entrypoints.push({type, code});
142
142
  },
143
143
  async import(module) {
144
- const {build} = config;
145
- const {root} = http.static;
146
- const path = [library, ...module.split("/")];
144
+ const {build: {modules}, http: {static: {root}}} = this.config;
145
+ const parts = module.split("/");
146
+ const path = [library, ...parts];
147
147
  const pkg = await Path.resolve().join(...path, packager).json();
148
148
  const exports = pkg.exports === undefined
149
149
  ? {[module]: `/${module}/${pkg.main}`}
150
150
  : transform(pkg.exports, entry => entry
151
- .filter(([, _export]) => _export.browser?.default !== undefined
152
- || _export.import !== undefined
153
- || _export.default !== undefined)
151
+ .filter(([, export$]) => export$.browser?.default !== undefined
152
+ || export$.import !== undefined
153
+ || export$.default !== undefined)
154
154
  .map(([key, value]) => [
155
155
  key.replace(".", module),
156
156
  value.browser?.default.replace(".", `./${module}`)
@@ -158,10 +158,10 @@ export default async (config, root, log) => {
158
158
  ?? value.import?.replace(".", `./${module}`),
159
159
  ]));
160
160
  const dependency = Path.resolve().join(...path);
161
- const to = new Path(this.build.paths.client, build.modules, ...module.split("/"));
161
+ const to = new Path(this.build.paths.client, modules, ...parts);
162
162
  await dependency.file.copy(to);
163
163
  this.importmaps = {
164
- ...valmap(exports, value => new Path(root, build.modules, value).path),
164
+ ...valmap(exports, value => new Path(root, modules, value).path),
165
165
  ...this.importmaps};
166
166
  },
167
167
  types,
@@ -169,10 +169,14 @@ export default async (config, root, log) => {
169
169
  dispatch: dispatch(types),
170
170
  };
171
171
 
172
+ const error = await app.paths.routes.join("+error.js");
172
173
  const modules = await loaders.modules(app, root, config);
173
174
 
174
175
  return {...app,
175
176
  modules,
177
+ error: {
178
+ default: await error.exists ? (await import(error)).default : undefined,
179
+ },
176
180
  layoutDepth: Math.max(...app.routes.map(({layouts}) => layouts.length)) + 1,
177
181
  route: hooks.route({...app, modules}),
178
182
  parse: hooks.parse(dispatch(types)),
@@ -14,7 +14,7 @@ export default app => {
14
14
  const route = async request => {
15
15
  const {pathname} = request.url;
16
16
  // if NoFileForPath is thrown, this will remain undefined
17
- let errorHandler = undefined;
17
+ let errorHandler = app.error.default;
18
18
 
19
19
  return tryreturn(async _ => {
20
20
  const {path, guards, errors, layouts, handler} = invalid(pathname)
@@ -50,9 +50,9 @@ export default app => {
50
50
  }, request);
51
51
  }).orelse(async error => {
52
52
  app.log.auto(error);
53
- console.log("HI")
53
+
54
54
  // the +error.js page itself could fail
55
- return tryreturn(_ => respond(errorHandler())(app, {}, request))
55
+ return tryreturn(_ => respond(errorHandler(request))(app, {}, request))
56
56
  .orelse(_ => clientError()(app, {}, request));
57
57
  });
58
58
  };
@@ -26,7 +26,7 @@ const make = path => {
26
26
  const specials = ["guards", "errors", "layouts"];
27
27
  export default async (log, directory, load = fs) => {
28
28
  const routes = await get.routes(log, directory, load);
29
- const $routes = from(await Promise.all(specials.map(async extra =>
29
+ const routes$ = from(await Promise.all(specials.map(async extra =>
30
30
  [extra, await get[extra](log, directory, load)])));
31
31
  const filter = path => ([name]) => path.includes(name);
32
32
 
@@ -40,9 +40,9 @@ export default async (log, directory, load = fs) => {
40
40
  method,
41
41
  handler,
42
42
  pathname: make(path.endsWith("/") ? path.slice(0, -1) : path),
43
- guards: $routes.guards.filter(filter(path)).map(([, guard]) => guard),
44
- errors: $routes.errors.filter(filter(path)).map(([, error]) => error),
45
- layouts: $routes.layouts.filter(filter(path)).map(([, layout]) => layout),
43
+ guards: routes$.guards.filter(filter(path)).map(([, guard]) => guard),
44
+ errors: routes$.errors.filter(filter(path)).map(([, error]) => error),
45
+ layouts: routes$.layouts.filter(filter(path)).map(([, layout]) => layout),
46
46
  }));
47
47
  }).flat();
48
48
  };