@primate/native 0.2.0 → 0.4.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.
- package/lib/private/Module.js +1 -1
- package/lib/private/command.js +3 -4
- package/lib/private/targets.js +1 -1
- package/package.json +4 -4
- package/lib/private/Loader.d.ts +0 -17
- package/lib/private/Loader.js +0 -28
- package/lib/private/desktop.d.ts +0 -4
- package/lib/private/desktop.js +0 -95
- package/lib/public/FileRef.d.ts +0 -2
- package/lib/public/FileRef.js +0 -2
- package/lib/public/Loader.d.ts +0 -2
- package/lib/public/Loader.js +0 -2
package/lib/private/Module.js
CHANGED
package/lib/private/command.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fail from "@primate/core/fail";
|
|
2
2
|
import runtime from "@rcompat/runtime";
|
|
3
3
|
const commands = {
|
|
4
4
|
bun: "bun build",
|
|
5
5
|
deno: "deno compile",
|
|
6
6
|
};
|
|
7
7
|
function which(target) {
|
|
8
|
-
if (target in commands)
|
|
8
|
+
if (target in commands)
|
|
9
9
|
return commands[target];
|
|
10
|
-
}
|
|
11
|
-
throw new AppError("unsupported runtime {0}", target);
|
|
10
|
+
throw fail("unsupported runtime {0}", target);
|
|
12
11
|
}
|
|
13
12
|
;
|
|
14
13
|
export default function (init) {
|
package/lib/private/targets.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Primate native",
|
|
5
5
|
"homepage": "https://primate.run/docs/native",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@rcompat/cli": "^0.11.3",
|
|
20
|
-
"@rcompat/fs": "^0.
|
|
20
|
+
"@rcompat/fs": "^0.22.3",
|
|
21
21
|
"@rcompat/record": "^0.9.1",
|
|
22
22
|
"@rcompat/runtime": "^0.6.0",
|
|
23
23
|
"@rcompat/stdio": "^0.12.2",
|
|
24
24
|
"@rcompat/string": "^0.10.0",
|
|
25
25
|
"@rcompat/webview": "^0.14.0",
|
|
26
|
-
"
|
|
27
|
-
"
|
|
26
|
+
"pema": "^0.4.0",
|
|
27
|
+
"@primate/core": "^0.4.0"
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
30
|
"imports": {
|
package/lib/private/Loader.d.ts
DELETED
|
@@ -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
|
package/lib/private/Loader.js
DELETED
|
@@ -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
|
package/lib/private/desktop.d.ts
DELETED
package/lib/private/desktop.js
DELETED
|
@@ -1,95 +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
|
-
${app_js === undefined ? "" : dedent `
|
|
58
|
-
const imports = {
|
|
59
|
-
app: "${FileRef.join("/", client_imports.find($import => $import.src.includes("app") && $import.src.endsWith(".js")).src)
|
|
60
|
-
.webpath()}"
|
|
61
|
-
};
|
|
62
|
-
// importmap
|
|
63
|
-
assets.push({
|
|
64
|
-
inline: true,
|
|
65
|
-
code: { imports },
|
|
66
|
-
type: "importmap",
|
|
67
|
-
});
|
|
68
|
-
`}
|
|
69
|
-
|
|
70
|
-
const page_imports = {};
|
|
71
|
-
${pages.map((page, i) => dedent `
|
|
72
|
-
import page${i} from "${FileRef.webpath(`./${location.server}/${location.pages}/${page}`)}" with { type: "file" };
|
|
73
|
-
page_imports["${page}"] = page${i};`).join("\n ")}
|
|
74
|
-
|
|
75
|
-
const load = async resource_map =>
|
|
76
|
-
Object.fromEntries(await Promise.all(Object.entries(resource_map).map(
|
|
77
|
-
async ([key, url]) => [key, await FileRef.text(url)])));
|
|
78
|
-
const pages = await load(page_imports);
|
|
79
|
-
|
|
80
|
-
export default {
|
|
81
|
-
assets,
|
|
82
|
-
loader: new Loader({
|
|
83
|
-
pages,
|
|
84
|
-
rootfile: import.meta.url,
|
|
85
|
-
static_root: "${app.config("http.static.root")}",
|
|
86
|
-
client_imports,
|
|
87
|
-
static_imports,
|
|
88
|
-
Webview,
|
|
89
|
-
}),
|
|
90
|
-
target: "${app.target.name}",
|
|
91
|
-
};
|
|
92
|
-
`;
|
|
93
|
-
await app.path.build.join("target.js").write(assets_scripts);
|
|
94
|
-
};
|
|
95
|
-
//# sourceMappingURL=desktop.js.map
|
package/lib/public/FileRef.d.ts
DELETED
package/lib/public/FileRef.js
DELETED
package/lib/public/Loader.d.ts
DELETED
package/lib/public/Loader.js
DELETED