@patodo/localapp 0.2.6 → 0.2.9
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/.localapp-artifact.json +117 -97
- package/README.md +1 -1
- package/bin/localapp.mjs +592 -503
- package/package.json +1 -1
- package/runtime/native/adapter-manifest.json +1 -1
- package/runtime/native/win32-x64/localapp-native.exe +0 -0
- package/runtime/server/.localapp-server-runtime.json +58 -58
- package/runtime/server/bin/server-cli.cjs +49 -16
- package/runtime/server/bin/worker.cjs +18217 -18143
- package/runtime/server/web/404.html +1 -1
- package/runtime/server/web/inbox.html +1 -1
- package/runtime/server/web/inbox.txt +1 -1
- package/runtime/server/web/index.html +1 -1
- package/runtime/server/web/index.txt +1 -1
- package/runtime/server/web/my/analytics.html +1 -1
- package/runtime/server/web/my/analytics.txt +1 -1
- package/runtime/server/web/my/apps/placeholder/settings.html +1 -1
- package/runtime/server/web/my/apps/placeholder/settings.txt +1 -1
- package/runtime/server/web/my/apps.html +1 -1
- package/runtime/server/web/my/apps.txt +1 -1
- package/runtime/server/web/my/dashboard.html +1 -1
- package/runtime/server/web/my/dashboard.txt +1 -1
- package/runtime/server/web/my/device-actions.html +1 -1
- package/runtime/server/web/my/device-actions.txt +1 -1
- package/runtime/server/web/my/device-notifications.html +1 -1
- package/runtime/server/web/my/device-notifications.txt +1 -1
- package/runtime/server/web/my/favorites.html +1 -1
- package/runtime/server/web/my/favorites.txt +1 -1
- package/runtime/server/web/my/groups.html +1 -1
- package/runtime/server/web/my/groups.txt +1 -1
- package/runtime/server/web/my/info.html +1 -1
- package/runtime/server/web/my/info.txt +1 -1
- package/runtime/server/web/my/keys.html +1 -1
- package/runtime/server/web/my/keys.txt +1 -1
- package/runtime/server/web/my/orgs.html +1 -1
- package/runtime/server/web/my/orgs.txt +1 -1
- package/runtime/server/web/my/pages.html +1 -1
- package/runtime/server/web/my/pages.txt +1 -1
- package/runtime/server/web/my/peers.html +1 -1
- package/runtime/server/web/my/peers.txt +1 -1
- package/runtime/server/web/my/recent.html +1 -1
- package/runtime/server/web/my/recent.txt +1 -1
- package/runtime/server/web/my/settings.html +1 -1
- package/runtime/server/web/my/settings.txt +1 -1
- package/runtime/server/web/my/studio.html +1 -1
- package/runtime/server/web/my/studio.txt +1 -1
- package/runtime/server/web/my/subscriptions.html +1 -1
- package/runtime/server/web/my/subscriptions.txt +1 -1
- package/runtime/server/web/my/system.html +1 -1
- package/runtime/server/web/my/system.txt +1 -1
- package/runtime/server/web/my/tasks.html +1 -1
- package/runtime/server/web/my/tasks.txt +1 -1
- package/runtime/server/web/my/users.html +1 -1
- package/runtime/server/web/my/users.txt +1 -1
- package/runtime/server/web/my.html +1 -1
- package/runtime/server/web/my.txt +1 -1
- package/runtime/server/web/platform-shell/placeholder/placeholder.html +1 -1
- package/runtime/server/web/platform-shell/placeholder/placeholder.txt +1 -1
- package/runtime/server/web/platform-shell-preview.html +1 -1
- package/runtime/server/web/platform-shell-preview.txt +1 -1
- package/runtime/server/web/setup.html +1 -1
- package/runtime/server/web/setup.txt +1 -1
- package/template/runtime/server-core/dist/lib/__tests__/runtime-errors.test.d.ts +2 -0
- package/template/runtime/server-core/dist/lib/__tests__/runtime-errors.test.d.ts.map +1 -0
- package/template/runtime/server-core/dist/lib/__tests__/runtime-errors.test.js +37 -0
- package/template/runtime/server-core/dist/lib/__tests__/runtime-errors.test.js.map +1 -0
- package/template/runtime/server-core/dist/lib/app-db.d.ts.map +1 -1
- package/template/runtime/server-core/dist/lib/app-db.js +8 -18
- package/template/runtime/server-core/dist/lib/app-db.js.map +1 -1
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts +21 -1
- package/template/runtime/server-core/dist/lib/runtime-errors.d.ts.map +1 -1
- package/template/runtime/server-core/dist/lib/runtime-errors.js +55 -0
- package/template/runtime/server-core/dist/lib/runtime-errors.js.map +1 -1
- package/template/runtime/version.json +1 -1
- package/template/tests/dev-shell-template.test.ts +4 -1
- /package/runtime/server/web/_next/static/{qBns-ZRUDtxsd4XX5SLLK → JieMOnNo6o-tBoC3hEZbI}/_buildManifest.js +0 -0
- /package/runtime/server/web/_next/static/{qBns-ZRUDtxsd4XX5SLLK → JieMOnNo6o-tBoC3hEZbI}/_ssgManifest.js +0 -0
package/bin/localapp.mjs
CHANGED
|
@@ -98,7 +98,7 @@ var require_pend = __commonJS({
|
|
|
98
98
|
// node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/fd-slicer.js
|
|
99
99
|
var require_fd_slicer = __commonJS({
|
|
100
100
|
"node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/fd-slicer.js"(exports) {
|
|
101
|
-
var
|
|
101
|
+
var fs31 = __require("fs");
|
|
102
102
|
var util3 = __require("util");
|
|
103
103
|
var stream = __require("stream");
|
|
104
104
|
var Readable2 = stream.Readable;
|
|
@@ -118,7 +118,7 @@ var require_fd_slicer = __commonJS({
|
|
|
118
118
|
FdSlicer.prototype.read = function(buffer, offset, length, position, callback) {
|
|
119
119
|
var self2 = this;
|
|
120
120
|
self2.pend.go(function(cb) {
|
|
121
|
-
|
|
121
|
+
fs31.read(self2.fd, buffer, offset, length, position, function(err, bytesRead, buffer2) {
|
|
122
122
|
cb();
|
|
123
123
|
callback(err, bytesRead, buffer2);
|
|
124
124
|
});
|
|
@@ -135,7 +135,7 @@ var require_fd_slicer = __commonJS({
|
|
|
135
135
|
self2.refCount -= 1;
|
|
136
136
|
if (self2.refCount < 0) throw new Error("invalid unref");
|
|
137
137
|
if (self2.refCount > 0) return;
|
|
138
|
-
|
|
138
|
+
fs31.close(self2.fd, onCloseDone);
|
|
139
139
|
function onCloseDone(err) {
|
|
140
140
|
if (err) {
|
|
141
141
|
self2.emit("error", err);
|
|
@@ -167,7 +167,7 @@ var require_fd_slicer = __commonJS({
|
|
|
167
167
|
}
|
|
168
168
|
self2.context.pend.go(function(cb) {
|
|
169
169
|
var buffer = Buffer.allocUnsafe(toRead);
|
|
170
|
-
|
|
170
|
+
fs31.read(self2.context.fd, buffer, 0, toRead, self2.pos, function(err, bytesRead) {
|
|
171
171
|
if (err) {
|
|
172
172
|
self2.destroy(err);
|
|
173
173
|
} else if (bytesRead === 0) {
|
|
@@ -527,7 +527,7 @@ var require_crc32 = __commonJS({
|
|
|
527
527
|
// node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/index.js
|
|
528
528
|
var require_yauzl = __commonJS({
|
|
529
529
|
"node_modules/.pnpm/yauzl@3.4.0/node_modules/yauzl/index.js"(exports) {
|
|
530
|
-
var
|
|
530
|
+
var fs31 = __require("fs");
|
|
531
531
|
var zlib2 = __require("zlib");
|
|
532
532
|
var fd_slicer = require_fd_slicer();
|
|
533
533
|
var util3 = __require("util");
|
|
@@ -552,9 +552,9 @@ var require_yauzl = __commonJS({
|
|
|
552
552
|
exports.Entry = Entry;
|
|
553
553
|
exports.LocalFileHeader = LocalFileHeader;
|
|
554
554
|
exports.RandomAccessReader = RandomAccessReader;
|
|
555
|
-
function openPromise(
|
|
555
|
+
function openPromise(path36, options2) {
|
|
556
556
|
return new Promise((resolve2, reject) => {
|
|
557
|
-
open2(
|
|
557
|
+
open2(path36, { ...options2, lazyEntries: true }, function(err, zipfile) {
|
|
558
558
|
if (err) return reject(err);
|
|
559
559
|
resolve2(zipfile);
|
|
560
560
|
});
|
|
@@ -584,7 +584,7 @@ var require_yauzl = __commonJS({
|
|
|
584
584
|
});
|
|
585
585
|
});
|
|
586
586
|
}
|
|
587
|
-
function open2(
|
|
587
|
+
function open2(path36, options2, callback) {
|
|
588
588
|
if (typeof options2 === "function") {
|
|
589
589
|
callback = options2;
|
|
590
590
|
options2 = null;
|
|
@@ -596,10 +596,10 @@ var require_yauzl = __commonJS({
|
|
|
596
596
|
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
597
597
|
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
598
598
|
if (callback == null) callback = defaultCallback;
|
|
599
|
-
|
|
599
|
+
fs31.open(path36, "r", function(err, fd) {
|
|
600
600
|
if (err) return callback(err);
|
|
601
601
|
fromFd(fd, options2, function(err2, zipfile) {
|
|
602
|
-
if (err2)
|
|
602
|
+
if (err2) fs31.close(fd, defaultCallback);
|
|
603
603
|
callback(err2, zipfile);
|
|
604
604
|
});
|
|
605
605
|
});
|
|
@@ -616,7 +616,7 @@ var require_yauzl = __commonJS({
|
|
|
616
616
|
if (options2.validateEntrySizes == null) options2.validateEntrySizes = true;
|
|
617
617
|
if (options2.strictFileNames == null) options2.strictFileNames = false;
|
|
618
618
|
if (callback == null) callback = defaultCallback;
|
|
619
|
-
|
|
619
|
+
fs31.fstat(fd, function(err, stats) {
|
|
620
620
|
if (err) return callback(err);
|
|
621
621
|
var reader = new fd_slicer.FdSlicer(fd);
|
|
622
622
|
fromRandomAccessReader(reader, stats.size, options2, callback);
|
|
@@ -2423,7 +2423,7 @@ var init_escape = __esm({
|
|
|
2423
2423
|
});
|
|
2424
2424
|
|
|
2425
2425
|
// node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js
|
|
2426
|
-
var minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform,
|
|
2426
|
+
var minimatch, starDotExtRE, starDotExtTest, starDotExtTestDot, starDotExtTestNocase, starDotExtTestNocaseDot, starDotStarRE, starDotStarTest, starDotStarTestDot, dotStarRE, dotStarTest, starRE, starTest, starTestDot, qmarksRE, qmarksTestNocase, qmarksTestNocaseDot, qmarksTestDot, qmarksTest, qmarksTestNoExt, qmarksTestNoExtDot, defaultPlatform, path10, sep, GLOBSTAR, qmark2, star2, twoStarDot, twoStarNoDot, filter, ext, defaults, braceExpand, makeRe, match, globMagic, regExpEscape2, Minimatch;
|
|
2427
2427
|
var init_esm3 = __esm({
|
|
2428
2428
|
"node_modules/.pnpm/minimatch@10.2.5/node_modules/minimatch/dist/esm/index.js"() {
|
|
2429
2429
|
init_esm2();
|
|
@@ -2492,11 +2492,11 @@ var init_esm3 = __esm({
|
|
|
2492
2492
|
return (f) => f.length === len && f !== "." && f !== "..";
|
|
2493
2493
|
};
|
|
2494
2494
|
defaultPlatform = typeof process === "object" && process ? typeof process.env === "object" && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : "posix";
|
|
2495
|
-
|
|
2495
|
+
path10 = {
|
|
2496
2496
|
win32: { sep: "\\" },
|
|
2497
2497
|
posix: { sep: "/" }
|
|
2498
2498
|
};
|
|
2499
|
-
sep = defaultPlatform === "win32" ?
|
|
2499
|
+
sep = defaultPlatform === "win32" ? path10.win32.sep : path10.posix.sep;
|
|
2500
2500
|
minimatch.sep = sep;
|
|
2501
2501
|
GLOBSTAR = /* @__PURE__ */ Symbol("globstar **");
|
|
2502
2502
|
minimatch.GLOBSTAR = GLOBSTAR;
|
|
@@ -3245,12 +3245,12 @@ var init_esm3 = __esm({
|
|
|
3245
3245
|
});
|
|
3246
3246
|
|
|
3247
3247
|
// node_modules/.pnpm/readdir-glob@3.0.0/node_modules/readdir-glob/dist/index.mjs
|
|
3248
|
-
import * as
|
|
3248
|
+
import * as fs8 from "fs";
|
|
3249
3249
|
import { EventEmitter } from "events";
|
|
3250
3250
|
import { resolve } from "path";
|
|
3251
3251
|
function readdir2(dir, strict) {
|
|
3252
3252
|
return new Promise((resolve$1, reject) => {
|
|
3253
|
-
|
|
3253
|
+
fs8.readdir(dir, { withFileTypes: true }, (err, files) => {
|
|
3254
3254
|
if (err) switch (err.code) {
|
|
3255
3255
|
case "ENOTDIR":
|
|
3256
3256
|
if (strict) reject(err);
|
|
@@ -3273,7 +3273,7 @@ function readdir2(dir, strict) {
|
|
|
3273
3273
|
}
|
|
3274
3274
|
function getStat(file, followSymlinks) {
|
|
3275
3275
|
return new Promise((resolve$1) => {
|
|
3276
|
-
const statFunc = followSymlinks ?
|
|
3276
|
+
const statFunc = followSymlinks ? fs8.stat : fs8.lstat;
|
|
3277
3277
|
statFunc(file, (err, stats) => {
|
|
3278
3278
|
if (err) switch (err.code) {
|
|
3279
3279
|
case "ENOENT":
|
|
@@ -3288,13 +3288,13 @@ function getStat(file, followSymlinks) {
|
|
|
3288
3288
|
});
|
|
3289
3289
|
});
|
|
3290
3290
|
}
|
|
3291
|
-
async function* exploreWalkAsync(dir,
|
|
3292
|
-
let files = await readdir2(
|
|
3291
|
+
async function* exploreWalkAsync(dir, path36, followSymlinks, useStat, shouldSkip, strict) {
|
|
3292
|
+
let files = await readdir2(path36 + dir, strict);
|
|
3293
3293
|
for (const file of files) {
|
|
3294
3294
|
let name = file.name;
|
|
3295
3295
|
const filename = dir + "/" + name;
|
|
3296
3296
|
const relative = filename.slice(1);
|
|
3297
|
-
const absolute =
|
|
3297
|
+
const absolute = path36 + "/" + relative;
|
|
3298
3298
|
let stat2 = file;
|
|
3299
3299
|
if (useStat || followSymlinks) stat2 = await getStat(absolute, followSymlinks) ?? stat2;
|
|
3300
3300
|
if (stat2.isDirectory()) {
|
|
@@ -3304,7 +3304,7 @@ async function* exploreWalkAsync(dir, path35, followSymlinks, useStat, shouldSki
|
|
|
3304
3304
|
absolute,
|
|
3305
3305
|
stat: stat2
|
|
3306
3306
|
};
|
|
3307
|
-
yield* exploreWalkAsync(filename,
|
|
3307
|
+
yield* exploreWalkAsync(filename, path36, followSymlinks, useStat, shouldSkip, false);
|
|
3308
3308
|
}
|
|
3309
3309
|
} else yield {
|
|
3310
3310
|
relative,
|
|
@@ -3313,8 +3313,8 @@ async function* exploreWalkAsync(dir, path35, followSymlinks, useStat, shouldSki
|
|
|
3313
3313
|
};
|
|
3314
3314
|
}
|
|
3315
3315
|
}
|
|
3316
|
-
async function* explore(
|
|
3317
|
-
yield* exploreWalkAsync("",
|
|
3316
|
+
async function* explore(path36, followSymlinks, useStat, shouldSkip) {
|
|
3317
|
+
yield* exploreWalkAsync("", path36, followSymlinks, useStat, shouldSkip, true);
|
|
3318
3318
|
}
|
|
3319
3319
|
function readOptions(options2) {
|
|
3320
3320
|
return {
|
|
@@ -13799,22 +13799,22 @@ var require_ours = __commonJS({
|
|
|
13799
13799
|
// node_modules/.pnpm/normalize-path@3.0.0/node_modules/normalize-path/index.js
|
|
13800
13800
|
var require_normalize_path = __commonJS({
|
|
13801
13801
|
"node_modules/.pnpm/normalize-path@3.0.0/node_modules/normalize-path/index.js"(exports, module) {
|
|
13802
|
-
module.exports = function(
|
|
13803
|
-
if (typeof
|
|
13802
|
+
module.exports = function(path36, stripTrailing) {
|
|
13803
|
+
if (typeof path36 !== "string") {
|
|
13804
13804
|
throw new TypeError("expected path to be a string");
|
|
13805
13805
|
}
|
|
13806
|
-
if (
|
|
13807
|
-
var len =
|
|
13808
|
-
if (len <= 1) return
|
|
13806
|
+
if (path36 === "\\" || path36 === "/") return "/";
|
|
13807
|
+
var len = path36.length;
|
|
13808
|
+
if (len <= 1) return path36;
|
|
13809
13809
|
var prefix = "";
|
|
13810
|
-
if (len > 4 &&
|
|
13811
|
-
var ch =
|
|
13812
|
-
if ((ch === "?" || ch === ".") &&
|
|
13813
|
-
|
|
13810
|
+
if (len > 4 && path36[3] === "\\") {
|
|
13811
|
+
var ch = path36[2];
|
|
13812
|
+
if ((ch === "?" || ch === ".") && path36.slice(0, 2) === "\\\\") {
|
|
13813
|
+
path36 = path36.slice(2);
|
|
13814
13814
|
prefix = "//";
|
|
13815
13815
|
}
|
|
13816
13816
|
}
|
|
13817
|
-
var segs =
|
|
13817
|
+
var segs = path36.split(/[/\\]+/);
|
|
13818
13818
|
if (stripTrailing !== false && segs[segs.length - 1] === "") {
|
|
13819
13819
|
segs.pop();
|
|
13820
13820
|
}
|
|
@@ -19519,15 +19519,15 @@ var require_sql_wasm = __commonJS({
|
|
|
19519
19519
|
"undefined" != typeof __filename ? ya = __filename : ba && (ya = self.location.href);
|
|
19520
19520
|
var za = "", Aa, Ba;
|
|
19521
19521
|
if (ca) {
|
|
19522
|
-
var
|
|
19522
|
+
var fs31 = __require("node:fs");
|
|
19523
19523
|
za = __dirname + "/";
|
|
19524
19524
|
Ba = (a) => {
|
|
19525
19525
|
a = Ca(a) ? new URL(a) : a;
|
|
19526
|
-
return
|
|
19526
|
+
return fs31.readFileSync(a);
|
|
19527
19527
|
};
|
|
19528
19528
|
Aa = async (a) => {
|
|
19529
19529
|
a = Ca(a) ? new URL(a) : a;
|
|
19530
|
-
return
|
|
19530
|
+
return fs31.readFileSync(a, void 0);
|
|
19531
19531
|
};
|
|
19532
19532
|
1 < process.argv.length && (wa = process.argv[1].replace(/\\/g, "/"));
|
|
19533
19533
|
process.argv.slice(2);
|
|
@@ -19809,7 +19809,7 @@ var require_sql_wasm = __commonJS({
|
|
|
19809
19809
|
if (ca) {
|
|
19810
19810
|
var b = Buffer.alloc(256), c = 0, d = process.stdin.fd;
|
|
19811
19811
|
try {
|
|
19812
|
-
c =
|
|
19812
|
+
c = fs31.readSync(d, b, 0, 256);
|
|
19813
19813
|
} catch (e) {
|
|
19814
19814
|
if (e.toString().includes("EOF")) c = 0;
|
|
19815
19815
|
else throw e;
|
|
@@ -24910,11 +24910,12 @@ Usage:
|
|
|
24910
24910
|
Options:
|
|
24911
24911
|
--data-dir <path> Server database, files, and configuration directory
|
|
24912
24912
|
--host <address> Listen address (default: 127.0.0.1)
|
|
24913
|
-
--port <number> Listen port, 0 selects an available port (default:
|
|
24913
|
+
--port <number> Listen port, 0 selects an available port (default: 50524)
|
|
24914
24914
|
-h, --help Show this help
|
|
24915
24915
|
|
|
24916
24916
|
Examples:
|
|
24917
24917
|
localapp server run
|
|
24918
|
+
localapp server run --port 55441
|
|
24918
24919
|
localapp server run --data-dir ./localapp-data --port 3000
|
|
24919
24920
|
localapp server run --host 0.0.0.0 --port 3000
|
|
24920
24921
|
`],
|
|
@@ -25068,8 +25069,8 @@ Usage:
|
|
|
25068
25069
|
localapp -V
|
|
25069
25070
|
`]
|
|
25070
25071
|
]);
|
|
25071
|
-
function resolveHelpTopic(
|
|
25072
|
-
return TOPICS.get(
|
|
25072
|
+
function resolveHelpTopic(path36) {
|
|
25073
|
+
return TOPICS.get(path36.join(" "));
|
|
25073
25074
|
}
|
|
25074
25075
|
function renderHelp(topic) {
|
|
25075
25076
|
const help2 = HELP.get(topic);
|
|
@@ -25569,9 +25570,9 @@ var LocalAppClient = class {
|
|
|
25569
25570
|
this.setTimeout = dependencies.setTimeout ?? globalThis.setTimeout;
|
|
25570
25571
|
this.clearTimeout = dependencies.clearTimeout ?? globalThis.clearTimeout;
|
|
25571
25572
|
}
|
|
25572
|
-
async requestJson(
|
|
25573
|
+
async requestJson(path36, options2 = {}) {
|
|
25573
25574
|
const body = options2.body === void 0 ? void 0 : JSON.stringify(options2.body);
|
|
25574
|
-
return this.request(
|
|
25575
|
+
return this.request(path36, {
|
|
25575
25576
|
method: options2.method ?? "GET",
|
|
25576
25577
|
body,
|
|
25577
25578
|
timeoutMs: options2.timeoutMs ?? 3e4,
|
|
@@ -25579,11 +25580,11 @@ var LocalAppClient = class {
|
|
|
25579
25580
|
signal: options2.signal
|
|
25580
25581
|
});
|
|
25581
25582
|
}
|
|
25582
|
-
async getJson(
|
|
25583
|
-
return this.requestJson(
|
|
25583
|
+
async getJson(path36, timeoutMs = 3e4) {
|
|
25584
|
+
return this.requestJson(path36, { method: "GET", timeoutMs });
|
|
25584
25585
|
}
|
|
25585
|
-
async postJson(
|
|
25586
|
-
return this.requestJson(
|
|
25586
|
+
async postJson(path36, body, timeoutMs = 3e4) {
|
|
25587
|
+
return this.requestJson(path36, { method: "POST", body, timeoutMs });
|
|
25587
25588
|
}
|
|
25588
25589
|
async installPackage(packagePath, signal) {
|
|
25589
25590
|
const form = new FormData();
|
|
@@ -25596,8 +25597,8 @@ var LocalAppClient = class {
|
|
|
25596
25597
|
async getSyncJob(id) {
|
|
25597
25598
|
return this.getJson(`/api/sync-jobs/${encodeURIComponent(id)}`);
|
|
25598
25599
|
}
|
|
25599
|
-
async request(
|
|
25600
|
-
if (!
|
|
25600
|
+
async request(path36, options2) {
|
|
25601
|
+
if (!path36.startsWith("/") || path36.startsWith("//")) return { ok: false, error: "Request path must be relative to the LocalApp Server" };
|
|
25601
25602
|
const controller = new AbortController();
|
|
25602
25603
|
let timedOut = false;
|
|
25603
25604
|
const timeout2 = this.setTimeout(() => {
|
|
@@ -25609,7 +25610,7 @@ var LocalAppClient = class {
|
|
|
25609
25610
|
if (options2.signal?.aborted) onExternalAbort();
|
|
25610
25611
|
try {
|
|
25611
25612
|
const version = await loadPackageVersion();
|
|
25612
|
-
const response = await fetch(`${this.serverUrl}${
|
|
25613
|
+
const response = await fetch(`${this.serverUrl}${path36}`, {
|
|
25613
25614
|
method: options2.method,
|
|
25614
25615
|
body: options2.body,
|
|
25615
25616
|
headers: { "X-API-Key": this.apiKey, "X-CLI-Version": version, ...options2.headers },
|
|
@@ -25767,8 +25768,8 @@ function withoutApiKeys(value2) {
|
|
|
25767
25768
|
|
|
25768
25769
|
// packages/localapp/src/commands/init.ts
|
|
25769
25770
|
import { spawn } from "node:child_process";
|
|
25770
|
-
import
|
|
25771
|
-
import
|
|
25771
|
+
import fs5 from "node:fs/promises";
|
|
25772
|
+
import path7 from "node:path";
|
|
25772
25773
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
25773
25774
|
|
|
25774
25775
|
// packages/localapp/src/errors.ts
|
|
@@ -25805,33 +25806,83 @@ function isValidProjectName(name) {
|
|
|
25805
25806
|
return /^[a-z][a-z0-9-]{1,61}[a-z0-9]$/.test(name) && !name.includes("--");
|
|
25806
25807
|
}
|
|
25807
25808
|
|
|
25809
|
+
// packages/localapp/src/process/command-invocation.ts
|
|
25810
|
+
import fs2 from "node:fs";
|
|
25811
|
+
import path4 from "node:path";
|
|
25812
|
+
function resolveCommandInvocation(command, args, options2 = {}) {
|
|
25813
|
+
const platform = options2.platform ?? process.platform;
|
|
25814
|
+
const env = options2.env ?? process.env;
|
|
25815
|
+
if (platform !== "win32" || !isBareCommandName(command)) return { command, args: [...args] };
|
|
25816
|
+
const interpreter = options2.commandInterpreter ?? env.ComSpec ?? env.COMSPEC ?? defaultCommandInterpreter(env);
|
|
25817
|
+
return { command: interpreter, args: ["/d", "/s", "/c", command, ...args] };
|
|
25818
|
+
}
|
|
25819
|
+
function isBareCommandName(command) {
|
|
25820
|
+
if (command.includes("/") || command.includes("\\") || command.includes("\0")) return false;
|
|
25821
|
+
return command.length > 0;
|
|
25822
|
+
}
|
|
25823
|
+
function defaultCommandInterpreter(env) {
|
|
25824
|
+
const systemRoot = env.SystemRoot ?? env.SYSTEMROOT ?? "C:\\Windows";
|
|
25825
|
+
return path4.win32.join(systemRoot, "System32", "cmd.exe");
|
|
25826
|
+
}
|
|
25827
|
+
function resolveExecutablePath(command, options2 = {}) {
|
|
25828
|
+
const platform = options2.platform ?? process.platform;
|
|
25829
|
+
const env = options2.env ?? process.env;
|
|
25830
|
+
if (!isBareCommandName(command)) return void 0;
|
|
25831
|
+
const pathApi = platform === "win32" ? path4.win32 : path4.posix;
|
|
25832
|
+
const searchPath = env.PATH ?? env.Path ?? env.path ?? "";
|
|
25833
|
+
const extensions = platform === "win32" ? (env.PATHEXT ?? ".COM;.EXE;.BAT;.CMD").split(";").filter(Boolean).map((entry) => entry.toLowerCase()) : [""];
|
|
25834
|
+
const names = platform === "win32" ? pathApi.extname(command) === "" ? extensions.map((extension2) => `${command}${extension2}`) : [command] : [command];
|
|
25835
|
+
const isFile2 = options2.isFile ?? ((candidate) => {
|
|
25836
|
+
try {
|
|
25837
|
+
return fs2.statSync(candidate).isFile();
|
|
25838
|
+
} catch {
|
|
25839
|
+
return false;
|
|
25840
|
+
}
|
|
25841
|
+
});
|
|
25842
|
+
for (const directory of searchPath.split(pathApi.delimiter)) {
|
|
25843
|
+
const trimmed = directory.trim();
|
|
25844
|
+
if (trimmed === "") continue;
|
|
25845
|
+
const unquoted = trimmed.length >= 2 && trimmed.startsWith('"') && trimmed.endsWith('"') ? trimmed.slice(1, -1) : trimmed;
|
|
25846
|
+
for (const name of names) {
|
|
25847
|
+
const candidate = pathApi.join(unquoted, name);
|
|
25848
|
+
if (isFile2(candidate)) return candidate;
|
|
25849
|
+
}
|
|
25850
|
+
}
|
|
25851
|
+
return void 0;
|
|
25852
|
+
}
|
|
25853
|
+
function resolveOwnedCommand(command, options2 = {}) {
|
|
25854
|
+
const platform = options2.platform ?? process.platform;
|
|
25855
|
+
if (platform !== "win32") return command;
|
|
25856
|
+
return resolveExecutablePath(command, options2) ?? command;
|
|
25857
|
+
}
|
|
25858
|
+
|
|
25808
25859
|
// packages/localapp/src/project/safety.ts
|
|
25809
25860
|
import crypto2 from "node:crypto";
|
|
25810
25861
|
import { constants as constants2 } from "node:fs";
|
|
25811
|
-
import
|
|
25812
|
-
import
|
|
25862
|
+
import fs3 from "node:fs/promises";
|
|
25863
|
+
import path5 from "node:path";
|
|
25813
25864
|
var NOT_PROJECT_MESSAGE = "This directory is not a LocalApp project. Run the command from a project created by localapp init.";
|
|
25814
25865
|
var UNSAFE_PATH_MESSAGE = "The LocalApp project contains a replaced, symlinked, or unsafe managed path. Restore real project directories before retrying.";
|
|
25815
25866
|
async function verifyProjectBase(projectDirectory) {
|
|
25816
|
-
const root =
|
|
25867
|
+
const root = path5.resolve(projectDirectory);
|
|
25817
25868
|
const rootGuard = await captureDirectoryGuard(root, void 0, "not_localapp_project");
|
|
25818
|
-
const localAppDirectory =
|
|
25819
|
-
const claudeDirectory =
|
|
25820
|
-
const skillsDirectory =
|
|
25821
|
-
const sourceDirectory =
|
|
25869
|
+
const localAppDirectory = path5.join(root, ".localapp");
|
|
25870
|
+
const claudeDirectory = path5.join(root, ".claude");
|
|
25871
|
+
const skillsDirectory = path5.join(claudeDirectory, "skills");
|
|
25872
|
+
const sourceDirectory = path5.join(root, "src");
|
|
25822
25873
|
const localAppGuard = await captureDirectoryGuard(localAppDirectory, rootGuard, "not_localapp_project");
|
|
25823
25874
|
const claudeGuard = await captureDirectoryGuard(claudeDirectory, rootGuard, "not_localapp_project");
|
|
25824
25875
|
const skillsGuard = await captureDirectoryGuard(skillsDirectory, claudeGuard, "not_localapp_project");
|
|
25825
25876
|
const sourceGuard = await captureDirectoryGuard(sourceDirectory, rootGuard, "not_localapp_project");
|
|
25826
|
-
const packagePath =
|
|
25827
|
-
const configPath =
|
|
25828
|
-
await requireProjectJson(
|
|
25877
|
+
const packagePath = path5.join(root, "package.json");
|
|
25878
|
+
const configPath = path5.join(localAppDirectory, "project-config.json");
|
|
25879
|
+
await requireProjectJson(path5.join(root, "manifest.json"), true, rootGuard);
|
|
25829
25880
|
await requireProjectJson(packagePath, false, rootGuard);
|
|
25830
|
-
await requireProjectJson(
|
|
25881
|
+
await requireProjectJson(path5.join(localAppDirectory, "dev-config.json"), false, localAppGuard);
|
|
25831
25882
|
return {
|
|
25832
25883
|
root,
|
|
25833
25884
|
localAppDirectory,
|
|
25834
|
-
runtimeDirectory:
|
|
25885
|
+
runtimeDirectory: path5.join(localAppDirectory, "runtime"),
|
|
25835
25886
|
claudeDirectory,
|
|
25836
25887
|
skillsDirectory,
|
|
25837
25888
|
sourceDirectory,
|
|
@@ -25850,19 +25901,19 @@ async function verifyManagedProject(project) {
|
|
|
25850
25901
|
await captureDirectoryGuard(project.runtimeDirectory, project.localAppGuard, "not_localapp_project");
|
|
25851
25902
|
await assertTreeHasNoSymlinks(project.runtimeDirectory);
|
|
25852
25903
|
for (const name of await managedSkillNames(project.skillsDirectory, project.skillsGuard)) {
|
|
25853
|
-
await assertTreeHasNoSymlinks(
|
|
25904
|
+
await assertTreeHasNoSymlinks(path5.join(project.skillsDirectory, name));
|
|
25854
25905
|
}
|
|
25855
25906
|
}
|
|
25856
25907
|
async function verifyInitParent(directory) {
|
|
25857
|
-
const resolved =
|
|
25908
|
+
const resolved = path5.resolve(directory);
|
|
25858
25909
|
await captureDirectoryGuard(resolved, void 0, "unsafe_project_path");
|
|
25859
25910
|
return resolved;
|
|
25860
25911
|
}
|
|
25861
25912
|
async function captureDirectoryGuard(directory, parent, missingCode = "unsafe_project_path") {
|
|
25862
|
-
const resolved =
|
|
25913
|
+
const resolved = path5.resolve(directory);
|
|
25863
25914
|
if (parent !== void 0) {
|
|
25864
25915
|
await verifyDirectoryGuard(parent);
|
|
25865
|
-
if (
|
|
25916
|
+
if (path5.dirname(resolved) !== parent.directory) throw unsafePath();
|
|
25866
25917
|
}
|
|
25867
25918
|
const stat2 = await lstatBigIntOptional(resolved);
|
|
25868
25919
|
if (stat2 === void 0) {
|
|
@@ -25870,8 +25921,8 @@ async function captureDirectoryGuard(directory, parent, missingCode = "unsafe_pr
|
|
|
25870
25921
|
throw unsafePath();
|
|
25871
25922
|
}
|
|
25872
25923
|
if (stat2.isSymbolicLink() || !stat2.isDirectory()) throw unsafePath();
|
|
25873
|
-
const real = await
|
|
25874
|
-
if (real === void 0 ||
|
|
25924
|
+
const real = await fs3.realpath(resolved).catch(() => void 0);
|
|
25925
|
+
if (real === void 0 || path5.resolve(real) !== resolved) throw unsafePath();
|
|
25875
25926
|
return {
|
|
25876
25927
|
directory: resolved,
|
|
25877
25928
|
chain: [...parent?.chain ?? [], { path: resolved, ...identityOf(stat2) }]
|
|
@@ -25881,15 +25932,15 @@ async function verifyDirectoryGuard(guard) {
|
|
|
25881
25932
|
for (const expected of guard.chain) {
|
|
25882
25933
|
const stat2 = await lstatBigIntOptional(expected.path);
|
|
25883
25934
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory() || !matchesIdentity(stat2, expected)) throw unsafePath();
|
|
25884
|
-
const real = await
|
|
25885
|
-
if (real === void 0 ||
|
|
25935
|
+
const real = await fs3.realpath(expected.path).catch(() => void 0);
|
|
25936
|
+
if (real === void 0 || path5.resolve(real) !== expected.path) throw unsafePath();
|
|
25886
25937
|
}
|
|
25887
25938
|
}
|
|
25888
25939
|
async function capturePathIdentity(target, kind = "directory") {
|
|
25889
25940
|
const stat2 = await lstatBigIntOptional(target);
|
|
25890
25941
|
if (stat2 === void 0 || stat2.isSymbolicLink() || (kind === "directory" ? !stat2.isDirectory() : !stat2.isFile())) throw unsafePath();
|
|
25891
|
-
const real = await
|
|
25892
|
-
if (real === void 0 ||
|
|
25942
|
+
const real = await fs3.realpath(target).catch(() => void 0);
|
|
25943
|
+
if (real === void 0 || path5.resolve(real) !== path5.resolve(target)) throw unsafePath();
|
|
25893
25944
|
return identityOf(stat2);
|
|
25894
25945
|
}
|
|
25895
25946
|
async function verifyPathIdentity(target, expected, kind = "directory") {
|
|
@@ -25897,32 +25948,32 @@ async function verifyPathIdentity(target, expected, kind = "directory") {
|
|
|
25897
25948
|
if (stat2 === void 0 || stat2.isSymbolicLink() || (kind === "directory" ? !stat2.isDirectory() : !stat2.isFile()) || !matchesIdentity(stat2, expected)) {
|
|
25898
25949
|
throw unsafePath();
|
|
25899
25950
|
}
|
|
25900
|
-
const real = await
|
|
25901
|
-
if (real === void 0 ||
|
|
25951
|
+
const real = await fs3.realpath(target).catch(() => void 0);
|
|
25952
|
+
if (real === void 0 || path5.resolve(real) !== path5.resolve(target)) throw unsafePath();
|
|
25902
25953
|
}
|
|
25903
25954
|
async function guardedRename(options2) {
|
|
25904
|
-
if (
|
|
25955
|
+
if (path5.dirname(path5.resolve(options2.source)) !== options2.sourceParent.directory || path5.dirname(path5.resolve(options2.destination)) !== options2.destinationParent.directory) throw unsafePath();
|
|
25905
25956
|
await options2.hooks?.beforeRename?.(options2.source, options2.destination);
|
|
25906
25957
|
await verifyDirectoryGuard(options2.sourceParent);
|
|
25907
25958
|
await verifyDirectoryGuard(options2.destinationParent);
|
|
25908
25959
|
await verifyPathIdentity(options2.source, options2.sourceIdentity);
|
|
25909
25960
|
if (await lstatOptional(options2.destination) !== void 0) throw unsafePath();
|
|
25910
|
-
await
|
|
25961
|
+
await fs3.rename(options2.source, options2.destination);
|
|
25911
25962
|
}
|
|
25912
25963
|
async function guardedCreateTemporaryDirectory(options2) {
|
|
25913
|
-
const prefixPath =
|
|
25914
|
-
if (
|
|
25964
|
+
const prefixPath = path5.resolve(options2.parent.directory, options2.prefix);
|
|
25965
|
+
if (path5.dirname(prefixPath) !== options2.parent.directory || path5.basename(prefixPath) !== options2.prefix) throw unsafePath();
|
|
25915
25966
|
await options2.hooks?.beforeCreate?.(prefixPath, "temporary-directory");
|
|
25916
25967
|
await verifyDirectoryGuard(options2.parent);
|
|
25917
|
-
const directory = await
|
|
25968
|
+
const directory = await fs3.mkdtemp(prefixPath);
|
|
25918
25969
|
return captureDirectoryGuard(directory, options2.parent);
|
|
25919
25970
|
}
|
|
25920
25971
|
async function guardedCreateDirectory(options2) {
|
|
25921
|
-
const target =
|
|
25922
|
-
if (
|
|
25972
|
+
const target = path5.resolve(options2.target);
|
|
25973
|
+
if (path5.dirname(target) !== options2.parent.directory) throw unsafePath();
|
|
25923
25974
|
await options2.hooks?.beforeCreate?.(target, "directory");
|
|
25924
25975
|
await verifyDirectoryGuard(options2.parent);
|
|
25925
|
-
await
|
|
25976
|
+
await fs3.mkdir(target).catch((error) => {
|
|
25926
25977
|
if (error.code === "EEXIST") throw unsafePath();
|
|
25927
25978
|
throw error;
|
|
25928
25979
|
});
|
|
@@ -25931,14 +25982,14 @@ async function guardedCreateDirectory(options2) {
|
|
|
25931
25982
|
function createGuardedCopyDestination(root, hooks) {
|
|
25932
25983
|
const guards = /* @__PURE__ */ new Map([[root.directory, root]]);
|
|
25933
25984
|
const ensureDirectory = async (destination) => {
|
|
25934
|
-
const resolved =
|
|
25985
|
+
const resolved = path5.resolve(destination);
|
|
25935
25986
|
if (!isInside(root.directory, resolved)) throw unsafePath();
|
|
25936
25987
|
const existing = guards.get(resolved);
|
|
25937
25988
|
if (existing !== void 0) {
|
|
25938
25989
|
await verifyDirectoryGuard(existing);
|
|
25939
25990
|
return;
|
|
25940
25991
|
}
|
|
25941
|
-
const parentPath =
|
|
25992
|
+
const parentPath = path5.dirname(resolved);
|
|
25942
25993
|
await ensureDirectory(parentPath);
|
|
25943
25994
|
const parent = guards.get(parentPath);
|
|
25944
25995
|
if (parent === void 0) throw unsafePath();
|
|
@@ -25947,15 +25998,15 @@ function createGuardedCopyDestination(root, hooks) {
|
|
|
25947
25998
|
return {
|
|
25948
25999
|
ensureDirectory,
|
|
25949
26000
|
copyFile: async (source, destination) => {
|
|
25950
|
-
const target =
|
|
26001
|
+
const target = path5.resolve(destination);
|
|
25951
26002
|
if (!isInside(root.directory, target) || target === root.directory) throw unsafePath();
|
|
25952
|
-
const parent = guards.get(
|
|
26003
|
+
const parent = guards.get(path5.dirname(target));
|
|
25953
26004
|
if (parent === void 0) throw unsafePath();
|
|
25954
26005
|
await hooks?.beforeCreate?.(target, "file");
|
|
25955
26006
|
const sourceIdentity = await capturePathIdentity(source, "file");
|
|
25956
26007
|
await verifyPathIdentity(source, sourceIdentity, "file");
|
|
25957
26008
|
await verifyDirectoryGuard(parent);
|
|
25958
|
-
await
|
|
26009
|
+
await fs3.copyFile(source, target, constants2.COPYFILE_EXCL).catch((error) => {
|
|
25959
26010
|
if (error.code === "EEXIST") throw unsafePath();
|
|
25960
26011
|
throw error;
|
|
25961
26012
|
});
|
|
@@ -25963,14 +26014,14 @@ function createGuardedCopyDestination(root, hooks) {
|
|
|
25963
26014
|
};
|
|
25964
26015
|
}
|
|
25965
26016
|
async function guardedRemoveTree(options2) {
|
|
25966
|
-
if (
|
|
26017
|
+
if (path5.dirname(path5.resolve(options2.target)) !== options2.parent.directory) throw unsafePath();
|
|
25967
26018
|
await options2.hooks?.beforeRemove?.(options2.target);
|
|
25968
26019
|
await verifyDirectoryGuard(options2.parent);
|
|
25969
26020
|
await verifyPathIdentity(options2.target, options2.targetIdentity);
|
|
25970
26021
|
await assertTreeHasNoSymlinks(options2.target);
|
|
25971
26022
|
await verifyDirectoryGuard(options2.parent);
|
|
25972
26023
|
await verifyPathIdentity(options2.target, options2.targetIdentity);
|
|
25973
|
-
await
|
|
26024
|
+
await fs3.rm(options2.target, { recursive: true });
|
|
25974
26025
|
}
|
|
25975
26026
|
async function readProjectConfig(project) {
|
|
25976
26027
|
await verifyDirectoryGuard(project.localAppGuard);
|
|
@@ -25978,7 +26029,7 @@ async function readProjectConfig(project) {
|
|
|
25978
26029
|
if (stat2 === void 0) return {};
|
|
25979
26030
|
if (!stat2.isFile() || stat2.isSymbolicLink()) throw unsafePath();
|
|
25980
26031
|
try {
|
|
25981
|
-
const parsed = JSON.parse(await
|
|
26032
|
+
const parsed = JSON.parse(await fs3.readFile(project.configPath, "utf8"));
|
|
25982
26033
|
if (!isRecord2(parsed)) throw new Error("invalid config");
|
|
25983
26034
|
return parsed;
|
|
25984
26035
|
} catch {
|
|
@@ -25990,15 +26041,15 @@ async function writeProjectConfig(project, value2, hooks) {
|
|
|
25990
26041
|
`, project.localAppGuard, hooks);
|
|
25991
26042
|
}
|
|
25992
26043
|
async function atomicWriteFile(target, contents, parent, hooks) {
|
|
25993
|
-
if (
|
|
26044
|
+
if (path5.dirname(path5.resolve(target)) !== parent.directory) throw unsafePath();
|
|
25994
26045
|
await verifyDirectoryGuard(parent);
|
|
25995
26046
|
const existingStat = await lstatOptional(target);
|
|
25996
26047
|
if (existingStat !== void 0 && (!existingStat.isFile() || existingStat.isSymbolicLink())) throw unsafePath();
|
|
25997
26048
|
const existingIdentity = existingStat === void 0 ? void 0 : identityOf(existingStat);
|
|
25998
|
-
const temporary =
|
|
26049
|
+
const temporary = path5.join(parent.directory, `.${path5.basename(target)}.${process.pid}.${crypto2.randomUUID()}.tmp`);
|
|
25999
26050
|
await hooks?.beforeCreate?.(temporary, "file");
|
|
26000
26051
|
await verifyDirectoryGuard(parent);
|
|
26001
|
-
await
|
|
26052
|
+
await fs3.writeFile(temporary, contents, { flag: "wx" });
|
|
26002
26053
|
const temporaryIdentity = await capturePathIdentity(temporary, "file");
|
|
26003
26054
|
let committed = false;
|
|
26004
26055
|
try {
|
|
@@ -26010,7 +26061,7 @@ async function atomicWriteFile(target, contents, parent, hooks) {
|
|
|
26010
26061
|
} else {
|
|
26011
26062
|
await verifyPathIdentity(target, existingIdentity, "file");
|
|
26012
26063
|
}
|
|
26013
|
-
await
|
|
26064
|
+
await fs3.rename(temporary, target);
|
|
26014
26065
|
committed = true;
|
|
26015
26066
|
} finally {
|
|
26016
26067
|
if (!committed) {
|
|
@@ -26022,7 +26073,7 @@ async function managedSkillNames(skillsDirectory, guard) {
|
|
|
26022
26073
|
if (guard !== void 0) await verifyDirectoryGuard(guard);
|
|
26023
26074
|
const stat2 = await lstatOptional(skillsDirectory);
|
|
26024
26075
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory()) throw unsafePath();
|
|
26025
|
-
const entries = await
|
|
26076
|
+
const entries = await fs3.readdir(skillsDirectory, { withFileTypes: true });
|
|
26026
26077
|
const names = [];
|
|
26027
26078
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
26028
26079
|
if (!isManagedSkillName(entry.name)) continue;
|
|
@@ -26037,20 +26088,20 @@ function isManagedSkillName(name) {
|
|
|
26037
26088
|
async function assertTreeHasNoSymlinks(root) {
|
|
26038
26089
|
const stat2 = await lstatOptional(root);
|
|
26039
26090
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory()) throw unsafePath();
|
|
26040
|
-
const entries = await
|
|
26091
|
+
const entries = await fs3.readdir(root, { withFileTypes: true });
|
|
26041
26092
|
for (const entry of entries) {
|
|
26042
26093
|
if (entry.isSymbolicLink()) throw unsafePath();
|
|
26043
|
-
const entryPath =
|
|
26094
|
+
const entryPath = path5.join(root, entry.name);
|
|
26044
26095
|
if (entry.isDirectory()) await assertTreeHasNoSymlinks(entryPath);
|
|
26045
26096
|
else if (!entry.isFile()) throw unsafePath();
|
|
26046
26097
|
}
|
|
26047
26098
|
}
|
|
26048
26099
|
async function lstatOptional(target) {
|
|
26049
|
-
return
|
|
26100
|
+
return fs3.lstat(target).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26050
26101
|
}
|
|
26051
26102
|
function isInside(root, target) {
|
|
26052
|
-
const relative =
|
|
26053
|
-
return relative === "" || !relative.startsWith(`..${
|
|
26103
|
+
const relative = path5.relative(root, target);
|
|
26104
|
+
return relative === "" || !relative.startsWith(`..${path5.sep}`) && relative !== ".." && !path5.isAbsolute(relative);
|
|
26054
26105
|
}
|
|
26055
26106
|
function unsafePath() {
|
|
26056
26107
|
return lifecycleError("unsafe_project_path", UNSAFE_PATH_MESSAGE);
|
|
@@ -26061,7 +26112,7 @@ async function requireProjectJson(filePath, manifest, parent) {
|
|
|
26061
26112
|
if (stat2 === void 0) throw lifecycleError("not_localapp_project", NOT_PROJECT_MESSAGE);
|
|
26062
26113
|
if (stat2.isSymbolicLink() || !stat2.isFile()) throw unsafePath();
|
|
26063
26114
|
try {
|
|
26064
|
-
const parsed = JSON.parse(await
|
|
26115
|
+
const parsed = JSON.parse(await fs3.readFile(filePath, "utf8"));
|
|
26065
26116
|
if (!isRecord2(parsed)) throw new Error("invalid json");
|
|
26066
26117
|
if (manifest && (typeof parsed.name !== "string" || typeof parsed.platformVersion !== "string")) throw new Error("invalid manifest");
|
|
26067
26118
|
} catch {
|
|
@@ -26071,10 +26122,10 @@ async function requireProjectJson(filePath, manifest, parent) {
|
|
|
26071
26122
|
async function removeTemporaryFile(target, identity, parent) {
|
|
26072
26123
|
await verifyDirectoryGuard(parent);
|
|
26073
26124
|
await verifyPathIdentity(target, identity, "file");
|
|
26074
|
-
await
|
|
26125
|
+
await fs3.rm(target);
|
|
26075
26126
|
}
|
|
26076
26127
|
async function lstatBigIntOptional(target) {
|
|
26077
|
-
return
|
|
26128
|
+
return fs3.lstat(target, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26078
26129
|
}
|
|
26079
26130
|
function identityOf(stat2) {
|
|
26080
26131
|
return { device: stat2.dev.toString(), inode: stat2.ino.toString() };
|
|
@@ -26087,15 +26138,15 @@ function isRecord2(value2) {
|
|
|
26087
26138
|
}
|
|
26088
26139
|
|
|
26089
26140
|
// packages/localapp/src/template/copy.ts
|
|
26090
|
-
import
|
|
26091
|
-
import
|
|
26141
|
+
import fs4 from "node:fs/promises";
|
|
26142
|
+
import path6 from "node:path";
|
|
26092
26143
|
async function copyDirectory(source, destination, excludedNames = /* @__PURE__ */ new Set(), destinationMutations) {
|
|
26093
|
-
const sourceStat = await
|
|
26144
|
+
const sourceStat = await fs4.lstat(source);
|
|
26094
26145
|
if (sourceStat.isSymbolicLink() || !sourceStat.isDirectory()) {
|
|
26095
26146
|
throw new Error(`Refusing to copy an unsafe template directory: ${source}`);
|
|
26096
26147
|
}
|
|
26097
26148
|
if (destinationMutations === void 0) {
|
|
26098
|
-
const destinationStat = await
|
|
26149
|
+
const destinationStat = await fs4.lstat(destination).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26099
26150
|
if (destinationStat !== void 0 && (destinationStat.isSymbolicLink() || !destinationStat.isDirectory())) {
|
|
26100
26151
|
throw new Error(`Refusing to copy through an unsafe destination: ${destination}`);
|
|
26101
26152
|
}
|
|
@@ -26103,19 +26154,19 @@ async function copyDirectory(source, destination, excludedNames = /* @__PURE__ *
|
|
|
26103
26154
|
} else {
|
|
26104
26155
|
await destinationMutations.ensureDirectory(destination);
|
|
26105
26156
|
}
|
|
26106
|
-
const entries = await
|
|
26157
|
+
const entries = await fs4.readdir(source, { withFileTypes: true });
|
|
26107
26158
|
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
26108
26159
|
if (excludedNames.has(entry.name) || entry.name.endsWith(".tsbuildinfo")) continue;
|
|
26109
|
-
const sourcePath =
|
|
26110
|
-
const destinationPath =
|
|
26160
|
+
const sourcePath = path6.join(source, entry.name);
|
|
26161
|
+
const destinationPath = path6.join(destination, entry.name);
|
|
26111
26162
|
if (entry.isDirectory()) {
|
|
26112
26163
|
await copyDirectory(sourcePath, destinationPath, excludedNames, destinationMutations);
|
|
26113
26164
|
} else if (entry.isFile()) {
|
|
26114
|
-
const currentSourceStat = await
|
|
26165
|
+
const currentSourceStat = await fs4.lstat(sourcePath);
|
|
26115
26166
|
if (currentSourceStat.isSymbolicLink() || !currentSourceStat.isFile()) {
|
|
26116
26167
|
throw new Error(`Builtin template may only contain regular files: ${sourcePath}`);
|
|
26117
26168
|
}
|
|
26118
|
-
if (destinationMutations === void 0) await
|
|
26169
|
+
if (destinationMutations === void 0) await fs4.copyFile(sourcePath, destinationPath);
|
|
26119
26170
|
else await destinationMutations.copyFile(sourcePath, destinationPath);
|
|
26120
26171
|
} else if (entry.isSymbolicLink()) {
|
|
26121
26172
|
throw new Error(`Builtin template may not contain symbolic links: ${sourcePath}`);
|
|
@@ -26123,18 +26174,18 @@ async function copyDirectory(source, destination, excludedNames = /* @__PURE__ *
|
|
|
26123
26174
|
}
|
|
26124
26175
|
}
|
|
26125
26176
|
async function isDirectory(directory) {
|
|
26126
|
-
return
|
|
26177
|
+
return fs4.lstat(directory).then((stat2) => stat2.isDirectory() && !stat2.isSymbolicLink(), () => false);
|
|
26127
26178
|
}
|
|
26128
26179
|
async function createDirectoryWithoutSymlinks(directory) {
|
|
26129
|
-
const stat2 = await
|
|
26180
|
+
const stat2 = await fs4.lstat(directory).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26130
26181
|
if (stat2 !== void 0) {
|
|
26131
26182
|
if (stat2.isSymbolicLink() || !stat2.isDirectory()) throw new Error(`Refusing to copy through an unsafe destination: ${directory}`);
|
|
26132
26183
|
return;
|
|
26133
26184
|
}
|
|
26134
|
-
const parent =
|
|
26185
|
+
const parent = path6.dirname(directory);
|
|
26135
26186
|
if (parent === directory) throw new Error(`Refusing to create an unsafe destination: ${directory}`);
|
|
26136
26187
|
await createDirectoryWithoutSymlinks(parent);
|
|
26137
|
-
await
|
|
26188
|
+
await fs4.mkdir(directory);
|
|
26138
26189
|
}
|
|
26139
26190
|
|
|
26140
26191
|
// packages/localapp/src/commands/init.ts
|
|
@@ -26143,19 +26194,19 @@ async function initializeProject(options2) {
|
|
|
26143
26194
|
throw lifecycleError("invalid_project_name", "Invalid name. Use 3-63 lowercase letters, digits, or hyphens; start with a letter and do not end with or repeat hyphens.");
|
|
26144
26195
|
}
|
|
26145
26196
|
const cwd = await verifyInitParent(options2.cwd);
|
|
26146
|
-
const useCurrentDirectory =
|
|
26147
|
-
const projectDir = useCurrentDirectory ? cwd :
|
|
26197
|
+
const useCurrentDirectory = path7.basename(cwd) === options2.name && await isEmptyDirectory(cwd);
|
|
26198
|
+
const projectDir = useCurrentDirectory ? cwd : path7.join(cwd, options2.name);
|
|
26148
26199
|
if (!useCurrentDirectory && await pathExists(projectDir)) {
|
|
26149
26200
|
throw lifecycleError("project_directory_exists", `Project directory already exists: ${options2.name}. Choose another name or remove the directory.`);
|
|
26150
26201
|
}
|
|
26151
26202
|
const templateDirectory = await resolveTemplateDirectory();
|
|
26152
|
-
if (!useCurrentDirectory) await
|
|
26203
|
+
if (!useCurrentDirectory) await fs5.mkdir(projectDir);
|
|
26153
26204
|
try {
|
|
26154
26205
|
await copyUserZone(templateDirectory, projectDir);
|
|
26155
26206
|
await copyManagedZone(templateDirectory, projectDir);
|
|
26156
26207
|
const manifest = await writeProjectManifest(projectDir, options2.name, options2.description);
|
|
26157
|
-
await
|
|
26158
|
-
await
|
|
26208
|
+
await fs5.mkdir(path7.join(projectDir, ".localapp"), { recursive: true });
|
|
26209
|
+
await fs5.writeFile(path7.join(projectDir, ".localapp/dev-config.json"), `${JSON.stringify({ serverUrl: "" }, null, 2)}
|
|
26159
26210
|
`);
|
|
26160
26211
|
if (!options2.skipInstall) await installDependencies(projectDir, options2.io);
|
|
26161
26212
|
options2.io.stdout(`${JSON.stringify({ created: options2.name })}
|
|
@@ -26164,7 +26215,7 @@ async function initializeProject(options2) {
|
|
|
26164
26215
|
options2.io.stderr("Project created locally. Run localapp app install --target <profile> when it is ready to publish.\n");
|
|
26165
26216
|
return { projectDir, manifest };
|
|
26166
26217
|
} catch (error) {
|
|
26167
|
-
if (!useCurrentDirectory) await
|
|
26218
|
+
if (!useCurrentDirectory) await fs5.rm(projectDir, { recursive: true, force: true });
|
|
26168
26219
|
if (error instanceof LocalAppLifecycleError) throw error;
|
|
26169
26220
|
throw lifecycleError("project_initialization_failed", "Project initialization failed. Check the builtin template and destination permissions, then retry.");
|
|
26170
26221
|
}
|
|
@@ -26172,33 +26223,33 @@ async function initializeProject(options2) {
|
|
|
26172
26223
|
async function resolveTemplateDirectory() {
|
|
26173
26224
|
const explicit = process.env.LOCALAPP_TEMPLATE_DIR;
|
|
26174
26225
|
if (explicit !== void 0 && await isDirectory(explicit)) return explicit;
|
|
26175
|
-
let packageDirectory =
|
|
26226
|
+
let packageDirectory = path7.dirname(fileURLToPath2(import.meta.url));
|
|
26176
26227
|
for (let level = 0; level < 4; level += 1) {
|
|
26177
|
-
const packagedTemplate =
|
|
26228
|
+
const packagedTemplate = path7.join(packageDirectory, "template");
|
|
26178
26229
|
if (await isDirectory(packagedTemplate)) return packagedTemplate;
|
|
26179
|
-
packageDirectory =
|
|
26230
|
+
packageDirectory = path7.dirname(packageDirectory);
|
|
26180
26231
|
}
|
|
26181
26232
|
throw lifecycleError("builtin_template_unavailable", "Builtin template is unavailable. Reinstall localapp or rebuild the package before running init.");
|
|
26182
26233
|
}
|
|
26183
26234
|
async function copyUserZone(templateDirectory, projectDirectory) {
|
|
26184
26235
|
const userExcludes = /* @__PURE__ */ new Set([".claude", ".next", ".DS_Store", "data", "dist", "node_modules", "runtime", "template.gitignore"]);
|
|
26185
26236
|
await copyDirectory(templateDirectory, projectDirectory, userExcludes);
|
|
26186
|
-
const stagedGitignore =
|
|
26187
|
-
if (await pathExists(stagedGitignore)) await
|
|
26188
|
-
const stagedNpmrc =
|
|
26189
|
-
if (await pathExists(stagedNpmrc)) await
|
|
26237
|
+
const stagedGitignore = path7.join(templateDirectory, "template.gitignore");
|
|
26238
|
+
if (await pathExists(stagedGitignore)) await fs5.copyFile(stagedGitignore, path7.join(projectDirectory, ".gitignore"));
|
|
26239
|
+
const stagedNpmrc = path7.join(templateDirectory, "template.npmrc");
|
|
26240
|
+
if (await pathExists(stagedNpmrc)) await fs5.copyFile(stagedNpmrc, path7.join(projectDirectory, ".npmrc"));
|
|
26190
26241
|
}
|
|
26191
26242
|
async function copyManagedZone(templateDirectory, projectDirectory, destinationMutations) {
|
|
26192
|
-
await copyDirectory(
|
|
26193
|
-
const skillsDirectory =
|
|
26243
|
+
await copyDirectory(path7.join(templateDirectory, "runtime"), path7.join(projectDirectory, ".localapp/runtime"), void 0, destinationMutations);
|
|
26244
|
+
const skillsDirectory = path7.join(templateDirectory, ".claude/skills");
|
|
26194
26245
|
if (!await isDirectory(skillsDirectory)) return;
|
|
26195
|
-
const names = await
|
|
26246
|
+
const names = await fs5.readdir(skillsDirectory, { withFileTypes: true });
|
|
26196
26247
|
for (const entry of names.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
26197
26248
|
if (!isManagedSkill(entry.name)) continue;
|
|
26198
26249
|
if (entry.isSymbolicLink() || !entry.isDirectory()) throw new Error(`Builtin template contains an unsafe managed skill: ${entry.name}`);
|
|
26199
26250
|
await copyDirectory(
|
|
26200
|
-
|
|
26201
|
-
|
|
26251
|
+
path7.join(skillsDirectory, entry.name),
|
|
26252
|
+
path7.join(projectDirectory, ".claude/skills", entry.name),
|
|
26202
26253
|
void 0,
|
|
26203
26254
|
destinationMutations
|
|
26204
26255
|
);
|
|
@@ -26209,7 +26260,8 @@ function isManagedSkill(name) {
|
|
|
26209
26260
|
}
|
|
26210
26261
|
async function installDependencies(projectDirectory, io) {
|
|
26211
26262
|
await new Promise((resolve2, reject) => {
|
|
26212
|
-
const
|
|
26263
|
+
const invocation = resolveCommandInvocation("npm", ["install"]);
|
|
26264
|
+
const child = spawn(invocation.command, invocation.args, { cwd: projectDirectory, stdio: ["ignore", "pipe", "pipe"] });
|
|
26213
26265
|
child.stdout.setEncoding("utf8");
|
|
26214
26266
|
child.stderr.setEncoding("utf8");
|
|
26215
26267
|
child.stdout.on("data", (chunk) => io.stdout(chunk));
|
|
@@ -26221,16 +26273,16 @@ async function installDependencies(projectDirectory, io) {
|
|
|
26221
26273
|
});
|
|
26222
26274
|
}
|
|
26223
26275
|
async function pathExists(target) {
|
|
26224
|
-
return
|
|
26276
|
+
return fs5.access(target).then(() => true, () => false);
|
|
26225
26277
|
}
|
|
26226
26278
|
async function isEmptyDirectory(directory) {
|
|
26227
|
-
const entries = await
|
|
26279
|
+
const entries = await fs5.readdir(directory).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26228
26280
|
return entries !== void 0 && entries.length === 0;
|
|
26229
26281
|
}
|
|
26230
26282
|
|
|
26231
26283
|
// packages/localapp/src/commands/sync-template.ts
|
|
26232
|
-
import
|
|
26233
|
-
import
|
|
26284
|
+
import fs6 from "node:fs/promises";
|
|
26285
|
+
import path8 from "node:path";
|
|
26234
26286
|
async function syncManagedTemplate(projectDir, { quiet }, hooks = {}) {
|
|
26235
26287
|
const project = await verifyProjectBase(projectDir);
|
|
26236
26288
|
const config = await readProjectConfig(project);
|
|
@@ -26244,16 +26296,16 @@ async function syncManagedTemplate(projectDir, { quiet }, hooks = {}) {
|
|
|
26244
26296
|
try {
|
|
26245
26297
|
backupRoot = await createRecoveryRoot(".sync-backup-", project.localAppGuard, hooks);
|
|
26246
26298
|
await copyManagedZone(templateDirectory, stageRoot.path, createGuardedCopyDestination(stageRoot.guard, hooks));
|
|
26247
|
-
const stagedLocalApp = await captureDirectoryGuard(
|
|
26248
|
-
const stagedRuntimePath =
|
|
26299
|
+
const stagedLocalApp = await captureDirectoryGuard(path8.join(stageRoot.path, ".localapp"), stageRoot.guard);
|
|
26300
|
+
const stagedRuntimePath = path8.join(stagedLocalApp.directory, "runtime");
|
|
26249
26301
|
const stagedRuntime = await pathReference(stagedRuntimePath, stagedLocalApp);
|
|
26250
|
-
const stagedClaude = await captureDirectoryGuard(
|
|
26251
|
-
const stagedSkills = await captureDirectoryGuard(
|
|
26302
|
+
const stagedClaude = await captureDirectoryGuard(path8.join(stageRoot.path, ".claude"), stageRoot.guard);
|
|
26303
|
+
const stagedSkills = await captureDirectoryGuard(path8.join(stagedClaude.directory, "skills"), stagedClaude);
|
|
26252
26304
|
version = await readStagedVersion(stagedRuntimePath);
|
|
26253
26305
|
const oldSkills = await managedSkillNames(project.skillsDirectory, project.skillsGuard);
|
|
26254
26306
|
const newSkills = await managedSkillNames(stagedSkills.directory, stagedSkills);
|
|
26255
26307
|
const backupSkills = await guardedCreateDirectory({
|
|
26256
|
-
target:
|
|
26308
|
+
target: path8.join(backupRoot.path, "skills"),
|
|
26257
26309
|
parent: backupRoot.guard,
|
|
26258
26310
|
hooks
|
|
26259
26311
|
});
|
|
@@ -26263,17 +26315,17 @@ async function syncManagedTemplate(projectDir, { quiet }, hooks = {}) {
|
|
|
26263
26315
|
currentParent: project.localAppGuard,
|
|
26264
26316
|
current: await pathReference(project.runtimeDirectory, project.localAppGuard),
|
|
26265
26317
|
staged: stagedRuntime,
|
|
26266
|
-
backupPath:
|
|
26318
|
+
backupPath: path8.join(backupRoot.path, "runtime"),
|
|
26267
26319
|
backupParent: backupRoot.guard,
|
|
26268
26320
|
movedCurrent: false,
|
|
26269
26321
|
installedStaged: false
|
|
26270
26322
|
},
|
|
26271
26323
|
...await Promise.all([.../* @__PURE__ */ new Set([...oldSkills, ...newSkills])].sort().map(async (name) => ({
|
|
26272
|
-
currentPath:
|
|
26324
|
+
currentPath: path8.join(project.skillsDirectory, name),
|
|
26273
26325
|
currentParent: project.skillsGuard,
|
|
26274
|
-
...oldSkills.includes(name) ? { current: await pathReference(
|
|
26275
|
-
...newSkills.includes(name) ? { staged: await pathReference(
|
|
26276
|
-
backupPath:
|
|
26326
|
+
...oldSkills.includes(name) ? { current: await pathReference(path8.join(project.skillsDirectory, name), project.skillsGuard) } : {},
|
|
26327
|
+
...newSkills.includes(name) ? { staged: await pathReference(path8.join(stagedSkills.directory, name), stagedSkills) } : {},
|
|
26328
|
+
backupPath: path8.join(backupSkills.directory, name),
|
|
26277
26329
|
backupParent: backupSkills,
|
|
26278
26330
|
movedCurrent: false,
|
|
26279
26331
|
installedStaged: false
|
|
@@ -26314,7 +26366,7 @@ async function pathReference(target, parent) {
|
|
|
26314
26366
|
return { path: target, parent, identity: await capturePathIdentity(target) };
|
|
26315
26367
|
}
|
|
26316
26368
|
async function readStagedVersion(runtimeDirectory) {
|
|
26317
|
-
const parsed = JSON.parse(await
|
|
26369
|
+
const parsed = JSON.parse(await fs6.readFile(path8.join(runtimeDirectory, "version.json"), "utf8"));
|
|
26318
26370
|
if (parsed === null || typeof parsed !== "object" || typeof parsed.cliVersion !== "string") {
|
|
26319
26371
|
throw new Error("invalid staged runtime version");
|
|
26320
26372
|
}
|
|
@@ -26383,8 +26435,8 @@ async function cleanupRecoveryRoots(roots, hooks) {
|
|
|
26383
26435
|
|
|
26384
26436
|
// packages/localapp/src/commands/eject-template.ts
|
|
26385
26437
|
import crypto3 from "node:crypto";
|
|
26386
|
-
import
|
|
26387
|
-
import
|
|
26438
|
+
import fs7 from "node:fs/promises";
|
|
26439
|
+
import path9 from "node:path";
|
|
26388
26440
|
|
|
26389
26441
|
// packages/localapp/src/template/package-json.ts
|
|
26390
26442
|
function rewritePackageJsonForEjectValue(packageJson) {
|
|
@@ -26437,7 +26489,7 @@ async function ejectManagedTemplate(projectDir, hooks = {}) {
|
|
|
26437
26489
|
}
|
|
26438
26490
|
}
|
|
26439
26491
|
async function prepareTransaction(project) {
|
|
26440
|
-
const packageContents = await
|
|
26492
|
+
const packageContents = await fs7.readFile(project.packagePath, "utf8");
|
|
26441
26493
|
let packageJson;
|
|
26442
26494
|
try {
|
|
26443
26495
|
const parsed = JSON.parse(packageContents);
|
|
@@ -26468,12 +26520,12 @@ async function prepareMove(project, source, destination) {
|
|
|
26468
26520
|
const destinationParentGuard = moveParentGuard(project, destination);
|
|
26469
26521
|
await verifyDirectoryGuard(sourceParent);
|
|
26470
26522
|
await verifyDirectoryGuard(destinationParentGuard);
|
|
26471
|
-
const sourceStat = await
|
|
26523
|
+
const sourceStat = await fs7.lstat(sourcePath, { bigint: true });
|
|
26472
26524
|
if (sourceStat.isSymbolicLink() || !sourceStat.isDirectory()) throw unsafeTransaction();
|
|
26473
26525
|
await capturePathIdentity(sourcePath);
|
|
26474
26526
|
await assertTreeHasNoSymlinks(sourcePath);
|
|
26475
26527
|
if (await lstatOptional(destinationPath) !== void 0) throw collision(destination);
|
|
26476
|
-
const destinationParent = await
|
|
26528
|
+
const destinationParent = await fs7.lstat(path9.dirname(destinationPath), { bigint: true });
|
|
26477
26529
|
if (destinationParent.isSymbolicLink() || !destinationParent.isDirectory() || destinationParent.dev !== sourceStat.dev) {
|
|
26478
26530
|
throw lifecycleError("template_eject_filesystem", "Eject requires managed sources and destinations to be directories on the same filesystem.");
|
|
26479
26531
|
}
|
|
@@ -26484,15 +26536,15 @@ async function resumeMove(project, move, hooks) {
|
|
|
26484
26536
|
const destinationPath = projectPath(project, move.destination);
|
|
26485
26537
|
const sourceParent = moveParentGuard(project, move.source);
|
|
26486
26538
|
const destinationParent = moveParentGuard(project, move.destination);
|
|
26487
|
-
const source = await
|
|
26488
|
-
const destination = await
|
|
26539
|
+
const source = await fs7.lstat(sourcePath, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26540
|
+
const destination = await fs7.lstat(destinationPath, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
26489
26541
|
if (source !== void 0) {
|
|
26490
26542
|
if (!matchesIdentity2(source, move) || source.isSymbolicLink() || !source.isDirectory()) throw unsafeTransaction();
|
|
26491
26543
|
await assertTreeHasNoSymlinks(sourcePath);
|
|
26492
26544
|
if (destination !== void 0) throw collision(move.destination);
|
|
26493
26545
|
await verifyDirectoryGuard(sourceParent);
|
|
26494
26546
|
await verifyDirectoryGuard(destinationParent);
|
|
26495
|
-
const destinationParentStat = await
|
|
26547
|
+
const destinationParentStat = await fs7.lstat(path9.dirname(destinationPath), { bigint: true });
|
|
26496
26548
|
if (destinationParentStat.dev !== source.dev) {
|
|
26497
26549
|
throw lifecycleError("template_eject_filesystem", "Eject requires managed sources and destinations to be directories on the same filesystem.");
|
|
26498
26550
|
}
|
|
@@ -26514,7 +26566,7 @@ async function resumeMove(project, move, hooks) {
|
|
|
26514
26566
|
await assertTreeHasNoSymlinks(destinationPath);
|
|
26515
26567
|
}
|
|
26516
26568
|
async function installEjectedPackage(project, transaction, hooks) {
|
|
26517
|
-
const current = await
|
|
26569
|
+
const current = await fs7.readFile(project.packagePath, "utf8");
|
|
26518
26570
|
const currentHash = sha256(current);
|
|
26519
26571
|
if (currentHash === transaction.ejectedPackageHash) return;
|
|
26520
26572
|
if (currentHash !== transaction.originalPackageHash) {
|
|
@@ -26546,7 +26598,7 @@ function parseMove(value2, project) {
|
|
|
26546
26598
|
return move;
|
|
26547
26599
|
}
|
|
26548
26600
|
function projectPath(project, relative) {
|
|
26549
|
-
const target =
|
|
26601
|
+
const target = path9.resolve(project.root, relative);
|
|
26550
26602
|
if (!isInside(project.root, target)) throw unsafeTransaction();
|
|
26551
26603
|
return target;
|
|
26552
26604
|
}
|
|
@@ -26571,13 +26623,13 @@ function unsafeTransaction() {
|
|
|
26571
26623
|
|
|
26572
26624
|
// packages/localapp/src/project/check.ts
|
|
26573
26625
|
import { spawn as spawn2 } from "node:child_process";
|
|
26574
|
-
import
|
|
26575
|
-
import
|
|
26626
|
+
import fs13 from "node:fs/promises";
|
|
26627
|
+
import path16 from "node:path";
|
|
26576
26628
|
|
|
26577
26629
|
// packages/server/src/lib/app-package.ts
|
|
26578
26630
|
import crypto4 from "node:crypto";
|
|
26579
|
-
import
|
|
26580
|
-
import
|
|
26631
|
+
import fs9 from "node:fs";
|
|
26632
|
+
import path11 from "node:path";
|
|
26581
26633
|
import { Transform as Transform5 } from "node:stream";
|
|
26582
26634
|
var import_yauzl = __toESM(require_yauzl());
|
|
26583
26635
|
import { pipeline } from "node:stream/promises";
|
|
@@ -26618,17 +26670,17 @@ var MAX_APP_PACKAGE_BYTES = 512 * 1024 * 1024;
|
|
|
26618
26670
|
var METADATA_PATHS = /* @__PURE__ */ new Set(["package.json", "checksums.json"]);
|
|
26619
26671
|
var FIXED_ARCHIVE_DATE = /* @__PURE__ */ new Date("1980-01-01T00:00:00.000Z");
|
|
26620
26672
|
var AppPackageValidationError = class extends Error {
|
|
26621
|
-
constructor(message,
|
|
26673
|
+
constructor(message, path36) {
|
|
26622
26674
|
super(message);
|
|
26623
|
-
this.path =
|
|
26675
|
+
this.path = path36;
|
|
26624
26676
|
this.name = "AppPackageValidationError";
|
|
26625
26677
|
}
|
|
26626
26678
|
path;
|
|
26627
26679
|
code = "APP_PACKAGE_INVALID";
|
|
26628
26680
|
};
|
|
26629
26681
|
async function inspectAppPackage(filePath) {
|
|
26630
|
-
const packagePath =
|
|
26631
|
-
const stat2 = await
|
|
26682
|
+
const packagePath = path11.resolve(filePath);
|
|
26683
|
+
const stat2 = await fs9.promises.stat(packagePath).catch((error) => {
|
|
26632
26684
|
throw new AppPackageValidationError(`Cannot read application package: ${error instanceof Error ? error.message : String(error)}`);
|
|
26633
26685
|
});
|
|
26634
26686
|
if (!stat2.isFile()) throw new AppPackageValidationError("Application package must be a regular file");
|
|
@@ -26830,7 +26882,7 @@ function assertSafeArchivePath(entryPath, allowDirectory) {
|
|
|
26830
26882
|
throw new AppPackageValidationError(`Unsafe package path: ${entryPath}`, entryPath);
|
|
26831
26883
|
}
|
|
26832
26884
|
const parts = candidate.split("/");
|
|
26833
|
-
if (parts.some((part) => !part || part === "." || part === "..") ||
|
|
26885
|
+
if (parts.some((part) => !part || part === "." || part === "..") || path11.posix.normalize(candidate) !== candidate) {
|
|
26834
26886
|
throw new AppPackageValidationError(`Unsafe package path: ${entryPath}`, entryPath);
|
|
26835
26887
|
}
|
|
26836
26888
|
}
|
|
@@ -26932,7 +26984,7 @@ function openEntry(zipFile, entry) {
|
|
|
26932
26984
|
}
|
|
26933
26985
|
async function sha256File(filePath) {
|
|
26934
26986
|
const hash = crypto4.createHash("sha256");
|
|
26935
|
-
await pipeline(
|
|
26987
|
+
await pipeline(fs9.createReadStream(filePath), new Transform5({
|
|
26936
26988
|
transform(chunk, _encoding, callback) {
|
|
26937
26989
|
hash.update(chunk);
|
|
26938
26990
|
callback(null, chunk);
|
|
@@ -26956,11 +27008,25 @@ function isRecord3(value2) {
|
|
|
26956
27008
|
|
|
26957
27009
|
// packages/server-core/src/lib/app-db.ts
|
|
26958
27010
|
var import_sql = __toESM(require_sql_wasm());
|
|
26959
|
-
import
|
|
26960
|
-
import
|
|
27011
|
+
import fs10 from "node:fs";
|
|
27012
|
+
import path12 from "node:path";
|
|
26961
27013
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
26962
27014
|
|
|
26963
27015
|
// packages/server-core/src/lib/runtime-errors.ts
|
|
27016
|
+
var LocalAppRuntimeError = class extends Error {
|
|
27017
|
+
status;
|
|
27018
|
+
code;
|
|
27019
|
+
details;
|
|
27020
|
+
cause;
|
|
27021
|
+
constructor(message, options2) {
|
|
27022
|
+
super(message);
|
|
27023
|
+
this.name = "LocalAppRuntimeError";
|
|
27024
|
+
this.status = options2.status ?? 500;
|
|
27025
|
+
this.code = options2.code;
|
|
27026
|
+
this.details = options2.details;
|
|
27027
|
+
this.cause = options2.cause;
|
|
27028
|
+
}
|
|
27029
|
+
};
|
|
26964
27030
|
function isWasmRuntimeError(err) {
|
|
26965
27031
|
if (typeof WebAssembly !== "undefined" && err instanceof WebAssembly.RuntimeError) return true;
|
|
26966
27032
|
const message = err instanceof Error ? err.message : String(err ?? "");
|
|
@@ -26968,26 +27034,49 @@ function isWasmRuntimeError(err) {
|
|
|
26968
27034
|
const stack = err instanceof Error ? err.stack ?? "" : "";
|
|
26969
27035
|
return /sql-wasm\.js/i.test(stack) && (message.trim() === "" || message.includes("\uFFFD"));
|
|
26970
27036
|
}
|
|
27037
|
+
function summarizeError(err) {
|
|
27038
|
+
if (err instanceof Error) {
|
|
27039
|
+
return {
|
|
27040
|
+
originalName: err.name,
|
|
27041
|
+
originalMessage: err.message
|
|
27042
|
+
};
|
|
27043
|
+
}
|
|
27044
|
+
return {
|
|
27045
|
+
originalMessage: String(err ?? "Unknown error")
|
|
27046
|
+
};
|
|
27047
|
+
}
|
|
27048
|
+
var sqlJsRuntimeStop;
|
|
27049
|
+
var sqlJsRuntimeStopReason;
|
|
27050
|
+
function markSqlJsRuntimeUnusable(err, scope) {
|
|
27051
|
+
const fatal = new LocalAppRuntimeError(
|
|
27052
|
+
`The LocalApp SQLite runtime is unusable after a WebAssembly trap in ${scope}; the Server must restart`,
|
|
27053
|
+
{
|
|
27054
|
+
status: 503,
|
|
27055
|
+
code: "db_runtime_restart_required",
|
|
27056
|
+
cause: err,
|
|
27057
|
+
details: { scope, ...summarizeError(err) }
|
|
27058
|
+
}
|
|
27059
|
+
);
|
|
27060
|
+
if (sqlJsRuntimeStopReason !== void 0) return fatal;
|
|
27061
|
+
sqlJsRuntimeStopReason = fatal.message;
|
|
27062
|
+
process.stderr.write(`[localapp] ${fatal.message} (${JSON.stringify(summarizeError(err))})
|
|
27063
|
+
`);
|
|
27064
|
+
if (sqlJsRuntimeStop) {
|
|
27065
|
+
sqlJsRuntimeStop(fatal.message);
|
|
27066
|
+
return fatal;
|
|
27067
|
+
}
|
|
27068
|
+
setImmediate(() => process.exit(1));
|
|
27069
|
+
return fatal;
|
|
27070
|
+
}
|
|
26971
27071
|
|
|
26972
27072
|
// packages/server-core/src/lib/app-db.ts
|
|
26973
|
-
var SqlJs = null;
|
|
26974
27073
|
var dbQueueOwner = new AsyncLocalStorage();
|
|
26975
27074
|
var _connections = /* @__PURE__ */ new Map();
|
|
26976
27075
|
var IDLE_TIMEOUT_MS = 5 * 60 * 1e3;
|
|
26977
27076
|
function recoverFromSqlJsRuntimeError(dbPath, err) {
|
|
26978
27077
|
if (!isWasmRuntimeError(err)) return;
|
|
26979
27078
|
evictConnectionForDbPath(dbPath);
|
|
26980
|
-
|
|
26981
|
-
}
|
|
26982
|
-
function resetSqlJsRuntimeAfterError() {
|
|
26983
|
-
for (const [dbPath, entry] of _connections) {
|
|
26984
|
-
try {
|
|
26985
|
-
entry.db.close();
|
|
26986
|
-
} catch {
|
|
26987
|
-
}
|
|
26988
|
-
_connections.delete(dbPath);
|
|
26989
|
-
}
|
|
26990
|
-
SqlJs = null;
|
|
27079
|
+
markSqlJsRuntimeUnusable(err, "application database");
|
|
26991
27080
|
}
|
|
26992
27081
|
function markDirty(dbPath) {
|
|
26993
27082
|
const entry = _connections.get(dbPath);
|
|
@@ -26998,10 +27087,10 @@ function saveConnection(dbPath) {
|
|
|
26998
27087
|
if (!entry) return;
|
|
26999
27088
|
if (!entry.dirty) return;
|
|
27000
27089
|
if (entry.transactionDepth > 0) return;
|
|
27001
|
-
const dir =
|
|
27002
|
-
if (!
|
|
27090
|
+
const dir = path12.dirname(dbPath);
|
|
27091
|
+
if (!fs10.existsSync(dir)) fs10.mkdirSync(dir, { recursive: true });
|
|
27003
27092
|
const data = entry.db.export();
|
|
27004
|
-
|
|
27093
|
+
fs10.writeFileSync(dbPath, Buffer.from(data));
|
|
27005
27094
|
entry.dirty = false;
|
|
27006
27095
|
}
|
|
27007
27096
|
function evictConnectionForDbPath(dbPath) {
|
|
@@ -27050,8 +27139,8 @@ function execRawSql(dbPath, sql, params) {
|
|
|
27050
27139
|
}
|
|
27051
27140
|
|
|
27052
27141
|
// packages/server-core/src/lib/backend-contract.ts
|
|
27053
|
-
import
|
|
27054
|
-
import
|
|
27142
|
+
import fs11 from "node:fs";
|
|
27143
|
+
import path13 from "node:path";
|
|
27055
27144
|
import { createHash } from "node:crypto";
|
|
27056
27145
|
|
|
27057
27146
|
// packages/server-core/src/generated/platform-capabilities.ts
|
|
@@ -27344,7 +27433,7 @@ function discoverBackendFiles(projectDir, config, options2) {
|
|
|
27344
27433
|
return relativePaths.filter((relativePath2) => relativePath2.endsWith(".json") && !isHostedActionFile(relativePath2)).sort().map((relativePath2) => {
|
|
27345
27434
|
const normalized = normalizePath4(relativePath2);
|
|
27346
27435
|
return {
|
|
27347
|
-
absolutePath:
|
|
27436
|
+
absolutePath: path13.join(projectDir, normalized),
|
|
27348
27437
|
relativePath: normalized,
|
|
27349
27438
|
schemaUrl: "",
|
|
27350
27439
|
kind: kindFromPath(normalized)
|
|
@@ -27362,17 +27451,17 @@ function isHostedActionFile(relativePath2) {
|
|
|
27362
27451
|
return relativePath2.endsWith("/actions.manifest.json") || relativePath2.endsWith("/actions.bundle.mjs") || relativePath2 === "actions.manifest.json" || relativePath2 === "actions.bundle.mjs" || /(^|\/)actions\/.+\.(?:ts|tsx|js|mjs)$/.test(relativePath2);
|
|
27363
27452
|
}
|
|
27364
27453
|
function discoverByRoot(projectDir, root) {
|
|
27365
|
-
const rootPath =
|
|
27454
|
+
const rootPath = path13.resolve(projectDir, root);
|
|
27366
27455
|
if (!isInside2(projectDir, rootPath)) {
|
|
27367
27456
|
throw new Error(`backend.root must stay inside project directory: ${root}`);
|
|
27368
27457
|
}
|
|
27369
|
-
if (!
|
|
27458
|
+
if (!fs11.existsSync(rootPath) || !fs11.statSync(rootPath).isDirectory()) {
|
|
27370
27459
|
throw new Error(`backend root does not exist: ${root}`);
|
|
27371
27460
|
}
|
|
27372
|
-
return walkFiles(rootPath).map((filePath) => normalizePath4(
|
|
27461
|
+
return walkFiles(rootPath).map((filePath) => normalizePath4(path13.relative(projectDir, filePath)));
|
|
27373
27462
|
}
|
|
27374
27463
|
function discoverByInclude(projectDir, patterns) {
|
|
27375
|
-
const allProjectFiles = walkFiles(projectDir).map((filePath) => normalizePath4(
|
|
27464
|
+
const allProjectFiles = walkFiles(projectDir).map((filePath) => normalizePath4(path13.relative(projectDir, filePath)));
|
|
27376
27465
|
const matched = /* @__PURE__ */ new Set();
|
|
27377
27466
|
for (const pattern of patterns) {
|
|
27378
27467
|
const regex = globToRegExp(normalizePath4(pattern));
|
|
@@ -27385,10 +27474,10 @@ function discoverByInclude(projectDir, patterns) {
|
|
|
27385
27474
|
return Array.from(matched);
|
|
27386
27475
|
}
|
|
27387
27476
|
function walkFiles(dir) {
|
|
27388
|
-
if (!
|
|
27477
|
+
if (!fs11.existsSync(dir)) return [];
|
|
27389
27478
|
const result = [];
|
|
27390
|
-
for (const entry of
|
|
27391
|
-
const entryPath =
|
|
27479
|
+
for (const entry of fs11.readdirSync(dir, { withFileTypes: true })) {
|
|
27480
|
+
const entryPath = path13.join(dir, entry.name);
|
|
27392
27481
|
if (entry.isDirectory()) {
|
|
27393
27482
|
result.push(...walkFiles(entryPath));
|
|
27394
27483
|
} else if (entry.isFile()) {
|
|
@@ -27398,7 +27487,7 @@ function walkFiles(dir) {
|
|
|
27398
27487
|
return result;
|
|
27399
27488
|
}
|
|
27400
27489
|
function readBackendJson(file) {
|
|
27401
|
-
const raw =
|
|
27490
|
+
const raw = fs11.readFileSync(file.absolutePath, "utf8");
|
|
27402
27491
|
const value2 = JSON.parse(raw);
|
|
27403
27492
|
const schemaUrl = value2.$schema;
|
|
27404
27493
|
if (typeof schemaUrl !== "string" || !schemaUrl.trim()) {
|
|
@@ -27957,7 +28046,7 @@ function extractSqlParams(sql) {
|
|
|
27957
28046
|
return names;
|
|
27958
28047
|
}
|
|
27959
28048
|
function kindFromPath(relativePath2) {
|
|
27960
|
-
const basename2 =
|
|
28049
|
+
const basename2 = path13.posix.basename(relativePath2);
|
|
27961
28050
|
if (basename2 === "schema.json") return "schema";
|
|
27962
28051
|
if (basename2 === "queries.json") return "queries";
|
|
27963
28052
|
if (basename2 === "mutations.json") return "mutations";
|
|
@@ -27986,8 +28075,8 @@ function normalizePath4(filePath) {
|
|
|
27986
28075
|
return filePath.replace(/\\/g, "/");
|
|
27987
28076
|
}
|
|
27988
28077
|
function isInside2(root, candidate) {
|
|
27989
|
-
const relative =
|
|
27990
|
-
return relative === "" || !relative.startsWith("..") && !
|
|
28078
|
+
const relative = path13.relative(path13.resolve(root), path13.resolve(candidate));
|
|
28079
|
+
return relative === "" || !relative.startsWith("..") && !path13.isAbsolute(relative);
|
|
27991
28080
|
}
|
|
27992
28081
|
function isRecord4(value2) {
|
|
27993
28082
|
return typeof value2 === "object" && value2 !== null && !Array.isArray(value2);
|
|
@@ -28037,15 +28126,15 @@ function validateMigrationFilenames(filenames) {
|
|
|
28037
28126
|
}
|
|
28038
28127
|
|
|
28039
28128
|
// packages/localapp/src/project/backend.ts
|
|
28040
|
-
import
|
|
28129
|
+
import path15 from "node:path";
|
|
28041
28130
|
|
|
28042
28131
|
// packages/localapp/src/project/files.ts
|
|
28043
28132
|
import { constants as constants3 } from "node:fs";
|
|
28044
|
-
import
|
|
28133
|
+
import fs12 from "node:fs/promises";
|
|
28045
28134
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
28046
|
-
import
|
|
28135
|
+
import path14 from "node:path";
|
|
28047
28136
|
async function readProjectJson(projectDir, filename, hooks) {
|
|
28048
|
-
const filePath =
|
|
28137
|
+
const filePath = path14.join(projectDir, filename);
|
|
28049
28138
|
const content = await readVerifiedFile(projectDir, filePath, filename, hooks);
|
|
28050
28139
|
let value2;
|
|
28051
28140
|
try {
|
|
@@ -28060,16 +28149,16 @@ async function collectProjectTree(options2) {
|
|
|
28060
28149
|
const root = await resolveProjectDirectory(options2);
|
|
28061
28150
|
if (root === void 0) return [];
|
|
28062
28151
|
const files = [];
|
|
28063
|
-
await collectTree(
|
|
28152
|
+
await collectTree(path14.resolve(options2.projectDir), root, root, options2.label, files, options2.hooks);
|
|
28064
28153
|
return files.sort((left, right) => left.relativePath.localeCompare(right.relativePath));
|
|
28065
28154
|
}
|
|
28066
28155
|
async function captureRegularProjectFile(projectDir, filePath, label, hooks) {
|
|
28067
|
-
const root =
|
|
28068
|
-
const target =
|
|
28156
|
+
const root = path14.resolve(projectDir);
|
|
28157
|
+
const target = path14.resolve(filePath);
|
|
28069
28158
|
if (!isInside3(root, target) || target === root) throw unsafePath2(`${label} must stay inside the project`);
|
|
28070
|
-
const ancestors = await captureDirectoryChain(root,
|
|
28159
|
+
const ancestors = await captureDirectoryChain(root, path14.dirname(target), label);
|
|
28071
28160
|
await hooks?.afterAncestorValidation?.(target);
|
|
28072
|
-
const stat2 = await
|
|
28161
|
+
const stat2 = await fs12.lstat(target, { bigint: true }).catch((error) => {
|
|
28073
28162
|
if (error.code === "ENOENT") throw lifecycleError("project_file_missing", `${label} does not exist`);
|
|
28074
28163
|
throw error;
|
|
28075
28164
|
});
|
|
@@ -28081,17 +28170,17 @@ async function readVerifiedFile(projectDir, filePath, label, hooks) {
|
|
|
28081
28170
|
return readValidatedRegularFile(filePath, label, captured, hooks);
|
|
28082
28171
|
}
|
|
28083
28172
|
async function resolveProjectDirectory(options2) {
|
|
28084
|
-
const root =
|
|
28173
|
+
const root = path14.resolve(options2.projectDir);
|
|
28085
28174
|
const configured = options2.configuredPath.trim();
|
|
28086
|
-
if (!configured ||
|
|
28175
|
+
if (!configured || path14.isAbsolute(configured)) {
|
|
28087
28176
|
throw unsafePath2(`${options2.label} must be a non-empty relative path inside the project`);
|
|
28088
28177
|
}
|
|
28089
|
-
const target =
|
|
28178
|
+
const target = path14.resolve(root, configured);
|
|
28090
28179
|
if (!isInside3(root, target) || target === root) {
|
|
28091
28180
|
throw unsafePath2(`${options2.label} must stay inside the project and must not be the project root`);
|
|
28092
28181
|
}
|
|
28093
28182
|
await assertPathChainHasNoSymlinks(root, target, options2.label, !options2.required);
|
|
28094
|
-
const stat2 = await
|
|
28183
|
+
const stat2 = await fs12.lstat(target).catch((error) => {
|
|
28095
28184
|
if (error.code === "ENOENT" && !options2.required) return void 0;
|
|
28096
28185
|
if (error.code === "ENOENT") throw lifecycleError("project_directory_missing", `${options2.label} does not exist: ${options2.configuredPath}`);
|
|
28097
28186
|
throw error;
|
|
@@ -28102,18 +28191,18 @@ async function resolveProjectDirectory(options2) {
|
|
|
28102
28191
|
}
|
|
28103
28192
|
async function resolveSafePackageOutput(options2) {
|
|
28104
28193
|
const configured = options2.outputPath ?? `${options2.defaultName}.localapp`;
|
|
28105
|
-
const outputPath =
|
|
28106
|
-
if (
|
|
28194
|
+
const outputPath = path14.resolve(options2.projectDir, configured);
|
|
28195
|
+
if (path14.extname(outputPath) !== ".localapp") {
|
|
28107
28196
|
throw lifecycleError("invalid_package_output", "Application package output must use the .localapp extension");
|
|
28108
28197
|
}
|
|
28109
28198
|
for (const protectedDirectory of options2.protectedDirectories) {
|
|
28110
|
-
const protectedPath =
|
|
28199
|
+
const protectedPath = path14.resolve(options2.projectDir, protectedDirectory);
|
|
28111
28200
|
if (isInside3(protectedPath, outputPath)) {
|
|
28112
28201
|
throw lifecycleError("invalid_package_output", "Application package output must be outside dist, migrations, and backend source directories");
|
|
28113
28202
|
}
|
|
28114
28203
|
}
|
|
28115
28204
|
await assertExistingOutputChainHasNoSymlinks(outputPath);
|
|
28116
|
-
const stat2 = await
|
|
28205
|
+
const stat2 = await fs12.lstat(outputPath).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
28117
28206
|
if (stat2 !== void 0 && (stat2.isSymbolicLink() || !stat2.isFile())) {
|
|
28118
28207
|
throw unsafePath2("Application package output must be a regular file without symlinks");
|
|
28119
28208
|
}
|
|
@@ -28123,28 +28212,28 @@ async function resolveSafePackageOutput(options2) {
|
|
|
28123
28212
|
return { path: outputPath, exists: stat2 !== void 0 };
|
|
28124
28213
|
}
|
|
28125
28214
|
async function preparePackageOutput(outputPath, overwrite) {
|
|
28126
|
-
const parentPath =
|
|
28127
|
-
await
|
|
28215
|
+
const parentPath = path14.dirname(outputPath);
|
|
28216
|
+
await fs12.mkdir(parentPath, { recursive: true, mode: 448 });
|
|
28128
28217
|
await assertExistingOutputChainHasNoSymlinks(parentPath);
|
|
28129
|
-
const parentStat = await
|
|
28218
|
+
const parentStat = await fs12.lstat(parentPath, { bigint: true });
|
|
28130
28219
|
if (parentStat.isSymbolicLink() || !parentStat.isDirectory()) {
|
|
28131
28220
|
throw unsafePath2("Application package output parent must be a directory without symlinks");
|
|
28132
28221
|
}
|
|
28133
|
-
const outputStat = await
|
|
28222
|
+
const outputStat = await fs12.lstat(outputPath, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
28134
28223
|
if (outputStat !== void 0 && (outputStat.isSymbolicLink() || !outputStat.isFile())) {
|
|
28135
28224
|
throw unsafePath2("Application package output must be a regular file without symlinks");
|
|
28136
28225
|
}
|
|
28137
28226
|
if (outputStat !== void 0 && !overwrite) throw packageOutputExists();
|
|
28138
28227
|
return {
|
|
28139
28228
|
path: outputPath,
|
|
28140
|
-
temporaryPath:
|
|
28229
|
+
temporaryPath: path14.join(parentPath, `.${path14.basename(outputPath)}.${process.pid}.${randomUUID2()}.tmp`),
|
|
28141
28230
|
parent: { path: parentPath, dev: parentStat.dev, ino: parentStat.ino },
|
|
28142
28231
|
overwrite
|
|
28143
28232
|
};
|
|
28144
28233
|
}
|
|
28145
28234
|
async function capturePreparedTemporary(prepared) {
|
|
28146
28235
|
await verifyPreparedParent(prepared);
|
|
28147
|
-
const stat2 = await
|
|
28236
|
+
const stat2 = await fs12.lstat(prepared.temporaryPath, { bigint: true });
|
|
28148
28237
|
if (stat2.isSymbolicLink() || !stat2.isFile()) throw unsafePath2("Application package temporary output is unsafe");
|
|
28149
28238
|
return { dev: stat2.dev, ino: stat2.ino, size: Number(stat2.size) };
|
|
28150
28239
|
}
|
|
@@ -28156,14 +28245,14 @@ function normalizeArchiveRelativePath(value2, label) {
|
|
|
28156
28245
|
return normalized;
|
|
28157
28246
|
}
|
|
28158
28247
|
function asyncReaddir(directory) {
|
|
28159
|
-
return
|
|
28248
|
+
return fs12.readdir(directory, { withFileTypes: true });
|
|
28160
28249
|
}
|
|
28161
28250
|
async function collectTree(projectDir, root, current, label, files, hooks) {
|
|
28162
28251
|
const entries = (await asyncReaddir(current)).sort((left, right) => left.name.localeCompare(right.name));
|
|
28163
28252
|
for (const entry of entries) {
|
|
28164
|
-
const absolutePath =
|
|
28165
|
-
const relativePath2 =
|
|
28166
|
-
const stat2 = await
|
|
28253
|
+
const absolutePath = path14.join(current, entry.name);
|
|
28254
|
+
const relativePath2 = path14.relative(root, absolutePath).replaceAll(path14.sep, "/");
|
|
28255
|
+
const stat2 = await fs12.lstat(absolutePath, { bigint: true });
|
|
28167
28256
|
if (stat2.isSymbolicLink()) throw unsafePath2(`${label} must not contain symlinks: ${relativePath2}`);
|
|
28168
28257
|
if (stat2.isDirectory()) {
|
|
28169
28258
|
await collectTree(projectDir, root, absolutePath, label, files, hooks);
|
|
@@ -28181,13 +28270,13 @@ async function collectTree(projectDir, root, current, label, files, hooks) {
|
|
|
28181
28270
|
async function readValidatedRegularFile(filePath, label, expected, hooks) {
|
|
28182
28271
|
await hooks?.beforeOpen?.(filePath);
|
|
28183
28272
|
const flags = process.platform !== "win32" && typeof constants3.O_NOFOLLOW === "number" ? constants3.O_RDONLY | constants3.O_NOFOLLOW : "r";
|
|
28184
|
-
const handle = await
|
|
28273
|
+
const handle = await fs12.open(filePath, flags).catch(() => {
|
|
28185
28274
|
throw unsafePath2(`${label} changed before it could be opened safely`);
|
|
28186
28275
|
});
|
|
28187
28276
|
try {
|
|
28188
28277
|
const opened = await handle.stat({ bigint: true });
|
|
28189
28278
|
await verifyDirectoryChain(expected.ancestors, label);
|
|
28190
|
-
const current = await
|
|
28279
|
+
const current = await fs12.lstat(filePath, { bigint: true }).catch(() => void 0);
|
|
28191
28280
|
if (current === void 0 || current.isSymbolicLink() || !current.isFile() || current.dev !== expected.file.dev || current.ino !== expected.file.ino || !opened.isFile() || opened.dev !== expected.file.dev || opened.ino !== expected.file.ino) {
|
|
28192
28281
|
throw unsafePath2(`${label} changed before it could be read safely`);
|
|
28193
28282
|
}
|
|
@@ -28197,17 +28286,17 @@ async function readValidatedRegularFile(filePath, label, expected, hooks) {
|
|
|
28197
28286
|
}
|
|
28198
28287
|
}
|
|
28199
28288
|
async function captureDirectoryChain(root, target, label) {
|
|
28200
|
-
const relative =
|
|
28201
|
-
if (relative.startsWith("..") ||
|
|
28289
|
+
const relative = path14.relative(root, target);
|
|
28290
|
+
if (relative.startsWith("..") || path14.isAbsolute(relative)) throw unsafePath2(`${label} escaped the project`);
|
|
28202
28291
|
const directories = [root];
|
|
28203
28292
|
let current = root;
|
|
28204
|
-
for (const component of relative.split(
|
|
28205
|
-
current =
|
|
28293
|
+
for (const component of relative.split(path14.sep).filter(Boolean)) {
|
|
28294
|
+
current = path14.join(current, component);
|
|
28206
28295
|
directories.push(current);
|
|
28207
28296
|
}
|
|
28208
28297
|
const identities = [];
|
|
28209
28298
|
for (const directory of directories) {
|
|
28210
|
-
const stat2 = await
|
|
28299
|
+
const stat2 = await fs12.lstat(directory, { bigint: true }).catch(() => void 0);
|
|
28211
28300
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory()) {
|
|
28212
28301
|
throw unsafePath2(`${label} must not contain symlinks`);
|
|
28213
28302
|
}
|
|
@@ -28217,21 +28306,21 @@ async function captureDirectoryChain(root, target, label) {
|
|
|
28217
28306
|
}
|
|
28218
28307
|
async function verifyDirectoryChain(expected, label) {
|
|
28219
28308
|
for (const directory of expected) {
|
|
28220
|
-
const stat2 = await
|
|
28309
|
+
const stat2 = await fs12.lstat(directory.path, { bigint: true }).catch(() => void 0);
|
|
28221
28310
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory() || stat2.dev !== directory.dev || stat2.ino !== directory.ino) {
|
|
28222
28311
|
throw unsafePath2(`${label} changed before it could be read safely`);
|
|
28223
28312
|
}
|
|
28224
28313
|
}
|
|
28225
28314
|
}
|
|
28226
28315
|
async function assertPathChainHasNoSymlinks(root, target, label, allowMissingTail = false) {
|
|
28227
|
-
const relative =
|
|
28228
|
-
if (relative.startsWith("..") ||
|
|
28316
|
+
const relative = path14.relative(root, target);
|
|
28317
|
+
if (relative.startsWith("..") || path14.isAbsolute(relative)) throw unsafePath2(`${label} escaped the project`);
|
|
28229
28318
|
let current = root;
|
|
28230
|
-
const rootStat = await
|
|
28319
|
+
const rootStat = await fs12.lstat(root);
|
|
28231
28320
|
if (rootStat.isSymbolicLink() || !rootStat.isDirectory()) throw unsafePath2("Project directory must not be symlinked");
|
|
28232
|
-
for (const component of relative.split(
|
|
28233
|
-
current =
|
|
28234
|
-
const stat2 = await
|
|
28321
|
+
for (const component of relative.split(path14.sep).filter(Boolean)) {
|
|
28322
|
+
current = path14.join(current, component);
|
|
28323
|
+
const stat2 = await fs12.lstat(current).catch((error) => {
|
|
28235
28324
|
if (allowMissingTail && error.code === "ENOENT") return void 0;
|
|
28236
28325
|
throw error;
|
|
28237
28326
|
});
|
|
@@ -28240,26 +28329,26 @@ async function assertPathChainHasNoSymlinks(root, target, label, allowMissingTai
|
|
|
28240
28329
|
}
|
|
28241
28330
|
}
|
|
28242
28331
|
async function assertExistingOutputChainHasNoSymlinks(outputPath) {
|
|
28243
|
-
const parsed =
|
|
28244
|
-
const components = outputPath.slice(parsed.root.length).split(
|
|
28332
|
+
const parsed = path14.parse(outputPath);
|
|
28333
|
+
const components = outputPath.slice(parsed.root.length).split(path14.sep).filter(Boolean);
|
|
28245
28334
|
let current = parsed.root;
|
|
28246
28335
|
for (const component of components) {
|
|
28247
|
-
current =
|
|
28248
|
-
const stat2 = await
|
|
28336
|
+
current = path14.join(current, component);
|
|
28337
|
+
const stat2 = await fs12.lstat(current).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
28249
28338
|
if (stat2 === void 0) return;
|
|
28250
28339
|
if (stat2.isSymbolicLink()) throw unsafePath2("Application package output path must not contain symlinks");
|
|
28251
28340
|
}
|
|
28252
28341
|
}
|
|
28253
28342
|
async function verifyPreparedParent(prepared) {
|
|
28254
28343
|
await assertExistingOutputChainHasNoSymlinks(prepared.parent.path);
|
|
28255
|
-
const stat2 = await
|
|
28344
|
+
const stat2 = await fs12.lstat(prepared.parent.path, { bigint: true });
|
|
28256
28345
|
if (stat2.isSymbolicLink() || !stat2.isDirectory() || stat2.dev !== prepared.parent.dev || stat2.ino !== prepared.parent.ino) {
|
|
28257
28346
|
throw unsafePath2("Application package output parent changed during publication");
|
|
28258
28347
|
}
|
|
28259
28348
|
}
|
|
28260
28349
|
function isInside3(root, target) {
|
|
28261
|
-
const relative =
|
|
28262
|
-
return relative === "" || !relative.startsWith(`..${
|
|
28350
|
+
const relative = path14.relative(root, target);
|
|
28351
|
+
return relative === "" || !relative.startsWith(`..${path14.sep}`) && relative !== ".." && !path14.isAbsolute(relative);
|
|
28263
28352
|
}
|
|
28264
28353
|
function unsafePath2(message) {
|
|
28265
28354
|
return lifecycleError("unsafe_project_path", message);
|
|
@@ -28320,7 +28409,7 @@ function validateBackendConfig(config) {
|
|
|
28320
28409
|
}
|
|
28321
28410
|
for (const pattern of config.include ?? []) {
|
|
28322
28411
|
const normalized = pattern.replaceAll("\\", "/");
|
|
28323
|
-
if (
|
|
28412
|
+
if (path15.posix.isAbsolute(normalized) || normalized.split("/").includes("..")) {
|
|
28324
28413
|
throw new Error(`manifest backend.include must stay inside the project: ${pattern}`);
|
|
28325
28414
|
}
|
|
28326
28415
|
}
|
|
@@ -28340,7 +28429,7 @@ var CHECK_PHASES = ["project", "capabilities", "migrations", "backend", "tests",
|
|
|
28340
28429
|
var RESERVED_NAMES2 = /* @__PURE__ */ new Set(["api", "serve", "health", "cli", "keys", "upload", "pages", "schemas"]);
|
|
28341
28430
|
async function checkProject(options2) {
|
|
28342
28431
|
throwIfCheckAborted(options2.signal);
|
|
28343
|
-
const projectDir =
|
|
28432
|
+
const projectDir = path16.resolve(options2.projectDir);
|
|
28344
28433
|
const report = createReport();
|
|
28345
28434
|
let manifest;
|
|
28346
28435
|
try {
|
|
@@ -28488,7 +28577,7 @@ async function detectPackageManager(projectDir, packageJson) {
|
|
|
28488
28577
|
["npm-shrinkwrap.json", "npm"]
|
|
28489
28578
|
];
|
|
28490
28579
|
for (const [filename, manager] of locks) {
|
|
28491
|
-
if (await
|
|
28580
|
+
if (await fs13.access(path16.join(projectDir, filename)).then(() => true, () => false)) return manager;
|
|
28492
28581
|
}
|
|
28493
28582
|
return "npm";
|
|
28494
28583
|
}
|
|
@@ -28670,7 +28759,7 @@ function compareVersion(left, right) {
|
|
|
28670
28759
|
}
|
|
28671
28760
|
function validateRelativeDirectory(value2, label) {
|
|
28672
28761
|
const normalized = value2.replaceAll("\\", "/");
|
|
28673
|
-
if (!normalized ||
|
|
28762
|
+
if (!normalized || path16.posix.isAbsolute(normalized) || normalized.split("/").includes("..") || normalized.split("/").filter((part) => part && part !== ".").length === 0) {
|
|
28674
28763
|
throw new Error(`${label} must be a relative directory inside the project`);
|
|
28675
28764
|
}
|
|
28676
28765
|
}
|
|
@@ -28731,10 +28820,10 @@ async function check(io, json) {
|
|
|
28731
28820
|
|
|
28732
28821
|
// packages/localapp/src/project/package.ts
|
|
28733
28822
|
import { spawn as spawn3 } from "node:child_process";
|
|
28734
|
-
import
|
|
28823
|
+
import path17 from "node:path";
|
|
28735
28824
|
async function buildApplicationPackage(options2) {
|
|
28736
28825
|
throwIfPackageBuildAborted(options2.signal);
|
|
28737
|
-
const projectDir =
|
|
28826
|
+
const projectDir = path17.resolve(options2.projectDir);
|
|
28738
28827
|
const manifest = await loadAndValidateProjectManifest(projectDir, options2.fileHooks);
|
|
28739
28828
|
throwIfPackageBuildAborted(options2.signal);
|
|
28740
28829
|
const backendRoot = manifest.backend?.root ?? "backend";
|
|
@@ -28967,8 +29056,8 @@ async function createAnchoredPackageCandidate(prepared, hooks, signal) {
|
|
|
28967
29056
|
const config = Buffer.from(JSON.stringify({
|
|
28968
29057
|
dev: prepared.parent.dev.toString(),
|
|
28969
29058
|
ino: prepared.parent.ino.toString(),
|
|
28970
|
-
temporary:
|
|
28971
|
-
target:
|
|
29059
|
+
temporary: path17.basename(prepared.temporaryPath),
|
|
29060
|
+
target: path17.basename(prepared.path),
|
|
28972
29061
|
overwrite: prepared.overwrite
|
|
28973
29062
|
})).toString("base64url");
|
|
28974
29063
|
const child = spawn3(process.execPath, ["--input-type=commonjs", "--eval", PACKAGE_OUTPUT_HELPER, config], {
|
|
@@ -29127,22 +29216,22 @@ async function buildPackage(output, io) {
|
|
|
29127
29216
|
}
|
|
29128
29217
|
|
|
29129
29218
|
// packages/localapp/src/commands/app-install.ts
|
|
29130
|
-
import
|
|
29131
|
-
import
|
|
29219
|
+
import fs15 from "node:fs/promises";
|
|
29220
|
+
import path19 from "node:path";
|
|
29132
29221
|
|
|
29133
29222
|
// packages/localapp/src/project/target.ts
|
|
29134
|
-
import
|
|
29135
|
-
import
|
|
29223
|
+
import fs14 from "node:fs/promises";
|
|
29224
|
+
import path18 from "node:path";
|
|
29136
29225
|
async function resolveProjectTarget(options2) {
|
|
29137
29226
|
const defaultProfile = await readDefaultProfile(options2.projectDir, options2.readHooks);
|
|
29138
29227
|
const store = options2.profileStore ?? new ProfileStore();
|
|
29139
29228
|
return store.resolve(options2.target ?? defaultProfile);
|
|
29140
29229
|
}
|
|
29141
29230
|
async function readDefaultProfile(projectDir, hooks) {
|
|
29142
|
-
const root = await captureDirectory(
|
|
29231
|
+
const root = await captureDirectory(path18.resolve(projectDir));
|
|
29143
29232
|
if (root === void 0) throw unsafePath();
|
|
29144
|
-
const localAppDirectory =
|
|
29145
|
-
const publishPath =
|
|
29233
|
+
const localAppDirectory = path18.join(root.path, ".localapp");
|
|
29234
|
+
const publishPath = path18.join(localAppDirectory, "publish.json");
|
|
29146
29235
|
const directory = await captureDirectory(localAppDirectory);
|
|
29147
29236
|
if (directory === void 0) {
|
|
29148
29237
|
await verifyDirectory(root);
|
|
@@ -29176,7 +29265,7 @@ async function readDefaultProfile(projectDir, hooks) {
|
|
|
29176
29265
|
async function captureDirectory(target) {
|
|
29177
29266
|
let stat2;
|
|
29178
29267
|
try {
|
|
29179
|
-
stat2 = await
|
|
29268
|
+
stat2 = await fs14.lstat(target, { bigint: true });
|
|
29180
29269
|
} catch (error) {
|
|
29181
29270
|
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return void 0;
|
|
29182
29271
|
throw lifecycleError("publish_config_unreadable", "Cannot safely read .localapp/publish.json");
|
|
@@ -29185,14 +29274,14 @@ async function captureDirectory(target) {
|
|
|
29185
29274
|
return { path: target, device: stat2.dev, inode: stat2.ino };
|
|
29186
29275
|
}
|
|
29187
29276
|
async function verifyDirectory(expected) {
|
|
29188
|
-
const stat2 = await
|
|
29277
|
+
const stat2 = await fs14.lstat(expected.path, { bigint: true }).catch(() => void 0);
|
|
29189
29278
|
if (stat2 === void 0 || stat2.isSymbolicLink() || !stat2.isDirectory() || stat2.dev !== expected.device || stat2.ino !== expected.inode) {
|
|
29190
29279
|
throw unsafePath();
|
|
29191
29280
|
}
|
|
29192
29281
|
}
|
|
29193
29282
|
async function lstatOrAbsent(target) {
|
|
29194
29283
|
try {
|
|
29195
|
-
return await
|
|
29284
|
+
return await fs14.lstat(target);
|
|
29196
29285
|
} catch (error) {
|
|
29197
29286
|
if (typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT") return void 0;
|
|
29198
29287
|
throw lifecycleError("publish_config_unreadable", "Cannot safely read .localapp/publish.json");
|
|
@@ -29207,7 +29296,7 @@ function invalidPublishConfig() {
|
|
|
29207
29296
|
|
|
29208
29297
|
// packages/localapp/src/commands/app-install.ts
|
|
29209
29298
|
async function installApplication(options2) {
|
|
29210
|
-
const projectDir =
|
|
29299
|
+
const projectDir = path19.resolve(options2.projectDir);
|
|
29211
29300
|
const target = await resolveProjectTarget({ projectDir, target: options2.target, profileStore: options2.profileStore });
|
|
29212
29301
|
const packagePath = options2.packagePath === void 0 ? (await buildApplicationPackage({ projectDir })).path : await inspectExplicitPackage(options2.packagePath);
|
|
29213
29302
|
const response = await new LocalAppClient(target).installPackage(packagePath);
|
|
@@ -29219,11 +29308,11 @@ async function installApplication(options2) {
|
|
|
29219
29308
|
async function inspectExplicitPackage(input) {
|
|
29220
29309
|
let packagePath;
|
|
29221
29310
|
try {
|
|
29222
|
-
packagePath = await
|
|
29311
|
+
packagePath = await fs15.realpath(input);
|
|
29223
29312
|
} catch {
|
|
29224
29313
|
throw lifecycleError("application_package_invalid", "Application package is invalid");
|
|
29225
29314
|
}
|
|
29226
|
-
if (
|
|
29315
|
+
if (path19.extname(packagePath).toLowerCase() !== ".localapp") {
|
|
29227
29316
|
throw lifecycleError("application_package_invalid", "Application package must use the .localapp extension");
|
|
29228
29317
|
}
|
|
29229
29318
|
try {
|
|
@@ -29302,26 +29391,26 @@ function safeResponseMessage2(response, credential, fallback) {
|
|
|
29302
29391
|
// packages/localapp/src/commands/dev.ts
|
|
29303
29392
|
import { randomBytes as randomBytes2 } from "node:crypto";
|
|
29304
29393
|
import { chmodSync, renameSync } from "node:fs";
|
|
29305
|
-
import
|
|
29394
|
+
import fs19 from "node:fs/promises";
|
|
29306
29395
|
import net from "node:net";
|
|
29307
|
-
import
|
|
29396
|
+
import path24 from "node:path";
|
|
29308
29397
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
29309
29398
|
|
|
29310
29399
|
// packages/localapp/src/dev/credentials.ts
|
|
29311
29400
|
import { randomBytes } from "node:crypto";
|
|
29312
|
-
import
|
|
29313
|
-
import
|
|
29401
|
+
import fs16 from "node:fs/promises";
|
|
29402
|
+
import path20 from "node:path";
|
|
29314
29403
|
var API_KEY_PATTERN = /^localapp_dev_[0-9a-f]{64}$/;
|
|
29315
29404
|
var PASSWORD_PATTERN = /^localapp_dev_password_[0-9a-f]{64}$/;
|
|
29316
29405
|
var JWT_SECRET_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
29317
29406
|
async function readOrCreateDevCredentials(projectDir) {
|
|
29318
|
-
const stateRoot =
|
|
29319
|
-
await
|
|
29320
|
-
if (process.platform !== "win32") await
|
|
29407
|
+
const stateRoot = path20.join(path20.resolve(projectDir), "tmp/localapp-dev");
|
|
29408
|
+
await fs16.mkdir(stateRoot, { recursive: true, mode: 448 });
|
|
29409
|
+
if (process.platform !== "win32") await fs16.chmod(stateRoot, 448);
|
|
29321
29410
|
const paths = {
|
|
29322
|
-
apiKey:
|
|
29323
|
-
password:
|
|
29324
|
-
jwtSecret:
|
|
29411
|
+
apiKey: path20.join(stateRoot, "server-api-key"),
|
|
29412
|
+
password: path20.join(stateRoot, "server-password"),
|
|
29413
|
+
jwtSecret: path20.join(stateRoot, "server-jwt-secret")
|
|
29325
29414
|
};
|
|
29326
29415
|
const [apiKey, password, jwtSecret] = await Promise.all([
|
|
29327
29416
|
readOrCreatePrivateValue(paths.apiKey, API_KEY_PATTERN, () => `localapp_dev_${randomBytes(32).toString("hex")}`),
|
|
@@ -29336,7 +29425,7 @@ async function readOrCreatePrivateValue(filePath, pattern, generate) {
|
|
|
29336
29425
|
const generated = generate();
|
|
29337
29426
|
let handle;
|
|
29338
29427
|
try {
|
|
29339
|
-
handle = await
|
|
29428
|
+
handle = await fs16.open(filePath, "wx", 384);
|
|
29340
29429
|
await handle.writeFile(`${generated}
|
|
29341
29430
|
`, "utf8");
|
|
29342
29431
|
await handle.sync();
|
|
@@ -29348,20 +29437,20 @@ async function readOrCreatePrivateValue(filePath, pattern, generate) {
|
|
|
29348
29437
|
} finally {
|
|
29349
29438
|
await handle?.close();
|
|
29350
29439
|
}
|
|
29351
|
-
if (process.platform !== "win32") await
|
|
29440
|
+
if (process.platform !== "win32") await fs16.chmod(filePath, 384);
|
|
29352
29441
|
return generated;
|
|
29353
29442
|
}
|
|
29354
29443
|
async function readPrivateValue(filePath) {
|
|
29355
29444
|
let stat2;
|
|
29356
29445
|
try {
|
|
29357
|
-
stat2 = await
|
|
29446
|
+
stat2 = await fs16.lstat(filePath);
|
|
29358
29447
|
} catch (error) {
|
|
29359
29448
|
if (error.code === "ENOENT") return void 0;
|
|
29360
29449
|
throw privateCredentialError(filePath);
|
|
29361
29450
|
}
|
|
29362
29451
|
if (stat2.isSymbolicLink() || !stat2.isFile()) throw privateCredentialError(filePath);
|
|
29363
|
-
if (process.platform !== "win32") await
|
|
29364
|
-
const value2 = (await
|
|
29452
|
+
if (process.platform !== "win32") await fs16.chmod(filePath, 384);
|
|
29453
|
+
const value2 = (await fs16.readFile(filePath, "utf8")).trim();
|
|
29365
29454
|
if (!value2) throw privateCredentialError(filePath);
|
|
29366
29455
|
return value2;
|
|
29367
29456
|
}
|
|
@@ -29379,17 +29468,17 @@ import { spawn as spawn5 } from "node:child_process";
|
|
|
29379
29468
|
// packages/localapp/src/native/native-adapter.ts
|
|
29380
29469
|
import { spawn as spawn4 } from "node:child_process";
|
|
29381
29470
|
import { existsSync } from "node:fs";
|
|
29382
|
-
import
|
|
29471
|
+
import fs18 from "node:fs/promises";
|
|
29383
29472
|
import { homedir as homedir2 } from "node:os";
|
|
29384
|
-
import
|
|
29473
|
+
import path23 from "node:path";
|
|
29385
29474
|
|
|
29386
29475
|
// packages/localapp/src/artifact-directory.ts
|
|
29387
29476
|
import { realpathSync } from "node:fs";
|
|
29388
|
-
import
|
|
29477
|
+
import path21 from "node:path";
|
|
29389
29478
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
29390
29479
|
function artifactDirectoryFromEntrypoint(entrypoint) {
|
|
29391
29480
|
const canonical = realpathSync(entrypoint);
|
|
29392
|
-
return
|
|
29481
|
+
return path21.resolve(path21.dirname(canonical), "..");
|
|
29393
29482
|
}
|
|
29394
29483
|
function localAppArtifactDirectory(entrypoint = process.argv[1]) {
|
|
29395
29484
|
if (entrypoint !== void 0 && entrypoint.length > 0) {
|
|
@@ -29398,7 +29487,7 @@ function localAppArtifactDirectory(entrypoint = process.argv[1]) {
|
|
|
29398
29487
|
} catch {
|
|
29399
29488
|
}
|
|
29400
29489
|
}
|
|
29401
|
-
return
|
|
29490
|
+
return path21.resolve(path21.dirname(fileURLToPath3(import.meta.url)), "..");
|
|
29402
29491
|
}
|
|
29403
29492
|
|
|
29404
29493
|
// packages/server/src/lib/device-action-types.ts
|
|
@@ -29524,27 +29613,27 @@ function invalid2() {
|
|
|
29524
29613
|
|
|
29525
29614
|
// packages/localapp/src/native/adapter-selection.ts
|
|
29526
29615
|
import crypto5 from "node:crypto";
|
|
29527
|
-
import
|
|
29528
|
-
import
|
|
29616
|
+
import fs17 from "node:fs/promises";
|
|
29617
|
+
import path22 from "node:path";
|
|
29529
29618
|
async function selectNativeAdapter(options2) {
|
|
29530
29619
|
const platform = options2.platform ?? process.platform;
|
|
29531
29620
|
const arch = options2.arch ?? process.arch;
|
|
29532
29621
|
const target = targetFor(platform, arch);
|
|
29533
|
-
const root =
|
|
29622
|
+
const root = path22.resolve(options2.root);
|
|
29534
29623
|
let value2;
|
|
29535
29624
|
try {
|
|
29536
|
-
value2 = JSON.parse(await
|
|
29625
|
+
value2 = JSON.parse(await fs17.readFile(path22.join(root, "adapter-manifest.json"), "utf8"));
|
|
29537
29626
|
} catch {
|
|
29538
29627
|
throw unsupported(platform, arch);
|
|
29539
29628
|
}
|
|
29540
29629
|
const manifest = parseManifest(value2, target, root, platform, arch);
|
|
29541
29630
|
for (const asset of manifest.assets) {
|
|
29542
|
-
const absolute =
|
|
29631
|
+
const absolute = path22.join(root, ...asset.path.split("/"));
|
|
29543
29632
|
let bytes;
|
|
29544
29633
|
try {
|
|
29545
|
-
const stat2 = await
|
|
29634
|
+
const stat2 = await fs17.lstat(absolute);
|
|
29546
29635
|
if (!stat2.isFile() || stat2.isSymbolicLink()) throw new Error("unsafe native asset");
|
|
29547
|
-
bytes = await
|
|
29636
|
+
bytes = await fs17.readFile(absolute);
|
|
29548
29637
|
} catch {
|
|
29549
29638
|
throw lifecycleError("native_adapter_digest_invalid", "The selected LocalApp native adapter is missing or unsafe");
|
|
29550
29639
|
}
|
|
@@ -29560,8 +29649,8 @@ async function selectNativeAdapter(options2) {
|
|
|
29560
29649
|
return {
|
|
29561
29650
|
target,
|
|
29562
29651
|
root,
|
|
29563
|
-
executable:
|
|
29564
|
-
ipcClient:
|
|
29652
|
+
executable: path22.join(root, ...executable.split("/")),
|
|
29653
|
+
ipcClient: path22.join(root, ...ipcClient.split("/")),
|
|
29565
29654
|
signing: manifest.signing,
|
|
29566
29655
|
assets: manifest.assets
|
|
29567
29656
|
};
|
|
@@ -29594,7 +29683,7 @@ function parseSingleManifest(value2, target, root, platform, arch) {
|
|
|
29594
29683
|
throw unsupported(platform, arch);
|
|
29595
29684
|
}
|
|
29596
29685
|
const assets = value2.assets.map((asset) => {
|
|
29597
|
-
if (!record(asset) || !exactKeys(asset, ["path", "sha256"]) || typeof asset.path !== "string" || typeof asset.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(asset.sha256) || !safeRelativeAsset(asset.path) || !asset.path.startsWith(`${target}/`) ||
|
|
29686
|
+
if (!record(asset) || !exactKeys(asset, ["path", "sha256"]) || typeof asset.path !== "string" || typeof asset.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(asset.sha256) || !safeRelativeAsset(asset.path) || !asset.path.startsWith(`${target}/`) || path22.resolve(root, ...asset.path.split("/")).startsWith(`${root}${path22.sep}`) === false) {
|
|
29598
29687
|
throw unsupported(platform, arch);
|
|
29599
29688
|
}
|
|
29600
29689
|
return { path: asset.path, sha256: asset.sha256 };
|
|
@@ -29603,7 +29692,7 @@ function parseSingleManifest(value2, target, root, platform, arch) {
|
|
|
29603
29692
|
return { signing: { mode: value2.signing.mode }, assets };
|
|
29604
29693
|
}
|
|
29605
29694
|
function safeRelativeAsset(value2) {
|
|
29606
|
-
return value2.length > 0 && value2.length <= 512 && !value2.includes("\\") && !value2.startsWith("/") && !value2.endsWith("/") &&
|
|
29695
|
+
return value2.length > 0 && value2.length <= 512 && !value2.includes("\\") && !value2.startsWith("/") && !value2.endsWith("/") && path22.posix.normalize(value2) === value2 && value2.split("/").every((part) => part && part !== "." && part !== "..");
|
|
29607
29696
|
}
|
|
29608
29697
|
function record(value2) {
|
|
29609
29698
|
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
@@ -29720,12 +29809,12 @@ function validateNativeNotificationEnvelope(value2, platform = process.platform)
|
|
|
29720
29809
|
async function installLinuxScheme(options2) {
|
|
29721
29810
|
if (!safeAbsoluteLocalPath(options2.dataHome, "linux")) throw lifecycleError("native_adapter_invalid", "The Linux data directory is invalid");
|
|
29722
29811
|
const desktop = buildLinuxDesktopEntry(options2.nodePath, options2.ipcClientPath);
|
|
29723
|
-
const applications =
|
|
29812
|
+
const applications = path23.posix.join(options2.dataHome, "applications");
|
|
29724
29813
|
const filename = "localapp.desktop";
|
|
29725
|
-
const destination =
|
|
29726
|
-
await
|
|
29727
|
-
const current = await
|
|
29728
|
-
if (current !== desktop) await
|
|
29814
|
+
const destination = path23.posix.join(applications, filename);
|
|
29815
|
+
await fs18.mkdir(applications, { recursive: true, mode: 448 });
|
|
29816
|
+
const current = await fs18.readFile(destination, "utf8").catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
29817
|
+
if (current !== desktop) await fs18.writeFile(destination, desktop, { mode: 420 });
|
|
29729
29818
|
await options2.run("xdg-mime", ["default", filename, "x-scheme-handler/localapp"]);
|
|
29730
29819
|
}
|
|
29731
29820
|
function buildLinuxDesktopEntry(nodePath, ipcClientPath) {
|
|
@@ -29754,9 +29843,9 @@ async function writeBridgeConfiguration(options2) {
|
|
|
29754
29843
|
if (options2.environment !== void 0) configuration.environment = options2.environment;
|
|
29755
29844
|
const content = `${JSON.stringify(configuration)}
|
|
29756
29845
|
`;
|
|
29757
|
-
await
|
|
29758
|
-
const current = await
|
|
29759
|
-
if (current !== content) await
|
|
29846
|
+
await fs18.mkdir(path23.dirname(options2.configPath), { recursive: true, mode: 448 });
|
|
29847
|
+
const current = await fs18.readFile(options2.configPath, "utf8").catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
29848
|
+
if (current !== content) await fs18.writeFile(options2.configPath, content, { mode: 384 });
|
|
29760
29849
|
}
|
|
29761
29850
|
function bridgeRuntimeEnvironment(env, platform) {
|
|
29762
29851
|
const keys = ["LOCALAPP_SUPPORT_DIR", "LOCALAPP_RUNTIME_DIR", "LOCALAPP_DATA_DIR"];
|
|
@@ -29770,13 +29859,13 @@ function bridgeRuntimeEnvironment(env, platform) {
|
|
|
29770
29859
|
return Object.keys(environment).length === 0 ? void 0 : environment;
|
|
29771
29860
|
}
|
|
29772
29861
|
function nativeBridgeConfigPath(platform, supportDir, env) {
|
|
29773
|
-
if (supportDir !== void 0) return platform === "win32" ?
|
|
29774
|
-
if (platform === "darwin") return
|
|
29775
|
-
if (platform === "win32") return
|
|
29776
|
-
return
|
|
29862
|
+
if (supportDir !== void 0) return platform === "win32" ? path23.win32.join(supportDir, "native-bridge.json") : path23.join(supportDir, "native-bridge.json");
|
|
29863
|
+
if (platform === "darwin") return path23.join(homedir2(), "Library", "Application Support", "LocalApp", "native-bridge.json");
|
|
29864
|
+
if (platform === "win32") return path23.win32.join(env.LOCALAPPDATA ?? path23.win32.join(homedir2(), "AppData", "Local"), "LocalApp", "native-bridge.json");
|
|
29865
|
+
return path23.join(env.XDG_DATA_HOME ?? path23.join(homedir2(), ".local", "share"), "localapp", "native-bridge.json");
|
|
29777
29866
|
}
|
|
29778
29867
|
function linuxDataHome(env) {
|
|
29779
|
-
return env.XDG_DATA_HOME ??
|
|
29868
|
+
return env.XDG_DATA_HOME ?? path23.join(homedir2(), ".local", "share");
|
|
29780
29869
|
}
|
|
29781
29870
|
function createWindowsProcessTreeAdapter(helper) {
|
|
29782
29871
|
return { spawnOwned: (command, args, options2) => helper.spawn(command, args, options2) };
|
|
@@ -29804,7 +29893,7 @@ function resolveWindowsNativeExecutable(options2 = {}) {
|
|
|
29804
29893
|
const roots = [env.LOCALAPP_RELEASE_PATH, options2.artifactDirectory ?? localAppArtifactDirectory()];
|
|
29805
29894
|
for (const root of roots) {
|
|
29806
29895
|
if (root === void 0 || root.length === 0) continue;
|
|
29807
|
-
const candidate =
|
|
29896
|
+
const candidate = path23.join(root, "runtime", "native", `win32-${arch}`, "localapp-native.exe");
|
|
29808
29897
|
if (existsSync(candidate)) return candidate;
|
|
29809
29898
|
}
|
|
29810
29899
|
return void 0;
|
|
@@ -29886,7 +29975,7 @@ function boundedTimeout(value2, fallback) {
|
|
|
29886
29975
|
}
|
|
29887
29976
|
async function verifyRegularLocalFile(iconPath) {
|
|
29888
29977
|
try {
|
|
29889
|
-
const stat2 = await
|
|
29978
|
+
const stat2 = await fs18.lstat(iconPath);
|
|
29890
29979
|
return stat2.isFile() && !stat2.isSymbolicLink();
|
|
29891
29980
|
} catch {
|
|
29892
29981
|
return false;
|
|
@@ -29964,7 +30053,7 @@ var PackagedLinuxNotificationSession = class {
|
|
|
29964
30053
|
function createPackagedLinuxNotificationSession(selected, nodePath, environment, timeoutMs) {
|
|
29965
30054
|
const relative = `${selected.target}/localapp-notifications`;
|
|
29966
30055
|
if (!selected.assets.some((asset) => asset.path === relative)) return unsupportedLinuxNotificationSession();
|
|
29967
|
-
return new PackagedLinuxNotificationSession(
|
|
30056
|
+
return new PackagedLinuxNotificationSession(path23.join(selected.root, ...relative.split("/")), nodePath, selected.ipcClient, environment, timeoutMs);
|
|
29968
30057
|
}
|
|
29969
30058
|
function readLinuxAccepted(child, timeoutMs) {
|
|
29970
30059
|
return new Promise((resolve2, reject) => {
|
|
@@ -30041,7 +30130,7 @@ function desktopExecQuote(value2) {
|
|
|
30041
30130
|
}
|
|
30042
30131
|
function safeAbsoluteLocalPath(value2, platform) {
|
|
30043
30132
|
if (typeof value2 !== "string" || value2.length === 0 || value2.includes("\0") || /[\r\n]/.test(value2) || /^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(value2)) return false;
|
|
30044
|
-
const pathApi = platform === "win32" ?
|
|
30133
|
+
const pathApi = platform === "win32" ? path23.win32 : path23.posix;
|
|
30045
30134
|
if (!pathApi.isAbsolute(value2) || pathApi.normalize(value2) !== value2) return false;
|
|
30046
30135
|
return !value2.split(/[\\/]/).some((part) => part === "." || part === "..");
|
|
30047
30136
|
}
|
|
@@ -30571,10 +30660,10 @@ function isRecord9(value2) {
|
|
|
30571
30660
|
// packages/localapp/src/commands/dev.ts
|
|
30572
30661
|
var DEV_USER_ID = "dev-user";
|
|
30573
30662
|
async function runDev(options2, dependencies = {}) {
|
|
30574
|
-
const projectDir =
|
|
30575
|
-
const stateRoot =
|
|
30576
|
-
const dataDir =
|
|
30577
|
-
const packagesDir =
|
|
30663
|
+
const projectDir = path24.resolve(options2.projectDir);
|
|
30664
|
+
const stateRoot = path24.join(projectDir, "tmp/localapp-dev");
|
|
30665
|
+
const dataDir = path24.join(stateRoot, "server");
|
|
30666
|
+
const packagesDir = path24.join(stateRoot, "packages");
|
|
30578
30667
|
const spawnProcess = dependencies.spawnOwnedProcess ?? spawnOwnedProcess;
|
|
30579
30668
|
const lifecycle = new DevLifecycle();
|
|
30580
30669
|
const abort = () => lifecycle.abort();
|
|
@@ -30588,8 +30677,8 @@ async function runDev(options2, dependencies = {}) {
|
|
|
30588
30677
|
const credentials = await lifecycle.runPhase(() => readOrCreateDevCredentials(projectDir));
|
|
30589
30678
|
await lifecycle.runPhase(async () => {
|
|
30590
30679
|
await Promise.all([
|
|
30591
|
-
|
|
30592
|
-
|
|
30680
|
+
fs19.mkdir(dataDir, { recursive: true, mode: 448 }),
|
|
30681
|
+
fs19.mkdir(packagesDir, { recursive: true, mode: 448 })
|
|
30593
30682
|
]);
|
|
30594
30683
|
});
|
|
30595
30684
|
const serverLauncher = dependencies.serverLauncher ?? embeddedServerLauncher();
|
|
@@ -30626,7 +30715,7 @@ async function runDev(options2, dependencies = {}) {
|
|
|
30626
30715
|
const initialize = dependencies.initializeServer ?? initializeServer;
|
|
30627
30716
|
await lifecycle.runPhase((signal) => initialize(ready.listenUrl, ready.setupUrl, credentials.password, signal));
|
|
30628
30717
|
const version = uniqueDevVersion();
|
|
30629
|
-
const packagePath =
|
|
30718
|
+
const packagePath = path24.join(packagesDir, `${manifest.name}-${version}.localapp`);
|
|
30630
30719
|
const build = dependencies.buildApplicationPackage ?? buildApplicationPackage;
|
|
30631
30720
|
const runBuildCommand = createOwnedProjectCommandRunner(lifecycle, spawnProcess, dependencies.windowsAdapter);
|
|
30632
30721
|
const applicationPackage = await lifecycle.runPhase((signal) => build({
|
|
@@ -30661,7 +30750,7 @@ async function runDev(options2, dependencies = {}) {
|
|
|
30661
30750
|
"--strictPort"
|
|
30662
30751
|
];
|
|
30663
30752
|
lifecycle.assertActive();
|
|
30664
|
-
const vite = lifecycle.spawn(() => spawnProcess(configuredVite.command, viteArgs, {
|
|
30753
|
+
const vite = lifecycle.spawn(() => spawnProcess(resolveOwnedCommand(configuredVite.command), viteArgs, {
|
|
30665
30754
|
cwd: projectDir,
|
|
30666
30755
|
env: { ...process.env, LOCALAPP_DEV_API_KEY: credentials.apiKey },
|
|
30667
30756
|
stdio: "ignore",
|
|
@@ -30837,8 +30926,7 @@ var DevLifecycle = class {
|
|
|
30837
30926
|
function createOwnedProjectCommandRunner(lifecycle, spawnProcess, windowsAdapter) {
|
|
30838
30927
|
return async (invocation) => {
|
|
30839
30928
|
lifecycle.assertActive();
|
|
30840
|
-
const
|
|
30841
|
-
const child = lifecycle.spawn(() => spawnProcess(command, invocation.args, {
|
|
30929
|
+
const child = lifecycle.spawn(() => spawnProcess(resolveOwnedCommand(invocation.command), invocation.args, {
|
|
30842
30930
|
cwd: invocation.cwd,
|
|
30843
30931
|
stdio: "ignore",
|
|
30844
30932
|
windowsAdapter
|
|
@@ -30884,15 +30972,15 @@ function isErrorCode(value2, code) {
|
|
|
30884
30972
|
}
|
|
30885
30973
|
async function writeDevConfig(options2) {
|
|
30886
30974
|
throwIfAborted(options2.signal);
|
|
30887
|
-
const projectDir =
|
|
30888
|
-
const localAppDir =
|
|
30889
|
-
const stateRoot =
|
|
30975
|
+
const projectDir = path24.resolve(options2.projectDir);
|
|
30976
|
+
const localAppDir = path24.join(projectDir, ".localapp");
|
|
30977
|
+
const stateRoot = path24.join(projectDir, "tmp/localapp-dev");
|
|
30890
30978
|
await Promise.all([
|
|
30891
|
-
|
|
30892
|
-
|
|
30979
|
+
fs19.mkdir(localAppDir, { recursive: true }),
|
|
30980
|
+
fs19.mkdir(stateRoot, { recursive: true, mode: 448 })
|
|
30893
30981
|
]);
|
|
30894
|
-
const temporary =
|
|
30895
|
-
const destination =
|
|
30982
|
+
const temporary = path24.join(stateRoot, `dev-config.${process.pid}.${randomBytes2(8).toString("hex")}.next`);
|
|
30983
|
+
const destination = path24.join(localAppDir, "dev-config.json");
|
|
30896
30984
|
const value2 = {
|
|
30897
30985
|
serverUrl: options2.serverUrl,
|
|
30898
30986
|
userId: DEV_USER_ID,
|
|
@@ -30900,7 +30988,7 @@ async function writeDevConfig(options2) {
|
|
|
30900
30988
|
appServerPort: options2.appServerPort
|
|
30901
30989
|
};
|
|
30902
30990
|
try {
|
|
30903
|
-
await
|
|
30991
|
+
await fs19.writeFile(temporary, `${JSON.stringify(value2, null, 2)}
|
|
30904
30992
|
`, {
|
|
30905
30993
|
flag: "wx",
|
|
30906
30994
|
mode: 384,
|
|
@@ -30910,16 +30998,16 @@ async function writeDevConfig(options2) {
|
|
|
30910
30998
|
renameSync(temporary, destination);
|
|
30911
30999
|
if (process.platform !== "win32") chmodSync(destination, 384);
|
|
30912
31000
|
} finally {
|
|
30913
|
-
await
|
|
31001
|
+
await fs19.rm(temporary, { force: true });
|
|
30914
31002
|
}
|
|
30915
31003
|
}
|
|
30916
31004
|
function embeddedServerLauncher() {
|
|
30917
|
-
return
|
|
31005
|
+
return path24.resolve(path24.dirname(fileURLToPath4(import.meta.url)), "../runtime/server/bin/server.mjs");
|
|
30918
31006
|
}
|
|
30919
31007
|
async function readManifest(projectDir) {
|
|
30920
31008
|
let value2;
|
|
30921
31009
|
try {
|
|
30922
|
-
value2 = JSON.parse(await
|
|
31010
|
+
value2 = JSON.parse(await fs19.readFile(path24.join(projectDir, "manifest.json"), "utf8"));
|
|
30923
31011
|
} catch {
|
|
30924
31012
|
throw lifecycleError("project_manifest_missing", "No valid manifest.json found. Run 'localapp init' first.");
|
|
30925
31013
|
}
|
|
@@ -31019,15 +31107,15 @@ function throwIfAborted(signal) {
|
|
|
31019
31107
|
if (signal?.aborted) throw abortedDevelopment();
|
|
31020
31108
|
}
|
|
31021
31109
|
async function isFile(filePath) {
|
|
31022
|
-
return
|
|
31110
|
+
return fs19.stat(filePath).then((stat2) => stat2.isFile(), () => false);
|
|
31023
31111
|
}
|
|
31024
31112
|
function isRecord10(value2) {
|
|
31025
31113
|
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
31026
31114
|
}
|
|
31027
31115
|
|
|
31028
31116
|
// packages/localapp/src/commands/server.ts
|
|
31029
|
-
import
|
|
31030
|
-
import
|
|
31117
|
+
import fs26 from "node:fs/promises";
|
|
31118
|
+
import path31 from "node:path";
|
|
31031
31119
|
|
|
31032
31120
|
// packages/localapp/src/daemon/ipc-client.ts
|
|
31033
31121
|
import net2 from "node:net";
|
|
@@ -31291,21 +31379,21 @@ function transportError(error) {
|
|
|
31291
31379
|
|
|
31292
31380
|
// packages/localapp/src/daemon/release-store.ts
|
|
31293
31381
|
import crypto6 from "node:crypto";
|
|
31294
|
-
import
|
|
31382
|
+
import fs20 from "node:fs/promises";
|
|
31295
31383
|
import { constants as fsConstants } from "node:fs";
|
|
31296
|
-
import
|
|
31384
|
+
import path25 from "node:path";
|
|
31297
31385
|
var DIGEST = /^[0-9a-f]{64}$/;
|
|
31298
31386
|
var VERSION = /^[0-9A-Za-z][0-9A-Za-z.+_-]{0,127}$/;
|
|
31299
31387
|
async function verifyReleaseArtifact(directory) {
|
|
31300
|
-
return (await inspectReleaseArtifact(
|
|
31388
|
+
return (await inspectReleaseArtifact(path25.resolve(directory))).manifest;
|
|
31301
31389
|
}
|
|
31302
31390
|
async function publishRelease(options2) {
|
|
31303
|
-
const sourceDirectory =
|
|
31391
|
+
const sourceDirectory = path25.resolve(options2.sourceDirectory);
|
|
31304
31392
|
const inspected = await inspectReleaseArtifact(sourceDirectory);
|
|
31305
31393
|
await ensurePrivateDirectories(options2.layout);
|
|
31306
31394
|
return withReleaseLock(options2.layout, options2.lockTimeoutMs ?? 5e3, async () => {
|
|
31307
31395
|
const releaseName = `${inspected.manifest.version}-${inspected.manifest.artifactDigest}`;
|
|
31308
|
-
const releasePath =
|
|
31396
|
+
const releasePath = path25.join(options2.layout.releasesDir, releaseName);
|
|
31309
31397
|
const existing = await lstatOptional2(releasePath);
|
|
31310
31398
|
if (existing === void 0) {
|
|
31311
31399
|
await publishImmutableDirectory(releasePath, inspected, options2.layout.releasesDir);
|
|
@@ -31321,7 +31409,7 @@ async function publishRelease(options2) {
|
|
|
31321
31409
|
entrypoint: inspected.manifest.entrypoint,
|
|
31322
31410
|
bootstrapEntrypoint: inspected.manifest.bootstrapEntrypoint
|
|
31323
31411
|
};
|
|
31324
|
-
const launcherBytes = await readRegularFile(
|
|
31412
|
+
const launcherBytes = await readRegularFile(path25.join(releasePath, ...inspected.manifest.bootstrapEntrypoint.split("/")));
|
|
31325
31413
|
await ensureStableLauncher(options2.layout.launcherPath, launcherBytes);
|
|
31326
31414
|
await writeAtomic(options2.layout.currentManifestPath, Buffer.from(`${JSON.stringify(current, null, 2)}
|
|
31327
31415
|
`), 384);
|
|
@@ -31338,8 +31426,8 @@ async function readCurrentRelease(layout) {
|
|
|
31338
31426
|
if (!isRecord12(value2) || !hasExactKeys2(value2, ["version", "artifactDigest", "releasePath", "entrypoint", "bootstrapEntrypoint"]) || typeof value2.version !== "string" || !VERSION.test(value2.version) || typeof value2.artifactDigest !== "string" || !DIGEST.test(value2.artifactDigest) || typeof value2.releasePath !== "string" || typeof value2.entrypoint !== "string" || typeof value2.bootstrapEntrypoint !== "string") {
|
|
31339
31427
|
throw lifecycleError("release_current_invalid", "The current LocalApp release manifest is missing or invalid");
|
|
31340
31428
|
}
|
|
31341
|
-
const expectedPath =
|
|
31342
|
-
if (
|
|
31429
|
+
const expectedPath = path25.join(layout.releasesDir, `${value2.version}-${value2.artifactDigest}`);
|
|
31430
|
+
if (path25.resolve(value2.releasePath) !== path25.resolve(expectedPath) || !isSafeRelativeFile(value2.entrypoint) || !isSafeRelativeFile(value2.bootstrapEntrypoint)) {
|
|
31343
31431
|
throw lifecycleError("release_current_invalid", "The current LocalApp release manifest is missing or invalid");
|
|
31344
31432
|
}
|
|
31345
31433
|
return {
|
|
@@ -31352,9 +31440,9 @@ async function readCurrentRelease(layout) {
|
|
|
31352
31440
|
}
|
|
31353
31441
|
async function inspectReleaseArtifact(directory) {
|
|
31354
31442
|
try {
|
|
31355
|
-
const root = await
|
|
31443
|
+
const root = await fs20.lstat(directory);
|
|
31356
31444
|
if (!root.isDirectory() || root.isSymbolicLink()) throw invalidArtifact();
|
|
31357
|
-
const manifestPath =
|
|
31445
|
+
const manifestPath = path25.join(directory, ".localapp-artifact.json");
|
|
31358
31446
|
const manifestBytes = await readRegularFile(manifestPath);
|
|
31359
31447
|
const manifest = parseArtifactManifest(JSON.parse(manifestBytes.toString("utf8")));
|
|
31360
31448
|
const observed = await listArtifactFiles(directory);
|
|
@@ -31364,7 +31452,7 @@ async function inspectReleaseArtifact(directory) {
|
|
|
31364
31452
|
}
|
|
31365
31453
|
const files = /* @__PURE__ */ new Map();
|
|
31366
31454
|
for (const entry of manifest.files) {
|
|
31367
|
-
const bytes = await readRegularFile(
|
|
31455
|
+
const bytes = await readRegularFile(path25.join(directory, ...entry.path.split("/")));
|
|
31368
31456
|
if (bytes.byteLength !== entry.size || sha2563(bytes) !== entry.sha256) throw invalidArtifact();
|
|
31369
31457
|
files.set(entry.path, bytes);
|
|
31370
31458
|
}
|
|
@@ -31491,13 +31579,13 @@ function parseArtifactFile(value2) {
|
|
|
31491
31579
|
async function listArtifactFiles(root) {
|
|
31492
31580
|
const files = /* @__PURE__ */ new Set();
|
|
31493
31581
|
const visit = async (directory, prefix) => {
|
|
31494
|
-
const entries = await
|
|
31582
|
+
const entries = await fs20.readdir(directory, { withFileTypes: true });
|
|
31495
31583
|
for (const entry of entries) {
|
|
31496
31584
|
const relativePath2 = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
31497
31585
|
if (relativePath2 === ".localapp-artifact.json") continue;
|
|
31498
31586
|
if (!isSafeRelativeFile(relativePath2)) throw invalidArtifact();
|
|
31499
31587
|
if (entry.isSymbolicLink()) throw invalidArtifact();
|
|
31500
|
-
if (entry.isDirectory()) await visit(
|
|
31588
|
+
if (entry.isDirectory()) await visit(path25.join(directory, entry.name), relativePath2);
|
|
31501
31589
|
else if (entry.isFile()) files.add(relativePath2);
|
|
31502
31590
|
else throw invalidArtifact();
|
|
31503
31591
|
}
|
|
@@ -31506,25 +31594,25 @@ async function listArtifactFiles(root) {
|
|
|
31506
31594
|
return files;
|
|
31507
31595
|
}
|
|
31508
31596
|
async function publishImmutableDirectory(releasePath, inspected, releasesDirectory) {
|
|
31509
|
-
const staging = await
|
|
31510
|
-
if (process.platform !== "win32") await
|
|
31597
|
+
const staging = await fs20.mkdtemp(path25.join(releasesDirectory, ".release-stage-"));
|
|
31598
|
+
if (process.platform !== "win32") await fs20.chmod(staging, 448);
|
|
31511
31599
|
try {
|
|
31512
31600
|
for (const [relativePath2, bytes] of inspected.files) {
|
|
31513
|
-
const destination =
|
|
31514
|
-
await
|
|
31515
|
-
await
|
|
31601
|
+
const destination = path25.join(staging, ...relativePath2.split("/"));
|
|
31602
|
+
await fs20.mkdir(path25.dirname(destination), { recursive: true, mode: 448 });
|
|
31603
|
+
await fs20.writeFile(destination, bytes, { flag: "wx", mode: isExecutableReleaseFile(relativePath2, inspected.manifest) ? 448 : 384 });
|
|
31516
31604
|
}
|
|
31517
|
-
await
|
|
31605
|
+
await fs20.writeFile(path25.join(staging, ".localapp-artifact.json"), inspected.manifestBytes, { flag: "wx", mode: 384 });
|
|
31518
31606
|
await inspectReleaseArtifact(staging);
|
|
31519
31607
|
try {
|
|
31520
|
-
await
|
|
31608
|
+
await fs20.rename(staging, releasePath);
|
|
31521
31609
|
} catch (error) {
|
|
31522
31610
|
if (error.code !== "EEXIST" && error.code !== "ENOTEMPTY") throw error;
|
|
31523
31611
|
const existing = await inspectReleaseArtifact(releasePath);
|
|
31524
31612
|
if (existing.manifest.artifactDigest !== inspected.manifest.artifactDigest) throw invalidArtifact();
|
|
31525
31613
|
}
|
|
31526
31614
|
} finally {
|
|
31527
|
-
await
|
|
31615
|
+
await fs20.rm(staging, { recursive: true, force: true });
|
|
31528
31616
|
}
|
|
31529
31617
|
}
|
|
31530
31618
|
function isExecutableReleaseFile(relativePath2, manifest) {
|
|
@@ -31534,7 +31622,7 @@ function isExecutableReleaseFile(relativePath2, manifest) {
|
|
|
31534
31622
|
async function ensurePrivateDirectories(layout) {
|
|
31535
31623
|
validateRuntimeLayout(layout);
|
|
31536
31624
|
await ensurePrivateDirectory(layout.supportDir);
|
|
31537
|
-
for (const directory of [layout.releasesDir, layout.logsDir,
|
|
31625
|
+
for (const directory of [layout.releasesDir, layout.logsDir, path25.dirname(layout.launcherPath), layout.runtimeDir]) {
|
|
31538
31626
|
await ensurePrivateDirectory(directory);
|
|
31539
31627
|
}
|
|
31540
31628
|
}
|
|
@@ -31557,12 +31645,12 @@ async function withReleaseLock(layout, timeoutMs, operation) {
|
|
|
31557
31645
|
}
|
|
31558
31646
|
}
|
|
31559
31647
|
async function tryCreateReleaseLock(layout) {
|
|
31560
|
-
const temporary =
|
|
31648
|
+
const temporary = path25.join(layout.runtimeDir, `.release-lock.${process.pid}.${crypto6.randomUUID()}.next`);
|
|
31561
31649
|
let handle;
|
|
31562
31650
|
let identity;
|
|
31563
31651
|
let linked = false;
|
|
31564
31652
|
try {
|
|
31565
|
-
handle = await
|
|
31653
|
+
handle = await fs20.open(temporary, "wx", 384);
|
|
31566
31654
|
const stat2 = await handle.stat({ bigint: true });
|
|
31567
31655
|
if (!stat2.isFile()) throw lifecycleError("release_store_lock_invalid", "The LocalApp release lock could not be initialized");
|
|
31568
31656
|
identity = { dev: stat2.dev, ino: stat2.ino };
|
|
@@ -31570,13 +31658,13 @@ async function tryCreateReleaseLock(layout) {
|
|
|
31570
31658
|
`);
|
|
31571
31659
|
await handle.sync();
|
|
31572
31660
|
try {
|
|
31573
|
-
await
|
|
31661
|
+
await fs20.link(temporary, layout.releaseLockPath);
|
|
31574
31662
|
} catch (error) {
|
|
31575
31663
|
if (error.code === "EEXIST") return void 0;
|
|
31576
31664
|
throw error;
|
|
31577
31665
|
}
|
|
31578
31666
|
linked = true;
|
|
31579
|
-
const canonical = await
|
|
31667
|
+
const canonical = await fs20.lstat(layout.releaseLockPath, { bigint: true });
|
|
31580
31668
|
if (!canonical.isFile() || canonical.isSymbolicLink() || canonical.dev !== identity.dev || canonical.ino !== identity.ino) {
|
|
31581
31669
|
throw lifecycleError("release_store_lock_invalid", "The LocalApp release lock identity changed during creation");
|
|
31582
31670
|
}
|
|
@@ -31590,12 +31678,12 @@ async function tryCreateReleaseLock(layout) {
|
|
|
31590
31678
|
if (!linked || identity === void 0) {
|
|
31591
31679
|
await handle?.close().catch(() => void 0);
|
|
31592
31680
|
if (identity !== void 0) await unlinkOwnedPath(temporary, identity).catch(() => void 0);
|
|
31593
|
-
else await
|
|
31681
|
+
else await fs20.rm(temporary, { force: true }).catch(() => void 0);
|
|
31594
31682
|
}
|
|
31595
31683
|
}
|
|
31596
31684
|
}
|
|
31597
31685
|
async function reclaimDeadReleaseLock(lockPath) {
|
|
31598
|
-
const before = await
|
|
31686
|
+
const before = await fs20.lstat(lockPath, { bigint: true }).catch((error) => {
|
|
31599
31687
|
if (error.code === "ENOENT") return void 0;
|
|
31600
31688
|
throw error;
|
|
31601
31689
|
});
|
|
@@ -31620,42 +31708,42 @@ function processExists(pid) {
|
|
|
31620
31708
|
}
|
|
31621
31709
|
}
|
|
31622
31710
|
async function unlinkOwnedPath(filePath, identity) {
|
|
31623
|
-
const current = await
|
|
31711
|
+
const current = await fs20.lstat(filePath, { bigint: true }).catch((error) => {
|
|
31624
31712
|
if (error.code === "ENOENT") return void 0;
|
|
31625
31713
|
throw error;
|
|
31626
31714
|
});
|
|
31627
31715
|
if (current === void 0 || current.isSymbolicLink() || current.dev !== identity.dev || current.ino !== identity.ino) return false;
|
|
31628
|
-
await
|
|
31716
|
+
await fs20.unlink(filePath);
|
|
31629
31717
|
return true;
|
|
31630
31718
|
}
|
|
31631
31719
|
async function ensurePrivateDirectory(directory) {
|
|
31632
|
-
await
|
|
31633
|
-
const stat2 = await
|
|
31720
|
+
await fs20.mkdir(directory, { recursive: true, mode: 448 });
|
|
31721
|
+
const stat2 = await fs20.lstat(directory);
|
|
31634
31722
|
if (!stat2.isDirectory() || stat2.isSymbolicLink()) {
|
|
31635
31723
|
throw lifecycleError("release_path_unsafe", "A LocalApp release directory is not a private regular directory");
|
|
31636
31724
|
}
|
|
31637
31725
|
if (process.platform !== "win32") {
|
|
31638
|
-
await
|
|
31639
|
-
const secured = await
|
|
31726
|
+
await fs20.chmod(directory, 448);
|
|
31727
|
+
const secured = await fs20.lstat(directory);
|
|
31640
31728
|
if (!secured.isDirectory() || secured.isSymbolicLink() || (secured.mode & 63) !== 0) {
|
|
31641
31729
|
throw lifecycleError("release_path_unsafe", "A LocalApp release directory is not private");
|
|
31642
31730
|
}
|
|
31643
31731
|
}
|
|
31644
31732
|
}
|
|
31645
31733
|
function validateRuntimeLayout(layout) {
|
|
31646
|
-
const support =
|
|
31734
|
+
const support = path25.resolve(layout.supportDir);
|
|
31647
31735
|
const expected = [
|
|
31648
|
-
[layout.releasesDir,
|
|
31649
|
-
[layout.currentManifestPath,
|
|
31650
|
-
[layout.launcherPath,
|
|
31651
|
-
[layout.logsDir,
|
|
31736
|
+
[layout.releasesDir, path25.join(support, "releases")],
|
|
31737
|
+
[layout.currentManifestPath, path25.join(support, "current.json")],
|
|
31738
|
+
[layout.launcherPath, path25.join(support, "bin", "localapp-daemon-bootstrap.mjs")],
|
|
31739
|
+
[layout.logsDir, path25.join(support, "logs")]
|
|
31652
31740
|
];
|
|
31653
|
-
if (expected.some(([actual, canonical]) =>
|
|
31741
|
+
if (expected.some(([actual, canonical]) => path25.resolve(actual) !== path25.resolve(canonical)) || path25.resolve(layout.releaseLockPath) !== path25.resolve(layout.runtimeDir, "release.lock")) {
|
|
31654
31742
|
throw lifecycleError("release_path_unsafe", "The LocalApp release layout is invalid");
|
|
31655
31743
|
}
|
|
31656
31744
|
}
|
|
31657
31745
|
async function ensureStableLauncher(filePath, bytes) {
|
|
31658
|
-
const existing = await
|
|
31746
|
+
const existing = await fs20.lstat(filePath).catch((error) => {
|
|
31659
31747
|
if (error.code === "ENOENT") return void 0;
|
|
31660
31748
|
throw error;
|
|
31661
31749
|
});
|
|
@@ -31670,30 +31758,30 @@ async function ensureStableLauncher(filePath, bytes) {
|
|
|
31670
31758
|
if (!current.equals(bytes)) {
|
|
31671
31759
|
throw lifecycleError("release_launcher_incompatible", "The stable LocalApp launcher is incompatible with this release");
|
|
31672
31760
|
}
|
|
31673
|
-
if (process.platform !== "win32") await
|
|
31761
|
+
if (process.platform !== "win32") await fs20.chmod(filePath, 448);
|
|
31674
31762
|
}
|
|
31675
31763
|
async function writeAtomic(filePath, bytes, mode) {
|
|
31676
|
-
await
|
|
31677
|
-
const temporary =
|
|
31764
|
+
await fs20.mkdir(path25.dirname(filePath), { recursive: true, mode: 448 });
|
|
31765
|
+
const temporary = path25.join(path25.dirname(filePath), `.${path25.basename(filePath)}.${process.pid}.${crypto6.randomUUID()}.next`);
|
|
31678
31766
|
let handle;
|
|
31679
31767
|
try {
|
|
31680
|
-
handle = await
|
|
31768
|
+
handle = await fs20.open(temporary, "wx", mode);
|
|
31681
31769
|
await handle.writeFile(bytes);
|
|
31682
31770
|
await handle.sync();
|
|
31683
31771
|
await handle.close();
|
|
31684
31772
|
handle = void 0;
|
|
31685
|
-
await
|
|
31686
|
-
if (process.platform !== "win32") await
|
|
31773
|
+
await fs20.rename(temporary, filePath);
|
|
31774
|
+
if (process.platform !== "win32") await fs20.chmod(filePath, mode);
|
|
31687
31775
|
} finally {
|
|
31688
31776
|
await handle?.close();
|
|
31689
|
-
await
|
|
31777
|
+
await fs20.rm(temporary, { force: true });
|
|
31690
31778
|
}
|
|
31691
31779
|
}
|
|
31692
31780
|
async function readRegularFile(filePath) {
|
|
31693
|
-
const before = await
|
|
31781
|
+
const before = await fs20.lstat(filePath, { bigint: true });
|
|
31694
31782
|
if (!before.isFile() || before.isSymbolicLink()) throw invalidArtifact();
|
|
31695
31783
|
const noFollow = "O_NOFOLLOW" in fsConstants ? fsConstants.O_NOFOLLOW : 0;
|
|
31696
|
-
const handle = await
|
|
31784
|
+
const handle = await fs20.open(filePath, fsConstants.O_RDONLY | noFollow);
|
|
31697
31785
|
try {
|
|
31698
31786
|
const opened = await handle.stat({ bigint: true });
|
|
31699
31787
|
if (!opened.isFile() || opened.dev !== before.dev || opened.ino !== before.ino) throw invalidArtifact();
|
|
@@ -31706,7 +31794,7 @@ async function readRegularFile(filePath) {
|
|
|
31706
31794
|
}
|
|
31707
31795
|
}
|
|
31708
31796
|
function isSafeRelativeFile(value2) {
|
|
31709
|
-
return value2.length > 0 && value2.length <= 512 && !value2.includes("\\") && !value2.startsWith("/") &&
|
|
31797
|
+
return value2.length > 0 && value2.length <= 512 && !value2.includes("\\") && !value2.startsWith("/") && path25.posix.normalize(value2) === value2 && !value2.endsWith("/") && value2.split("/").every((segment) => segment !== "" && segment !== "." && segment !== "..");
|
|
31710
31798
|
}
|
|
31711
31799
|
function compareArtifactFiles(left, right) {
|
|
31712
31800
|
return left.path < right.path ? -1 : left.path > right.path ? 1 : 0;
|
|
@@ -31729,18 +31817,18 @@ function isRecord12(value2) {
|
|
|
31729
31817
|
return value2 !== null && typeof value2 === "object" && !Array.isArray(value2);
|
|
31730
31818
|
}
|
|
31731
31819
|
async function lstatOptional2(filePath) {
|
|
31732
|
-
return
|
|
31820
|
+
return fs20.lstat(filePath).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
31733
31821
|
}
|
|
31734
31822
|
|
|
31735
31823
|
// packages/localapp/src/daemon/runtime-layout.ts
|
|
31736
31824
|
import crypto7 from "node:crypto";
|
|
31737
31825
|
import { homedir as homedir3 } from "node:os";
|
|
31738
|
-
import
|
|
31826
|
+
import path26 from "node:path";
|
|
31739
31827
|
function createRuntimeLayout(options2 = {}) {
|
|
31740
31828
|
const platform = options2.platform ?? process.platform;
|
|
31741
31829
|
const env = options2.env ?? process.env;
|
|
31742
31830
|
const homeDirectory = options2.homeDir ?? homedir3();
|
|
31743
|
-
const pathApi = platform === "win32" ?
|
|
31831
|
+
const pathApi = platform === "win32" ? path26.win32 : path26.posix;
|
|
31744
31832
|
const supportDir = options2.supportDir ?? defaultSupportDirectory(platform, env, homeDirectory, pathApi);
|
|
31745
31833
|
const runtimeDir = options2.runtimeDir ?? defaultRuntimeDirectory(platform, env, homeDirectory, supportDir, options2.uid, pathApi);
|
|
31746
31834
|
const dataDir = options2.dataDir ?? pathApi.join(supportDir, "data");
|
|
@@ -31778,38 +31866,38 @@ function defaultRuntimeDirectory(platform, env, homeDirectory, supportDirectory,
|
|
|
31778
31866
|
}
|
|
31779
31867
|
|
|
31780
31868
|
// packages/localapp/src/service/service-manager.ts
|
|
31781
|
-
import
|
|
31869
|
+
import fs25 from "node:fs/promises";
|
|
31782
31870
|
import { spawn as spawn6 } from "node:child_process";
|
|
31783
31871
|
|
|
31784
31872
|
// packages/localapp/src/service/linux-systemd-user.ts
|
|
31785
|
-
import
|
|
31786
|
-
import
|
|
31873
|
+
import fs22 from "node:fs/promises";
|
|
31874
|
+
import path28 from "node:path";
|
|
31787
31875
|
|
|
31788
31876
|
// packages/localapp/src/service/service-files.ts
|
|
31789
31877
|
import crypto8 from "node:crypto";
|
|
31790
|
-
import
|
|
31791
|
-
import
|
|
31878
|
+
import fs21 from "node:fs/promises";
|
|
31879
|
+
import path27 from "node:path";
|
|
31792
31880
|
async function writeServiceFile(filePath, value2) {
|
|
31793
|
-
const existing = await
|
|
31881
|
+
const existing = await fs21.readFile(filePath, "utf8").catch((error) => {
|
|
31794
31882
|
if (error.code === "ENOENT") return void 0;
|
|
31795
31883
|
throw error;
|
|
31796
31884
|
});
|
|
31797
31885
|
if (existing === value2) return false;
|
|
31798
|
-
await
|
|
31799
|
-
const temporary =
|
|
31886
|
+
await fs21.mkdir(path27.dirname(filePath), { recursive: true, mode: 448 });
|
|
31887
|
+
const temporary = path27.join(path27.dirname(filePath), `.${path27.basename(filePath)}.${process.pid}.${crypto8.randomUUID()}.next`);
|
|
31800
31888
|
let handle;
|
|
31801
31889
|
try {
|
|
31802
|
-
handle = await
|
|
31890
|
+
handle = await fs21.open(temporary, "wx", 384);
|
|
31803
31891
|
await handle.writeFile(value2, "utf8");
|
|
31804
31892
|
await handle.sync();
|
|
31805
31893
|
await handle.close();
|
|
31806
31894
|
handle = void 0;
|
|
31807
|
-
await
|
|
31808
|
-
if (process.platform !== "win32") await
|
|
31895
|
+
await fs21.rename(temporary, filePath);
|
|
31896
|
+
if (process.platform !== "win32") await fs21.chmod(filePath, 384);
|
|
31809
31897
|
return true;
|
|
31810
31898
|
} finally {
|
|
31811
31899
|
await handle?.close();
|
|
31812
|
-
await
|
|
31900
|
+
await fs21.rm(temporary, { force: true });
|
|
31813
31901
|
}
|
|
31814
31902
|
}
|
|
31815
31903
|
function xmlEscape(value2) {
|
|
@@ -31819,8 +31907,8 @@ function xmlEscape(value2) {
|
|
|
31819
31907
|
// packages/localapp/src/service/linux-systemd-user.ts
|
|
31820
31908
|
var UNIT_NAME = "localapp.service";
|
|
31821
31909
|
function createLinuxSystemdUserService(options2) {
|
|
31822
|
-
const configHome = options2.env?.XDG_CONFIG_HOME ??
|
|
31823
|
-
const registrationPath =
|
|
31910
|
+
const configHome = options2.env?.XDG_CONFIG_HOME ?? path28.join(options2.homeDir, ".config");
|
|
31911
|
+
const registrationPath = path28.join(configHome, "systemd", "user", UNIT_NAME);
|
|
31824
31912
|
const unit = buildUnit(options2);
|
|
31825
31913
|
const systemctl = options2.env?.SYSTEMCTL_PATH ?? "systemctl";
|
|
31826
31914
|
return {
|
|
@@ -31858,7 +31946,7 @@ function createLinuxSystemdUserService(options2) {
|
|
|
31858
31946
|
if (disabled.code !== 0 && !isMissingUnit(disabled.stderr)) {
|
|
31859
31947
|
throw lifecycleError("user_service_command_failed", "The systemd user service could not be removed");
|
|
31860
31948
|
}
|
|
31861
|
-
await
|
|
31949
|
+
await fs22.rm(registrationPath, { force: true });
|
|
31862
31950
|
await runServiceCommand(options2.run, { command: systemctl, args: ["--user", "daemon-reload"] });
|
|
31863
31951
|
}
|
|
31864
31952
|
};
|
|
@@ -31894,15 +31982,15 @@ function systemdQuote(value2) {
|
|
|
31894
31982
|
|
|
31895
31983
|
// packages/localapp/src/service/macos-launch-agent.ts
|
|
31896
31984
|
import crypto9 from "node:crypto";
|
|
31897
|
-
import
|
|
31898
|
-
import
|
|
31985
|
+
import fs23 from "node:fs/promises";
|
|
31986
|
+
import path29 from "node:path";
|
|
31899
31987
|
var LABEL = "com.localapp.daemon";
|
|
31900
31988
|
function createMacosLaunchAgent(options2) {
|
|
31901
31989
|
const uid = options2.uid ?? (typeof process.getuid === "function" ? process.getuid() : void 0);
|
|
31902
31990
|
if (!Number.isSafeInteger(uid) || (uid ?? -1) < 0) {
|
|
31903
31991
|
throw lifecycleError("user_service_configuration_invalid", "The current macOS user identity is unavailable");
|
|
31904
31992
|
}
|
|
31905
|
-
const registrationPath =
|
|
31993
|
+
const registrationPath = path29.join(options2.homeDir, "Library", "LaunchAgents", `${LABEL}.plist`);
|
|
31906
31994
|
const domain = `gui/${uid}`;
|
|
31907
31995
|
const target = `${domain}/${LABEL}`;
|
|
31908
31996
|
const plist = buildPlist(options2);
|
|
@@ -31912,7 +32000,7 @@ function createMacosLaunchAgent(options2) {
|
|
|
31912
32000
|
registrationPath,
|
|
31913
32001
|
async install() {
|
|
31914
32002
|
const installed = await writeServiceFile(registrationPath, plist);
|
|
31915
|
-
const receipt = await
|
|
32003
|
+
const receipt = await fs23.readFile(receiptPath, "utf8").then((value2) => value2.trim(), () => void 0);
|
|
31916
32004
|
const loaded = await options2.run({ command: "/bin/launchctl", args: ["print", target] });
|
|
31917
32005
|
if (loaded.code === 0 && receipt === plistDigest) return { mode: "service", installed };
|
|
31918
32006
|
if (loaded.code !== 0 && !isMissingService(loaded.stderr)) {
|
|
@@ -31956,8 +32044,8 @@ function createMacosLaunchAgent(options2) {
|
|
|
31956
32044
|
if (result.code !== 0 && !/could not find service|no such process/i.test(result.stderr)) {
|
|
31957
32045
|
throw lifecycleError("user_service_command_failed", "The macOS LaunchAgent could not be removed");
|
|
31958
32046
|
}
|
|
31959
|
-
await
|
|
31960
|
-
await
|
|
32047
|
+
await fs23.rm(registrationPath, { force: true });
|
|
32048
|
+
await fs23.rm(receiptPath, { force: true });
|
|
31961
32049
|
}
|
|
31962
32050
|
};
|
|
31963
32051
|
}
|
|
@@ -31994,13 +32082,13 @@ ${environment}
|
|
|
31994
32082
|
}
|
|
31995
32083
|
|
|
31996
32084
|
// packages/localapp/src/service/windows-user-task.ts
|
|
31997
|
-
import
|
|
31998
|
-
import
|
|
32085
|
+
import fs24 from "node:fs/promises";
|
|
32086
|
+
import path30 from "node:path";
|
|
31999
32087
|
var TASK_NAME = "LocalApp User Daemon";
|
|
32000
32088
|
function createWindowsUserTask(options2) {
|
|
32001
|
-
const registrationPath =
|
|
32089
|
+
const registrationPath = path30.join(options2.layout.supportDir, "service", "windows-user-task.json");
|
|
32002
32090
|
const systemRoot = options2.env?.SystemRoot ?? options2.env?.SYSTEMROOT ?? "C:\\Windows";
|
|
32003
|
-
const scheduler =
|
|
32091
|
+
const scheduler = path30.win32.join(systemRoot, "System32", "schtasks.exe");
|
|
32004
32092
|
const taskCommand = `${quoteWindowsArgument(options2.nodePath)} ${quoteWindowsArgument(options2.layout.launcherPath)}`;
|
|
32005
32093
|
const metadata = `${JSON.stringify({
|
|
32006
32094
|
schemaVersion: 1,
|
|
@@ -32013,9 +32101,9 @@ function createWindowsUserTask(options2) {
|
|
|
32013
32101
|
registrationPath,
|
|
32014
32102
|
async install() {
|
|
32015
32103
|
const installed = await writeServiceFile(registrationPath, metadata);
|
|
32016
|
-
const definitionPath =
|
|
32017
|
-
await
|
|
32018
|
-
await
|
|
32104
|
+
const definitionPath = path30.join(path30.dirname(registrationPath), "windows-user-task.xml");
|
|
32105
|
+
await fs24.mkdir(path30.dirname(definitionPath), { recursive: true });
|
|
32106
|
+
await fs24.writeFile(definitionPath, taskDefinition(options2.nodePath, options2.layout.launcherPath));
|
|
32019
32107
|
await runServiceCommand(options2.run, {
|
|
32020
32108
|
command: scheduler,
|
|
32021
32109
|
args: ["/Create", "/TN", TASK_NAME, "/XML", definitionPath, "/F"]
|
|
@@ -32048,7 +32136,7 @@ function createWindowsUserTask(options2) {
|
|
|
32048
32136
|
if (result.code !== 0 && !/cannot find|does not exist/i.test(result.stderr)) {
|
|
32049
32137
|
throw lifecycleError("user_service_command_failed", "The Windows user task could not be removed");
|
|
32050
32138
|
}
|
|
32051
|
-
await
|
|
32139
|
+
await fs24.rm(registrationPath, { force: true });
|
|
32052
32140
|
}
|
|
32053
32141
|
};
|
|
32054
32142
|
}
|
|
@@ -32197,7 +32285,7 @@ function withLogs(manager, layout) {
|
|
|
32197
32285
|
if (!Number.isSafeInteger(lines) || lines < 1 || lines > 1e4) {
|
|
32198
32286
|
throw lifecycleError("user_service_logs_invalid", "The requested log line count is invalid");
|
|
32199
32287
|
}
|
|
32200
|
-
const handle = await
|
|
32288
|
+
const handle = await fs25.open(layout.daemonLogPath, "r").catch((error) => {
|
|
32201
32289
|
if (error.code === "ENOENT") return void 0;
|
|
32202
32290
|
throw error;
|
|
32203
32291
|
});
|
|
@@ -32220,6 +32308,7 @@ ${tail}` : tail;
|
|
|
32220
32308
|
}
|
|
32221
32309
|
|
|
32222
32310
|
// packages/localapp/src/commands/server.ts
|
|
32311
|
+
var DEFAULT_FOREGROUND_PORT = 50524;
|
|
32223
32312
|
async function runServerCommand(options2, dependencies = {}) {
|
|
32224
32313
|
const layout = dependencies.layout ?? runtimeLayoutFromEnvironment();
|
|
32225
32314
|
const ipc = dependencies.ipcClient ?? (() => createIpcClient({ endpoint: layout.controlEndpoint }));
|
|
@@ -32229,7 +32318,7 @@ async function runServerCommand(options2, dependencies = {}) {
|
|
|
32229
32318
|
const artifactDirectory = dependencies.artifactDirectory ?? defaultArtifactDirectory();
|
|
32230
32319
|
await (dependencies.verifyReleaseArtifact ?? verifyReleaseArtifact)(artifactDirectory);
|
|
32231
32320
|
const release = await (dependencies.publishRelease ?? publishRelease)({ sourceDirectory: artifactDirectory, layout });
|
|
32232
|
-
const native = await (dependencies.createNativeAdapter ?? createNativeAdapter)(
|
|
32321
|
+
const native = await (dependencies.createNativeAdapter ?? createNativeAdapter)(path31.join(release.releasePath, "runtime", "native"), { supportDir: layout.supportDir });
|
|
32233
32322
|
await native.installScheme();
|
|
32234
32323
|
const manager = service();
|
|
32235
32324
|
const installed = await manager.install();
|
|
@@ -32269,7 +32358,7 @@ async function runServerForeground(options2, dependencies = {}) {
|
|
|
32269
32358
|
const artifact = dependencies.artifactDirectory ?? defaultArtifactDirectory();
|
|
32270
32359
|
const manifest = await verifyReleaseArtifact(artifact);
|
|
32271
32360
|
if (typeof manifest.serverEntrypoint !== "string") throw lifecycleError("canonical_server_unavailable", "The packed canonical LocalApp Server runtime is unavailable");
|
|
32272
|
-
const entrypoint =
|
|
32361
|
+
const entrypoint = path31.join(artifact, ...manifest.serverEntrypoint.split("/"));
|
|
32273
32362
|
const child = (dependencies.spawnOwnedProcess ?? spawnOwnedProcess)(process.execPath, [
|
|
32274
32363
|
entrypoint,
|
|
32275
32364
|
"start",
|
|
@@ -32278,7 +32367,7 @@ async function runServerForeground(options2, dependencies = {}) {
|
|
|
32278
32367
|
"--host",
|
|
32279
32368
|
options2.host ?? "127.0.0.1",
|
|
32280
32369
|
"--port",
|
|
32281
|
-
String(options2.port ??
|
|
32370
|
+
String(options2.port ?? DEFAULT_FOREGROUND_PORT)
|
|
32282
32371
|
], { stdio: "inherit" });
|
|
32283
32372
|
return await new Promise((resolve2, reject) => {
|
|
32284
32373
|
let termination;
|
|
@@ -32337,7 +32426,7 @@ async function readyStatus(ipc, health) {
|
|
|
32337
32426
|
async function waitForStopped(layout, ipc) {
|
|
32338
32427
|
const deadline = Date.now() + 15e3;
|
|
32339
32428
|
while (Date.now() < deadline) {
|
|
32340
|
-
const lockMissing = await
|
|
32429
|
+
const lockMissing = await fs26.lstat(layout.lockPath).then(() => false, (error) => error.code === "ENOENT");
|
|
32341
32430
|
try {
|
|
32342
32431
|
await ipc.request({ type: "status" });
|
|
32343
32432
|
} catch (error) {
|
|
@@ -32396,7 +32485,7 @@ function publicRelease(release) {
|
|
|
32396
32485
|
}
|
|
32397
32486
|
async function removeTransientRuntimeFiles(layout) {
|
|
32398
32487
|
await Promise.all([layout.lockPath, layout.controlEndpoint].map(async (target) => {
|
|
32399
|
-
const stat2 = await
|
|
32488
|
+
const stat2 = await fs26.lstat(target).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
32400
32489
|
if (stat2 !== void 0) throw lifecycleError("daemon_ownership_unproven", "LocalApp refuses to remove an unproven daemon ownership artifact");
|
|
32401
32490
|
}));
|
|
32402
32491
|
}
|
|
@@ -32406,8 +32495,8 @@ function delay2(ms) {
|
|
|
32406
32495
|
|
|
32407
32496
|
// packages/localapp/src/daemon/daemon.ts
|
|
32408
32497
|
import crypto11 from "node:crypto";
|
|
32409
|
-
import
|
|
32410
|
-
import
|
|
32498
|
+
import fs29 from "node:fs/promises";
|
|
32499
|
+
import path34 from "node:path";
|
|
32411
32500
|
|
|
32412
32501
|
// packages/localapp/src/activation/activation-broker.ts
|
|
32413
32502
|
var DEVICE_ACTION_STATUSES = /* @__PURE__ */ new Set([
|
|
@@ -32516,8 +32605,8 @@ function recordWithExactKeys(value2, keys) {
|
|
|
32516
32605
|
import crypto10 from "node:crypto";
|
|
32517
32606
|
import { execFile } from "node:child_process";
|
|
32518
32607
|
import { constants as constants4 } from "node:fs";
|
|
32519
|
-
import
|
|
32520
|
-
import
|
|
32608
|
+
import fs27 from "node:fs/promises";
|
|
32609
|
+
import path32 from "node:path";
|
|
32521
32610
|
import { promisify } from "node:util";
|
|
32522
32611
|
var EMPTY_STATE = { version: 1, sources: [] };
|
|
32523
32612
|
var SOURCE_ID = /^[A-Za-z0-9](?:[A-Za-z0-9_-]{0,127})$/;
|
|
@@ -32541,7 +32630,7 @@ var DeliveryStore = class {
|
|
|
32541
32630
|
tail = Promise.resolve();
|
|
32542
32631
|
poisoned = false;
|
|
32543
32632
|
constructor(options2) {
|
|
32544
|
-
this.statePath =
|
|
32633
|
+
this.statePath = path32.resolve(options2.statePath);
|
|
32545
32634
|
this.now = options2.now ?? (() => /* @__PURE__ */ new Date());
|
|
32546
32635
|
this.randomBytes = options2.randomBytes ?? crypto10.randomBytes;
|
|
32547
32636
|
this.fault = options2.fault;
|
|
@@ -32574,7 +32663,7 @@ var DeliveryStore = class {
|
|
|
32574
32663
|
return snapshot(source);
|
|
32575
32664
|
});
|
|
32576
32665
|
}
|
|
32577
|
-
async preparePending(sourceId, value2, expiresAt, sourceLabel = sourceId, iconPath =
|
|
32666
|
+
async preparePending(sourceId, value2, expiresAt, sourceLabel = sourceId, iconPath = path32.resolve(process.cwd(), "localapp-notification.png")) {
|
|
32578
32667
|
return this.mutate((state) => {
|
|
32579
32668
|
const source = requiredSource(state, sourceId);
|
|
32580
32669
|
const delivery = validateDelivery(value2);
|
|
@@ -32717,9 +32806,9 @@ var DeliveryStore = class {
|
|
|
32717
32806
|
});
|
|
32718
32807
|
}
|
|
32719
32808
|
async withFileLock(operation) {
|
|
32720
|
-
const parent =
|
|
32809
|
+
const parent = path32.dirname(this.statePath);
|
|
32721
32810
|
await ensurePrivateParent(parent);
|
|
32722
|
-
const lockPath =
|
|
32811
|
+
const lockPath = path32.join(parent, `.${path32.basename(this.statePath)}.lock`);
|
|
32723
32812
|
const deadline = Date.now() + this.lockTimeoutMs;
|
|
32724
32813
|
let lock;
|
|
32725
32814
|
while (lock === void 0) {
|
|
@@ -32730,7 +32819,7 @@ var DeliveryStore = class {
|
|
|
32730
32819
|
await new Promise((resolve2) => setTimeout(resolve2, 10));
|
|
32731
32820
|
}
|
|
32732
32821
|
try {
|
|
32733
|
-
await removeOwnedStaleTemps(parent,
|
|
32822
|
+
await removeOwnedStaleTemps(parent, path32.basename(this.statePath));
|
|
32734
32823
|
return await operation();
|
|
32735
32824
|
} finally {
|
|
32736
32825
|
await lock.handle.close().catch(() => void 0);
|
|
@@ -32746,12 +32835,12 @@ var DeliveryStore = class {
|
|
|
32746
32835
|
return run;
|
|
32747
32836
|
}
|
|
32748
32837
|
async read() {
|
|
32749
|
-
await ensurePrivateParent(
|
|
32838
|
+
await ensurePrivateParent(path32.dirname(this.statePath));
|
|
32750
32839
|
let handle;
|
|
32751
32840
|
try {
|
|
32752
|
-
const before = await
|
|
32841
|
+
const before = await fs27.lstat(this.statePath, { bigint: true });
|
|
32753
32842
|
assertPrivateRegular(before, "Notification delivery state");
|
|
32754
|
-
handle = await
|
|
32843
|
+
handle = await fs27.open(this.statePath, process.platform === "win32" ? "r" : constants4.O_RDONLY | constants4.O_NOFOLLOW);
|
|
32755
32844
|
const opened = await handle.stat({ bigint: true });
|
|
32756
32845
|
assertPrivateRegular(opened, "Notification delivery state");
|
|
32757
32846
|
if (!sameIdentity(before, opened)) throw unsafe("Notification delivery state identity changed");
|
|
@@ -32768,11 +32857,11 @@ var DeliveryStore = class {
|
|
|
32768
32857
|
}
|
|
32769
32858
|
}
|
|
32770
32859
|
async publish(state) {
|
|
32771
|
-
const parent =
|
|
32860
|
+
const parent = path32.dirname(this.statePath);
|
|
32772
32861
|
const parentBefore = await privateDirectoryIdentity(parent);
|
|
32773
|
-
const parentHandle = await
|
|
32862
|
+
const parentHandle = await fs27.open(parent, "r");
|
|
32774
32863
|
let existing;
|
|
32775
|
-
const temporary =
|
|
32864
|
+
const temporary = path32.join(parent, `.${path32.basename(this.statePath)}.${process.pid}.${this.token(12)}.tmp`);
|
|
32776
32865
|
let handle;
|
|
32777
32866
|
let tempIdentity;
|
|
32778
32867
|
let renamed = false;
|
|
@@ -32782,10 +32871,10 @@ var DeliveryStore = class {
|
|
|
32782
32871
|
const content = Buffer.from(`${JSON.stringify(state)}
|
|
32783
32872
|
`);
|
|
32784
32873
|
if (content.byteLength > MAX_STATE_BYTES) throw new Error("Notification delivery state is too large");
|
|
32785
|
-
handle = await
|
|
32874
|
+
handle = await fs27.open(temporary, "wx", 384);
|
|
32786
32875
|
const created = await handle.stat({ bigint: true });
|
|
32787
32876
|
assertPrivateRegular(created, "Notification delivery temporary file");
|
|
32788
|
-
tempIdentity = await
|
|
32877
|
+
tempIdentity = await fs27.lstat(temporary, { bigint: true });
|
|
32789
32878
|
if (!sameIdentity(created, tempIdentity)) throw unsafe("Notification delivery temporary identity changed");
|
|
32790
32879
|
await handle.writeFile(content);
|
|
32791
32880
|
await handle.sync();
|
|
@@ -32799,7 +32888,7 @@ var DeliveryStore = class {
|
|
|
32799
32888
|
if (!optionalSameIdentity(existing, current)) throw unsafe("Notification delivery state was replaced");
|
|
32800
32889
|
await this.fault?.("before-rename");
|
|
32801
32890
|
try {
|
|
32802
|
-
await renameInPinnedParent(parent,
|
|
32891
|
+
await renameInPinnedParent(parent, path32.basename(temporary), path32.basename(this.statePath), parentBefore, tempIdentity);
|
|
32803
32892
|
renamed = true;
|
|
32804
32893
|
} catch (error) {
|
|
32805
32894
|
if (error instanceof PinnedRenamePreconditionError) throw error;
|
|
@@ -32818,7 +32907,7 @@ var DeliveryStore = class {
|
|
|
32818
32907
|
await handle?.close().catch(() => void 0);
|
|
32819
32908
|
if (!renamed && tempIdentity !== void 0) {
|
|
32820
32909
|
const current = await optionalLstat(temporary);
|
|
32821
|
-
if (current !== void 0 && sameIdentity(tempIdentity, current)) await
|
|
32910
|
+
if (current !== void 0 && sameIdentity(tempIdentity, current)) await fs27.rm(temporary, { force: true }).catch(() => void 0);
|
|
32822
32911
|
}
|
|
32823
32912
|
throw error;
|
|
32824
32913
|
} finally {
|
|
@@ -32944,7 +33033,7 @@ function validateDisplaySourceLabel(value2) {
|
|
|
32944
33033
|
return value2;
|
|
32945
33034
|
}
|
|
32946
33035
|
function validateIconPath(value2) {
|
|
32947
|
-
if (typeof value2 !== "string" || value2.length > 2048 || !
|
|
33036
|
+
if (typeof value2 !== "string" || value2.length > 2048 || !path32.isAbsolute(value2) || path32.resolve(value2) !== value2 || /[\u0000-\u001f\u007f]/.test(value2)) throw new Error("Notification icon path is invalid");
|
|
32948
33037
|
return value2;
|
|
32949
33038
|
}
|
|
32950
33039
|
function validateSourceId(value2) {
|
|
@@ -33006,18 +33095,18 @@ async function ensurePrivateParent(directory) {
|
|
|
33006
33095
|
await assertNoSymlinkAncestors(directory, true);
|
|
33007
33096
|
const existing = await optionalLstat(directory);
|
|
33008
33097
|
if (existing === void 0) {
|
|
33009
|
-
await
|
|
33010
|
-
if (process.platform !== "win32") await
|
|
33098
|
+
await fs27.mkdir(directory, { recursive: true, mode: 448 });
|
|
33099
|
+
if (process.platform !== "win32") await fs27.chmod(directory, 448);
|
|
33011
33100
|
}
|
|
33012
33101
|
await assertNoSymlinkAncestors(directory, false);
|
|
33013
33102
|
await privateDirectoryIdentity(directory);
|
|
33014
33103
|
}
|
|
33015
33104
|
async function assertNoSymlinkAncestors(target, allowMissingTail) {
|
|
33016
|
-
const absolute =
|
|
33017
|
-
const parsed =
|
|
33105
|
+
const absolute = path32.resolve(target);
|
|
33106
|
+
const parsed = path32.parse(absolute);
|
|
33018
33107
|
let current = parsed.root;
|
|
33019
|
-
for (const segment of absolute.slice(parsed.root.length).split(
|
|
33020
|
-
current =
|
|
33108
|
+
for (const segment of absolute.slice(parsed.root.length).split(path32.sep).filter(Boolean)) {
|
|
33109
|
+
current = path32.join(current, segment);
|
|
33021
33110
|
const stat2 = await optionalLstat(current);
|
|
33022
33111
|
if (stat2 === void 0) {
|
|
33023
33112
|
if (allowMissingTail) return;
|
|
@@ -33027,7 +33116,7 @@ async function assertNoSymlinkAncestors(target, allowMissingTail) {
|
|
|
33027
33116
|
}
|
|
33028
33117
|
}
|
|
33029
33118
|
async function privateDirectoryIdentity(directory) {
|
|
33030
|
-
const stat2 = await
|
|
33119
|
+
const stat2 = await fs27.lstat(directory, { bigint: true });
|
|
33031
33120
|
if (!stat2.isDirectory() || stat2.isSymbolicLink() || stat2.nlink < 1n) throw unsafe("Notification delivery parent path is unsafe");
|
|
33032
33121
|
if (process.platform !== "win32" && ((BigInt(stat2.mode) & 0o777n) !== 0o700n || BigInt(stat2.uid) !== BigInt(process.getuid?.() ?? Number(stat2.uid)))) throw unsafe("Notification delivery parent permissions are unsafe");
|
|
33033
33122
|
return stat2;
|
|
@@ -33044,7 +33133,7 @@ function optionalSameIdentity(a, b) {
|
|
|
33044
33133
|
}
|
|
33045
33134
|
async function optionalLstat(target) {
|
|
33046
33135
|
try {
|
|
33047
|
-
return await
|
|
33136
|
+
return await fs27.lstat(target, { bigint: true });
|
|
33048
33137
|
} catch (error) {
|
|
33049
33138
|
if (isCode(error, "ENOENT")) return void 0;
|
|
33050
33139
|
throw error;
|
|
@@ -33081,16 +33170,16 @@ async function renameInPinnedParent(parent, source, destination, identity, sourc
|
|
|
33081
33170
|
}
|
|
33082
33171
|
async function removeOwnedStaleTemps(parent, basename2) {
|
|
33083
33172
|
const prefix = `.${basename2}.`;
|
|
33084
|
-
const names = (await
|
|
33173
|
+
const names = (await fs27.readdir(parent)).filter((name) => name.startsWith(prefix) && name.endsWith(".tmp"));
|
|
33085
33174
|
if (names.length === 0) return;
|
|
33086
33175
|
for (const name of names) {
|
|
33087
|
-
const target =
|
|
33088
|
-
const stat2 = await
|
|
33176
|
+
const target = path32.join(parent, name);
|
|
33177
|
+
const stat2 = await fs27.lstat(target, { bigint: true });
|
|
33089
33178
|
assertPrivateRegular(stat2, "Notification delivery stale temporary file");
|
|
33090
33179
|
await unlinkOwned(target, { dev: BigInt(stat2.dev), ino: BigInt(stat2.ino) });
|
|
33091
33180
|
}
|
|
33092
33181
|
if (process.platform !== "win32") {
|
|
33093
|
-
const directory = await
|
|
33182
|
+
const directory = await fs27.open(parent, "r");
|
|
33094
33183
|
try {
|
|
33095
33184
|
await directory.sync();
|
|
33096
33185
|
} finally {
|
|
@@ -33182,12 +33271,12 @@ function strictJsonParse(input) {
|
|
|
33182
33271
|
return result;
|
|
33183
33272
|
}
|
|
33184
33273
|
async function tryAcquireLock(lockPath) {
|
|
33185
|
-
const temporary =
|
|
33274
|
+
const temporary = path32.join(path32.dirname(lockPath), `.${path32.basename(lockPath)}.${process.pid}.${crypto10.randomUUID()}.next`);
|
|
33186
33275
|
let handle;
|
|
33187
33276
|
let identity;
|
|
33188
33277
|
let linked = false;
|
|
33189
33278
|
try {
|
|
33190
|
-
handle = await
|
|
33279
|
+
handle = await fs27.open(temporary, "wx", 384);
|
|
33191
33280
|
const opened = await handle.stat({ bigint: true });
|
|
33192
33281
|
assertPrivateRegular(opened, "Notification delivery lock");
|
|
33193
33282
|
identity = { dev: opened.dev, ino: opened.ino };
|
|
@@ -33195,13 +33284,13 @@ async function tryAcquireLock(lockPath) {
|
|
|
33195
33284
|
`);
|
|
33196
33285
|
await handle.sync();
|
|
33197
33286
|
try {
|
|
33198
|
-
await
|
|
33287
|
+
await fs27.link(temporary, lockPath);
|
|
33199
33288
|
} catch (error) {
|
|
33200
33289
|
if (isCode(error, "EEXIST")) return void 0;
|
|
33201
33290
|
throw error;
|
|
33202
33291
|
}
|
|
33203
33292
|
linked = true;
|
|
33204
|
-
const visible = await
|
|
33293
|
+
const visible = await fs27.lstat(lockPath, { bigint: true });
|
|
33205
33294
|
if (!sameIdentity(opened, visible)) throw unsafe("Notification delivery lock identity changed");
|
|
33206
33295
|
if (!await unlinkOwned(temporary, identity)) throw unsafe("Notification delivery lock temporary identity changed");
|
|
33207
33296
|
return { handle, identity };
|
|
@@ -33212,7 +33301,7 @@ async function tryAcquireLock(lockPath) {
|
|
|
33212
33301
|
if (!linked) {
|
|
33213
33302
|
await handle?.close().catch(() => void 0);
|
|
33214
33303
|
if (identity !== void 0) await unlinkOwned(temporary, identity).catch(() => void 0);
|
|
33215
|
-
else await
|
|
33304
|
+
else await fs27.rm(temporary, { force: true }).catch(() => void 0);
|
|
33216
33305
|
}
|
|
33217
33306
|
}
|
|
33218
33307
|
}
|
|
@@ -33224,7 +33313,7 @@ async function reclaimDeadLock(lockPath) {
|
|
|
33224
33313
|
const linkedTemporary = visible.linkedTemporary;
|
|
33225
33314
|
let handle;
|
|
33226
33315
|
try {
|
|
33227
|
-
handle = await
|
|
33316
|
+
handle = await fs27.open(lockPath, process.platform === "win32" ? "r" : constants4.O_RDONLY | constants4.O_NOFOLLOW);
|
|
33228
33317
|
const opened = await handle.stat({ bigint: true });
|
|
33229
33318
|
if (!sameIdentity(before, opened)) return false;
|
|
33230
33319
|
const bytes = await handle.readFile();
|
|
@@ -33256,11 +33345,11 @@ async function validateVisibleLock(stat2, lockPath) {
|
|
|
33256
33345
|
throw unsafe("Notification delivery lock path is unsafe");
|
|
33257
33346
|
}
|
|
33258
33347
|
if (stat2.nlink === 1n) return { stable: true, linkedTemporary: void 0 };
|
|
33259
|
-
const prefix = `.${
|
|
33260
|
-
const candidates = (await
|
|
33348
|
+
const prefix = `.${path32.basename(lockPath)}.`;
|
|
33349
|
+
const candidates = (await fs27.readdir(path32.dirname(lockPath))).filter((name) => name.startsWith(prefix) && name.endsWith(".next"));
|
|
33261
33350
|
const same = [];
|
|
33262
33351
|
for (const name of candidates) {
|
|
33263
|
-
const candidate =
|
|
33352
|
+
const candidate = path32.join(path32.dirname(lockPath), name);
|
|
33264
33353
|
const metadata = await optionalLstat(candidate);
|
|
33265
33354
|
if (metadata !== void 0 && sameIdentity(stat2, metadata)) same.push(candidate);
|
|
33266
33355
|
}
|
|
@@ -33283,7 +33372,7 @@ function processExists2(pid) {
|
|
|
33283
33372
|
async function unlinkOwned(target, identity) {
|
|
33284
33373
|
const current = await optionalLstat(target);
|
|
33285
33374
|
if (current === void 0 || current.isSymbolicLink() || current.dev !== identity.dev || current.ino !== identity.ino) return false;
|
|
33286
|
-
await
|
|
33375
|
+
await fs27.unlink(target);
|
|
33287
33376
|
return true;
|
|
33288
33377
|
}
|
|
33289
33378
|
function unchanged(value2) {
|
|
@@ -33997,9 +34086,9 @@ function delay3(ms, signal) {
|
|
|
33997
34086
|
}
|
|
33998
34087
|
|
|
33999
34088
|
// packages/localapp/src/daemon/ipc-server.ts
|
|
34000
|
-
import
|
|
34089
|
+
import fs28 from "node:fs/promises";
|
|
34001
34090
|
import net3 from "node:net";
|
|
34002
|
-
import
|
|
34091
|
+
import path33 from "node:path";
|
|
34003
34092
|
var DEFAULT_TIMEOUT_MS2 = 5e3;
|
|
34004
34093
|
async function createIpcServer(options2) {
|
|
34005
34094
|
const platform = options2.platform ?? process.platform;
|
|
@@ -34020,7 +34109,7 @@ async function createIpcServer(options2) {
|
|
|
34020
34109
|
});
|
|
34021
34110
|
let identity;
|
|
34022
34111
|
if (platform !== "win32") {
|
|
34023
|
-
const stat2 = await
|
|
34112
|
+
const stat2 = await fs28.lstat(options2.endpoint, { bigint: true });
|
|
34024
34113
|
if (!stat2.isSocket() || stat2.isSymbolicLink()) {
|
|
34025
34114
|
await closeNetServer(server);
|
|
34026
34115
|
throw lifecycleError("ipc_path_unsafe", "The LocalApp control endpoint is not a socket");
|
|
@@ -34100,15 +34189,15 @@ function serveConnection(socket, handle, afterResponse, timeoutMs, platform) {
|
|
|
34100
34189
|
});
|
|
34101
34190
|
}
|
|
34102
34191
|
async function prepareUnixEndpoint(endpoint, reclaim) {
|
|
34103
|
-
const parent =
|
|
34104
|
-
const parentStat = await
|
|
34192
|
+
const parent = path33.dirname(endpoint);
|
|
34193
|
+
const parentStat = await fs28.lstat(parent).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
34105
34194
|
if (parentStat === void 0 || !parentStat.isDirectory() || parentStat.isSymbolicLink() || (Number(parentStat.mode) & 63) !== 0) throw lifecycleError("ipc_path_unsafe", "The LocalApp control directory is not private");
|
|
34106
|
-
const existing = await
|
|
34195
|
+
const existing = await fs28.lstat(endpoint, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
34107
34196
|
if (existing === void 0) return;
|
|
34108
34197
|
if (!existing.isSocket() || existing.isSymbolicLink() || reclaim === void 0 || !await reclaim()) throw lifecycleError("ipc_path_unsafe", "The LocalApp control endpoint already exists");
|
|
34109
|
-
const current = await
|
|
34198
|
+
const current = await fs28.lstat(endpoint, { bigint: true });
|
|
34110
34199
|
if (!current.isSocket() || current.isSymbolicLink() || current.dev !== existing.dev || current.ino !== existing.ino) throw lifecycleError("ipc_path_unsafe", "The LocalApp control endpoint changed during stale cleanup");
|
|
34111
|
-
await
|
|
34200
|
+
await fs28.unlink(endpoint);
|
|
34112
34201
|
}
|
|
34113
34202
|
async function closeNetServer(server) {
|
|
34114
34203
|
await new Promise((resolve2) => server.close(() => resolve2()));
|
|
@@ -34117,8 +34206,8 @@ async function closeServer(server, sockets, endpoint, identity, timeoutMs) {
|
|
|
34117
34206
|
for (const socket of sockets) socket.destroy();
|
|
34118
34207
|
await Promise.race([closeNetServer(server), new Promise((resolve2) => setTimeout(resolve2, timeoutMs))]);
|
|
34119
34208
|
if (identity === void 0) return;
|
|
34120
|
-
const current = await
|
|
34121
|
-
if (current !== void 0 && current.isSocket() && !current.isSymbolicLink() && current.dev === identity.dev && current.ino === identity.ino) await
|
|
34209
|
+
const current = await fs28.lstat(endpoint, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
34210
|
+
if (current !== void 0 && current.isSocket() && !current.isSymbolicLink() && current.dev === identity.dev && current.ino === identity.ino) await fs28.unlink(endpoint);
|
|
34122
34211
|
}
|
|
34123
34212
|
|
|
34124
34213
|
// packages/localapp/src/daemon/daemon.ts
|
|
@@ -34137,7 +34226,7 @@ async function acquireDaemonLock(options2) {
|
|
|
34137
34226
|
let reclaimed = false;
|
|
34138
34227
|
while (true) {
|
|
34139
34228
|
try {
|
|
34140
|
-
const handle = await
|
|
34229
|
+
const handle = await fs29.open(options2.layout.lockPath, "wx", 384);
|
|
34141
34230
|
try {
|
|
34142
34231
|
await handle.writeFile(`${JSON.stringify(record6)}
|
|
34143
34232
|
`);
|
|
@@ -34154,7 +34243,7 @@ async function acquireDaemonLock(options2) {
|
|
|
34154
34243
|
} };
|
|
34155
34244
|
} catch (error) {
|
|
34156
34245
|
await handle.close().catch(() => void 0);
|
|
34157
|
-
await
|
|
34246
|
+
await fs29.unlink(options2.layout.lockPath).catch(() => void 0);
|
|
34158
34247
|
throw error;
|
|
34159
34248
|
}
|
|
34160
34249
|
} catch (error) {
|
|
@@ -34291,7 +34380,7 @@ var LocalAppDaemon = class {
|
|
|
34291
34380
|
const current = await readCurrentRelease(this.options.layout);
|
|
34292
34381
|
const manifest = await verifyReleaseArtifact(current.releasePath);
|
|
34293
34382
|
if (typeof manifest.serverEntrypoint !== "string") throw lifecycleError("canonical_server_unavailable", "The packed canonical LocalApp Server runtime is unavailable");
|
|
34294
|
-
const entrypoint =
|
|
34383
|
+
const entrypoint = path34.join(current.releasePath, ...manifest.serverEntrypoint.split("/"));
|
|
34295
34384
|
const spawn8 = this.options.spawnOwnedProcess ?? spawnOwnedProcess;
|
|
34296
34385
|
const server = spawn8(process.execPath, [entrypoint, "start", "--data-dir", this.options.layout.dataDir, "--host", "127.0.0.1", "--port", "0"], {
|
|
34297
34386
|
cwd: current.releasePath,
|
|
@@ -34361,12 +34450,12 @@ var LocalAppDaemon = class {
|
|
|
34361
34450
|
if (failure !== void 0) throw failure;
|
|
34362
34451
|
}
|
|
34363
34452
|
async createDefaultNotificationRuntime(options2) {
|
|
34364
|
-
const store = new DeliveryStore({ statePath:
|
|
34365
|
-
const native = await createNativeAdapter(
|
|
34453
|
+
const store = new DeliveryStore({ statePath: path34.join(this.options.layout.supportDir, "notifications", "delivery-state.json") });
|
|
34454
|
+
const native = await createNativeAdapter(path34.join(options2.releasePath, "runtime", "native"), { supportDir: this.options.layout.supportDir });
|
|
34366
34455
|
const dispatcher = new NotificationDispatcher({
|
|
34367
34456
|
store,
|
|
34368
34457
|
adapter: native,
|
|
34369
|
-
iconPath:
|
|
34458
|
+
iconPath: path34.join(options2.releasePath, "runtime", "server", "web", "home", "redline-launch-hero.png")
|
|
34370
34459
|
});
|
|
34371
34460
|
const manager = new NotificationConnectionManager({
|
|
34372
34461
|
localServerOrigin: options2.listenUrl,
|
|
@@ -34456,17 +34545,17 @@ async function verifyHealth2(listenUrl, timeoutMs) {
|
|
|
34456
34545
|
}
|
|
34457
34546
|
}
|
|
34458
34547
|
async function readLock(lockPath) {
|
|
34459
|
-
const before = await
|
|
34548
|
+
const before = await fs29.lstat(lockPath, { bigint: true });
|
|
34460
34549
|
if (!before.isFile() || before.isSymbolicLink() || process.platform !== "win32" && (Number(before.mode) & 63) !== 0) {
|
|
34461
34550
|
throw lifecycleError("daemon_lock_invalid", "The LocalApp daemon lock is unsafe");
|
|
34462
34551
|
}
|
|
34463
34552
|
let value2;
|
|
34464
34553
|
try {
|
|
34465
|
-
value2 = JSON.parse(await
|
|
34554
|
+
value2 = JSON.parse(await fs29.readFile(lockPath, "utf8"));
|
|
34466
34555
|
} catch {
|
|
34467
34556
|
throw lifecycleError("daemon_lock_invalid", "The LocalApp daemon lock is malformed");
|
|
34468
34557
|
}
|
|
34469
|
-
const after = await
|
|
34558
|
+
const after = await fs29.lstat(lockPath, { bigint: true });
|
|
34470
34559
|
if (!after.isFile() || after.isSymbolicLink() || after.dev !== before.dev || after.ino !== before.ino) {
|
|
34471
34560
|
throw lifecycleError("daemon_lock_invalid", "The LocalApp daemon lock changed while reading");
|
|
34472
34561
|
}
|
|
@@ -34497,20 +34586,20 @@ async function probeEndpoint(endpoint, bootId) {
|
|
|
34497
34586
|
}
|
|
34498
34587
|
}
|
|
34499
34588
|
async function ensurePrivateRuntimeDirectory(directory) {
|
|
34500
|
-
await
|
|
34501
|
-
const stat2 = await
|
|
34589
|
+
await fs29.mkdir(directory, { recursive: true, mode: 448 });
|
|
34590
|
+
const stat2 = await fs29.lstat(directory);
|
|
34502
34591
|
if (!stat2.isDirectory() || stat2.isSymbolicLink() || process.platform !== "win32" && (stat2.mode & 63) !== 0) {
|
|
34503
34592
|
throw lifecycleError("daemon_lock_invalid", "The LocalApp runtime directory is unsafe");
|
|
34504
34593
|
}
|
|
34505
34594
|
}
|
|
34506
34595
|
async function unlinkOwned2(filePath, identity) {
|
|
34507
|
-
const current = await
|
|
34596
|
+
const current = await fs29.lstat(filePath, { bigint: true }).catch((error) => error.code === "ENOENT" ? void 0 : Promise.reject(error));
|
|
34508
34597
|
if (current === void 0 || !current.isFile() || current.isSymbolicLink() || current.dev !== identity.dev || current.ino !== identity.ino) return false;
|
|
34509
|
-
await
|
|
34598
|
+
await fs29.unlink(filePath);
|
|
34510
34599
|
return true;
|
|
34511
34600
|
}
|
|
34512
34601
|
function digestDataRoot(dataDir) {
|
|
34513
|
-
return crypto11.createHash("sha256").update(
|
|
34602
|
+
return crypto11.createHash("sha256").update(path34.resolve(dataDir)).digest("hex");
|
|
34514
34603
|
}
|
|
34515
34604
|
async function withCleanupTimeout(operation, timeoutMs) {
|
|
34516
34605
|
let timer;
|
|
@@ -34574,8 +34663,8 @@ async function verifyWindowsRuntimeOwnership(layout) {
|
|
|
34574
34663
|
}
|
|
34575
34664
|
|
|
34576
34665
|
// packages/localapp/src/main.ts
|
|
34577
|
-
import
|
|
34578
|
-
import
|
|
34666
|
+
import path35 from "node:path";
|
|
34667
|
+
import fs30 from "node:fs";
|
|
34579
34668
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
34580
34669
|
async function runLocalApp(argv, io = defaultCliIo()) {
|
|
34581
34670
|
try {
|
|
@@ -34592,7 +34681,7 @@ async function runLocalApp(argv, io = defaultCliIo()) {
|
|
|
34592
34681
|
} else if (command.kind === "whoami") {
|
|
34593
34682
|
return whoami(command, io);
|
|
34594
34683
|
} else if (command.kind === "init") {
|
|
34595
|
-
const name = command.name ??
|
|
34684
|
+
const name = command.name ?? path35.basename(process.cwd());
|
|
34596
34685
|
await initializeProject({ cwd: process.cwd(), name, skipInstall: command.skipInstall, skipDeploy: command.skipDeploy, io });
|
|
34597
34686
|
} else if (command.kind === "sync-template") {
|
|
34598
34687
|
const result = await syncManagedTemplate(process.cwd(), command);
|
|
@@ -34679,9 +34768,9 @@ if (process.argv[1] !== void 0 && isMainModule(fileURLToPath5(import.meta.url),
|
|
|
34679
34768
|
}
|
|
34680
34769
|
function isMainModule(modulePath, invokedPath) {
|
|
34681
34770
|
try {
|
|
34682
|
-
return
|
|
34771
|
+
return fs30.realpathSync(modulePath) === fs30.realpathSync(invokedPath);
|
|
34683
34772
|
} catch {
|
|
34684
|
-
return
|
|
34773
|
+
return path35.resolve(modulePath) === path35.resolve(invokedPath);
|
|
34685
34774
|
}
|
|
34686
34775
|
}
|
|
34687
34776
|
export {
|