-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow arguments to be passed to npm scripts #356
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test the withinEnv
case again and post the results here. Thanks.
@@ -265,7 +265,7 @@ class Generator extends Base { | |||
// no pre post test tasks | |||
cmds.filter((s) => toPatch.test(s)).forEach((s) => { | |||
// generate scoped tasks | |||
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s}'"`; | |||
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s}'" --`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s}'" --`; | |
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s} --'"`; |
@oltionchampari Did you test this case? @anita-steiner and I assume that the --
must be placed directly after the run command (as in the other change above). It could even be that this does not work at all, as you want to pass arguments through multiple layers (e.g., withinEnv
and exec
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running npm run check:phovea_server
or any other withinEnv
command from the workspace results in an error.
I do not know if there is a problem with my docker setup or the withinEnv
script is outdated.
@thinkh Could you please test if the commands work for you. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This whole command does not work...
Investigation report
- (I had to switch the line ending for withinEnv from
CRLF
toLF
, which might be caused by my Windows) - I can confirm your results; I get the same output
- Executing the command from withinEnv manually (
docker-compose run --service-ports api
) starts the container docker-compose run --service-ports api exec
results inError response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"exec\": executable file not found in $PATH": unknown
- Checking the docker documentation it can be either
docker-compose run
ORdocker-compose exec
- There is no such command
docker-compose run ... exec
- Checking the docker documentation it can be either
docker-compose run --service-ports api /bin/sh
results in a terminal inside the container- However,
npm -v
fails with/bin/sh: 2: npm: not found
, as npm is not part of thepython:3.7
base image!
- However,
docker-compose run --service-ports api /bin/sh -c "cd phovea_server && npm run test"
should be the correct command, but it also fails with/bin/sh: 1: npm: not found
(see previous point)- Replacing
docker-compose run --service-ports api
withwithinEnv
(command:./withinEnv /bin/sh -c "cd phovea_server && echo test"
) printsdocker-compose run --service-ports api /bin/sh -c cd phovea_server && echo test
, i.e., without additional quotes and results in an empty terminal output - Escaping the command
./withinEnv "/bin/sh -c \"cd phovea_server && echo test\""
results indocker-compose run --service-ports api /bin/sh -c "cd phovea_server && echo test"
and printsphovea_server: 1: phovea_server: Syntax error: Unterminated quoted string
- Since the print statement itself works, but the execution itself fails it must be a problem with the
$@
- Reading the documentation about
$@
it seems that it is not possible to pass strings from incoming parameter to the subsequent command - An alternative syntax to
-c
is the<<<
syntax (see https://stackoverflow.com/a/40487106)
- Since the print statement itself works, but the execution itself fails it must be a problem with the
./withinEnv /bin/bash <<< "cd phovea_server && echo test"
results in the expected outputtest
- Note that the whole bin/sh command is not wrapped in single quotes so that
$@
can expand it as different paramters and pass it down todocker-compose
- Note that the whole bin/sh command is not wrapped in single quotes so that
- Copying the new command to package.json (
"test:phovea_server": "./withinEnv /bin/bash <<< \"cd phovea_server && npm run test\""
) and executingnpm run test:phovea_server
results in the following error:sh: 1: Syntax error: redirection unexpected
- I found no obvious way how to fix this syntax in the npm script
- The only solution I found is to move the redirection into the
withinEnv
:docker-compose run --service-ports api /bin/bash <<< $@
- Change the npm script to
./withinEnv \"cd phovea_server && npm run test\"
- Running
npm run test:phovea_server
results in the expected/bin/sh: 1: npm: not found
- Now only the npm script
npm run start:phovea_server
does not work anymore and needs to be changed to"start:phovea_server": "./withinEnv \"cd phovea_server && npm run start\"",
- Alternatively we can use
"start:phovea_server": "./withinEnv \"python phovea_server\"",
to start the phovea server
- Alternatively we can use
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See investigation report for the full list of commands I tried.
TL;DR
Long story short... this command will never work, since npm
is not part of the python:3.7
base image.
Beside that fact the exec
call needs to be removed and the quotes needs to be changed from the npm scripts:
"start:phovea_server": "./withinEnv \"cd phovea_server && npm run start\"",
"check:phovea_server": "./withinEnv \"cd phovea_server && npm run check\"",
"test:phovea_server": "./withinEnv \"cd phovea_server && npm run test\"",
"dist:phovea_server": "./withinEnv \"cd phovea_server && npm run dist\""
Last the withinEnv needs to be adapted by the /bin/sh <<<
call:
#!/usr/bin/env bash
set -e
echo "docker-compose run --service-ports api /bin/bash <<< $@"
docker-compose run --service-ports api /bin/bash <<< $@
Finally, I'm not really sure, if we need the --
at all since all parameters are passed $@
to the bash. I couldn't test it with the npm script either since npm is not installed.
@@ -265,7 +265,7 @@ class Generator extends Base { | |||
// no pre post test tasks | |||
cmds.filter((s) => toPatch.test(s)).forEach((s) => { | |||
// generate scoped tasks | |||
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s}'"`; | |||
let cmd = `.${path.sep}withinEnv "exec 'cd ${p} && npm run ${s}'" --`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. This whole command does not work...
Investigation report
- (I had to switch the line ending for withinEnv from
CRLF
toLF
, which might be caused by my Windows) - I can confirm your results; I get the same output
- Executing the command from withinEnv manually (
docker-compose run --service-ports api
) starts the container docker-compose run --service-ports api exec
results inError response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"exec\": executable file not found in $PATH": unknown
- Checking the docker documentation it can be either
docker-compose run
ORdocker-compose exec
- There is no such command
docker-compose run ... exec
- Checking the docker documentation it can be either
docker-compose run --service-ports api /bin/sh
results in a terminal inside the container- However,
npm -v
fails with/bin/sh: 2: npm: not found
, as npm is not part of thepython:3.7
base image!
- However,
docker-compose run --service-ports api /bin/sh -c "cd phovea_server && npm run test"
should be the correct command, but it also fails with/bin/sh: 1: npm: not found
(see previous point)- Replacing
docker-compose run --service-ports api
withwithinEnv
(command:./withinEnv /bin/sh -c "cd phovea_server && echo test"
) printsdocker-compose run --service-ports api /bin/sh -c cd phovea_server && echo test
, i.e., without additional quotes and results in an empty terminal output - Escaping the command
./withinEnv "/bin/sh -c \"cd phovea_server && echo test\""
results indocker-compose run --service-ports api /bin/sh -c "cd phovea_server && echo test"
and printsphovea_server: 1: phovea_server: Syntax error: Unterminated quoted string
- Since the print statement itself works, but the execution itself fails it must be a problem with the
$@
- Reading the documentation about
$@
it seems that it is not possible to pass strings from incoming parameter to the subsequent command - An alternative syntax to
-c
is the<<<
syntax (see https://stackoverflow.com/a/40487106)
- Since the print statement itself works, but the execution itself fails it must be a problem with the
./withinEnv /bin/bash <<< "cd phovea_server && echo test"
results in the expected outputtest
- Note that the whole bin/sh command is not wrapped in single quotes so that
$@
can expand it as different paramters and pass it down todocker-compose
- Note that the whole bin/sh command is not wrapped in single quotes so that
- Copying the new command to package.json (
"test:phovea_server": "./withinEnv /bin/bash <<< \"cd phovea_server && npm run test\""
) and executingnpm run test:phovea_server
results in the following error:sh: 1: Syntax error: redirection unexpected
- I found no obvious way how to fix this syntax in the npm script
- The only solution I found is to move the redirection into the
withinEnv
:docker-compose run --service-ports api /bin/bash <<< $@
- Change the npm script to
./withinEnv \"cd phovea_server && npm run test\"
- Running
npm run test:phovea_server
results in the expected/bin/sh: 1: npm: not found
- Now only the npm script
npm run start:phovea_server
does not work anymore and needs to be changed to"start:phovea_server": "./withinEnv \"cd phovea_server && npm run start\"",
- Alternatively we can use
"start:phovea_server": "./withinEnv \"python phovea_server\"",
to start the phovea server
- Alternatively we can use
Closes #354
Developer Checklist (Definition of Done)
release: minor
) to this PR following semverSummary of changes
--
to npm scripts.--
to the server scripts, i am not sure that is necessary but it has no effect on the functionality.To test
"myscript":"git"
yo phovea:update
in workspacenpm run myscript:<plugin> -- -b my_branch