primate 0.22.3 → 0.23.0

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/README.md CHANGED
@@ -1,7 +1,14 @@
1
- # Primate core framework
1
+ # Primate
2
2
 
3
- This package contains the core framework code.
3
+ Expressive, minimal and extensible web framework. To start [read guide].
4
4
 
5
- See the [Getting started][getting-started] guide for documentation.
5
+ ## Resources
6
6
 
7
- [getting-started]: https://primatejs.com/guide/getting-started
7
+ * Website: https://primatejs.com
8
+ * IRC: Join the `#primate` channel on `irc.libera.chat`
9
+
10
+ ## License
11
+
12
+ MIT
13
+
14
+ [read guide]: https://primatejs.com/guide/getting-started
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.22.3",
3
+ "version": "0.23.0",
4
4
  "description": "Expressive, minimal and extensible web framework",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
@@ -18,10 +18,10 @@
18
18
  "directory": "packages/primate"
19
19
  },
20
20
  "dependencies": {
21
- "runtime-compat": "^0.25.8"
21
+ "runtime-compat": "^0.27.1"
22
22
  },
23
23
  "engines": {
24
- "node": ">=18.16"
24
+ "node": ">=18"
25
25
  },
26
26
  "type": "module",
27
27
  "exports": "./src/exports.js"
package/src/app.js CHANGED
@@ -3,8 +3,10 @@ import {tryreturn} from "runtime-compat/async";
3
3
  import {File, Path} from "runtime-compat/fs";
4
4
  import {bold, blue} from "runtime-compat/colors";
5
5
  import {is} from "runtime-compat/dyndef";
6
- import {transform, valmap} from "runtime-compat/object";
6
+ import {transform, valmap, to} from "runtime-compat/object";
7
7
  import {globify} from "runtime-compat/string";
8
+ import * as runtime from "runtime-compat/meta";
9
+
8
10
  import errors from "./errors.js";
9
11
  import {print} from "./Logger.js";
10
12
  import dispatch from "./dispatch.js";
@@ -14,10 +16,6 @@ import * as loaders from "./loaders/exports.js";
14
16
 
15
17
  const {DoubleFileExtension} = errors;
16
18
 
17
- // do not hard-depend on node
18
- const packager = import.meta.runtime?.packager ?? "package.json";
19
- const library = import.meta.runtime?.library ?? "node_modules";
20
-
21
19
  // use user-provided file or fall back to default
22
20
  const index = (base, page, fallback) =>
23
21
  tryreturn(_ => File.read(`${base.join(page)}`))
@@ -32,12 +30,12 @@ const attribute = attributes => Object.keys(attributes).length > 0
32
30
  const tag = ({name, attributes = {}, code = "", close = true}) =>
33
31
  `<${name}${attribute(attributes)}${close ? `>${code}</${name}>` : "/>"}`;
34
32
 
35
- const base = new Path(import.meta.url).up(1);
33
+ const {name, version} = await new Path(import.meta.url).up(2)
34
+ .join(runtime.manifest).json();
36
35
 
