@primate/native 0.3.0 → 0.5.0

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.
@@ -6,8 +6,8 @@ import type NextBuild from "@primate/core/NextBuild";
6
6
  import type NextServe from "@primate/core/NextServe";
7
7
  import type ServeApp from "@primate/core/ServeApp";
8
8
  declare const schema: import("pema").ObjectType<{
9
- debug: import("pema").DefaultType<import("pema/boolean").BooleanType, false>;
10
- start: import("pema").DefaultType<import("pema/string").StringType, "/">;
9
+ debug: import("pema").DefaultType<import("pema").BooleanType, false>;
10
+ start: import("pema").DefaultType<import("pema").StringType, "/">;
11
11
  }>;
12
12
  export default class NativeModule extends Module {
13
13
  #private;
@@ -17,9 +17,9 @@ export default class NativeModule extends Module {
17
17
  start?: string | undefined;
18
18
  } | undefined;
19
19
  constructor(config: typeof schema.input);
20
- init<T extends App>(app: T, next: Next<T>): import("@rcompat/type/MaybePromise").default<T>;
21
- build(app: BuildApp, next: NextBuild): import("@rcompat/type/MaybePromise").default<BuildApp>;
22
- serve(app: ServeApp, next: NextServe): import("@rcompat/type/MaybePromise").default<ServeApp>;
20
+ init<T extends App>(app: T, next: Next<T>): import("@rcompat/type").MaybePromise<T>;
21
+ build(app: BuildApp, next: NextBuild): import("@rcompat/type").MaybePromise<BuildApp>;
22
+ serve(app: ServeApp, next: NextServe): import("@rcompat/type").MaybePromise<ServeApp>;
23
23
  }
24
24
  export {};
25
25
  //# sourceMappingURL=Module.d.ts.map
@@ -2,15 +2,13 @@ import command from "#command";
2
2
  import targets from "#targets";
3
3
  import log from "@primate/core/log";
4
4
  import Module from "@primate/core/Module";
5
- import dim from "@rcompat/cli/color/dim";
6
- import execute from "@rcompat/stdio/execute";
7
- import pema from "pema";
8
- import boolean from "pema/boolean";
9
- import string from "pema/string";
5
+ import color from "@rcompat/cli/color";
6
+ import io from "@rcompat/io";
7
+ import p from "pema";
10
8
  const names = targets.map(t => t.name);
