Skip to content

Commit bb6e846

Browse files
fix: implement package to preserve shebang
1 parent ea91bd6 commit bb6e846

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
},
1818
"scripts": {
1919
"start": "tsdx watch",
20-
"build": "tsdx build --target node",
20+
"addShebang": "node ./scripts/appendShebang.js",
21+
"build": "tsdx build --target node && npm run addShebang",
2122
"test": "tsdx test",
2223
"lint": "tsdx lint",
23-
"prepare": "tsdx build",
24+
"prepare": "npm run build",
2425
"size": "size-limit",
2526
"analyze": "size-limit --why"
2627
},
@@ -52,6 +53,7 @@
5253
"@size-limit/preset-small-lib": "^4.10.0",
5354
"del": "4.1.1",
5455
"husky": "^5.1.3",
56+
"rollup-plugin-preserve-shebang": "^1.0.1",
5557
"size-limit": "^4.10.0",
5658
"tsdx": "^0.14.1",
5759
"tslib": "^2.1.0",

scripts/appendShebang.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// https://github.com/formium/tsdx/issues/793
2+
// https://github.com/formium/tsdx/issues/338
3+
const path = require('path');
4+
const fs = require('fs');
5+
6+
const indexPath = path.join(__dirname, '../dist/index.js');
7+
8+
const content = fs.readFileSync(indexPath);
9+
fs.writeFile(indexPath, `#!/usr/bin/env node\n${content}`, err => {
10+
if (err) {
11+
console.error(err);
12+
process.exit(1);
13+
}
14+
console.log('> Successfully to add the Shebang to the dist/index.js file.');
15+
});

yarn.lock

+7
Original file line numberDiff line numberDiff line change
@@ -7226,6 +7226,13 @@ ripemd160@^2.0.0, ripemd160@^2.0.1:
72267226
hash-base "^3.0.0"
72277227
inherits "^2.0.1"
72287228

7229+
rollup-plugin-preserve-shebang@^1.0.1:
7230+
version "1.0.1"
7231+
resolved "https://registry.yarnpkg.com/rollup-plugin-preserve-shebang/-/rollup-plugin-preserve-shebang-1.0.1.tgz#17109cdb4ed12c3cac9379b802182427cdbee5a1"
7232+
integrity sha512-gk7ExGBqvUinhgrvldKHkAKXXwRkWMXMZymNkrtn50uBgHITlhRjhnKmbNGwAIc4Bzgl3yLv7/8Fhi/XeHhFKg==
7233+
dependencies:
7234+
magic-string "^0.25.7"
7235+
72297236
rollup-plugin-sourcemaps@^0.6.2:
72307237
version "0.6.3"
72317238
resolved "https://registry.yarnpkg.com/rollup-plugin-sourcemaps/-/rollup-plugin-sourcemaps-0.6.3.tgz#bf93913ffe056e414419607f1d02780d7ece84ed"

0 commit comments

Comments
 (0)