Skip to content

Positional arguments in npm run-script #69

@piranna

Description

@piranna

promise-spawn/lib/index.js

Lines 116 to 123 in 8e99175

} else {
for (const arg of args) {
script += ` ${escape.sh(arg)}`
}
realArgs.push('-c', script)
}
return promiseSpawn(command, realArgs, options, extra)

We are concatenating the user provided arguments to the command_string, but POSIX shell -c flag allow extra arguments, one to set the $0 (process name) of the executed script from the command_string, and next ones to define the other positional arguments ($1, $2, $3...). It seems like a dumb change, but since we are just concatenating the strings to the real_args variable, $@ and $* are shown as empty, so for example it's not possible to use variables expansion with them like eslint ${@:-.} on package.json scripts to set current directory as default value if files argument are not provided when executing npm run.

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