Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
chore(cli): remove findup-sync from package dir and move to utils
remove findup-sync from package dir and move to utils
cli(utils): added path-util to be used after next release
added path-util to be used after next release

ISSUES CLOSED: #805
  • Loading branch information
anshumanv committed Apr 19, 2019
1 parent 964bff5 commit fe9c289
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 35 deletions.
2 changes: 2 additions & 0 deletions bin/utils/convert-argv.js
Expand Up @@ -7,6 +7,7 @@ const webpackConfigurationSchema = require("../config/webpackConfigurationSchema
const validateSchema = require("webpack").validateSchema;
const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError;
const findup = require("findup-sync");
// const { webpackConfigPath } = require("@webpack-cli/utils/path-utils");

module.exports = function(...args) {
const argv = args[1] || args[0];
Expand Down Expand Up @@ -72,6 +73,7 @@ module.exports = function(...args) {
const defaultConfigFileNames = ["webpack.config", "webpackfile"].join("|");
const webpackConfigFileRegExp = `(${defaultConfigFileNames})(${extensions.join("|")})`;
const pathToWebpackConfig = findup(webpackConfigFileRegExp);
// const pathToWebpackConfig = webpackConfigPath(extensions);

if (pathToWebpackConfig) {
const resolvedPath = path.resolve(pathToWebpackConfig);
Expand Down
2 changes: 1 addition & 1 deletion 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", () => {
Expand Down
14 changes: 0 additions & 14 deletions packages/utils/find-root.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/utils/is-local-path.ts

This file was deleted.

2 changes: 1 addition & 1 deletion 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";
Expand Down
43 changes: 43 additions & 0 deletions packages/utils/path-utils.ts
@@ -0,0 +1,43 @@
import * as findup from "findup-sync";
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 function isLocalPath(str: string): boolean {
return path.isAbsolute(str) || /^\./.test(str) || fs.existsSync(str);
}

/**
* Get absolute path of a webpack config in a project.
*
* @param {String[]} str - array of extensions to look for.
* @returns {String} Absolute path of the config.
*/

export function webpackConfigPath(extensions: string[]): string {
const defaultConfigFileNames = ["webpack.config", "webpackfile"].join("|");
const webpackConfigFileRegExp = `(${defaultConfigFileNames})(${extensions.join("|")})`;
return findup(webpackConfigFileRegExp);
}

/**
* Find the root directory path of a project.
*
* @returns {String} Absolute path of the project root.
*/

export function findProjectRoot(): string {
const rootFilePath = findup(`package.json`);
const projectRoot = path.dirname(rootFilePath);
return projectRoot;
}
2 changes: 1 addition & 1 deletion 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;
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/scaffold.ts
Expand Up @@ -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";
Expand Down

0 comments on commit fe9c289

Please sign in to comment.