Skip to content

Commit

Permalink
style: format with prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Aug 16, 2023
1 parent bee69fd commit bb92395
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pnpm-lock.yaml
.yarn
.pnp.loader.mjs
10 changes: 5 additions & 5 deletions src/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { detectPackageManager } from "./package-manager";
export async function findup<T>(
cwd: string,
match: (path: string) => T | Promise<T>,
options: Pick<DetectPackageManagerOptions, "includeParentDirs"> = {},
options: Pick<DetectPackageManagerOptions, "includeParentDirs"> = {}
): Promise<T | undefined> {
const segments = normalize(cwd).split("/");

Expand All @@ -27,7 +27,7 @@ export async function findup<T>(
export async function executeCommand(
command: string,
args: string[],
options: Pick<OperationOptions, "cwd" | "silent"> = {},
options: Pick<OperationOptions, "cwd" | "silent"> = {}
): Promise<void> {
const { execa } = await import("execa");
const { resolve } = await import("pathe");
Expand All @@ -49,7 +49,7 @@ export const NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG =
"No package manager auto-detected.";

export async function resolveOperationOptions(
options: OperationOptions = {},
options: OperationOptions = {}
): Promise<
NonPartial<
Pick<OperationOptions, "cwd" | "silent" | "packageManager" | "dev">
Expand All @@ -76,7 +76,7 @@ export async function resolveOperationOptions(
}

export function getWorkspaceArgs(
options: Awaited<ReturnType<typeof resolveOperationOptions>>,
options: Awaited<ReturnType<typeof resolveOperationOptions>>
): string[] {
if (!options.workspace) {
if (options.packageManager.name === "pnpm") {
Expand Down Expand Up @@ -113,7 +113,7 @@ export function doesDependencyExist(
options: Pick<
Awaited<ReturnType<typeof resolveOperationOptions>>,
"cwd" | "workspace"
>,
>
) {
const require = createRequire(withTrailingSlash(options.cwd));

Expand Down
10 changes: 5 additions & 5 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { OperationOptions } from "./types";
* @param options.packageManager - The package manager info to use (auto-detected).
*/
export async function installDependencies(
options: Pick<OperationOptions, "cwd" | "silent" | "packageManager"> = {},
options: Pick<OperationOptions, "cwd" | "silent" | "packageManager"> = {}
) {
const resolvedOptions = await resolveOperationOptions(options);

Expand All @@ -38,7 +38,7 @@ export async function installDependencies(
*/
export async function addDependency(
name: string,
options: OperationOptions = {},
options: OperationOptions = {}
) {
const resolvedOptions = await resolveOperationOptions(options);

Expand Down Expand Up @@ -77,7 +77,7 @@ export async function addDependency(
*/
export async function addDevDependency(
name: string,
options: Omit<OperationOptions, "dev"> = {},
options: Omit<OperationOptions, "dev"> = {}
) {
await addDependency(name, { ...options, dev: true });
}
Expand All @@ -95,7 +95,7 @@ export async function addDevDependency(
*/
export async function removeDependency(
name: string,
options: OperationOptions = {},
options: OperationOptions = {}
) {
const resolvedOptions = await resolveOperationOptions(options);

Expand Down Expand Up @@ -134,7 +134,7 @@ export async function removeDependency(
*/
export async function ensureDependencyInstalled(
name: string,
options: Pick<OperationOptions, "cwd" | "dev" | "workspace"> = {},
options: Pick<OperationOptions, "cwd" | "dev" | "workspace"> = {}
) {
const resolvedOptions = await resolveOperationOptions(options);

Expand Down
8 changes: 4 additions & 4 deletions src/package-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const _packageManagers: PackageManager[] = [

export async function detectPackageManager(
cwd: string,
options: DetectPackageManagerOptions = {},
options: DetectPackageManagerOptions = {}
): Promise<PackageManager | undefined> {
const detected = await findup(
cwd,
Expand All @@ -62,15 +62,15 @@ export async function detectPackageManager(
const packageJSONPath = join(path, "package.json");
if (existsSync(packageJSONPath)) {
const packageJSON = JSON.parse(
await readFile(packageJSONPath, "utf8"),
await readFile(packageJSONPath, "utf8")
);
if (packageJSON?.packageManager) {
const [name, version = "0.0.0"] =
packageJSON.packageManager.split("@");
const majorVersion = version.split(".")[0];
const packageManager =
_packageManagers.find(
(pm) => pm.name === name && pm.majorVersion === majorVersion,
(pm) => pm.name === name && pm.majorVersion === majorVersion
) || _packageManagers.find((pm) => pm.name === name);
return {
...packageManager,
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function detectPackageManager(
},
{
includeParentDirs: options.includeParentDirs,
},
}
);

return detected;
Expand Down
12 changes: 6 additions & 6 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeInstallDependenciesSpy(),
async () => await executeInstallDependenciesSpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeInstallDependenciesSpy();
Expand All @@ -157,7 +157,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeAddDependencySpy(),
async () => await executeAddDependencySpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeAddDependencySpy();
Expand All @@ -176,7 +176,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeEnsureDependencyInstalledSpy(),
async () => await executeEnsureDependencyInstalledSpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeEnsureDependencyInstalledSpy();
Expand All @@ -196,7 +196,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeRemoveDependencySpy(),
async () => await executeRemoveDependencySpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeRemoveDependencySpy();
Expand All @@ -217,7 +217,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeAddDependencySpy(),
async () => await executeAddDependencySpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeAddDependencySpy();
Expand All @@ -238,7 +238,7 @@ describe("api", () => {

if (fixture.name === "empty") {
expect(
async () => await executeRemoveDependencySpy(),
async () => await executeRemoveDependencySpy()
).rejects.toThrowError(NO_PACKAGE_MANAGER_DETECTED_ERROR_MSG);
} else {
await executeRemoveDependencySpy();
Expand Down

0 comments on commit bb92395

Please sign in to comment.