Skip to content

Commit 916c9b8

Browse files
committed
Don't mutate global config object
Closes #152
1 parent 205a83b commit 916c9b8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

index.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const output = argv.output
2424

2525
if (argv.map) argv.map = { inline: false }
2626

27-
let config = {
27+
const cliConfig = {
2828
options: {
2929
map: argv.map !== undefined ? argv.map : { inline: true },
3030
parser: argv.parser ? require(argv.parser) : undefined,
@@ -42,6 +42,8 @@ let config = {
4242
: []
4343
}
4444

45+
let configFile
46+
4547
if (argv.env) process.env.NODE_ENV = argv.env
4648
if (argv.config) argv.config = path.resolve(argv.config)
4749

@@ -90,7 +92,7 @@ Promise.resolve()
9092
interval: argv.poll && typeof argv.poll === 'number' ? argv.poll : 100
9193
})
9294

93-
if (config.file) watcher.add(config.file)
95+
if (configFile) watcher.add(configFile)
9496

9597
watcher.on('ready', printMessage).on('change', file => {
9698
let recompile = []
@@ -117,7 +119,7 @@ Promise.resolve()
117119
})
118120

119121
function rc(ctx, path) {
120-
if (argv.use) return Promise.resolve()
122+
if (argv.use) return Promise.resolve(cliConfig)
121123

122124
// Set argv: false to keep cosmiconfig from attempting to read the --config
123125
// flag from process.argv
@@ -128,7 +130,8 @@ function rc(ctx, path) {
128130
'Config Error: Can not set from or to options in config file, use CLI arguments instead'
129131
)
130132
}
131-
config = rc
133+
configFile = rc.file
134+
return rc
132135
})
133136
.catch(err => {
134137
if (err.message.indexOf('No PostCSS Config found') === -1) throw err
@@ -153,7 +156,7 @@ function files(files) {
153156
}
154157

155158
function css(css, file) {
156-
const ctx = { options: config.options }
159+
const ctx = { options: cliConfig.options }
157160

158161
if (file !== 'stdin') {
159162
ctx.file = {
@@ -175,7 +178,8 @@ function css(css, file) {
175178
printVerbose(chalk`{cyan Processing {bold ${relativePath}}...}`)
176179

177180
return rc(ctx, argv.config)
178-
.then(() => {
181+
.then(config => {
182+
config = config || cliConfig
179183
const options = config.options
180184

181185
if (file === 'stdin' && output) file = output

0 commit comments

Comments
 (0)