Comparing version 1.1.1 to 1.2.0
@@ -5,6 +5,8 @@ 'use strict'; | ||
getPort().then(port => process.stdout.write('' + port)).catch(err => | ||
setTimeout(() => { | ||
throw err; | ||
}, 0) | ||
); | ||
getPort() | ||
.then(port => process.stdout.write('' + port)) | ||
.catch(err => | ||
setTimeout(() => { | ||
throw err; | ||
}, 0) | ||
); |
@@ -9,3 +9,13 @@ 'use strict'; | ||
const host = '127.0.0.1'; | ||
const NC_PATH = require.resolve('./nc'); | ||
function nodeNetCatSrc(port, input) { | ||
return ( | ||
"var c=require('net').connect(" + | ||
port + | ||
",'127.0.0.1',()=>{c.end(" + | ||
JSON.stringify(input) | ||
.replace(/\u2028/g, '\\u2028') | ||
.replace(/\u2029/g, '\\u2029') + | ||
').pipe(process.stdout)});' | ||
); | ||
} | ||
@@ -63,6 +73,14 @@ const FUNCTION_PRIORITY = [nativeNC, nodeNC]; | ||
let response = null; | ||
while (response !== 'pong') { | ||
let err = null; | ||
let timeout = Date.now() + 1000; | ||
while (response !== 'pong' && Date.now() < timeout) { | ||
const result = nodeNC(port, 'ping\r\n'); | ||
response = result.stdout && result.stdout.toString(); | ||
err = result.stderr && result.stderr.toString(); | ||
} | ||
if (response !== 'pong') { | ||
throw new Error( | ||
'Timed out waiting for ping to return pong:\n\n' + err + '\n' + response | ||
); | ||
} | ||
} | ||
@@ -75,3 +93,3 @@ | ||
function nodeNC(port, input) { | ||
return spawnSync(process.execPath, [NC_PATH, host, port], {input: input}); | ||
return spawnSync(process.execPath, ['-e', nodeNetCatSrc(port, input)]); | ||
} | ||
@@ -78,0 +96,0 @@ |
{ | ||
"name": "sync-rpc", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "lib/index.js", | ||
@@ -21,4 +21,4 @@ "description": "Run asynchronous commands synchronously by putting them in a separate process", | ||
"precommit": "lint-staged", | ||
"prettier": "prettier --single-quote --trailing-comma es5 --no-bracket-spacing --write \"lib/**/*.js\"", | ||
"prettier:check": "prettier --single-quote --trailing-comma es5 --no-bracket-spacing --list-different \"lib/**/*.js\"", | ||
"prettier": "prettier --write \"lib/**/*.js\"", | ||
"prettier:check": "prettier--list-different \"lib/**/*.js\"", | ||
"test": "jest --coverage", | ||
@@ -29,3 +29,3 @@ "watch": "jest --coverage --watch" | ||
"*.js": [ | ||
"prettier --single-quote --trailing-comma es5 --no-bracket-spacing --write", | ||
"prettier --write", | ||
"git add" | ||
@@ -32,0 +32,0 @@ ] |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12438
281
3
12