-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: drop support for Node < 8 (#170)
BREAKING CHANGE: drop support for versions of Node which are EOL'd as of 2019-04-30. * chore: upgrade mocha to fix some devDeps issues with npm audit * chore: upgrade commander and electron deps * chore: upgrade electron-mocha, which requires Node >= 8 * docs: update code examples for Node 8 * refactor: replace pify with util.promisify * refactor: use async/await everywhere * chore: remove Node 6 from the Node versions tested in CI * refactor: use async readFile method * refactor: simplify pattern construction * docs: reformat createPackageFromFiles doc comment * refactor: DRY up determineFileType * chore: remove mz devDependency
- Loading branch information
Showing
13 changed files
with
603 additions
and
555 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 |
---|---|---|
@@ -1,37 +1,31 @@ | ||
'use strict' | ||
|
||
const pify = require('pify') | ||
const { promisify } = require('util') | ||
|
||
const fs = pify(process.versions.electron ? require('original-fs') : require('fs')) | ||
const glob = pify(require('glob')) | ||
const fs = require('./wrapped-fs') | ||
const glob = promisify(require('glob')) | ||
|
||
function determineFileType (filename) { | ||
return fs.lstat(filename) | ||
.then(stat => { | ||
if (stat.isFile()) { | ||
return [filename, { type: 'file', stat: stat }] | ||
} else if (stat.isDirectory()) { | ||
return [filename, { type: 'directory', stat: stat }] | ||
} else if (stat.isSymbolicLink()) { | ||
return [filename, { type: 'link', stat: stat }] | ||
} | ||
|
||
return [filename, undefined] | ||
}) | ||
async function determineFileType (filename) { | ||
const stat = await fs.lstat(filename) | ||
if (stat.isFile()) { | ||
return { type: 'file', stat } | ||
} else if (stat.isDirectory()) { | ||
return { type: 'directory', stat } | ||
} else if (stat.isSymbolicLink()) { | ||
return { type: 'link', stat } | ||
} | ||
} | ||
|
||
module.exports = function (dir, options) { | ||
module.exports = async function (dir, options) { | ||
const metadata = {} | ||
return glob(dir, options) | ||
.then(filenames => Promise.all(filenames.map(filename => determineFileType(filename)))) | ||
.then(results => { | ||
const filenames = [] | ||
for (const [filename, type] of results) { | ||
filenames.push(filename) | ||
if (type) { | ||
metadata[filename] = type | ||
} | ||
} | ||
return [filenames, metadata] | ||
}) | ||
const crawled = await glob(dir, options) | ||
const results = await Promise.all(crawled.map(async filename => [filename, await determineFileType(filename)])) | ||
const filenames = results.map(([filename, type]) => { | ||
if (type) { | ||
metadata[filename] = type | ||
} | ||
return filename | ||
}) | ||
return [filenames, metadata] | ||
} | ||
module.exports.determineFileType = determineFileType |
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
Oops, something went wrong.