goscript 0.0.3 → 0.0.5

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.
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawn } from 'node:child_process';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { dirname } from 'node:path';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ // Go up two levels from cmd/goscript/ to the project root
11
+ const projectRoot = path.join(__dirname, '..', '..');
12
+
13
+ // Get arguments passed to the script, excluding node executable and script path
14
+ const args = process.argv.slice(2);
15
+
16
+ // Construct the go run command with the absolute path to the goscript executable
17
+ // Use path.join for robustness
18
+ const goscriptCmd = `go run ./cmd/goscript`;
19
+
20
+ // Combine the goscript command with the arguments
21
+ const command = `${goscriptCmd} ${args.join(" ")}`;
22
+
23
+ // Execute the command
24
+ const child = spawn(command, {
25
+ shell: true, // Use shell to correctly parse the command string
26
+ stdio: 'inherit', // Inherit stdin, stdout, and stderr
27
+ cwd: projectRoot, // Execute in the current working directory where the script is run
28
+ });
29
+
30
+ child.on('error', (error) => {
31
+ console.error(`Failed to start subprocess: ${error.message}`);
32
+ process.exit(1);
33
+ });
34
+
35
+ child.on('exit', (code) => {
36
+ process.exit(code ?? 0); // Exit with the child process's exit code
37
+ });
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "goscript",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Go to TypeScript compiler",
5
+ "bin": {
6
+ "goscript": "./cmd/goscript/main.js"
7
+ },
5
8
  "type": "module",
6
9
  "exports": {
7
10
  ".": {