Skip to content

Commit 9706f74

Browse files
committed
convert init.ts to ESM
1 parent 9181bf9 commit 9706f74

File tree

4 files changed

+89
-9
lines changed

4 files changed

+89
-9
lines changed

packages/cli/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-zero-ui",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Zero-UI project scaffolder for React. Instantly sets up zero-runtime UI state, Tailwind variants, PostCSS, and SSR-safe config in Vite or Next.js apps.",
55
"keywords": [
66
"react",
@@ -43,6 +43,6 @@
4343
"test": "node --test ../core/__tests__/unit/cli.test.cjs"
4444
},
4545
"dependencies": {
46-
"@react-zero-ui/core": "^0.3.1"
46+
"@react-zero-ui/core": "^0.3.3"
4747
}
48-
}
48+
}

packages/cli/tests/test-cli.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#!/usr/bin/env node
2+
import { execSync } from 'node:child_process';
3+
import { mkdtempSync, rmSync, existsSync, readFileSync } from 'node:fs';
4+
import { join } from 'node:path';
5+
import { tmpdir } from 'node:os';
6+
7+
const TARBALL = '../create-zero-ui-1.1.0.tgz';
8+
9+
console.log('🧪 Testing CLI package with npx (no global install)...\n');
10+
11+
// Create temp test directory
12+
const testDir = mkdtempSync(join(tmpdir(), 'test-zero-ui-'));
13+
const tarballPath = join(process.cwd(), TARBALL);
14+
15+
try {
16+
console.log('🚀 Testing CLI execution with npx...');
17+
process.chdir(testDir);
18+
19+
// Run the CLI using npx (completely isolated, no global install)
20+
try {
21+
execSync(`npx ${tarballPath} .`, { stdio: 'pipe', timeout: 30000 });
22+
console.log('✅ CLI executed without errors');
23+
} catch (error) {
24+
console.log('⚠️ CLI execution had issues:', error.message);
25+
// Check if basic setup still worked despite the known core CLI issue
26+
}
27+
28+
// Validate results
29+
console.log('\n🔍 Validating installation results...');
30+
31+
const checks = [
32+
{ name: 'package.json created', test: () => existsSync('package.json') },
33+
{
34+
name: '@react-zero-ui/core installed',
35+
test: () => {
36+
if (!existsSync('package.json')) return false;
37+
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
38+
return pkg.dependencies && '@react-zero-ui/core' in pkg.dependencies;
39+
},
40+
},
41+
{
42+
name: '@tailwindcss/postcss dev dependency',
43+
test: () => {
44+
if (!existsSync('package.json')) return false;
45+
const pkg = JSON.parse(readFileSync('package.json', 'utf-8'));
46+
return pkg.devDependencies && '@tailwindcss/postcss' in pkg.devDependencies;
47+
},
48+
},
49+
{ name: 'node_modules created', test: () => existsSync('node_modules') },
50+
];
51+
52+
let allPassed = true;
53+
for (const check of checks) {
54+
const passed = check.test();
55+
console.log(`${passed ? '✅' : '❌'} ${check.name}`);
56+
if (!passed) allPassed = false;
57+
}
58+
59+
console.log('\n📊 Test Summary:');
60+
if (allPassed) {
61+
console.log('🎉 All checks passed! CLI package is ready to publish.');
62+
process.exit(0);
63+
} else {
64+
console.log('❌ Some checks failed. Review before publishing.');
65+
process.exit(1);
66+
}
67+
} catch (error) {
68+
console.error('💥 Test failed:', error.message);
69+
process.exit(1);
70+
} finally {
71+
// Cleanup temp directory only
72+
console.log('\n🧹 Cleaning up...');
73+
try {
74+
process.chdir(process.cwd());
75+
rmSync(testDir, { recursive: true, force: true });
76+
console.log('✅ Cleanup complete');
77+
} catch (e) {
78+
console.log('⚠️ Cleanup had issues:', e.message);
79+
}
80+
}

packages/core/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@react-zero-ui/core",
3-
"version": "0.3.2",
3+
"version": "0.3.3",
44
"private": false,
55
"description": "Ultra-fast React UI state library with zero runtime, zero re-renders, Tailwind variant support, and automatic data-attribute/css-vars based styling. Replace context, prop drilling, and global stores with build-time magic.",
66
"keywords": [
@@ -59,7 +59,6 @@
5959
},
6060
"./cli": {
6161
"types": "./dist/cli/init.d.ts",
62-
"require": "./dist/cli/init.js",
6362
"import": "./dist/cli/init.js"
6463
},
6564
"./experimental": {

packages/core/src/cli/init.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ async function cli() {
1010
return await runZeroUiInit();
1111
}
1212

13-
/* -------- CL I -------- */
14-
if (require.main === module) {
13+
/* -------- CLI -------- */
14+
// ES module equivalent of require.main === module
15+
if (import.meta.url === `file://${process.argv[1]}`) {
1516
cli().catch((error) => {
1617
console.error('CLI failed:', error);
1718
process.exit(1);
1819
});
1920
}
2021

21-
/* -------- CJS -------- */
22-
module.exports = cli; // `require('@…/cli')()`
22+
/* -------- ES Module Export -------- */
23+
export default cli;

0 commit comments

Comments
 (0)