@tarve/core 0.5.0 → 0.6.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 +46 -0
- package/README.md +54 -2
- package/dist/npm/build.js +714 -138
- package/dist/npm/cli.js +1013 -161
- package/dist/npm/embedded-assets.js +7 -2
- package/dist/npm/index.js +3096 -1084
- package/dist/npm/jsx-dev-runtime.js +1268 -0
- package/dist/npm/jsx-runtime.js +1268 -0
- package/dist/npm/native-runtime.json +3 -3
- package/dist/npm/node-build.js +299 -5
- package/dist/npm/protocol.js +1 -1
- package/dist/npm/txiki/fetch.ts +228 -0
- package/dist/npm/txiki/intl-data.ts +7 -0
- package/dist/npm/txiki/intl.test.ts +53 -0
- package/dist/npm/txiki/intl.ts +249 -0
- package/dist/npm/txiki/prelude.ts +132 -0
- package/dist/npm/txiki/runtime.ts +6 -0
- package/dist/npm/txiki/shims/buffer.ts +112 -0
- package/dist/npm/txiki/shims/child-process.ts +151 -0
- package/dist/npm/txiki/shims/crypto.ts +30 -0
- package/dist/npm/txiki/shims/events.ts +75 -0
- package/dist/npm/txiki/shims/fs-promises.ts +77 -0
- package/dist/npm/txiki/shims/fs.ts +231 -0
- package/dist/npm/txiki/shims/module.ts +8 -0
- package/dist/npm/txiki/shims/net.ts +69 -0
- package/dist/npm/txiki/shims/os.ts +72 -0
- package/dist/npm/txiki/shims/path.ts +4 -0
- package/dist/npm/txiki/shims/timers-promises.ts +9 -0
- package/dist/npm/txiki/shims/zlib.ts +9 -0
- package/dist/npm/txiki/tjs.d.ts +58 -0
- package/dist/npm/txiki/unavailable.ts +10 -0
- package/dist/types/core/build.d.ts +5 -2
- package/dist/types/core/jsx-compile.d.ts +7 -0
- package/dist/types/core/src/advanced-controls.d.ts +1 -1
- package/dist/types/core/src/app/element-events.d.ts +18 -0
- package/dist/types/core/src/app/media.d.ts +15 -0
- package/dist/types/core/src/app/requests.d.ts +25 -0
- package/dist/types/core/src/app/shadow.d.ts +7 -0
- package/dist/types/core/src/app/stats.d.ts +12 -0
- package/dist/types/core/src/app/tray.d.ts +40 -0
- package/dist/types/core/src/app-metadata.d.ts +2 -0
- package/dist/types/core/src/app.d.ts +29 -27
- package/dist/types/core/src/bridge/index.d.ts +1 -1
- package/dist/types/core/src/chat-controls.d.ts +2 -1
- package/dist/types/core/src/components/button.d.ts +1 -1
- package/dist/types/core/src/components/glass.d.ts +52 -0
- package/dist/types/core/src/components/icon.d.ts +1 -1
- package/dist/types/core/src/components/image.d.ts +1 -1
- package/dist/types/core/src/components/layout.d.ts +1 -1
- package/dist/types/core/src/components/pressable.d.ts +1 -1
- package/dist/types/core/src/components/rich-content.d.ts +1 -1
- package/dist/types/core/src/components/scroll.d.ts +2 -2
- package/dist/types/core/src/components/svg.d.ts +1 -1
- package/dist/types/core/src/components/titlebar.d.ts +15 -1
- package/dist/types/core/src/components/window.d.ts +21 -1
- package/dist/types/core/src/components.d.ts +2 -0
- package/dist/types/core/src/css-shadow.d.ts +1 -1
- package/dist/types/core/src/desktop-controls.d.ts +2 -2
- package/dist/types/core/src/embedded-assets.d.ts +3 -2
- package/dist/types/core/src/extra-controls.d.ts +1 -1
- package/dist/types/core/src/form-controls.d.ts +1 -1
- package/dist/types/core/src/index.d.ts +20 -11
- package/dist/types/core/src/inline-text.d.ts +7 -3
- package/dist/types/core/src/intrinsic-style.d.ts +1 -1
- package/dist/types/core/src/jsx-runtime.d.ts +10 -4
- package/dist/types/core/src/media-element.d.ts +3 -4
- package/dist/types/core/src/memo.d.ts +10 -0
- package/dist/types/core/src/motion.d.ts +1 -1
- package/dist/types/core/src/popups.d.ts +1 -1
- package/dist/types/core/src/protocol.d.ts +6 -0
- package/dist/types/core/src/reconciler/diff.d.ts +11 -0
- package/dist/types/core/src/reconciler/intrinsics.d.ts +24 -0
- package/dist/types/core/src/reconciler.d.ts +10 -11
- package/dist/types/core/src/render-scope.d.ts +8 -0
- package/dist/types/core/src/style.d.ts +1 -1
- package/dist/types/core/src/tailwind-palette.d.ts +1 -0
- package/dist/types/core/src/tailwind.d.ts +8 -0
- package/dist/types/core/src/test-renderer.d.ts +1 -1
- package/dist/types/core/src/text-search.d.ts +1 -1
- package/dist/types/core/src/theme.d.ts +8 -1
- package/dist/types/core/src/updates.d.ts +87 -0
- package/dist/types/core/src/virtual-list.d.ts +3 -1
- package/dist/types/core/txiki/fetch.d.ts +1 -0
- package/dist/types/core/txiki/intl-data.d.ts +6 -0
- package/dist/types/core/txiki/intl.d.ts +92 -0
- package/dist/types/core/txiki/prelude.d.ts +1 -0
- package/dist/types/core/txiki/runtime.d.ts +2 -0
- package/dist/types/core/txiki/shims/buffer.d.ts +37 -0
- package/dist/types/core/txiki/shims/child-process.d.ts +46 -0
- package/dist/types/core/txiki/shims/crypto.d.ts +16 -0
- package/dist/types/core/txiki/shims/events.d.ts +21 -0
- package/dist/types/core/txiki/shims/fs-promises.d.ts +41 -0
- package/dist/types/core/txiki/shims/fs.d.ts +44 -0
- package/dist/types/core/txiki/shims/module.d.ts +5 -0
- package/dist/types/core/txiki/shims/net.d.ts +22 -0
- package/dist/types/core/txiki/shims/os.d.ts +52 -0
- package/dist/types/core/txiki/shims/path.d.ts +3 -0
- package/dist/types/core/txiki/shims/timers-promises.d.ts +7 -0
- package/dist/types/core/txiki/shims/zlib.d.ts +11 -0
- package/dist/types/core/txiki/unavailable.d.ts +5 -0
- package/dist/types/core/txiki-build.d.ts +23 -0
- package/dist/types/core/updates-build.d.ts +35 -0
- package/dist/types/protocol/src/index.d.ts +159 -8
- 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 +3 -2
- /package/dist/types/core/{app-metadata.d.ts → package-metadata.d.ts} +0 -0
package/dist/npm/build.js
CHANGED
|
@@ -255,7 +255,7 @@ var init_png = __esm(() => {
|
|
|
255
255
|
});
|
|
256
256
|
});
|
|
257
257
|
|
|
258
|
-
// packages/core/
|
|
258
|
+
// packages/core/package-metadata.ts
|
|
259
259
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
260
260
|
import { basename, dirname, extname, join, relative, resolve } from "path";
|
|
261
261
|
function fields(value, where) {
|
|
@@ -365,6 +365,7 @@ function buildMetadata(entrypoint, overrides) {
|
|
|
365
365
|
function runtimeMetadata(metadata, icon) {
|
|
366
366
|
return JSON.stringify({
|
|
367
367
|
name: metadata.name,
|
|
368
|
+
...metadata.version ? { version: metadata.version } : {},
|
|
368
369
|
...metadata.appId ? { appId: metadata.appId } : {},
|
|
369
370
|
...icon ? { icon } : {}
|
|
370
371
|
});
|
|
@@ -392,7 +393,7 @@ function writeLinuxDesktopEntry(outfile, metadata, png) {
|
|
|
392
393
|
return desktop;
|
|
393
394
|
}
|
|
394
395
|
var FIELDS, ICO_SIZES;
|
|
395
|
-
var
|
|
396
|
+
var init_package_metadata = __esm(() => {
|
|
396
397
|
init_png();
|
|
397
398
|
FIELDS = ["name", "version", "description", "publisher", "copyright", "icon", "appId"];
|
|
398
399
|
ICO_SIZES = [16, 20, 24, 32, 40, 48, 64, 96, 128, 256];
|
|
@@ -442,7 +443,7 @@ var init_targets = __esm(() => {
|
|
|
442
443
|
});
|
|
443
444
|
|
|
444
445
|
// packages/protocol/src/index.ts
|
|
445
|
-
var NATIVE_ABI_VERSION = 5, PROTOCOL_VERSION =
|
|
446
|
+
var NATIVE_ABI_VERSION = 5, PROTOCOL_VERSION = 59;
|
|
446
447
|
|
|
447
448
|
// packages/core/native-runtime.ts
|
|
448
449
|
import { createHash } from "crypto";
|
|
@@ -553,12 +554,613 @@ var init_native_runtime = __esm(() => {
|
|
|
553
554
|
init_targets();
|
|
554
555
|
});
|
|
555
556
|
|
|
557
|
+
// packages/core/jsx-compile.ts
|
|
558
|
+
var exports_jsx_compile = {};
|
|
559
|
+
__export(exports_jsx_compile, {
|
|
560
|
+
closeJsxCompiler: () => closeJsxCompiler,
|
|
561
|
+
compileJsx: () => compileJsx
|
|
562
|
+
});
|
|
563
|
+
async function loadParser() {
|
|
564
|
+
let modules;
|
|
565
|
+
try {
|
|
566
|
+
modules = await Promise.all([import("typescript/unstable/ast"), import("typescript/unstable/ast/is")]);
|
|
567
|
+
} catch (error) {
|
|
568
|
+
throw new Error(`compileJsx needs TypeScript 7 (npm install -D typescript@7): ${error instanceof Error ? error.message : String(error)}`);
|
|
569
|
+
}
|
|
570
|
+
const [ast, is] = modules;
|
|
571
|
+
const files = new Map([[CONFIG, JSON.stringify({ compilerOptions: { jsx: "preserve", noLib: true, noResolve: true, types: [] }, files: ["app.tsx"] })]]);
|
|
572
|
+
const normalize = (path) => path.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "");
|
|
573
|
+
const options = {
|
|
574
|
+
cwd: ROOT,
|
|
575
|
+
fs: {
|
|
576
|
+
readFile: (path) => files.get(normalize(path)),
|
|
577
|
+
fileExists: (path) => files.has(normalize(path)),
|
|
578
|
+
directoryExists: (path) => {
|
|
579
|
+
const p = normalize(path).replace(/\/$/, "");
|
|
580
|
+
return p === "" || ROOT.startsWith(p);
|
|
581
|
+
},
|
|
582
|
+
getAccessibleEntries: (path) => normalize(path).replace(/\/$/, "") === ROOT ? { files: ["app.tsx", "tsconfig.json"], directories: [] } : { files: [], directories: [] },
|
|
583
|
+
realpath: (path) => path
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
const request = { openProject: CONFIG, fileChanges: { invalidateAll: true } };
|
|
587
|
+
if ((process.platform === "win32" || typeof Bun === "undefined") && process.env.TARVE_TSGO_ASYNC !== "1") {
|
|
588
|
+
const sync = await import("typescript/unstable/sync");
|
|
589
|
+
const api = new sync.API(options);
|
|
590
|
+
return {
|
|
591
|
+
ast,
|
|
592
|
+
is,
|
|
593
|
+
files,
|
|
594
|
+
parse: async () => {
|
|
595
|
+
api.clearSourceFileCache();
|
|
596
|
+
const snapshot = api.updateSnapshot(request);
|
|
597
|
+
try {
|
|
598
|
+
return snapshot.getProjects()[0].program.getSourceFile(FILE);
|
|
599
|
+
} finally {
|
|
600
|
+
snapshot.dispose();
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
close: async () => api.close()
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
const asyncApi = await import("typescript/unstable/async");
|
|
607
|
+
const api = new asyncApi.API(options);
|
|
608
|
+
return {
|
|
609
|
+
ast,
|
|
610
|
+
is,
|
|
611
|
+
files,
|
|
612
|
+
parse: async () => {
|
|
613
|
+
api.clearSourceFileCache();
|
|
614
|
+
const snapshot = await api.updateSnapshot(request);
|
|
615
|
+
try {
|
|
616
|
+
return await snapshot.getProjects()[0].program.getSourceFile(FILE);
|
|
617
|
+
} finally {
|
|
618
|
+
await snapshot.dispose();
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
close: () => api.close()
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
async function closeJsxCompiler() {
|
|
625
|
+
const current = parser;
|
|
626
|
+
parser = undefined;
|
|
627
|
+
if (current)
|
|
628
|
+
await (await current).close();
|
|
629
|
+
}
|
|
630
|
+
function constant(node, ast, ts) {
|
|
631
|
+
const isConstant = (child) => constant(child, ast, ts);
|
|
632
|
+
if (ts.isParenthesizedExpression(node))
|
|
633
|
+
return isConstant(node.expression);
|
|
634
|
+
if (ts.isNumericLiteral(node) || ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
|
|
635
|
+
return true;
|
|
636
|
+
if (node.kind === ast.SyntaxKind.TrueKeyword || node.kind === ast.SyntaxKind.FalseKeyword || node.kind === ast.SyntaxKind.NullKeyword)
|
|
637
|
+
return true;
|
|
638
|
+
if (ts.isIdentifier(node) && node.text === "undefined")
|
|
639
|
+
return true;
|
|
640
|
+
if (ts.isPrefixUnaryExpression(node) && (node.operator === ast.SyntaxKind.MinusToken || node.operator === ast.SyntaxKind.PlusToken))
|
|
641
|
+
return ts.isNumericLiteral(node.operand);
|
|
642
|
+
if (ts.isArrayLiteralExpression(node))
|
|
643
|
+
return node.elements.every((element) => !ts.isSpreadElement(element) && isConstant(element));
|
|
644
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
645
|
+
return node.properties.every((property) => ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name)) && isConstant(property.initializer));
|
|
646
|
+
}
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
async function compileJsx(source) {
|
|
650
|
+
if (!/<[A-Za-z>]/.test(source))
|
|
651
|
+
return { code: source, templates: 0 };
|
|
652
|
+
const loaded = await (parser ??= loadParser());
|
|
653
|
+
const turn = queue.then(async () => {
|
|
654
|
+
loaded.files.set(FILE, source);
|
|
655
|
+
const file = await loaded.parse();
|
|
656
|
+
if (!file || file.text !== source)
|
|
657
|
+
throw new Error("compileJsx: TypeScript returned a different parse of the file");
|
|
658
|
+
return compileFile(source, file, loaded.ast, loaded.is);
|
|
659
|
+
});
|
|
660
|
+
queue = turn.catch(() => {
|
|
661
|
+
return;
|
|
662
|
+
});
|
|
663
|
+
return turn;
|
|
664
|
+
}
|
|
665
|
+
function compileFile(source, file, ast, ts) {
|
|
666
|
+
const isConstant = (node) => constant(node, ast, ts);
|
|
667
|
+
const isJsx = (node) => ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
|
|
668
|
+
const core = new Set;
|
|
669
|
+
let lastImport = 0;
|
|
670
|
+
for (const statement of file.statements) {
|
|
671
|
+
if (!ts.isImportDeclaration(statement))
|
|
672
|
+
continue;
|
|
673
|
+
lastImport = statement.end;
|
|
674
|
+
if (!ts.isStringLiteral(statement.moduleSpecifier) || !CORE.test(statement.moduleSpecifier.text))
|
|
675
|
+
continue;
|
|
676
|
+
const bindings = statement.importClause?.namedBindings;
|
|
677
|
+
if (bindings && ts.isNamedImports(bindings) && statement.importClause.phaseModifier !== ast.SyntaxKind.TypeKeyword) {
|
|
678
|
+
for (const element of bindings.elements)
|
|
679
|
+
if (!element.isTypeOnly)
|
|
680
|
+
core.add(element.name.text);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
const shadowed = new Set;
|
|
684
|
+
const scan = (node) => {
|
|
685
|
+
const name = node.kind === ast.SyntaxKind.Parameter || ts.isVariableDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) ? node.name : undefined;
|
|
686
|
+
if (name && ts.isIdentifier(name) && core.has(name.text))
|
|
687
|
+
shadowed.add(name.text);
|
|
688
|
+
node.forEachChild(scan);
|
|
689
|
+
};
|
|
690
|
+
file.forEachChild(scan);
|
|
691
|
+
for (const name of shadowed)
|
|
692
|
+
core.delete(name);
|
|
693
|
+
const pure = (node) => {
|
|
694
|
+
if (ts.isJsxFragment(node))
|
|
695
|
+
return true;
|
|
696
|
+
const tag = ts.isJsxElement(node) ? node.openingElement.tagName : node.tagName;
|
|
697
|
+
if (ts.isIdentifier(tag))
|
|
698
|
+
return /^[a-z]/.test(tag.text) || core.has(tag.text);
|
|
699
|
+
return false;
|
|
700
|
+
};
|
|
701
|
+
const text = (start, end) => source.slice(start, end);
|
|
702
|
+
const declarations = [];
|
|
703
|
+
function rewrite(start, end, root) {
|
|
704
|
+
const roots = [];
|
|
705
|
+
const find = (node) => {
|
|
706
|
+
if (node.end <= start || node.pos >= end)
|
|
707
|
+
return;
|
|
708
|
+
if (isJsx(node) && node.getStart() >= start && node.end <= end) {
|
|
709
|
+
roots.push(node);
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
node.forEachChild(find);
|
|
713
|
+
};
|
|
714
|
+
find(root);
|
|
715
|
+
let out = "";
|
|
716
|
+
let at = start;
|
|
717
|
+
for (const node of roots) {
|
|
718
|
+
out += text(at, node.getStart()) + compileRoot(node);
|
|
719
|
+
at = node.end;
|
|
720
|
+
}
|
|
721
|
+
return out + text(at, end);
|
|
722
|
+
}
|
|
723
|
+
function compileRoot(node) {
|
|
724
|
+
if (!pure(node))
|
|
725
|
+
return impure(node);
|
|
726
|
+
const holes = [];
|
|
727
|
+
const events = [];
|
|
728
|
+
let key;
|
|
729
|
+
const hole = (expression, event = false) => {
|
|
730
|
+
const name = "h" + holes.length;
|
|
731
|
+
holes.push(expression);
|
|
732
|
+
if (event)
|
|
733
|
+
events.push(name);
|
|
734
|
+
return "p." + name;
|
|
735
|
+
};
|
|
736
|
+
let elements = 0;
|
|
737
|
+
function body(element, isRoot) {
|
|
738
|
+
if (!pure(element))
|
|
739
|
+
return "{" + hole(impure(element)) + "}";
|
|
740
|
+
elements++;
|
|
741
|
+
let out = "";
|
|
742
|
+
let at = element.getStart();
|
|
743
|
+
const end = element.end;
|
|
744
|
+
const attributes = ts.isJsxElement(element) ? element.openingElement.attributes : ts.isJsxSelfClosingElement(element) ? element.attributes : undefined;
|
|
745
|
+
const children = ts.isJsxElement(element) || ts.isJsxFragment(element) ? element.children : undefined;
|
|
746
|
+
const parts = [];
|
|
747
|
+
for (const attribute of attributes?.properties ?? []) {
|
|
748
|
+
if (ts.isJsxSpreadAttribute(attribute)) {
|
|
749
|
+
parts.push({ start: attribute.expression.getStart(), end: attribute.expression.end, replacement: hole(rewrite(attribute.expression.getStart(), attribute.expression.end, attribute.expression)) });
|
|
750
|
+
continue;
|
|
751
|
+
}
|
|
752
|
+
const name = attribute.name.getText();
|
|
753
|
+
const initializer = attribute.initializer;
|
|
754
|
+
if (isRoot && name === "key") {
|
|
755
|
+
key = initializer ? ts.isJsxExpression(initializer) && initializer.expression ? rewrite(initializer.expression.getStart(), initializer.expression.end, initializer.expression) : initializer.getText() : "true";
|
|
756
|
+
parts.push({ start: attribute.getStart(), end: attribute.end, replacement: "" });
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
if (!initializer)
|
|
760
|
+
continue;
|
|
761
|
+
if (ts.isJsxExpression(initializer) && initializer.expression && !isConstant(initializer.expression)) {
|
|
762
|
+
const expression = initializer.expression;
|
|
763
|
+
parts.push({ start: expression.getStart(), end: expression.end, replacement: hole(rewrite(expression.getStart(), expression.end, expression), EVENT.test(name)) });
|
|
764
|
+
} else if (isJsx(initializer)) {
|
|
765
|
+
const value = initializer;
|
|
766
|
+
parts.push({ start: value.getStart(), end: value.end, replacement: "{" + hole(compileRoot(value)) + "}" });
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
for (const child of children ?? []) {
|
|
770
|
+
if (ts.isJsxExpression(child)) {
|
|
771
|
+
if (!child.expression)
|
|
772
|
+
continue;
|
|
773
|
+
if (isConstant(child.expression) && !ts.isObjectLiteralExpression(child.expression) && !ts.isArrayLiteralExpression(child.expression))
|
|
774
|
+
continue;
|
|
775
|
+
parts.push({ start: child.expression.getStart(), end: child.expression.end, replacement: hole(rewrite(child.expression.getStart(), child.expression.end, child.expression)) });
|
|
776
|
+
} else if (isJsx(child)) {
|
|
777
|
+
parts.push({ start: child.getStart(), end: child.end, replacement: body(child, false) });
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
parts.sort((a, b) => a.start - b.start);
|
|
781
|
+
for (const part of parts) {
|
|
782
|
+
out += text(at, part.start) + part.replacement;
|
|
783
|
+
at = part.end;
|
|
784
|
+
}
|
|
785
|
+
return out + text(at, end);
|
|
786
|
+
}
|
|
787
|
+
const template = body(node, true);
|
|
788
|
+
if (elements < 2)
|
|
789
|
+
return impure(node);
|
|
790
|
+
const name = "__tarveTemplate" + declarations.length;
|
|
791
|
+
declarations.push(`const ${name} = __tarveCompileTemplate((p: any) => (${template}), ${JSON.stringify(events)});`);
|
|
792
|
+
const props = holes.map((expression, index) => `h${index}={${expression}}`);
|
|
793
|
+
if (key !== undefined)
|
|
794
|
+
props.unshift(`key={${key}}`);
|
|
795
|
+
return `<${name} ${props.join(" ")} />`;
|
|
796
|
+
}
|
|
797
|
+
function impure(node) {
|
|
798
|
+
let out = "";
|
|
799
|
+
let at = node.getStart();
|
|
800
|
+
const visit = (child) => {
|
|
801
|
+
if (isJsx(child) && child !== node) {
|
|
802
|
+
out += text(at, child.getStart()) + compileRoot(child);
|
|
803
|
+
at = child.end;
|
|
804
|
+
return;
|
|
805
|
+
}
|
|
806
|
+
if (ts.isJsxExpression(child) && child.expression) {
|
|
807
|
+
out += text(at, child.expression.getStart()) + rewrite(child.expression.getStart(), child.expression.end, child.expression);
|
|
808
|
+
at = child.expression.end;
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
if (ts.isJsxSpreadAttribute(child)) {
|
|
812
|
+
out += text(at, child.expression.getStart()) + rewrite(child.expression.getStart(), child.expression.end, child.expression);
|
|
813
|
+
at = child.expression.end;
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
child.forEachChild(visit);
|
|
817
|
+
};
|
|
818
|
+
node.forEachChild(visit);
|
|
819
|
+
return out + text(at, node.end);
|
|
820
|
+
}
|
|
821
|
+
const body = rewrite(lastImport, source.length, file);
|
|
822
|
+
if (!declarations.length)
|
|
823
|
+
return { code: source, templates: 0 };
|
|
824
|
+
const code = text(0, lastImport) + `
|
|
825
|
+
import { template as __tarveCompileTemplate } from "@tarve/core";
|
|
826
|
+
` + declarations.join(`
|
|
827
|
+
`) + `
|
|
828
|
+
` + body;
|
|
829
|
+
return { code, templates: declarations.length };
|
|
830
|
+
}
|
|
831
|
+
var ROOT = "/tarve-jsx", FILE, CONFIG, parser, queue, CORE, EVENT;
|
|
832
|
+
var init_jsx_compile = __esm(() => {
|
|
833
|
+
FILE = ROOT + "/app.tsx";
|
|
834
|
+
CONFIG = ROOT + "/tsconfig.json";
|
|
835
|
+
queue = Promise.resolve();
|
|
836
|
+
CORE = /^(?:@tarve\/core|tarve)(?:\/.*)?$/;
|
|
837
|
+
EVENT = /^on[A-Z]/;
|
|
838
|
+
});
|
|
839
|
+
|
|
840
|
+
// packages/core/windows-executable.ts
|
|
841
|
+
var exports_windows_executable = {};
|
|
842
|
+
__export(exports_windows_executable, {
|
|
843
|
+
brandWindowsExecutable: () => brandWindowsExecutable
|
|
844
|
+
});
|
|
845
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
846
|
+
import { Data, NtExecutable, NtExecutableResource, Resource } from "resedit";
|
|
847
|
+
function numericVersion(version) {
|
|
848
|
+
const parts = version.split(/[.+-]/).slice(0, 4).map((part) => Number.parseInt(part, 10));
|
|
849
|
+
return [0, 1, 2, 3].map((index) => {
|
|
850
|
+
const value = parts[index];
|
|
851
|
+
return Number.isInteger(value) && value >= 0 && value <= 65535 ? value : 0;
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
function brandWindowsExecutable(path, info) {
|
|
855
|
+
const executable = NtExecutable.from(readFileSync2(path), { ignoreCert: true });
|
|
856
|
+
const resources = NtExecutableResource.from(executable);
|
|
857
|
+
const versionInfo = Resource.VersionInfo.fromEntries(resources.entries)[0] ?? Resource.VersionInfo.createEmpty();
|
|
858
|
+
const languages = versionInfo.getAllLanguagesForStringValues();
|
|
859
|
+
if (languages.length === 0)
|
|
860
|
+
languages.push({ lang: 1033, codepage: 1200 });
|
|
861
|
+
const [major, minor, patch, revision] = numericVersion(info.version);
|
|
862
|
+
const text = `${major}.${minor}.${patch}.${revision}`;
|
|
863
|
+
for (const language of languages) {
|
|
864
|
+
for (const key of ["CompanyName", "LegalCopyright", "LegalTrademarks", "Comments", "PrivateBuild", "SpecialBuild"]) {
|
|
865
|
+
versionInfo.removeStringValue(language, key);
|
|
866
|
+
}
|
|
867
|
+
versionInfo.setStringValues(language, {
|
|
868
|
+
FileDescription: info.description ?? `${info.name} \u2014 native Tarve application`,
|
|
869
|
+
...info.publisher ? { CompanyName: info.publisher } : {},
|
|
870
|
+
...info.copyright ? { LegalCopyright: info.copyright } : {},
|
|
871
|
+
ProductName: info.name,
|
|
872
|
+
InternalName: info.name,
|
|
873
|
+
OriginalFilename: info.filename,
|
|
874
|
+
FileVersion: text,
|
|
875
|
+
ProductVersion: text
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
versionInfo.setFileVersion(major, minor, patch, revision);
|
|
879
|
+
versionInfo.setProductVersion(major, minor, patch, revision);
|
|
880
|
+
versionInfo.outputToResourceEntries(resources.entries);
|
|
881
|
+
if (info.ico) {
|
|
882
|
+
const groups = Resource.IconGroupEntry.fromEntries(resources.entries);
|
|
883
|
+
const group = groups[0];
|
|
884
|
+
const icons = Data.IconFile.from(info.ico).icons.map((icon) => icon.data);
|
|
885
|
+
Resource.IconGroupEntry.replaceIconsForResource(resources.entries, group?.id ?? 1, group?.lang ?? 1033, icons);
|
|
886
|
+
}
|
|
887
|
+
resources.outputResource(executable);
|
|
888
|
+
const output = Buffer.from(executable.generate());
|
|
889
|
+
output.writeUInt16LE(IMAGE_SUBSYSTEM_WINDOWS_GUI, output.readUInt32LE(60) + 24 + 68);
|
|
890
|
+
writeFileSync2(path, output);
|
|
891
|
+
}
|
|
892
|
+
var IMAGE_SUBSYSTEM_WINDOWS_GUI = 2;
|
|
893
|
+
var init_windows_executable = () => {};
|
|
894
|
+
|
|
895
|
+
// packages/core/txiki-build.ts
|
|
896
|
+
import { execFileSync } from "child_process";
|
|
897
|
+
import { createHash as createHash2 } from "crypto";
|
|
898
|
+
import { chmodSync, existsSync as existsSync3, mkdtempSync, readFileSync as readFileSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
899
|
+
import { mkdir, rm } from "fs/promises";
|
|
900
|
+
import { builtinModules } from "module";
|
|
901
|
+
import { tmpdir } from "os";
|
|
902
|
+
import { basename as basename3, dirname as dirname3, join as join3, relative as relative2, resolve as resolve2 } from "path";
|
|
903
|
+
import { gzipSync } from "zlib";
|
|
904
|
+
import { nativePath } from "#tarve/runtime";
|
|
905
|
+
function findTxiki(explicit) {
|
|
906
|
+
const candidate = explicit ?? process.env.TARVE_TXIKI ?? (process.versions.bun ? Bun.which("tjs") : undefined) ?? "tjs";
|
|
907
|
+
try {
|
|
908
|
+
execFileSync(candidate, ["--version"], { stdio: "pipe" });
|
|
909
|
+
} catch {
|
|
910
|
+
throw new Error(`txiki.js was not found (${candidate}). Install it (winget install Saghul.TxikiJS) or set TARVE_TXIKI.`);
|
|
911
|
+
}
|
|
912
|
+
return candidate;
|
|
913
|
+
}
|
|
914
|
+
function txikiBinary(tjs) {
|
|
915
|
+
return execFileSync(tjs, ["eval", "console.log(tjs.exePath)"], { encoding: "utf8" }).trim();
|
|
916
|
+
}
|
|
917
|
+
async function buildTxiki(options) {
|
|
918
|
+
const target = options.target ?? hostBuildTarget();
|
|
919
|
+
if (!target)
|
|
920
|
+
throw new Error(`Unsupported txiki.js build host: ${process.platform}-${process.arch}`);
|
|
921
|
+
const config = targetConfig(target);
|
|
922
|
+
const tjs = findTxiki(options.txikiExecutable);
|
|
923
|
+
const host = txikiBinary(tjs);
|
|
924
|
+
const base = options.targetExecutable ? resolve2(options.targetExecutable) : host;
|
|
925
|
+
if (target !== hostBuildTarget() && !options.targetExecutable) {
|
|
926
|
+
throw new Error(`Cross-compiling for ${target} needs targetExecutable: the txiki.js ${execFileSync(tjs, ["--version"], { encoding: "utf8" }).trim()} binary for that platform.`);
|
|
927
|
+
}
|
|
928
|
+
if (!existsSync3(base))
|
|
929
|
+
throw new Error(`txiki.js executable is missing: ${base}`);
|
|
930
|
+
const { metadata, images, define } = buildMetadata(options.entrypoint, metadataOverrides(options));
|
|
931
|
+
const outfile = resolve2(options.outfile ?? `dist/${metadata.name}${config.executableSuffix}`);
|
|
932
|
+
const library = resolve2(options.nativeLibrary ?? (target === hostBuildTarget() ? nativePath() : join3(import.meta.dirname, "../../native", config.nativeDirectory, config.nativeName)));
|
|
933
|
+
if (!existsSync3(library))
|
|
934
|
+
throw new Error(`Tarve native library missing: ${library}`);
|
|
935
|
+
const temporary = mkdtempSync(join3(tmpdir(), "tarve-txiki-build-"));
|
|
936
|
+
try {
|
|
937
|
+
const root = import.meta.dirname;
|
|
938
|
+
const source = existsSync3(join3(root, "src/index.ts"));
|
|
939
|
+
const assets = [];
|
|
940
|
+
const missing = new Map;
|
|
941
|
+
const importers = new Map;
|
|
942
|
+
const runtime = {
|
|
943
|
+
name: "tarve-txiki-runtime",
|
|
944
|
+
setup(build) {
|
|
945
|
+
build.onResolve({ filter: /^tjs:/ }, (args) => ({ path: args.path, external: true }));
|
|
946
|
+
build.onResolve({ filter: /^(?:node:)?[a-z_]+(?:\/[a-z_]+)?$/ }, (args) => {
|
|
947
|
+
const name = args.path.replace(/^node:/, "");
|
|
948
|
+
if (!NODE_SHIMS[name] && !args.path.startsWith("node:") && !builtinModules.includes(name))
|
|
949
|
+
return;
|
|
950
|
+
if (!importers.has(name))
|
|
951
|
+
importers.set(name, new Set);
|
|
952
|
+
importers.get(name).add(args.importer);
|
|
953
|
+
return { path: name, namespace: "tarve-node", sideEffects: false };
|
|
954
|
+
});
|
|
955
|
+
build.onResolve({ filter: /^#tarve\/runtime$/ }, () => ({ path: join3(root, "txiki/runtime.ts") }));
|
|
956
|
+
if (source) {
|
|
957
|
+
build.onResolve({ filter: /^(?:@tarve\/core(?:-internal)?|tarve)(?:\/(?:jsx-runtime|jsx-dev-runtime))?$/ }, (args) => {
|
|
958
|
+
const entry = args.path.replace(/^(?:@tarve\/core(?:-internal)?|tarve)/, "") || "/index";
|
|
959
|
+
return { path: join3(root, "src", `${entry.slice(1)}.ts`) };
|
|
960
|
+
});
|
|
961
|
+
}
|
|
962
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
963
|
+
const type = args.with?.type ?? (ASSET.test(args.path) && args.kind === "import-statement" ? "file" : undefined);
|
|
964
|
+
if (type !== "file" && type !== "text")
|
|
965
|
+
return;
|
|
966
|
+
return { path: resolve2(dirname3(args.importer), args.path), namespace: `tarve-${type}` };
|
|
967
|
+
});
|
|
968
|
+
build.onLoad({ filter: /.*/, namespace: "tarve-node" }, (args) => {
|
|
969
|
+
const shim = NODE_SHIMS[args.path] && JSON.stringify(join3(root, "txiki/shims", `${NODE_SHIMS[args.path]}.ts`));
|
|
970
|
+
const placeholder = (api) => `/* @__PURE__ */ unavailable(${JSON.stringify(`${UNAVAILABLE}node:${api}`)})`;
|
|
971
|
+
return {
|
|
972
|
+
contents: [
|
|
973
|
+
`import { unavailable } from ${JSON.stringify(join3(root, "txiki/unavailable.ts"))};`,
|
|
974
|
+
...shim ? [`export * from ${shim};`, `export { default } from ${shim};`] : [`export default ${placeholder(args.path)};`],
|
|
975
|
+
...[...missing.get(args.path) ?? []].map((name) => `export const ${name} = ${placeholder(`${args.path}.${name}`)};`)
|
|
976
|
+
].join(`
|
|
977
|
+
`),
|
|
978
|
+
loader: "js",
|
|
979
|
+
resolveDir: root
|
|
980
|
+
};
|
|
981
|
+
});
|
|
982
|
+
if (options.compileJsx) {
|
|
983
|
+
build.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
|
|
984
|
+
if (/[\\/]node_modules[\\/]/.test(args.path) || args.path.startsWith(join3(root, "src")))
|
|
985
|
+
return;
|
|
986
|
+
await Promise.resolve().then(() => init_jsx_compile());
|
|
987
|
+
return { contents: (await compileJsx(readFileSync3(args.path, "utf8"))).code, loader: args.path.endsWith(".jsx") ? "jsx" : "tsx", resolveDir: dirname3(args.path) };
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
build.onLoad({ filter: /.*/, namespace: "tarve-text" }, (args) => ({ contents: readFileSync3(args.path, "utf8"), loader: "text" }));
|
|
991
|
+
build.onLoad({ filter: /.*/, namespace: "tarve-file" }, (args) => {
|
|
992
|
+
const data = readFileSync3(args.path);
|
|
993
|
+
const name = `${createHash2("sha256").update(data).digest("hex").slice(0, 12)}-${basename3(args.path)}`;
|
|
994
|
+
if (!assets.some((asset) => asset.name === name))
|
|
995
|
+
assets.push({ name, data, gzip: false });
|
|
996
|
+
return { contents: `export default globalThis.__tarveAssets[${JSON.stringify(name)}];`, loader: "js" };
|
|
997
|
+
});
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
const entry = join3(temporary, "entry.ts");
|
|
1001
|
+
writeFileSync3(entry, [
|
|
1002
|
+
`import ${JSON.stringify(join3(root, "txiki/prelude.ts"))};`,
|
|
1003
|
+
`import ${JSON.stringify(resolve2(options.entrypoint))};`
|
|
1004
|
+
].join(`
|
|
1005
|
+
`));
|
|
1006
|
+
const bundle = join3(temporary, "app.js");
|
|
1007
|
+
const { build: esbuild } = await import("esbuild");
|
|
1008
|
+
const bundleApp = () => esbuild({
|
|
1009
|
+
entryPoints: [entry],
|
|
1010
|
+
outfile: bundle,
|
|
1011
|
+
bundle: true,
|
|
1012
|
+
platform: "neutral",
|
|
1013
|
+
mainFields: ["module", "main"],
|
|
1014
|
+
format: "esm",
|
|
1015
|
+
target: "es2023",
|
|
1016
|
+
minify: !process.env.TARVE_TXIKI_DEBUG,
|
|
1017
|
+
jsx: "automatic",
|
|
1018
|
+
jsxImportSource: "@tarve/core",
|
|
1019
|
+
logLevel: "silent",
|
|
1020
|
+
define: {
|
|
1021
|
+
...define,
|
|
1022
|
+
"process.env.NODE_ENV": JSON.stringify("production"),
|
|
1023
|
+
"import.meta.dirname": "globalThis.__tarveDirname",
|
|
1024
|
+
TARVE_TXIKI_PLATFORM: JSON.stringify(config.platform),
|
|
1025
|
+
TARVE_TXIKI_NATIVE_NAME: JSON.stringify(config.nativeName)
|
|
1026
|
+
},
|
|
1027
|
+
plugins: [runtime],
|
|
1028
|
+
metafile: !!process.env.TARVE_TXIKI_DEBUG
|
|
1029
|
+
});
|
|
1030
|
+
for (let attempt = 0;; attempt++) {
|
|
1031
|
+
try {
|
|
1032
|
+
const result = await bundleApp();
|
|
1033
|
+
if (process.env.TARVE_TXIKI_DEBUG)
|
|
1034
|
+
writeFileSync3(`${process.env.TARVE_TXIKI_DEBUG}.meta.json`, JSON.stringify(result.metafile));
|
|
1035
|
+
break;
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
const errors = error.errors ?? [];
|
|
1038
|
+
const lacking = errors.map(({ text }) => /^No matching export in "tarve-node:([^"]+)" for import "([^"]+)"$/.exec(text));
|
|
1039
|
+
if (!lacking.length || lacking.some((match) => !match) || attempt > 3)
|
|
1040
|
+
throw error;
|
|
1041
|
+
for (const match of lacking) {
|
|
1042
|
+
if (!missing.has(match[1]))
|
|
1043
|
+
missing.set(match[1], new Set);
|
|
1044
|
+
missing.get(match[1]).add(match[2]);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
assertAvailable(readFileSync3(bundle, "utf8"), importers);
|
|
1049
|
+
if (process.env.TARVE_TXIKI_DEBUG)
|
|
1050
|
+
writeFileSync3(process.env.TARVE_TXIKI_DEBUG, readFileSync3(bundle));
|
|
1051
|
+
const compiled = join3(temporary, `compiled${config.executableSuffix}`);
|
|
1052
|
+
execFileSync(tjs, ["compile", bundle, compiled], { stdio: "pipe" });
|
|
1053
|
+
const payload = txikiPayload(readFileSync3(compiled), readFileSync3(host).byteLength);
|
|
1054
|
+
const executable = join3(temporary, `base${config.executableSuffix}`);
|
|
1055
|
+
writeFileSync3(executable, readFileSync3(base));
|
|
1056
|
+
if (config.platform === "win32") {
|
|
1057
|
+
const tarveVersion = JSON.parse(readFileSync3(resolve2(root, "../../package.json"), "utf8")).version;
|
|
1058
|
+
(await Promise.resolve().then(() => (init_windows_executable(), exports_windows_executable))).brandWindowsExecutable(executable, {
|
|
1059
|
+
name: metadata.name,
|
|
1060
|
+
version: metadata.version ?? tarveVersion,
|
|
1061
|
+
filename: basename3(outfile),
|
|
1062
|
+
description: metadata.description,
|
|
1063
|
+
publisher: metadata.publisher,
|
|
1064
|
+
copyright: metadata.copyright,
|
|
1065
|
+
ico: images?.ico
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
1068
|
+
const files = [{ name: config.nativeName, data: readFileSync3(library), gzip: true }, ...assets];
|
|
1069
|
+
await mkdir(dirname3(outfile), { recursive: true });
|
|
1070
|
+
await rm(outfile, { force: true });
|
|
1071
|
+
writeFileSync3(outfile, fuse(readFileSync3(executable), files, payload));
|
|
1072
|
+
if (config.platform !== "win32")
|
|
1073
|
+
chmodSync(outfile, 493);
|
|
1074
|
+
if (config.platform === "linux" && (metadata.icon || metadata.appId))
|
|
1075
|
+
writeLinuxDesktopEntry(outfile, metadata, images?.png);
|
|
1076
|
+
return outfile;
|
|
1077
|
+
} finally {
|
|
1078
|
+
if (options.compileJsx)
|
|
1079
|
+
await (await Promise.resolve().then(() => (init_jsx_compile(), exports_jsx_compile))).closeJsxCompiler();
|
|
1080
|
+
await rm(temporary, { recursive: true, force: true });
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
function assertAvailable(bundle, importers = new Map) {
|
|
1084
|
+
const apis = [...new Set([...bundle.matchAll(new RegExp(`${UNAVAILABLE}node:([\\w/.-]+)`, "g"))].map((match) => match[1]))].sort();
|
|
1085
|
+
const bun = [...new Set([...bundle.matchAll(/(?<![\w$.])Bun\.([A-Za-z_$][\w$]*)/g)].filter((match) => !bundle.slice(Math.max(0, match.index - 400), match.index).includes("typeof Bun")).map((match) => `Bun.${match[1]}`))].sort();
|
|
1086
|
+
if (!apis.length && !bun.length)
|
|
1087
|
+
return;
|
|
1088
|
+
const lines = apis.map((api) => {
|
|
1089
|
+
const [module, name] = api.split(".");
|
|
1090
|
+
const users = [...importers.get(module) ?? []].filter((file) => !name || !existsSync3(file) || new RegExp(`\\b${name}\\b`).test(readFileSync3(file, "utf8"))).map((file) => relative2(process.cwd(), file).replaceAll("\\", "/"));
|
|
1091
|
+
return ` node:${api}${users.length ? ` (imported by ${users.slice(0, 3).join(", ")}${users.length > 3 ? ", \u2026" : ""})` : ""}`;
|
|
1092
|
+
});
|
|
1093
|
+
throw new Error([
|
|
1094
|
+
"This app reaches APIs the txiki.js runtime does not provide:",
|
|
1095
|
+
...lines,
|
|
1096
|
+
...bun.map((api) => ` ${api} (the Bun global; guard it with typeof Bun !== "undefined")`),
|
|
1097
|
+
"Remove those calls from code the app can run, or build with --runtime bun or --runtime node."
|
|
1098
|
+
].join(`
|
|
1099
|
+
`));
|
|
1100
|
+
}
|
|
1101
|
+
function txikiPayload(compiled, hostSize) {
|
|
1102
|
+
const trailer = compiled.subarray(compiled.length - 12);
|
|
1103
|
+
const offset = new DataView(trailer.buffer, trailer.byteOffset, 12).getUint32(8, true);
|
|
1104
|
+
if (new TextDecoder().decode(trailer.subarray(0, 8)) !== TXIKI_MAGIC || offset !== hostSize) {
|
|
1105
|
+
throw new Error("Unrecognized `tjs compile` output; this txiki.js version is not supported.");
|
|
1106
|
+
}
|
|
1107
|
+
return compiled.subarray(offset, compiled.length - 12);
|
|
1108
|
+
}
|
|
1109
|
+
function fuse(executable, files, payload) {
|
|
1110
|
+
const parts = [executable];
|
|
1111
|
+
const index = [];
|
|
1112
|
+
let offset = executable.length;
|
|
1113
|
+
for (const file of files) {
|
|
1114
|
+
const stored = file.gzip ? gzipSync(file.data, { level: 9 }) : file.data;
|
|
1115
|
+
index.push({ name: file.name, offset, length: stored.length, size: file.data.length, sha256: createHash2("sha256").update(file.data).digest("hex"), gzip: file.gzip });
|
|
1116
|
+
parts.push(stored);
|
|
1117
|
+
offset += stored.length;
|
|
1118
|
+
}
|
|
1119
|
+
const json = new TextEncoder().encode(JSON.stringify(index));
|
|
1120
|
+
const header = new Uint8Array(16);
|
|
1121
|
+
new DataView(header.buffer).setUint32(0, json.length, true);
|
|
1122
|
+
header.set(new TextEncoder().encode(BLOB_MAGIC), 8);
|
|
1123
|
+
parts.push(json, header);
|
|
1124
|
+
const payloadOffset = offset + json.length + header.length;
|
|
1125
|
+
const trailer = new Uint8Array(12);
|
|
1126
|
+
trailer.set(new TextEncoder().encode(TXIKI_MAGIC));
|
|
1127
|
+
new DataView(trailer.buffer).setUint32(8, payloadOffset, true);
|
|
1128
|
+
parts.push(payload, trailer);
|
|
1129
|
+
const out = new Uint8Array(parts.reduce((size, part) => size + part.length, 0));
|
|
1130
|
+
let position = 0;
|
|
1131
|
+
for (const part of parts) {
|
|
1132
|
+
out.set(part, position);
|
|
1133
|
+
position += part.length;
|
|
1134
|
+
}
|
|
1135
|
+
return out;
|
|
1136
|
+
}
|
|
1137
|
+
var TXIKI_MAGIC = "tx1k1.js", BLOB_MAGIC = "TARVEBLB", NODE_SHIMS, ASSET, UNAVAILABLE = "tarve-txiki-unavailable:";
|
|
1138
|
+
var init_txiki_build = __esm(() => {
|
|
1139
|
+
init_build();
|
|
1140
|
+
init_package_metadata();
|
|
1141
|
+
init_targets();
|
|
1142
|
+
NODE_SHIMS = {
|
|
1143
|
+
fs: "fs",
|
|
1144
|
+
"fs/promises": "fs-promises",
|
|
1145
|
+
path: "path",
|
|
1146
|
+
os: "os",
|
|
1147
|
+
crypto: "crypto",
|
|
1148
|
+
net: "net",
|
|
1149
|
+
module: "module",
|
|
1150
|
+
zlib: "zlib",
|
|
1151
|
+
events: "events",
|
|
1152
|
+
child_process: "child-process",
|
|
1153
|
+
"timers/promises": "timers-promises"
|
|
1154
|
+
};
|
|
1155
|
+
ASSET = /\.(?:png|jpe?g|webp|gif|svg|ico|ttf|otf|woff2?)$/i;
|
|
1156
|
+
});
|
|
1157
|
+
|
|
556
1158
|
// packages/core/esbuild-file-imports.ts
|
|
557
|
-
import { readFileSync as
|
|
558
|
-
import { dirname as
|
|
559
|
-
var
|
|
1159
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
1160
|
+
import { dirname as dirname4, resolve as resolve3 } from "path";
|
|
1161
|
+
var ASSET2, fileImportAttributes;
|
|
560
1162
|
var init_esbuild_file_imports = __esm(() => {
|
|
561
|
-
|
|
1163
|
+
ASSET2 = /\.(?:png|jpe?g|webp|gif|svg)$/i;
|
|
562
1164
|
fileImportAttributes = {
|
|
563
1165
|
name: "tarve-file-import-attributes",
|
|
564
1166
|
setup(build) {
|
|
@@ -566,12 +1168,12 @@ var init_esbuild_file_imports = __esm(() => {
|
|
|
566
1168
|
if (args.namespace === "tarve-file") {
|
|
567
1169
|
return args.path.startsWith("node:") ? { path: args.path, external: true } : { path: args.path, namespace: "tarve-file-copy" };
|
|
568
1170
|
}
|
|
569
|
-
const type = args.with?.type ?? (
|
|
1171
|
+
const type = args.with?.type ?? (ASSET2.test(args.path) && args.kind === "import-statement" ? "file" : undefined);
|
|
570
1172
|
if (type !== "file" && type !== "text")
|
|
571
1173
|
return;
|
|
572
|
-
return { path:
|
|
1174
|
+
return { path: resolve3(dirname4(args.importer), args.path), namespace: `tarve-${type}` };
|
|
573
1175
|
});
|
|
574
|
-
build.onLoad({ filter: /.*/, namespace: "tarve-text" }, (args) => ({ contents:
|
|
1176
|
+
build.onLoad({ filter: /.*/, namespace: "tarve-text" }, (args) => ({ contents: readFileSync4(args.path, "utf8"), loader: "text" }));
|
|
575
1177
|
build.onLoad({ filter: /.*/, namespace: "tarve-file" }, (args) => ({
|
|
576
1178
|
contents: [
|
|
577
1179
|
`import relative from ${JSON.stringify(args.path)};`,
|
|
@@ -580,10 +1182,10 @@ var init_esbuild_file_imports = __esm(() => {
|
|
|
580
1182
|
].join(`
|
|
581
1183
|
`),
|
|
582
1184
|
loader: "js",
|
|
583
|
-
resolveDir:
|
|
1185
|
+
resolveDir: dirname4(args.path)
|
|
584
1186
|
}));
|
|
585
1187
|
build.onLoad({ filter: /.*/, namespace: "tarve-file-copy" }, (args) => ({
|
|
586
|
-
contents:
|
|
1188
|
+
contents: readFileSync4(args.path),
|
|
587
1189
|
loader: "file"
|
|
588
1190
|
}));
|
|
589
1191
|
}
|
|
@@ -591,10 +1193,10 @@ var init_esbuild_file_imports = __esm(() => {
|
|
|
591
1193
|
});
|
|
592
1194
|
|
|
593
1195
|
// packages/core/node-target.ts
|
|
594
|
-
import { createHash as
|
|
595
|
-
import { chmodSync, existsSync as
|
|
1196
|
+
import { createHash as createHash3, randomUUID } from "crypto";
|
|
1197
|
+
import { chmodSync as chmodSync2, existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync5, renameSync, rmSync, writeFileSync as writeFileSync4 } from "fs";
|
|
596
1198
|
import { homedir } from "os";
|
|
597
|
-
import { join as
|
|
1199
|
+
import { join as join4 } from "path";
|
|
598
1200
|
import { gunzipSync } from "zlib";
|
|
599
1201
|
function distribution(target, version) {
|
|
600
1202
|
return target === "windows-x64" ? { file: "win-x64/node.exe", executable: "node.exe" } : { file: `node-v${version}-linux-x64.tar.gz`, member: `node-v${version}-linux-x64/bin/node`, executable: "node" };
|
|
@@ -603,8 +1205,8 @@ function cacheRoot() {
|
|
|
603
1205
|
if (process.env.TARVE_CACHE_DIR)
|
|
604
1206
|
return process.env.TARVE_CACHE_DIR;
|
|
605
1207
|
if (process.platform === "win32")
|
|
606
|
-
return
|
|
607
|
-
return
|
|
1208
|
+
return join4(process.env.LOCALAPPDATA ?? join4(homedir(), "AppData", "Local"), "tarve", "cache");
|
|
1209
|
+
return join4(process.env.XDG_CACHE_HOME ?? join4(homedir(), ".cache"), "tarve");
|
|
608
1210
|
}
|
|
609
1211
|
function mirror() {
|
|
610
1212
|
return (process.env.NODEJS_ORG_MIRROR ?? "https://nodejs.org/dist").replace(/\/+$/, "");
|
|
@@ -640,15 +1242,15 @@ function extractTarMember(archive, member) {
|
|
|
640
1242
|
throw new Error(`${member} not found in the Node.js archive`);
|
|
641
1243
|
}
|
|
642
1244
|
function assertNodeVersion(executable, version) {
|
|
643
|
-
if (!
|
|
1245
|
+
if (!readFileSync5(executable).includes(`node-v${version}`)) {
|
|
644
1246
|
throw new Error(`${executable} is not Node.js v${version}; the target executable must match the Node.js that builds the app`);
|
|
645
1247
|
}
|
|
646
1248
|
}
|
|
647
1249
|
async function targetNodeExecutable(target, version) {
|
|
648
1250
|
const { file, member, executable } = distribution(target, version);
|
|
649
|
-
const directory =
|
|
650
|
-
const path =
|
|
651
|
-
if (
|
|
1251
|
+
const directory = join4(cacheRoot(), "node", `v${version}`, target);
|
|
1252
|
+
const path = join4(directory, executable);
|
|
1253
|
+
if (existsSync4(path))
|
|
652
1254
|
return path;
|
|
653
1255
|
const base = `${mirror()}/v${version}`;
|
|
654
1256
|
const sums = (await download(`${base}/SHASUMS256.txt`)).toString("utf8");
|
|
@@ -656,120 +1258,65 @@ async function targetNodeExecutable(target, version) {
|
|
|
656
1258
|
if (!expected)
|
|
657
1259
|
throw new Error(`${file} is not listed in the Node.js v${version} SHASUMS256.txt`);
|
|
658
1260
|
const payload = await download(`${base}/${file}`);
|
|
659
|
-
const actual =
|
|
1261
|
+
const actual = createHash3("sha256").update(payload).digest("hex");
|
|
660
1262
|
if (actual !== expected)
|
|
661
1263
|
throw new Error(`Checksum mismatch for ${file}: expected ${expected}, got ${actual}`);
|
|
662
1264
|
const binary = member ? extractTarMember(gunzipSync(payload), member) : payload;
|
|
663
1265
|
mkdirSync2(directory, { recursive: true });
|
|
664
|
-
const temporary =
|
|
1266
|
+
const temporary = join4(directory, `${executable}.${randomUUID()}.tmp`);
|
|
665
1267
|
try {
|
|
666
|
-
|
|
1268
|
+
writeFileSync4(temporary, binary, { mode: 493 });
|
|
667
1269
|
try {
|
|
668
1270
|
renameSync(temporary, path);
|
|
669
1271
|
} catch (error) {
|
|
670
|
-
if (!
|
|
1272
|
+
if (!existsSync4(path))
|
|
671
1273
|
throw error;
|
|
672
1274
|
}
|
|
673
1275
|
} finally {
|
|
674
1276
|
rmSync(temporary, { force: true });
|
|
675
1277
|
}
|
|
676
1278
|
if (process.platform !== "win32")
|
|
677
|
-
|
|
1279
|
+
chmodSync2(path, 493);
|
|
678
1280
|
return path;
|
|
679
1281
|
}
|
|
680
1282
|
var init_node_target = () => {};
|
|
681
1283
|
|
|
682
|
-
// packages/core/windows-executable.ts
|
|
683
|
-
var exports_windows_executable = {};
|
|
684
|
-
__export(exports_windows_executable, {
|
|
685
|
-
brandWindowsExecutable: () => brandWindowsExecutable
|
|
686
|
-
});
|
|
687
|
-
import { readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "fs";
|
|
688
|
-
import { Data, NtExecutable, NtExecutableResource, Resource } from "resedit";
|
|
689
|
-
function numericVersion(version) {
|
|
690
|
-
const parts = version.split(/[.+-]/).slice(0, 4).map((part) => Number.parseInt(part, 10));
|
|
691
|
-
return [0, 1, 2, 3].map((index) => {
|
|
692
|
-
const value = parts[index];
|
|
693
|
-
return Number.isInteger(value) && value >= 0 && value <= 65535 ? value : 0;
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
function brandWindowsExecutable(path, info) {
|
|
697
|
-
const executable = NtExecutable.from(readFileSync4(path), { ignoreCert: true });
|
|
698
|
-
const resources = NtExecutableResource.from(executable);
|
|
699
|
-
const versionInfo = Resource.VersionInfo.fromEntries(resources.entries)[0] ?? Resource.VersionInfo.createEmpty();
|
|
700
|
-
const languages = versionInfo.getAllLanguagesForStringValues();
|
|
701
|
-
if (languages.length === 0)
|
|
702
|
-
languages.push({ lang: 1033, codepage: 1200 });
|
|
703
|
-
const [major, minor, patch, revision] = numericVersion(info.version);
|
|
704
|
-
const text = `${major}.${minor}.${patch}.${revision}`;
|
|
705
|
-
for (const language of languages) {
|
|
706
|
-
for (const key of ["CompanyName", "LegalCopyright", "LegalTrademarks", "Comments", "PrivateBuild", "SpecialBuild"]) {
|
|
707
|
-
versionInfo.removeStringValue(language, key);
|
|
708
|
-
}
|
|
709
|
-
versionInfo.setStringValues(language, {
|
|
710
|
-
FileDescription: info.description ?? `${info.name} \u2014 native Tarve application`,
|
|
711
|
-
...info.publisher ? { CompanyName: info.publisher } : {},
|
|
712
|
-
...info.copyright ? { LegalCopyright: info.copyright } : {},
|
|
713
|
-
ProductName: info.name,
|
|
714
|
-
InternalName: info.name,
|
|
715
|
-
OriginalFilename: info.filename,
|
|
716
|
-
FileVersion: text,
|
|
717
|
-
ProductVersion: text
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
versionInfo.setFileVersion(major, minor, patch, revision);
|
|
721
|
-
versionInfo.setProductVersion(major, minor, patch, revision);
|
|
722
|
-
versionInfo.outputToResourceEntries(resources.entries);
|
|
723
|
-
if (info.ico) {
|
|
724
|
-
const groups = Resource.IconGroupEntry.fromEntries(resources.entries);
|
|
725
|
-
const group = groups[0];
|
|
726
|
-
const icons = Data.IconFile.from(info.ico).icons.map((icon) => icon.data);
|
|
727
|
-
Resource.IconGroupEntry.replaceIconsForResource(resources.entries, group?.id ?? 1, group?.lang ?? 1033, icons);
|
|
728
|
-
}
|
|
729
|
-
resources.outputResource(executable);
|
|
730
|
-
const output = Buffer.from(executable.generate());
|
|
731
|
-
output.writeUInt16LE(IMAGE_SUBSYSTEM_WINDOWS_GUI, output.readUInt32LE(60) + 24 + 68);
|
|
732
|
-
writeFileSync3(path, output);
|
|
733
|
-
}
|
|
734
|
-
var IMAGE_SUBSYSTEM_WINDOWS_GUI = 2;
|
|
735
|
-
var init_windows_executable = () => {};
|
|
736
|
-
|
|
737
1284
|
// packages/core/node-build.ts
|
|
738
|
-
import { execFileSync } from "child_process";
|
|
739
|
-
import { existsSync as
|
|
740
|
-
import { mkdir, rm } from "fs/promises";
|
|
741
|
-
import { tmpdir } from "os";
|
|
742
|
-
import { basename as
|
|
743
|
-
import { nativePath } from "#tarve/runtime";
|
|
1285
|
+
import { execFileSync as execFileSync2 } from "child_process";
|
|
1286
|
+
import { existsSync as existsSync5, mkdtempSync as mkdtempSync2, writeFileSync as writeFileSync5, readFileSync as readFileSync6 } from "fs";
|
|
1287
|
+
import { mkdir as mkdir2, rm as rm2 } from "fs/promises";
|
|
1288
|
+
import { tmpdir as tmpdir2 } from "os";
|
|
1289
|
+
import { basename as basename4, dirname as dirname5, join as join5, relative as relative3, resolve as resolve4 } from "path";
|
|
1290
|
+
import { nativePath as nativePath2 } from "#tarve/runtime";
|
|
744
1291
|
async function buildNode(options) {
|
|
745
1292
|
const target = options.target ?? hostBuildTarget();
|
|
746
1293
|
if (!target)
|
|
747
1294
|
throw new Error(`Unsupported Node.js build host: ${process.platform}-${process.arch}`);
|
|
748
1295
|
const config = targetConfig(target);
|
|
749
1296
|
const node = options.nodeExecutable ?? (process.versions.bun ? Bun.which("node") ?? "node" : process.execPath);
|
|
750
|
-
const version =
|
|
1297
|
+
const version = execFileSync2(node, ["--version"], { encoding: "utf8" }).trim();
|
|
751
1298
|
const match = /^v(\d+)\.(\d+)\./.exec(version);
|
|
752
1299
|
if (!match || Number(match[1]) < 26 || Number(match[1]) === 26 && Number(match[2]) < 10) {
|
|
753
1300
|
throw new Error(`Node.js 26.10+ is required for node:ffi inside a SEA (found ${version})`);
|
|
754
1301
|
}
|
|
755
1302
|
const { metadata, images, define } = buildMetadata(options.entrypoint, metadataOverrides(options));
|
|
756
|
-
const outfile =
|
|
1303
|
+
const outfile = resolve4(options.outfile ?? `dist/${metadata.name}${config.executableSuffix}`);
|
|
757
1304
|
let executable;
|
|
758
1305
|
if (options.targetExecutable) {
|
|
759
|
-
executable =
|
|
760
|
-
if (!
|
|
1306
|
+
executable = resolve4(options.targetExecutable);
|
|
1307
|
+
if (!existsSync5(executable))
|
|
761
1308
|
throw new Error(`Target Node.js executable is missing: ${executable}`);
|
|
762
1309
|
assertNodeVersion(executable, version.slice(1));
|
|
763
1310
|
}
|
|
764
|
-
const library =
|
|
765
|
-
if (!
|
|
1311
|
+
const library = resolve4(options.nativeLibrary ?? (target === hostBuildTarget() ? nativePath2() : join5(import.meta.dirname, "../../native", config.nativeDirectory, config.nativeName)));
|
|
1312
|
+
if (!existsSync5(library))
|
|
766
1313
|
throw new Error(`Tarve native library missing: ${library}`);
|
|
767
|
-
const temporary =
|
|
1314
|
+
const temporary = mkdtempSync2(join5(tmpdir2(), "tarve-node-build-"));
|
|
768
1315
|
try {
|
|
769
1316
|
const root = import.meta.dirname;
|
|
770
|
-
const source =
|
|
1317
|
+
const source = existsSync5(join5(root, "src/index.ts"));
|
|
771
1318
|
if (!options.nativeLibrary && (!source || target !== hostBuildTarget())) {
|
|
772
|
-
const expected = source ? await createNativeCompatibilityManifest(
|
|
1319
|
+
const expected = source ? await createNativeCompatibilityManifest(resolve4(root, "../.."), JSON.parse(readFileSync6(resolve4(root, "../../package.json"), "utf8")).version) : await readNativeCompatibilityManifest(join5(root, NATIVE_COMPATIBILITY_MANIFEST_NAME));
|
|
773
1320
|
await assertNativeRuntimeCompatible(library, target, expected);
|
|
774
1321
|
}
|
|
775
1322
|
if (!executable && target !== hostBuildTarget()) {
|
|
@@ -777,8 +1324,8 @@ async function buildNode(options) {
|
|
|
777
1324
|
}
|
|
778
1325
|
const { build: bundle } = await import("esbuild");
|
|
779
1326
|
const result = await bundle({
|
|
780
|
-
entryPoints: [
|
|
781
|
-
outfile:
|
|
1327
|
+
entryPoints: [resolve4(options.entrypoint)],
|
|
1328
|
+
outfile: join5(temporary, "app.mjs"),
|
|
782
1329
|
bundle: true,
|
|
783
1330
|
platform: "node",
|
|
784
1331
|
format: "esm",
|
|
@@ -792,10 +1339,18 @@ async function buildNode(options) {
|
|
|
792
1339
|
plugins: [fileImportAttributes, {
|
|
793
1340
|
name: "tarve-node-runtime",
|
|
794
1341
|
setup(build) {
|
|
1342
|
+
if (options.compileJsx) {
|
|
1343
|
+
build.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
|
|
1344
|
+
if (/[\\/]node_modules[\\/]/.test(args.path) || args.path.startsWith(join5(root, "src")))
|
|
1345
|
+
return;
|
|
1346
|
+
await Promise.resolve().then(() => init_jsx_compile());
|
|
1347
|
+
return { contents: (await compileJsx(readFileSync6(args.path, "utf8"))).code, loader: args.path.endsWith(".jsx") ? "jsx" : "tsx", resolveDir: dirname5(args.path) };
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
795
1350
|
if (source) {
|
|
796
1351
|
build.onResolve({ filter: /^@tarve\/core(?:\/(?:jsx-runtime|jsx-dev-runtime))?$/ }, (args) => {
|
|
797
1352
|
const entry = args.path.slice("@tarve/core".length) || "/index";
|
|
798
|
-
return { path:
|
|
1353
|
+
return { path: join5(root, "src", `${entry.slice(1)}.ts`) };
|
|
799
1354
|
});
|
|
800
1355
|
}
|
|
801
1356
|
build.onResolve({ filter: /^#tarve\/runtime$/ }, () => ({ path: "native-runtime", namespace: "tarve-node" }));
|
|
@@ -809,11 +1364,11 @@ async function buildNode(options) {
|
|
|
809
1364
|
const assets = { [config.nativeName]: seaPath(library) };
|
|
810
1365
|
for (const [path, output] of Object.entries(result.metafile.outputs)) {
|
|
811
1366
|
if (!output.entryPoint)
|
|
812
|
-
assets[
|
|
1367
|
+
assets[relative3(temporary, resolve4(path)).replaceAll("\\", "/")] = seaPath(resolve4(path));
|
|
813
1368
|
}
|
|
814
|
-
const sea =
|
|
815
|
-
|
|
816
|
-
main: seaPath(
|
|
1369
|
+
const sea = join5(temporary, "sea.json");
|
|
1370
|
+
writeFileSync5(sea, JSON.stringify({
|
|
1371
|
+
main: seaPath(join5(temporary, "app.mjs")),
|
|
817
1372
|
mainFormat: "module",
|
|
818
1373
|
output: seaPath(outfile),
|
|
819
1374
|
...executable ? { executable: seaPath(executable) } : {},
|
|
@@ -824,15 +1379,15 @@ async function buildNode(options) {
|
|
|
824
1379
|
execArgv: ["--disable-warning=ExperimentalWarning"],
|
|
825
1380
|
execArgvExtension: "env"
|
|
826
1381
|
}));
|
|
827
|
-
await
|
|
828
|
-
await
|
|
829
|
-
|
|
1382
|
+
await mkdir2(dirname5(outfile), { recursive: true });
|
|
1383
|
+
await rm2(outfile, { force: true });
|
|
1384
|
+
execFileSync2(node, ["--build-sea", sea], { stdio: "pipe" });
|
|
830
1385
|
if (config.platform === "win32") {
|
|
831
|
-
const tarveVersion = JSON.parse(
|
|
1386
|
+
const tarveVersion = JSON.parse(readFileSync6(resolve4(root, "../../package.json"), "utf8")).version;
|
|
832
1387
|
(await Promise.resolve().then(() => (init_windows_executable(), exports_windows_executable))).brandWindowsExecutable(outfile, {
|
|
833
1388
|
name: metadata.name,
|
|
834
1389
|
version: metadata.version ?? tarveVersion,
|
|
835
|
-
filename:
|
|
1390
|
+
filename: basename4(outfile),
|
|
836
1391
|
description: metadata.description,
|
|
837
1392
|
publisher: metadata.publisher,
|
|
838
1393
|
copyright: metadata.copyright,
|
|
@@ -843,7 +1398,9 @@ async function buildNode(options) {
|
|
|
843
1398
|
writeLinuxDesktopEntry(outfile, metadata, images?.png);
|
|
844
1399
|
return outfile;
|
|
845
1400
|
} finally {
|
|
846
|
-
|
|
1401
|
+
if (options.compileJsx)
|
|
1402
|
+
await (await Promise.resolve().then(() => (init_jsx_compile(), exports_jsx_compile))).closeJsxCompiler();
|
|
1403
|
+
await rm2(temporary, { recursive: true, force: true });
|
|
847
1404
|
}
|
|
848
1405
|
}
|
|
849
1406
|
function seaPath(path) {
|
|
@@ -853,22 +1410,22 @@ var init_node_build = __esm(() => {
|
|
|
853
1410
|
init_esbuild_file_imports();
|
|
854
1411
|
init_targets();
|
|
855
1412
|
init_build();
|
|
856
|
-
|
|
1413
|
+
init_package_metadata();
|
|
857
1414
|
init_native_runtime();
|
|
858
1415
|
init_node_target();
|
|
859
1416
|
});
|
|
860
1417
|
|
|
861
1418
|
// packages/core/build.ts
|
|
862
|
-
import { existsSync as
|
|
863
|
-
import { mkdir as
|
|
864
|
-
import { tmpdir as
|
|
865
|
-
import { dirname as
|
|
1419
|
+
import { existsSync as existsSync6, mkdtempSync as mkdtempSync3, writeFileSync as writeFileSync6 } from "fs";
|
|
1420
|
+
import { mkdir as mkdir3, rm as rm3 } from "fs/promises";
|
|
1421
|
+
import { tmpdir as tmpdir3 } from "os";
|
|
1422
|
+
import { dirname as dirname6, join as join6, resolve as resolve5 } from "path";
|
|
866
1423
|
import { fileURLToPath } from "url";
|
|
867
|
-
import { nativePath as
|
|
1424
|
+
import { nativePath as nativePath3 } from "#tarve/runtime";
|
|
868
1425
|
function resolveNativeLibrary(target, override) {
|
|
869
1426
|
if (override) {
|
|
870
|
-
const path =
|
|
871
|
-
if (!
|
|
1427
|
+
const path = resolve5(override);
|
|
1428
|
+
if (!existsSync6(path))
|
|
872
1429
|
throw new Error(`Tarve native library does not exist: ${path}`);
|
|
873
1430
|
return path;
|
|
874
1431
|
}
|
|
@@ -876,19 +1433,23 @@ function resolveNativeLibrary(target, override) {
|
|
|
876
1433
|
const hostTarget = hostBuildTarget();
|
|
877
1434
|
if (hostTarget === target) {
|
|
878
1435
|
try {
|
|
879
|
-
return
|
|
1436
|
+
return nativePath3();
|
|
880
1437
|
} catch {}
|
|
881
1438
|
}
|
|
882
1439
|
const candidates = [
|
|
883
|
-
|
|
884
|
-
|
|
1440
|
+
join6(import.meta.dir, config.nativeName),
|
|
1441
|
+
resolve5(import.meta.dir, "../../native", config.nativeDirectory, config.nativeName)
|
|
885
1442
|
];
|
|
886
|
-
const found = candidates.find(
|
|
1443
|
+
const found = candidates.find(existsSync6);
|
|
887
1444
|
if (found)
|
|
888
1445
|
return found;
|
|
889
1446
|
throw new Error(`Tarve native library missing for ${target}. Expected ${config.nativeName} in native/${config.nativeDirectory}. ` + "Use a Tarve package containing that target runtime or pass nativeLibrary explicitly.");
|
|
890
1447
|
}
|
|
891
1448
|
async function build(options) {
|
|
1449
|
+
if (options.runtime === "txiki") {
|
|
1450
|
+
await Promise.resolve().then(() => init_txiki_build());
|
|
1451
|
+
return buildTxiki(options);
|
|
1452
|
+
}
|
|
892
1453
|
if (options.runtime === "node") {
|
|
893
1454
|
await Promise.resolve().then(() => init_node_build());
|
|
894
1455
|
return buildNode(options);
|
|
@@ -899,19 +1460,19 @@ async function build(options) {
|
|
|
899
1460
|
if (!isBuildTarget(target))
|
|
900
1461
|
throw new TypeError(`Unsupported Tarve build target: ${String(target)}. Expected ${BUILD_TARGETS.join(" or ")}.`);
|
|
901
1462
|
const config = targetConfig(target);
|
|
902
|
-
const entrypoint =
|
|
903
|
-
const packageMetadata = await Bun.file(
|
|
1463
|
+
const entrypoint = resolve5(options.entrypoint);
|
|
1464
|
+
const packageMetadata = await Bun.file(resolve5(import.meta.dir, "../../package.json")).json();
|
|
904
1465
|
if (typeof packageMetadata.version !== "string" || packageMetadata.version.length === 0) {
|
|
905
1466
|
throw new Error("Tarve package version is missing.");
|
|
906
1467
|
}
|
|
907
1468
|
const { metadata, images, define } = buildMetadata(entrypoint, metadataOverrides(options));
|
|
908
1469
|
const name = metadata.name;
|
|
909
|
-
const outfile =
|
|
1470
|
+
const outfile = resolve5(options.outfile ?? `dist/${name}${config.executableSuffix}`);
|
|
910
1471
|
const library = resolveNativeLibrary(target, options.nativeLibrary);
|
|
911
1472
|
const assetsModule = fileURLToPath(import.meta.resolve("#tarve/assets"));
|
|
912
|
-
const sourceDirectory =
|
|
913
|
-
const repositorySource =
|
|
914
|
-
const expectedCompatibility = repositorySource ? await createNativeCompatibilityManifest(
|
|
1473
|
+
const sourceDirectory = join6(import.meta.dir, "src");
|
|
1474
|
+
const repositorySource = existsSync6(join6(sourceDirectory, "index.ts"));
|
|
1475
|
+
const expectedCompatibility = repositorySource ? await createNativeCompatibilityManifest(resolve5(import.meta.dir, "../.."), packageMetadata.version) : await readNativeCompatibilityManifest(join6(import.meta.dir, NATIVE_COMPATIBILITY_MANIFEST_NAME));
|
|
915
1476
|
const requireRuntimeManifest = target !== hostBuildTarget() || !options.nativeLibrary && !repositorySource;
|
|
916
1477
|
if (requireRuntimeManifest) {
|
|
917
1478
|
await assertNativeRuntimeCompatible(library, target, expectedCompatibility);
|
|
@@ -921,32 +1482,43 @@ async function build(options) {
|
|
|
921
1482
|
sha256: new Bun.CryptoHasher("sha256").update(libraryBytes).digest("hex"),
|
|
922
1483
|
size: libraryBytes.byteLength
|
|
923
1484
|
};
|
|
1485
|
+
const packDirectory = mkdtempSync3(join6(tmpdir3(), "tarve-native-"));
|
|
1486
|
+
const packedLibrary = join6(packDirectory, `${config.nativeName}.zst`);
|
|
1487
|
+
writeFileSync6(packedLibrary, Bun.zstdCompressSync(libraryBytes, { level: NATIVE_ZSTD_LEVEL }));
|
|
924
1488
|
const runtime = {
|
|
925
1489
|
name: "tarve-native-runtime",
|
|
926
1490
|
setup(builder) {
|
|
927
1491
|
if (repositorySource) {
|
|
928
|
-
builder.onResolve({ filter: /^tarve$/ }, () => ({ path:
|
|
929
|
-
builder.onResolve({ filter: /^tarve\/jsx-runtime$/ }, () => ({ path:
|
|
930
|
-
builder.onResolve({ filter: /^tarve\/jsx-dev-runtime$/ }, () => ({ path:
|
|
1492
|
+
builder.onResolve({ filter: /^tarve$/ }, () => ({ path: join6(sourceDirectory, "index.ts") }));
|
|
1493
|
+
builder.onResolve({ filter: /^tarve\/jsx-runtime$/ }, () => ({ path: join6(sourceDirectory, "jsx-runtime.ts") }));
|
|
1494
|
+
builder.onResolve({ filter: /^tarve\/jsx-dev-runtime$/ }, () => ({ path: join6(sourceDirectory, "jsx-dev-runtime.ts") }));
|
|
1495
|
+
}
|
|
1496
|
+
if (options.compileJsx) {
|
|
1497
|
+
builder.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
|
|
1498
|
+
if (/[\\/]node_modules[\\/]/.test(args.path) || args.path.startsWith(join6(import.meta.dir, "src")))
|
|
1499
|
+
return;
|
|
1500
|
+
await Promise.resolve().then(() => init_jsx_compile());
|
|
1501
|
+
return { contents: (await compileJsx(await Bun.file(args.path).text())).code, loader: args.path.endsWith(".jsx") ? "jsx" : "tsx" };
|
|
1502
|
+
});
|
|
931
1503
|
}
|
|
932
1504
|
builder.onResolve({ filter: /^#tarve\/runtime$/ }, () => ({ path: "runtime", namespace: "tarve" }));
|
|
933
1505
|
builder.onLoad({ filter: /^runtime$/, namespace: "tarve" }, () => ({
|
|
934
1506
|
loader: "ts",
|
|
935
1507
|
contents: [
|
|
936
|
-
`import library from ${JSON.stringify(
|
|
1508
|
+
`import library from ${JSON.stringify(packedLibrary)} with { type: "file" };`,
|
|
937
1509
|
`import { materializeAsset } from ${JSON.stringify(assetsModule)};`,
|
|
938
1510
|
`const digest = ${JSON.stringify(libraryDigest)};`,
|
|
939
|
-
`export function nativePath() { return materializeAsset(library, ${JSON.stringify(config.nativeName)}, digest); }`
|
|
1511
|
+
`export function nativePath() { return materializeAsset(library, ${JSON.stringify(config.nativeName)}, digest, "zstd"); }`
|
|
940
1512
|
].join(`
|
|
941
1513
|
`)
|
|
942
1514
|
}));
|
|
943
1515
|
}
|
|
944
1516
|
};
|
|
945
|
-
await
|
|
946
|
-
const iconDirectory = images && config.platform === "win32" ?
|
|
947
|
-
const icoPath = iconDirectory ?
|
|
1517
|
+
await mkdir3(dirname6(outfile), { recursive: true });
|
|
1518
|
+
const iconDirectory = images && config.platform === "win32" ? mkdtempSync3(join6(tmpdir3(), "tarve-icon-")) : undefined;
|
|
1519
|
+
const icoPath = iconDirectory ? join6(iconDirectory, "app.ico") : undefined;
|
|
948
1520
|
if (icoPath)
|
|
949
|
-
|
|
1521
|
+
writeFileSync6(icoPath, images.ico);
|
|
950
1522
|
try {
|
|
951
1523
|
const result = await Bun.build({
|
|
952
1524
|
entrypoints: [entrypoint],
|
|
@@ -975,8 +1547,11 @@ async function build(options) {
|
|
|
975
1547
|
if (!result.success)
|
|
976
1548
|
throw new AggregateError(result.logs, "Could not compile the Tarve application");
|
|
977
1549
|
} finally {
|
|
1550
|
+
if (options.compileJsx)
|
|
1551
|
+
await (await Promise.resolve().then(() => (init_jsx_compile(), exports_jsx_compile))).closeJsxCompiler();
|
|
1552
|
+
await rm3(packDirectory, { recursive: true, force: true });
|
|
978
1553
|
if (iconDirectory)
|
|
979
|
-
await
|
|
1554
|
+
await rm3(iconDirectory, { recursive: true, force: true });
|
|
980
1555
|
}
|
|
981
1556
|
if (config.platform === "linux" && (metadata.icon || metadata.appId))
|
|
982
1557
|
writeLinuxDesktopEntry(outfile, metadata, images?.png);
|
|
@@ -985,8 +1560,9 @@ async function build(options) {
|
|
|
985
1560
|
function metadataOverrides(options) {
|
|
986
1561
|
return { name: options.name, version: options.version, description: options.description, publisher: options.publisher, copyright: options.copyright, icon: options.icon, appId: options.appId };
|
|
987
1562
|
}
|
|
1563
|
+
var NATIVE_ZSTD_LEVEL = 12;
|
|
988
1564
|
var init_build = __esm(() => {
|
|
989
|
-
|
|
1565
|
+
init_package_metadata();
|
|
990
1566
|
init_targets();
|
|
991
1567
|
init_native_runtime();
|
|
992
1568
|
init_targets();
|