
Security News
TC39 Advances 11 Proposals for Math Precision, Binary APIs, and More
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
gulp-not-supported-file
Advanced tools
Not a Gulp plugin,
but for Gulp plugin developers.
Check the file before process it in your Gulp plugin
Most of Gulp plugins for compiling/rendering static files use through2 for processing. And first step of each code is a testing file
- it is not null
- it is not stream
- it is not ...
And after this checkouts we may work with file.
Little example
const through2 = require('through2');
const PluginError = require('plugin-error');
const PLUGIN_NAME = 'my-plugin';
function myGulpPLugin(options) {
// process options if need
// ...
// processing
return through2.obj(function(file, enc, cb) {
if (file.isNull()) {
return cb(null, file);
}
if (file.isStream()) {
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
}
if (!file.contents.length) {
return cb(null, file);
}
// and other if and if
// ...
// and then work with it
});
}
I'm tired of writing the same code every time.
So I wrote it once and wrapped it in a tiny module.
Call this module with your file and with your plugin error handler. Module will return result:
false
if the file is suitable for workArray
if the file failed the test. Array will contain arguments. First of them is text status name of fail and next arguments for through2
callback.Status list
'isDirectory'
- will be error'isNull'
- will be error'isStream'
- will be error'isEmpty'
- skip file'isUnderscore'
- skip fileUsage example
const through2 = require('through2');
const PluginError = require('plugin-error');
const PLUGIN_NAME = 'my-plugin';
const notSupportedFile = require('gulp-not-supported-file');
// ---------------------------
// private method plugin error
function pluginError (data, errorOptions) {
return new PluginError(PLUGIN_NAME, data, errorOptions);
}
// core plugin method
function myGulpPlugin(options) {
// process options if need
// ...
// processing
return through2.obj(function (file, enc, cb) {
let notSupported = notSupportedFile(file, pluginError);
if (Array.isArray(notSupported)) {
notSupported.shift(); // or with saving -> let failStatus = notSupported.shift();
return cb(...notSupported); // or es5 apply -> cb.apply(null, notSupported);
}
// work with file if passed
// ...
});
}
module.exports = myGulpPlugin;
Options are passed by the third argument and must be an object
let notSupported = notSupportedFile(file, pluginError, options);
noUnderscore
type boolean
/
default true
File with empty content will be skipped and not using in stream next.
You will receive message in console if it happens
Example of log:
noEmpty
type boolean
/
default true
File with empty content will be skipped and not using in stream next.
Return ['isEmpty']
Note! Spaces, tabs and newlines will be treated as empty content.
You will receive message in console if it happens_stream next.
Example of log:
silent
type boolean
/
default false
No logs about noEmpty
and noUnderscore
files
npm install --save gulp-not-supported-file
# or using yarn cli
yarn add gulp-not-supported-file
npm test
for testing code style and run mocha testsnpm run happiness-fix
for automatically fix most of problems with code stylePlease read CHANGELOG.md
Please read CONTRIBUTING.md
FAQs
Check the file before process it in your Gulp plugin
The npm package gulp-not-supported-file receives a total of 216 weekly downloads. As such, gulp-not-supported-file popularity was classified as not popular.
We found that gulp-not-supported-file demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.
Research
/Security News
A flawed sandbox in @nestjs/devtools-integration lets attackers run code on your machine via CSRF, leading to full Remote Code Execution (RCE).
Product
Customize license detection with Socket’s new license overlays: gain control, reduce noise, and handle edge cases with precision.