@caplab/read 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/cjs/errors/structured.d.ts +12 -0
- package/dist/cjs/errors/structured.d.ts.map +1 -0
- package/dist/cjs/errors/structured.js +124 -0
- package/dist/cjs/errors/structured.js.map +1 -0
- package/dist/cjs/factory.d.ts +3 -0
- package/dist/cjs/factory.d.ts.map +1 -0
- package/dist/cjs/factory.js +92 -0
- package/dist/cjs/factory.js.map +1 -0
- package/dist/cjs/fs/binary.d.ts +4 -0
- package/dist/cjs/fs/binary.d.ts.map +1 -0
- package/dist/cjs/fs/binary.js +116 -0
- package/dist/cjs/fs/binary.js.map +1 -0
- package/dist/cjs/fs/directory.d.ts +3 -0
- package/dist/cjs/fs/directory.d.ts.map +1 -0
- package/dist/cjs/fs/directory.js +163 -0
- package/dist/cjs/fs/directory.js.map +1 -0
- package/dist/cjs/fs/reader.d.ts +3 -0
- package/dist/cjs/fs/reader.d.ts.map +1 -0
- package/dist/cjs/fs/reader.js +145 -0
- package/dist/cjs/fs/reader.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/output/formatter.d.ts +4 -0
- package/dist/cjs/output/formatter.d.ts.map +1 -0
- package/dist/cjs/output/formatter.js +26 -0
- package/dist/cjs/output/formatter.js.map +1 -0
- package/dist/cjs/output/truncation.d.ts +5 -0
- package/dist/cjs/output/truncation.d.ts.map +1 -0
- package/dist/cjs/output/truncation.js +10 -0
- package/dist/cjs/output/truncation.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/path/guard.d.ts +5 -0
- package/dist/cjs/path/guard.d.ts.map +1 -0
- package/dist/cjs/path/guard.js +91 -0
- package/dist/cjs/path/guard.js.map +1 -0
- package/dist/cjs/path/normalizer.d.ts +3 -0
- package/dist/cjs/path/normalizer.d.ts.map +1 -0
- package/dist/cjs/path/normalizer.js +47 -0
- package/dist/cjs/path/normalizer.js.map +1 -0
- package/dist/cjs/path/resolver.d.ts +5 -0
- package/dist/cjs/path/resolver.d.ts.map +1 -0
- package/dist/cjs/path/resolver.js +73 -0
- package/dist/cjs/path/resolver.js.map +1 -0
- package/dist/cjs/read/encoding.d.ts +5 -0
- package/dist/cjs/read/encoding.d.ts.map +1 -0
- package/dist/cjs/read/encoding.js +29 -0
- package/dist/cjs/read/encoding.js.map +1 -0
- package/dist/cjs/read/multi-file.d.ts +4 -0
- package/dist/cjs/read/multi-file.d.ts.map +1 -0
- package/dist/cjs/read/multi-file.js +293 -0
- package/dist/cjs/read/multi-file.js.map +1 -0
- package/dist/cjs/search/adapter.d.ts +3 -0
- package/dist/cjs/search/adapter.d.ts.map +1 -0
- package/dist/cjs/search/adapter.js +34 -0
- package/dist/cjs/search/adapter.js.map +1 -0
- package/dist/cjs/types/internal.d.ts +24 -0
- package/dist/cjs/types/internal.d.ts.map +1 -0
- package/dist/cjs/types/internal.js +4 -0
- package/dist/cjs/types/internal.js.map +1 -0
- package/dist/cjs/types/public.d.ts +87 -0
- package/dist/cjs/types/public.d.ts.map +1 -0
- package/dist/cjs/types/public.js +4 -0
- package/dist/cjs/types/public.js.map +1 -0
- package/dist/errors/structured.d.ts +12 -0
- package/dist/errors/structured.d.ts.map +1 -0
- package/dist/errors/structured.js +79 -0
- package/dist/errors/structured.js.map +1 -0
- package/dist/factory.d.ts +3 -0
- package/dist/factory.d.ts.map +1 -0
- package/dist/factory.js +89 -0
- package/dist/factory.js.map +1 -0
- package/dist/fs/binary.d.ts +4 -0
- package/dist/fs/binary.d.ts.map +1 -0
- package/dist/fs/binary.js +79 -0
- package/dist/fs/binary.js.map +1 -0
- package/dist/fs/directory.d.ts +3 -0
- package/dist/fs/directory.d.ts.map +1 -0
- package/dist/fs/directory.js +127 -0
- package/dist/fs/directory.js.map +1 -0
- package/dist/fs/reader.d.ts +3 -0
- package/dist/fs/reader.d.ts.map +1 -0
- package/dist/fs/reader.js +109 -0
- package/dist/fs/reader.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/output/formatter.d.ts +4 -0
- package/dist/output/formatter.d.ts.map +1 -0
- package/dist/output/formatter.js +22 -0
- package/dist/output/formatter.js.map +1 -0
- package/dist/output/truncation.d.ts +5 -0
- package/dist/output/truncation.d.ts.map +1 -0
- package/dist/output/truncation.js +7 -0
- package/dist/output/truncation.js.map +1 -0
- package/dist/path/guard.d.ts +5 -0
- package/dist/path/guard.d.ts.map +1 -0
- package/dist/path/guard.js +55 -0
- package/dist/path/guard.js.map +1 -0
- package/dist/path/normalizer.d.ts +3 -0
- package/dist/path/normalizer.d.ts.map +1 -0
- package/dist/path/normalizer.js +10 -0
- package/dist/path/normalizer.js.map +1 -0
- package/dist/path/resolver.d.ts +5 -0
- package/dist/path/resolver.d.ts.map +1 -0
- package/dist/path/resolver.js +35 -0
- package/dist/path/resolver.js.map +1 -0
- package/dist/read/encoding.d.ts +5 -0
- package/dist/read/encoding.d.ts.map +1 -0
- package/dist/read/encoding.js +26 -0
- package/dist/read/encoding.js.map +1 -0
- package/dist/read/multi-file.d.ts +4 -0
- package/dist/read/multi-file.d.ts.map +1 -0
- package/dist/read/multi-file.js +257 -0
- package/dist/read/multi-file.js.map +1 -0
- package/dist/search/adapter.d.ts +3 -0
- package/dist/search/adapter.d.ts.map +1 -0
- package/dist/search/adapter.js +31 -0
- package/dist/search/adapter.js.map +1 -0
- package/dist/types/internal.d.ts +24 -0
- package/dist/types/internal.d.ts.map +1 -0
- package/dist/types/internal.js +3 -0
- package/dist/types/internal.js.map +1 -0
- package/dist/types/public.d.ts +87 -0
- package/dist/types/public.d.ts.map +1 -0
- package/dist/types/public.js +3 -0
- package/dist/types/public.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.listDirectory = listDirectory;
|
|
37
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const normalizer_js_1 = require("../path/normalizer.js");
|
|
40
|
+
function minimatch(str, pattern) {
|
|
41
|
+
// Simple glob pattern matcher supporting * and ?
|
|
42
|
+
const regexPattern = pattern
|
|
43
|
+
.replace(/\./g, '\\.')
|
|
44
|
+
.replace(/\*/g, '.*')
|
|
45
|
+
.replace(/\?/g, '.');
|
|
46
|
+
const regex = new RegExp(`^${regexPattern}$`);
|
|
47
|
+
return regex.test(str);
|
|
48
|
+
}
|
|
49
|
+
async function listDirectory(dirPath, workspaceRoot, options = {}) {
|
|
50
|
+
try {
|
|
51
|
+
const stats = await fs.stat(dirPath);
|
|
52
|
+
if (!stats.isDirectory()) {
|
|
53
|
+
return {
|
|
54
|
+
success: false,
|
|
55
|
+
error: 'path_not_found',
|
|
56
|
+
path: dirPath,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const entries = [];
|
|
60
|
+
const maxDepth = options.maxDepth ?? Infinity;
|
|
61
|
+
const includeHidden = options.includeHidden ?? false;
|
|
62
|
+
const includePatterns = options.include ?? [];
|
|
63
|
+
const excludePatterns = options.exclude ?? [];
|
|
64
|
+
const maxEntries = options.maxEntries ?? 1000;
|
|
65
|
+
async function collectEntries(currentPath, currentDepth) {
|
|
66
|
+
if (currentDepth > maxDepth) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
const dirents = await fs.readdir(currentPath, { withFileTypes: true });
|
|
71
|
+
for (const dirent of dirents) {
|
|
72
|
+
const fullPath = path.join(currentPath, dirent.name);
|
|
73
|
+
const relativePath = path.relative(workspaceRoot, fullPath);
|
|
74
|
+
const normalizedRelativePath = (0, normalizer_js_1.normalizePath)(relativePath);
|
|
75
|
+
// Skip hidden files unless includeHidden is true
|
|
76
|
+
if (!includeHidden && dirent.name.startsWith('.')) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
// Apply exclude patterns (apply to both files and directories)
|
|
80
|
+
if (excludePatterns.length > 0) {
|
|
81
|
+
const matchesExclude = excludePatterns.some(pattern => minimatch(normalizedRelativePath, pattern));
|
|
82
|
+
if (matchesExclude) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// For files, apply include patterns
|
|
87
|
+
if (dirent.isFile()) {
|
|
88
|
+
if (includePatterns.length > 0) {
|
|
89
|
+
const matchesInclude = includePatterns.some(pattern => minimatch(normalizedRelativePath, pattern));
|
|
90
|
+
if (!matchesInclude) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const entry = {
|
|
95
|
+
path: (0, normalizer_js_1.normalizePath)(fullPath),
|
|
96
|
+
relativePath: normalizedRelativePath,
|
|
97
|
+
type: 'file',
|
|
98
|
+
};
|
|
99
|
+
// Get size for files
|
|
100
|
+
try {
|
|
101
|
+
const fileStats = await fs.stat(fullPath);
|
|
102
|
+
entry.size = fileStats.size;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Ignore stat errors
|
|
106
|
+
}
|
|
107
|
+
entries.push(entry);
|
|
108
|
+
}
|
|
109
|
+
// Always recurse into directories to find nested files
|
|
110
|
+
if (dirent.isDirectory()) {
|
|
111
|
+
// Add directory entry if it matches include patterns or if no include patterns
|
|
112
|
+
if (includePatterns.length === 0 || includePatterns.some(pattern => minimatch(normalizedRelativePath, pattern))) {
|
|
113
|
+
const entry = {
|
|
114
|
+
path: (0, normalizer_js_1.normalizePath)(fullPath),
|
|
115
|
+
relativePath: normalizedRelativePath,
|
|
116
|
+
type: 'directory',
|
|
117
|
+
};
|
|
118
|
+
entries.push(entry);
|
|
119
|
+
}
|
|
120
|
+
await collectEntries(fullPath, currentDepth + 1);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
if (error.code === 'EACCES' || error.code === 'EPERM') {
|
|
126
|
+
// Skip directories we can't access
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
await collectEntries(dirPath, 0);
|
|
134
|
+
// Sort by normalized path (deterministic)
|
|
135
|
+
entries.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
136
|
+
// Cap to maxEntries
|
|
137
|
+
const truncated = entries.length > maxEntries;
|
|
138
|
+
const finalEntries = entries.slice(0, maxEntries);
|
|
139
|
+
return {
|
|
140
|
+
success: true,
|
|
141
|
+
entries: finalEntries,
|
|
142
|
+
truncated,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
if (error.code === 'ENOENT') {
|
|
147
|
+
return {
|
|
148
|
+
success: false,
|
|
149
|
+
error: 'path_not_found',
|
|
150
|
+
path: dirPath,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (error.code === 'EACCES' || error.code === 'EPERM') {
|
|
154
|
+
return {
|
|
155
|
+
success: false,
|
|
156
|
+
error: 'permission_denied',
|
|
157
|
+
path: dirPath,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=directory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directory.js","sourceRoot":"","sources":["../../../src/fs/directory.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,sCAiIC;AAhJD,qDAAuC;AACvC,gDAAkC;AAElC,yDAAsD;AAEtD,SAAS,SAAS,CAAC,GAAW,EAAE,OAAe;IAC7C,iDAAiD;IACjD,MAAM,YAAY,GAAG,OAAO;SACzB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC;SACrB,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC;SACpB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACvB,MAAM,KAAK,GAAG,IA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AAC,OAAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,gBAAgB;gBACvB,IAAI,EAAE,OAAO;aACd,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACtD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,mBAAmB;gBAC1B,IAAI,EAAE,OAAO;aACd,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FileReadResult } from '../types/public.js';
|
|
2
|
+
export declare function readFileWithBudget(filePath: string, maxBytes: number, maxLines: number, encoding?: 'utf-8' | 'utf-16le' | 'utf-16be' | 'auto', workspaceRoot?: string): Promise<FileReadResult>;
|
|
3
|
+
//# sourceMappingURL=reader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reader.d.ts","sourceRoot":"","sources":["../../../src/fs/reader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGzD,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,EACrD,aAAa,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,cAAc,CAAC,CA8GzB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.readFileWithBudget = readFileWithBudget;
|
|
37
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
const binary_js_1 = require("./binary.js");
|
|
40
|
+
async function readFileWithBudget(filePath, maxBytes, maxLines, encoding, workspaceRoot) {
|
|
41
|
+
const getRelativePath = () => {
|
|
42
|
+
if (workspaceRoot) {
|
|
43
|
+
const relative = path.relative(workspaceRoot, filePath);
|
|
44
|
+
// Normalize to forward slashes for consistency
|
|
45
|
+
return relative.split(path.sep).join('/');
|
|
46
|
+
}
|
|
47
|
+
return path.basename(filePath);
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const stats = await fs.stat(filePath);
|
|
51
|
+
if (!stats.isFile()) {
|
|
52
|
+
return {
|
|
53
|
+
success: false,
|
|
54
|
+
error: 'file_not_found',
|
|
55
|
+
path: filePath,
|
|
56
|
+
relativePath: getRelativePath(),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
// Detect encoding if auto
|
|
60
|
+
let finalEncoding;
|
|
61
|
+
if (encoding === 'auto' || !encoding) {
|
|
62
|
+
const detection = await (0, binary_js_1.detectEncoding)(filePath);
|
|
63
|
+
if (detection.encoding === 'unknown') {
|
|
64
|
+
return {
|
|
65
|
+
success: false,
|
|
66
|
+
error: 'unsupported_encoding',
|
|
67
|
+
path: filePath,
|
|
68
|
+
relativePath: getRelativePath(),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
finalEncoding = detection.encoding;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
finalEncoding = encoding;
|
|
75
|
+
}
|
|
76
|
+
// Check if binary
|
|
77
|
+
const isBinary = await (0, binary_js_1.isBinaryFile)(filePath, finalEncoding);
|
|
78
|
+
if (isBinary) {
|
|
79
|
+
return {
|
|
80
|
+
success: false,
|
|
81
|
+
error: 'binary_file',
|
|
82
|
+
path: filePath,
|
|
83
|
+
relativePath: getRelativePath(),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// Read file with budgets
|
|
87
|
+
const handle = await fs.open(filePath, 'r');
|
|
88
|
+
const buffer = Buffer.alloc(maxBytes);
|
|
89
|
+
const { bytesRead } = await handle.read(buffer, 0, maxBytes, 0);
|
|
90
|
+
await handle.close();
|
|
91
|
+
const data = buffer.subarray(0, bytesRead);
|
|
92
|
+
// Use fatal: true when reading full file to catch encoding errors
|
|
93
|
+
// Use fatal: false when truncated to handle multibyte sequence cuts
|
|
94
|
+
const decoder = new TextDecoder(finalEncoding, { fatal: bytesRead === stats.size });
|
|
95
|
+
let content;
|
|
96
|
+
try {
|
|
97
|
+
content = decoder.decode(data);
|
|
98
|
+
}
|
|
99
|
+
catch (decodeError) {
|
|
100
|
+
return {
|
|
101
|
+
success: false,
|
|
102
|
+
error: 'unsupported_encoding',
|
|
103
|
+
path: filePath,
|
|
104
|
+
relativePath: getRelativePath(),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// Count lines and apply line limit
|
|
108
|
+
const lines = content.split('\n');
|
|
109
|
+
const truncatedLines = lines.length > maxLines;
|
|
110
|
+
const finalContent = truncatedLines ? lines.slice(0, maxLines).join('\n') : content;
|
|
111
|
+
const linesRead = Math.min(lines.length, maxLines);
|
|
112
|
+
const truncatedBytes = bytesRead === maxBytes && stats.size > maxBytes;
|
|
113
|
+
return {
|
|
114
|
+
success: true,
|
|
115
|
+
path: filePath,
|
|
116
|
+
relativePath: getRelativePath(),
|
|
117
|
+
content: finalContent,
|
|
118
|
+
encoding: finalEncoding,
|
|
119
|
+
truncatedBytes,
|
|
120
|
+
truncatedLines,
|
|
121
|
+
bytesRead,
|
|
122
|
+
linesRead,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
if (error.code === 'ENOENT') {
|
|
127
|
+
return {
|
|
128
|
+
success: false,
|
|
129
|
+
error: 'file_not_found',
|
|
130
|
+
path: filePath,
|
|
131
|
+
relativePath: getRelativePath(),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (error.code === 'EACCES' || error.code === 'EPERM') {
|
|
135
|
+
return {
|
|
136
|
+
success: false,
|
|
137
|
+
error: 'permission_denied',
|
|
138
|
+
path: filePath,
|
|
139
|
+
relativePath: getRelativePath(),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
throw error;
|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Y,EAAE,eAAe,EAAE;aAChC,CAAC;QACJ,CAAC;QACD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { WorkspaceReaderOptions, ListDirectoryOptions, DirectoryResult, DirectoryEntry, ReadFileOptions, FileReadResult, ReadMultipleFilesOptions, MultiFileResult, FileSearchOptions, WorkspaceReader, } from "./types/public.js";
|
|
2
|
+
export { createWorkspaceReader } from "./factory.js";
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,YAAY,EACX,sBAAsB,EACtB,oBAAoB,EACpB,eAAe,EACf,cAAc,EACd,eAAe,EACf,cAAc,EACd,wBAAwB,EACxB,eAAe,EACf,iBAAiB,EACjB,eAAe,GACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Public API exports for @caplab/read
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.createWorkspaceReader = void 0;
|
|
5
|
+
var factory_js_1 = require("./factory.js");
|
|
6
|
+
Object.defineProperty(exports, "createWorkspaceReader", { enumerable: true, get: function () { return factory_js_1.createWorkspaceReader; } });
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA,sCAAsC;;;AAetC,2CAAqD;AAA5C,mHAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FileReadResult, DirectoryEntry } from '../types/public.js';
|
|
2
|
+
export declare function formatFileReadResult(path: string, relativePath: string, content: string, encoding: string, truncatedBytes: boolean, truncatedLines: boolean, bytesRead: number, linesRead: number): FileReadResult;
|
|
3
|
+
export declare function formatDirectoryEntry(path: string, relativePath: string, type: 'file' | 'directory', size?: number): DirectoryEntry;
|
|
4
|
+
//# sourceMappingURL=formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.d.ts","sourceRoot":"","sources":["../../../src/output/formatter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzE,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,cAAc,EAAE,OAAO,EACvB,cAAc,EAAE,OAAO,EACvB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB,cAAc,CAYhB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,MAAM,GAAG,WAAW,EAC1B,IAAI,CAAC,EAAE,MAAM,GACZ,cAAc,CAOhB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.formatFileReadResult = formatFileReadResult;
|
|
4
|
+
exports.formatDirectoryEntry = formatDirectoryEntry;
|
|
5
|
+
function formatFileReadResult(path, relativePath, content, encoding, truncatedBytes, truncatedLines, bytesRead, linesRead) {
|
|
6
|
+
return {
|
|
7
|
+
success: true,
|
|
8
|
+
path,
|
|
9
|
+
relativePath,
|
|
10
|
+
content,
|
|
11
|
+
encoding,
|
|
12
|
+
truncatedBytes,
|
|
13
|
+
truncatedLines,
|
|
14
|
+
bytesRead,
|
|
15
|
+
linesRead,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function formatDirectoryEntry(path, relativePath, type, size) {
|
|
19
|
+
return {
|
|
20
|
+
path,
|
|
21
|
+
relativePath,
|
|
22
|
+
type,
|
|
23
|
+
size,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatter.js","sourceRoot":"","sources":["../../../src/output/formatter.ts"],"names":[],"mappings":";;AAEA,oDAqBC;AAED,oDAYC;AAnCD,SAAgB,oBAAoB,CAClC,IAAY,EACZ,YAAoB,EACpB,OAAe,EACf,QAAgB,EAChB,cAAuB,EACvB,cAAuB,EACvB,SAAiB,EACjB,SAAiB;IAEjB,OAAO;QACL,OAAO,EAAE,IAAI;QACb,IAAI;QACJ,YAAY;QACZ,OAAO;QACP,QAAQ;QACR,cAAc;QACd,cAAc;QACd,SAAS;QACT,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAgB,oBAAoB,CAClC,IAAY,EACZ,YAAoB,EACpB,IAA0B,EAC1B,IAAa;IAEb,OAAO;QACL,IAAI;QACJ,YAAY;QACZ,IAAI;QACJ,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncation.d.ts","sourceRoot":"","sources":["../../../src/output/truncation.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,CAC5B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,CAOtD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.markTruncation = markTruncation;
|
|
4
|
+
function markTruncation(content, maxBytes, maxLines, bytesRead, fileSize) {
|
|
5
|
+
const truncatedBytes = bytesRead === maxBytes && fileSize > maxBytes;
|
|
6
|
+
const lines = content.split('\n');
|
|
7
|
+
const truncatedLines = lines.length > maxLines;
|
|
8
|
+
return { truncatedBytes, truncatedLines };
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=truncation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncation.js","sourceRoot":"","sources":["../../../src/output/truncation.ts"],"names":[],"mappings":";;AAAA,wCAaC;AAbD,SAAgB,cAAc,CAC5B,OAAe,EACf,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,QAAgB;IAEhB,MAAM,cAAc,GAAG,SAAS,KAAK,QAAQ,IAAI,QAAQ,GAAG,QAAQ,CAAC;IAErE,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC;IAE/C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../../src/path/guard.ts"],"names":[],"mappings":"AAGA,wBAAsB,oBAAoB,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,WAAW,GAAG,mBAAmB,CAAA;CAAE,CAAC,CA4D9J"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.validatePathBoundary = validatePathBoundary;
|
|
37
|
+
const path = __importStar(require("node:path"));
|
|
38
|
+
const fs = __importStar(require("node:fs/promises"));
|
|
39
|
+
async function validatePathBoundary(absolutePath, workspaceRoot) {
|
|
40
|
+
// First check if the resolved path is within the workspace root
|
|
41
|
+
// This must happen before checking if the path exists
|
|
42
|
+
const resolvedPath = path.resolve(absolutePath);
|
|
43
|
+
const resolvedRoot = path.resolve(workspaceRoot);
|
|
44
|
+
// On Windows, check if paths are on different drives
|
|
45
|
+
if (process.platform === 'win32') {
|
|
46
|
+
const pathDrive = resolvedPath.split(path.sep)[0];
|
|
47
|
+
const rootDrive = resolvedRoot.split(path.sep)[0];
|
|
48
|
+
if (pathDrive.toLowerCase() !== rootDrive.toLowerCase()) {
|
|
49
|
+
return { valid: false, error: undefined };
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const relativePath = path.relative(resolvedRoot, resolvedPath);
|
|
53
|
+
// If relative path starts with '..', it's outside the workspace
|
|
54
|
+
if (relativePath.startsWith('..')) {
|
|
55
|
+
return { valid: false, error: undefined };
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
// Check if path exists to distinguish error types
|
|
59
|
+
await fs.stat(absolutePath);
|
|
60
|
+
// Resolve symlinks to prevent escape via symlinks
|
|
61
|
+
const realPath = await fs.realpath(absolutePath);
|
|
62
|
+
const realWorkspaceRoot = await fs.realpath(workspaceRoot);
|
|
63
|
+
const realResolvedPath = path.resolve(realPath);
|
|
64
|
+
const realResolvedRoot = path.resolve(realWorkspaceRoot);
|
|
65
|
+
// On Windows, check if resolved paths are on different drives
|
|
66
|
+
if (process.platform === 'win32') {
|
|
67
|
+
const realPathDrive = realResolvedPath.split(path.sep)[0];
|
|
68
|
+
const realRootDrive = realResolvedRoot.split(path.sep)[0];
|
|
69
|
+
if (realPathDrive.toLowerCase() !== realRootDrive.toLowerCase()) {
|
|
70
|
+
return { valid: false, error: undefined };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// Check if the resolved path is within the workspace root (after symlink resolution)
|
|
74
|
+
const realRelativePath = path.relative(realResolvedRoot, realResolvedPath);
|
|
75
|
+
// If relative path starts with '..', it's outside the workspace
|
|
76
|
+
if (realRelativePath.startsWith('..')) {
|
|
77
|
+
return { valid: false, error: undefined };
|
|
78
|
+
}
|
|
79
|
+
return { valid: true };
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
if (error.code === 'ENOENT') {
|
|
83
|
+
return { valid: false, error: 'not_found' };
|
|
84
|
+
}
|
|
85
|
+
if (error.code === 'EACCES' || error.code === 'EPERM') {
|
|
86
|
+
return { valid: false, error: 'permission_denied' };
|
|
87
|
+
}
|
|
88
|
+
return { valid: false, error: undefined };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../../src/path/guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,oDA4DC;AA/DD,gDAAkC;AAClC,qDAAuC;AAEhC,KAAK,UAAU,oBAAoB,CAAC,YAAoB,EAAE,aAAqB;IACpF,gEAAgE;IAChE,sDAAsD;IACtD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAChD,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAEjD,qDAAqD;IACrD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,SAAS,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,IAAI,SAAS,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE,EAAE,CAAC;YACxD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;QAC5C,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAE/D,gEAAgE;IAChE,IAAI,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAClC,OAAO,EAAE,KAAK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AAO,KAAU,EAAE,CAAC;QACpB,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,CAAC;QAC9C,CAAC;QACD,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACtD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,mBAAmB,EAAE,CAAC;QACtD,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAC5C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../../src/path/normalizer.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAIvD;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.normalizePath = normalizePath;
|
|
37
|
+
exports.isAbsolute = isAbsolute;
|
|
38
|
+
const path = __importStar(require("node:path"));
|
|
39
|
+
function normalizePath(inputPath) {
|
|
40
|
+
const normalized = path.normalize(inputPath);
|
|
41
|
+
// Convert backslashes to forward slashes for consistency
|
|
42
|
+
return normalized.split(path.sep).join('/');
|
|
43
|
+
}
|
|
44
|
+
function isAbsolute(inputPath) {
|
|
45
|
+
return path.isAbsolute(inputPath);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=normalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizer.js","sourceRoot":"","sources":["../../../src/path/normalizer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,sCAIC;AAED,gCAEC;AAVD,gDAAkC;AAElC,SAAgB,aAAa,CAAC,SAAiB;IAC7C,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7C,yDAAyD;IACzD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,SAAgB,UAAU,CAAC,SAAiB;IAC1C,OAAO,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { WorkspaceConfig } from '../types/internal.js';
|
|
2
|
+
export declare function validateWorkspaceRoot(workspaceRoot: string): Promise<WorkspaceConfig | null>;
|
|
3
|
+
export declare function resolvePath(inputPath: string, workspaceRoot: string): string;
|
|
4
|
+
export declare function getRelativePath(absolutePath: string, workspaceRoot: string): string;
|
|
5
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/path/resolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAqBlG;AAED,wBAAgB,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAK5E;AAED,wBAAgB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAInF"}
|