@graphql-tools/git-loader 7.1.18 → 7.2.0-alpha-6c480b2d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{index.js → cjs/index.js} +37 -126
- package/cjs/load-git.js +82 -0
- package/cjs/package.json +1 -0
- package/cjs/parse.js +16 -0
- package/{index.mjs → esm/index.js} +10 -98
- package/esm/load-git.js +74 -0
- package/esm/parse.js +12 -0
- package/package.json +33 -12
- /package/{index.d.ts → typings/index.d.ts} +0 -0
- /package/{load-git.d.ts → typings/load-git.d.ts} +0 -0
- /package/{parse.d.ts → typings/parse.d.ts} +0 -0
|
@@ -1,104 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const isGlob = _interopDefault(require('is-glob'));
|
|
15
|
-
const process = require('process');
|
|
16
|
-
|
|
17
|
-
const createLoadError = (error) => new Error('Unable to load file from git: ' + error);
|
|
18
|
-
const createShowCommand = ({ ref, path }) => {
|
|
19
|
-
return ['show', `${ref}:${path}`];
|
|
20
|
-
};
|
|
21
|
-
const createTreeError = (error) => new Error('Unable to load the file tree from git: ' + error);
|
|
22
|
-
const createTreeCommand = ({ ref }) => {
|
|
23
|
-
return ['ls-tree', '-r', '--name-only', ref];
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
async function readTreeAtRef(ref) {
|
|
29
|
-
try {
|
|
30
|
-
return await new Promise((resolve, reject) => {
|
|
31
|
-
child_process.execFile('git', createTreeCommand({ ref }), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
32
|
-
if (error) {
|
|
33
|
-
reject(error);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
resolve(stdout.split(os.EOL).map(line => line.trim()));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
throw createTreeError(error);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* @internal
|
|
47
|
-
*/
|
|
48
|
-
function readTreeAtRefSync(ref) {
|
|
49
|
-
try {
|
|
50
|
-
return child_process.execFileSync('git', createTreeCommand({ ref }), { encoding: 'utf-8' })
|
|
51
|
-
.split(os.EOL)
|
|
52
|
-
.map(line => line.trim());
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw createTreeError(error);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @internal
|
|
60
|
-
*/
|
|
61
|
-
async function loadFromGit(input) {
|
|
62
|
-
try {
|
|
63
|
-
return await new Promise((resolve, reject) => {
|
|
64
|
-
child_process.execFile('git', createShowCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
65
|
-
if (error) {
|
|
66
|
-
reject(error);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
resolve(stdout);
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
catch (error) {
|
|
75
|
-
throw createLoadError(error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* @internal
|
|
80
|
-
*/
|
|
81
|
-
function loadFromGitSync(input) {
|
|
82
|
-
try {
|
|
83
|
-
return child_process.execFileSync('git', createShowCommand(input), { encoding: 'utf-8' });
|
|
84
|
-
}
|
|
85
|
-
catch (error) {
|
|
86
|
-
throw createLoadError(error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
function parse({ path, pointer, content, options, }) {
|
|
94
|
-
if (/\.(gql|graphql)s?$/i.test(path)) {
|
|
95
|
-
return utils.parseGraphQLSDL(pointer, content, options);
|
|
96
|
-
}
|
|
97
|
-
if (/\.json$/i.test(path)) {
|
|
98
|
-
return utils.parseGraphQLJSON(pointer, content, options);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitLoader = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_tag_pluck_1 = require("@graphql-tools/graphql-tag-pluck");
|
|
6
|
+
const micromatch_1 = tslib_1.__importDefault(require("micromatch"));
|
|
7
|
+
const unixify_1 = tslib_1.__importDefault(require("unixify"));
|
|
8
|
+
const load_git_js_1 = require("./load-git.js");
|
|
9
|
+
const parse_js_1 = require("./parse.js");
|
|
10
|
+
const graphql_1 = require("graphql");
|
|
11
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
12
|
+
const is_glob_1 = tslib_1.__importDefault(require("is-glob"));
|
|
13
|
+
const process_1 = require("process");
|
|
102
14
|
// git:branch:path/to/file
|
|
103
15
|
function extractData(pointer) {
|
|
104
16
|
const parts = pointer.replace(/^git\:/i, '').split(':');
|
|
@@ -136,7 +48,7 @@ class GitLoader {
|
|
|
136
48
|
if (!refsForPaths.has(ref)) {
|
|
137
49
|
refsForPaths.set(ref, []);
|
|
138
50
|
}
|
|
139
|
-
refsForPaths.get(ref).push(
|
|
51
|
+
refsForPaths.get(ref).push((0, unixify_1.default)(path));
|
|
140
52
|
for (const ignore of ignores) {
|
|
141
53
|
const data = extractData(ignore);
|
|
142
54
|
if (data === null) {
|
|
@@ -146,11 +58,11 @@ class GitLoader {
|
|
|
146
58
|
if (!refsForPaths.has(ref)) {
|
|
147
59
|
refsForPaths.set(ref, []);
|
|
148
60
|
}
|
|
149
|
-
refsForPaths.get(ref).push(`!${
|
|
61
|
+
refsForPaths.get(ref).push(`!${(0, unixify_1.default)(path)}`);
|
|
150
62
|
}
|
|
151
63
|
const resolved = [];
|
|
152
64
|
await Promise.all([...refsForPaths.entries()].map(async ([ref, paths]) => {
|
|
153
|
-
resolved.push(...
|
|
65
|
+
resolved.push(...(0, micromatch_1.default)(await (0, load_git_js_1.readTreeAtRef)(ref), paths).map(filePath => `git:${ref}:${filePath}`));
|
|
154
66
|
}));
|
|
155
67
|
return resolved;
|
|
156
68
|
}
|
|
@@ -164,7 +76,7 @@ class GitLoader {
|
|
|
164
76
|
if (!refsForPaths.has(ref)) {
|
|
165
77
|
refsForPaths.set(ref, []);
|
|
166
78
|
}
|
|
167
|
-
refsForPaths.get(ref).push(
|
|
79
|
+
refsForPaths.get(ref).push((0, unixify_1.default)(path));
|
|
168
80
|
for (const ignore of ignores) {
|
|
169
81
|
const data = extractData(ignore);
|
|
170
82
|
if (data === null) {
|
|
@@ -174,11 +86,11 @@ class GitLoader {
|
|
|
174
86
|
if (!refsForPaths.has(ref)) {
|
|
175
87
|
refsForPaths.set(ref, []);
|
|
176
88
|
}
|
|
177
|
-
refsForPaths.get(ref).push(`!${
|
|
89
|
+
refsForPaths.get(ref).push(`!${(0, unixify_1.default)(path)}`);
|
|
178
90
|
}
|
|
179
91
|
const resolved = [];
|
|
180
92
|
for (const [ref, paths] of refsForPaths.entries()) {
|
|
181
|
-
resolved.push(...
|
|
93
|
+
resolved.push(...(0, micromatch_1.default)((0, load_git_js_1.readTreeAtRefSync)(ref), paths).map(filePath => `git:${ref}:${filePath}`));
|
|
182
94
|
}
|
|
183
95
|
return resolved;
|
|
184
96
|
}
|
|
@@ -188,15 +100,15 @@ class GitLoader {
|
|
|
188
100
|
return [];
|
|
189
101
|
}
|
|
190
102
|
const { ref, path } = result;
|
|
191
|
-
const content = await loadFromGit({ ref, path });
|
|
192
|
-
const parsed = parse({ path, options, pointer, content });
|
|
103
|
+
const content = await (0, load_git_js_1.loadFromGit)({ ref, path });
|
|
104
|
+
const parsed = (0, parse_js_1.parse)({ path, options, pointer, content });
|
|
193
105
|
if (parsed) {
|
|
194
106
|
return [parsed];
|
|
195
107
|
}
|
|
196
|
-
const sources = await
|
|
108
|
+
const sources = await (0, graphql_tag_pluck_1.gqlPluckFromCodeString)(pointer, content, options.pluckConfig);
|
|
197
109
|
return sources.map(source => ({
|
|
198
110
|
location: pointer,
|
|
199
|
-
document:
|
|
111
|
+
document: (0, graphql_1.parse)(source, options),
|
|
200
112
|
}));
|
|
201
113
|
}
|
|
202
114
|
async load(pointer, options) {
|
|
@@ -208,8 +120,8 @@ class GitLoader {
|
|
|
208
120
|
const finalResult = [];
|
|
209
121
|
const errors = [];
|
|
210
122
|
try {
|
|
211
|
-
if (
|
|
212
|
-
const resolvedPaths = await this.resolveGlobs(pointer,
|
|
123
|
+
if ((0, is_glob_1.default)(path)) {
|
|
124
|
+
const resolvedPaths = await this.resolveGlobs(pointer, (0, utils_1.asArray)(options.ignore || []));
|
|
213
125
|
await Promise.all(resolvedPaths.map(async (path) => {
|
|
214
126
|
const results = await this.load(path, options);
|
|
215
127
|
results === null || results === void 0 ? void 0 : results.forEach(result => finalResult.push(result));
|
|
@@ -221,10 +133,10 @@ class GitLoader {
|
|
|
221
133
|
}
|
|
222
134
|
}
|
|
223
135
|
catch (error) {
|
|
224
|
-
if (
|
|
136
|
+
if (process_1.env['DEBUG']) {
|
|
225
137
|
console.error(error);
|
|
226
138
|
}
|
|
227
|
-
if (error instanceof
|
|
139
|
+
if (error instanceof utils_1.AggregateError) {
|
|
228
140
|
for (const errorElement of error.errors) {
|
|
229
141
|
errors.push(errorElement);
|
|
230
142
|
}
|
|
@@ -237,7 +149,7 @@ class GitLoader {
|
|
|
237
149
|
if (errors.length === 1) {
|
|
238
150
|
throw errors[0];
|
|
239
151
|
}
|
|
240
|
-
throw new
|
|
152
|
+
throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
|
|
241
153
|
}
|
|
242
154
|
return finalResult;
|
|
243
155
|
}
|
|
@@ -247,15 +159,15 @@ class GitLoader {
|
|
|
247
159
|
return [];
|
|
248
160
|
}
|
|
249
161
|
const { ref, path } = result;
|
|
250
|
-
const content = loadFromGitSync({ ref, path });
|
|
251
|
-
const parsed = parse({ path, options, pointer, content });
|
|
162
|
+
const content = (0, load_git_js_1.loadFromGitSync)({ ref, path });
|
|
163
|
+
const parsed = (0, parse_js_1.parse)({ path, options, pointer, content });
|
|
252
164
|
if (parsed) {
|
|
253
165
|
return [parsed];
|
|
254
166
|
}
|
|
255
|
-
const sources =
|
|
167
|
+
const sources = (0, graphql_tag_pluck_1.gqlPluckFromCodeStringSync)(pointer, content, options.pluckConfig);
|
|
256
168
|
return sources.map(source => ({
|
|
257
169
|
location: pointer,
|
|
258
|
-
document:
|
|
170
|
+
document: (0, graphql_1.parse)(source, options),
|
|
259
171
|
}));
|
|
260
172
|
}
|
|
261
173
|
loadSync(pointer, options) {
|
|
@@ -267,8 +179,8 @@ class GitLoader {
|
|
|
267
179
|
const finalResult = [];
|
|
268
180
|
const errors = [];
|
|
269
181
|
try {
|
|
270
|
-
if (
|
|
271
|
-
const resolvedPaths = this.resolveGlobsSync(pointer,
|
|
182
|
+
if ((0, is_glob_1.default)(path)) {
|
|
183
|
+
const resolvedPaths = this.resolveGlobsSync(pointer, (0, utils_1.asArray)(options.ignore || []));
|
|
272
184
|
const finalResult = [];
|
|
273
185
|
for (const path of resolvedPaths) {
|
|
274
186
|
if (this.canLoadSync(path)) {
|
|
@@ -287,10 +199,10 @@ class GitLoader {
|
|
|
287
199
|
}
|
|
288
200
|
}
|
|
289
201
|
catch (error) {
|
|
290
|
-
if (
|
|
202
|
+
if (process_1.env['DEBUG']) {
|
|
291
203
|
console.error(error);
|
|
292
204
|
}
|
|
293
|
-
if (error instanceof
|
|
205
|
+
if (error instanceof utils_1.AggregateError) {
|
|
294
206
|
for (const errorElement of error.errors) {
|
|
295
207
|
errors.push(errorElement);
|
|
296
208
|
}
|
|
@@ -303,10 +215,9 @@ class GitLoader {
|
|
|
303
215
|
if (errors.length === 1) {
|
|
304
216
|
throw errors[0];
|
|
305
217
|
}
|
|
306
|
-
throw new
|
|
218
|
+
throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
|
|
307
219
|
}
|
|
308
220
|
return finalResult;
|
|
309
221
|
}
|
|
310
222
|
}
|
|
311
|
-
|
|
312
223
|
exports.GitLoader = GitLoader;
|
package/cjs/load-git.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadFromGitSync = exports.loadFromGit = exports.readTreeAtRefSync = exports.readTreeAtRef = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const os_1 = tslib_1.__importDefault(require("os"));
|
|
7
|
+
const createLoadError = (error) => new Error('Unable to load file from git: ' + error);
|
|
8
|
+
const createShowCommand = ({ ref, path }) => {
|
|
9
|
+
return ['show', `${ref}:${path}`];
|
|
10
|
+
};
|
|
11
|
+
const createTreeError = (error) => new Error('Unable to load the file tree from git: ' + error);
|
|
12
|
+
const createTreeCommand = ({ ref }) => {
|
|
13
|
+
return ['ls-tree', '-r', '--name-only', ref];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
async function readTreeAtRef(ref) {
|
|
19
|
+
try {
|
|
20
|
+
return await new Promise((resolve, reject) => {
|
|
21
|
+
(0, child_process_1.execFile)('git', createTreeCommand({ ref }), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
22
|
+
if (error) {
|
|
23
|
+
reject(error);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
resolve(stdout.split(os_1.default.EOL).map(line => line.trim()));
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
throw createTreeError(error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.readTreeAtRef = readTreeAtRef;
|
|
36
|
+
/**
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
function readTreeAtRefSync(ref) {
|
|
40
|
+
try {
|
|
41
|
+
return (0, child_process_1.execFileSync)('git', createTreeCommand({ ref }), { encoding: 'utf-8' })
|
|
42
|
+
.split(os_1.default.EOL)
|
|
43
|
+
.map(line => line.trim());
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
throw createTreeError(error);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.readTreeAtRefSync = readTreeAtRefSync;
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
async function loadFromGit(input) {
|
|
54
|
+
try {
|
|
55
|
+
return await new Promise((resolve, reject) => {
|
|
56
|
+
(0, child_process_1.execFile)('git', createShowCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
57
|
+
if (error) {
|
|
58
|
+
reject(error);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
resolve(stdout);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
throw createLoadError(error);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.loadFromGit = loadFromGit;
|
|
71
|
+
/**
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
function loadFromGitSync(input) {
|
|
75
|
+
try {
|
|
76
|
+
return (0, child_process_1.execFileSync)('git', createShowCommand(input), { encoding: 'utf-8' });
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw createLoadError(error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.loadFromGitSync = loadFromGitSync;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/cjs/parse.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parse = void 0;
|
|
4
|
+
const utils_1 = require("@graphql-tools/utils");
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
function parse({ path, pointer, content, options, }) {
|
|
9
|
+
if (/\.(gql|graphql)s?$/i.test(path)) {
|
|
10
|
+
return (0, utils_1.parseGraphQLSDL)(pointer, content, options);
|
|
11
|
+
}
|
|
12
|
+
if (/\.json$/i.test(path)) {
|
|
13
|
+
return (0, utils_1.parseGraphQLJSON)(pointer, content, options);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.parse = parse;
|
|
@@ -1,98 +1,12 @@
|
|
|
1
|
-
import { gqlPluckFromCodeString, gqlPluckFromCodeStringSync } from '@graphql-tools/graphql-tag-pluck';
|
|
1
|
+
import { gqlPluckFromCodeString, gqlPluckFromCodeStringSync, } from '@graphql-tools/graphql-tag-pluck';
|
|
2
2
|
import micromatch from 'micromatch';
|
|
3
3
|
import unixify from 'unixify';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { loadFromGit, loadFromGitSync, readTreeAtRef, readTreeAtRefSync } from './load-git.js';
|
|
5
|
+
import { parse as handleStuff } from './parse.js';
|
|
6
|
+
import { parse } from 'graphql';
|
|
7
|
+
import { asArray, AggregateError } from '@graphql-tools/utils';
|
|
8
8
|
import isGlob from 'is-glob';
|
|
9
9
|
import { env } from 'process';
|
|
10
|
-
|
|
11
|
-
const createLoadError = (error) => new Error('Unable to load file from git: ' + error);
|
|
12
|
-
const createShowCommand = ({ ref, path }) => {
|
|
13
|
-
return ['show', `${ref}:${path}`];
|
|
14
|
-
};
|
|
15
|
-
const createTreeError = (error) => new Error('Unable to load the file tree from git: ' + error);
|
|
16
|
-
const createTreeCommand = ({ ref }) => {
|
|
17
|
-
return ['ls-tree', '-r', '--name-only', ref];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
async function readTreeAtRef(ref) {
|
|
23
|
-
try {
|
|
24
|
-
return await new Promise((resolve, reject) => {
|
|
25
|
-
execFile('git', createTreeCommand({ ref }), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
26
|
-
if (error) {
|
|
27
|
-
reject(error);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
resolve(stdout.split(os.EOL).map(line => line.trim()));
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
throw createTreeError(error);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @internal
|
|
41
|
-
*/
|
|
42
|
-
function readTreeAtRefSync(ref) {
|
|
43
|
-
try {
|
|
44
|
-
return execFileSync('git', createTreeCommand({ ref }), { encoding: 'utf-8' })
|
|
45
|
-
.split(os.EOL)
|
|
46
|
-
.map(line => line.trim());
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
throw createTreeError(error);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
async function loadFromGit(input) {
|
|
56
|
-
try {
|
|
57
|
-
return await new Promise((resolve, reject) => {
|
|
58
|
-
execFile('git', createShowCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
59
|
-
if (error) {
|
|
60
|
-
reject(error);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
resolve(stdout);
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
throw createLoadError(error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* @internal
|
|
74
|
-
*/
|
|
75
|
-
function loadFromGitSync(input) {
|
|
76
|
-
try {
|
|
77
|
-
return execFileSync('git', createShowCommand(input), { encoding: 'utf-8' });
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
throw createLoadError(error);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @internal
|
|
86
|
-
*/
|
|
87
|
-
function parse({ path, pointer, content, options, }) {
|
|
88
|
-
if (/\.(gql|graphql)s?$/i.test(path)) {
|
|
89
|
-
return parseGraphQLSDL(pointer, content, options);
|
|
90
|
-
}
|
|
91
|
-
if (/\.json$/i.test(path)) {
|
|
92
|
-
return parseGraphQLJSON(pointer, content, options);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
10
|
// git:branch:path/to/file
|
|
97
11
|
function extractData(pointer) {
|
|
98
12
|
const parts = pointer.replace(/^git\:/i, '').split(':');
|
|
@@ -113,7 +27,7 @@ function extractData(pointer) {
|
|
|
113
27
|
* })
|
|
114
28
|
* ```
|
|
115
29
|
*/
|
|
116
|
-
class GitLoader {
|
|
30
|
+
export class GitLoader {
|
|
117
31
|
async canLoad(pointer) {
|
|
118
32
|
return this.canLoadSync(pointer);
|
|
119
33
|
}
|
|
@@ -183,14 +97,14 @@ class GitLoader {
|
|
|
183
97
|
}
|
|
184
98
|
const { ref, path } = result;
|
|
185
99
|
const content = await loadFromGit({ ref, path });
|
|
186
|
-
const parsed =
|
|
100
|
+
const parsed = handleStuff({ path, options, pointer, content });
|
|
187
101
|
if (parsed) {
|
|
188
102
|
return [parsed];
|
|
189
103
|
}
|
|
190
104
|
const sources = await gqlPluckFromCodeString(pointer, content, options.pluckConfig);
|
|
191
105
|
return sources.map(source => ({
|
|
192
106
|
location: pointer,
|
|
193
|
-
document: parse
|
|
107
|
+
document: parse(source, options),
|
|
194
108
|
}));
|
|
195
109
|
}
|
|
196
110
|
async load(pointer, options) {
|
|
@@ -242,14 +156,14 @@ class GitLoader {
|
|
|
242
156
|
}
|
|
243
157
|
const { ref, path } = result;
|
|
244
158
|
const content = loadFromGitSync({ ref, path });
|
|
245
|
-
const parsed =
|
|
159
|
+
const parsed = handleStuff({ path, options, pointer, content });
|
|
246
160
|
if (parsed) {
|
|
247
161
|
return [parsed];
|
|
248
162
|
}
|
|
249
163
|
const sources = gqlPluckFromCodeStringSync(pointer, content, options.pluckConfig);
|
|
250
164
|
return sources.map(source => ({
|
|
251
165
|
location: pointer,
|
|
252
|
-
document: parse
|
|
166
|
+
document: parse(source, options),
|
|
253
167
|
}));
|
|
254
168
|
}
|
|
255
169
|
loadSync(pointer, options) {
|
|
@@ -302,5 +216,3 @@ class GitLoader {
|
|
|
302
216
|
return finalResult;
|
|
303
217
|
}
|
|
304
218
|
}
|
|
305
|
-
|
|
306
|
-
export { GitLoader };
|
package/esm/load-git.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { execFile, execFileSync } from 'child_process';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
const createLoadError = (error) => new Error('Unable to load file from git: ' + error);
|
|
4
|
+
const createShowCommand = ({ ref, path }) => {
|
|
5
|
+
return ['show', `${ref}:${path}`];
|
|
6
|
+
};
|
|
7
|
+
const createTreeError = (error) => new Error('Unable to load the file tree from git: ' + error);
|
|
8
|
+
const createTreeCommand = ({ ref }) => {
|
|
9
|
+
return ['ls-tree', '-r', '--name-only', ref];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export async function readTreeAtRef(ref) {
|
|
15
|
+
try {
|
|
16
|
+
return await new Promise((resolve, reject) => {
|
|
17
|
+
execFile('git', createTreeCommand({ ref }), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
18
|
+
if (error) {
|
|
19
|
+
reject(error);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
resolve(stdout.split(os.EOL).map(line => line.trim()));
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
throw createTreeError(error);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export function readTreeAtRefSync(ref) {
|
|
35
|
+
try {
|
|
36
|
+
return execFileSync('git', createTreeCommand({ ref }), { encoding: 'utf-8' })
|
|
37
|
+
.split(os.EOL)
|
|
38
|
+
.map(line => line.trim());
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw createTreeError(error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export async function loadFromGit(input) {
|
|
48
|
+
try {
|
|
49
|
+
return await new Promise((resolve, reject) => {
|
|
50
|
+
execFile('git', createShowCommand(input), { encoding: 'utf-8', maxBuffer: 1024 * 1024 * 1024 }, (error, stdout) => {
|
|
51
|
+
if (error) {
|
|
52
|
+
reject(error);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
resolve(stdout);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
throw createLoadError(error);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
export function loadFromGitSync(input) {
|
|
68
|
+
try {
|
|
69
|
+
return execFileSync('git', createShowCommand(input), { encoding: 'utf-8' });
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
throw createLoadError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
package/esm/parse.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { parseGraphQLSDL, parseGraphQLJSON } from '@graphql-tools/utils';
|
|
2
|
+
/**
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export function parse({ path, pointer, content, options, }) {
|
|
6
|
+
if (/\.(gql|graphql)s?$/i.test(path)) {
|
|
7
|
+
return parseGraphQLSDL(pointer, content, options);
|
|
8
|
+
}
|
|
9
|
+
if (/\.json$/i.test(path)) {
|
|
10
|
+
return parseGraphQLJSON(pointer, content, options);
|
|
11
|
+
}
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/git-loader",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0-alpha-6c480b2d.0",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/graphql-tag-pluck": "7.
|
|
11
|
-
"@graphql-tools/utils": "8.
|
|
10
|
+
"@graphql-tools/graphql-tag-pluck": "7.3.0-alpha-6c480b2d.0",
|
|
11
|
+
"@graphql-tools/utils": "8.8.0-alpha-6c480b2d.0",
|
|
12
12
|
"is-glob": "4.0.3",
|
|
13
13
|
"micromatch": "^4.0.4",
|
|
14
14
|
"tslib": "^2.4.0",
|
|
@@ -21,21 +21,42 @@
|
|
|
21
21
|
},
|
|
22
22
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"main": "index.js",
|
|
25
|
-
"module": "index.
|
|
26
|
-
"typings": "index.d.ts",
|
|
24
|
+
"main": "cjs/index.js",
|
|
25
|
+
"module": "esm/index.js",
|
|
26
|
+
"typings": "typings/index.d.ts",
|
|
27
27
|
"typescript": {
|
|
28
|
-
"definition": "index.d.ts"
|
|
28
|
+
"definition": "typings/index.d.ts"
|
|
29
29
|
},
|
|
30
|
+
"type": "module",
|
|
30
31
|
"exports": {
|
|
31
32
|
".": {
|
|
32
|
-
"require":
|
|
33
|
-
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./typings/index.d.ts",
|
|
35
|
+
"default": "./cjs/index.js"
|
|
36
|
+
},
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
},
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./typings/index.d.ts",
|
|
43
|
+
"default": "./esm/index.js"
|
|
44
|
+
}
|
|
34
45
|
},
|
|
35
46
|
"./*": {
|
|
36
|
-
"require":
|
|
37
|
-
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./typings/*.d.ts",
|
|
49
|
+
"default": "./cjs/*.js"
|
|
50
|
+
},
|
|
51
|
+
"import": {
|
|
52
|
+
"types": "./typings/*.d.ts",
|
|
53
|
+
"default": "./esm/*.js"
|
|
54
|
+
},
|
|
55
|
+
"default": {
|
|
56
|
+
"types": "./typings/*.d.ts",
|
|
57
|
+
"default": "./esm/*.js"
|
|
58
|
+
}
|
|
38
59
|
},
|
|
39
60
|
"./package.json": "./package.json"
|
|
40
61
|
}
|
|
41
|
-
}
|
|
62
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|