1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | function path() {
|
9 | const data = _interopRequireWildcard(require('path'));
|
10 |
|
11 | path = function () {
|
12 | return data;
|
13 | };
|
14 |
|
15 | return data;
|
16 | }
|
17 |
|
18 | function _execa() {
|
19 | const data = _interopRequireDefault(require('execa'));
|
20 |
|
21 | _execa = function () {
|
22 | return data;
|
23 | };
|
24 |
|
25 | return data;
|
26 | }
|
27 |
|
28 | function _interopRequireDefault(obj) {
|
29 | return obj && obj.__esModule ? obj : {default: obj};
|
30 | }
|
31 |
|
32 | function _getRequireWildcardCache(nodeInterop) {
|
33 | if (typeof WeakMap !== 'function') return null;
|
34 | var cacheBabelInterop = new WeakMap();
|
35 | var cacheNodeInterop = new WeakMap();
|
36 | return (_getRequireWildcardCache = function (nodeInterop) {
|
37 | return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
38 | })(nodeInterop);
|
39 | }
|
40 |
|
41 | function _interopRequireWildcard(obj, nodeInterop) {
|
42 | if (!nodeInterop && obj && obj.__esModule) {
|
43 | return obj;
|
44 | }
|
45 | if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
46 | return {default: obj};
|
47 | }
|
48 | var cache = _getRequireWildcardCache(nodeInterop);
|
49 | if (cache && cache.has(obj)) {
|
50 | return cache.get(obj);
|
51 | }
|
52 | var newObj = {};
|
53 | var hasPropertyDescriptor =
|
54 | Object.defineProperty && Object.getOwnPropertyDescriptor;
|
55 | for (var key in obj) {
|
56 | if (key !== 'default' && Object.prototype.hasOwnProperty.call(obj, key)) {
|
57 | var desc = hasPropertyDescriptor
|
58 | ? Object.getOwnPropertyDescriptor(obj, key)
|
59 | : null;
|
60 | if (desc && (desc.get || desc.set)) {
|
61 | Object.defineProperty(newObj, key, desc);
|
62 | } else {
|
63 | newObj[key] = obj[key];
|
64 | }
|
65 | }
|
66 | }
|
67 | newObj.default = obj;
|
68 | if (cache) {
|
69 | cache.set(obj, newObj);
|
70 | }
|
71 | return newObj;
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | const findChangedFilesUsingCommand = async (args, cwd) => {
|
82 | let result;
|
83 |
|
84 | try {
|
85 | result = await (0, _execa().default)('git', args, {
|
86 | cwd
|
87 | });
|
88 | } catch (e) {
|
89 |
|
90 | e.message = e.stderr;
|
91 | throw e;
|
92 | }
|
93 |
|
94 | return result.stdout
|
95 | .split('\n')
|
96 | .filter(s => s !== '')
|
97 | .map(changedPath => path().resolve(cwd, changedPath));
|
98 | };
|
99 |
|
100 | const adapter = {
|
101 | findChangedFiles: async (cwd, options) => {
|
102 | const changedSince =
|
103 | options && (options.withAncestor ? 'HEAD^' : options.changedSince);
|
104 | const includePaths = ((options && options.includePaths) || []).map(
|
105 | absoluteRoot => path().normalize(path().relative(cwd, absoluteRoot))
|
106 | );
|
107 |
|
108 | if (options && options.lastCommit) {
|
109 | return findChangedFilesUsingCommand(
|
110 | ['show', '--name-only', '--pretty=format:', 'HEAD', '--'].concat(
|
111 | includePaths
|
112 | ),
|
113 | cwd
|
114 | );
|
115 | }
|
116 |
|
117 | if (changedSince) {
|
118 | const [committed, staged, unstaged] = await Promise.all([
|
119 | findChangedFilesUsingCommand(
|
120 | ['diff', '--name-only', `${changedSince}...HEAD`, '--'].concat(
|
121 | includePaths
|
122 | ),
|
123 | cwd
|
124 | ),
|
125 | findChangedFilesUsingCommand(
|
126 | ['diff', '--cached', '--name-only', '--'].concat(includePaths),
|
127 | cwd
|
128 | ),
|
129 | findChangedFilesUsingCommand(
|
130 | [
|
131 | 'ls-files',
|
132 | '--other',
|
133 | '--modified',
|
134 | '--exclude-standard',
|
135 | '--'
|
136 | ].concat(includePaths),
|
137 | cwd
|
138 | )
|
139 | ]);
|
140 | return [...committed, ...staged, ...unstaged];
|
141 | }
|
142 |
|
143 | const [staged, unstaged] = await Promise.all([
|
144 | findChangedFilesUsingCommand(
|
145 | ['diff', '--cached', '--name-only', '--'].concat(includePaths),
|
146 | cwd
|
147 | ),
|
148 | findChangedFilesUsingCommand(
|
149 | [
|
150 | 'ls-files',
|
151 | '--other',
|
152 | '--modified',
|
153 | '--exclude-standard',
|
154 | '--'
|
155 | ].concat(includePaths),
|
156 | cwd
|
157 | )
|
158 | ]);
|
159 | return [...staged, ...unstaged];
|
160 | },
|
161 | getRoot: async cwd => {
|
162 | const options = ['rev-parse', '--show-cdup'];
|
163 |
|
164 | try {
|
165 | const result = await (0, _execa().default)('git', options, {
|
166 | cwd
|
167 | });
|
168 | return path().resolve(cwd, result.stdout);
|
169 | } catch {
|
170 | return null;
|
171 | }
|
172 | }
|
173 | };
|
174 | var _default = adapter;
|
175 | exports.default = _default;
|