Skip to content

Commit

Permalink
fix(cli): do not use : char in command filenames (#2544)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenko authored Apr 11, 2022
1 parent f5d34f6 commit 08a689b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-keys-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-frontend/mc-scripts': patch
---

Fix problem with file name in Windows when name contains characters like `:`.
17 changes: 12 additions & 5 deletions packages/mc-scripts/src/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ const applicationDirectory = fs.realpathSync(process.cwd());

// Get specific flag for this command.
const commandArgs = getArgsForCommand(['dry-run']);
proxyCommand(command, { commandArgs });
proxyCommand(command, {
commandArgs,
// File names with `:` cause issues in Windows, therefore the file name is
// different from the command name.
fileName: 'config-sync',
});
break;
}
default:
Expand All @@ -145,15 +150,17 @@ function getArgsForCommand(allowedFlags = []) {
}, []);
}

function proxyCommand(fileName, { commandArgs, noExit } = {}) {
function proxyCommand(commandName, { commandArgs, fileName, noExit } = {}) {
// Load dotenv files into the process environment.
// This is essentially what `dotenv-cli` does, but it's now built into this CLI.
loadDotEnvFiles(flags);

// Spawn the actual command.
const result = spawn.sync(
'node',
[require.resolve(`../commands/${fileName}`)].concat(commandArgs),
[require.resolve(`../commands/${fileName || commandName}`)].concat(
commandArgs
),
{ stdio: 'inherit' }
);

Expand All @@ -162,13 +169,13 @@ function proxyCommand(fileName, { commandArgs, noExit } = {}) {
switch (result.signal) {
case 'SIGKILL': {
console.log(
`The command ${fileName} failed because the process exited too early. This probably means the system ran out of memory or someone called "kill -9" on the process.`
`The command ${commandName} failed because the process exited too early. This probably means the system ran out of memory or someone called "kill -9" on the process.`
);
break;
}
case 'SIGTERM': {
console.log(
`The command ${fileName} failed because the process exited too early. Someone might have called "kill" or "killall", or the system could be shutting down.`
`The command ${commandName} failed because the process exited too early. Someone might have called "kill" or "killall", or the system could be shutting down.`
);
break;
}
Expand Down

1 comment on commit 08a689b

@vercel
Copy link

@vercel vercel bot commented on 08a689b Apr 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.