@graphql-inspector/commands
Advanced tools
Comparing version 0.0.0-canary.57e2caa to 0.0.0-canary.9cf9b2c
116
index.cjs.js
@@ -10,117 +10,4 @@ 'use strict'; | ||
const yargs = _interopDefault(require('yargs')); | ||
const fs = require('fs'); | ||
const yamljs = require('yamljs'); | ||
const searchPlaces = [ | ||
`graphql.config.js`, | ||
'graphql.config.json', | ||
'graphql.config.yaml', | ||
'graphql.config.yml', | ||
'.graphqlrc', | ||
'.graphqlrc.js', | ||
'.graphqlrc.json', | ||
'.graphqlrc.yml', | ||
'.graphqlrc.yaml', | ||
]; | ||
const legacySearchPlaces = [ | ||
'.graphqlconfig', | ||
'.graphqlconfig.json', | ||
'.graphqlconfig.yaml', | ||
'.graphqlconfig.yml', | ||
]; | ||
const pickPointers = (args, required) => tslib.__awaiter(void 0, void 0, void 0, function* () { | ||
let schema; | ||
let documents; | ||
if (args.config) { | ||
const config = yield useGraphQLConfig(); | ||
schema = config.schema; | ||
documents = config.documents; | ||
} | ||
else { | ||
schema = args.schema; | ||
documents = args.documents; | ||
} | ||
if (required.documents || required.schema) { | ||
const errors = []; | ||
if (required.schema && !schema) { | ||
errors.push(`Schema pointer is missing`); | ||
} | ||
if (required.documents && !documents) { | ||
errors.push(`Documents pointer is missing`); | ||
} | ||
if (errors.length) { | ||
throw new Error(errors.join('\n')); | ||
} | ||
} | ||
return { | ||
schema, | ||
documents, | ||
}; | ||
}); | ||
function useGraphQLConfig() { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const found = yield firstExisting(searchPlaces); | ||
if (found) { | ||
return parse(found); | ||
} | ||
const foundLegacy = yield firstExisting(legacySearchPlaces); | ||
if (foundLegacy) { | ||
return parse(foundLegacy); | ||
} | ||
throw new Error(`Couldn't find a GraphQL Config`); | ||
}); | ||
} | ||
function firstExisting(places) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const statuses = yield Promise.all(places.map((place) => path.resolve(process.cwd(), place)).map(exists)); | ||
return places.find((_, i) => statuses[i] === true); | ||
}); | ||
} | ||
function parse(path$1) { | ||
return tslib.__awaiter(this, void 0, void 0, function* () { | ||
const normalizedPath = path.resolve(process.cwd(), path$1.toLowerCase()); | ||
if (normalizedPath.endsWith('.js')) { | ||
const mod = require(normalizedPath); | ||
return mod.default || mod; | ||
} | ||
const content = yield read(path$1); | ||
if (normalizedPath.endsWith('.yml') || normalizedPath.endsWith('.yaml')) { | ||
return yamljs.parse(content); | ||
} | ||
if (normalizedPath.endsWith('.json')) { | ||
return JSON.parse(content); | ||
} | ||
try { | ||
return yamljs.parse(content); | ||
} | ||
catch (error) { } | ||
try { | ||
return JSON.parse(content); | ||
} | ||
catch (error) { } | ||
throw new Error(`Failed to parse: ${path$1}`); | ||
}); | ||
} | ||
function read(path) { | ||
return new Promise((resolve, reject) => { | ||
fs.readFile(path, 'utf-8', (error, data) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
} | ||
function exists(path) { | ||
return new Promise((resolve) => { | ||
fs.stat(path, (error) => { | ||
resolve(error ? false : true); | ||
}); | ||
}); | ||
} | ||
function useCommands(input) { | ||
const api = Object.assign(Object.assign({}, input), { pickPointers }); | ||
function useCommands(api) { | ||
return api.config.commands.map((name) => loadCommand(name)(api)); | ||
@@ -170,4 +57,3 @@ } | ||
exports.parseGlobalArgs = parseGlobalArgs; | ||
exports.pickPointers = pickPointers; | ||
exports.useCommands = useCommands; | ||
//# sourceMappingURL=index.cjs.js.map |
import { InspectorConfig } from '@graphql-inspector/config'; | ||
import { Loaders } from '@graphql-inspector/loaders'; | ||
import { CommandModule } from 'yargs'; | ||
import { pickPointers, PickPointers } from './graphql-config'; | ||
export { CommandModule as Command, PickPointers, pickPointers }; | ||
export { CommandModule as Command }; | ||
export interface UseCommandsAPI { | ||
config: InspectorConfig; | ||
loaders: Loaders; | ||
pickPointers: PickPointers; | ||
} | ||
export declare type CommandFactory<T = {}, U = {}> = (api: UseCommandsAPI) => CommandModule<T, U>; | ||
export declare function useCommands(input: Omit<UseCommandsAPI, 'pickPointers'>): CommandModule[]; | ||
export declare function useCommands(api: UseCommandsAPI): CommandModule[]; | ||
export declare function createCommand<T = {}, U = {}>(factory: CommandFactory<T, U>): CommandFactory<T, U>; | ||
@@ -14,0 +12,0 @@ export declare function ensureAbsolute(filepath: string, basepath?: string): string; |
119
index.esm.js
import { __awaiter } from 'tslib'; | ||
import { resolve, isAbsolute } from 'path'; | ||
import { isAbsolute, resolve } from 'path'; | ||
import yargs from 'yargs'; | ||
import { readFile, stat } from 'fs'; | ||
import { parse as parse$1 } from 'yamljs'; | ||
const searchPlaces = [ | ||
`graphql.config.js`, | ||
'graphql.config.json', | ||
'graphql.config.yaml', | ||
'graphql.config.yml', | ||
'.graphqlrc', | ||
'.graphqlrc.js', | ||
'.graphqlrc.json', | ||
'.graphqlrc.yml', | ||
'.graphqlrc.yaml', | ||
]; | ||
const legacySearchPlaces = [ | ||
'.graphqlconfig', | ||
'.graphqlconfig.json', | ||
'.graphqlconfig.yaml', | ||
'.graphqlconfig.yml', | ||
]; | ||
const pickPointers = (args, required) => __awaiter(void 0, void 0, void 0, function* () { | ||
let schema; | ||
let documents; | ||
if (args.config) { | ||
const config = yield useGraphQLConfig(); | ||
schema = config.schema; | ||
documents = config.documents; | ||
} | ||
else { | ||
schema = args.schema; | ||
documents = args.documents; | ||
} | ||
if (required.documents || required.schema) { | ||
const errors = []; | ||
if (required.schema && !schema) { | ||
errors.push(`Schema pointer is missing`); | ||
} | ||
if (required.documents && !documents) { | ||
errors.push(`Documents pointer is missing`); | ||
} | ||
if (errors.length) { | ||
throw new Error(errors.join('\n')); | ||
} | ||
} | ||
return { | ||
schema, | ||
documents, | ||
}; | ||
}); | ||
function useGraphQLConfig() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const found = yield firstExisting(searchPlaces); | ||
if (found) { | ||
return parse(found); | ||
} | ||
const foundLegacy = yield firstExisting(legacySearchPlaces); | ||
if (foundLegacy) { | ||
return parse(foundLegacy); | ||
} | ||
throw new Error(`Couldn't find a GraphQL Config`); | ||
}); | ||
} | ||
function firstExisting(places) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const statuses = yield Promise.all(places.map((place) => resolve(process.cwd(), place)).map(exists)); | ||
return places.find((_, i) => statuses[i] === true); | ||
}); | ||
} | ||
function parse(path) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const normalizedPath = resolve(process.cwd(), path.toLowerCase()); | ||
if (normalizedPath.endsWith('.js')) { | ||
const mod = require(normalizedPath); | ||
return mod.default || mod; | ||
} | ||
const content = yield read(path); | ||
if (normalizedPath.endsWith('.yml') || normalizedPath.endsWith('.yaml')) { | ||
return parse$1(content); | ||
} | ||
if (normalizedPath.endsWith('.json')) { | ||
return JSON.parse(content); | ||
} | ||
try { | ||
return parse$1(content); | ||
} | ||
catch (error) { } | ||
try { | ||
return JSON.parse(content); | ||
} | ||
catch (error) { } | ||
throw new Error(`Failed to parse: ${path}`); | ||
}); | ||
} | ||
function read(path) { | ||
return new Promise((resolve, reject) => { | ||
readFile(path, 'utf-8', (error, data) => { | ||
if (error) { | ||
reject(error); | ||
} | ||
else { | ||
resolve(data); | ||
} | ||
}); | ||
}); | ||
} | ||
function exists(path) { | ||
return new Promise((resolve) => { | ||
stat(path, (error) => { | ||
resolve(error ? false : true); | ||
}); | ||
}); | ||
} | ||
function useCommands(input) { | ||
const api = Object.assign(Object.assign({}, input), { pickPointers }); | ||
function useCommands(api) { | ||
return api.config.commands.map((name) => loadCommand(name)(api)); | ||
@@ -159,3 +46,3 @@ } | ||
export { createCommand, ensureAbsolute, mockCommand, parseGlobalArgs, pickPointers, useCommands }; | ||
export { createCommand, ensureAbsolute, mockCommand, parseGlobalArgs, useCommands }; | ||
//# sourceMappingURL=index.esm.js.map |
{ | ||
"name": "@graphql-inspector/commands", | ||
"version": "0.0.0-canary.57e2caa", | ||
"version": "0.0.0-canary.9cf9b2c", | ||
"description": "Plugin system for commands in GraphQL Inspector", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"@graphql-inspector/config": "0.0.0-canary.57e2caa", | ||
"@graphql-inspector/loaders": "0.0.0-canary.57e2caa", | ||
"@graphql-inspector/config": "0.0.0-canary.9cf9b2c", | ||
"@graphql-inspector/loaders": "0.0.0-canary.9cf9b2c", | ||
"graphql": "^0.13.0 || ^14.0.0 || ^15.0.0", | ||
@@ -12,4 +13,3 @@ "yargs": "15.3.1" | ||
"dependencies": { | ||
"tslib": "^1.11.1", | ||
"yamljs": "0.3.0" | ||
"tslib": "^2.0.0" | ||
}, | ||
@@ -16,0 +16,0 @@ "repository": { |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
5
4
11696
131
1
+ Added@ardatan/aggregate-error@0.0.6(transitive)
+ Added@graphql-inspector/config@0.0.0-canary.9cf9b2c(transitive)
+ Added@graphql-inspector/loaders@0.0.0-canary.9cf9b2c(transitive)
+ Added@graphql-tools/load@6.2.8(transitive)
+ Added@graphql-tools/merge@6.2.178.3.1(transitive)
+ Added@graphql-tools/schema@8.5.1(transitive)
+ Added@graphql-tools/utils@6.2.47.10.08.0.28.9.0(transitive)
+ Addedcamel-case@4.1.2(transitive)
+ Addedglobby@11.0.3(transitive)
+ Addedp-limit@3.1.0(transitive)
+ Addedtslib@2.0.32.2.02.3.1(transitive)
+ Addedvalue-or-promise@1.0.11(transitive)
+ Addedyocto-queue@0.1.0(transitive)
- Removedyamljs@0.3.0
- Removed@babel/runtime@7.25.6(transitive)
- Removed@graphql-inspector/config@0.0.0-canary.57e2caa(transitive)
- Removed@graphql-inspector/loaders@0.0.0-canary.57e2caa(transitive)
- Removed@graphql-toolkit/common@0.10.7(transitive)
- Removed@graphql-toolkit/core@0.10.7(transitive)
- Removed@graphql-toolkit/schema-merging@0.10.7(transitive)
- Removed@wry/equality@0.1.11(transitive)
- Removedaggregate-error@3.0.1(transitive)
- Removedapollo-link@1.2.14(transitive)
- Removedapollo-link-http-common@0.2.16(transitive)
- Removedapollo-upload-client@13.0.0(transitive)
- Removedapollo-utilities@1.3.4(transitive)
- Removedargparse@1.0.10(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedbalanced-match@1.0.2(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedclean-stack@2.2.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removeddeepmerge@4.2.2(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removeddeprecated-decorator@0.1.6(transitive)
- Removedextract-files@8.1.0(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedform-data@3.0.1(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@7.2.3(transitive)
- Removedglobby@11.0.0(transitive)
- Removedgraphql-tools@5.0.0(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedinflight@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removediterall@1.3.0(transitive)
- Removedlodash@4.17.15(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedminimatch@3.1.2(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removedonce@1.4.0(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
- Removedregenerator-runtime@0.14.1(transitive)
- Removedsprintf-js@1.0.3(transitive)
- Removedtr46@0.0.3(transitive)
- Removedts-invariant@0.4.4(transitive)
- Removedtslib@1.11.2(transitive)
- Removeduuid@7.0.3(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedwrappy@1.0.2(transitive)
- Removedyamljs@0.3.0(transitive)
- Removedzen-observable@0.8.15(transitive)
- Removedzen-observable-ts@0.8.21(transitive)
Updatedtslib@^2.0.0