@ugo-studio/jspp 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env bun
2
+ import { spawn } from "child_process";
2
3
  import fs from "fs/promises";
3
4
  import path from "path";
4
5
  import pkg from "../package.json";
@@ -63,15 +64,22 @@ async function main() {
63
64
  if (shouldRebuild) {
64
65
  spinner.update("Rebuilding precompiled headers (this may take a while)...");
65
66
  // Use spawn (async) instead of spawnSync to keep spinner alive
66
- const rebuild = Bun.spawn({
67
- cmd: ["bun", "run", "scripts/precompile-headers.ts"],
68
- stdout: "pipe", // pipe to hide output unless error, or handle differently
69
- stderr: "pipe",
67
+ const rebuild = spawn("bun", [
68
+ "run",
69
+ "scripts/precompile-headers.ts",
70
+ ], {
70
71
  cwd: pkgDir,
72
+ stdio: ["ignore", "pipe", "pipe"],
73
+ });
74
+ const stderrChunks = [];
75
+ if (rebuild.stderr) {
76
+ rebuild.stderr.on("data", (chunk) => stderrChunks.push(chunk));
77
+ }
78
+ const exitCode = await new Promise((resolve) => {
79
+ rebuild.on("close", (code) => resolve(code ?? 1));
71
80
  });
72
- const exitCode = await rebuild.exited;
73
81
  if (exitCode !== 0) {
74
- const stderr = await new Response(rebuild.stderr).text();
82
+ const stderr = Buffer.concat(stderrChunks).toString();
75
83
  spinner.fail("Failed to rebuild precompiled headers");
76
84
  console.error(stderr);
77
85
  process.exit(1);
@@ -86,25 +94,28 @@ async function main() {
86
94
  spinner.start();
87
95
  // Ensure output directory exists
88
96
  await fs.mkdir(path.dirname(exeFilePath), { recursive: true });
89
- const compile = Bun.spawn({
90
- cmd: [
91
- "g++",
92
- "-std=c++23",
93
- ...flags,
94
- cppFilePath,
95
- "-o",
96
- exeFilePath,
97
- "-I",
98
- pchDir,
99
- "-I",
100
- preludePath,
101
- ],
102
- stdout: "pipe",
103
- stderr: "pipe",
97
+ const compile = spawn("g++", [
98
+ "-std=c++23",
99
+ ...flags,
100
+ cppFilePath,
101
+ "-o",
102
+ exeFilePath,
103
+ "-I",
104
+ pchDir,
105
+ "-I",
106
+ preludePath,
107
+ ], {
108
+ stdio: ["ignore", "pipe", "pipe"],
109
+ });
110
+ const compileStderrChunks = [];
111
+ if (compile.stderr) {
112
+ compile.stderr.on("data", (chunk) => compileStderrChunks.push(chunk));
113
+ }
114
+ const compileExitCode = await new Promise((resolve) => {
115
+ compile.on("close", (code) => resolve(code ?? 1));
104
116
  });
105
- const compileExitCode = await compile.exited;
106
117
  if (compileExitCode !== 0) {
107
- const stderr = await new Response(compile.stderr).text();
118
+ const stderr = Buffer.concat(compileStderrChunks).toString();
108
119
  spinner.fail(`Compilation failed`);
109
120
  console.error(stderr);
110
121
  process.exit(1);
@@ -121,12 +132,12 @@ async function main() {
121
132
  }
122
133
  // 4. Execution Phase
123
134
  console.log(`\n${COLORS.cyan}--- Running Output ---${COLORS.reset}`);
124
- const run = Bun.spawn({
125
- cmd: [exeFilePath, ...scriptArgs],
126
- stdout: "inherit",
127
- stderr: "inherit",
135
+ const run = spawn(exeFilePath, scriptArgs, {
136
+ stdio: "inherit",
137
+ });
138
+ const runExitCode = await new Promise((resolve) => {
139
+ run.on("close", (code) => resolve(code ?? 1));
128
140
  });
129
- const runExitCode = await run.exited;
130
141
  console.log(`${COLORS.cyan}----------------------${COLORS.reset}\n`);
131
142
  if (runExitCode !== 0) {
132
143
  console.error(`${COLORS.red}Execution failed with exit code ${runExitCode}${COLORS.reset}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ugo-studio/jspp",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "A modern transpiler that converts JavaScript code into high-performance, standard C++23.",
5
5
  "main": "dist/index.js",
6
6
  "module": "src/index.ts",
@@ -1,3 +1,4 @@
1
+ import { spawnSync } from "child_process";
1
2
  import fs from "fs/promises";
2
3
  import path from "path";
3
4
 
@@ -76,9 +77,9 @@ async function precompileHeaders() {
76
77
  }
77
78
 
78
79
  console.log(`[${mode.name.toUpperCase()}] Compiling header...`);
79
- const compile = Bun.spawnSync({
80
- cmd: [
81
- "g++",
80
+ const compile = spawnSync(
81
+ "g++",
82
+ [
82
83
  "-x",
83
84
  "c++-header",
84
85
  "-std=c++23",
@@ -89,11 +90,12 @@ async function precompileHeaders() {
89
90
  "-I",
90
91
  PRELUDE_DIR,
91
92
  ],
92
- stdout: "inherit",
93
- stderr: "inherit",
94
- });
93
+ {
94
+ stdio: "inherit",
95
+ }
96
+ );
95
97
 
96
- if (compile.exitCode !== 0) {
98
+ if (compile.status !== 0) {
97
99
  console.error(
98
100
  `[${mode.name.toUpperCase()}] Failed to precompile headers.`,
99
101
  );