elm-live icon indicating copy to clipboard operation
elm-live copied to clipboard

elm make separator -- is not seen as a command prompt argument in powershell unless it is quoted

Open olenitsj opened this issue 4 years ago • 1 comments

node --version v12.16.1.

elm --version 0.19.1

elm-live --version 4.0.2

When running: PS C:\Users\Igor\Documents\sources\repos\com.olenitsj> .\node_modules\.bin\elm-live.ps1 src/Main.elm -e node_modules/.bin/elm -- --output=main.js on Windows 10, power-shell.

Results in:

----------------------
|| ERROR IN COMMAND ||
----------------------
Usage: <elm-main> [options] [--] [elm make options]

-- Output In Wrong Location -----------------

You have used the elm make flag --output in the wrong location. As seen in the usage example about, all elm make flags must be added to your command after the -- separator.

image

The work around:

Quoting the -- e.g. PS C:\Users\Igor\Documents\sources\repos\com.olenitsj> .\node_modules\.bin\elm-live.ps1 src/Main.elm -e node_modules/.bin/elm '--' --output=main.js

Proposed solution:

Update example code to use '--', unless this is breaking some other behavior.

Or fix this part of the code:

In node_modules/elm-live/bin/elm-live.js:

const errorReducer = isHot => ([past, flags], arg) => {
  const isOutput = arg.includes('--output')
  if (!past && isOutput) {
    flags.wrongLocation = true
  }

  if (isHot && isOutput) {
    const target = arg.split('=')[1]
    const outputType = mime.getType(target)
    if (outputType !== 'application/javascript') {
      flags.needsJs = true
    }
  }

  return [past || arg === '--', flags]
}

The arg === '--' check is never true as the -- is never received as a parameter in program.rawArgs

Some related material:

https://stackoverflow.com/questions/43046885/what-does-do-when-running-an-npm-command https://stackoverflow.com/questions/15780174/powershell-command-line-parameters-and https://stackoverflow.com/questions/12197823/powershell-why-do-i-need-to-escape-a-double-dash-parameter-in-args

olenitsj avatar Mar 22 '20 21:03 olenitsj

Thanks for finding this bug! I will have to take a look. Maybe we can remove the need for it altogether 👌

wking-io avatar Apr 14 '20 22:04 wking-io