Skip to content

Commit

Permalink
Revert "updated dependancies (#3349)" (#3500)
Browse files Browse the repository at this point in the history
This reverts commit f595440.
  • Loading branch information
ntotten authored Aug 14, 2024
1 parent ba90037 commit 20686e0
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 275 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@
"@types/sinon": "^17.0.3",
"@types/tmp": "^0.2.6",
"@types/vscode": "^1.60.0",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"@vscode/test-electron": "^2.3.9",
"@vscode/test-web": "^0.0.52",
"copy-webpack-plugin": "^12.0.2",
"eslint": "^8.57.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^9.1.0",
"fs-extra": "^11.2.0",
"glob": "^7.2.0",
Expand All @@ -116,8 +118,7 @@
"sinon": "^17.0.1",
"tmp": "^0.2.3",
"ts-loader": "^9.5.1",
"typescript": "^5.4.3",
"typescript-eslint": "^7.3.1",
"typescript": "^4.6.3",
"util": "^0.12.4",
"vsce": "^2.15.0",
"vscode-nls-dev": "^4.0.4",
Expand Down
65 changes: 31 additions & 34 deletions src/ModuleResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ import {
UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER,
USING_BUNDLED_PRETTIER,
} from "./message";
import { loadNodeModule, resolveConfigPlugins } from "./ModuleLoader";
import { PrettierInstance } from "./PrettierInstance";
import { PrettierMainThreadInstance } from "./PrettierMainThreadInstance";
import { PrettierWorkerInstance } from "./PrettierWorkerInstance";
import {
ModuleResolverInterface,
PackageManagers,
Expand All @@ -28,6 +24,10 @@ import {
PrettierVSCodeConfig,
} from "./types";
import { getConfig, getWorkspaceRelativePath, isAboveV3 } from "./util";
import { PrettierWorkerInstance } from "./PrettierWorkerInstance";
import { PrettierInstance } from "./PrettierInstance";
import { PrettierMainThreadInstance } from "./PrettierMainThreadInstance";
import { loadNodeModule, resolveConfigPlugins } from "./ModuleLoader";

const minPrettierVersion = "1.13.0";

Expand All @@ -36,7 +36,7 @@ export type PrettierNodeModule = typeof prettier;
const origFsStatSync = fs.statSync;
const fsStatSyncWorkaround = (
path: fs.PathLike,
options: fs.StatSyncOptions
options: fs.StatSyncOptions,
) => {
if (
options?.throwIfNoEntry === true ||
Expand All @@ -47,13 +47,8 @@ const fsStatSyncWorkaround = (
options.throwIfNoEntry = true;
try {
return origFsStatSync(path, options);
} catch (error) {
if (
error &&
typeof error === "object" &&
"code" in error &&
error.code === "ENOENT"
) {
} catch (error: any) {
if (error.code === "ENOENT") {
return undefined;
}
throw error;
Expand Down Expand Up @@ -141,8 +136,10 @@ export class ModuleResolver implements ModuleResolverInterface {
typeof prettierPkgJson === "object" &&
prettierPkgJson !== null &&
"version" in prettierPkgJson &&
// @ts-expect-error checked
typeof prettierPkgJson.version === "string"
) {
// @ts-expect-error checked
version = prettierPkgJson.version;
}

Expand All @@ -158,15 +155,15 @@ export class ModuleResolver implements ModuleResolverInterface {
* @param fileName The path of the file to use as the starting point. If none provided, the bundled prettier will be used.
*/
public async getPrettierInstance(
fileName: string
fileName: string,
): Promise<PrettierNodeModule | PrettierInstance | undefined> {
if (!workspace.isTrusted) {
this.loggingService.logDebug(UNTRUSTED_WORKSPACE_USING_BUNDLED_PRETTIER);
return prettier;
}

const { prettierPath, resolveGlobalModules } = getConfig(
Uri.file(fileName)
Uri.file(fileName),
);

// Look for local module
Expand All @@ -191,7 +188,7 @@ export class ModuleResolver implements ModuleResolverInterface {
this.loggingService.logInfo(
`Attempted to determine module path from ${
modulePath || moduleDirectory || "package.json"
}`
}`,
);
this.loggingService.logError(FAILED_TO_LOAD_MODULE_MESSAGE, error);

Expand All @@ -214,7 +211,7 @@ export class ModuleResolver implements ModuleResolverInterface {
if (resolvedGlobalPackageManagerPath) {
const globalModulePath = path.join(
resolvedGlobalPackageManagerPath,
"prettier"
"prettier",
);
if (fs.existsSync(globalModulePath)) {
modulePath = globalModulePath;
Expand Down Expand Up @@ -249,7 +246,7 @@ export class ModuleResolver implements ModuleResolverInterface {
this.loggingService.logInfo(
`Attempted to load Prettier module from ${
modulePath || "package.json"
}`
}`,
);
this.loggingService.logError(FAILED_TO_LOAD_MODULE_MESSAGE, error);

Expand All @@ -271,7 +268,7 @@ export class ModuleResolver implements ModuleResolverInterface {

if (!isValidVersion) {
this.loggingService.logInfo(
`Attempted to load Prettier module from ${modulePath}`
`Attempted to load Prettier module from ${modulePath}`,
);
this.loggingService.logError(OUTDATED_PRETTIER_VERSION_MESSAGE);
return undefined;
Expand All @@ -287,7 +284,7 @@ export class ModuleResolver implements ModuleResolverInterface {

public async getResolvedIgnorePath(
fileName: string,
ignorePath: string
ignorePath: string,
): Promise<string | undefined> {
const cacheKey = `${fileName}:${ignorePath}`;
// cache resolvedIgnorePath because resolving it checks the file system
Expand Down Expand Up @@ -317,7 +314,7 @@ export class ModuleResolver implements ModuleResolverInterface {
// https://stackoverflow.com/questions/17699599/node-js-check-if-file-exists#comment121041700_57708635
await fs.promises.stat(p).then(
() => true,
() => false
() => false,
)
) {
resolvedIgnorePath = p;
Expand All @@ -334,7 +331,7 @@ export class ModuleResolver implements ModuleResolverInterface {

private adjustFileNameForPrettierVersion3_1_1(
prettierInstance: { version: string | null },
fileName: string
fileName: string,
) {
if (!prettierInstance.version) {
return fileName;
Expand All @@ -353,12 +350,12 @@ export class ModuleResolver implements ModuleResolverInterface {
resolveConfigFile(filePath?: string): Promise<string | null>;
resolveConfig(
fileName: string,
options?: prettier.ResolveConfigOptions
options?: prettier.ResolveConfigOptions,
): Promise<PrettierOptions | null>;
},
uri: Uri,
fileName: string,
vscodeConfig: PrettierVSCodeConfig
vscodeConfig: PrettierVSCodeConfig,
): Promise<"error" | "disabled" | PrettierOptions | null> {
const isVirtual = uri.scheme !== "file" && uri.scheme !== "vscode-userdata";

Expand All @@ -369,14 +366,14 @@ export class ModuleResolver implements ModuleResolverInterface {
(await prettierInstance.resolveConfigFile(
this.adjustFileNameForPrettierVersion3_1_1(
prettierInstance,
fileName
)
fileName,
),
)) ?? undefined;
}
} catch (error) {
this.loggingService.logError(
`Error resolving prettier configuration for ${fileName}`,
error
error,
);
return "error";
}
Expand All @@ -398,15 +395,15 @@ export class ModuleResolver implements ModuleResolverInterface {
} catch (error) {
this.loggingService.logError(
"Invalid prettier configuration file detected.",
error
error,
);
this.loggingService.logError(INVALID_PRETTIER_CONFIG);

return "error";
}
if (resolveConfigOptions.config) {
this.loggingService.logInfo(
`Using config file at ${resolveConfigOptions.config}`
`Using config file at ${resolveConfigOptions.config}`,
);
}

Expand All @@ -416,7 +413,7 @@ export class ModuleResolver implements ModuleResolverInterface {

if (!isVirtual && !resolvedConfig && vscodeConfig.requireConfig) {
this.loggingService.logInfo(
"Require config set to true and no config present. Skipping file."
"Require config set to true and no config present. Skipping file.",
);
return "disabled";
}
Expand All @@ -426,7 +423,7 @@ export class ModuleResolver implements ModuleResolverInterface {

public async getResolvedConfig(
{ fileName, uri }: TextDocument,
vscodeConfig: PrettierVSCodeConfig
vscodeConfig: PrettierVSCodeConfig,
): Promise<"error" | "disabled" | PrettierOptions | null> {
const prettierInstance: typeof prettier | PrettierInstance =
(await this.getPrettierInstance(fileName)) || prettier;
Expand All @@ -435,7 +432,7 @@ export class ModuleResolver implements ModuleResolverInterface {
prettierInstance,
uri,
fileName,
vscodeConfig
vscodeConfig,
);

return resolvedConfig;
Expand Down Expand Up @@ -498,7 +495,7 @@ export class ModuleResolver implements ModuleResolverInterface {
let packageJson;
try {
packageJson = JSON.parse(
fs.readFileSync(path.join(dir, "package.json"), "utf8")
fs.readFileSync(path.join(dir, "package.json"), "utf8"),
);
} catch (e) {
// Swallow, if we can't read it we don't want to resolve based on it
Expand All @@ -518,7 +515,7 @@ export class ModuleResolver implements ModuleResolverInterface {
return findUp.stop;
}
},
{ cwd: finalPath, type: "directory" }
{ cwd: finalPath, type: "directory" },
);

if (packageJsonResDir) {
Expand All @@ -538,7 +535,7 @@ export class ModuleResolver implements ModuleResolverInterface {
return findUp.stop;
}
},
{ cwd: finalPath, type: "directory" }
{ cwd: finalPath, type: "directory" },
);

if (nodeModulesResDir) {
Expand Down
15 changes: 7 additions & 8 deletions src/PrettierWorkerInstance.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as path from "path";
import { Options, ResolveConfigOptions } from "prettier";
import * as url from "url";
import { Worker } from "worker_threads";
import {
PrettierInstance,
PrettierInstanceConstructor,
} from "./PrettierInstance";
import * as url from "url";
import * as path from "path";
import {
PrettierFileInfoOptions,
PrettierFileInfoResult,
PrettierOptions,
PrettierPlugin,
PrettierSupportLanguage,
} from "./types";
import {
PrettierInstance,
PrettierInstanceConstructor,
} from "./PrettierInstance";
import { ResolveConfigOptions, Options } from "prettier";

let currentCallId = 0;

Expand Down Expand Up @@ -119,7 +119,6 @@ export const PrettierWorkerInstance: PrettierInstanceConstructor = class Prettie
return result;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private callMethod(methodName: string, methodArgs: unknown[]): Promise<any> {
const callId = currentCallId++;
const promise = new Promise((resolve, reject) => {
Expand Down
Loading

0 comments on commit 20686e0

Please sign in to comment.