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

Commit 7e586b6

Browse files
committed
refactor(*): function is move to find-nextjs-project-root.ts.
1 parent 0f3ca30 commit 7e586b6

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

src/_internal/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +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';

src/_internal/utils/build-in.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
'use server';
22

33
import { readFileSync, appendFileSync, mkdirSync, existsSync } from 'fs';
4-
import { findNextJsProjectRoot, isServer } from './helper';
4+
import { isServer } from './helper';
55
import { join } from 'path';
6+
import { findNextJsProjectRoot } from '..';
67

78
export const buildIn = (styleSheet: string, global?: string) => {
89
const projectRoot = findNextJsProjectRoot(__dirname);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use server';
2+
3+
import * as fs from 'fs';
4+
import * as path from 'path';
5+
import { isServer } from './helper';
6+
7+
export function findNextJsProjectRoot(startPath: string): string | null {
8+
if (!isServer) return null;
9+
let currentPath = startPath;
10+
while (currentPath !== '/') {
11+
if (
12+
fs.existsSync(path.join(currentPath, 'package.json')) &&
13+
(fs.existsSync(path.join(currentPath, 'next.config.js')) || fs.existsSync(path.join(currentPath, 'next.config.mjs')))
14+
) {
15+
return currentPath;
16+
}
17+
currentPath = path.dirname(currentPath);
18+
}
19+
return null;
20+
}

src/_internal/utils/helper.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,6 @@
1-
import * as path from 'path';
2-
import * as fs from 'fs';
31
import type { ClassesObjectType, HasEPE, HasECE } from '..';
42
import htmlTags from './html-tags';
53

6-
export function findNextJsProjectRoot(startPath: string): string | null {
7-
let currentPath = startPath;
8-
while (currentPath !== '/') {
9-
if (
10-
fs.existsSync(path.join(currentPath, 'package.json')) &&
11-
(fs.existsSync(path.join(currentPath, 'next.config.js')) || fs.existsSync(path.join(currentPath, 'next.config.mjs')))
12-
) {
13-
return currentPath;
14-
}
15-
currentPath = path.dirname(currentPath);
16-
}
17-
return null;
18-
}
19-
204
const isWindowDefined = typeof window !== 'undefined';
215
const isDocumentDefined = typeof document !== 'undefined';
226
export const isServer = !isWindowDefined || !isDocumentDefined;
@@ -41,7 +25,7 @@ export const toPascalCase = (str: string) => {
4125
return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
4226
};
4327

44-
const pascalCaseHtmlTags = htmlTags.map((code) => toPascalCase(code));
28+
const pascalCaseHtmlTags = htmlTags.map(code => toPascalCase(code));
4529
const hasECERegex = /^has(.*?)Child(.*?)$/;
4630
const hasEPERegex = /^has(.*?)Plus(.*?)$/;
4731

@@ -53,14 +37,6 @@ function isHasEPEType(property: string): property is HasEPE {
5337
return hasEPERegex.test(property);
5438
}
5539

56-
const dir = (direname: string, relativePath: string) => {
57-
return path.join(direname, relativePath);
58-
};
59-
60-
export const get = {
61-
dir,
62-
};
63-
6440
export const camelToKebabCase = (property: string) => {
6541
const toKebabCase = (str: string) => str.replace(/([A-Z])/g, '-$1').toLowerCase();
6642

0 commit comments

Comments
 (0)