From 96d325e8611b82ba6577887af88025f2a43b4b80 Mon Sep 17 00:00:00 2001 From: Anshuman Verma Date: Sat, 30 Mar 2019 19:01:45 +0530 Subject: [PATCH] chore(util): single path util file single path util file ISSUES CLOSED: #805 --- bin/utils/convert-argv.js | 2 +- packages/utils/__tests__/is-local-path.test.ts | 2 +- packages/utils/find-root.ts | 8 -------- packages/utils/is-local-path.ts | 17 ----------------- packages/utils/npm-packages-exists.ts | 2 +- packages/utils/resolve-packages.ts | 2 +- packages/utils/scaffold.ts | 2 +- 7 files changed, 5 insertions(+), 30 deletions(-) delete mode 100644 packages/utils/find-root.ts delete mode 100644 packages/utils/is-local-path.ts diff --git a/bin/utils/convert-argv.js b/bin/utils/convert-argv.js index 9c7537bb1dd..528d8406115 100644 --- a/bin/utils/convert-argv.js +++ b/bin/utils/convert-argv.js @@ -6,7 +6,7 @@ const prepareOptions = require("./prepareOptions"); const webpackConfigurationSchema = require("../config/webpackConfigurationSchema.json"); const validateSchema = require("webpack").validateSchema; const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError; -const { webpackConfigPath } = require("../../packages/utils/webpack-config-path"); +const { webpackConfigPath } = require("@webpack-cli/utils/path-utils"); module.exports = function(...args) { const argv = args[1] || args[0]; diff --git a/packages/utils/__tests__/is-local-path.test.ts b/packages/utils/__tests__/is-local-path.test.ts index ca34c0e7b66..654884b9e1a 100644 --- a/packages/utils/__tests__/is-local-path.test.ts +++ b/packages/utils/__tests__/is-local-path.test.ts @@ -1,7 +1,7 @@ "use strict"; import * as path from "path"; -import isLocalPath from "../is-local-path"; +import { isLocalPath } from "../path-utils"; describe("is-local-path", () => { it("returns true for paths beginning in the current directory", () => { diff --git a/packages/utils/find-root.ts b/packages/utils/find-root.ts deleted file mode 100644 index 9e1baf5b1a6..00000000000 --- a/packages/utils/find-root.ts +++ /dev/null @@ -1,8 +0,0 @@ -import * as findup from "findup-sync"; -import * as path from "path"; - -export function findProjectRoot(): string { - const rootFilePath = findup(`package.json`); - const projectRoot = path.dirname(rootFilePath); - return projectRoot; -} diff --git a/packages/utils/is-local-path.ts b/packages/utils/is-local-path.ts deleted file mode 100644 index 0efb8c6fc2c..00000000000 --- a/packages/utils/is-local-path.ts +++ /dev/null @@ -1,17 +0,0 @@ -import * as fs from "fs"; -import * as path from "path"; - -/** - * Attempts to detect whether the string is a local path regardless of its - * existence by checking its format. The point is to distinguish between - * paths and modules on the npm registry. This will fail for non-existent - * local Windows paths that begin with a drive letter, e.g. C:..\generator.js, - * but will succeed for any existing files and any absolute paths. - * - * @param {String} str - string to check - * @returns {Boolean} whether the string could be a path to a local file or directory - */ - -export default function(str: string): boolean { - return path.isAbsolute(str) || /^\./.test(str) || fs.existsSync(str); -} diff --git a/packages/utils/npm-packages-exists.ts b/packages/utils/npm-packages-exists.ts index a1987c3332d..2ad1d797510 100644 --- a/packages/utils/npm-packages-exists.ts +++ b/packages/utils/npm-packages-exists.ts @@ -1,7 +1,7 @@ import chalk from "chalk"; -import isLocalPath from "./is-local-path"; import npmExists from "./npm-exists"; +import { isLocalPath } from "./path-utils"; import { resolvePackages } from "./resolve-packages"; const WEBPACK_SCAFFOLD_PREFIX = "webpack-scaffold"; diff --git a/packages/utils/resolve-packages.ts b/packages/utils/resolve-packages.ts index b16823509a9..9cfbc21fa32 100644 --- a/packages/utils/resolve-packages.ts +++ b/packages/utils/resolve-packages.ts @@ -1,10 +1,10 @@ import chalk from "chalk"; import * as path from "path"; -import isLocalPath from "./is-local-path"; import modifyConfigHelper from "./modify-config-helper"; import { getPathToGlobalPackages } from "./package-manager"; import { spawnChild } from "./package-manager"; +import { isLocalPath } from "./path-utils"; interface IChildProcess { status: number; diff --git a/packages/utils/scaffold.ts b/packages/utils/scaffold.ts index 7aa5ff7eb63..caacf61ef6a 100644 --- a/packages/utils/scaffold.ts +++ b/packages/utils/scaffold.ts @@ -2,7 +2,7 @@ import chalk from "chalk"; import * as j from "jscodeshift"; import pEachSeries = require("p-each-series"); import * as path from "path"; -import { findProjectRoot } from "./find-root"; +import { findProjectRoot } from "./path-utils"; import { IError } from "../init/types"; import { IConfig, ITransformConfig } from "./modify-config-helper";