rip-lang 3.10.2 → 3.10.4

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.
Files changed (2) hide show
  1. package/bin/rip +28 -13
  2. package/package.json +1 -1
package/bin/rip CHANGED
@@ -1,9 +1,9 @@
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
- import { dirname, join } from 'path';
6
+ import { dirname, basename, join } from 'path';
7
7
  import { Compiler } from '../src/compiler.js';
8
8
  import { startREPL } from '../src/repl.js';
9
9
  import packageJson from '../package.json' with { type: 'json' };
@@ -180,25 +180,40 @@ async function main() {
180
180
  }
181
181
  }
182
182
 
183
- // If .rip file without compile flags → execute instead of compile
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 && inputFile.endsWith('.rip') && !hasCompileFlag) {
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
- try {
196
- execSync(`bun --preload ${loaderPath} ${inputFile} ${scriptArgs.join(' ')}`, {
197
- stdio: 'inherit'
198
- });
199
- process.exit(0);
200
- } catch (error) {
201
- process.exit(error.status || 1);
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), `.${basename(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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rip-lang",
3
- "version": "3.10.2",
3
+ "version": "3.10.4",
4
4
  "description": "A modern language that compiles to JavaScript",
5
5
  "type": "module",
6
6
  "main": "src/compiler.js",