hparra/gulp-rename

Renaming changes working/base directory?

leewz opened this issue · 3 comments

leewz commented

I'm using gulp-rename 1.2.2 with gulp-less and gulp-inject, and somehow, the path that was injected into the HTML had a bunch of extra ../ if I piped it through gulp-rename. The weird thing is, most of them were there because I piped through gulp-rename, not because of how I used it. Both of these gave the same different result (vs skipping rename):

.pipe(rename(x=>x))
.pipe(rename({}))

I didn't expect these apparently-empty operations to have an effect, but they did. Taking out gulp-less also got rid of the extra ../s.

What I was trying to do: Pipe a .less source (with a specified base directory) into gulp-less, then change its dirname, then inject it (without writing the CSS file first).

I tried to make a minimal reproduction from scratch, but wasn't able to reproduce it. If anyone has any tips on tracking down the problem, I'll take them.

leewz commented

I isolated it. gulp-rename is changing file.path (the absolute path) to a relative path if base is specified.

gulpfile.js:

var gulp = require('gulp');
var rename = require('gulp-rename');

gulp.task('default', function() {
    // gulp.src('gulpfile.js')
    gulp.src('gulpfile.js', {base: '.'})
        .pipe(show('Before:'))
        // .pipe(rename({}))
        .pipe(rename(x=>x))
        // .pipe(rename({basename:'gulpfile'}))
        .pipe(show('After:'))
});

var through = require('through2');
function show(label) {
    return through.obj(function(file, encoding, callback) {
    callback(null, doSomethingWithTheFile(file));
  });

  function doSomethingWithTheFile(file) {
      console.log(label, file.path);
      return file;
  }
}

Output:

[15:49:30] Using gulpfile ~\Documents\BUGTEST-gulp-rename\gulpfile.js
[15:49:30] Starting 'default'...
[15:49:30] Finished 'default' after 8.83 ms
Before: C:\Users\Franklin\Documents\BUGTEST-gulp-rename\gulpfile.js
After: gulpfile.js

I have this problem to, that's block me.

Cleaning up old tickets so I'm going to close this - if you still have this issue let me know and I'll reopen it.