Skip to content

Commit 0896aeb

Browse files
committed
fix dir
2 parents e40a320 + f46d0df commit 0896aeb

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/cli/src/cache.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
import fs from 'fs/promises';
1010
import path from 'path';
11-
const { utils } = require('@stylexjs/shared');
11+
import { utils } from '@stylexjs/shared';
1212

1313
const hash = utils.hash;
1414

@@ -17,6 +17,26 @@ export function getDefaultCachePath() {
1717
return path.join('node_modules', '.stylex-cache');
1818
}
1919

20+
function findProjectRoot(startDir = process.cwd()) {
21+
let currentDir = startDir;
22+
23+
while (currentDir !== path.parse(currentDir).root) {
24+
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
25+
return currentDir;
26+
}
27+
currentDir = path.dirname(currentDir);
28+
}
29+
30+
throw new Error('Project root not found');
31+
}
32+
33+
export async function getCacheFilePath(cachePath, filePath) {
34+
const projectRoot = path.join(__dirname, '../../../');
35+
const relativePath = path.relative(projectRoot, filePath);
36+
const fileName = relativePath.replace(/[\\/]/g, '__');
37+
return path.join(cachePath, `${fileName}.json`);
38+
}
39+
2040
export async function getCacheFilePath(cachePath, filePath) {
2141
const projectRoot = path.resolve();
2242
const relativePath = path.relative(projectRoot, filePath);

0 commit comments

Comments
 (0)