Skip to content

Commit

Permalink
chore: undo unwanted formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joemckenney committed Jan 10, 2024
1 parent cb18223 commit 1a01bcb
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 97 deletions.
82 changes: 41 additions & 41 deletions src/ModuleResolver.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { execSync } from "child_process"
import { TextDocument, Uri, window } from "coc.nvim"
import * as findUp from "find-up"
import * as fs from "fs"
import * as path from "path"
import * as prettier from "prettier"
import * as resolve from "resolve"
import * as semver from "semver"
import { resolveGlobalNodePath, resolveGlobalYarnPath } from "./Files"
import { LoggingService } from "./LoggingService"
import { execSync } from 'child_process'
import { TextDocument, Uri, window } from 'coc.nvim'
import * as findUp from 'find-up'
import * as fs from 'fs'
import * as path from 'path'
import * as prettier from 'prettier'
import * as resolve from 'resolve'
import * as semver from 'semver'
import { resolveGlobalNodePath, resolveGlobalYarnPath } from './Files'
import { LoggingService } from './LoggingService'
import {
FAILED_TO_LOAD_MODULE_MESSAGE,
INVALID_PRETTIER_CONFIG,
INVALID_PRETTIER_PATH_MESSAGE,
OUTDATED_PRETTIER_VERSION_MESSAGE,
USING_BUNDLED_PRETTIER
} from "./message"
} from './message'
import {
ModuleResolverInterface,
PackageManagers,
PrettierOptions,
PrettierResolveConfigOptions,
PrettierVSCodeConfig
} from "./types"
import { getConfig, getWorkspaceRelativePath } from "./util"
} from './types'
import { getConfig, getWorkspaceRelativePath } from './util'

const minPrettierVersion = "1.13.0"
const minPrettierVersion = '1.13.0'

export type PrettierNodeModule = typeof prettier

