Skip to content

Commit d802caa

Browse files
committed
refactor: simplify command execution in build-package.ts
- Replaced the spawn function with execSync for building the bundler and executing the bundler CLI, streamlining the code and improving error handling. - Enhanced cross-platform compatibility by directly executing commands without platform-specific logic.
1 parent 0410ad8 commit d802caa

1 file changed

Lines changed: 12 additions & 33 deletions

File tree

scripts/build-package.ts

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env node
22

3-
import { spawn } from 'node:child_process';
3+
import { execSync } from 'node:child_process';
44
import { existsSync, statSync } from 'node:fs';
55
import { dirname, resolve } from 'node:path';
66
import { fileURLToPath } from 'node:url';
@@ -33,49 +33,28 @@ function checkBundlerBuilt(): boolean {
3333
async function buildBundler(): Promise<void> {
3434
console.log('🔨 Building bundler...');
3535

36-
return new Promise((resolve, reject) => {
37-
const isWindows = process.platform === 'win32';
38-
const cmd = isWindows ? 'cmd.exe' : 'pnpm';
39-
const args = isWindows ? ['/c', 'pnpm', 'build'] : ['build'];
40-
const child = spawn(cmd, args, {
36+
try {
37+
execSync('pnpm build', {
4138
cwd: BUNDLER_PATH,
4239
stdio: 'inherit',
43-
shell: false,
44-
});
45-
46-
child.on('close', (code) => {
47-
if (code === 0) {
48-
console.log('✅ Bundler built successfully');
49-
resolve();
50-
} else {
51-
reject(new Error(`Bundler build failed with code ${code}`));
52-
}
5340
});
54-
55-
child.on('error', reject);
56-
});
41+
console.log('✅ Bundler built successfully');
42+
} catch (error) {
43+
throw new Error(`Bundler build failed: ${(error as Error).message}`);
44+
}
5745
}
5846

5947
/**
6048
* Execute the bundler CLI with provided arguments
6149
*/
6250
async function executeBundler(args: string[]): Promise<void> {
63-
return new Promise((resolve, reject) => {
64-
const child = spawn('node', [BUNDLER_CLI, ...args], {
51+
try {
52+
execSync(`node "${BUNDLER_CLI}" ${args.join(' ')}`, {
6553
stdio: 'inherit',
66-
shell: false,
67-
});
68-
69-
child.on('close', (code) => {
70-
if (code === 0) {
71-
resolve();
72-
} else {
73-
reject(new Error(`Bundler execution failed with code ${code}`));
74-
}
7554
});
76-
77-
child.on('error', reject);
78-
});
55+
} catch (error) {
56+
throw new Error(`Bundler execution failed: ${(error as Error).message}`);
57+
}
7958
}
8059

8160
/**

0 commit comments

Comments
 (0)