From aca7a733bd08d1a423b76ab1586f22afce2eeb47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Fut=C3=A1sz?= Date: Wed, 23 Jan 2019 16:38:18 +0100 Subject: [PATCH 1/5] Fix void type for cp return value to ShellArray cp function returns an object that is e.g. important for error code checking. --- types/shelljs/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 1f1eb5c375..9b5c6a76a7 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -4,6 +4,7 @@ // Vojtech Jasny // George Kalpakas // Paul Huynh +// Alexander Futász // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -50,7 +51,7 @@ export function find(...path: Array): ShellArray; * @param source The source. * @param dest The destination. */ -export function cp(source: string | string[], dest: string): void; +export function cp(source: string | string[], dest: string): ShellArray; /** * Copies files. The wildcard * is accepted. From 6ff82ecb633f8f56bfde045589639440c7e620f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Fut=C3=A1sz?= Date: Thu, 24 Jan 2019 11:03:42 +0100 Subject: [PATCH 2/5] Change return value of all cp functions to ShellString --- types/shelljs/index.d.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 9b5c6a76a7..85c930be0a 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -50,16 +50,18 @@ export function find(...path: Array): ShellArray; * Copies files. The wildcard * is accepted. * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function cp(source: string | string[], dest: string): ShellArray; +export function cp(source: string | string[], dest: string): ShellString; /** * Copies files. The wildcard * is accepted. * @param options Available options: -f: force (default behavior) -n: no-clobber -u: only copy if source is newer than dest -r, -R: recursive -L: follow symlinks -P: don't follow symlinks * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function cp(options: string, source: string | string[], dest: string): void; +export function cp(options: string, source: string | string[], dest: string): ShellString; /** * Removes files. The wildcard * is accepted. From d95b487d88baa1b7331ca5188af7a558c4557243 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Fut=C3=A1sz?= Date: Thu, 24 Jan 2019 11:06:55 +0100 Subject: [PATCH 3/5] Fix return type for cd, rm, mv, mkdir, ln, chmod, touch to ShellString --- types/shelljs/index.d.ts | 47 +++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 85c930be0a..c47a9410c1 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -15,8 +15,9 @@ import glob = require("glob"); /** * Changes to directory dir for the duration of the script. Changes to home directory if no argument is supplied. * @param dir Directory to change in. + * @return Object with shell exit code. */ -export function cd(dir?: string): void; +export function cd(dir?: string): ShellString; /** * Returns the current directory. @@ -66,43 +67,49 @@ export function cp(options: string, source: string | string[], dest: string): Sh /** * Removes files. The wildcard * is accepted. * @param ...files Files to remove. + * @return Object with shell exit code. */ -export function rm(...files: Array): void; +export function rm(...files: Array): ShellString; /** * Removes files. The wildcard * is accepted. * @param options Available options: -f (force), -r, -R (recursive) * @param ...files Files to remove. + * @return Object with shell exit code. */ -export function rm(options: string, ...files: Array): void; +export function rm(options: string, ...files: Array): ShellString; /** * Moves files. The wildcard * is accepted. * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function mv(source: string | string[], dest: string): void; +export function mv(source: string | string[], dest: string): ShellString; /** * Moves files. The wildcard * is accepted. * @param options Available options: -f: force (default behavior) -n: no-clobber * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function mv(options: string, source: string | string[], dest: string): void; +export function mv(options: string, source: string | string[], dest: string): ShellString; /** * Creates directories. * @param ...dir Directories to create. + * @return Object with shell exit code. */ -export function mkdir(...dir: Array): void; +export function mkdir(...dir: Array): ShellString; /** * Creates directories. * @param options Available options: p (full paths, will create intermediate dirs if necessary) * @param ...dir The directories to create. + * @return Object with shell exit code. */ -export function mkdir(options: string, ...dir: Array): void; +export function mkdir(options: string, ...dir: Array): ShellString; /** * Evaluates expression using the available primaries and returns corresponding value. @@ -307,16 +314,18 @@ export function dirs(options: string): any; * Links source to dest. Use -f to force the link, should dest already exist. * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function ln(source: string, dest: string): void; +export function ln(source: string, dest: string): ShellString; /** * Links source to dest. Use -f to force the link, should dest already exist. * @param options Available options: s (symlink), f (force) * @param source The source. * @param dest The destination. + * @return Object with shell exit code. */ -export function ln(options: string, source: string, dest: string): void; +export function ln(options: string, source: string, dest: string): ShellString; /** * Exits the current process with the given exit code. @@ -403,8 +412,9 @@ export type ShellArray = string[] & ShellReturnValue; * - There is no "quiet" option since default behavior is to run silent. * @param octalMode The access mode. Octal. * @param file The file to use. + * @return Object with shell exit code. */ -export function chmod(octalMode: number, file: string): void; +export function chmod(octalMode: number, file: string): ShellString; /** * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: @@ -413,8 +423,9 @@ export function chmod(octalMode: number, file: string): void; * @param options Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively) * @param octalMode The access mode. Octal. * @param file The file to use. + * @return Object with shell exit code. */ -export function chmod(options: string, octalMode: number, file: string): void; +export function chmod(options: string, octalMode: number, file: string): ShellString; /** * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: @@ -422,8 +433,9 @@ export function chmod(options: string, octalMode: number, file: string): void; * - There is no "quiet" option since default behavior is to run silent. * @param mode The access mode. Can be an octal string or a symbolic mode string. * @param file The file to use. + * @return Object with shell exit code. */ -export function chmod(mode: string, file: string): void; +export function chmod(mode: string, file: string): ShellString; /** * Alters the permissions of a file or directory by either specifying the absolute permissions in octal form or expressing the changes in symbols. This command tries to mimic the POSIX behavior as much as possible. Notable exceptions: @@ -432,8 +444,9 @@ export function chmod(mode: string, file: string): void; * @param options Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively) * @param mode The access mode. Can be an octal string or a symbolic mode string. * @param file The file to use. + * @return Object with shell exit code. */ -export function chmod(options: string, mode: string, file: string): void; +export function chmod(options: string, mode: string, file: string): ShellString; // Non-Unix commands @@ -459,10 +472,10 @@ export interface TouchOptionsArray { '-r'?: string; } -export function touch(...files: string[]): void; -export function touch(files: string[]): void; -export function touch(options: TouchOptionsLiteral, ...files: Array): void; -export function touch(options: TouchOptionsArray, ...files: Array): void; +export function touch(...files: string[]): ShellString; +export function touch(files: string[]): ShellString; +export function touch(options: TouchOptionsLiteral, ...files: Array): ShellString; +export function touch(options: TouchOptionsArray, ...files: Array): ShellString; export interface HeadOptions { /** Show the first lines of the files. */ From aad32876fcaea679ccd813de583bd5d0e5c6e7d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Fut=C3=A1sz?= Date: Thu, 24 Jan 2019 11:15:54 +0100 Subject: [PATCH 4/5] Fix expected return type error --- types/shelljs-exec-proxy/shelljs-exec-proxy-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/shelljs-exec-proxy/shelljs-exec-proxy-tests.ts b/types/shelljs-exec-proxy/shelljs-exec-proxy-tests.ts index 71b7038a44..be6bde704d 100644 --- a/types/shelljs-exec-proxy/shelljs-exec-proxy-tests.ts +++ b/types/shelljs-exec-proxy/shelljs-exec-proxy-tests.ts @@ -5,5 +5,5 @@ shell.git.add('.'); // $ExpectType ExecOutputReturnValue shell.git.commit('-am', 'Fixed issue #1'); // $ExpectType ExecOutputReturnValue shell.git.push('origin', 'master'); // $ExpectType ExecOutputReturnValue -shell.cd('string'); // $ExpectType void +shell.cd('string'); // $ExpectType ShellString shell.cd(123); // $ExpectError From 392f6235e5e93c07121f44f94999d30c84ed44f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Fut=C3=A1sz?= Date: Fri, 25 Jan 2019 15:05:41 +0100 Subject: [PATCH 5/5] Use more detailed return annotation --- types/shelljs/index.d.ts | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index c47a9410c1..38f55bfceb 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -15,7 +15,7 @@ import glob = require("glob"); /** * Changes to directory dir for the duration of the script. Changes to home directory if no argument is supplied. * @param dir Directory to change in. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function cd(dir?: string): ShellString; @@ -51,7 +51,7 @@ export function find(...path: Array): ShellArray; * Copies files. The wildcard * is accepted. * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function cp(source: string | string[], dest: string): ShellString; @@ -60,14 +60,14 @@ export function cp(source: string | string[], dest: string): ShellString; * @param options Available options: -f: force (default behavior) -n: no-clobber -u: only copy if source is newer than dest -r, -R: recursive -L: follow symlinks -P: don't follow symlinks * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function cp(options: string, source: string | string[], dest: string): ShellString; /** * Removes files. The wildcard * is accepted. * @param ...files Files to remove. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function rm(...files: Array): ShellString; @@ -75,7 +75,7 @@ export function rm(...files: Array): ShellString; * Removes files. The wildcard * is accepted. * @param options Available options: -f (force), -r, -R (recursive) * @param ...files Files to remove. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function rm(options: string, ...files: Array): ShellString; @@ -83,7 +83,7 @@ export function rm(options: string, ...files: Array): ShellSt * Moves files. The wildcard * is accepted. * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function mv(source: string | string[], dest: string): ShellString; @@ -92,14 +92,14 @@ export function mv(source: string | string[], dest: string): ShellString; * @param options Available options: -f: force (default behavior) -n: no-clobber * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function mv(options: string, source: string | string[], dest: string): ShellString; /** * Creates directories. * @param ...dir Directories to create. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function mkdir(...dir: Array): ShellString; @@ -107,7 +107,7 @@ export function mkdir(...dir: Array): ShellString; * Creates directories. * @param options Available options: p (full paths, will create intermediate dirs if necessary) * @param ...dir The directories to create. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function mkdir(options: string, ...dir: Array): ShellString; @@ -314,7 +314,7 @@ export function dirs(options: string): any; * Links source to dest. Use -f to force the link, should dest already exist. * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function ln(source: string, dest: string): ShellString; @@ -323,7 +323,7 @@ export function ln(source: string, dest: string): ShellString; * @param options Available options: s (symlink), f (force) * @param source The source. * @param dest The destination. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function ln(options: string, source: string, dest: string): ShellString; @@ -412,7 +412,7 @@ export type ShellArray = string[] & ShellReturnValue; * - There is no "quiet" option since default behavior is to run silent. * @param octalMode The access mode. Octal. * @param file The file to use. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function chmod(octalMode: number, file: string): ShellString; @@ -423,7 +423,7 @@ export function chmod(octalMode: number, file: string): ShellString; * @param options Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively) * @param octalMode The access mode. Octal. * @param file The file to use. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function chmod(options: string, octalMode: number, file: string): ShellString; @@ -433,7 +433,7 @@ export function chmod(options: string, octalMode: number, file: string): ShellSt * - There is no "quiet" option since default behavior is to run silent. * @param mode The access mode. Can be an octal string or a symbolic mode string. * @param file The file to use. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function chmod(mode: string, file: string): ShellString; @@ -444,7 +444,7 @@ export function chmod(mode: string, file: string): ShellString; * @param options Available options: -v (output a diagnostic for every file processed), -c (like -v but report only when a change is made), -R (change files and directories recursively) * @param mode The access mode. Can be an octal string or a symbolic mode string. * @param file The file to use. - * @return Object with shell exit code. + * @return Object with shell exit code, stderr and stdout. */ export function chmod(options: string, mode: string, file: string): ShellString;