Skip to content

Commit

Permalink
Wrap CLI in Node runner for platform independence
Browse files Browse the repository at this point in the history
Linux needs `#!/usr/bin/env -S` but this breaks Windows shims
<npm/cmd-shim#54>

Wrap in another layer of Node as a workaround.
  • Loading branch information
edemaine committed Aug 10, 2022
1 parent bf7c223 commit f994fcf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
9 changes: 9 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env node
// Cross-platform launcher for Node with source-map support
require('child_process').spawnSync('node', [
'--enable-source-maps',
require('path').join(__dirname, 'lib/svgtiler.js'),
...process.argv.slice(2)
], {
stdio: 'inherit'
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
},
"main": "lib/svgtiler.js",
"bin": {
"svgtiler": "lib/svgtiler.js"
"svgtiler": "cli.js"
},
"preferGlobal": true,
"scripts": {
"prepare": "coffee --no-header --bare -o lib -c src/svgtiler.coffee",
"prepare": "coffee -o lib -c src/svgtiler.coffee",
"test": "make test"
},
"dependencies": {
Expand Down
6 changes: 0 additions & 6 deletions src/svgtiler.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
`#!/usr/bin/env -S node --enable-source-maps
(function() {
`

unless window?
path = require 'path'
fs = require 'fs'
Expand Down Expand Up @@ -1616,5 +1612,3 @@ if module? and require?.main == module and not window?
require('module').Module._initPaths()

main()

`}).call(this)`

0 comments on commit f994fcf

Please sign in to comment.