37
36
  export default async (log, root, config) => {
38
37
  const {http} = config;
39
38
  const secure = http?.ssl !== undefined;
40
- const {name, version} = await base.up(1).join(packager).json();
41
39
  const path = valmap(config.location, value => root.join(value));
42
40
 
43
41
  const at = `at http${secure ? "s" : ""}://${http.host}:${http.port}\n`;
@@ -52,7 +50,6 @@ export default async (log, root, config) => {
52
50
  const types = await loaders.types(log, path.types);
53
51
  const error = await path.routes.join("+error.js");
54
52
  const routes = await loaders.routes(log, path.routes);
55
- const modules = await loaders.modules(log, root, config);
56
53
 
57
54
  return {
58
55
  config,
@@ -75,9 +72,8 @@ export default async (log, root, config) => {
75
72
  depth: Math.max(...routes.map(({layouts}) => layouts.length)) + 1,
76
73
  },
77
74
  dispatch: dispatch(types),
78
- modules,
79
- packager,
80
- library,
75
+ modules: await loaders.modules(log, root, config),
76
+ ...runtime,
81
77
  // copy files to build folder, potentially transforming them
82
78
  async stage(source, directory, filter) {
83
79
  const {paths, mapper} = this.config.build.transform;
@@ -182,7 +178,7 @@ export default async (log, root, config) => {
182
178
 
183
179
  const parts = module.split("/");
184
180
  const path = [this.library, ...parts];
185
- const pkg = await Path.resolve().join(...path, this.packager).json();
181
+ const pkg = await Path.resolve().join(...path, this.manifest).json();
186
182
  const exports = pkg.exports === undefined
187
183
  ? {[module]: `/${module}/${pkg.main}`}
188
184
  : transform(pkg.exports, entry => entry
package/src/errors.json CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  {
4
2
  "module": "primate",
5
3
  "errors": {
@@ -1,3 +1,3 @@
1
1
  import {cascade} from "runtime-compat/async";
2
2
 
3
- export default app => cascade(app.modules.bundle)(app);
3
+ export default async app => (await cascade(app.modules.bundle))(app);
@@ -30,10 +30,16 @@ const pre = async app => {
30
30
  await app.stage(path.components, to, /^.*.js$/u);
31
31
  }
32
32
 
33
+ if (await path.static.exists) {
34
+ // copy static files to build/server/static
35
+ await app.stage(path.static, new Path(location.server, location.static));
36
+ }
37
+
33
38
  // copy additional subdirectories to build/server
34
39
  await copy_includes(app, location.server);
35
40
 
36
41
  return app;
37
42
  };
38
43
 
39
- export default async app => cascade(app.modules.compile)(await pre(app));
44
+ export default async app =>
45
+ (await cascade(app.modules.compile))(await pre(app));
@@ -43,7 +43,7 @@ export default app => {
43
43
  }
44
44
 
45
45
  // handle request
46
- const response = cascade(app.modules.route, handler)({...request, path});
46
+ const response = (await cascade(app.modules.route, handler))({...request, path});
47
47
  return (await respond(await response))(app, {
48
48
  layouts: await Promise.all(layouts.map(layout => layout(request))),
49
49
  }, request);
package/src/hooks/init.js CHANGED
@@ -1,3 +1,3 @@
1
1
  import {cascade} from "runtime-compat/async";
2
2
 
3
- export default app => cascade(app.modules.init)(app);
3
+ export default async app => (await cascade(app.modules.init))(app);
@@ -59,4 +59,5 @@ const post = async app => {
59
59
  return app;
60
60
  };
61
61
 
62
- export default async app => post(await cascade(app.modules.publish)(app));
62
+ export default async app =>
63
+ post(await (await cascade(app.modules.publish))(app));
@@ -1,3 +1,3 @@
1
1
  import {cascade} from "runtime-compat/async";
2
2
 
3
- export default app => cascade(app.modules.register)(app);
3
+ export default async app => (await cascade(app.modules.register))(app);
@@ -2,5 +2,5 @@ import {cascade} from "runtime-compat/async";
2
2
 
3
3
  export default async (app, server) => {
4
4
  app.log.info("running serve hooks", {module: "primate"});
5
- await cascade(app.modules.serve)({...app, server});
5
+ await (await cascade(app.modules.serve))({...app, server});
6
6
  };
package/src/start.js CHANGED
@@ -4,23 +4,25 @@ import * as hooks from "./hooks/exports.js";
4
4
 
5
5
  export default async (app$, deactivated = []) => {
6
6
  // run one-time hooks
7
- const app = await cascade(["init", "register", "compile", "publish", "bundle"]
8
- .filter(hook => !deactivated.includes(hook))
9
- .map(hook => async (input, next) => {
10
- app$.log.info(`running ${hook} hooks`, {module: "primate"});
11
- return next(await hooks[hook](input));
12
- }))(app$);
7
+ let app = app$;
8
+ for (const hook of ["init", "register", "compile", "publish", "bundle"]) {
9
+ if (deactivated.includes(hook)) {
10
+ continue;
11
+ }
12
+ app.log.info(`running ${hook} hooks`, {module: "primate"});
13
+ app = await hooks[hook](app);
14
+ }
13
15
 
14
16
  app.route = hooks.route(app);
15
17
  app.parse = hooks.parse(app.dispatch);
16
18
 
17
19
  const server = await serve(async request =>
18
- tryreturn(async _ => hooks.handle(app)(await app.parse(request)))
20
+ tryreturn(async _ => (await hooks.handle(app))(await app.parse(request)))
19
21
  .orelse(error => {
20
22
  app.log.auto(error);
21
23
  return new Response(null, {status: Status.INTERNAL_SERVER_ERROR});
22
24
  }),
23
25
  app.config.http);
24
26
 
25
- await cascade(app.modules.serve)({...app, server});
27
+ await (await cascade(app.modules.serve))({...app, server});
26
28
  };