spec-change
Advanced tools
Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "spec-change", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Computes specs to re-run when files change", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -72,2 +72,14 @@ # spec-change | ||
#### affectedFiles | ||
Takes the dependencies computed using `getDependsInFolder` or `getDependentFiles` and a list of source files and produces a list of potentially affected files. | ||
```js | ||
const { getDependsInFolder, affectedFiles } = require('spec-change') | ||
const deps = getDependsInFolder(directory) | ||
const changedFiles = ['utils/sub/misc.js'] | ||
const affected = affectedFiles(deps, changedFiles) | ||
// a list of files that depend on the misc file | ||
``` | ||
## Debugging | ||
@@ -74,0 +86,0 @@ |
@@ -133,2 +133,9 @@ const dependencyTree = require('dependency-tree') | ||
/** | ||
* Give the folder name and optional file mask, finds dependencies between all files. | ||
* The returned object can have _other_ files, if they are imported or required | ||
* from the source files. | ||
* @param {string} folder Absolute path to the folder | ||
* @param {string} fileMask Optional file mask to use to find the source files | ||
*/ | ||
function getDependsInFolder(folder, fileMask = '**/*.{js,ts}') { | ||
@@ -150,2 +157,26 @@ la(path.isAbsolute(folder), 'expected an absolute folder path', folder) | ||
/** | ||
* Given the computed dependencies object and a list of files, | ||
* returns a list of files that are affected by the changes. | ||
* Useful when the files are computed using source control changes | ||
* and now we want to verify _all_ potentially affected source files. | ||
* @see `getDependsInFolder` | ||
* @param {Object} deps Source file dependencies computed using `getDependentFiles` or `getDependsInFolder` | ||
* @param {string[]} filenames List of filenames (relative) that have changed | ||
* @returns {string[]} | ||
*/ | ||
function affectedFiles(deps, filenames) { | ||
const affected = new Set() | ||
filenames.forEach((filename) => { | ||
if (deps[filename]) { | ||
const filesAffectedByThisChangedFile = deps[filename] | ||
filesAffectedByThisChangedFile.forEach((name) => { | ||
affected.add(name) | ||
}) | ||
} | ||
}) | ||
return [...affected].sort() | ||
} | ||
module.exports = { | ||
@@ -157,2 +188,3 @@ getFileDependencies, | ||
getDependsInFolder, | ||
affectedFiles, | ||
} |
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
11489
193
105