Expand All @@ -40,7 +40,7 @@ const globalPaths: {
pnpm: {
cache: undefined,
get(): string {
const pnpmPath = execSync("pnpm root -g").toString().trim()
const pnpmPath = execSync('pnpm root -g').toString().trim()
return pnpmPath
}
},
Expand Down Expand Up @@ -91,9 +91,9 @@ export class ModuleResolver implements ModuleResolverInterface {
try {
modulePath = prettierPath
? getWorkspaceRelativePath(fileName, prettierPath)
: this.findPkg(fileName, "prettier")
: this.findPkg(fileName, 'prettier')
} catch (error) {
let moduleDirectory = ""
let moduleDirectory = ''
if (!modulePath && error instanceof Error) {
// If findPkg threw an error from `resolve.sync`, attempt to parse the
// directory it failed on to provide a better error message
Expand All @@ -106,7 +106,7 @@ export class ModuleResolver implements ModuleResolverInterface {

this.loggingService.logInfo(
`Attempted to determine module path from ${
modulePath || moduleDirectory || "package.json"
modulePath || moduleDirectory || 'package.json'
}`
)
this.loggingService.logError(FAILED_TO_LOAD_MODULE_MESSAGE, error)
Expand All @@ -118,17 +118,17 @@ export class ModuleResolver implements ModuleResolverInterface {

// If global modules allowed, look for global module
if (resolveGlobalModules && !modulePath) {
let items: PackageManagers[] = ["npm", "pnpm", "yarn"]
let items: PackageManagers[] = ['npm', 'pnpm', 'yarn']
const idx = await window.showMenuPicker(items, {
title: "Choose package manager"
title: 'Choose package manager'
})
if (idx !== -1) {
const packageManager = items[idx]
const resolvedGlobalPackageManagerPath = globalPathGet(packageManager)
if (resolvedGlobalPackageManagerPath) {
const globalModulePath = path.join(
resolvedGlobalPackageManagerPath,
"prettier"
'prettier'
)
if (fs.existsSync(globalModulePath)) {
modulePath = globalModulePath
Expand All @@ -155,7 +155,7 @@ export class ModuleResolver implements ModuleResolverInterface {
} catch (error) {
this.loggingService.logInfo(
`Attempted to load Prettier module from ${
modulePath || "package.json"
modulePath || 'package.json'
}`
)
this.loggingService.logError(FAILED_TO_LOAD_MODULE_MESSAGE, error)
Expand Down Expand Up @@ -193,7 +193,7 @@ export class ModuleResolver implements ModuleResolverInterface {
} else {
if (onlyUseLocalVersion) {
this.loggingService.logInfo(
"Ignored bundled prettier by onlyUseLocalVersion configuration."
'Ignored bundled prettier by onlyUseLocalVersion configuration.'
)
return undefined
}
Expand All @@ -205,10 +205,10 @@ export class ModuleResolver implements ModuleResolverInterface {
public async getResolvedConfig(
textDocument: TextDocument,
vscodeConfig: PrettierVSCodeConfig
): Promise<"error" | "disabled" | PrettierOptions | null> {
): Promise<'error' | 'disabled' | PrettierOptions | null> {
const uri = Uri.parse(textDocument.uri)
const fileName = uri.fsPath
const isVirtual = uri.scheme !== "file"
const isVirtual = uri.scheme !== 'file'

let configPath: string | undefined
try {
Expand All @@ -221,7 +221,7 @@ export class ModuleResolver implements ModuleResolverInterface {
error
)

return "error"
return 'error'
}

const resolveConfigOptions: PrettierResolveConfigOptions = {
Expand All @@ -240,12 +240,12 @@ export class ModuleResolver implements ModuleResolverInterface {
: await prettier.resolveConfig(fileName, resolveConfigOptions)
} catch (error) {
this.loggingService.logError(
"Invalid prettier configuration file detected.",
'Invalid prettier configuration file detected.',
error
)
this.loggingService.logError(INVALID_PRETTIER_CONFIG)

return "error"
return 'error'
}
if (resolveConfigOptions.config) {
this.loggingService.logInfo(
Expand All @@ -255,9 +255,9 @@ 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"
return 'disabled'
}
return resolvedConfig
}
Expand All @@ -271,7 +271,7 @@ export class ModuleResolver implements ModuleResolverInterface {
try {
module.clearConfigCache()
} catch (error) {
this.loggingService.logError("Error clearing module cache.", error)
this.loggingService.logError('Error clearing module cache.', error)
}
})
this.path2Module.clear()
Expand All @@ -291,11 +291,11 @@ export class ModuleResolver implements ModuleResolverInterface {
}

private isInternalTestRoot(dir: string): boolean {
if (process.env.NODE_ENV !== "production") {
if (process.env.NODE_ENV !== 'production') {
// This is for testing purposes only. This code is removed in the
// shipped version of this extension so do not use this in your
// project. It won't work.
return fs.existsSync(path.join(dir, ".do-not-use-prettier-vscode-root"))
return fs.existsSync(path.join(dir, '.do-not-use-prettier-vscode-root'))
} else {
return false
}
Expand All @@ -316,22 +316,22 @@ export class ModuleResolver implements ModuleResolverInterface {
}

// Only look for a module definition outside of any `node_modules` directories
const splitPath = fsPath.split("/")
const splitPath = fsPath.split('/')
let finalPath = fsPath
const nodeModulesIndex = splitPath.indexOf("node_modules")
const nodeModulesIndex = splitPath.indexOf('node_modules')

if (nodeModulesIndex > 1) {
finalPath = splitPath.slice(0, nodeModulesIndex).join("/")
finalPath = splitPath.slice(0, nodeModulesIndex).join('/')
}

// First look for an explicit package.json dep
const packageJsonResDir = findUp.sync(
(dir) => {
if (fs.existsSync(path.join(dir, "package.json"))) {
if (fs.existsSync(path.join(dir, 'package.json'))) {
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 @@ -351,7 +351,7 @@ export class ModuleResolver implements ModuleResolverInterface {
return findUp.stop
}
},
{ cwd: finalPath, type: "directory" }
{ cwd: finalPath, type: 'directory' }
)

if (packageJsonResDir) {
Expand All @@ -363,15 +363,15 @@ export class ModuleResolver implements ModuleResolverInterface {
// If no explicit package.json dep found, instead look for implicit dep
const nodeModulesResDir = findUp.sync(
(dir) => {
if (fs.existsSync(path.join(dir, "node_modules", pkgName))) {
if (fs.existsSync(path.join(dir, 'node_modules', pkgName))) {
return dir
}

if (this.isInternalTestRoot(dir)) {
return findUp.stop
}
},
{ cwd: finalPath, type: "directory" }
{ cwd: finalPath, type: 'directory' }
)

if (nodeModulesResDir) {
Expand Down

0 comments on commit 1a01bcb

Please sign in to comment.