-
Notifications
You must be signed in to change notification settings - Fork 2
modernized code base #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
modernized code base #137
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8700d46
replaced `promisify` with native alternatives
FND c0282a3
switched to proper `Set` and `Map` instances
FND b5ee75a
tweaked syntax for functions without arguments
FND de0a193
switched to named instead of default exports
FND ae3f548
ensured dynamic imports are asynchronous
FND File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 +1,10 @@ | ||
| #!/usr/bin/env node | ||
| "use strict"; | ||
|
|
||
| let faucet = require("../lib"); | ||
| let parseCLI = require("../lib/cli"); | ||
| let { faucetDispatch } = require("../lib"); | ||
| let { parseCLI } = require("../lib/cli"); | ||
|
|
||
| let { referenceDir, config, options } = parseCLI(); | ||
| faucet(referenceDir, config, options); | ||
| parseCLI(). | ||
| then(({ referenceDir, config, options }) => { | ||
| faucetDispatch(referenceDir, config, options); | ||
| }); | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 +1,29 @@ | ||
| "use strict"; | ||
|
|
||
| let { abort, repr } = require("../"); | ||
| let fs = require("fs"); | ||
| let { writeFile } = require("fs/promises"); | ||
| let { mkdirSync } = require("fs"); | ||
| let path = require("path"); | ||
| let { promisify } = require("util"); | ||
|
|
||
| let KNOWN = {}; // avoids redundant `mkdirp` invocations | ||
| let LOCKS = {}; | ||
|
|
||
| let writeFile = promisify(fs.writeFile); | ||
| let KNOWN = new Set(); // avoids redundant `mkdir` invocations | ||
| let LOCKS = new Map(); | ||
|
|
||
| // avoids concurrent write operations and creates target directory if necessary | ||
| module.exports = function createFile(filepath, contents) { | ||
| let lock = LOCKS[filepath]; | ||
| exports.createFile = function createFile(filepath, contents) { | ||
| let lock = LOCKS.get(filepath); | ||
| if(lock) { // defer | ||
| return lock.then(_ => createFile(filepath, contents)); | ||
| return lock.then(() => createFile(filepath, contents)); | ||
| } | ||
|
|
||
| // create directory if necessary | ||
| if(!KNOWN[filepath]) { | ||
| KNOWN[filepath] = true; | ||
| if(!KNOWN.has(filepath)) { | ||
| KNOWN.add(filepath); | ||
| // NB: `sync` avoids race condition for subsequent operations | ||
| mkdirpSync(path.dirname(filepath)); | ||
| mkdirSync(path.dirname(filepath), { recursive: true }); | ||
| } | ||
|
|
||
| let prom = writeFile(filepath, contents); | ||
| LOCKS[filepath] = prom; | ||
| return prom.then(_ => { | ||
| delete LOCKS[filepath]; | ||
| LOCKS.set(filepath, prom); | ||
| return prom.then(() => { | ||
| LOCKS.delete(filepath); | ||
| }); | ||
| }; | ||
|
|
||
| function mkdirpSync(directory) { | ||
| try { | ||
| // NB: `recursive` option was introduced in Node v10.12.0 | ||
| fs.mkdirSync(directory, { recursive: true }); | ||
| } catch(err) { | ||
| abort(`ERROR: auto-creating ${repr(directory)} requires ` + | ||
| "Node v10.12.0 or above"); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.