@graphql-tools/load-files 6.5.2 → 6.6.0-alpha-b76ec274.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} +45 -57
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +22 -13
- package/package.json +37 -15
- package/{index.d.ts → typings/index.d.ts} +0 -0
- package/README.md +0 -5
|
@@ -1,36 +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
|
-
|
|
33
|
-
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;
|
|
34
13
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
35
14
|
const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];
|
|
36
15
|
const DEFAULT_EXPORT_NAMES = ['schema', 'typeDef', 'typeDefs', 'resolver', 'resolvers'];
|
|
@@ -63,7 +42,7 @@ function asArray(obj) {
|
|
|
63
42
|
}
|
|
64
43
|
function isDirectorySync(path) {
|
|
65
44
|
try {
|
|
66
|
-
const pathStat =
|
|
45
|
+
const pathStat = (0, fs_1.statSync)(path);
|
|
67
46
|
return pathStat.isDirectory();
|
|
68
47
|
}
|
|
69
48
|
catch (e) {
|
|
@@ -80,7 +59,7 @@ async function isDirectory(path) {
|
|
|
80
59
|
}
|
|
81
60
|
}
|
|
82
61
|
function scanForFilesSync(globStr, globOptions = {}) {
|
|
83
|
-
return
|
|
62
|
+
return (0, globby_1.sync)(globStr, { absolute: true, ...globOptions });
|
|
84
63
|
}
|
|
85
64
|
function formatExtension(extension) {
|
|
86
65
|
return extension.charAt(0) === '.' ? extension : `.${extension}`;
|
|
@@ -97,6 +76,7 @@ const LoadFilesDefaultOptions = {
|
|
|
97
76
|
requireMethod: null,
|
|
98
77
|
globOptions: {
|
|
99
78
|
absolute: true,
|
|
79
|
+
cwd: (0, process_1.cwd)(),
|
|
100
80
|
},
|
|
101
81
|
exportNames: DEFAULT_EXPORT_NAMES,
|
|
102
82
|
recursive: true,
|
|
@@ -108,36 +88,37 @@ const LoadFilesDefaultOptions = {
|
|
|
108
88
|
* @param options Additional options
|
|
109
89
|
*/
|
|
110
90
|
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
111
|
-
var _a;
|
|
91
|
+
var _a, _b;
|
|
112
92
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
113
93
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
114
|
-
? buildGlob(
|
|
115
|
-
:
|
|
94
|
+
? buildGlob((0, unixify_1.default)(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
95
|
+
: (0, unixify_1.default)(path)), options.globOptions);
|
|
116
96
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
117
|
-
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'));
|
|
118
98
|
return relevantPaths
|
|
119
|
-
.map(path
|
|
120
|
-
if (!checkExtension(path
|
|
99
|
+
.map(path => {
|
|
100
|
+
if (!checkExtension(path, options)) {
|
|
121
101
|
return null;
|
|
122
102
|
}
|
|
123
|
-
if (isIndex(path
|
|
103
|
+
if (isIndex(path, execOptions.extensions) && options.ignoreIndex) {
|
|
124
104
|
return false;
|
|
125
105
|
}
|
|
126
|
-
const extension =
|
|
106
|
+
const extension = (0, path_1.extname)(path);
|
|
127
107
|
if (extension === formatExtension('js') || extension === formatExtension('ts') || execOptions.useRequire) {
|
|
128
|
-
const fileExports = requireMethod(path
|
|
108
|
+
const fileExports = requireMethod(path);
|
|
129
109
|
const extractedExport = extractExports(fileExports);
|
|
130
110
|
return extractedExport;
|
|
131
111
|
}
|
|
132
112
|
else {
|
|
133
|
-
const maybeSDL =
|
|
113
|
+
const maybeSDL = (0, fs_1.readFileSync)(path, { encoding: 'utf-8' });
|
|
134
114
|
return tryToParse(maybeSDL);
|
|
135
115
|
}
|
|
136
116
|
})
|
|
137
117
|
.filter(v => v);
|
|
138
118
|
}
|
|
119
|
+
exports.loadFilesSync = loadFilesSync;
|
|
139
120
|
async function scanForFiles(globStr, globOptions = {}) {
|
|
140
|
-
return
|
|
121
|
+
return (0, globby_1.default)(globStr, { absolute: true, ...globOptions });
|
|
141
122
|
}
|
|
142
123
|
const checkExtension = (path, { extensions, ignoredExtensions }) => {
|
|
143
124
|
if (ignoredExtensions) {
|
|
@@ -175,38 +156,45 @@ async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
|
175
156
|
var _a;
|
|
176
157
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
177
158
|
const relevantPaths = await scanForFiles(await Promise.all(asArray(pattern).map(async (path) => (await isDirectory(path))
|
|
178
|
-
? buildGlob(
|
|
179
|
-
:
|
|
159
|
+
? buildGlob((0, unixify_1.default)(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
160
|
+
: (0, unixify_1.default)(path))), options.globOptions);
|
|
180
161
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
181
|
-
const defaultRequireMethod = (path) =>
|
|
162
|
+
const defaultRequireMethod = (path) => Promise.resolve().then(() => tslib_1.__importStar(require(path))).catch(importError => {
|
|
163
|
+
var _a;
|
|
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'));
|
|
165
|
+
try {
|
|
166
|
+
return cwdRequire(path);
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
throw importError;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
182
172
|
const requireMethod = execOptions.requireMethod || defaultRequireMethod;
|
|
183
173
|
return Promise.all(relevantPaths
|
|
184
174
|
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
|
|
185
|
-
.map(async (path
|
|
186
|
-
const extension =
|
|
175
|
+
.map(async (path) => {
|
|
176
|
+
const extension = (0, path_1.extname)(path);
|
|
187
177
|
if (extension === formatExtension('js') || extension === formatExtension('ts') || execOptions.useRequire) {
|
|
188
|
-
const fileExports = await requireMethod(path
|
|
178
|
+
const fileExports = await requireMethod(path);
|
|
189
179
|
const extractedExport = extractExports(fileExports);
|
|
190
180
|
return extractedExport;
|
|
191
181
|
}
|
|
192
182
|
else {
|
|
193
|
-
const maybeSDL = await readFile(path
|
|
183
|
+
const maybeSDL = await readFile(path, { encoding: 'utf-8' });
|
|
194
184
|
return tryToParse(maybeSDL);
|
|
195
185
|
}
|
|
196
186
|
}));
|
|
197
187
|
}
|
|
188
|
+
exports.loadFiles = loadFiles;
|
|
198
189
|
function isIndex(path, extensions = []) {
|
|
199
190
|
const IS_INDEX = /(\/|\\)index\.[^\/\\]+$/i; // (/ or \) AND `index.` AND (everything except \ and /)(end of line)
|
|
200
191
|
return IS_INDEX.test(path) && extensions.some(ext => path.endsWith(formatExtension(ext)));
|
|
201
192
|
}
|
|
202
193
|
function tryToParse(maybeSDL) {
|
|
203
194
|
try {
|
|
204
|
-
return
|
|
195
|
+
return (0, graphql_1.parse)(maybeSDL);
|
|
205
196
|
}
|
|
206
197
|
catch (e) {
|
|
207
198
|
return maybeSDL;
|
|
208
199
|
}
|
|
209
200
|
}
|
|
210
|
-
|
|
211
|
-
exports.loadFiles = loadFiles;
|
|
212
|
-
exports.loadFilesSync = loadFilesSync;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import globby, { sync } from 'globby';
|
|
1
|
+
import globby, { sync as globbySync } from 'globby';
|
|
2
2
|
import unixify from 'unixify';
|
|
3
|
-
import { extname } from 'path';
|
|
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
|
-
|
|
7
|
-
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import { cwd } from 'process';
|
|
8
|
+
const { readFile, stat } = fsPromises;
|
|
8
9
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
9
10
|
const DEFAULT_EXTENSIONS = ['gql', 'graphql', 'graphqls', 'ts', 'js'];
|
|
10
11
|
const DEFAULT_EXPORT_NAMES = ['schema', 'typeDef', 'typeDefs', 'resolver', 'resolvers'];
|
|
@@ -54,7 +55,7 @@ async function isDirectory(path) {
|
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
57
|
function scanForFilesSync(globStr, globOptions = {}) {
|
|
57
|
-
return
|
|
58
|
+
return globbySync(globStr, { absolute: true, ...globOptions });
|
|
58
59
|
}
|
|
59
60
|
function formatExtension(extension) {
|
|
60
61
|
return extension.charAt(0) === '.' ? extension : `.${extension}`;
|
|
@@ -71,6 +72,7 @@ const LoadFilesDefaultOptions = {
|
|
|
71
72
|
requireMethod: null,
|
|
72
73
|
globOptions: {
|
|
73
74
|
absolute: true,
|
|
75
|
+
cwd: cwd(),
|
|
74
76
|
},
|
|
75
77
|
exportNames: DEFAULT_EXPORT_NAMES,
|
|
76
78
|
recursive: true,
|
|
@@ -81,14 +83,14 @@ const LoadFilesDefaultOptions = {
|
|
|
81
83
|
* @param pattern Glob pattern or patterns to use when loading files
|
|
82
84
|
* @param options Additional options
|
|
83
85
|
*/
|
|
84
|
-
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
85
|
-
var _a;
|
|
86
|
+
export function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
87
|
+
var _a, _b;
|
|
86
88
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
87
89
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
88
90
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
89
91
|
: unixify(path)), options.globOptions);
|
|
90
92
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
91
|
-
const requireMethod = execOptions.requireMethod ||
|
|
93
|
+
const requireMethod = execOptions.requireMethod || createRequire(join(((_b = options === null || options === void 0 ? void 0 : options.globOptions) === null || _b === void 0 ? void 0 : _b.cwd) || cwd(), 'noop.js'));
|
|
92
94
|
return relevantPaths
|
|
93
95
|
.map(path => {
|
|
94
96
|
if (!checkExtension(path, options)) {
|
|
@@ -145,14 +147,23 @@ const checkExtension = (path, { extensions, ignoredExtensions }) => {
|
|
|
145
147
|
* @param pattern Glob pattern or patterns to use when loading files
|
|
146
148
|
* @param options Additional options
|
|
147
149
|
*/
|
|
148
|
-
async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
150
|
+
export async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
149
151
|
var _a;
|
|
150
152
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
151
153
|
const relevantPaths = await scanForFiles(await Promise.all(asArray(pattern).map(async (path) => (await isDirectory(path))
|
|
152
154
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
153
155
|
: unixify(path))), options.globOptions);
|
|
154
156
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
155
|
-
const defaultRequireMethod = (path) => import(path).catch(
|
|
157
|
+
const defaultRequireMethod = (path) => import(path).catch(importError => {
|
|
158
|
+
var _a;
|
|
159
|
+
const cwdRequire = createRequire(join(((_a = options === null || options === void 0 ? void 0 : options.globOptions) === null || _a === void 0 ? void 0 : _a.cwd) || cwd(), 'noop.js'));
|
|
160
|
+
try {
|
|
161
|
+
return cwdRequire(path);
|
|
162
|
+
}
|
|
163
|
+
catch (e) {
|
|
164
|
+
throw importError;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
156
167
|
const requireMethod = execOptions.requireMethod || defaultRequireMethod;
|
|
157
168
|
return Promise.all(relevantPaths
|
|
158
169
|
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
|
|
@@ -181,5 +192,3 @@ function tryToParse(maybeSDL) {
|
|
|
181
192
|
return maybeSDL;
|
|
182
193
|
}
|
|
183
194
|
}
|
|
184
|
-
|
|
185
|
-
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-b76ec274.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,20 +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
|
-
|
|
35
|
-
|
|
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
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./package.json": "./package.json"
|
|
36
58
|
}
|
|
37
|
-
}
|
|
59
|
+
}
|
|
File without changes
|
package/README.md
DELETED