@decantr/verifier 1.0.4 → 1.0.6
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/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { existsSync as existsSync2, readdirSync, readFileSync as readFileSync2 } from "fs";
|
|
2
|
+
import { existsSync as existsSync2, realpathSync, readdirSync, readFileSync as readFileSync2 } from "fs";
|
|
3
3
|
import { readFile } from "fs/promises";
|
|
4
4
|
import { extname as extname2, isAbsolute, join as join2, relative, resolve } from "path";
|
|
5
5
|
import { evaluateGuard, isV3, validateEssence } from "@decantr/essence-spec";
|
|
@@ -11162,8 +11162,18 @@ function critiqueSource({
|
|
|
11162
11162
|
reviewPack
|
|
11163
11163
|
};
|
|
11164
11164
|
}
|
|
11165
|
+
function resolveProjectFilePath(projectRoot, filePath) {
|
|
11166
|
+
const root = existsSync2(projectRoot) ? realpathSync.native(projectRoot) : resolve(projectRoot);
|
|
11167
|
+
const candidatePath = isAbsolute(filePath) ? resolve(filePath) : resolve(root, filePath);
|
|
11168
|
+
const resolvedPath = existsSync2(candidatePath) ? realpathSync.native(candidatePath) : candidatePath;
|
|
11169
|
+
const relativePath = relative(root, resolvedPath);
|
|
11170
|
+
if (relativePath.startsWith("..") || isAbsolute(relativePath)) {
|
|
11171
|
+
throw new Error(`Path escapes the project root: ${filePath}`);
|
|
11172
|
+
}
|
|
11173
|
+
return resolvedPath;
|
|
11174
|
+
}
|
|
11165
11175
|
async function critiqueFile(filePath, projectRoot) {
|
|
11166
|
-
const resolvedPath =
|
|
11176
|
+
const resolvedPath = resolveProjectFilePath(projectRoot, filePath);
|
|
11167
11177
|
const code = await readFile(resolvedPath, "utf-8");
|
|
11168
11178
|
const treatmentsCss = readTextIfExists(join2(projectRoot, "src", "styles", "treatments.css"));
|
|
11169
11179
|
const reviewPack = loadReviewPack(projectRoot);
|