Use Buffer.toString in node-only context (#175592)

This commit is contained in:
Joyce Er 2023-02-27 14:31:16 -08:00 committed by GitHub
parent 477b8a2af6
commit 5148e0bde9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,6 @@ import * as MarkdownItType from 'markdown-it';
import { languages, workspace, Disposable, TextDocument, Uri, Diagnostic, Range, DiagnosticSeverity, Position, env, l10n } from 'vscode';
import { INormalizedVersion, normalizeVersion, parseVersion } from './extensionEngineValidation';
import { TextDecoder } from 'util';
const product = JSON.parse(fs.readFileSync(path.join(env.appRoot, 'product.json'), { encoding: 'utf-8' }));
const allowedBadgeProviders: string[] = (product.extensionAllowedBadgeProviders || []).map((s: string) => s.toLowerCase());
@ -70,7 +69,6 @@ export class ExtensionLinter {
private timer: NodeJS.Timer | undefined;
private markdownIt: MarkdownItType.MarkdownIt | undefined;
private parse5: typeof import('parse5') | undefined;
private textDecoder = new TextDecoder();
constructor() {
this.disposables.push(
@ -349,7 +347,7 @@ export class ExtensionLinter {
const file = folder.with({ path: path.posix.join(folder.path, 'package.json') });
try {
const fileContents = await workspace.fs.readFile(file); // #174888
return parseTree(this.textDecoder.decode(fileContents));
return parseTree(Buffer.from(fileContents).toString('utf-8'));
} catch (err) {
return undefined;
}