Skip to content

Commit 680fb69

Browse files
author
Maël Nison
committed
Implements a deprecation warning
1 parent 8b08820 commit 680fb69

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/cli/index.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ export function main({
110110
command = commands.run;
111111
}
112112

113+
let warnAboutRunDashDash = false;
113114
// we using "yarn <script> -abc" or "yarn run <script> -abc", we want -abc to be script options, not yarn options
114115
if (command === commands.run) {
115-
args.unshift('--');
116+
if (endArgs.length === 0) {
117+
endArgs = ['--', ... args.splice(1, args.length)];
118+
} else {
119+
warnAboutRunDashDash = true;
120+
}
116121
}
117122

118123
command.setFlags(commander);
@@ -124,7 +129,7 @@ export function main({
124129
...getRcArgs(commandName, args),
125130
...args,
126131
]);
127-
commander.args = commander.args.concat(endArgs);
132+
commander.args = commander.args.concat(endArgs.slice(1));
128133

129134
// we strip cmd
130135
console.assert(commander.args.length >= 1);
@@ -176,6 +181,11 @@ export function main({
176181
//
177182
const run = (): Promise<void> => {
178183
invariant(command, 'missing command');
184+
185+
if (warnAboutRunDashDash) {
186+
reporter.warn(reporter.lang('dashDashDeprecation'));
187+
}
188+
179189
return command.run(config, reporter, commander, commander.args).then(exitCode => {
180190
if (outputWrapper) {
181191
reporter.footer(false);
@@ -408,7 +418,7 @@ export default function start() {
408418
const doubleDashIndex = process.argv.findIndex(element => element === '--');
409419
const startArgs = process.argv.slice(0, 2);
410420
const args = process.argv.slice(2, doubleDashIndex === -1 ? process.argv.length : doubleDashIndex);
411-
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex + 1, process.argv.length);
421+
const endArgs = doubleDashIndex === -1 ? [] : process.argv.slice(doubleDashIndex, process.argv.length);
412422

413423
main({startArgs, args, endArgs});
414424
}

src/reporters/lang/en.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ const messages = {
188188

189189
execMissingCommand: 'Missing command name.',
190190

191+
dashDashDeprecation: "Using -- to pass arguments to your scripts isn't required anymore. Doing this may cause issues in future versions.",
191192
commandNotSpecified: 'No command specified.',
192193
binCommands: 'Commands available from binary scripts: ',
193194
possibleCommands: 'Project commands',

0 commit comments

Comments
 (0)