@primate/core 0.3.2 → 0.3.4
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/BuildApp.d.ts +3 -1
- package/lib/private/BuildApp.js +7 -2
- 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 +2 -1
- package/lib/private/frontend/Module.js +11 -7
- package/lib/private/frontend/bundle-server.d.ts +3 -1
- package/lib/private/frontend/bundle-server.js +4 -4
- package/package.json +1 -1
|
@@ -7,9 +7,11 @@ type Loader = (source: string, file: FileRef) => MaybePromise<string>;
|
|
|
7
7
|
type Resolver = (basename: string, file: FileRef) => string;
|
|
8
8
|
export default class BuildApp extends App {
|
|
9
9
|
#private;
|
|
10
|
-
frontends: Map<string, string>;
|
|
10
|
+
frontends: Map<string, string[]>;
|
|
11
|
+
conditions: Set<string>;
|
|
11
12
|
buildInit(): Promise<void>;
|
|
12
13
|
get id(): string;
|
|
14
|
+
get frontendExtensions(): string[];
|
|
13
15
|
get build(): Build;
|
|
14
16
|
get server_build(): string[];
|
|
15
17
|
addRoot(root: FileRef): void;
|
package/lib/private/BuildApp.js
CHANGED
|
@@ -8,6 +8,7 @@ import cache from "@rcompat/kv/cache";
|
|
|
8
8
|
const s = Symbol("primate.Build");
|
|
9
9
|
export default class BuildApp extends App {
|
|
10
10
|
frontends = new Map();
|
|
11
|
+
conditions = new Set();
|
|
11
12
|
#postbuild = [];
|
|
12
13
|
#roots = [];
|
|
13
14
|
#server_build = ["route"];
|
|
@@ -20,8 +21,12 @@ export default class BuildApp extends App {
|
|
|
20
21
|
get id() {
|
|
21
22
|
return this.#id;
|
|
22
23
|
}
|
|
24
|
+
get frontendExtensions() {
|
|
25
|
+
return [...this.frontends.values()].flat();
|
|
26
|
+
}
|
|
23
27
|
get build() {
|
|
24
|
-
const extensions =
|
|
28
|
+
const extensions = this.frontendExtensions;
|
|
29
|
+
const conditions = this.conditions.values();
|
|
25
30
|
return cache.get(s, () => new Build({
|
|
26
31
|
...(this.config("build")),
|
|
27
32
|
outdir: this.runpath(location.client).path,
|
|
@@ -29,7 +34,7 @@ export default class BuildApp extends App {
|
|
|
29
34
|
contents: "",
|
|
30
35
|
resolveDir: this.root.path,
|
|
31
36
|
},
|
|
32
|
-
conditions: ["style", "browser", "default", "module"],
|
|
37
|
+
conditions: ["style", "browser", "default", "module", ...conditions],
|
|
33
38
|
resolveExtensions: [".ts", ".js", ...extensions],
|
|
34
39
|
tsconfigRaw: {
|
|
35
40
|
compilerOptions: {
|
|
@@ -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,11 +24,12 @@ 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;
|
|
31
31
|
};
|
|
32
|
+
conditions: string[];
|
|
32
33
|
static schema: import("pema").ObjectType<{
|
|
33
34
|
fileExtensions: import("pema").OptionalType<import("pema/array").ArrayType<import("pema/string").StringType>>;
|
|
34
35
|
spa: import("pema").DefaultType<import("pema/boolean").BooleanType, true>;
|
|
@@ -23,6 +23,7 @@ export default class FrontendModule extends Module {
|
|
|
23
23
|
root;
|
|
24
24
|
compile = {};
|
|
25
25
|
css;
|
|
26
|
+
conditions = [];
|
|
26
27
|
static schema = pema({
|
|
27
28
|
fileExtensions: array(string).optional(),
|
|
28
29
|
spa: boolean.default(true),
|
|
@@ -64,10 +65,10 @@ export default class FrontendModule extends Module {
|
|
|
64
65
|
const app_asset = app.assets.find(asset => asset.src?.includes("app") && asset.src.endsWith(".js"));
|
|
65
66
|
if (!app_asset)
|
|
66
67
|
throw fail("Could not find app.js in assets");
|
|
67
|
-
const app_script = `<script type="module" src="${app_asset.src}"
|
|
68
|
+
const app_script = `<script type="module" src="${app_asset.src}"></script>`;
|
|
68
69
|
const json_props = JSON.stringify({ frontend: this.name, ...client });
|
|
69
70
|
const hydrated = await inline(json_props, APPLICATION_JSON, "hydration");
|
|
70
|
-
const script_src = [hydrated.integrity
|
|
71
|
+
const script_src = [hydrated.integrity];
|
|
71
72
|
return {
|
|
72
73
|
body,
|
|
73
74
|
head: head.concat(app_script, hydrated.head),
|
|
@@ -138,7 +139,7 @@ export default class FrontendModule extends Module {
|
|
|
138
139
|
}
|
|
139
140
|
catch (error) {
|
|
140
141
|
const path = `${location.views}/${view}`;
|
|
141
|
-
throw fail("error in view{0}\n{1}", path, error);
|
|
142
|
+
throw fail("error in view {0}\n{1}", path, error);
|
|
142
143
|
}
|
|
143
144
|
};
|
|
144
145
|
serve(app, next) {
|
|
@@ -147,9 +148,10 @@ export default class FrontendModule extends Module {
|
|
|
147
148
|
}
|
|
148
149
|
publish(app) {
|
|
149
150
|
if (this.compile.client) {
|
|
150
|
-
const { compile, css, fileExtensions, name, root } = this;
|
|
151
|
+
const { compile, css, fileExtensions, name, root, conditions } = this;
|
|
151
152
|
if (this.client) {
|
|
152
|
-
|
|
153
|
+
app.frontends.set(name, fileExtensions);
|
|
154
|
+
conditions.forEach(condition => app.conditions.add(condition));
|
|
153
155
|
}
|
|
154
156
|
app.build.plugin({
|
|
155
157
|
name,
|
|
@@ -217,13 +219,15 @@ export default class FrontendModule extends Module {
|
|
|
217
219
|
app.bind(e, async (file, { context }) => {
|
|
218
220
|
assert(contexts.includes(context), `${this.name}: only components supported`);
|
|
219
221
|
if (this.compile.server) {
|
|
220
|
-
const code = await this.compile.server(await file.text());
|
|
222
|
+
const code = await this.compile.server(await file.text(), file);
|
|
221
223
|
const bundled = await bundle({
|
|
222
224
|
code,
|
|
223
225
|
source: file,
|
|
224
226
|
root: app.root,
|
|
225
227
|
extensions: this.fileExtensions,
|
|
226
|
-
compile: async (s) => this.compile.server(s),
|
|
228
|
+
compile: async (s, f) => this.compile.server(s, f),
|
|
229
|
+
bundle: app.config("bundle"),
|
|
230
|
+
conditions: [...app.conditions],
|
|
227
231
|
});
|
|
228
232
|
return bundled;
|
|
229
233
|
}
|
|
@@ -5,7 +5,9 @@ type Init = {
|
|
|
5
5
|
root: FileRef;
|
|
6
6
|
extensions: string[];
|
|
7
7
|
compile: (src: string, file?: FileRef) => Promise<string>;
|
|
8
|
+
bundle: string[];
|
|
9
|
+
conditions: string[];
|
|
8
10
|
};
|
|
9
|
-
export default function
|
|
11
|
+
export default function bundle_server(init: Init): Promise<string>;
|
|
10
12
|
export {};
|
|
11
13
|
//# 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
|
});
|
|
@@ -32,7 +32,7 @@ export default async function bundleServer(init) {
|
|
|
32
32
|
platform: "node",
|
|
33
33
|
format: "esm",
|
|
34
34
|
target: "esnext",
|
|
35
|
-
conditions: ["node", "default",
|
|
35
|
+
conditions: ["node", "default", ...init.conditions],
|
|
36
36
|
resolveExtensions: [".ts", ".js", ...extensions],
|
|
37
37
|
plugins: [plugin],
|
|
38
38
|
stdin: {
|