rip-lang 3.10.2 → 3.10.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/bin/rip +27 -12
- package/package.json +1 -1
package/bin/rip
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
|
|
3
|
-
import { readFileSync, writeFileSync, existsSync, statSync } from 'fs';
|
|
3
|
+
import { readFileSync, writeFileSync, existsSync, statSync, unlinkSync } from 'fs';
|
|
4
4
|
import { execSync, spawn } from 'child_process';
|
|
5
5
|
import { fileURLToPath } from 'url';
|
|
6
6
|
import { dirname, join } from 'path';
|
|
@@ -180,25 +180,40 @@ async function main() {
|
|
|
180
180
|
}
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
// If
|
|
183
|
+
// If no compile flags → execute the script instead of compiling it
|
|
184
184
|
const hasCompileFlag = showCompiled || showTokens || showSExpr || generateDts || generateMap || outputFile;
|
|
185
|
-
if (inputFile &&
|
|
186
|
-
// Check if file exists
|
|
185
|
+
if (inputFile && !hasCompileFlag) {
|
|
187
186
|
if (!existsSync(inputFile)) {
|
|
188
187
|
console.error(`Error: File not found: ${inputFile}`);
|
|
189
188
|
process.exit(1);
|
|
190
189
|
}
|
|
191
190
|
|
|
192
|
-
// Execute the script with Bun using our loader
|
|
193
191
|
const loaderPath = join(__dirname, '../rip-loader.js');
|
|
194
192
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
193
|
+
if (inputFile.endsWith('.rip')) {
|
|
194
|
+
try {
|
|
195
|
+
execSync(`bun --preload ${loaderPath} ${inputFile} ${scriptArgs.join(' ')}`, {
|
|
196
|
+
stdio: 'inherit'
|
|
197
|
+
});
|
|
198
|
+
process.exit(0);
|
|
199
|
+
} catch (error) {
|
|
200
|
+
process.exit(error.status || 1);
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
// Non-.rip files (e.g. shebang scripts): compile, write temp file, execute
|
|
204
|
+
const source = readFileSync(inputFile, 'utf-8');
|
|
205
|
+
const compiler = new Compiler();
|
|
206
|
+
const result = compiler.compile(source);
|
|
207
|
+
const tmp = join(dirname(inputFile), `.${inputFile}.__rip__.mjs`);
|
|
208
|
+
let exitCode = 0;
|
|
209
|
+
try {
|
|
210
|
+
writeFileSync(tmp, result.code);
|
|
211
|
+
execSync(`bun --preload ${loaderPath} "${tmp}" ${scriptArgs.join(' ')}`, { stdio: 'inherit' });
|
|
212
|
+
} catch (error) {
|
|
213
|
+
exitCode = error.status || 1;
|
|
214
|
+
}
|
|
215
|
+
try { unlinkSync(tmp); } catch {}
|
|
216
|
+
process.exit(exitCode);
|
|
202
217
|
}
|
|
203
218
|
}
|
|
204
219
|
|