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

Commit 6a4665b

Browse files
committed
feat(find-project-root.ts*): Name and functionality changed from find-nextjs-project-root.
1 parent 79f8217 commit 6a4665b

File tree

6 files changed

+26
-27
lines changed

6 files changed

+26
-27
lines changed

bin/typedcssx.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
#!/usr/bin/env node
22

3-
const { findNextJsProjectRoot } = require('../src/_internal');
3+
const { findProjectRoot } = require('../src/_internal');
44
const { execSync } = require('child_process');
55
const { join } = require('path');
66

77
(async () => {
88
if (process.argv.includes('--compile')) {
99
try {
10-
const packageRoot = await findNextJsProjectRoot(__dirname);
10+
const packageRoot = await findProjectRoot(__dirname);
1111
if (!packageRoot) {
1212
throw new Error('Could not find Next.js project root');
1313
}

compiler/src/clean-up.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { findNextJsProjectRoot } from '../../src/_internal';
1+
import { findProjectRoot } from '../../src/_internal';
22
import { existsSync, writeFileSync } from 'fs';
33
import { join } from 'path';
44

55
export const cleanUp = async () => {
6-
const projectRoot = await findNextJsProjectRoot(__dirname);
6+
const projectRoot = await findProjectRoot(__dirname);
77

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

src/_internal/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ export { injectServerCSS, getServerCSS } from './utils/inject-server-css';
88
export { buildIn } from './utils/build-in';
99
export { sheetCompiler } from './utils/sheet-compiler';
1010
export { styleCompiler } from './utils/style-compiler';
11-
export { findNextJsProjectRoot } from './utils/find-nextjs-project-root';
11+
export { findProjectRoot } from './utils/find-project-root';

src/_internal/utils/build-in.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import { readFileSync, appendFileSync, mkdirSync, existsSync } from 'fs';
44
import { isServer } from './helper';
55
import { join } from 'path';
6-
import { findNextJsProjectRoot } from '..';
6+
import { findProjectRoot } from '..';
77

88
export const buildIn = async (styleSheet: string, global?: string): Promise<void> => {
9-
const projectRoot = await findNextJsProjectRoot(__dirname);
9+
const projectRoot = await findProjectRoot(__dirname);
1010

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

src/_internal/utils/find-nextjs-project-root.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use server';
2+
3+
import * as fs from 'fs';
4+
import * as path from 'path';
5+
import { isServer } from './helper';
6+
7+
export async function findProjectRoot(startPath: string): Promise<string | null> {
8+
if (!isServer) return null;
9+
let currentPath = startPath;
10+
while (currentPath !== '/') {
11+
const packageJsonPath = path.join(currentPath, 'package.json');
12+
const lockFiles = ['pnpm-lock.yaml', 'package-lock.json', 'yarn.lock', 'bun.lockb'].some(file => fs.existsSync(path.join(currentPath, file)));
13+
if (fs.existsSync(packageJsonPath) && lockFiles) {
14+
return currentPath;
15+
}
16+
currentPath = path.dirname(currentPath);
17+
}
18+
return null;
19+
}

0 commit comments

Comments
 (0)