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

Upgraded typescript #3505

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"sinon": "^17.0.1",
"tmp": "^0.2.3",
"ts-loader": "^9.5.1",
"typescript": "^4.6.3",
"typescript": "^5.5.4",
"util": "^0.12.4",
"vsce": "^2.15.0",
"vscode-nls-dev": "^4.0.4",
Expand Down
48 changes: 23 additions & 25 deletions src/ModuleResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -136,10 +136,8 @@ 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 @@ -155,15 +153,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 @@ -188,7 +186,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 @@ -211,7 +209,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 @@ -246,7 +244,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 @@ -268,7 +266,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 @@ -284,7 +282,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 @@ -314,7 +312,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 @@ -331,7 +329,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 @@ -350,12 +348,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 @@ -366,14 +364,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 @@ -395,15 +393,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 @@ -418,7 +416,7 @@ export class ModuleResolver implements ModuleResolverInterface {
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 @@ -428,7 +426,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 @@ -437,7 +435,7 @@ export class ModuleResolver implements ModuleResolverInterface {
prettierInstance,
uri,
fileName,
vscodeConfig,
vscodeConfig
);

return resolvedConfig;
Expand Down Expand Up @@ -500,7 +498,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 @@ -520,7 +518,7 @@ export class ModuleResolver implements ModuleResolverInterface {
return findUp.stop;
}
},
{ cwd: finalPath, type: "directory" },
{ cwd: finalPath, type: "directory" }
);

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

if (nodeModulesResDir) {
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4010,11 +4010,16 @@ typed-rest-client@^1.8.4:
tunnel "0.0.6"
underscore "^1.12.1"

typescript@^4.5.4, typescript@^4.6.3:
typescript@^4.5.4:
version "4.7.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235"
integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ==

typescript@^5.5.4:
version "5.5.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.5.4.tgz#d9852d6c82bad2d2eda4fd74a5762a8f5909e9ba"
integrity sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==

uc.micro@^1.0.1, uc.micro@^1.0.5:
version "1.0.6"
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-1.0.6.tgz#9c411a802a409a91fc6cf74081baba34b24499ac"
Expand Down
Loading