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

Commit 8d56e1c

Browse files
committed
refactor(build-in*): Directly make it async and remove unnecessary execute functions
1 parent 6ece179 commit 8d56e1c

File tree

5 files changed

+7
-23
lines changed

5 files changed

+7
-23
lines changed

src/_internal/utils/build-in.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
'use server';
22
import { isServer } from './helper';
33

4-
export const buildIn = (styleSheet: string, global?: string): void => {
4+
export const buildIn = async (styleSheet: string, global?: string): Promise<void> => {
55
if (!isServer) return;
6-
let fs: typeof import('fs');
7-
let path: typeof import('path');
8-
fs = require('fs');
9-
path = require('path');
10-
6+
const fs = await import('fs');
7+
const path = await import('path');
118
const styleFilePath = path.join(__dirname, '../../core/styles/style.module.css');
129
const globalFilePath = path.join(__dirname, '../../core/styles/global.css');
13-
1410
const filePath = global === '--global' ? globalFilePath : styleFilePath;
1511
const message = global === '--global' ? ' ✅ Generating global static css \n' : ' ✅ Generating module static css \n';
1612

src/core/method/create-build-in-helper.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ function createGlobalStyleSheetPromise() {
1414
});
1515
}
1616

17-
async function executeBuildIn(styleSheet: string): Promise<void> {
18-
if (!isDevelopment && styleSheet) buildIn(styleSheet);
19-
}
20-
2117
async function processStyleSheets() {
2218
while (styleSheetQueue.length > 0) {
2319
const [styleSheet] = styleSheetQueue.shift() as [string];
24-
await executeBuildIn(styleSheet);
20+
if (!isDevelopment && styleSheet) await buildIn(styleSheet);
2521
}
2622
isProcessing = false;
2723
}

src/core/method/global-build-in-helper.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ function createGlobalStyleSheetPromise() {
1414
});
1515
}
1616

17-
async function executeBuildIn(styleSheet: string, option?: string): Promise<void> {
18-
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
19-
}
20-
2117
async function processStyleSheets() {
2218
while (styleSheetQueue.length > 0) {
2319
const [styleSheet, option] = styleSheetQueue.shift() as [string, string?];
24-
await executeBuildIn(styleSheet, option);
20+
if (!isDevelopment && styleSheet) await buildIn(styleSheet, option);
2521
}
2622
isProcessing = false;
2723
}

src/core/method/root-build-in-helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function createGlobalStyleSheetPromise() {
1212
export async function rootBuildIn(): Promise<void> {
1313
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
1414
const [styleSheet, option] = await globalStyleSheetPromise;
15-
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
15+
if (!isDevelopment && styleSheet) await buildIn(styleSheet, option);
1616
createGlobalStyleSheetPromise();
1717
}
1818

src/core/method/set-build-in-helper.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,10 @@ function createGlobalStyleSheetPromise() {
1414
});
1515
}
1616

17-
async function executeBuildIn(styleSheet: string): Promise<void> {
18-
if (!isDevelopment && styleSheet) buildIn(styleSheet);
19-
}
20-
2117
async function processStyleSheets() {
2218
while (styleSheetQueue.length > 0) {
2319
const [styleSheet] = styleSheetQueue.shift() as [string];
24-
await executeBuildIn(styleSheet);
20+
if (!isDevelopment && styleSheet) await buildIn(styleSheet);
2521
}
2622
isProcessing = false;
2723
}

0 commit comments

Comments
 (0)