Skip to content
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

fix(cli): do not use : char in command filenames #2544

Merged
merged 1 commit into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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