@graphql-tools/load-files 6.5.2 → 6.5.3
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 +15 -3
- package/index.mjs +16 -4
- package/package.json +3 -2
package/index.js
CHANGED
|
@@ -29,6 +29,8 @@ const unixify = _interopDefault(require('unixify'));
|
|
|
29
29
|
const path = require('path');
|
|
30
30
|
const fs = require('fs');
|
|
31
31
|
const graphql = require('graphql');
|
|
32
|
+
const module$1 = require('module');
|
|
33
|
+
const process = require('process');
|
|
32
34
|
|
|
33
35
|
const { readFile, stat } = fs.promises;
|
|
34
36
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
@@ -97,6 +99,7 @@ const LoadFilesDefaultOptions = {
|
|
|
97
99
|
requireMethod: null,
|
|
98
100
|
globOptions: {
|
|
99
101
|
absolute: true,
|
|
102
|
+
cwd: process.cwd(),
|
|
100
103
|
},
|
|
101
104
|
exportNames: DEFAULT_EXPORT_NAMES,
|
|
102
105
|
recursive: true,
|
|
@@ -108,13 +111,13 @@ const LoadFilesDefaultOptions = {
|
|
|
108
111
|
* @param options Additional options
|
|
109
112
|
*/
|
|
110
113
|
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
111
|
-
var _a;
|
|
114
|
+
var _a, _b;
|
|
112
115
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
113
116
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
114
117
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
115
118
|
: unixify(path)), options.globOptions);
|
|
116
119
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
117
|
-
const requireMethod = execOptions.requireMethod ||
|
|
120
|
+
const requireMethod = execOptions.requireMethod || module$1.createRequire(path.join(((_b = options === null || options === void 0 ? void 0 : options.globOptions) === null || _b === void 0 ? void 0 : _b.cwd) || process.cwd(), 'noop.js'));
|
|
118
121
|
return relevantPaths
|
|
119
122
|
.map(path$1 => {
|
|
120
123
|
if (!checkExtension(path$1, options)) {
|
|
@@ -178,7 +181,16 @@ async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
|
178
181
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
179
182
|
: unixify(path))), options.globOptions);
|
|
180
183
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
181
|
-
const defaultRequireMethod = (path) => new Promise(function (resolve) { resolve(_interopNamespace(require(path))); }).catch(
|
|
184
|
+
const defaultRequireMethod = (path$1) => new Promise(function (resolve) { resolve(_interopNamespace(require(path$1))); }).catch(importError => {
|
|
185
|
+
var _a;
|
|
186
|
+
const cwdRequire = module$1.createRequire(path.join(((_a = options === null || options === void 0 ? void 0 : options.globOptions) === null || _a === void 0 ? void 0 : _a.cwd) || process.cwd(), 'noop.js'));
|
|
187
|
+
try {
|
|
188
|
+
return cwdRequire(path$1);
|
|
189
|
+
}
|
|
190
|
+
catch (e) {
|
|
191
|
+
throw importError;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
182
194
|
const requireMethod = execOptions.requireMethod || defaultRequireMethod;
|
|
183
195
|
return Promise.all(relevantPaths
|
|
184
196
|
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
|
package/index.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import globby, { sync } from 'globby';
|
|
2
2
|
import unixify from 'unixify';
|
|
3
|
-
import { extname } from 'path';
|
|
3
|
+
import { join, extname } from 'path';
|
|
4
4
|
import { readFileSync, promises, statSync } from 'fs';
|
|
5
5
|
import { parse } from 'graphql';
|
|
6
|
+
import { createRequire } from 'module';
|
|
7
|
+
import { cwd } from 'process';
|
|
6
8
|
|
|
7
9
|
const { readFile, stat } = promises;
|
|
8
10
|
const DEFAULT_IGNORED_EXTENSIONS = ['spec', 'test', 'd', 'map'];
|
|
@@ -71,6 +73,7 @@ const LoadFilesDefaultOptions = {
|
|
|
71
73
|
requireMethod: null,
|
|
72
74
|
globOptions: {
|
|
73
75
|
absolute: true,
|
|
76
|
+
cwd: cwd(),
|
|
74
77
|
},
|
|
75
78
|
exportNames: DEFAULT_EXPORT_NAMES,
|
|
76
79
|
recursive: true,
|
|
@@ -82,13 +85,13 @@ const LoadFilesDefaultOptions = {
|
|
|
82
85
|
* @param options Additional options
|
|
83
86
|
*/
|
|
84
87
|
function loadFilesSync(pattern, options = LoadFilesDefaultOptions) {
|
|
85
|
-
var _a;
|
|
88
|
+
var _a, _b;
|
|
86
89
|
const execOptions = { ...LoadFilesDefaultOptions, ...options };
|
|
87
90
|
const relevantPaths = scanForFilesSync(asArray(pattern).map(path => isDirectorySync(path)
|
|
88
91
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
89
92
|
: unixify(path)), options.globOptions);
|
|
90
93
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
91
|
-
const requireMethod = execOptions.requireMethod ||
|
|
94
|
+
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
95
|
return relevantPaths
|
|
93
96
|
.map(path => {
|
|
94
97
|
if (!checkExtension(path, options)) {
|
|
@@ -152,7 +155,16 @@ async function loadFiles(pattern, options = LoadFilesDefaultOptions) {
|
|
|
152
155
|
? buildGlob(unixify(path), execOptions.extensions, execOptions.ignoredExtensions, execOptions.recursive)
|
|
153
156
|
: unixify(path))), options.globOptions);
|
|
154
157
|
const extractExports = execOptions.extractExports || DEFAULT_EXTRACT_EXPORTS_FACTORY((_a = execOptions.exportNames) !== null && _a !== void 0 ? _a : []);
|
|
155
|
-
const defaultRequireMethod = (path) => import(path).catch(
|
|
158
|
+
const defaultRequireMethod = (path) => import(path).catch(importError => {
|
|
159
|
+
var _a;
|
|
160
|
+
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'));
|
|
161
|
+
try {
|
|
162
|
+
return cwdRequire(path);
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
throw importError;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
156
168
|
const requireMethod = execOptions.requireMethod || defaultRequireMethod;
|
|
157
169
|
return Promise.all(relevantPaths
|
|
158
170
|
.filter(path => checkExtension(path, options) && !(isIndex(path, execOptions.extensions) && options.ignoreIndex))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/load-files",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.3",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"./*": {
|
|
33
33
|
"require": "./*.js",
|
|
34
34
|
"import": "./*.mjs"
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"./package.json": "./package.json"
|
|
36
37
|
}
|
|
37
38
|
}
|