@tarve/core 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.
- package/CHANGELOG.md +101 -1
- package/README.md +68 -11
- package/dist/npm/build.js +830 -84
- package/dist/npm/cli.js +1094 -117
- package/dist/npm/embedded-assets.js +35 -4
- package/dist/npm/index.js +2515 -207
- package/dist/npm/native-runtime.json +3 -3
- package/dist/npm/node-build.js +865 -0
- package/dist/npm/protocol.js +1 -1
- package/dist/npm/runtime.js +5 -5
- package/dist/types/core/app-metadata.d.ts +49 -0
- package/dist/types/core/build.d.ts +21 -0
- package/dist/types/core/cli.d.ts +1 -1
- package/dist/types/core/esbuild-file-imports.d.ts +8 -0
- package/dist/types/core/node-build.d.ts +7 -0
- package/dist/types/core/node-dev.d.ts +4 -0
- package/dist/types/core/node-target.d.ts +10 -0
- package/dist/types/core/runtime-select.d.ts +8 -0
- package/dist/types/core/src/app-metadata.d.ts +16 -0
- package/dist/types/core/src/app.d.ts +87 -2
- package/dist/types/core/src/assets.d.ts +4 -0
- package/dist/types/core/src/bridge/binding.d.ts +10 -34
- package/dist/types/core/src/canvas.d.ts +161 -0
- package/dist/types/core/src/components/image.d.ts +7 -3
- package/dist/types/core/src/components/layout.d.ts +4 -3
- package/dist/types/core/src/components/pressable.d.ts +2 -2
- package/dist/types/core/src/embedded-assets.d.ts +12 -2
- package/dist/types/core/src/extra-controls.d.ts +1 -1
- package/dist/types/core/src/html-elements.d.ts +26 -0
- package/dist/types/core/src/index.d.ts +5 -2
- package/dist/types/core/src/inline-text.d.ts +21 -0
- package/dist/types/core/src/jsx-runtime.d.ts +175 -4
- package/dist/types/core/src/media-element.d.ts +71 -0
- package/dist/types/core/src/memo.d.ts +18 -0
- package/dist/types/core/src/png.d.ts +29 -0
- package/dist/types/core/src/popups.d.ts +3 -2
- package/dist/types/core/src/reconciler.d.ts +27 -3
- package/dist/types/core/src/test-renderer.d.ts +2 -0
- package/dist/types/core/src/theme.d.ts +2 -1
- package/dist/types/core/src/virtual-list.d.ts +5 -1
- package/dist/types/core/windows-executable.d.ts +16 -0
- package/dist/types/protocol/src/index.d.ts +206 -6
- package/native/linux-x64/libtarve_native.so +0 -0
- package/native/linux-x64/runtime.json +4 -4
- package/native/win32-x64/runtime.json +4 -4
- package/native/win32-x64/tarve_native.dll +0 -0
- package/package.json +11 -2
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// packages/core/src/embedded-assets.ts
|
|
3
3
|
import { createHash, randomUUID } from "crypto";
|
|
4
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "fs";
|
|
5
5
|
import { tmpdir } from "os";
|
|
6
6
|
import { basename, dirname, isAbsolute, join, resolve } from "path";
|
|
7
|
+
import { createRequire } from "module";
|
|
7
8
|
var materialized = new Map;
|
|
8
9
|
function nativeAssetPath(source) {
|
|
9
|
-
|
|
10
|
+
if (/^https?:\/\//i.test(source))
|
|
11
|
+
return source;
|
|
12
|
+
const path = isAbsolute(source) ? source : resolve(sourceRoot(source), source);
|
|
10
13
|
const normalized = path.replaceAll("\\", "/");
|
|
11
14
|
if (normalized.startsWith("/$bunfs/") || /^[a-z]:\/~BUN\//i.test(normalized)) {
|
|
12
15
|
return materializeAsset(path, basename(path));
|
|
13
16
|
}
|
|
17
|
+
if (typeof Bun === "undefined" && path.startsWith(import.meta.dirname + (process.platform === "win32" ? "\\" : "/"))) {
|
|
18
|
+
const { isSea } = createRequire(import.meta.url)("node:sea");
|
|
19
|
+
if (isSea())
|
|
20
|
+
return materializeAsset(path, basename(path));
|
|
21
|
+
}
|
|
14
22
|
return path;
|
|
15
23
|
}
|
|
16
|
-
function materializeAsset(source, filename) {
|
|
24
|
+
function materializeAsset(source, filename, digest) {
|
|
17
25
|
if (!filename || filename === "." || filename === ".." || basename(filename) !== filename) {
|
|
18
26
|
throw new Error("An embedded asset filename must be a simple filename");
|
|
19
27
|
}
|
|
@@ -21,12 +29,22 @@ function materializeAsset(source, filename) {
|
|
|
21
29
|
const cached = materialized.get(key);
|
|
22
30
|
if (cached)
|
|
23
31
|
return cached;
|
|
32
|
+
if (digest) {
|
|
33
|
+
const path = join(tmpdir(), "tarve-assets", digest.sha256, filename);
|
|
34
|
+
if (sizeOf(path) === digest.size) {
|
|
35
|
+
materialized.set(key, path);
|
|
36
|
+
return path;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
24
39
|
const bytes = readFileSync(source);
|
|
25
40
|
const hash = createHash("sha256").update(bytes).digest("hex");
|
|
41
|
+
if (digest && hash !== digest.sha256) {
|
|
42
|
+
throw new Error(`Embedded asset ${filename} does not match its build-time digest; rebuild the executable.`);
|
|
43
|
+
}
|
|
26
44
|
const directory = join(tmpdir(), "tarve-assets", hash);
|
|
27
45
|
const path = join(directory, filename);
|
|
28
46
|
mkdirSync(directory, { recursive: true });
|
|
29
|
-
if (!existsSync(path)) {
|
|
47
|
+
if (!existsSync(path) || digest && sizeOf(path) !== digest.size) {
|
|
30
48
|
const temporary = join(directory, `${filename}.${randomUUID()}.tmp`);
|
|
31
49
|
try {
|
|
32
50
|
writeFileSync(temporary, bytes, { flag: "wx" });
|
|
@@ -46,6 +64,19 @@ function materializeAsset(source, filename) {
|
|
|
46
64
|
materialized.set(key, path);
|
|
47
65
|
return path;
|
|
48
66
|
}
|
|
67
|
+
function sizeOf(path) {
|
|
68
|
+
try {
|
|
69
|
+
return statSync(path).size;
|
|
70
|
+
} catch {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function sourceRoot(source) {
|
|
75
|
+
if (typeof Bun !== "undefined")
|
|
76
|
+
return dirname(Bun.main);
|
|
77
|
+
const roots = [import.meta.dirname, process.env.TARVE_ENTRY && dirname(process.env.TARVE_ENTRY), process.argv[1] && dirname(resolve(process.argv[1]))].filter((root) => !!root);
|
|
78
|
+
return roots.find((root) => existsSync(resolve(root, source))) ?? roots[0];
|
|
79
|
+
}
|
|
49
80
|
export {
|
|
50
81
|
materializeAsset,
|
|
51
82
|
nativeAssetPath
|