@ugo-studio/jspp 0.2.1 → 0.2.3
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/README.md +4 -4
- package/dist/cli.js +40 -29
- package/package.json +1 -1
- package/scripts/precompile-headers.ts +9 -7
package/README.md
CHANGED
|
@@ -51,8 +51,8 @@ To contribute to JSPP or run its test suite, follow these steps:
|
|
|
51
51
|
|
|
52
52
|
### Prerequisites
|
|
53
53
|
|
|
54
|
-
- **
|
|
55
|
-
- [Install
|
|
54
|
+
- **Node.js:** This project uses Node.js for package management and script execution.
|
|
55
|
+
- [Install Node.js](https://nodejs.org/)
|
|
56
56
|
- **C++ Compiler:** A compiler with support for C++23 is required. This project is tested with `g++`.
|
|
57
57
|
- `g++` (MinGW on Windows, or available via build-essentials on Linux)
|
|
58
58
|
|
|
@@ -64,7 +64,7 @@ To contribute to JSPP or run its test suite, follow these steps:
|
|
|
64
64
|
```
|
|
65
65
|
2. Install dependencies:
|
|
66
66
|
```sh
|
|
67
|
-
|
|
67
|
+
npm install
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
## Usage
|
|
@@ -88,7 +88,7 @@ The transpiled C++ file and executable will be generated in the same directory a
|
|
|
88
88
|
You can also run the test suite, which will transpile all the JavaScript test cases in `test/cases/`, build the resulting C++ files, and run them.
|
|
89
89
|
|
|
90
90
|
```sh
|
|
91
|
-
|
|
91
|
+
npm test
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
## Roadmap
|
package/dist/cli.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
1
|
+
#!/usr/bin/env node
|
|
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 =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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 =
|
|
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 =
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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 =
|
|
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 =
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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,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 =
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
{
|
|
94
|
+
stdio: "inherit",
|
|
95
|
+
}
|
|
96
|
+
);
|
|
95
97
|
|
|
96
|
-
if (compile.
|
|
98
|
+
if (compile.status !== 0) {
|
|
97
99
|
console.error(
|
|
98
100
|
`[${mode.name.toUpperCase()}] Failed to precompile headers.`,
|
|
99
101
|
);
|