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

Commit 0446709

Browse files
committed
feat(build-in-helper): desync
1 parent 1e2ff0d commit 0446709

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

compiler/src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ async function getAppRoot(): Promise<string> {
3535
const files = await fg([path.join(appRoot, '**/*.{ts,tsx}')]);
3636
const styleFiles = files.filter(isCSSX);
3737
console.log('\n💬 The following CSS caches were accepted:\n');
38+
const importPromises = styleFiles.map(styleFile => import(path.resolve(styleFile)));
39+
await Promise.all(importPromises);
40+
41+
for (let i = 0; i < styleFiles.length; i++) {
42+
await createBuildIn();
43+
}
44+
for (let i = 0; i < styleFiles.length; i++) {
45+
await setBuildIn();
46+
}
47+
for (let i = 0; i < styleFiles.length; i++) {
48+
await globalBuildIn();
49+
}
3850
for (let i = 0; i < styleFiles.length; i++) {
39-
await import(path.resolve(styleFiles[i]));
40-
createBuildIn();
41-
setBuildIn();
42-
globalBuildIn();
43-
rootBuildIn();
51+
await rootBuildIn();
4452
}
4553
})();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function processStyleSheets() {
2626
isProcessing = false;
2727
}
2828

29-
export function createBuildIn(): void {
29+
export async function createBuildIn(): Promise<void> {
3030
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
3131
if (!isProcessing && styleSheetQueue.length > 0) {
3232
isProcessing = true;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function processStyleSheets() {
2626
isProcessing = false;
2727
}
2828

29-
export function globalBuildIn(): void {
29+
export async function globalBuildIn(): Promise<void> {
3030
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
3131
if (!isProcessing && styleSheetQueue.length > 0) {
3232
isProcessing = true;

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,36 @@ import { buildIn, isDevelopment } from '../../_internal';
22

33
let resolveGlobalStyleSheet: (value: [string, string?]) => void;
44
let globalStyleSheetPromise: Promise<[string, string?]>;
5+
const styleSheetQueue: [string, string?][] = [];
6+
let isProcessing = false;
57

68
function createGlobalStyleSheetPromise() {
79
globalStyleSheetPromise = new Promise<[string, string?]>(resolve => {
8-
resolveGlobalStyleSheet = resolve;
10+
resolveGlobalStyleSheet = (value: [string, string?]) => {
11+
styleSheetQueue.push(value);
12+
resolve(value);
13+
};
914
});
1015
}
1116

17+
async function executeBuildIn(styleSheet: string, option?: string): Promise<void> {
18+
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
19+
}
20+
21+
async function processStyleSheets() {
22+
while (styleSheetQueue.length > 0) {
23+
const [styleSheet, option] = styleSheetQueue.shift() as [string, string?];
24+
await executeBuildIn(styleSheet, option);
25+
}
26+
isProcessing = false;
27+
}
28+
1229
export async function rootBuildIn(): Promise<void> {
1330
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
14-
const [styleSheet, option] = await globalStyleSheetPromise;
15-
if (!isDevelopment && styleSheet) buildIn(styleSheet, option);
16-
createGlobalStyleSheetPromise();
31+
if (!isProcessing && styleSheetQueue.length > 0) {
32+
isProcessing = true;
33+
processStyleSheets();
34+
}
1735
}
1836

1937
export { resolveGlobalStyleSheet, globalStyleSheetPromise, createGlobalStyleSheetPromise };

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async function processStyleSheets() {
2626
isProcessing = false;
2727
}
2828

29-
export function setBuildIn(): void {
29+
export async function setBuildIn(): Promise<void> {
3030
if (typeof globalStyleSheetPromise === 'undefined') createGlobalStyleSheetPromise();
3131
if (!isProcessing && styleSheetQueue.length > 0) {
3232
isProcessing = true;

0 commit comments

Comments
 (0)