Use parametric modules for passing around state, and use that to implement a custom extensions option
parent
3cd5ff620a
commit
3840a1f8d3
@ -1,5 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
module.exports = function isCss(item) {
|
||||
return /\.css$/.test(item.file);
|
||||
const defaultValue = require("default-value");
|
||||
const path = require("path");
|
||||
|
||||
// Yes, there is a good reason this is a separate module. In the future we may need to add more heuristics to determine whether a "CSS file" *really* is a CSS file, rather than just going off the filename, and this centralizes the checking logic we'd need to change for that. If this ever occurs, though, keep in mind that this function doesn't always get a *full* file object (sometimes it just gets an object with a filename), so any such heuristics would need to be able to deal with that.
|
||||
|
||||
module.exports = function (state) {
|
||||
let targetExtensions = new Set(defaultValue(state.extensions, [ "css" ]));
|
||||
|
||||
return function isCss(item) {
|
||||
let itemExtension = path.extname(item.file).replace(/^\./, "");
|
||||
|
||||
return targetExtensions.has(itemExtension);
|
||||
};
|
||||
};
|
||||
|
@ -1,13 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
const cssOnlyStream = require("../css-only-stream");
|
||||
const hideCss = require("../hide-css");
|
||||
|
||||
module.exports = function createSyntaxHideStream() {
|
||||
module.exports = function (state) {
|
||||
const cssOnlyStream = require("../css-only-stream")(state);
|
||||
|
||||
return function createSyntaxHideStream() {
|
||||
return cssOnlyStream((file) => {
|
||||
return {
|
||||
... file,
|
||||
source: hideCss(file.source)
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
|
@ -1,13 +1,16 @@
|
||||
"use strict";
|
||||
|
||||
const cssOnlyStream = require("../css-only-stream");
|
||||
const unhideCss = require("../unhide-css");
|
||||
|
||||
module.exports = function createSyntaxHideStream() {
|
||||
module.exports = function (state) {
|
||||
const cssOnlyStream = require("../css-only-stream")(state);
|
||||
|
||||
return function createSyntaxHideStream() {
|
||||
return cssOnlyStream((file) => {
|
||||
return {
|
||||
... file,
|
||||
source: unhideCss(file.source)
|
||||
};
|
||||
});
|
||||
};
|
||||
};
|
||||
|
Loading…
Reference in New Issue