@graphql-inspector/config
Advanced tools
Comparing version 1.30.3 to 1.30.4
@@ -5,26 +5,41 @@ 'use strict'; | ||
const tslib = require('tslib'); | ||
const cosmiconfig = require('cosmiconfig'); | ||
const path = require('path'); | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
function useConfig(options) { | ||
var _a, _b, _c, _d; | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const cosmi = cosmiconfig.cosmiconfig('inspector', { | ||
cache: true, | ||
}); | ||
const config = yield ((options === null || options === void 0 ? void 0 : options.config) ? cosmi.load(path.isAbsolute(options.config) | ||
? options.config | ||
: path.resolve(process.cwd(), options.config)) | ||
: cosmi.search()); | ||
if (!config) { | ||
throw new Error('Config not found'); | ||
} | ||
if (config.isEmpty) { | ||
throw new Error('Config is empty'); | ||
} | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function useConfig() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
use: { | ||
loaders: ensureList((_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.use) === null || _b === void 0 ? void 0 : _b.loaders, 'loaders'), | ||
commands: ensureList((_d = (_c = config.config) === null || _c === void 0 ? void 0 : _c.use) === null || _d === void 0 ? void 0 : _d.commands, 'commands'), | ||
loaders: ensureList(discoverLoaders(['code', 'git', 'github', 'graphql', 'json', 'url']), 'loaders'), | ||
commands: ensureList(discoverCommands([ | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
]), 'commands'), | ||
}, | ||
@@ -34,2 +49,21 @@ }; | ||
} | ||
function moduleExists(name) { | ||
var _a; | ||
try { | ||
require(name); | ||
return true; | ||
} | ||
catch (error) { | ||
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(`Cannot find module '${name}'`)) { | ||
return false; | ||
} | ||
throw error; | ||
} | ||
} | ||
function discoverLoaders(loaders) { | ||
return loaders.filter((name) => moduleExists(`@graphql-inspector/${name}-loader`)); | ||
} | ||
function discoverCommands(commands) { | ||
return commands.filter((name) => moduleExists(`@graphql-inspector/${name}-command`)); | ||
} | ||
function ensureList(list, path) { | ||
@@ -36,0 +70,0 @@ if (!list) { |
@@ -7,6 +7,2 @@ export interface InspectorConfig { | ||
} | ||
interface UseConfigOptions { | ||
config?: string; | ||
} | ||
export declare function useConfig(options?: UseConfigOptions): Promise<InspectorConfig | never>; | ||
export {}; | ||
export declare function useConfig(): Promise<InspectorConfig | never>; |
@@ -1,25 +0,40 @@ | ||
import { __awaiter } from 'tslib'; | ||
import { cosmiconfig } from 'cosmiconfig'; | ||
import { isAbsolute, resolve } from 'path'; | ||
/*! ***************************************************************************** | ||
Copyright (c) Microsoft Corporation. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); you may not use | ||
this file except in compliance with the License. You may obtain a copy of the | ||
License at http://www.apache.org/licenses/LICENSE-2.0 | ||
function useConfig(options) { | ||
var _a, _b, _c, _d; | ||
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED | ||
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, | ||
MERCHANTABLITY OR NON-INFRINGEMENT. | ||
See the Apache Version 2.0 License for specific language governing permissions | ||
and limitations under the License. | ||
***************************************************************************** */ | ||
function __awaiter(thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
} | ||
function useConfig() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const cosmi = cosmiconfig('inspector', { | ||
cache: true, | ||
}); | ||
const config = yield ((options === null || options === void 0 ? void 0 : options.config) ? cosmi.load(isAbsolute(options.config) | ||
? options.config | ||
: resolve(process.cwd(), options.config)) | ||
: cosmi.search()); | ||
if (!config) { | ||
throw new Error('Config not found'); | ||
} | ||
if (config.isEmpty) { | ||
throw new Error('Config is empty'); | ||
} | ||
return { | ||
use: { | ||
loaders: ensureList((_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.use) === null || _b === void 0 ? void 0 : _b.loaders, 'loaders'), | ||
commands: ensureList((_d = (_c = config.config) === null || _c === void 0 ? void 0 : _c.use) === null || _d === void 0 ? void 0 : _d.commands, 'commands'), | ||
loaders: ensureList(discoverLoaders(['code', 'git', 'github', 'graphql', 'json', 'url']), 'loaders'), | ||
commands: ensureList(discoverCommands([ | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
]), 'commands'), | ||
}, | ||
@@ -29,2 +44,21 @@ }; | ||
} | ||
function moduleExists(name) { | ||
var _a; | ||
try { | ||
require(name); | ||
return true; | ||
} | ||
catch (error) { | ||
if ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes(`Cannot find module '${name}'`)) { | ||
return false; | ||
} | ||
throw error; | ||
} | ||
} | ||
function discoverLoaders(loaders) { | ||
return loaders.filter((name) => moduleExists(`@graphql-inspector/${name}-loader`)); | ||
} | ||
function discoverCommands(commands) { | ||
return commands.filter((name) => moduleExists(`@graphql-inspector/${name}-command`)); | ||
} | ||
function ensureList(list, path) { | ||
@@ -31,0 +65,0 @@ if (!list) { |
{ | ||
"name": "@graphql-inspector/config", | ||
"version": "1.30.3", | ||
"version": "1.30.4", | ||
"peerDependencies": { | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0", | ||
"yargs": "15.3.1" | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0" | ||
}, | ||
"dependencies": { | ||
"cosmiconfig": "6.0.0", | ||
"tslib": "^1.11.1" | ||
}, | ||
"repository": { | ||
@@ -13,0 +8,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
36526
1
147
2
- Removedcosmiconfig@6.0.0
- Removedtslib@^1.11.1
- Removed@babel/code-frame@7.24.7(transitive)
- Removed@babel/helper-validator-identifier@7.24.7(transitive)
- Removed@babel/highlight@7.24.7(transitive)
- Removed@types/parse-json@4.0.2(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@3.2.14.3.0(transitive)
- Removedcallsites@3.1.0(transitive)
- Removedcamelcase@5.3.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcliui@6.0.0(transitive)
- Removedcolor-convert@1.9.32.0.1(transitive)
- Removedcolor-name@1.1.31.1.4(transitive)
- Removedcosmiconfig@6.0.0(transitive)
- Removeddecamelize@1.2.0(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removederror-ex@1.3.2(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedfind-up@4.1.0(transitive)
- Removedget-caller-file@2.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removedimport-fresh@3.3.0(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedjson-parse-even-better-errors@2.3.1(transitive)
- Removedlines-and-columns@1.2.4(transitive)
- Removedlocate-path@5.0.0(transitive)
- Removedp-limit@2.3.0(transitive)
- Removedp-locate@4.1.0(transitive)
- Removedp-try@2.2.0(transitive)
- Removedparent-module@1.0.1(transitive)
- Removedparse-json@5.2.0(transitive)
- Removedpath-exists@4.0.0(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicocolors@1.0.1(transitive)
- Removedrequire-directory@2.1.1(transitive)
- Removedrequire-main-filename@2.0.0(transitive)
- Removedresolve-from@4.0.0(transitive)
- Removedset-blocking@2.0.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@5.5.0(transitive)
- Removedtslib@1.14.1(transitive)
- Removedwhich-module@2.0.1(transitive)
- Removedwrap-ansi@6.2.0(transitive)
- Removedy18n@4.0.3(transitive)
- Removedyaml@1.10.2(transitive)
- Removedyargs@15.3.1(transitive)
- Removedyargs-parser@18.1.3(transitive)