Skip to content

Commit

Permalink
add script to update hashbang
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Nov 21, 2024
1 parent ac2a12d commit 139be14
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"test:ci": "mocha --recursive ./test --require ./test/mocha-root-hooks.mjs --reporter mocha-multi-reporters --reporter-options configFile=./test/config/reporter.json",
"build": "npm run build:app && npm run build:sea",
"build:app": "esbuild --bundle ./src/user-entrypoint.mjs --platform=node --outfile=./dist/cli.cjs --format=cjs --inject:./sea/import-meta-url.js --define:import.meta.url=importMetaUrl",
"postbuild:app": "sed -i '' '1s/.*/#!\\/usr\\/bin\\/env NODE_NO_WARNINGS=1 node/' ./dist/cli.cjs",
"postbuild:app": "node ./scripts/update-prod-hashbang.mjs",
"build:sea": "node ./sea/build.cjs",
"format": "prettier -w ."
},
Expand Down
15 changes: 15 additions & 0 deletions scripts/update-prod-hashbang.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node
import * as fs from "node:fs";
import * as path from "node:path";

const __dirname = import.meta.dirname;

const filePath = path.resolve(path.join(__dirname, "../dist/cli.cjs"));
let fileContents = fs.readFileSync(filePath);
const endOfFirstLine = fileContents.indexOf("\n");
fileContents = fileContents.slice(endOfFirstLine);
fileContents = `#!/usr/bin/env NODE_NO_WARNINGS=1 node\n${fileContents}`;
fs.rmSync(filePath);
fs.writeFileSync(filePath, fileContents, {
mode: 755,
});
2 changes: 2 additions & 0 deletions test/general-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe("cli operations", function () {
it("enables nodeJS warnings from the dev entrypoint", async function () {
let stderr = spawnSync("./src/user-entrypoint.mjs", ["warn"], {
encoding: "utf8",
shell: true,
stdio: "pipe",
}).stderr;

Expand All @@ -140,6 +141,7 @@ describe("cli operations", function () {
it("suppresses nodeJS warnings from the prod entrypoint", async function () {
let stderr = spawnSync("./dist/cli.cjs", ["warn"], {
encoding: "utf8",
shell: true,
stdio: "pipe",
}).stderr;

Expand Down

0 comments on commit 139be14

Please sign in to comment.