Skip to content

npm package opens cli.js file instead of executing cli.js with node #2

@Thomas-Gallant

Description

@Thomas-Gallant

First, I want to say that I am really happy I found this library! I am surprised that it doesn't have more stars. Being able to benchmark Javascript code on different platforms is really great, and I was having trouble finding any tools that would do that. (I was worried I would have to try to build my own). Tachometer is another option but it only supports web browsers and requires all Javascript code to be within HTML files.

summary

When I try to run npm run benchmark on Windows after following the getting started instructions, the cli.js file is opened in my IDE instead of being executed.

I discovered that the npm documentation says the following:

Please make sure that your file(s) referenced in bin starts with #!/usr/bin/env node; otherwise, the scripts are started without the node executable!

I checked how some other libraries do it, and they add the above annotation in their bin files.

Typescript example:

#!/usr/bin/env node
require('../lib/tsc.js')

workaround

I am using the command node node_modules\esbench\lib\host\cli.js to bypass the npm shim to call the package directly.

additional details

npm uses cmd-shim to generate a esbench.cmd file inside of node_modules/.bin. Below is a comparison of the generated files for esbench vs typescript:

esbench.cmd

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0
"%dp0%\..\esbench\lib\host\cli.js"   %*

tsc.cmd

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\..\typescript\bin\tsc" %*

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions