Skip to content

Commit d40d3f7

Browse files
authored
Fix published executable (#42)
Executables — files that ship with packages that are meant to be executed and which are specified via the `bin` field in `package.json` — aren't automatically run through Node. The standard way to do this is to add a hashbang line to the executable. Since we are using TypeScript, and we have to go through a compilation step before we publish the package, we have two options: * Add `#!/usr/bin/env node` to the top of `src/cli.ts` * Make a new file *not* written in TypeScript which will execute the compiled version of the CLI The former seems confusing, because it's impossible to run a TypeScript file through `node`, so we go with the latter.
1 parent 1cb2e17 commit d40d3f7

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

bin/create-release-branch.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
/* eslint-disable-next-line import/no-unassigned-import */
4+
require('../dist/cli');

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
"type": "git",
77
"url": "https://github.com/MetaMask/create-release-branch.git"
88
},
9-
"bin": "dist/cli.js",
9+
"bin": "bin/create-release-branch.js",
1010
"files": [
11+
"bin/",
1112
"dist/"
1213
],
1314
"scripts": {
@@ -17,7 +18,7 @@
1718
"lint:eslint": "eslint . --cache --ext js,ts",
1819
"lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
1920
"lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' '**/*.yml' '!.yarnrc.yml' --ignore-path .gitignore --no-error-on-unmatched-pattern",
20-
"prepack": "yarn build:clean && chmod +x dist/cli.js && yarn lint && yarn test",
21+
"prepack": "yarn lint && yarn build:clean && yarn test",
2122
"test": "jest && jest-it-up",
2223
"test:watch": "jest --watch"
2324
},

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ __metadata:
909909
yaml: ^2.1.1
910910
yargs: ^17.5.1
911911
bin:
912-
create-release-branch: dist/cli.js
912+
create-release-branch: bin/create-release-branch.js
913913
languageName: unknown
914914
linkType: soft
915915

0 commit comments

Comments
 (0)