@graphql-mesh/include 1.0.0-alpha-20240731125001-cbfa3d2b9c73d559c5290247c504e217b058639f → 1.0.0-alpha-20240731131055-cc75982d4fd0ac4620db99f91aad65613007fedf

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.
Files changed (3) hide show
  1. package/cjs/index.js +13 -22
  2. package/esm/index.js +13 -22
  3. package/package.json +1 -1
package/cjs/index.js CHANGED
@@ -3,6 +3,7 @@ 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
6
7
  const node_module_1 = tslib_1.__importDefault(require("node:module"));
7
8
  const get_tsconfig_1 = require("get-tsconfig");
8
9
  const jiti_1 = tslib_1.__importDefault(require("jiti"));
@@ -22,30 +23,17 @@ const jiti = (0, jiti_1.default)(
22
23
  * If the module at {@link path} is not found, `null` will be returned.
23
24
  */
24
25
  async function include(path) {
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;
26
+ const module = await jiti.import(path, {});
27
+ if (!module) {
28
+ throw new Error('Included module is empty');
37
29
  }
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
- }
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;
47
35
  }
48
- return null;
36
+ return module;
49
37
  }
50
38
  /**
51
39
  * Parses the closest `(t|j)sconfig.json` paths and augments Node's module
@@ -56,8 +44,10 @@ async function include(path) {
56
44
  function registerTsconfigPaths({ searchPath = process.cwd(), configName = process.env.MESH_INCLUDE_TSCONFIG_NAME || 'tsconfig.json', } = {}) {
57
45
  const tsconfig = (0, get_tsconfig_1.getTsconfig)(searchPath, configName);
58
46
  const pathsMatcher = (0, get_tsconfig_1.createPathsMatcher)(tsconfig);
47
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
59
48
  // @ts-expect-error
60
49
  const originalResolveFilename = node_module_1.default._resolveFilename;
50
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
61
51
  // @ts-expect-error
62
52
  node_module_1.default._resolveFilename = (...args) => {
63
53
  const [path, ...rest] = args;
@@ -83,6 +73,7 @@ function registerTsconfigPaths({ searchPath = process.cwd(), configName = proces
83
73
  }
84
74
  };
85
75
  return function unregisterTsconfigPaths() {
76
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
86
77
  // @ts-expect-error
87
78
  node_module_1.default._resolveFilename = originalResolveFilename;
88
79
  };
package/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ // eslint-disable-next-line import/no-nodejs-modules
1
2
  import Module from 'node:module';
2
3
  import { createPathsMatcher, getTsconfig } from 'get-tsconfig';
3
4
  import createJITI from 'jiti';
@@ -17,30 +18,17 @@ const jiti = createJITI(
17
18
  * If the module at {@link path} is not found, `null` will be returned.
18
19
  */
19
20
  export async function include(path) {
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;
21
+ const module = await jiti.import(path, {});
22
+ if (!module) {
23
+ throw new Error('Included module is empty');
32
24
  }
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
- }
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;
42
30
  }
43
- return null;
31
+ return module;
44
32
  }
45
33
  /**
46
34
  * Parses the closest `(t|j)sconfig.json` paths and augments Node's module
@@ -51,8 +39,10 @@ export async function include(path) {
51
39
  export function registerTsconfigPaths({ searchPath = process.cwd(), configName = process.env.MESH_INCLUDE_TSCONFIG_NAME || 'tsconfig.json', } = {}) {
52
40
  const tsconfig = getTsconfig(searchPath, configName);
53
41
  const pathsMatcher = createPathsMatcher(tsconfig);
42
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
54
43
  // @ts-expect-error
55
44
  const originalResolveFilename = Module._resolveFilename;
45
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
56
46
  // @ts-expect-error
57
47
  Module._resolveFilename = (...args) => {
58
48
  const [path, ...rest] = args;
@@ -78,6 +68,7 @@ export function registerTsconfigPaths({ searchPath = process.cwd(), configName =
78
68
  }
79
69
  };
80
70
  return function unregisterTsconfigPaths() {
71
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
81
72
  // @ts-expect-error
82
73
  Module._resolveFilename = originalResolveFilename;
83
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/include",
3
- "version": "1.0.0-alpha-20240731125001-cbfa3d2b9c73d559c5290247c504e217b058639f",
3
+ "version": "1.0.0-alpha-20240731131055-cc75982d4fd0ac4620db99f91aad65613007fedf",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
6
  "dotenv": "^16.3.1",