-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use files-property in package.json to be more precise about the size...
- Loading branch information
Showing
19 changed files
with
419 additions
and
16 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
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,93 @@ | ||
var globby = require('globby') | ||
var deep = require('deep-aplus')(Promise) | ||
|
||
/** | ||
* List of ignored files (from https://docs.npmjs.com/files/package.json#files) | ||
* @type {string[]} | ||
*/ | ||
var alwaysIgnored = [ | ||
'.git', | ||
'CVS', | ||
'.svn', | ||
'.hg', | ||
'.lock-wscript', | ||
'.wafpickle-*', | ||
'.*.swp', | ||
'.DS_Store', | ||
'._*', | ||
'npm-debug.log', | ||
'.npmrc', | ||
'node_modules', | ||
'config.gypi', | ||
'*.orig' | ||
] | ||
|
||
var alwaysIncluded = [ | ||
'package.json' | ||
] | ||
|
||
var alwaysIncludedIgnoreCase = [ | ||
'README', 'README.*', | ||
'CHANGES', 'CHANGES.*', | ||
'CHANGELOG', 'CHANGELOG.*', | ||
'HISTORY', 'HISTORY.*', | ||
'LICENSE', 'LICENSE.*', | ||
'LICENCE', 'LICENCE.*', | ||
'NOTICE', 'NOTICE.*' | ||
] | ||
|
||
/** | ||
* | ||
* @param {string} cwd the projects basedir | ||
* @param {{files: string[]} packageJson the parsed package.json | ||
* @param {string[]} npmIgnore non-comment lines of the npm-ignore file | ||
* @returns {Promise.<string[]>} a promise for a list of valid files in the project | ||
*/ | ||
function validFiles (cwd, packageJson, npmIgnore = []) { | ||
var ignored = alwaysIgnored.concat(npmIgnore).map(withChildren) | ||
|
||
var globs | ||
if (packageJson.files) { | ||
globs = packageJson.files | ||
.map((file) => file.replace(/\/?$/, '{,/**}')) | ||
.concat(alwaysIncluded) | ||
} else { | ||
globs = '**' | ||
} | ||
|
||
return deep({ | ||
withCase: globby(globs, {nocase: false, ignore: ignored, cwd, mark: true}), | ||
ignoreCase: globby(alwaysIncludedIgnoreCase, {nocase: true, ignore: ignored, cwd, mark: true}) | ||
}) | ||
// Join | ||
.then(({withCase, ignoreCase}) => withCase.concat(ignoreCase, '/')) | ||
// remove duplicates | ||
.then(files => Array.from(new Set(files))) | ||
} | ||
|
||
/** | ||
* Returns a glob the matches the file itself and its children (if it is an directory) | ||
* @param file | ||
*/ | ||
function withChildren (file) { | ||
return file.replace(/\/?$/, '{,/**}') | ||
} | ||
|
||
/** | ||
* Returns an array of globs that match a file, its children (if it is an directory) and its | ||
* parent directories (recursively) | ||
* @param file | ||
*/ | ||
function withParentsAndChildren (file) { | ||
// Determine globs for parents matching | ||
const globs = file.replace(/\/$/, '').match(/.*?\//g) | ||
.map((item, index, array) => array.slice(0, index + 1).join('')) | ||
// Add pattern to match children | ||
globs.push(withChildren(file)) | ||
return globs | ||
} | ||
|
||
module.exports = { | ||
validFiles, | ||
withParentsAndChildren | ||
} |
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
Empty file.
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 @@ | ||
a readme |
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 @@ | ||
a |
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 @@ | ||
a |
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 @@ | ||
ab |
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,100 @@ | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 | ||
0123456789012345678901234567890123456789012345678 |
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 @@ | ||
abcef |
Oops, something went wrong.