Skip to content

Commit

Permalink
fix dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mellyeliu committed Jan 13, 2025
2 parents e40a320 + f46d0df commit 0896aeb
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/cli/src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import fs from 'fs/promises';
import path from 'path';
const { utils } = require('@stylexjs/shared');
import { utils } from '@stylexjs/shared';

const hash = utils.hash;

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

function findProjectRoot(startDir = process.cwd()) {
let currentDir = startDir;

while (currentDir !== path.parse(currentDir).root) {
if (fs.existsSync(path.join(currentDir, 'package.json'))) {
return currentDir;
}
currentDir = path.dirname(currentDir);
}

throw new Error('Project root not found');
}

export async function getCacheFilePath(cachePath, filePath) {
const projectRoot = path.join(__dirname, '../../../');
const relativePath = path.relative(projectRoot, filePath);
const fileName = relativePath.replace(/[\\/]/g, '__');
return path.join(cachePath, `${fileName}.json`);
}

export async function getCacheFilePath(cachePath, filePath) {
const projectRoot = path.resolve();
const relativePath = path.relative(projectRoot, filePath);
Expand Down

0 comments on commit 0896aeb

Please sign in to comment.