@graphql-mesh/include 0.0.1-alpha-20240731134627-3296805fb396a7068c95cc1b16e82c4577219970 → 1.0.0-alpha-20240731125001-cbfa3d2b9c73d559c5290247c504e217b058639f
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/cjs/index.js +22 -13
- package/esm/index.js +22 -13
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.include = include;
|
|
4
4
|
exports.registerTsconfigPaths = registerTsconfigPaths;
|
|
5
5
|
const tslib_1 = require("tslib");
|
|
6
|
-
// eslint-disable-next-line import/no-nodejs-modules
|
|
7
6
|
const node_module_1 = tslib_1.__importDefault(require("node:module"));
|
|
8
7
|
const get_tsconfig_1 = require("get-tsconfig");
|
|
9
8
|
const jiti_1 = tslib_1.__importDefault(require("jiti"));
|
|
@@ -23,17 +22,30 @@ const jiti = (0, jiti_1.default)(
|
|
|
23
22
|
* If the module at {@link path} is not found, `null` will be returned.
|
|
24
23
|
*/
|
|
25
24
|
async function include(path) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
try {
|
|
26
|
+
const module = await jiti.import(path, {});
|
|
27
|
+
if (!module) {
|
|
28
|
+
throw new Error('Included module is empty');
|
|
29
|
+
}
|
|
30
|
+
if (typeof module !== 'object') {
|
|
31
|
+
throw new Error(`Included module is not an object, is instead "${typeof module}"`);
|
|
32
|
+
}
|
|
33
|
+
if ('default' in module) {
|
|
34
|
+
return module.default;
|
|
35
|
+
}
|
|
36
|
+
return module;
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
catch (err) {
|
|
39
|
+
// NOTE: we dont use the err.code because maybe the included module is importing another module that does not exist.
|
|
40
|
+
// if we were to use the MODULE_NOT_FOUND code, then those includes will fail with an unclear error
|
|
41
|
+
if (String(err).includes(`Cannot find module '${path}'`)) {
|
|
42
|
+
//
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
|
-
return
|
|
48
|
+
return null;
|
|
37
49
|
}
|
|
38
50
|
/**
|
|
39
51
|
* Parses the closest `(t|j)sconfig.json` paths and augments Node's module
|
|
@@ -44,10 +56,8 @@ async function include(path) {
|
|
|
44
56
|
function registerTsconfigPaths({ searchPath = process.cwd(), configName = process.env.MESH_INCLUDE_TSCONFIG_NAME || 'tsconfig.json', } = {}) {
|
|
45
57
|
const tsconfig = (0, get_tsconfig_1.getTsconfig)(searchPath, configName);
|
|
46
58
|
const pathsMatcher = (0, get_tsconfig_1.createPathsMatcher)(tsconfig);
|
|
47
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
48
59
|
// @ts-expect-error
|
|
49
60
|
const originalResolveFilename = node_module_1.default._resolveFilename;
|
|
50
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
51
61
|
// @ts-expect-error
|
|
52
62
|
node_module_1.default._resolveFilename = (...args) => {
|
|
53
63
|
const [path, ...rest] = args;
|
|
@@ -73,7 +83,6 @@ function registerTsconfigPaths({ searchPath = process.cwd(), configName = proces
|
|
|
73
83
|
}
|
|
74
84
|
};
|
|
75
85
|
return function unregisterTsconfigPaths() {
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
77
86
|
// @ts-expect-error
|
|
78
87
|
node_module_1.default._resolveFilename = originalResolveFilename;
|
|
79
88
|
};
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-nodejs-modules
|
|
2
1
|
import Module from 'node:module';
|
|
3
2
|
import { createPathsMatcher, getTsconfig } from 'get-tsconfig';
|
|
4
3
|
import createJITI from 'jiti';
|
|
@@ -18,17 +17,30 @@ const jiti = createJITI(
|
|
|
18
17
|
* If the module at {@link path} is not found, `null` will be returned.
|
|
19
18
|
*/
|
|
20
19
|
export async function include(path) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
try {
|
|
21
|
+
const module = await jiti.import(path, {});
|
|
22
|
+
if (!module) {
|
|
23
|
+
throw new Error('Included module is empty');
|
|
24
|
+
}
|
|
25
|
+
if (typeof module !== 'object') {
|
|
26
|
+
throw new Error(`Included module is not an object, is instead "${typeof module}"`);
|
|
27
|
+
}
|
|
28
|
+
if ('default' in module) {
|
|
29
|
+
return module.default;
|
|
30
|
+
}
|
|
31
|
+
return module;
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
|
|
33
|
+
catch (err) {
|
|
34
|
+
// NOTE: we dont use the err.code because maybe the included module is importing another module that does not exist.
|
|
35
|
+
// if we were to use the MODULE_NOT_FOUND code, then those includes will fail with an unclear error
|
|
36
|
+
if (String(err).includes(`Cannot find module '${path}'`)) {
|
|
37
|
+
//
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
30
42
|
}
|
|
31
|
-
return
|
|
43
|
+
return null;
|
|
32
44
|
}
|
|
33
45
|
/**
|
|
34
46
|
* Parses the closest `(t|j)sconfig.json` paths and augments Node's module
|
|
@@ -39,10 +51,8 @@ export async function include(path) {
|
|
|
39
51
|
export function registerTsconfigPaths({ searchPath = process.cwd(), configName = process.env.MESH_INCLUDE_TSCONFIG_NAME || 'tsconfig.json', } = {}) {
|
|
40
52
|
const tsconfig = getTsconfig(searchPath, configName);
|
|
41
53
|
const pathsMatcher = createPathsMatcher(tsconfig);
|
|
42
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
43
54
|
// @ts-expect-error
|
|
44
55
|
const originalResolveFilename = Module._resolveFilename;
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
46
56
|
// @ts-expect-error
|
|
47
57
|
Module._resolveFilename = (...args) => {
|
|
48
58
|
const [path, ...rest] = args;
|
|
@@ -68,7 +78,6 @@ export function registerTsconfigPaths({ searchPath = process.cwd(), configName =
|
|
|
68
78
|
}
|
|
69
79
|
};
|
|
70
80
|
return function unregisterTsconfigPaths() {
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
81
|
// @ts-expect-error
|
|
73
82
|
Module._resolveFilename = originalResolveFilename;
|
|
74
83
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/include",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0-alpha-20240731125001-cbfa3d2b9c73d559c5290247c504e217b058639f",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"dotenv": "^16.3.1",
|