Skip to content

Commit 2996523

Browse files
committed
Refactor use of process
1 parent 5079054 commit 2996523

File tree

15 files changed

+117
-62
lines changed

15 files changed

+117
-62
lines changed

lib/node_modules/@stdlib/process/argv/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
2526
var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives;
@@ -42,7 +43,7 @@ tape( 'main export is an object', opts, function test( t ) {
4243
});
4344

4445
tape( 'the export is an alias for `process.argv`', opts, function test( t ) {
45-
t.strictEqual( ARGV, process.argv, 'is an alias' );
46+
t.strictEqual( ARGV, proc.argv, 'is an alias' );
4647
t.end();
4748
});
4849

lib/node_modules/@stdlib/process/cwd/test/test.cli.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var resolve = require( 'path' ).resolve;
2425
var exec = require( 'child_process' ).exec;
2526
var tape = require( 'tape' );
2627
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
2728
var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
2829
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
30+
var EXEC_PATH = require( '@stdlib/process/exec-path' );
2931

3032

3133
// VARIABLES //
@@ -56,7 +58,7 @@ tape( 'when invoked with a `--help` flag, the command-line interface prints the
5658
'encoding': 'utf8'
5759
});
5860
cmd = [
59-
process.execPath,
61+
EXEC_PATH,
6062
fpath,
6163
'--help'
6264
];
@@ -82,7 +84,7 @@ tape( 'when invoked with a `-h` flag, the command-line interface prints the help
8284
'encoding': 'utf8'
8385
});
8486
cmd = [
85-
process.execPath,
87+
EXEC_PATH,
8688
fpath,
8789
'-h'
8890
];
@@ -102,7 +104,7 @@ tape( 'when invoked with a `-h` flag, the command-line interface prints the help
102104

103105
tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
104106
var cmd = [
105-
process.execPath,
107+
EXEC_PATH,
106108
fpath,
107109
'--version'
108110
];
@@ -122,7 +124,7 @@ tape( 'when invoked with a `--version` flag, the command-line interface prints t
122124

123125
tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
124126
var cmd = [
125-
process.execPath,
127+
EXEC_PATH,
126128
fpath,
127129
'-V'
128130
];
@@ -142,7 +144,7 @@ tape( 'when invoked with a `-V` flag, the command-line interface prints the vers
142144

143145
tape( 'the command-line interface prints the current working directory', opts, function test( t ) {
144146
var cmd = [
145-
process.execPath,
147+
EXEC_PATH,
146148
fpath
147149
];
148150

@@ -154,7 +156,7 @@ tape( 'the command-line interface prints the current working directory', opts, f
154156
t.fail( error.message );
155157
} else {
156158
str = stdout.toString();
157-
t.strictEqual( str, process.cwd()+'\n', 'prints path to `stdout`' );
159+
t.strictEqual( str, proc.cwd()+'\n', 'prints path to `stdout`' );
158160
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
159161
}
160162
t.end();

lib/node_modules/@stdlib/process/cwd/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
2526
var cwd = require( './../lib' );
@@ -41,6 +42,6 @@ tape( 'main export is a function', opts, function test( t ) {
4142
});
4243

4344
tape( 'the function returns the current working directory', opts, function test( t ) {
44-
t.equal( cwd(), process.cwd(), 'returns current working directory' );
45+
t.equal( cwd(), proc.cwd(), 'returns current working directory' );
4546
t.end();
4647
});

lib/node_modules/@stdlib/process/env/test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
2526
var ENV = require( './../lib' );
@@ -41,7 +42,6 @@ tape( 'main export is an object', opts, function test( t ) {
4142
});
4243

4344
tape( 'the export is an alias for `process.env`', opts, function test( t ) {
44-
// eslint-disable-next-line no-process-env
45-
t.strictEqual( ENV, process.env, 'is an alias' );
45+
t.strictEqual( ENV, proc.env, 'is an alias' );
4646
t.end();
4747
});

lib/node_modules/@stdlib/process/getegid/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var proxyquire = require( 'proxyquire' );
2526
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
@@ -45,7 +46,7 @@ tape( 'if `process.getegid` is a function, the main export aliases `process.gete
4546
var getegid = proxyquire( './../lib/main.js', {
4647
'@stdlib/assert/is-function': isFunction
4748
});
48-
t.strictEqual( getegid, process.getegid, 'is alias' );
49+
t.strictEqual( getegid, proc.getegid, 'is alias' );
4950
t.end();
5051

5152
function isFunction() {

lib/node_modules/@stdlib/process/geteuid/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var proxyquire = require( 'proxyquire' );
2526
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
@@ -45,7 +46,7 @@ tape( 'if `process.geteuid` is a function, the main export aliases `process.gete
4546
var geteuid = proxyquire( './../lib/main.js', {
4647
'@stdlib/assert/is-function': isFunction
4748
});
48-
t.strictEqual( geteuid, process.geteuid, 'is alias' );
49+
t.strictEqual( geteuid, proc.geteuid, 'is alias' );
4950
t.end();
5051

5152
function isFunction() {

lib/node_modules/@stdlib/process/getgid/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var proxyquire = require( 'proxyquire' );
2526
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
@@ -45,7 +46,7 @@ tape( 'if `process.getgid` is a function, the main export aliases `process.getgi
4546
var getgid = proxyquire( './../lib/main.js', {
4647
'@stdlib/assert/is-function': isFunction
4748
});
48-
t.strictEqual( getgid, process.getgid, 'is alias' );
49+
t.strictEqual( getgid, proc.getgid, 'is alias' );
4950
t.end();
5051

5152
function isFunction() {

lib/node_modules/@stdlib/process/getuid/test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var tape = require( 'tape' );
2425
var proxyquire = require( 'proxyquire' );
2526
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
@@ -45,7 +46,7 @@ tape( 'if `process.getuid` is a function, the main export aliases `process.getui
4546
var getuid = proxyquire( './../lib/main.js', {
4647
'@stdlib/assert/is-function': isFunction
4748
});
48-
t.strictEqual( getuid, process.getuid, 'is alias' );
49+
t.strictEqual( getuid, proc.getuid, 'is alias' );
4950
t.end();
5051

5152
function isFunction() {

lib/node_modules/@stdlib/process/node-version/test/test.cli.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020

2121
// MODULES //
2222

23+
var proc = require( 'process' );
2324
var resolve = require( 'path' ).resolve;
2425
var exec = require( 'child_process' ).exec;
2526
var tape = require( 'tape' );
2627
var IS_BROWSER = require( '@stdlib/assert/is-browser' );
2728
var IS_WINDOWS = require( '@stdlib/assert/is-windows' );
2829
var readFileSync = require( '@stdlib/fs/read-file' ).sync;
30+
var EXEC_PATH = require( '@stdlib/process/exec-path' );
2931

3032

3133
// VARIABLES //
@@ -56,7 +58,7 @@ tape( 'when invoked with a `--help` flag, the command-line interface prints the
5658
'encoding': 'utf8'
5759
});
5860
cmd = [
59-
process.execPath,
61+
EXEC_PATH,
6062
fpath,
6163
'--help'
6264
];
@@ -82,7 +84,7 @@ tape( 'when invoked with a `-h` flag, the command-line interface prints the help
8284
'encoding': 'utf8'
8385
});
8486
cmd = [
85-
process.execPath,
87+
EXEC_PATH,
8688
fpath,
8789
'-h'
8890
];
@@ -102,7 +104,7 @@ tape( 'when invoked with a `-h` flag, the command-line interface prints the help
102104

103105
tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
104106
var cmd = [
105-
process.execPath,
107+
EXEC_PATH,
106108
fpath,
107109
'--version'
108110
];
@@ -122,7 +124,7 @@ tape( 'when invoked with a `--version` flag, the command-line interface prints t
122124

123125
tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) {
124126
var cmd = [
125-
process.execPath,
127+
EXEC_PATH,
126128
fpath,
127129
'-V'
128130
];
@@ -142,7 +144,7 @@ tape( 'when invoked with a `-V` flag, the command-line interface prints the vers
142144

143145
tape( 'the command-line interface prints the Node version', opts, function test( t ) {
144146
var cmd = [
145-
process.execPath,
147+
EXEC_PATH,
146148
fpath
147149
];
148150

@@ -154,7 +156,7 @@ tape( 'the command-line interface prints the Node version', opts, function test(
154156
t.fail( error.message );
155157
} else {
156158
str = stdout.toString();
157-
t.strictEqual( str, 'v'+process.versions.node+'\n', 'prints Node version to `stdout`' );
159+
t.strictEqual( str, 'v'+proc.versions.node+'\n', 'prints Node version to `stdout`' );
158160
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
159161
}
160162
t.end();

lib/node_modules/@stdlib/process/read-stdin/README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# stdin
2222

23-
> Read data from `stdin`.
23+
> Read data from [`stdin`][@stdlib/streams/node/stdin].
2424
2525
<section class="usage">
2626

@@ -32,14 +32,14 @@ var stdin = require( '@stdlib/process/read-stdin' );
3232

3333
#### stdin( \[encoding,] clbk )
3434

35-
Reads data from `stdin`.
35+
Reads data from [`stdin`][@stdlib/streams/node/stdin].
3636

3737
<!-- run-disable -->
3838

3939
```javascript
4040
function onRead( error, data ) {
4141
if ( error ) {
42-
throw error;
42+
return console.error( 'Error: %s', error.message );
4343
}
4444
console.log( data.toString() );
4545
// => '...'
@@ -55,7 +55,7 @@ By default, returned `data` is a [`Buffer`][buffer]. To return a `string` of a s
5555
```javascript
5656
function onRead( error, data ) {
5757
if ( error ) {
58-
throw error;
58+
return console.error( 'Error: %s', error.message );
5959
}
6060
console.log( data );
6161
// => '...'
@@ -64,20 +64,22 @@ function onRead( error, data ) {
6464
stdin( 'utf8', onRead );
6565
```
6666

67-
When a file's calling Node.js process is running in a [TTY][tty] context (i.e., no `stdin`), `data` will either be an empty [`Buffer`][buffer] (no encoding provided) or an empty `string` (encoding provided).
67+
When a file's calling Node.js process is running in a [TTY][tty] context (i.e., no [`stdin`][@stdlib/streams/node/stdin]), `data` will either be an empty [`Buffer`][buffer] (no encoding provided) or an empty `string` (encoding provided).
6868

6969
<!-- run-disable -->
7070

7171
```javascript
72+
var stream = require( '@stdlib/streams/node/stdin' );
73+
7274
function onRead( error, data ) {
7375
if ( error ) {
74-
throw error;
76+
return console.error( 'Error: %s', error.message );
7577
}
7678
console.log( data );
7779
// => ''
7880
}
7981

80-
process.stdin.isTTY = true;
82+
stream.isTTY = true;
8183

8284
stdin( 'utf8', onRead );
8385
```
@@ -96,6 +98,7 @@ stdin( 'utf8', onRead );
9698

9799
```javascript
98100
var string2buffer = require( '@stdlib/buffer/from-string' );
101+
var stream = require( '@stdlib/streams/node/stdin' );
99102
var stdin = require( '@stdlib/process/read-stdin' );
100103

101104
function onRead( error, data ) {
@@ -108,18 +111,18 @@ function onRead( error, data ) {
108111
}
109112

110113
// Fake not being in a terminal context:
111-
process.stdin.isTTY = false;
114+
stream.isTTY = false;
112115

113116
// Provide a callback to consume all data from `stdin`:
114117
stdin( onRead );
115118

116119
// Push some data to `stdin`:
117-
process.stdin.push( string2buffer( 'beep' ) );
118-
process.stdin.push( string2buffer( ' ' ) );
119-
process.stdin.push( string2buffer( 'boop' ) );
120+
stream.push( string2buffer( 'beep' ) );
121+
stream.push( string2buffer( ' ' ) );
122+
stream.push( string2buffer( 'boop' ) );
120123

121124
// End the stream:
122-
process.stdin.push( null );
125+
stream.push( null );
123126
```
124127

125128
</section>
@@ -132,6 +135,8 @@ process.stdin.push( null );
132135

133136
[tty]: https://nodejs.org/api/tty.html#tty_tty
134137

138+
[@stdlib/streams/node/stdin]: https://github.com/stdlib-js/stdlib
139+
135140
</section>
136141

137142
<!-- /.links -->

0 commit comments

Comments
 (0)