@primate/core 0.2.2 → 0.2.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/App.d.ts +2 -0
- package/lib/private/App.js +1 -0
- package/lib/private/BindingContext.d.ts +1 -1
- package/lib/private/BuildApp.js +4 -0
- package/lib/private/frontend/Module.js +7 -6
- package/lib/private/hook/build.js +6 -0
- package/lib/private/location.d.ts +1 -0
- package/lib/private/location.js +2 -0
- package/package.json +2 -1
package/lib/private/App.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default class App {
|
|
|
13
13
|
app_html: "app.html";
|
|
14
14
|
build: "build";
|
|
15
15
|
client: "client";
|
|
16
|
+
lib: "lib";
|
|
16
17
|
components: "components";
|
|
17
18
|
config: "config";
|
|
18
19
|
error_html: "error.html";
|
|
@@ -30,6 +31,7 @@ export default class App {
|
|
|
30
31
|
readonly app_html: FileRef;
|
|
31
32
|
readonly build: FileRef;
|
|
32
33
|
readonly client: FileRef;
|
|
34
|
+
readonly lib: FileRef;
|
|
33
35
|
readonly components: FileRef;
|
|
34
36
|
readonly config: FileRef;
|
|
35
37
|
readonly error_html: FileRef;
|
package/lib/private/App.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
type BindingContext = "components" | "config" | "locales" | "modules" | "routes" | "stores";
|
|
1
|
+
type BindingContext = "lib" | "components" | "config" | "locales" | "modules" | "routes" | "stores";
|
|
2
2
|
export type { BindingContext as default };
|
|
3
3
|
//# sourceMappingURL=BindingContext.d.ts.map
|
package/lib/private/BuildApp.js
CHANGED
|
@@ -29,11 +29,15 @@ export default class BuildApp extends App {
|
|
|
29
29
|
contents: "",
|
|
30
30
|
resolveDir: this.root.path,
|
|
31
31
|
},
|
|
32
|
+
conditions: ["style", "browser", "default", "module"],
|
|
32
33
|
resolveExtensions: [".ts", ".js", ...extensions],
|
|
33
34
|
tsconfigRaw: {
|
|
34
35
|
compilerOptions: {
|
|
35
36
|
baseUrl: "${configDir}",
|
|
36
37
|
paths: {
|
|
38
|
+
"#lib/*": [
|
|
39
|
+
"lib/*", ...extensions.map(e => `lib/*${e}`),
|
|
40
|
+
],
|
|
37
41
|
"#component/*": [
|
|
38
42
|
"components/*", ...extensions.map(e => `components/*${e}`),
|
|
39
43
|
],
|
|
@@ -13,6 +13,7 @@ import pema from "pema";
|
|
|
13
13
|
import array from "pema/array";
|
|
14
14
|
import boolean from "pema/boolean";
|
|
15
15
|
import string from "pema/string";
|
|
16
|
+
const contexts = ["lib", "components"];
|
|
16
17
|
async function normalize(path) {
|
|
17
18
|
return `p_${await hash(path)}`;
|
|
18
19
|
}
|
|
@@ -168,16 +169,16 @@ export default class FrontendModule extends Module {
|
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
171
|
const components_filter = new RegExp(`^${name}:components`);
|
|
172
|
+
const components_base = app.root.join(location.components);
|
|
171
173
|
build.onResolve({ filter: components_filter }, ({ path }) => {
|
|
172
174
|
return { namespace: `${name}`, path };
|
|
173
175
|
});
|
|
174
176
|
build.onLoad({ filter: components_filter }, async () => {
|
|
175
|
-
const components = await
|
|
176
|
-
.join(location.components)
|
|
177
|
+
const components = await components_base
|
|
177
178
|
.collect(c => fileExtensions.includes(c.fullExtension));
|
|
178
179
|
let contents = "";
|
|
179
180
|
for (const component of components) {
|
|
180
|
-
const { path } = component.debase(
|
|
181
|
+
const { path } = component.debase(components_base, "/");
|
|
181
182
|
contents += `export { default as ${await normalize(path)} }
|
|
182
183
|
from "#component/${path}";\n`;
|
|
183
184
|
}
|
|
@@ -206,10 +207,10 @@ export default class FrontendModule extends Module {
|
|
|
206
207
|
init(app, next) {
|
|
207
208
|
this.fileExtensions.forEach(e => {
|
|
208
209
|
app.bind(e, async (file, { context }) => {
|
|
209
|
-
assert(context
|
|
210
|
+
assert(contexts.includes(context), `${this.name}: only components or lib supported`);
|
|
210
211
|
if (this.compile.server) {
|
|
211
|
-
const original = file.debase(app.runpath("stage",
|
|
212
|
-
const source = app.path.
|
|
212
|
+
const original = file.debase(app.runpath("stage", context));
|
|
213
|
+
const source = app.path[context].join(original);
|
|
213
214
|
const code = await this.compile.server(await source.text());
|
|
214
215
|
const bundled = await bundle({
|
|
215
216
|
code,
|
|
@@ -157,6 +157,10 @@ const post = async (app) => {
|
|
|
157
157
|
await app.stage(app.path.locales, "locales", file => `export { default } from "#stage/locale${file}";`);
|
|
158
158
|
// stage app config after locales so #locale imports can be resolved
|
|
159
159
|
await app.stage(app.path.config, "config", file => `export { default } from "#stage/config${file}";`);
|
|
160
|
+
// component library
|
|
161
|
+
await app.stage(app.path.lib, "lib", file => `
|
|
162
|
+
export * from "#stage/lib${file}";
|
|
163
|
+
`);
|
|
160
164
|
// stage components
|
|
161
165
|
await app.stage(app.path.components, "components", file => `
|
|
162
166
|
import * as component from "#stage/component${file}";
|
|
@@ -223,10 +227,12 @@ const post = async (app) => {
|
|
|
223
227
|
"#database/*": "./config/database/*.js",
|
|
224
228
|
"#session": "./config/session.js",
|
|
225
229
|
"#i18n": "./config/i18n.js",
|
|
230
|
+
"#lib/*": "./lib/*.js",
|
|
226
231
|
"#component/*": "./components/*.js",
|
|
227
232
|
"#locale/*": "./locales/*.js",
|
|
228
233
|
"#module/*": "./modules/*.js",
|
|
229
234
|
"#route/*": "./routes/*.js",
|
|
235
|
+
"#stage/lib/*": "./stage/lib/*.js",
|
|
230
236
|
"#stage/component/*": "./stage/components/*.js",
|
|
231
237
|
"#stage/locale/*": "./stage/locales/*.js",
|
|
232
238
|
"#stage/config/*": "./stage/config/*.js",
|
package/lib/private/location.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "The universal web framework",
|
|
5
5
|
"homepage": "https://primate.run",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"@rcompat/package": "^0.22.0",
|
|
32
32
|
"@rcompat/record": "^0.9.1",
|
|
33
33
|
"@rcompat/string": "^0.10.0",
|
|
34
|
+
"@rcompat/type": "^0.6.1",
|
|
34
35
|
"pema": "^0.2.0"
|
|
35
36
|
},
|
|
36
37
|
"type": "module",
|