@primate/core 0.3.1 → 0.3.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/lib/private/ServeApp.js +1 -1
- package/lib/private/config/index.d.ts +1 -0
- package/lib/private/config/schema.d.ts +1 -0
- package/lib/private/config/schema.js +3 -2
- package/lib/private/frontend/Module.d.ts +1 -1
- package/lib/private/frontend/Module.js +6 -5
- package/lib/private/frontend/bundle-server.d.ts +2 -1
- package/lib/private/frontend/bundle-server.js +3 -3
- package/package.json +1 -1
package/lib/private/ServeApp.js
CHANGED
|
@@ -280,7 +280,7 @@ export default class ServeApp extends App {
|
|
|
280
280
|
const verbs = router.get(v);
|
|
281
281
|
const routeHandler = verbs[verb];
|
|
282
282
|
return routeHandler?.handler;
|
|
283
|
-
}).filter(Boolean)])
|
|
283
|
+
}).filter(Boolean).toReversed()])
|
|
284
284
|
.get();
|
|
285
285
|
const verbs = router.get(route.path);
|
|
286
286
|
const routePath = verbs[verb];
|
|
@@ -2,6 +2,7 @@ import Module from "#Module";
|
|
|
2
2
|
import FileRef from "@rcompat/fs/FileRef";
|
|
3
3
|
declare const _default: import("pema").ObjectType<{
|
|
4
4
|
build: import("pema").OptionalType<import("pema/record").RecordType<import("pema/string").StringType, import("pema/unknown").UnknownType>>;
|
|
5
|
+
bundle: import("pema").DefaultType<import("pema/array").ArrayType<import("pema/string").StringType>, string[]>;
|
|
5
6
|
http: import("pema").ObjectType<{
|
|
6
7
|
csp: import("pema").OptionalType<import("pema/record").RecordType<import("pema/string").StringType, import("pema/array").ArrayType<import("pema/string").StringType>>>;
|
|
7
8
|
headers: import("pema").OptionalType<import("pema/record").RecordType<import("pema/string").StringType, import("pema/string").StringType>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Module from "#Module";
|
|
2
2
|
import FileRef from "@rcompat/fs/FileRef";
|
|
3
|
-
import
|
|
3
|
+
import p from "pema";
|
|
4
4
|
import array from "pema/array";
|
|
5
5
|
import boolean from "pema/boolean";
|
|
6
6
|
import constructor from "pema/constructor";
|
|
@@ -9,8 +9,9 @@ import string from "pema/string";
|
|
|
9
9
|
import uint from "pema/uint";
|
|
10
10
|
import union from "pema/union";
|
|
11
11
|
import unknown from "pema/unknown";
|
|
12
|
-
export default
|
|
12
|
+
export default p({
|
|
13
13
|
build: record(string, unknown).optional(),
|
|
14
|
+
bundle: p.array(p.string).default([]),
|
|
14
15
|
http: {
|
|
15
16
|
csp: record(string, array(string)).optional(),
|
|
16
17
|
headers: record(string, string).optional(),
|
|
@@ -24,7 +24,7 @@ export default abstract class FrontendModule<S = ServerView> extends Module {
|
|
|
24
24
|
css?: null | string;
|
|
25
25
|
js: string;
|
|
26
26
|
}>;
|
|
27
|
-
server?: (text: string) => MaybePromise<string>;
|
|
27
|
+
server?: (text: string, file?: FileRef) => MaybePromise<string>;
|
|
28
28
|
};
|
|
29
29
|
css?: {
|
|
30
30
|
filter: RegExp;
|
|
@@ -64,10 +64,10 @@ export default class FrontendModule extends Module {
|
|
|
64
64
|
const app_asset = app.assets.find(asset => asset.src?.includes("app") && asset.src.endsWith(".js"));
|
|
65
65
|
if (!app_asset)
|
|
66
66
|
throw fail("Could not find app.js in assets");
|
|
67
|
-
const app_script = `<script type="module" src="${app_asset.src}"
|
|
67
|
+
const app_script = `<script type="module" src="${app_asset.src}"></script>`;
|
|
68
68
|
const json_props = JSON.stringify({ frontend: this.name, ...client });
|
|
69
69
|
const hydrated = await inline(json_props, APPLICATION_JSON, "hydration");
|
|
70
|
-
const script_src = [hydrated.integrity
|
|
70
|
+
const script_src = [hydrated.integrity];
|
|
71
71
|
return {
|
|
72
72
|
body,
|
|
73
73
|
head: head.concat(app_script, hydrated.head),
|
|
@@ -138,7 +138,7 @@ export default class FrontendModule extends Module {
|
|
|
138
138
|
}
|
|
139
139
|
catch (error) {
|
|
140
140
|
const path = `${location.views}/${view}`;
|
|
141
|
-
throw fail("error in view{0}\n{1}", path, error);
|
|
141
|
+
throw fail("error in view {0}\n{1}", path, error);
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
serve(app, next) {
|
|
@@ -217,13 +217,14 @@ export default class FrontendModule extends Module {
|
|
|
217
217
|
app.bind(e, async (file, { context }) => {
|
|
218
218
|
assert(contexts.includes(context), `${this.name}: only components supported`);
|
|
219
219
|
if (this.compile.server) {
|
|
220
|
-
const code = await this.compile.server(await file.text());
|
|
220
|
+
const code = await this.compile.server(await file.text(), file);
|
|
221
221
|
const bundled = await bundle({
|
|
222
222
|
code,
|
|
223
223
|
source: file,
|
|
224
224
|
root: app.root,
|
|
225
225
|
extensions: this.fileExtensions,
|
|
226
|
-
compile: async (s) => this.compile.server(s),
|
|
226
|
+
compile: async (s, f) => this.compile.server(s, f),
|
|
227
|
+
bundle: app.config("bundle"),
|
|
227
228
|
});
|
|
228
229
|
return bundled;
|
|
229
230
|
}
|
|
@@ -5,7 +5,8 @@ type Init = {
|
|
|
5
5
|
root: FileRef;
|
|
6
6
|
extensions: string[];
|
|
7
7
|
compile: (src: string, file?: FileRef) => Promise<string>;
|
|
8
|
+
bundle: string[];
|
|
8
9
|
};
|
|
9
|
-
export default function
|
|
10
|
+
export default function bundle_server(init: Init): Promise<string>;
|
|
10
11
|
export {};
|
|
11
12
|
//# sourceMappingURL=bundle-server.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import FileRef from "@rcompat/fs/FileRef";
|
|
2
2
|
import * as esbuild from "esbuild";
|
|
3
|
-
export default async function
|
|
4
|
-
const { code, source, root, extensions, compile } = init;
|
|
3
|
+
export default async function bundle_server(init) {
|
|
4
|
+
const { code, source, root, extensions, compile, bundle } = init;
|
|
5
5
|
const filter = new RegExp(`(${extensions.map(e => e.replace(".", "\\.")).join("|")})$`);
|
|
6
6
|
const plugin = {
|
|
7
7
|
name: "primate/bundle/server",
|
|
@@ -18,7 +18,7 @@ export default async function bundleServer(init) {
|
|
|
18
18
|
const p = args.path;
|
|
19
19
|
const relative = p.startsWith("./") || p.startsWith("../");
|
|
20
20
|
const views = p.startsWith("#view/");
|
|
21
|
-
if (!relative && !views)
|
|
21
|
+
if (!relative && !views && !bundle.includes(p))
|
|
22
22
|
return { path: p, external: true };
|
|
23
23
|
return null;
|
|
24
24
|
});
|