-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agents must have a temp dir of their own, or risk interference with o…
…ther agents in other threads
- Loading branch information
Showing
8 changed files
with
310 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = function(api) { | ||
return function(...args) { | ||
return new Promise((resolve, reject) => { | ||
args.push((error, result) => { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(result); | ||
}); | ||
api(...args); | ||
}); | ||
}; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,37 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const promisify = require('./promisify'); | ||
const mkdir = promisify(fs.mkdir); | ||
const stat = promisify(fs.stat); | ||
const writeFile = promisify(fs.writeFile); | ||
|
||
module.exports = function(sources) { | ||
module.exports = async function(sources) { | ||
let {0: [file]} = sources; | ||
let dir = path.dirname(file); | ||
|
||
await safeMkdir(dir); | ||
/* | ||
first: path to output file | ||
second: contents | ||
*/ | ||
return Promise.all( | ||
// TODO: Can we use built-in fs-promise? | ||
return await Promise.all( | ||
sources.map(args => writeFile(...args)) | ||
); | ||
}; | ||
|
||
function promisify(api) { | ||
return function(...args) { | ||
return new Promise(function(resolve, reject) { | ||
args.push(function(error, result) { | ||
if (error) { | ||
return reject(error); | ||
} | ||
return resolve(result); | ||
}); | ||
api(...args); | ||
}); | ||
}; | ||
async function safeMkdir(dir) { | ||
try { | ||
await stat(dir); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
try { | ||
await mkdir(dir); | ||
} catch ({}) { | ||
// suppressed? | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.