@graphql-tools/load-files 6.5.3 → 6.6.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 -61
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +7 -10
- package/package.json +35 -14
- /package/{index.d.ts → typings/index.d.ts} +0 -0
|
@@ -1,38 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return e[k];
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
n['default'] = e;
|
|
22
|
-
return n;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const globby = require('globby');
|
|
27
|
-
const globby__default = _interopDefault(globby);
|
|
28
|
-
const unixify = _interopDefault(require('unixify'));
|
|
29
|
-
const path = require('path');
|
|
30
|
-
const fs = require('fs');
|
|
31
|
-
const graphql = require('graphql');
|
|
32
|
-
const module$1 = require('module');
|
|
33
|
-
const process = require('process');
|
|
34
|
-
|
|
35
|
-
const { readFile, stat } = fs.promises;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadFiles = exports.loadFilesSync = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const globby_1 = tslib_1.__importStar(require("globby"));
|
|
6
|
+
const unixify_1 = tslib_1.__importDefault(require("unixify"));
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
10
|
+
const module_1 = require("module");
|
|
11
|
+
const process_1 = require("process");
|
|
12
|
+
const { readFile, stat } = fs_1.promises;
|
|
36
13
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
37
14
|
const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];
|
|
38
15
|
const DEFAULT_EXPORT_NAMES = ['schema', 'typeDef', 'typeDefs', 'resolver', 'resolvers'];
|
|
@@ -65,7 +42,7 @@ function asArray(obj) {
|
|
|
65
42
|
}
|
|
66
43
|
function isDirectorySync(path) {
|
|
67
44
|
try {
|
|
68
|
-
const pathStat =
|
|
45
|
+
const pathStat = (0, fs_1.statSync)(path);
|
|
69
46
|
return pathStat.isDirectory();
|
|
70
47
|
}
|
|
71
48
|
catch (e) {
|
|
@@ -82,7 +59,7 @@ async function isDirectory(path) {
|
|
|
82
59
|
}
|
|
83
60
|
}
|
|
84
61
|
function scanForFilesSync(globStr, globOptions = {}) {
|
|
85
|
-
return
|
|
62
|
+
return (0, globby_1.sync)(globStr, { absolute: true, ...globOptions });
|
|
86
63
|
}
|
|
87
64
|
function formatExtension(extension) {
|
|
88
65
|
return extension.charAt(0) === '.' ? extension : `.${extension}`;
|
|
@@ -99,7 +76,7 @@ const LoadFilesDefaultOptions = {
|
|
|
99
76
|
requireMethod: null,
|
|
100
77
|
globOptions: {
|
|
101
78
|
absolute: true,
|
|
102
|
-
cwd:
|
|
79
|
+
cwd: (0, process_1.cwd)(),
|
|
103
80
|
},
|
|
104
81
|
exportNames: DEFAULT_EXPORT_NAMES,
|
|
105
82
|
recursive: true,
|
|
@@ -114,33 +91,34 @@ function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
|
114
91
|
var _a, _b;
|
|
115
92
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
116
93
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
117
|
-
? buildGlob(
|
|
118
|
-
:
|
|
94
|
+
? buildGlob((0, unixify_1.default)(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
95
|
+
: (0, unixify_1.default)(path)), options.globOptions);
|
|
119
96
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
120
|
-
const requireMethod = execOptions.requireMethod ||
|
|
97
|
+
const requireMethod = execOptions.requireMethod || (0, module_1.createRequire)((0, path_1.join)(((_b = options === null || options === void 0 ? void 0 : options.globOptions) === null || _b === void 0 ? void 0 : _b.cwd) || (0, process_1.cwd)(), 'noop.js'));
|
|
121
98
|
return relevantPaths
|
|
122
|
-
.map(path
|
|
123
|
-
if (!checkExtension(path
|
|
99
|
+
.map(path => {
|
|
100
|
+
if (!checkExtension(path, options)) {
|
|
124
101
|
return null;
|
|
125
102
|
}
|
|
126
|
-
if (isIndex(path
|
|
103
|
+
if (isIndex(path, execOptions.extensions) && options.ignoreIndex) {
|
|
127
104
|
return false;
|
|
128
105
|
}
|
|
129
|
-
const extension =
|
|
106
|
+
const extension = (0, path_1.extname)(path);
|
|
130
107
|
if (extension === formatExtension('js') || extension === formatExtension('ts') || execOptions.useRequire) {
|
|
131
|
-
const fileExports = requireMethod(path
|
|
108
|
+
const fileExports = requireMethod(path);
|
|
132
109
|
const extractedExport = extractExports(fileExports);
|
|
133
110
|
return extractedExport;
|
|
134
111
|
}
|
|
135
112
|
else {
|
|
136
|
-
const maybeSDL =
|
|
113
|
+
const maybeSDL = (0, fs_1.readFileSync)(path, { encoding: 'utf-8' });
|
|
137
114
|
return tryToParse(maybeSDL);
|
|
138
115
|
}
|
|
139
116
|
})
|
|
140
117
|
.filter(v => v);
|
|
141
118
|
}
|
|
119
|
+
exports.loadFilesSync = loadFilesSync;
|
|
142
120
|
async function scanForFiles(globStr, globOptions = {}) {
|
|
143
|
-
return
|
|
121
|
+
return (0, globby_1.default)(globStr, { absolute: true, ...globOptions });
|
|
144
122
|
}
|
|
145
123
|
const checkExtension = (path, { extensions, ignoredExtensions }) => {
|
|
146
124
|
if (ignoredExtensions) {
|
|
@@ -178,14 +156,14 @@ async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
|
178
156
|
var _a;
|
|
179
157
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
180
158
|
const relevantPaths = await scanForFiles(await Promise.all(asArray(pattern).map(async (path) => (await isDirectory(path))
|
|
181
|
-
? buildGlob(
|
|
182
|
-
:
|
|
159
|
+
? buildGlob((0, unixify_1.default)(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
160
|
+
: (0, unixify_1.default)(path))), options.globOptions);
|
|
183
161
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
184
|
-
const defaultRequireMethod = (path
|
|
162
|
+
const defaultRequireMethod = (path) => Promise.resolve().then(() => tslib_1.__importStar(require(path))).catch(importError => {
|
|
185
163
|
var _a;
|
|
186
|
-
const cwdRequire =
|
|
164
|
+
const cwdRequire = (0, module_1.createRequire)((0, path_1.join)(((_a = options === null || options === void 0 ? void 0 : options.globOptions) === null || _a === void 0 ? void 0 : _a.cwd) || (0, process_1.cwd)(), 'noop.js'));
|
|
187
165
|
try {
|
|
188
|
-
return cwdRequire(path
|
|
166
|
+
return cwdRequire(path);
|
|
189
167
|
}
|
|
190
168
|
catch (e) {
|
|
191
169
|
throw importError;
|
|
@@ -194,31 +172,29 @@ async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
|
194
172
|
const requireMethod = execOptions.requireMethod || defaultRequireMethod;
|
|
195
173
|
return Promise.all(relevantPaths
|
|
196
174
|
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
|
|
197
|
-
.map(async (path
|
|
198
|
-
const extension =
|
|
175
|
+
.map(async (path) => {
|
|
176
|
+
const extension = (0, path_1.extname)(path);
|
|
199
177
|
if (extension === formatExtension('js') || extension === formatExtension('ts') || execOptions.useRequire) {
|
|
200
|
-
const fileExports = await requireMethod(path
|
|
178
|
+
const fileExports = await requireMethod(path);
|
|
201
179
|
const extractedExport = extractExports(fileExports);
|
|
202
180
|
return extractedExport;
|
|
203
181
|
}
|
|
204
182
|
else {
|
|
205
|
-
const maybeSDL = await readFile(path
|
|
183
|
+
const maybeSDL = await readFile(path, { encoding: 'utf-8' });
|
|
206
184
|
return tryToParse(maybeSDL);
|
|
207
185
|
}
|
|
208
186
|
}));
|
|
209
187
|
}
|
|
188
|
+
exports.loadFiles = loadFiles;
|
|
210
189
|
function isIndex(path, extensions = []) {
|
|
211
190
|
const IS_INDEX = /(\/|\\)index\.[^\/\\]+$/i; // (/ or \) AND `index.` AND (everything except \ and /)(end of line)
|
|
212
191
|
return IS_INDEX.test(path) && extensions.some(ext => path.endsWith(formatExtension(ext)));
|
|
213
192
|
}
|
|
214
193
|
function tryToParse(maybeSDL) {
|
|
215
194
|
try {
|
|
216
|
-
return
|
|
195
|
+
return (0, graphql_1.parse)(maybeSDL);
|
|
217
196
|
}
|
|
218
197
|
catch (e) {
|
|
219
198
|
return maybeSDL;
|
|
220
199
|
}
|
|
221
200
|
}
|
|
222
|
-
|
|
223
|
-
exports.loadFiles = loadFiles;
|
|
224
|
-
exports.loadFilesSync = loadFilesSync;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import globby, { sync } from 'globby';
|
|
1
|
+
import globby, { sync as globbySync } from 'globby';
|
|
2
2
|
import unixify from 'unixify';
|
|
3
|
-
import {
|
|
4
|
-
import { readFileSync, promises
|
|
3
|
+
import { extname, join } from 'path';
|
|
4
|
+
import { statSync, readFileSync, promises as fsPromises } from 'fs';
|
|
5
5
|
import { parse } from 'graphql';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
import { cwd } from 'process';
|
|
8
|
-
|
|
9
|
-
const { readFile, stat } = promises;
|
|
8
|
+
const { readFile, stat } = fsPromises;
|
|
10
9
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
11
10
|
const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];
|
|
12
11
|
const DEFAULT_EXPORT_NAMES = ['schema', 'typeDef', 'typeDefs', 'resolver', 'resolvers'];
|
|
@@ -56,7 +55,7 @@ async function isDirectory(path) {
|
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
function scanForFilesSync(globStr, globOptions = {}) {
|
|
59
|
-
return
|
|
58
|
+
return globbySync(globStr, { absolute: true, ...globOptions });
|
|
60
59
|
}
|
|
61
60
|
function formatExtension(extension) {
|
|
62
61
|
return extension.charAt(0) === '.' ? extension : `.${extension}`;
|
|
@@ -84,7 +83,7 @@ const LoadFilesDefaultOptions = {
|
|
|
84
83
|
* @param pattern Glob pattern or patterns to use when loading files
|
|
85
84
|
* @param options Additional options
|
|
86
85
|
*/
|
|
87
|
-
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
86
|
+
export function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
88
87
|
var _a, _b;
|
|
89
88
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
90
89
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
@@ -148,7 +147,7 @@ const checkExtension = (path, { extensions, ignoredExtensions }) => {
|
|
|
148
147
|
* @param pattern Glob pattern or patterns to use when loading files
|
|
149
148
|
* @param options Additional options
|
|
150
149
|
*/
|
|
151
|
-
async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
150
|
+
export async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
152
151
|
var _a;
|
|
153
152
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
154
153
|
const relevantPaths = await scanForFiles(await Promise.all(asArray(pattern).map(async (path) => (await isDirectory(path))
|
|
@@ -193,5 +192,3 @@ function tryToParse(maybeSDL) {
|
|
|
193
192
|
return maybeSDL;
|
|
194
193
|
}
|
|
195
194
|
}
|
|
196
|
-
|
|
197
|
-
export { loadFiles, loadFilesSync };
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/load-files",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.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
|
-
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"globby": "11.0
|
|
11
|
-
"
|
|
12
|
-
"
|
|
10
|
+
"globby": "11.1.0",
|
|
11
|
+
"unixify": "1.0.0",
|
|
12
|
+
"tslib": "^2.4.0"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"type": "git",
|
|
@@ -18,21 +18,42 @@
|
|
|
18
18
|
},
|
|
19
19
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
20
20
|
"license": "MIT",
|
|
21
|
-
"main": "index.js",
|
|
22
|
-
"module": "index.
|
|
23
|
-
"typings": "index.d.ts",
|
|
21
|
+
"main": "cjs/index.js",
|
|
22
|
+
"module": "esm/index.js",
|
|
23
|
+
"typings": "typings/index.d.ts",
|
|
24
24
|
"typescript": {
|
|
25
|
-
"definition": "index.d.ts"
|
|
25
|
+
"definition": "typings/index.d.ts"
|
|
26
26
|
},
|
|
27
|
+
"type": "module",
|
|
27
28
|
"exports": {
|
|
28
29
|
".": {
|
|
29
|
-
"require":
|
|
30
|
-
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./typings/index.d.ts",
|
|
32
|
+
"default": "./cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./typings/index.d.ts",
|
|
36
|
+
"default": "./esm/index.js"
|
|
37
|
+
},
|
|
38
|
+
"default": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
41
|
+
}
|
|
31
42
|
},
|
|
32
43
|
"./*": {
|
|
33
|
-
"require":
|
|
34
|
-
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./typings/*.d.ts",
|
|
46
|
+
"default": "./cjs/*.js"
|
|
47
|
+
},
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./typings/*.d.ts",
|
|
50
|
+
"default": "./esm/*.js"
|
|
51
|
+
},
|
|
52
|
+
"default": {
|
|
53
|
+
"types": "./typings/*.d.ts",
|
|
54
|
+
"default": "./esm/*.js"
|
|
55
|
+
}
|
|
35
56
|
},
|
|
36
57
|
"./package.json": "./package.json"
|
|
37
58
|
}
|
|
38
|
-
}
|
|
59
|
+
}
|
|
File without changes
|