@youtyan/code-viewer 0.1.31 → 0.1.32
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/dist/code-viewer.js +31 -20
- package/package.json +1 -1
package/dist/code-viewer.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
readFileSync as readFileSync2,
|
|
12
12
|
realpathSync,
|
|
13
13
|
renameSync,
|
|
14
|
-
statSync,
|
|
14
|
+
statSync as statSync2,
|
|
15
15
|
unlinkSync,
|
|
16
16
|
watch,
|
|
17
17
|
writeFileSync
|
|
@@ -106,7 +106,8 @@ import {
|
|
|
106
106
|
existsSync,
|
|
107
107
|
lstatSync as lstatSync2,
|
|
108
108
|
readdirSync,
|
|
109
|
-
readFileSync
|
|
109
|
+
readFileSync,
|
|
110
|
+
statSync
|
|
110
111
|
} from "node:fs";
|
|
111
112
|
import { join as join2 } from "node:path";
|
|
112
113
|
|
|
@@ -767,26 +768,36 @@ function listTree(ref, path, cwd, options = {}) {
|
|
|
767
768
|
};
|
|
768
769
|
}
|
|
769
770
|
function untrackedMeta(cwd) {
|
|
770
|
-
return untracked(cwd).
|
|
771
|
+
return untracked(cwd).flatMap((path) => {
|
|
771
772
|
const full = join2(cwd, path);
|
|
772
773
|
let binary = false;
|
|
773
774
|
let lines = 0;
|
|
774
|
-
|
|
775
|
+
let fileExists = false;
|
|
776
|
+
try {
|
|
777
|
+
fileExists = existsSync(full) && statSync(full).isFile();
|
|
778
|
+
} catch {
|
|
779
|
+
fileExists = false;
|
|
780
|
+
}
|
|
781
|
+
if (fileExists) {
|
|
775
782
|
const data = readFileSync(full);
|
|
776
783
|
const probe = data.subarray(0, 8192);
|
|
777
784
|
binary = probe.includes(0);
|
|
778
785
|
if (!binary)
|
|
779
786
|
lines = data.toString("utf8").split(`
|
|
780
787
|
`).length - 1;
|
|
788
|
+
} else {
|
|
789
|
+
return [];
|
|
781
790
|
}
|
|
782
|
-
return
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
791
|
+
return [
|
|
792
|
+
{
|
|
793
|
+
path,
|
|
794
|
+
status: "A",
|
|
795
|
+
additions: binary ? 0 : lines,
|
|
796
|
+
deletions: 0,
|
|
797
|
+
binary,
|
|
798
|
+
untracked: true
|
|
799
|
+
}
|
|
800
|
+
];
|
|
790
801
|
});
|
|
791
802
|
}
|
|
792
803
|
function fileMeta(args, cwd, includeUntracked = false) {
|
|
@@ -1982,7 +1993,7 @@ function worktreeFileMetadata(path, knownSize) {
|
|
|
1982
1993
|
if (!full)
|
|
1983
1994
|
return {};
|
|
1984
1995
|
try {
|
|
1985
|
-
const stat =
|
|
1996
|
+
const stat = statSync2(full);
|
|
1986
1997
|
return {
|
|
1987
1998
|
size: knownSize ?? stat.size,
|
|
1988
1999
|
created_at: isoDate(stat.birthtimeMs),
|
|
@@ -2007,7 +2018,7 @@ function directoryMetadata(target, path) {
|
|
|
2007
2018
|
if (!full)
|
|
2008
2019
|
return {};
|
|
2009
2020
|
try {
|
|
2010
|
-
const stat =
|
|
2021
|
+
const stat = statSync2(full);
|
|
2011
2022
|
return {
|
|
2012
2023
|
created_at: isoDate(stat.birthtimeMs),
|
|
2013
2024
|
updated_at: isoDate(stat.mtimeMs)
|
|
@@ -2334,7 +2345,7 @@ function handleFileDiff(url) {
|
|
|
2334
2345
|
}
|
|
2335
2346
|
function worktreeLineIndexSignature(full) {
|
|
2336
2347
|
try {
|
|
2337
|
-
const stat =
|
|
2348
|
+
const stat = statSync2(full);
|
|
2338
2349
|
return `size:${stat.size}|mtime:${stat.mtimeMs}|ctime:${stat.ctimeMs}|ino:${stat.ino || 0}`;
|
|
2339
2350
|
} catch {
|
|
2340
2351
|
return null;
|
|
@@ -2350,7 +2361,7 @@ async function getWorktreeLineIndex(full) {
|
|
|
2350
2361
|
lineIndexCache.set(full, cached);
|
|
2351
2362
|
return cached.index;
|
|
2352
2363
|
}
|
|
2353
|
-
const stat =
|
|
2364
|
+
const stat = statSync2(full);
|
|
2354
2365
|
if (stat.size > LINE_INDEX_MAX_FILE_BYTES)
|
|
2355
2366
|
return null;
|
|
2356
2367
|
const index = await buildLineOffsetIndexFromStream(fileReadableStream(full), stat.size);
|
|
@@ -2595,7 +2606,7 @@ function rawFileSize(path, ref) {
|
|
|
2595
2606
|
if (!full)
|
|
2596
2607
|
return null;
|
|
2597
2608
|
try {
|
|
2598
|
-
return
|
|
2609
|
+
return statSync2(full).size;
|
|
2599
2610
|
} catch {
|
|
2600
2611
|
return null;
|
|
2601
2612
|
}
|
|
@@ -2694,7 +2705,7 @@ async function handleUploadFiles(req) {
|
|
|
2694
2705
|
const realDir = safeOpenWorktreePath(dir);
|
|
2695
2706
|
if (!realDir)
|
|
2696
2707
|
return text("not found", 404);
|
|
2697
|
-
const stats =
|
|
2708
|
+
const stats = statSync2(realDir);
|
|
2698
2709
|
if (!stats.isDirectory())
|
|
2699
2710
|
return text("not a directory", 400);
|
|
2700
2711
|
const files = form.getAll("files").filter((item) => item instanceof File);
|
|
@@ -2942,7 +2953,7 @@ async function handleOpenPath(req) {
|
|
|
2942
2953
|
const target = safeOpenWorktreePath(targetPath);
|
|
2943
2954
|
if (!target)
|
|
2944
2955
|
return text("not found", 404);
|
|
2945
|
-
const stats =
|
|
2956
|
+
const stats = statSync2(target);
|
|
2946
2957
|
if (!stats.isDirectory())
|
|
2947
2958
|
return text("not a directory", 400);
|
|
2948
2959
|
openOsPath(target);
|
|
@@ -3027,7 +3038,7 @@ async function handleCreateDirectory(req) {
|
|
|
3027
3038
|
const parent = safeOpenWorktreePath(dir);
|
|
3028
3039
|
if (!parent)
|
|
3029
3040
|
return text("not found", 404);
|
|
3030
|
-
const stats =
|
|
3041
|
+
const stats = statSync2(parent);
|
|
3031
3042
|
if (!stats.isDirectory())
|
|
3032
3043
|
return text("not a directory", 400);
|
|
3033
3044
|
const targetPath = dir ? `${dir}/${name}` : name;
|