Skip to content

Commit f55ce9d

Browse files
committed
fixed: Made crucial functions async
1 parent 86a9359 commit f55ce9d

File tree

13 files changed

+40
-38
lines changed

13 files changed

+40
-38
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"packageManager": "[email protected]",
99
"scripts": {
1010
"preinstall": "npx only-allow pnpm",
11+
"reset": "git clean -fdx && pnpm install --frozen-lockfile && pnpm prepack:core && pnpm i-tarball",
1112
"test": "cd packages/core && pnpm test:all",
1213
"prepack:core": "pnpm -F @austinserb/react-zero-ui pack --pack-destination ./dist",
1314
"i-tarball": "node scripts/install-local-tarball.js",

packages/core/__tests__/config/playwright.next.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ export default defineConfig({
3838
command: "pnpm run dev",
3939
cwd: path.resolve(__dirname, "../fixtures/next"),
4040
url: BASE_URL,
41+
timeout: 60_000, // Give more time for CI environments
42+
reuseExistingServer: !process.env.CI, // Don't reuse in CI
4143
},
4244
});

packages/core/__tests__/config/playwright.vite.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,7 @@ export default defineConfig({
3737
command: "pnpm run dev",
3838
cwd: path.resolve(__dirname, "../fixtures/vite"),
3939
url: BASE_URL,
40+
timeout: 60_000, // Give more time for CI environments
41+
reuseExistingServer: !process.env.CI, // Don't reuse in CI
4042
},
4143
});

packages/core/__tests__/fixtures/next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"clean": "rm -rf .next node_modules package-lock.json"
99
},
1010
"dependencies": {
11+
"@austinserb/react-zero-ui": "file:/Users/austinserb/Desktop/React-Zero/react-zero-ui/dist/austinserb-react-zero-ui-1.0.18.tgz",
1112
"next": "^15.0.0",
1213
"react": "^18.2.0",
1314
"react-dom": "^18.2.0"

packages/core/__tests__/fixtures/vite/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"clean": "rm -rf node_modules package-lock.json"
1212
},
1313
"dependencies": {
14+
"@austinserb/react-zero-ui": "file:/Users/austinserb/Desktop/React-Zero/react-zero-ui/dist/austinserb-react-zero-ui-1.0.18.tgz",
1415
"react": "^19.1.0",
1516
"react-dom": "^19.1.0"
1617
},

packages/core/__tests__/helpers/globalSetup.next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default async function globalSetup() {
1111

1212
// Reset and setup the Next.js fixture
1313
console.log('[Global Setup] Setting up Next.js fixture...');
14-
resetZeroUiState(projectDir, true);
14+
await resetZeroUiState(projectDir, true);
1515

1616
const zeroUiCli = await loadCliFromFixture(projectDir);
1717
await zeroUiCli([]);

packages/core/__tests__/helpers/globalSetup.vite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default async function globalSetup() {
1010

1111
// Reset and setup the Vite fixture
1212
console.log('[Global Setup] Setting up Vite fixture...');
13-
resetZeroUiState(projectDir, false);
13+
await resetZeroUiState(projectDir, false);
1414

1515
const zeroUiCli = await loadCliFromFixture(projectDir);
1616
await zeroUiCli([]);

packages/core/__tests__/unit/cli.test.cjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function cleanupTestDir(testDir) {
3737
fs.unlinkSync(fullPath);
3838
} catch (e) {
3939
// Ignore
40+
console.log(`Error deleting file ${fullPath}: ${e.message}`);
4041
}
4142
}
4243
}
@@ -306,12 +307,12 @@ test('CLI script imports and executes library CLI', async () => {
306307
// Create mock CLI module that matches the actual structure
307308
const mockCLI = `
308309
// Mock implementation of the CLI
309-
function runZeroUiInit() {
310+
async function runZeroUiInit() {
310311
console.log('Mock CLI executed successfully');
311312
}
312313
313314
function cli(argv = process.argv.slice(2)) {
314-
runZeroUiInit(argv);
315+
await runZeroUiInit(argv);
315316
return Promise.resolve();
316317
}
317318
@@ -406,7 +407,7 @@ export function TestComponent() {
406407
process.chdir(testDir);
407408

408409
try {
409-
runZeroUiInit();
410+
await runZeroUiInit();
410411

411412
// Check that initialization messages were logged
412413
const logOutput = logMessages.join('\n');
@@ -454,7 +455,7 @@ test('Library CLI handles errors gracefully', async () => {
454455
const { runZeroUiInit } = require('../../src/cli/postInstall.cjs');
455456

456457
// This should complete without errors in most cases
457-
runZeroUiInit();
458+
await runZeroUiInit();
458459

459460
console.log('✅ Library CLI handles execution without crashing');
460461

@@ -723,7 +724,7 @@ export function Toggle() {
723724
process.chdir(testDir);
724725

725726
try {
726-
runZeroUiInit();
727+
await runZeroUiInit();
727728

728729
const logOutput = logMessages.join('\n');
729730
assert(logOutput.includes('[Zero-UI] Initializing...'), 'Should log initialization');

packages/core/src/cli/init.cjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ const { runZeroUiInit } = require('./postInstall.cjs');
77

88

99
// Take command line arguments (defaulting to process.argv.slice(2) which are the args after node <scriptname>) and pass them to runZeroUiInit
10-
function cli(argv = process.argv.slice(2)) {
11-
runZeroUiInit(argv);
10+
async function cli(argv = process.argv.slice(2)) {
11+
return await runZeroUiInit(argv);
1212
}
1313

1414
/* -------- CL I -------- */
15-
if (require.main === module) cli(); // `npx init-react-zero-ui`
15+
if (require.main === module) {
16+
cli().catch(error => {
17+
console.error('CLI failed:', error);
18+
process.exit(1);
19+
});
20+
}
1621

1722
/* -------- CJS -------- */
1823
module.exports = cli; // `require('@…/cli')()`

packages/core/src/cli/postInstall.cjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@ const {
88
hasViteConfig,
99
} = require('../postcss/helpers.cjs');
1010

11-
function runZeroUiInit() {
11+
async function runZeroUiInit() {
1212
try {
1313
console.log('[Zero-UI] Initializing...');
1414

1515
// Patch Vite config for Vite projects
1616
if (hasViteConfig()) {
17-
patchViteConfig();
17+
await patchViteConfig();
1818
}
1919

2020

2121
if (!hasViteConfig()) {
2222
// Patch config for module resolution
23-
patchConfigAlias();
23+
await patchConfigAlias();
2424
// Patch PostCSS config for Next.js projects
25-
patchPostcssConfig();
25+
await patchPostcssConfig();
2626
}
2727

2828
// Process all variants using the shared helper
29-
const { finalVariants, initialValues, sourceFiles } = processVariants();
29+
const { finalVariants, initialValues, sourceFiles } = await processVariants();
3030

3131
// Generate attribute files using the shared helper
32-
generateAttributesFile(finalVariants, initialValues);
32+
await generateAttributesFile(finalVariants, initialValues);
3333

3434

3535
console.log(`[Zero-UI] ✅ Initialized with ${finalVariants.length} variants from ${sourceFiles.length} files`);

0 commit comments

Comments
 (0)