From b1f962051fb3c6f693e85357a80aab63b2e96992 Mon Sep 17 00:00:00 2001 From: Wil Wilsman Date: Tue, 2 Feb 2021 13:56:07 -0600 Subject: [PATCH] =?UTF-8?q?=E2=9E=96=20Remove=20path-type=20dependency=20(?= =?UTF-8?q?#162)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This dependency has many small helpers based on two single sync and async helpers. In both places we use this dependency, we only use it to check if a filepath is a directory synchronously. This is done by the depdendency wrapping fs.statSync().isDirectory() in a try-catch to catch ENOENT errors. In both places we use this helper, we are already wrapping them in a try-catch, so we can swap out this dependency entirely with the native method. However this dep will still exist in our tree, as I believe cosmiconfig depends on it. --- packages/cli-config/package.json | 3 +-- packages/cli-config/src/commands/config/migrate.js | 3 +-- packages/config/package.json | 1 - packages/config/src/load.js | 4 ++-- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/packages/cli-config/package.json b/packages/cli-config/package.json index 0d9c7531d..058a519c5 100644 --- a/packages/cli-config/package.json +++ b/packages/cli-config/package.json @@ -41,7 +41,6 @@ "@oclif/config": "^1.17.0", "@percy/config": "^1.0.0-beta.31", "@percy/core": "^1.0.0-beta.31", - "@percy/logger": "^1.0.0-beta.31", - "path-type": "^4.0.0" + "@percy/logger": "^1.0.0-beta.31" } } diff --git a/packages/cli-config/src/commands/config/migrate.js b/packages/cli-config/src/commands/config/migrate.js index 5b6b86337..f6802e5ee 100644 --- a/packages/cli-config/src/commands/config/migrate.js +++ b/packages/cli-config/src/commands/config/migrate.js @@ -1,6 +1,5 @@ import fs from 'fs'; import path from 'path'; -import { isDirectorySync } from 'path-type'; import Command, { flags } from '@oclif/command'; import PercyConfig from '@percy/config'; import logger from '@percy/logger'; @@ -43,7 +42,7 @@ export class Migrate extends Command { // load config using the explorer directly rather than the load method to // better control logs and prevent validation try { - let result = !input || isDirectorySync(input) + let result = !input || fs.statSync(input).isDirectory() ? PercyConfig.explorer.search(input) : PercyConfig.explorer.load(input); diff --git a/packages/config/package.json b/packages/config/package.json index 4357cb69a..857e6eb33 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -28,7 +28,6 @@ "@percy/logger": "^1.0.0-beta.31", "ajv": "^7.0.3", "cosmiconfig": "^7.0.0", - "path-type": "^4.0.0", "yaml": "^1.10.0" }, "devDependencies": { diff --git a/packages/config/src/load.js b/packages/config/src/load.js index 5b626bb75..b9064ac85 100644 --- a/packages/config/src/load.js +++ b/packages/config/src/load.js @@ -1,6 +1,6 @@ import { relative } from 'path'; +import { statSync } from 'fs'; import { cosmiconfigSync } from 'cosmiconfig'; -import { isDirectorySync } from 'path-type'; import logger from '@percy/logger'; import getDefaults from './defaults'; import migrate from './migrate'; @@ -49,7 +49,7 @@ export default function load({ // load config or reload cached config if (path !== false && (!config || reload)) { try { - let result = !path || isDirectorySync(path) + let result = !path || statSync(path).isDirectory() ? explorer.search(path) : explorer.load(path); if (result && result.config) {