From 310d37b2fc821882cb10b952635844e65dd4c506 Mon Sep 17 00:00:00 2001 From: Adam Reis Date: Thu, 21 Dec 2017 07:20:06 +1300 Subject: [PATCH] Fix CLI path resolving for absolute paths --- README.md | 13 +++++++++---- lib/helpers/load-config.js | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ac6f1f2..f6272ba 100644 --- a/README.md +++ b/README.md @@ -223,15 +223,20 @@ replace-in-file from to some/file.js,some/**/glob.js Multiple files or globs can be replaced by providing a comma separated list. -The flags `disableGlobs`, `ignore` and `encoding` are supported in the CLI. +The flags `--disableGlobs`, `--ignore` and `--encoding` are supported in the CLI. -The flag `allowEmptyPaths` is not supported in the CLI as the replacement is -synchronous, and the flag is only relevant for asynchronous replacement. +The setting `allowEmptyPaths` is not supported in the CLI as the replacement is +synchronous, and this setting is only relevant for asynchronous replacement. -To list the changed files, use the `verbose` flag. +To list the changed files, use the `--verbose` flag. A regular expression may be used for the `from` parameter by specifying the `--isRegex` flag. +The `from` and `to` parameters, as well as the files list, can be omitted if you provide this +information in a configuration file. You can provide a path to a configuration file +(either Javascript or JSON) with the `--configFile` flag. This path will be resolved using +Node’s built in `path.resolve()`, so you can pass in an absolute or relative path. + ## Version information From version 3.0.0 onwards, replace in file requires Node 6 or higher. If you need support for Node 4 or 5, use version 2.x.x. diff --git a/lib/helpers/load-config.js b/lib/helpers/load-config.js index 251f3f9..cc190c1 100644 --- a/lib/helpers/load-config.js +++ b/lib/helpers/load-config.js @@ -15,8 +15,8 @@ module.exports = function loadConfig(file) { return {}; } - //Combine with CWD - file = path.join(process.cwd(), file); + //Resolve path + file = path.resolve(file); //Try to load return require(file);