@primate/native 0.5.0 → 0.7.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.
@@ -1,18 +1,24 @@
1
- import fail from "@primate/core/fail";
1
+ import error from "@rcompat/error";
2
2
  import runtime from "@rcompat/runtime";
3
3
  const commands = {
4
4
  bun: "bun build",
5
5
  deno: "deno compile",
6
6
  };
7
+ function unsupported_runtime(target) {
8
+ return error.template `unsupported runtime ${target}`;
9
+ }
10
+ const errors = error.coded({
11
+ unsupported_runtime,
12
+ });
7
13
  function which(target) {
8
14
  if (target in commands)
9
15
  return commands[target];
10
- throw fail("unsupported runtime {0}", target);
16
+ throw errors.unsupported_runtime(target);
11
17
  }
12
18
  ;
13
19
  export default function (init) {
14
20
  return `
15
- ${which(runtime)} \
21
+ ${which(runtime.name)} \
16
22
  ${init.files.map(file => `build/${file}`).join(" ")} \
17
23
  --conditions=runtime --compile --minify \
18
24
  ${init.flags} \
@@ -0,0 +1,11 @@
1
+ import type { Module } from "@primate/core";
2
+ declare const Schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
3
+ readonly debug: import("pema").DefaultType<import("pema").BooleanType, false>;
4
+ readonly start: import("pema").DefaultType<import("pema").StringType, "/">;
5
+ }>, {
6
+ debug: boolean;
7
+ start: string;
8
+ }>;
9
+ export default function module(input?: typeof Schema.input): Module;
10
+ export {};
11
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1,54 @@
1
+ import command from "#command";
2
+ import targets from "#targets";
3
+ import cli from "@rcompat/cli";
4
+ import io from "@rcompat/io";
5
+ import p from "pema";
6
+ const Schema = p({
7
+ debug: p.boolean.default(false),
8
+ start: p.string.default("/"),
9
+ });
10
+ const names = new Set([...targets.map(t => t.name)]);
11
+ export default function module(input = {}) {
12
+ const options = Schema.parse(input);
13
+ return {
14
+ name: module.name,
15
+ setup({ onInit, onBuild, onServe }) {
16
+ onInit(app => {
17
+ targets.forEach(t => app.target.add(t));
18
+ });
19
+ onBuild(app => {
20
+ if (names.has(app.target.name)) {
21
+ app.done(async () => {
22
+ const { exe, flags } = app.target.get();
23
+ const executable_path = cli.fg.dim(`${app.path.build}/${exe}`);
24
+ const { host, port } = app.config("http");
25
+ await app.runpath("worker.js").write(`
26
+ import target from "@primate/native/target/${app.target.target}";
27
+ import Webview from "@primate/native/Webview";
28
+ const webview = new Webview({ platform: target });
29
+ webview.navigate("http://${host}:${port}/${options.start}");
30
+ webview.run();
31
+ `);
32
+ await io.run(command({
33
+ exe,
34
+ files: ["server.js", "worker.js"],
35
+ flags,
36
+ }));
37
+ app.log.system `executable written to ${executable_path}`;
38
+ });
39
+ }
40
+ });
41
+ onServe(app => {
42
+ if (names.has(app.target.name)) {
43
+ const worker = new Worker(app.root.join("worker.js").path);
44
+ worker.addEventListener("message", event => {
45
+ if (event.data === "destroyed") {
46
+ app.stop();
47
+ }
48
+ });
49
+ }
50
+ });
51
+ },
52
+ };
53
+ }
54
+ //# sourceMappingURL=module.js.map
@@ -1,4 +1,8 @@
1
- import type NativeTarget from "#NativeTarget";
1
+ import type { Target } from "@primate/core";
2
+ export interface NativeTarget extends Target {
3
+ exe: string;
4
+ flags: string;
5
+ }
2
6
  declare const targets: NativeTarget[];
3
7
  export default targets;
4
8
  //# sourceMappingURL=targets.d.ts.map
@@ -1,4 +1,2 @@
1
- import Module from "#Module";
2
- declare const _default: (config?: typeof Module.input) => Module;
3
- export default _default;
1
+ export { default } from "#module";
4
2
  //# sourceMappingURL=index.d.ts.map
@@ -1,3 +1,2 @@
1
- import Module from "#Module";
2
- export default (config) => new Module(config);
1
+ export { default } from "#module";
3
2
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primate/native",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "Primate native applications",
5
5
  "homepage": "https://primate.run/docs/native",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -17,36 +17,36 @@
17
17
  "!/**/*.spec.*"
18
18
  ],
19
19
  "dependencies": {
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"
20
+ "@rcompat/cli": "^0.24.0",
21
+ "@rcompat/error": "^0.8.0",
22
+ "@rcompat/io": "^0.10.0",
23
+ "@rcompat/runtime": "^0.16.0",
24
+ "@rcompat/webview": "^0.25.0",
25
+ "@primate/core": "^0.7.0",
26
+ "pema": "^0.7.0"
26
27
  },
27
28
  "peerDependencies": {
28
- "primate": "^0.36.0"
29
+ "primate": "^0.38.0"
29
30
  },
30
31
  "imports": {
31
32
  "#*": {
32
- "apekit": "./src/private/*.ts",
33
+ "@primate/source": "./src/private/*.ts",
33
34
  "default": "./lib/private/*.js"
34
35
  }
35
36
  },
36
37
  "exports": {
37
38
  ".": {
38
- "apekit": "./src/public/index.ts",
39
+ "@primate/source": "./src/public/index.ts",
39
40
  "default": "./lib/public/index.js"
40
41
  },
41
42
  "./*": {
42
- "apekit": "./src/public/*.ts",
43
+ "@primate/source": "./src/public/*.ts",
43
44
  "default": "./lib/public/*.js"
44
45
  }
45
46
  },
46
47
  "scripts": {
47
48
  "build": "npm run clean && tsc",
48
49
  "clean": "rm -rf ./lib",
49
- "lint": "eslint .",
50
- "test": "npm run build && npx proby"
50
+ "lint": "eslint ."
51
51
  }
52
52
  }
@@ -1,25 +0,0 @@
1
- import type App from "@primate/core/App";
2
- import type BuildApp from "@primate/core/BuildApp";
3
- import Module from "@primate/core/Module";
4
- import type Next from "@primate/core/Next";
5
- import type NextBuild from "@primate/core/NextBuild";
6
- import type NextServe from "@primate/core/NextServe";
7
- import type ServeApp from "@primate/core/ServeApp";
8
- declare const schema: import("pema").ObjectType<{
9
- debug: import("pema").DefaultType<import("pema").BooleanType, false>;
10
- start: import("pema").DefaultType<import("pema").StringType, "/">;
11
- }>;
12
- export default class NativeModule extends Module {
13
- #private;
14
- name: string;
15
- static input: {
16
- debug?: boolean | undefined;
17
- start?: string | undefined;
18
- } | undefined;
19
- constructor(config: typeof schema.input);
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
- }
24
- export {};
25
- //# sourceMappingURL=Module.d.ts.map
@@ -1,60 +0,0 @@
1
- import command from "#command";
2
- import targets from "#targets";
3
- import log from "@primate/core/log";
4
- import Module from "@primate/core/Module";
5
- import color from "@rcompat/cli/color";
6
- import io from "@rcompat/io";
7
- import p from "pema";
8
- const names = targets.map(t => t.name);
9
- const schema = p({
10
- debug: p.boolean.default(false),
11
- start: p.string.default("/"),
12
- });
13
- export default class NativeModule extends Module {
14
- name = "native";
15
- #config;
16
- static input = schema.input;
17
- constructor(config) {
18
- super();
19
- this.#config = schema.parse(config);
20
- }
21
- init(app, next) {
22
- targets.forEach(t => app.target.add(t));
23
- return next(app);
24
- }
25
- build(app, next) {
26
- if (names.includes(app.target.name)) {
27
- app.done(async () => {
28
- const { exe, flags } = app.target.get();
29
- const executable_path = color.dim(`${app.path.build}/${exe}`);
30
- const { host, port } = app.config("http");
31
- await app.runpath("worker.js").write(`
32
- import target from "@primate/native/target/${app.target.target}";
33
- import Webview from "@primate/native/Webview";
34
- const webview = new Webview({ platform: target });
35
- webview.navigate("http://${host}:${port}/${this.#config.start}");
36
- webview.run();
37
- `);
38
- await io.run(command({
39
- exe,
40
- files: ["server.js", "worker.js"],
41
- flags,
42
- }));
43
- log.system("executable written to {0}", executable_path);
44
- });
45
- }
46
- return next(app);
47
- }
48
- serve(app, next) {
49
- if (names.includes(app.target.name)) {
50
- const worker = new Worker(app.root.join("worker.js").path);
51
- worker.addEventListener("message", event => {
52
- if (event.data === "destroyed") {
53
- app.stop();
54
- }
55
- });
56
- }
57
- return next(app);
58
- }
59
- }
60
- //# sourceMappingURL=Module.js.map
@@ -1,6 +0,0 @@
1
- import type Target from "@primate/core/Target";
2
- export default interface NativeTarget extends Target {
3
- exe: string;
4
- flags: string;
5
- }
6
- //# sourceMappingURL=NativeTarget.d.ts.map
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=NativeTarget.js.map