@primate/native 0.1.1 → 0.1.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/native",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Primate native applications",
5
5
  "homepage": "https://primatejs.com/modules/native",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
@@ -16,10 +16,10 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@rcompat/cli": "^0.5.1",
19
- "@rcompat/fs": "^0.4.1",
19
+ "@rcompat/fs": "^0.5.0",
20
20
  "@rcompat/stdio": "^0.5.0",
21
21
  "@rcompat/webview": "^0.7.0",
22
- "@primate/core": "^0.1.1"
22
+ "@primate/core": "^0.1.5"
23
23
  },
24
24
  "type": "module",
25
25
  "exports": {
package/src/desktop.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import collect from "@rcompat/fs/collect";
2
+ import webpath from "@rcompat/fs/webpath";
3
+
2
4
  const html = /^.*.html$/u;
3
5
 
4
6
  export default async app => {
@@ -6,6 +8,12 @@ export default async app => {
6
8
  const http = app.get("http");
7
9
  const client = app.runpath(location.client);
8
10
  const re = /app..*(?:js|css)$/u;
11
+
12
+ const import_statics = (await client.collect()).map((path, i) => `
13
+ import static${i} from "${webpath(`./client${path.debase(client)}`)}" with { type: "file" };
14
+ statics["${webpath(path.debase(client))}"] = await file(static${i});`)
15
+ .join("\n");
16
+
9
17
  const $imports = (await Promise.all((await client.collect(re, { recursive: false }))
10
18
  .map(async (file, i) => {
11
19
  const type = file.extension === ".css" ? "style" : "js";
@@ -30,6 +38,8 @@ export default async app => {
30
38
  import file from "@rcompat/fs/file";
31
39
  import stringify from "@rcompat/object/stringify";
32
40
  import crypto from "@rcompat/crypto";
41
+ import { OK } from "@rcompat/http/status";
42
+ import { resolve } from "@rcompat/http/mime";
33
43
 
34
44
  const encoder = new TextEncoder();
35
45
  const hash = async (data, algorithm = "sha-384") => {
@@ -38,6 +48,9 @@ export default async app => {
38
48
  return \`\${prefix}-\${btoa(String.fromCharCode(...new Uint8Array(bytes)))}\`;
39
49
  };
40
50
 
51
+ const statics = {};
52
+ ${import_statics}
53
+
41
54
  ${$imports.map(({ path }, i) =>
42
55
  `import asset${i} from "${path}" with { type: "file" };
43
56
  const file${i} = await file(asset${i}).text();`).join("\n ")}
@@ -63,19 +76,32 @@ export default async app => {
63
76
  });`}
64
77
 
65
78
  ${pages.map((page, i) =>
66
- `import i_page${i} from "./${location.pages}/${page}" with { type: "file" };
79
+ `import i_page${i} from "${webpath(`./${location.pages}/${page}`)}" with { type: "file" };
67
80
  const page${i} = await file(i_page${i}).text();`).join("\n ")}
68
81
 
69
82
  const pages = {
70
83
  ${pages.map((page, i) => `"${page}": page${i},`).join("\n ")}
71
84
  };
85
+ const serve_asset = asset => new Response(asset.stream(), {
86
+ status: OK,
87
+ headers: {
88
+ "Content-Type": resolve(asset.name),
89
+ },
90
+ });
72
91
 
73
92
  const loader = {
74
93
  page(name) {
75
94
  return pages[name] ?? pages["${app.get("pages.app")}"];
76
95
  },
77
96
  asset(pathname) {
78
- return assets.find(asset => asset.src === pathname);
97
+ const root_asset = statics[pathname];
98
+ if (root_asset !== undefined) {
99
+ return serve_asset(root_asset);
100
+ }
101
+ const static_asset = statics[\`/static\${pathname}\`];
102
+ if (static_asset !== undefined) {
103
+ return serve_asset(static_asset);
104
+ }
79
105
  },
80
106
  webview() {
81
107
  return Webview;
package/src/index.js CHANGED
@@ -8,6 +8,7 @@ const command = "bun build build/serve.js --conditions=runtime --compile --minif
8
8
 
9
9
  export default ({
10
10
  start = "/",
11
+ debug = false,
11
12
  } = {}) => {
12
13
  return {
13
14
  name: "primate:native",
@@ -29,7 +30,7 @@ export default ({
29
30
  async serve(app, next) {
30
31
  if (target_keys.includes(app.build_target)) {
31
32
  const Webview = app.loader.webview();
32
- const webview = new Webview();
33
+ const webview = new Webview(debug);
33
34
  const { host, port } = app.get("http");
34
35
  webview.navigate(`http://${host}:${port}${start}`);
35
36
  webview.run();