Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,4 @@
**/__mocks__/**
**/__tests__/**
src
yarn.lock

View File

@@ -0,0 +1,48 @@
# jest-changed-files
A module used internally by Jest to check which files have changed since you
last committed in git or hg.
## Install
```sh
$ npm install --save jest-changed-files
```
## API
### `hg.isHGRepository(cwd: string): Promise<?string>`
Get the root of the mercurial repository containing `cwd` or return `null` if
`cwd` is not inside a mercurial repository.
### `git.isGitRepository(cwd: string): Promise<?string>`
Get the root of the git repository containing `cwd` or return `null` if
`cwd` is not inside a git repository.
### `hg.findChangedFiles / git.findChangedFiles (root: string): Promise<Array<string>>`
Get the list of files in a git/mecurial repository that have changed since the
last commit.
## Usage
```javascript
import {git, hg} from 'jest-changed-files';
function changedFiles(cwd) {
return Promise.all([
git.isGitRepository(cwd),
hg.isHGRepository(cwd),
]).then(([gitRoot, hgRoot]) => {
if (gitRoot !== null) {
return git.findChangedFiles(gitRoot);
} else if (hgRoot !== null) {
return hg.findChangedFiles(hgRoot);
} else {
throw new Error('Not in a git or hg repo');
}
});
}
```

View File

@@ -0,0 +1,71 @@
'use strict';
const path = require('path'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const childProcess = require('child_process');function findChangedFiles(
cwd,
options)
{
return new Promise((resolve, reject) => {
const args = options && options.lastCommit ?
['show', '--name-only', '--pretty=%b', 'HEAD'] :
['ls-files', '--other', '--modified', '--exclude-standard'];
const child = childProcess.spawn('git', args, { cwd });
let stdout = '';
let stderr = '';
child.stdout.on('data', data => stdout += data);
child.stderr.on('data', data => stderr += data);
child.on('error', e => reject(e));
child.on('close', code => {
if (code === 0) {
stdout = stdout.trim();
if (stdout === '') {
resolve([]);
} else {
resolve(
stdout.
split('\n').
map(changedPath => path.resolve(cwd, changedPath)));
}
} else {
reject(code + ': ' + stderr);
}
});
});
}
function isGitRepository(cwd) {
return new Promise(resolve => {
try {
let stdout = '';
const options = ['rev-parse', '--show-toplevel'];
const child = childProcess.spawn('git', options, { cwd });
child.stdout.on('data', data => stdout += data);
child.on('error', () => resolve(null));
child.on('close', code => resolve(code === 0 ? stdout.trim() : null));
} catch (e) {
resolve(null);
}
});
}
module.exports = {
findChangedFiles,
isGitRepository };

View File

@@ -0,0 +1,74 @@
'use strict';
const path = require('path'); /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/const childProcess = require('child_process');const env = Object.assign({}, process.env, { HGPLAIN: 1 });
function findChangedFiles(cwd, options) {
return new Promise((resolve, reject) => {
let args = ['status', '-amn'];
if (options && options.withAncestor) {
args.push('--rev', 'ancestor(.^)');
} else if (options && options.lastCommit === true) {
args = ['tip', '--template', '{files%"{file}\n"}'];
}
const child = childProcess.spawn('hg', args, { cwd, env });
let stdout = '';
let stderr = '';
child.stdout.on('data', data => stdout += data);
child.stderr.on('data', data => stderr += data);
child.on('error', e => reject(e));
child.on('close', code => {
if (code === 0) {
stdout = stdout.trim();
if (stdout === '') {
resolve([]);
} else {
resolve(
stdout.
split('\n').
map(changedPath => path.resolve(cwd, changedPath)));
}
} else {
reject(code + ': ' + stderr);
}
});
});
}
function isHGRepository(cwd) {
return new Promise(resolve => {
try {
let stdout = '';
const child = childProcess.spawn('hg', ['root'], { cwd, env });
child.stdout.on('data', data => stdout += data);
child.on('error', () => resolve(null));
child.on('close', code => resolve(code === 0 ? stdout.trim() : null));
} catch (e) {
resolve(null);
}
});
}
module.exports = {
findChangedFiles,
isHGRepository };

View File

@@ -0,0 +1,13 @@
'use strict'; /**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*
*/
module.exports = {
git: require('./git'),
hg: require('./hg') };

View File

@@ -0,0 +1,43 @@
{
"_args": [
[
"jest-changed-files@20.0.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "jest-changed-files@20.0.3",
"_id": "jest-changed-files@20.0.3",
"_inBundle": false,
"_integrity": "sha1-k5TVzGXEOEBhSb7xv01Sto4D4/g=",
"_location": "/react-scripts/jest-changed-files",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jest-changed-files@20.0.3",
"name": "jest-changed-files",
"escapedName": "jest-changed-files",
"rawSpec": "20.0.3",
"saveSpec": null,
"fetchSpec": "20.0.3"
},
"_requiredBy": [
"/react-scripts/jest/jest-cli"
],
"_resolved": "https://registry.npmjs.org/jest-changed-files/-/jest-changed-files-20.0.3.tgz",
"_spec": "20.0.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"bugs": {
"url": "https://github.com/facebook/jest/issues"
},
"description": "A module used internally by Jest to check which files have changed since you last committed in git or hg.",
"homepage": "https://github.com/facebook/jest#readme",
"license": "BSD-3-Clause",
"main": "build/index.js",
"name": "jest-changed-files",
"repository": {
"type": "git",
"url": "git+https://github.com/facebook/jest.git"
},
"version": "20.0.3"
}