@graphql-inspector/config
Advanced tools
Comparing version 0.0.0-canary.da4bdcc to 0.0.0-canary.f71f99b
@@ -32,49 +32,52 @@ '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`); | ||
} | ||
@@ -81,0 +84,0 @@ |
export interface InspectorConfig { | ||
loaders: string[]; | ||
commands: string[]; | ||
loaders: string[]; | ||
commands: string[]; | ||
} | ||
@@ -5,0 +5,0 @@ export declare const availableCommands: string[]; |
@@ -28,49 +28,52 @@ /*! ***************************************************************************** | ||
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`); | ||
} | ||
@@ -77,0 +80,0 @@ |
{ | ||
"name": "@graphql-inspector/config", | ||
"version": "0.0.0-canary.da4bdcc", | ||
"version": "0.0.0-canary.f71f99b", | ||
"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
163
36548