From abf09ab21f9efe922309bc10d6044b7ced159865 Mon Sep 17 00:00:00 2001 From: Mirco Sanguineti <19243840+msanguineti@users.noreply.github.com> Date: Fri, 12 Apr 2019 09:35:14 +0300 Subject: [PATCH 1/5] feat(shelljs): single param construct and function signatures --- types/shelljs/index.d.ts | 45 ++++++++++++++++++++++++++++++++++ types/shelljs/make.d.ts | 1 + types/shelljs/shelljs-tests.ts | 28 ++++++++++++--------- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 0301f2c1e0..bd26c0e3cb 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -965,6 +965,51 @@ export type ShellString = string & ShellReturnValue; export type ShellArray = string[] & ShellReturnValue; +export const ShellString: ShellStringFunction; + +export interface ShellStringFunction { + /** + * Wraps a string (or array) value. This has all the string (or array) methods, + * but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able + * methods (ex. `.cat()`, `.grep()`, etc.). + * + * This can be easily converted into a string by calling `.toString()`. + * + * This type also exposes the corresponding command's stdout, stderr, and return status + * code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties + * respectively. + * + * Construct signature allows for: + * + * var foo = new ShellString('hello world'); + * + * as per example in shelljs docs: + * https://github.com/shelljs/shelljs#shellstringstr + * + * @param value The string value to wrap. + * @return A string-like object with special methods. + */ + new(value: string): ShellString; + new(value: string[]): ShellArray; + + /** + * Wraps a string (or array) value. This has all the string (or array) methods, + * but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able + * methods (ex. `.cat()`, `.grep()`, etc.). + * + * This can be easily converted into a string by calling `.toString()`. + * + * This type also exposes the corresponding command's stdout, stderr, and return status + * code via the `.stdout` (string), `.stderr` (string), and `.code` (number) properties + * respectively. + * + * @param value The string value to wrap. + * @return A string-like object with special methods. + */ + (value: string): ShellString; + (value: string[]): ShellArray; +} + export interface ChmodFunction { /** * Alters the permissions of a file or directory by either specifying the absolute diff --git a/types/shelljs/make.d.ts b/types/shelljs/make.d.ts index b6b6f99fa9..652b0cfb45 100644 --- a/types/shelljs/make.d.ts +++ b/types/shelljs/make.d.ts @@ -39,4 +39,5 @@ declare global { const tempdir: typeof shelljs.tempdir; const touch: typeof shelljs.touch; const uniq: typeof shelljs.uniq; + const ShellString: typeof shelljs.ShellString; } diff --git a/types/shelljs/shelljs-tests.ts b/types/shelljs/shelljs-tests.ts index 37d8933e39..50ec3c2cc5 100644 --- a/types/shelljs/shelljs-tests.ts +++ b/types/shelljs/shelljs-tests.ts @@ -89,24 +89,24 @@ const testPath = shell.env["path"]; const version = shell.exec("node --version").stdout; // $ExpectType ShellString -const version2 = shell.exec("node --version", {async: false}); +const version2 = shell.exec("node --version", { async: false }); const output = version2.stdout; // $ExpectType ChildProcess -const asyncVersion3 = shell.exec("node --version", {async: true}); +const asyncVersion3 = shell.exec("node --version", { async: true }); let pid = asyncVersion3.pid; declare let isAsync: boolean; // $ExpectType ShellString | ChildProcess -const unknownUntilRuntime = shell.exec("node --version", {async: isAsync}); +const unknownUntilRuntime = shell.exec("node --version", { async: isAsync }); -shell.exec("node --version", {silent: true}, (code, stdout, stderr) => { +shell.exec("node --version", { silent: true }, (code, stdout, stderr) => { const version = stdout; }); shell.exec( "node --version", - {silent: true, async: true, cwd: "/usr/local/bin"}, + { silent: true, async: true, cwd: "/usr/local/bin" }, (code, stdout, stderr) => { const version = stdout; } @@ -149,18 +149,18 @@ shell.touch("-c", "/Users/brandom/test1"); shell.touch("-c", "/Users/brandom/test1", "/Users/brandom/test2"); shell.touch("-c", ["/Users/brandom/test1", "/Users/brandom/test2"]); -shell.touch({"-r": "/some/file.txt"}, "/Users/brandom/test1"); +shell.touch({ "-r": "/some/file.txt" }, "/Users/brandom/test1"); shell.touch( - {"-r": "/some/file.txt"}, + { "-r": "/some/file.txt" }, "/Users/brandom/test1", "/Users/brandom/test2" ); -shell.touch({"-r": "/oome/file.txt"}, [ +shell.touch({ "-r": "/oome/file.txt" }, [ "/Users/brandom/test1", "/Users/brandom/test2" ]); -shell.head({"-n": 1}, "file*.txt"); +shell.head({ "-n": 1 }, "file*.txt"); shell.head("file1", "file2"); shell.head(["file1", "file2"]); // same as above @@ -169,7 +169,7 @@ shell.sort("-r", "foo.txt"); shell.sort("-r", ["file.txt"]); shell.sort(["file.txt"]); -shell.tail({"-n": 1}, "file*.txt"); +shell.tail({ "-n": 1 }, "file*.txt"); shell.tail("file1", "file2"); shell.tail(["file1", "file2"]); // same as above @@ -195,4 +195,10 @@ shell.config.globOptions = { shell .ls("dir") .grep(/^stuff/) - .head({"-n": 5}).stdout; + .head({ "-n": 5 }).stdout; + +const foo = new shell.ShellString('hello world'); +const farr = new shell.ShellString(['hello', 'world']); + +const bar = shell.ShellString('hello world'); +const barr = shell.ShellString(['hello', 'world']); From d2e7e589a98348dc60955dcf82877541bad13c8e Mon Sep 17 00:00:00 2001 From: Mirco Sanguineti <19243840+msanguineti@users.noreply.github.com> Date: Fri, 12 Apr 2019 09:40:52 +0300 Subject: [PATCH 2/5] docs: added my name to contributors --- types/shelljs/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index bd26c0e3cb..d66df36a7f 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -6,6 +6,7 @@ // Paul Huynh // Alexander Futász // ExE Boss +// Mirco Sanguineti // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 226cc36ae9fe2553ff4ecc9c3664cb7b297d0fcc Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Fri, 12 Apr 2019 14:45:17 +0300 Subject: [PATCH 3/5] Apply suggestions from code review Co-Authored-By: msanguineti <19243840+msanguineti@users.noreply.github.com> --- types/shelljs/index.d.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index d66df36a7f..7f13e1f22b 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -966,9 +966,8 @@ export type ShellString = string & ShellReturnValue; export type ShellArray = string[] & ShellReturnValue; -export const ShellString: ShellStringFunction; -export interface ShellStringFunction { +export interface ShellStringConstructor { /** * Wraps a string (or array) value. This has all the string (or array) methods, * but also exposes extra methods: `.to()`, `.toEnd()`, and all the pipe-able @@ -1011,6 +1010,8 @@ export interface ShellStringFunction { (value: string[]): ShellArray; } +export const ShellString: ShellStringConstructor; + export interface ChmodFunction { /** * Alters the permissions of a file or directory by either specifying the absolute From 88d6ac1c4ea50a30fcaa7c54f8849eed63298d20 Mon Sep 17 00:00:00 2001 From: Mirco Sanguineti <19243840+msanguineti@users.noreply.github.com> Date: Fri, 12 Apr 2019 14:55:01 +0300 Subject: [PATCH 4/5] build(ci): remove extra line --- types/shelljs/index.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/types/shelljs/index.d.ts b/types/shelljs/index.d.ts index 7f13e1f22b..7557ddae22 100644 --- a/types/shelljs/index.d.ts +++ b/types/shelljs/index.d.ts @@ -966,7 +966,6 @@ export type ShellString = string & ShellReturnValue; export type ShellArray = string[] & ShellReturnValue; - export interface ShellStringConstructor { /** * Wraps a string (or array) value. This has all the string (or array) methods, From b93ecfcbf9311c67dde9121a2d4f2c9bc7ddb6bf Mon Sep 17 00:00:00 2001 From: Mirco Sanguineti <19243840+msanguineti@users.noreply.github.com> Date: Fri, 12 Apr 2019 15:25:12 +0300 Subject: [PATCH 5/5] revert: revert formatting --- types/shelljs/shelljs-tests.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/types/shelljs/shelljs-tests.ts b/types/shelljs/shelljs-tests.ts index 50ec3c2cc5..b7b7afc5b1 100644 --- a/types/shelljs/shelljs-tests.ts +++ b/types/shelljs/shelljs-tests.ts @@ -89,24 +89,24 @@ const testPath = shell.env["path"]; const version = shell.exec("node --version").stdout; // $ExpectType ShellString -const version2 = shell.exec("node --version", { async: false }); +const version2 = shell.exec("node --version", {async: false}); const output = version2.stdout; // $ExpectType ChildProcess -const asyncVersion3 = shell.exec("node --version", { async: true }); +const asyncVersion3 = shell.exec("node --version", {async: true}); let pid = asyncVersion3.pid; declare let isAsync: boolean; // $ExpectType ShellString | ChildProcess -const unknownUntilRuntime = shell.exec("node --version", { async: isAsync }); +const unknownUntilRuntime = shell.exec("node --version", {async: isAsync}); -shell.exec("node --version", { silent: true }, (code, stdout, stderr) => { +shell.exec("node --version", {silent: true}, (code, stdout, stderr) => { const version = stdout; }); shell.exec( "node --version", - { silent: true, async: true, cwd: "/usr/local/bin" }, + {silent: true, async: true, cwd: "/usr/local/bin"}, (code, stdout, stderr) => { const version = stdout; } @@ -149,18 +149,18 @@ shell.touch("-c", "/Users/brandom/test1"); shell.touch("-c", "/Users/brandom/test1", "/Users/brandom/test2"); shell.touch("-c", ["/Users/brandom/test1", "/Users/brandom/test2"]); -shell.touch({ "-r": "/some/file.txt" }, "/Users/brandom/test1"); +shell.touch({"-r": "/some/file.txt"}, "/Users/brandom/test1"); shell.touch( - { "-r": "/some/file.txt" }, + {"-r": "/some/file.txt"}, "/Users/brandom/test1", "/Users/brandom/test2" ); -shell.touch({ "-r": "/oome/file.txt" }, [ +shell.touch({"-r": "/oome/file.txt"}, [ "/Users/brandom/test1", "/Users/brandom/test2" ]); -shell.head({ "-n": 1 }, "file*.txt"); +shell.head({"-n": 1}, "file*.txt"); shell.head("file1", "file2"); shell.head(["file1", "file2"]); // same as above @@ -169,7 +169,7 @@ shell.sort("-r", "foo.txt"); shell.sort("-r", ["file.txt"]); shell.sort(["file.txt"]); -shell.tail({ "-n": 1 }, "file*.txt"); +shell.tail({"-n": 1}, "file*.txt"); shell.tail("file1", "file2"); shell.tail(["file1", "file2"]); // same as above @@ -195,10 +195,10 @@ shell.config.globOptions = { shell .ls("dir") .grep(/^stuff/) - .head({ "-n": 5 }).stdout; + .head({"-n": 5}).stdout; const foo = new shell.ShellString('hello world'); const farr = new shell.ShellString(['hello', 'world']); -const bar = shell.ShellString('hello world'); +const boo = shell.ShellString('hello world'); const barr = shell.ShellString(['hello', 'world']);