Skip to content

Commit f553fde

Browse files
authoredNov 4, 2022
fix(generate): prevent type error when existing task (#3793)
this commit updates the generate task to suppress instances of hitting ctrl-c during the generate task would cause an error to be printed to the console: > TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument > must be of type string. Received undefined this was reported to have happened in v5.8 of zsh on MacOS, and was replicated using PowerShell on Windows.
1 parent c244082 commit f553fde

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed
 

‎src/cli/task-generate.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,25 @@ export const taskGenerate = async (coreCompiler: CoreCompiler, config: Validated
4040
config.flags.unknownArgs.find((arg) => !arg.startsWith('-')) ||
4141
((await prompt({ name: 'tagName', type: 'text', message: 'Component tag name (dash-case):' })).tagName as string);
4242

43+
if (undefined === input) {
44+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
45+
// explicitly return here to avoid printing the error message.
46+
return;
47+
}
4348
const { dir, base: componentName } = path.parse(input);
4449

4550
const tagError = validateComponentTag(componentName);
4651
if (tagError) {
4752
config.logger.error(tagError);
4853
return config.sys.exit(1);
4954
}
50-
51-
const extensionsToGenerate: GenerableExtension[] = ['tsx', ...(await chooseFilesToGenerate())];
55+
const filesToGenerateExt = await chooseFilesToGenerate();
56+
if (undefined === filesToGenerateExt) {
57+
// in some shells (e.g. Windows PowerShell), hitting Ctrl+C results in a TypeError printed to the console.
58+
// explicitly return here to avoid printing the error message.
59+
return;
60+
}
61+
const extensionsToGenerate: GenerableExtension[] = ['tsx', ...filesToGenerateExt];
5262

5363
const testFolder = extensionsToGenerate.some(isTest) ? 'test' : '';
5464

0 commit comments

Comments
 (0)
Please sign in to comment.