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 +1 -1
- package/src/app.js +15 -11
- package/src/hooks/handle.js +3 -3
- package/src/loaders/routes.js +4 -4
package/package.json
CHANGED
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(
|
|
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((
|
|
87
|
-
`${
|
|
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
|
|
146
|
-
const path = [library, ...
|
|
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(([,
|
|
152
|
-
||
|
|
153
|
-
||
|
|
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,
|
|
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,
|
|
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)),
|
package/src/hooks/handle.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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
|
};
|
package/src/loaders/routes.js
CHANGED
|
@@ -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 $
|
|
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:
|
|
44
|
-
errors:
|
|
45
|
-
layouts:
|
|
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
|
};
|