MCPcopy
hub / github.com/haydenbleasel/ultracite / assertWritableProjectPath

Function assertWritableProjectPath

packages/cli/src/utils.ts:79–115  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

77};
78
79export const assertWritableProjectPath = (filePath: string): void => {
80 const projectRoot = getRealPath(process.cwd());
81 const targetPath = path.resolve(process.cwd(), filePath);
82
83 if (!isInsidePath(targetPath, projectRoot)) {
84 throw new Error(`Refusing to write outside project: ${filePath}`);
85 }
86
87 const parentPath = path.dirname(targetPath);
88 const realParentPath = getRealPathOfNearestExistingAncestor(parentPath);
89
90 if (!isInsidePath(realParentPath, projectRoot)) {
91 throw new Error(
92 `Refusing to write through directory outside project: ${filePath}`
93 );
94 }
95
96 try {
97 const targetStats =
98 typeof lstatSync === "function" ? lstatSync(targetPath) : undefined;
99
100 if (targetStats?.isSymbolicLink()) {
101 throw new Error(`Refusing to write through symbolic link: ${filePath}`);
102 }
103
104 const realTargetPath = getRealPath(targetPath);
105 if (!isInsidePath(realTargetPath, projectRoot)) {
106 throw new Error(`Refusing to write outside project: ${filePath}`);
107 }
108 } catch (error) {
109 if ((error as NodeJS.ErrnoException).code === "ENOENT") {
110 return;
111 }
112
113 throw error;
114 }
115};
116
117export const writeProjectFile = async (
118 filePath: string,

Callers 1

writeProjectFileFunction · 0.85

Calls 3

getRealPathFunction · 0.85
isInsidePathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…