Skip to content

Commit fe9c289

Browse files
committed
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
1 parent 964bff5 commit fe9c289

File tree

8 files changed

+49
-35
lines changed

8 files changed

+49
-35
lines changed

bin/utils/convert-argv.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const webpackConfigurationSchema = require("../config/webpackConfigurationSchema
77
const validateSchema = require("webpack").validateSchema;
88
const WebpackOptionsValidationError = require("webpack").WebpackOptionsValidationError;
99
const findup = require("findup-sync");
10+
// const { webpackConfigPath } = require("@webpack-cli/utils/path-utils");
1011

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

7678
if (pathToWebpackConfig) {
7779
const resolvedPath = path.resolve(pathToWebpackConfig);

packages/utils/__tests__/is-local-path.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"use strict";
22

33
import * as path from "path";
4-
import isLocalPath from "../is-local-path";
4+
import { isLocalPath } from "../path-utils";
55

66
describe("is-local-path", () => {
77
it("returns true for paths beginning in the current directory", () => {

packages/utils/find-root.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/utils/is-local-path.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

packages/utils/npm-packages-exists.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import chalk from "chalk";
22

3-
import isLocalPath from "./is-local-path";
43
import npmExists from "./npm-exists";
4+
import { isLocalPath } from "./path-utils";
55
import { resolvePackages } from "./resolve-packages";
66

77
const WEBPACK_SCAFFOLD_PREFIX = "webpack-scaffold";

packages/utils/path-utils.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import * as findup from "findup-sync";
2+
import * as fs from "fs";
3+
import * as path from "path";
4+
5+
/**
6+
* Attempts to detect whether the string is a local path regardless of its
7+
* existence by checking its format. The point is to distinguish between
8+
* paths and modules on the npm registry. This will fail for non-existent
9+
* local Windows paths that begin with a drive letter, e.g. C:..\generator.js,
10+
* but will succeed for any existing files and any absolute paths.
11+
*
12+
* @param {String} str - string to check
13+
* @returns {Boolean} whether the string could be a path to a local file or directory
14+
*/
15+
16+
export function isLocalPath(str: string): boolean {
17+
return path.isAbsolute(str) || /^\./.test(str) || fs.existsSync(str);
18+
}
19+
20+
/**
21+
* Get absolute path of a webpack config in a project.
22+
*
23+
* @param {String[]} str - array of extensions to look for.
24+
* @returns {String} Absolute path of the config.
25+
*/
26+
27+
export function webpackConfigPath(extensions: string[]): string {
28+
const defaultConfigFileNames = ["webpack.config", "webpackfile"].join("|");
29+
const webpackConfigFileRegExp = `(${defaultConfigFileNames})(${extensions.join("|")})`;
30+
return findup(webpackConfigFileRegExp);
31+
}
32+
33+
/**
34+
* Find the root directory path of a project.
35+
*
36+
* @returns {String} Absolute path of the project root.
37+
*/
38+
39+
export function findProjectRoot(): string {
40+
const rootFilePath = findup(`package.json`);
41+
const projectRoot = path.dirname(rootFilePath);
42+
return projectRoot;
43+
}

packages/utils/resolve-packages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import chalk from "chalk";
22
import * as path from "path";
33

4-
import isLocalPath from "./is-local-path";
54
import modifyConfigHelper from "./modify-config-helper";
65
import { getPathToGlobalPackages } from "./package-manager";
76
import { spawnChild } from "./package-manager";
7+
import { isLocalPath } from "./path-utils";
88

99
interface IChildProcess {
1010
status: number;

packages/utils/scaffold.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import chalk from "chalk";
22
import * as j from "jscodeshift";
33
import pEachSeries = require("p-each-series");
44
import * as path from "path";
5-
import { findProjectRoot } from "./find-root";
5+
import { findProjectRoot } from "./path-utils";
66

77
import { IError } from "../init/types";
88
import { IConfig, ITransformConfig } from "./modify-config-helper";

0 commit comments

Comments
 (0)