Skip to content
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

use writeFile from fs/promises instead promisify(writeFile) #3082

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/codemirror-graphql/src/__tests__/lint-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ describe('graphql-lint', () => {
expect(editor.getHelpers(editor.getCursor(), 'lint')).not.toHaveLength(0);
});

const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});
const kitchenSink = readFileSync(
join(__dirname, '/kitchen-sink.graphql'),
'utf8',
);

it('returns no syntactic/validation errors after parsing kitchen-sink query', async () => {
const errors = await printLintErrors(kitchenSink);
Expand Down
9 changes: 5 additions & 4 deletions packages/codemirror-graphql/src/__tests__/mode-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ describe('graphql-mode', () => {
});

it('parses kitchen-sink query without invalidchar', () => {
const kitchenSink = readFileSync(join(__dirname, '/kitchen-sink.graphql'), {
encoding: 'utf8',
});
const kitchenSink = readFileSync(
join(__dirname, '/kitchen-sink.graphql'),
'utf8',
);

CodeMirror.runMode(kitchenSink, 'graphql', (_token, style) => {
expect(style).not.toBe('invalidchar');
Expand All @@ -81,7 +82,7 @@ describe('graphql-mode', () => {
it('parses schema-kitchen-sink query without invalidchar', () => {
const schemaKitchenSink = readFileSync(
join(__dirname, '/schema-kitchen-sink.graphql'),
{ encoding: 'utf8' },
'utf8',
);

CodeMirror.runMode(schemaKitchenSink, 'graphql', (_token, style) => {
Expand Down
14 changes: 4 additions & 10 deletions packages/graphql-language-service-server/src/MessageProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/

import mkdirp from 'mkdirp';
import { readFileSync, existsSync, writeFileSync, writeFile } from 'node:fs';
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import glob from 'fast-glob';
import { URI } from 'vscode-uri';
Expand Down Expand Up @@ -71,9 +72,6 @@ import {
ProjectNotFoundError,
} from 'graphql-config';
import type { LoadConfigOptions } from './types';
import { promisify } from 'node:util';

const writeFileAsync = promisify(writeFile);

const configDocLink =
'https://www.npmjs.com/package/graphql-language-service-server#user-content-graphql-configuration-file';
Expand Down Expand Up @@ -1064,16 +1062,12 @@ export class MessageProcessor {
const cachedSchemaDoc = this._getCachedDocument(uri);

if (!cachedSchemaDoc) {
await writeFileAsync(fsPath, schemaText, {
encoding: 'utf-8',
});
await writeFile(fsPath, schemaText, 'utf8');
await this._cacheSchemaText(uri, schemaText, 1);
}
// do we have a change in the getSchema result? if so, update schema cache
if (cachedSchemaDoc) {
writeFileSync(fsPath, schemaText, {
encoding: 'utf-8',
});
writeFileSync(fsPath, schemaText, 'utf8');
await this._cacheSchemaText(
uri,
schemaText,
Expand Down
8 changes: 2 additions & 6 deletions packages/graphql-language-service/benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,11 @@ const runGraphqlParserTest = (name: string, schema: string) => {

const kitchenSchema = fs.readFileSync(
path.resolve(__dirname, './fixtures/kitchen-sink.graphql'),
{
encoding: 'utf8',
},
'utf8',
);
const githubSchema = fs.readFileSync(
path.resolve(__dirname, './fixtures/github.graphql'),
{
encoding: 'utf8',
},
'utf8',
);

runWholeTest('kitchen-sink:whole', kitchenSchema);
Expand Down