Skip to content
This repository was archived by the owner on Jan 30, 2025. It is now read-only.

Commit 3a3a324

Browse files
committed
fix(build-in.ts): add necessary inside function
1 parent 5d49340 commit 3a3a324

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

src/_internal/utils/build-in.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22

33
import { readFileSync, appendFileSync, mkdirSync, existsSync } from 'fs';
44
import { isServer } from './helper';
5-
import { join } from 'path';
6-
import { findProjectRoot } from '../../../lib/find-project-root.mjs';
5+
import { join, dirname } from 'path';
6+
import * as fs from 'fs';
77

8-
export const buildIn = (styleSheet: string, global?: string): void => {
9-
const projectRoot = findProjectRoot(__dirname);
8+
// Those affected by builds that exist in dist
9+
// Functions required on the outside and inside
10+
async function findProjectRoot(startPath: string): Promise<string | null> {
11+
if (!isServer) return null;
12+
let currentPath = startPath;
13+
while (currentPath !== '/') {
14+
const packageJsonPath = join(currentPath, 'package.json');
15+
const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lockb'].some(file => fs.existsSync(join(currentPath, file)));
16+
if (fs.existsSync(packageJsonPath) && lockFiles) {
17+
return currentPath;
18+
}
19+
currentPath = dirname(currentPath);
20+
}
21+
return null;
22+
}
23+
24+
export const buildIn = async (styleSheet: string, global?: string): Promise<void> => {
25+
const projectRoot = await findProjectRoot(__dirname);
1026

1127
if (!projectRoot) {
1228
console.error('Next.js project root not found');

0 commit comments

Comments
 (0)