Actually validate the options that the user provides

pull/1/head
Sven Slootweg 5 years ago
parent 96984a9061
commit 5197c5116a

@ -1,5 +1,7 @@
"use strict";
const { validateArguments, required, oneOf, arrayOf, allowExtraProperties, ValidationError } = require("validatem");
const createTransform = require("./src/transform");
const createCssDepsStream = require("./src/phase-streams/deps-css");
const createSyntaxHideStream = require("./src/phase-streams/syntax-hide");
@ -7,6 +9,12 @@ const createSyntaxUnhideStream = require("./src/phase-streams/syntax-unhide");
const createKahnSortingStream = require("./src/phase-streams/sort-kahn");
const createDedupeBundleCssStream = require("./src/phase-streams/dedupe-bundle-css");
function isPostcssPlugin(value) {
if (value.postcssPlugin == null || value.postcssVersion == null || typeof value !== "function") {
throw new ValidationError(`Must be a PostCSS plugin`);
}
}
// FIXME: When there's >1 icssify instance set up on the Browserify instance (can this happen when a module specifies its own dependency on icssify?), either throw an error (if incompatible?) or merge the two somehow, so that there's only one resulting .css file
function setupPipeline(browserify, options) {
@ -35,6 +43,17 @@ function setupPipeline(browserify, options) {
}
module.exports = function (browserify, options) {
console.log(options);
validateArguments(arguments, [
[ "browserify" ],
[ "options", allowExtraProperties({
mode: oneOf([ "local", "global" ]),
before: arrayOf([ required, isPostcssPlugin ]),
after: arrayOf([ required, isPostcssPlugin ])
})]
]);
browserify.transform(createTransform, options);
browserify.on("reset", () => {

Loading…
Cancel
Save