-
-
Notifications
You must be signed in to change notification settings - Fork 832
Dependency cleanup #6896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dependency cleanup #6896
Changes from 15 commits
f86e8c1
75b3325
9eb6cb2
d2bb322
681479b
073c46c
fc0984d
0100558
a36360d
7f71230
e050278
594b79c
9b8ac2a
e43b159
8d12e42
ab92147
d7c2fed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| '@graphql-tools/graphql-file-loader': patch | ||
| '@graphql-tools/code-file-loader': patch | ||
| '@graphql-tools/json-file-loader': patch | ||
| '@graphql-tools/load-files': patch | ||
| '@graphql-tools/documents': patch | ||
| '@graphql-tools/load': patch | ||
| --- | ||
|
|
||
| Replace globby with tinyglobby and remove lodash.sortby dependency |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ import { | |
| type SelectionNode, | ||
| type VariableDefinitionNode, | ||
| } from 'graphql'; | ||
| import sortBy from 'lodash.sortby'; | ||
| import { normalizeWhiteSpace } from './normalize-whitespace.js'; | ||
|
|
||
| // Cache the sorted nodes to avoid sorting the same nodes multiple times | ||
|
|
@@ -44,39 +43,54 @@ export function sortExecutableNodes( | |
| } | ||
|
|
||
| if (isOfKindList<DirectiveNode>(nodes, Kind.DIRECTIVE)) { | ||
| return cacheResult(sortBy(nodes as any, 'name.value')); | ||
| return cacheResult(nodes.sort((a, b) => a.name.value.localeCompare(b.name.value))); | ||
| } | ||
|
|
||
| if (isOfKindList<VariableDefinitionNode>(nodes, Kind.VARIABLE_DEFINITION)) { | ||
| return cacheResult(sortBy(nodes as any, 'variable.name.value')); | ||
| return cacheResult( | ||
| nodes.sort((a, b) => a.variable.name.value.localeCompare(b.variable.name.value)), | ||
| ); | ||
| } | ||
|
|
||
| if (isOfKindList<ArgumentNode>(nodes, Kind.ARGUMENT)) { | ||
| return cacheResult(sortBy(nodes as any, 'name.value')); | ||
| return cacheResult(nodes.sort((a, b) => a.name.value.localeCompare(b.name.value))); | ||
| } | ||
|
|
||
| if ( | ||
| isOfKindList<SelectionNode>(nodes, [Kind.FIELD, Kind.FRAGMENT_SPREAD, Kind.INLINE_FRAGMENT]) | ||
| ) { | ||
| return cacheResult( | ||
| sortBy(nodes as any, node => { | ||
| if (node.kind === Kind.FIELD) { | ||
| return sortPrefixField + node.name.value; | ||
| } else if (node.kind === Kind.FRAGMENT_SPREAD) { | ||
| return sortPrefixFragmentSpread + node.name.value; | ||
| } else { | ||
| const typeCondition = node.typeCondition?.name.value ?? ''; | ||
| // if you have a better idea, send a PR :) | ||
| const sortedNodes = buildInlineFragmentSelectionSetKey( | ||
| cacheResult(sortExecutableNodes(node.selectionSet.selections)), | ||
| ); | ||
| return sortPrefixInlineFragmentNode + typeCondition + sortedNodes; | ||
| } | ||
| nodes.sort((a, b) => { | ||
| const getSortKey = (node: SelectionNode) => { | ||
| if (node.kind === Kind.FIELD) { | ||
| return sortPrefixField + node.name.value; | ||
| } else if (node.kind === Kind.FRAGMENT_SPREAD) { | ||
| return sortPrefixFragmentSpread + node.name.value; | ||
| } else { | ||
| const typeCondition = node.typeCondition?.name.value ?? ''; | ||
| const sortedSelections = buildInlineFragmentSelectionSetKey( | ||
| cacheResult(sortExecutableNodes(node.selectionSet.selections)), | ||
| ); | ||
| return sortPrefixInlineFragmentNode + typeCondition + sortedSelections; | ||
| } | ||
| }; | ||
|
|
||
| return getSortKey(a).localeCompare(getSortKey(b)); | ||
| }), | ||
| ); | ||
| } | ||
| const _nodes = nodes as ASTNode[]; | ||
| return cacheResult( | ||
| _nodes.sort((nodeA, nodeB) => { | ||
| const kindComparison = nodeA.kind.localeCompare(nodeB.kind); | ||
| if (kindComparison !== 0) return kindComparison; | ||
|
|
||
| const nameA = (nodeA as any).name?.value ?? ''; | ||
| const nameB = (nodeB as any).name?.value ?? ''; | ||
|
|
||
| return cacheResult(sortBy(nodes as any, 'kind', 'name.value')); | ||
| return nameA.localeCompare(nameB); | ||
| }), | ||
| ); | ||
| } | ||
|
Comment on lines
+82
to
94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do I need to add comments here or it's fine as it is? |
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,8 @@ import { existsSync, promises as fsPromises, readFileSync } from 'fs'; | |
| import { createRequire } from 'module'; | ||
| import { isAbsolute, resolve } from 'path'; | ||
| import { cwd, env } from 'process'; | ||
| import type { GlobbyOptions } from 'globby'; | ||
| import globby from 'globby'; | ||
| import { DocumentNode, GraphQLSchema, isSchema, parse } from 'graphql'; | ||
| import unixify from 'unixify'; | ||
| import { glob, globSync, type GlobOptions } from 'tinyglobby'; | ||
| import { | ||
| gqlPluckFromCodeString, | ||
| gqlPluckFromCodeStringSync, | ||
|
|
@@ -19,6 +17,7 @@ import { | |
| Loader, | ||
| parseGraphQLSDL, | ||
| Source, | ||
| unixifyWithDriveLetter, | ||
| } from '@graphql-tools/utils'; | ||
| import { tryToLoadFromExport, tryToLoadFromExportSync } from './load-from-module.js'; | ||
|
|
||
|
|
@@ -59,7 +58,7 @@ const FILE_EXTENSIONS = [ | |
| '.gjs', | ||
| ]; | ||
|
|
||
| function createGlobbyOptions(options: CodeFileLoaderOptions): GlobbyOptions { | ||
| function createGlobbyOptions(options: CodeFileLoaderOptions): GlobOptions { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure the options are the same? Otherwise it is a breaking change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think some options are different, so I think I better rename it to TinyGlobbyOptions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the options used here are |
||
| return { absolute: true, ...options, ignore: [] }; | ||
| } | ||
|
|
||
|
|
@@ -131,20 +130,23 @@ export class CodeFileLoader implements Loader<CodeFileLoaderOptions> { | |
|
|
||
| private _buildGlobs(glob: string, options: CodeFileLoaderOptions) { | ||
| const ignores = asArray(options.ignore || []); | ||
| const globs = [unixify(glob), ...ignores.map(v => buildIgnoreGlob(unixify(v)))]; | ||
| const globs = [ | ||
| unixifyWithDriveLetter(glob), | ||
| ...ignores.map(v => buildIgnoreGlob(unixifyWithDriveLetter(v))), | ||
| ]; | ||
| return globs; | ||
| } | ||
|
|
||
| async resolveGlobs(glob: string, options: CodeFileLoaderOptions) { | ||
| async resolveGlobs(path: string, options: CodeFileLoaderOptions) { | ||
| options = this.getMergedOptions(options); | ||
| const globs = this._buildGlobs(glob, options); | ||
| return globby(globs, createGlobbyOptions(options)); | ||
| const globs = this._buildGlobs(path, options); | ||
| return glob(globs, createGlobbyOptions(options)); | ||
| } | ||
|
|
||
| resolveGlobsSync(glob: string, options: CodeFileLoaderOptions) { | ||
| options = this.getMergedOptions(options); | ||
| const globs = this._buildGlobs(glob, options); | ||
| return globby.sync(globs, createGlobbyOptions(options)); | ||
| return globSync(globs, createGlobbyOptions(options)); | ||
| } | ||
|
|
||
| async load(pointer: string, options: CodeFileLoaderOptions): Promise<Source[]> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.