11
- const schema = pema({
12
- debug: boolean.default(false),
13
- start: string.default("/"),
9
+ const schema = p({
10
+ debug: p.boolean.default(false),
11
+ start: p.string.default("/"),
14
12
  });
15
13
  export default class NativeModule extends Module {
16
14
  name = "native";
@@ -28,7 +26,7 @@ export default class NativeModule extends Module {
28
26
  if (names.includes(app.target.name)) {
29
27
  app.done(async () => {
30
28
  const { exe, flags } = app.target.get();
31
- const executable_path = dim(`${app.path.build}/${exe}`);
29
+ const executable_path = color.dim(`${app.path.build}/${exe}`);
32
30
  const { host, port } = app.config("http");
33
31
  await app.runpath("worker.js").write(`
34
32
  import target from "@primate/native/target/${app.target.target}";
@@ -37,9 +35,9 @@ export default class NativeModule extends Module {
37
35
  webview.navigate("http://${host}:${port}/${this.#config.start}");
38
36
  webview.run();
39
37
  `);
40
- await execute(command({
38
+ await io.run(command({
41
39
  exe,
42
- files: ["serve.js", "worker.js"],
40
+ files: ["server.js", "worker.js"],
43
41
  flags,
44
42
  }));
45
43
  log.system("executable written to {0}", executable_path);
@@ -1,4 +1,4 @@
1
- import runner from "#desktop";
1
+ const runner = () => { };
2
2
  const targets = [
3
3
  {
4
4
  exe: "app",
package/package.json CHANGED
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@primate/native",
3
- "version": "0.3.0",
4
- "description": "Primate native",
3
+ "version": "0.5.0",
4
+ "description": "Primate native applications",
5
5
  "homepage": "https://primate.run/docs/native",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
7
+ "type": "module",
7
8
  "license": "MIT",
8
- "files": [
9
- "/lib/**/*.js",
10
- "/lib/**/*.d.ts",
11
- "!/**/*.spec.*"
12
- ],
13
9
  "repository": {
14
10
  "type": "git",
15
11
  "url": "https://github.com/primate-run/primate",
16
12
  "directory": "packages/native"
17
13
  },
14
+ "files": [
15
+ "/lib/**/*.js",
16
+ "/lib/**/*.d.ts",
17
+ "!/**/*.spec.*"
18
+ ],
18
19
  "dependencies": {
19
- "@rcompat/cli": "^0.11.3",
20
- "@rcompat/fs": "^0.21.1",
21
- "@rcompat/record": "^0.9.1",
22
- "@rcompat/runtime": "^0.6.0",
23
- "@rcompat/stdio": "^0.12.2",
24
- "@rcompat/string": "^0.10.0",
25
- "@rcompat/webview": "^0.14.0",
26
- "@primate/core": "^0.3.0",
27
- "pema": "^0.3.0"
20
+ "@rcompat/cli": "^0.14.0",
21
+ "@rcompat/io": "^0.3.0",
22
+ "@rcompat/runtime": "^0.9.0",
23
+ "@rcompat/webview": "^0.18.0",
24
+ "@primate/core": "^0.5.0",
25
+ "pema": "^0.5.0"
26
+ },
27
+ "peerDependencies": {
28
+ "primate": "^0.36.0"
28
29
  },
29
- "type": "module",
30
30
  "imports": {
31
31
  "#*": {
32
32
  "apekit": "./src/private/*.ts",
@@ -1,17 +0,0 @@
1
- import Loader from "@primate/core/Loader";
2
- import type Dict from "@rcompat/type/Dict";
3
- type Init = {
4
- client_imports: Dict<string>;
5
- pages: Dict<string>;
6
- pages_app: string;
7
- rootfile: string;
8
- static_imports: Dict<string>;
9
- static_root: string;
10
- };
11
- export default class NativeLoader extends Loader {
12
- #private;
13
- constructor(init: Init);
14
- serve(pathname: string): Promise<Response | undefined>;
15
- }
16
- export {};
17
- //# sourceMappingURL=Loader.d.ts.map
@@ -1,28 +0,0 @@
1
- import Loader from "@primate/core/Loader";
2
- import FileRef from "@rcompat/fs/FileRef";
3
- import entries from "@rcompat/record/entries";
4
- export default class NativeLoader extends Loader {
5
- #clients = {};
6
- #statics = {};
7
- constructor(init) {
8
- super(init);
9
- this.#clients = entries(init.client_imports)
10
- .valmap(([, url]) => new FileRef(url)).get();
11
- this.#statics = entries(init.static_imports)
12
- .valmap(([, url]) => new FileRef(url)).get();
13
- }
14
- async serve(pathname) {
15
- const client_file = this.#clients[pathname];
16
- if (client_file !== undefined) {
17
- return this.asset(client_file);
18
- }
19
- if (pathname.startsWith(this.static_root)) {
20
- const assetname = pathname.slice(this.static_root.length);
21
- const static_file = this.#statics[assetname];
22
- if (static_file !== undefined) {
23
- return this.asset(static_file);
24
- }
25
- }
26
- }
27
- }
28
- //# sourceMappingURL=Loader.js.map
@@ -1,4 +0,0 @@
1
- import type App from "@primate/core/App";
2
- declare const _default: (app: App) => Promise<void>;
3
- export default _default;
4
- //# sourceMappingURL=desktop.d.ts.map
@@ -1,82 +0,0 @@
1
- import location from "@primate/core/location";
2
- import FileRef from "@rcompat/fs/FileRef";
3
- import dedent from "@rcompat/string/dedent";
4
- const html = /^.*.html$/u;
5
- export default async (app) => {
6
- const server_static = app.runpath(location.server, location.static);
7
- // explicitly import static assets as files
8
- const static_imports = (await server_static.collect()).map((path, i) => dedent `
9
- import static${i} from
10
- "${FileRef.webpath(`./server/static${path.debase(server_static)}`)}"
11
- with { type: "file" };
12
- static_imports["${FileRef
13
- .webpath(path.debase(server_static))}"] = static${i};
14
- `)
15
- .join("\n");
16
- const client = app.runpath(location.client);
17
- // explicitly import client assets as files
18
- const client_imports = (await Promise.all((await client.collect())
19
- .map(async (file, i) => {
20
- const type = file.extension === ".css" ? "style" : "js";
21
- const src = `/${file.debase(client).name}`;
22
- const path = `./${file.debase(`${app.path.build}/`)}`;
23
- return {
24
- code: `await FileRef.text(asset${i})`,
25
- empty: (await file.text()).length === 0,
26
- path,
27
- src,
28
- type,
29
- };
30
- }))).filter(file => !file.empty);
31
- const d = app.runpath(location.server, location.pages);
32
- const pages = await Promise.all((await FileRef.collect(d, file => html.test(file.path)))
33
- .map(async (file) => `${file}`.replace(`${d}/`, _ => "")));
34
- const app_js = client_imports.find($import => $import.src.endsWith(".js"));
35
- const assets_scripts = dedent `
36
- import Webview from "@primate/native/target/${app.target.target}";
37
- import Loader from "@primate/native/Loader";
38
- import FileRef from "@primate/native/FileRef";
39
-
40
- const static_imports = {};
41
- ${static_imports}
42
-
43
- const client_imports = {};
44
- ${client_imports.map(({ path, src }, i) => dedent `
45
- import client${i} from "${path}" with { type: "file" };
46
- client_imports["${FileRef.webpath(src)}"] = client${i};
47
- const file${i} = await FileRef.text(client${i});
48
- `).join("\n ")}
49
-
50
- const assets = [${client_imports.map(($import, i) => dedent `{
51
- src: "${$import.src}",
52
- code: file${i},
53
- type: "${$import.type}",
54
- inline: false,
55
- }`).join(",\n ")}];
56
-
57
- const page_imports = {};
58
- ${pages.map((page, i) => dedent `
59
- import page${i} from "${FileRef.webpath(`./${location.server}/${location.pages}/${page}`)}" with { type: "file" };
60
- page_imports["${page}"] = page${i};`).join("\n ")}
61
-
62
- const load = async resource_map =>
63
- Object.fromEntries(await Promise.all(Object.entries(resource_map).map(
64
- async ([key, url]) => [key, await FileRef.text(url)])));
65
- const pages = await load(page_imports);
66
-
67
- export default {
68
- assets,
69
- loader: new Loader({
70
- pages,
71
- rootfile: import.meta.url,
72
- static_root: "${app.config("http.static.root")}",
73
- client_imports,
74
- static_imports,
75
- Webview,
76
- }),
77
- target: "${app.target.name}",
78
- };
79
- `;
80
- await app.path.build.join("target.js").write(assets_scripts);
81
- };
82
- //# sourceMappingURL=desktop.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "@rcompat/fs/FileRef";
2
- //# sourceMappingURL=FileRef.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "@rcompat/fs/FileRef";
2
- //# sourceMappingURL=FileRef.js.map
@@ -1,2 +0,0 @@
1
- export { default } from "#Loader";
2
- //# sourceMappingURL=Loader.d.ts.map
@@ -1,2 +0,0 @@
1
- export { default } from "#Loader";
2
- //# sourceMappingURL=Loader.js.map