Skip to content

Commit

Permalink
chore: rewrite wrapper script in js (#139)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
argl authored Dec 18, 2024
1 parent 8e2a31b commit 7b863e1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
33 changes: 33 additions & 0 deletions bin/wrapper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env node
"use strict";

import { spawnSync } from "node:child_process";
import { createRequire } from "node:module";
import path from "node:path";
import { fileURLToPath } from "node:url";

// Resolve __dirname from ESM environment
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Set the environment variable for extra CA certificates
let caCertPath = import.meta.resolve("node_extra_ca_certs_mozilla_bundle");
caCertPath = new URL(caCertPath).pathname;
caCertPath = path.dirname(caCertPath);
caCertPath = path.join(caCertPath, "ca_bundle", "ca_intermediate_bundle.pem");
process.env.NODE_EXTRA_CA_CERTS = caCertPath;

// The target script you want to run (relative to this script's directory)
const targetScript = path.join(__dirname, "..", "src", "scan.js");

// Forward any arguments passed to this script
const args = process.argv.slice(2);

// Spawn a new Node process to run the target script with inherited stdio
const result = spawnSync(process.execPath, [targetScript, ...args], {
stdio: "inherit",
env: process.env,
});

// Exit with the same code the spawned script returned
process.exit(result.status ?? 1);
4 changes: 0 additions & 4 deletions bin/wrapper.sh

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"migrate": "node -e 'import(\"./src/database/migrate.js\").then( m => m.migrateDatabase() )'"
},
"bin": {
"mdn-http-observatory-scan": "./bin/wrapper.sh"
"mdn-http-observatory-scan": "./bin/wrapper.js"
},
"type": "module",
"license": "MPL-2.0",
Expand Down

0 comments on commit 7b863e1

Please sign in to comment.