@graphql-inspector/config
Advanced tools
Comparing version 0.0.0-canary.3c127cf to 0.0.0-canary.485af9a
@@ -32,52 +32,49 @@ 'use strict'; | ||
const availableCommands = [ | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
]; | ||
const availableLoaders = [ | ||
'code', | ||
'git', | ||
'github', | ||
'graphql', | ||
'json', | ||
'url', | ||
'code', | ||
'git', | ||
'github', | ||
'graphql', | ||
'json', | ||
'url', | ||
]; | ||
function useConfig() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
loaders: ensureList(discoverLoaders(availableLoaders), 'loaders'), | ||
commands: ensureList(discoverCommands(availableCommands), 'commands'), | ||
}; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
loaders: ensureList(discoverLoaders(availableLoaders), 'loaders'), | ||
commands: ensureList(discoverCommands(availableCommands), 'commands'), | ||
}; | ||
}); | ||
} | ||
function moduleExists(name) { | ||
try { | ||
require.resolve(name); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
try { | ||
require.resolve(name); | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
} | ||
function discoverLoaders(loaders) { | ||
return loaders.filter((name) => | ||
moduleExists(`@graphql-inspector/${name}-loader`), | ||
); | ||
return loaders.filter((name) => moduleExists(`@graphql-inspector/${name}-loader`)); | ||
} | ||
function discoverCommands(commands) { | ||
return commands.filter((name) => | ||
moduleExists(`@graphql-inspector/${name}-command`), | ||
); | ||
return commands.filter((name) => moduleExists(`@graphql-inspector/${name}-command`)); | ||
} | ||
function ensureList(list, path) { | ||
if (!list) { | ||
return []; | ||
} | ||
if (Array.isArray(list)) { | ||
return list; | ||
} | ||
throw new Error(`Value of ${path} expected to be a list`); | ||
if (!list) { | ||
return []; | ||
} | ||
if (Array.isArray(list)) { | ||
return list; | ||
} | ||
throw new Error(`Value of ${path} expected to be a list`); | ||
} | ||
@@ -84,0 +81,0 @@ |
export interface InspectorConfig { | ||
loaders: string[]; | ||
commands: string[]; | ||
loaders: string[]; | ||
commands: string[]; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const availableCommands: string[]; |
@@ -28,52 +28,49 @@ /*! ***************************************************************************** | ||
const availableCommands = [ | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
'coverage', | ||
'diff', | ||
'docs', | ||
'introspect', | ||
'serve', | ||
'similar', | ||
'validate', | ||
]; | ||
const availableLoaders = [ | ||
'code', | ||
'git', | ||
'github', | ||
'graphql', | ||
'json', | ||
'url', | ||
'code', | ||
'git', | ||
'github', | ||
'graphql', | ||
'json', | ||
'url', | ||
]; | ||
function useConfig() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
loaders: ensureList(discoverLoaders(availableLoaders), 'loaders'), | ||
commands: ensureList(discoverCommands(availableCommands), 'commands'), | ||
}; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
loaders: ensureList(discoverLoaders(availableLoaders), 'loaders'), | ||
commands: ensureList(discoverCommands(availableCommands), 'commands'), | ||
}; | ||
}); | ||
} | ||
function moduleExists(name) { | ||
try { | ||
require.resolve(name); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
try { | ||
require.resolve(name); | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
} | ||
function discoverLoaders(loaders) { | ||
return loaders.filter((name) => | ||
moduleExists(`@graphql-inspector/${name}-loader`), | ||
); | ||
return loaders.filter((name) => moduleExists(`@graphql-inspector/${name}-loader`)); | ||
} | ||
function discoverCommands(commands) { | ||
return commands.filter((name) => | ||
moduleExists(`@graphql-inspector/${name}-command`), | ||
); | ||
return commands.filter((name) => moduleExists(`@graphql-inspector/${name}-command`)); | ||
} | ||
function ensureList(list, path) { | ||
if (!list) { | ||
return []; | ||
} | ||
if (Array.isArray(list)) { | ||
return list; | ||
} | ||
throw new Error(`Value of ${path} expected to be a list`); | ||
if (!list) { | ||
return []; | ||
} | ||
if (Array.isArray(list)) { | ||
return list; | ||
} | ||
throw new Error(`Value of ${path} expected to be a list`); | ||
} | ||
@@ -80,0 +77,0 @@ |
{ | ||
"name": "@graphql-inspector/config", | ||
"version": "0.0.0-canary.3c127cf", | ||
"version": "0.0.0-canary.485af9a", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37712
157