Skip to content

Commit 7b863e1

Browse files
authored
chore: rewrite wrapper script in js (#139)
* chore: replace wrapper shell script with javascript implementation * Revert "chore: replace wrapper shell script with javascript implementation" This reverts commit 60db6be. * rewrite bin wrapper in js
1 parent 8e2a31b commit 7b863e1

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

bin/wrapper.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
4+
import { spawnSync } from "node:child_process";
5+
import { createRequire } from "node:module";
6+
import path from "node:path";
7+
import { fileURLToPath } from "node:url";
8+
9+
// Resolve __dirname from ESM environment
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
13+
// Set the environment variable for extra CA certificates
14+
let caCertPath = import.meta.resolve("node_extra_ca_certs_mozilla_bundle");
15+
caCertPath = new URL(caCertPath).pathname;
16+
caCertPath = path.dirname(caCertPath);
17+
caCertPath = path.join(caCertPath, "ca_bundle", "ca_intermediate_bundle.pem");
18+
process.env.NODE_EXTRA_CA_CERTS = caCertPath;
19+
20+
// The target script you want to run (relative to this script's directory)
21+
const targetScript = path.join(__dirname, "..", "src", "scan.js");
22+
23+
// Forward any arguments passed to this script
24+
const args = process.argv.slice(2);
25+
26+
// Spawn a new Node process to run the target script with inherited stdio
27+
const result = spawnSync(process.execPath, [targetScript, ...args], {
28+
stdio: "inherit",
29+
env: process.env,
30+
});
31+
32+
// Exit with the same code the spawned script returned
33+
process.exit(result.status ?? 1);

bin/wrapper.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"migrate": "node -e 'import(\"./src/database/migrate.js\").then( m => m.migrateDatabase() )'"
2020
},
2121
"bin": {
22-
"mdn-http-observatory-scan": "./bin/wrapper.sh"
22+
"mdn-http-observatory-scan": "./bin/wrapper.js"
2323
},
2424
"type": "module",
2525
"license": "MPL-2.0",

0 commit comments

Comments
 (0)