gulp-path-length

A Gulp plugin for enforcing a character limit on file paths

Usage no npm install needed!

<script type="module">
  import gulpPathLength from 'https://cdn.skypack.dev/gulp-path-length';
</script>

README

gulp-path-length

NPM version Build Status Windows Build Status Dependency Status


A Gulp plugin for enforcing a character limit on file paths. Created with Windows' 256 character limit in mind but can be used on other platforms too.

Installation

npm install gulp-path-length

Usage

var gulp = require('gulp');
var pathLength = require('gulp-path-length');

gulp.task('default', function(){
    gulp.src('./example/path/to/directory/**', {read: false})
        .pipe(pathLength()); 
});

This will stop the build with an error if you've an overly long path. I've passed {read: false} to gulp.src here because we don't need to read the contents, we just need the paths. But if you're using gulp-path-length after some other pipes, it's likely you shouldn't pass {read: false}.

API

There is only one (optional) parameter; an options object. The possible properties it can contain are:

  • maxLength - defaults to 256
  • rewrite - This is an optional object which should contain match and replacement properties which contains mappings between directories. So for example:
rewrite: {
    match: './example/path/to/directory/',
    replacement: 'C:\\Program Files (x86)\\abc'
}

When the plugin goes to check the file ./example/path/to/directory/x.txt, it will actually check C:\Program Files (x86)\abc\x.txt.

  • rewrite.match accepts a path to resolve (like ./example), relative (example/a) or absolute paths (C:\a).
  • rewrite.replacement only accepts an absolute path.