Skip to content

Commit a7579a3

Browse files
committed
Allow running without plugins
1 parent 9aaa652 commit a7579a3

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ all: clean lint test
33
lint:
44
./node_modules/.bin/jshint *.js
55

6-
TESTS = opts source-maps source-maps-file stdout stdin config config-all config-wildcard js-config js-config-all invalid warning
6+
TESTS = opts source-maps source-maps-file stdout stdin config config-all config-wildcard js-config js-config-all invalid warning no-plugin
77

88

99
DIFF = diff -q
@@ -83,6 +83,9 @@ test/build/invalid.css: test/in-force-error.css
8383
test/build/warning.css: test/in-warning.css
8484
./bin/postcss --use ./test/dummy-plugin -o $@ $< && echo Warning is OK here....
8585

86+
test/build/no-plugin.css: test/no-plugin.css
87+
./bin/postcss ./test/no-plugin.css -o $@ && echo It works without plugins
88+
8689
test/build/config.css: test/in.css
8790
./bin/postcss -u postcss-url -c test/config.json -o $@ $<
8891
$(DIFF) $@ $(subst build,ref,$@)

index.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ var argv = require("yargs")
4949
.help('h')
5050
.alias('h', 'help')
5151
.check(function(argv) {
52-
if (!argv.use) {
53-
throw 'Please specify at least one plugin name.';
54-
}
5552
if (argv._.length && argv.input) {
5653
throw 'Both positional arguments and --input option used for `input file`: please only use one of them.';
5754
}
@@ -104,8 +101,10 @@ var plugins = argv.use.map(function(name) {
104101
if (local) {
105102
var resolved = resolve.sync(name, {basedir: process.cwd()});
106103
plugin = require(resolved);
107-
} else {
104+
} else if (name) {
108105
plugin = require(name);
106+
} else {
107+
return null;
109108
}
110109
if (name in argv) {
111110
plugin = plugin(argv[name]);
@@ -136,7 +135,7 @@ var path = require('path');
136135
var readFile = require('read-file-stdin');
137136
var path = require('path');
138137
var postcss = require('postcss');
139-
var processor = postcss(plugins);
138+
var processor = plugins[0] ? postcss(plugins) : postcss();
140139
var mkdirp = require('mkdirp');
141140

142141
// hook for dynamically updating the list of watched files

test/no-plugin.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
margin: 0;
3+
}

0 commit comments

Comments
 (0)