@graphql-tools/json-file-loader 7.3.16 → 7.4.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.
@@ -1,17 +1,14 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
-
7
- const utils = require('@graphql-tools/utils');
8
- const path = require('path');
9
- const fs = require('fs');
10
- const process = require('process');
11
- const globby = _interopDefault(require('globby'));
12
- const unixify = _interopDefault(require('unixify'));
13
-
14
- const { readFile, access } = fs.promises;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JsonFileLoader = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const utils_1 = require("@graphql-tools/utils");
6
+ const path_1 = require("path");
7
+ const fs_1 = require("fs");
8
+ const process_1 = require("process");
9
+ const globby_1 = tslib_1.__importDefault(require("globby"));
10
+ const unixify_1 = tslib_1.__importDefault(require("unixify"));
11
+ const { readFile, access } = fs_1.promises;
15
12
  const FILE_EXTENSIONS = ['.json'];
16
13
  function createGlobbyOptions(options) {
17
14
  return { absolute: true, ...options, ignore: [] };
@@ -42,9 +39,9 @@ const buildIgnoreGlob = (path) => `!${path}`;
42
39
  */
43
40
  class JsonFileLoader {
44
41
  async canLoad(pointer, options) {
45
- if (utils.isValidPath(pointer)) {
42
+ if ((0, utils_1.isValidPath)(pointer)) {
46
43
  if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
47
- const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
44
+ const normalizedFilePath = (0, path_1.isAbsolute)(pointer) ? pointer : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), pointer);
48
45
  try {
49
46
  await access(normalizedFilePath);
50
47
  return true;
@@ -57,42 +54,42 @@ class JsonFileLoader {
57
54
  return false;
58
55
  }
59
56
  canLoadSync(pointer, options) {
60
- if (utils.isValidPath(pointer)) {
57
+ if ((0, utils_1.isValidPath)(pointer)) {
61
58
  if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
62
- const normalizedFilePath = path.isAbsolute(pointer) ? pointer : path.resolve(options.cwd || process.cwd(), pointer);
63
- return fs.existsSync(normalizedFilePath);
59
+ const normalizedFilePath = (0, path_1.isAbsolute)(pointer) ? pointer : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), pointer);
60
+ return (0, fs_1.existsSync)(normalizedFilePath);
64
61
  }
65
62
  }
66
63
  return false;
67
64
  }
68
65
  _buildGlobs(glob, options) {
69
- const ignores = utils.asArray(options.ignore || []);
70
- const globs = [unixify(glob), ...ignores.map(v => buildIgnoreGlob(unixify(v)))];
66
+ const ignores = (0, utils_1.asArray)(options.ignore || []);
67
+ const globs = [(0, unixify_1.default)(glob), ...ignores.map(v => buildIgnoreGlob((0, unixify_1.default)(v)))];
71
68
  return globs;
72
69
  }
73
70
  async resolveGlobs(glob, options) {
74
71
  const globs = this._buildGlobs(glob, options);
75
- const result = await globby(globs, createGlobbyOptions(options));
72
+ const result = await (0, globby_1.default)(globs, createGlobbyOptions(options));
76
73
  return result;
77
74
  }
78
75
  resolveGlobsSync(glob, options) {
79
76
  const globs = this._buildGlobs(glob, options);
80
- const result = globby.sync(globs, createGlobbyOptions(options));
77
+ const result = globby_1.default.sync(globs, createGlobbyOptions(options));
81
78
  return result;
82
79
  }
83
80
  async load(pointer, options) {
84
81
  const resolvedPaths = await this.resolveGlobs(pointer, options);
85
82
  const finalResult = [];
86
83
  const errors = [];
87
- await Promise.all(resolvedPaths.map(async (path$1) => {
88
- if (await this.canLoad(path$1, options)) {
84
+ await Promise.all(resolvedPaths.map(async (path) => {
85
+ if (await this.canLoad(path, options)) {
89
86
  try {
90
- const normalizedFilePath = path.isAbsolute(path$1) ? path$1 : path.resolve(options.cwd || process.cwd(), path$1);
87
+ const normalizedFilePath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), path);
91
88
  const rawSDL = await readFile(normalizedFilePath, { encoding: 'utf8' });
92
89
  finalResult.push(this.handleFileContent(normalizedFilePath, rawSDL, options));
93
90
  }
94
91
  catch (e) {
95
- if (process.env['DEBUG']) {
92
+ if (process_1.env['DEBUG']) {
96
93
  console.error(e);
97
94
  }
98
95
  errors.push(e);
@@ -103,7 +100,7 @@ class JsonFileLoader {
103
100
  if (errors.length === 1) {
104
101
  throw errors[0];
105
102
  }
106
- throw new utils.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
103
+ throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
107
104
  }
108
105
  return finalResult;
109
106
  }
@@ -111,15 +108,15 @@ class JsonFileLoader {
111
108
  const resolvedPaths = this.resolveGlobsSync(pointer, options);
112
109
  const finalResult = [];
113
110
  const errors = [];
114
- for (const path$1 of resolvedPaths) {
115
- if (this.canLoadSync(path$1, options)) {
111
+ for (const path of resolvedPaths) {
112
+ if (this.canLoadSync(path, options)) {
116
113
  try {
117
- const normalizedFilePath = path.isAbsolute(path$1) ? path$1 : path.resolve(options.cwd || process.cwd(), path$1);
118
- const rawSDL = fs.readFileSync(normalizedFilePath, { encoding: 'utf8' });
114
+ const normalizedFilePath = (0, path_1.isAbsolute)(path) ? path : (0, path_1.resolve)(options.cwd || (0, process_1.cwd)(), path);
115
+ const rawSDL = (0, fs_1.readFileSync)(normalizedFilePath, { encoding: 'utf8' });
119
116
  finalResult.push(this.handleFileContent(normalizedFilePath, rawSDL, options));
120
117
  }
121
118
  catch (e) {
122
- if (process.env['DEBUG']) {
119
+ if (process_1.env['DEBUG']) {
123
120
  console.error(e);
124
121
  }
125
122
  errors.push(e);
@@ -130,18 +127,17 @@ class JsonFileLoader {
130
127
  if (errors.length === 1) {
131
128
  throw errors[0];
132
129
  }
133
- throw new utils.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
130
+ throw new utils_1.AggregateError(errors, `Reading from ${pointer} failed ; \n ` + errors.map((e) => e.message).join('\n'));
134
131
  }
135
132
  return finalResult;
136
133
  }
137
134
  handleFileContent(normalizedFilePath, rawSDL, options) {
138
135
  try {
139
- return utils.parseGraphQLJSON(normalizedFilePath, rawSDL, options);
136
+ return (0, utils_1.parseGraphQLJSON)(normalizedFilePath, rawSDL, options);
140
137
  }
141
138
  catch (e) {
142
139
  throw new Error(`Unable to read JSON file: ${normalizedFilePath}: ${e.message || /* istanbul ignore next */ e}`);
143
140
  }
144
141
  }
145
142
  }
146
-
147
143
  exports.JsonFileLoader = JsonFileLoader;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,11 +1,10 @@
1
- import { isValidPath, asArray, AggregateError, parseGraphQLJSON } from '@graphql-tools/utils';
1
+ import { isValidPath, asArray, parseGraphQLJSON, AggregateError, } from '@graphql-tools/utils';
2
2
  import { isAbsolute, resolve } from 'path';
3
- import { existsSync, readFileSync, promises } from 'fs';
4
- import { cwd, env } from 'process';
3
+ import { readFileSync, promises as fsPromises, existsSync } from 'fs';
4
+ import { cwd as processCwd, env } from 'process';
5
5
  import globby from 'globby';
6
6
  import unixify from 'unixify';
7
-
8
- const { readFile, access } = promises;
7
+ const { readFile, access } = fsPromises;
9
8
  const FILE_EXTENSIONS = ['.json'];
10
9
  function createGlobbyOptions(options) {
11
10
  return { absolute: true, ...options, ignore: [] };
@@ -34,11 +33,11 @@ const buildIgnoreGlob = (path) => `!${path}`;
34
33
  * });
35
34
  * ```
36
35
  */
37
- class JsonFileLoader {
36
+ export class JsonFileLoader {
38
37
  async canLoad(pointer, options) {
39
38
  if (isValidPath(pointer)) {
40
39
  if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
41
- const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
40
+ const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || processCwd(), pointer);
42
41
  try {
43
42
  await access(normalizedFilePath);
44
43
  return true;
@@ -53,7 +52,7 @@ class JsonFileLoader {
53
52
  canLoadSync(pointer, options) {
54
53
  if (isValidPath(pointer)) {
55
54
  if (FILE_EXTENSIONS.find(extension => pointer.endsWith(extension))) {
56
- const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || cwd(), pointer);
55
+ const normalizedFilePath = isAbsolute(pointer) ? pointer : resolve(options.cwd || processCwd(), pointer);
57
56
  return existsSync(normalizedFilePath);
58
57
  }
59
58
  }
@@ -81,7 +80,7 @@ class JsonFileLoader {
81
80
  await Promise.all(resolvedPaths.map(async (path) => {
82
81
  if (await this.canLoad(path, options)) {
83
82
  try {
84
- const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || cwd(), path);
83
+ const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || processCwd(), path);
85
84
  const rawSDL = await readFile(normalizedFilePath, { encoding: 'utf8' });
86
85
  finalResult.push(this.handleFileContent(normalizedFilePath, rawSDL, options));
87
86
  }
@@ -108,7 +107,7 @@ class JsonFileLoader {
108
107
  for (const path of resolvedPaths) {
109
108
  if (this.canLoadSync(path, options)) {
110
109
  try {
111
- const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || cwd(), path);
110
+ const normalizedFilePath = isAbsolute(path) ? path : resolve(options.cwd || processCwd(), path);
112
111
  const rawSDL = readFileSync(normalizedFilePath, { encoding: 'utf8' });
113
112
  finalResult.push(this.handleFileContent(normalizedFilePath, rawSDL, options));
114
113
  }
@@ -137,5 +136,3 @@ class JsonFileLoader {
137
136
  }
138
137
  }
139
138
  }
140
-
141
- export { JsonFileLoader };
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@graphql-tools/json-file-loader",
3
- "version": "7.3.16",
3
+ "version": "7.4.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
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
8
8
  },
9
9
  "dependencies": {
10
- "@graphql-tools/utils": "8.7.0",
10
+ "@graphql-tools/utils": "8.8.0-alpha-b76ec274.0",
11
11
  "globby": "^11.0.3",
12
- "tslib": "^2.4.0",
13
- "unixify": "^1.0.0"
12
+ "unixify": "^1.0.0",
13
+ "tslib": "^2.4.0"
14
14
  },
15
15
  "repository": {
16
16
  "type": "git",
@@ -19,21 +19,42 @@
19
19
  },
20
20
  "author": "Dotan Simha <dotansimha@gmail.com>",
21
21
  "license": "MIT",
22
- "main": "index.js",
23
- "module": "index.mjs",
24
- "typings": "index.d.ts",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "typings": "typings/index.d.ts",
25
25
  "typescript": {
26
- "definition": "index.d.ts"
26
+ "definition": "typings/index.d.ts"
27
27
  },
28
+ "type": "module",
28
29
  "exports": {
29
30
  ".": {
30
- "require": "./index.js",
31
- "import": "./index.mjs"
31
+ "require": {
32
+ "types": "./typings/index.d.ts",
33
+ "default": "./cjs/index.js"
34
+ },
35
+ "import": {
36
+ "types": "./typings/index.d.ts",
37
+ "default": "./esm/index.js"
38
+ },
39
+ "default": {
40
+ "types": "./typings/index.d.ts",
41
+ "default": "./esm/index.js"
42
+ }
32
43
  },
33
44
  "./*": {
34
- "require": "./*.js",
35
- "import": "./*.mjs"
45
+ "require": {
46
+ "types": "./typings/*.d.ts",
47
+ "default": "./cjs/*.js"
48
+ },
49
+ "import": {
50
+ "types": "./typings/*.d.ts",
51
+ "default": "./esm/*.js"
52
+ },
53
+ "default": {
54
+ "types": "./typings/*.d.ts",
55
+ "default": "./esm/*.js"
56
+ }
36
57
  },
37
58
  "./package.json": "./package.json"
38
59
  }
39
- }
60
+ }
File without changes