sindresorhus / gulp-rev

Static asset revisioning by appending content hash to filenames: `unicorn.css` → `unicorn-d41d8cd98f.css`
MIT License
1.54k stars 217 forks source link

Manifest output doesn't follow the base path #141

Closed Tanato closed 8 years ago

Tanato commented 8 years ago

Like in issue #47, I have a problem when using streams with differents paths but the fix doesn't solve my problem

I have to copy my files from the structure below to the next one

app
├ app.js
└ file2.js
assets
├ assets01.js
└ assets02.js
build
  ├ app
  | ├ app-a6b81a1b26.js
  | └ file2-45c0a77698.js
  ├ assets
  | ├ assets01-57d1fd59e2.js
  | └ assets02-a8caee4b31.js

And for my needs, I expect the structure in the manifest file to be something like this:

{
    "app/app.js": "app/app-a6b81a1b26.js",
    "app/file2.js": "app/file2-45c0a77698.js",
    "assets/assets.js": "assets/assets-57d1fd59e2.js",
    "assets/assets.js": "assets/assets-a8caee4b31.js"
}

All those files have the same build/ folder in the destination, so I map the base in src to { base: './'} as you can see in my code below:

gulp.task('appBuild', function () {
    return gulp.src('**/*.js', { cwd: 'app/', base: './' })
        .pipe(addsrc('**/*.js', { cwd: 'assets/', base: './' }))
        .pipe(rev())
        .pipe(revReplace())
        .pipe(gulp.dest('build/'))
        .pipe(rev.manifest('version.json', { merge: true }))
        .pipe(gulp.dest('build/'));
});

I know that I could use multiple streams for achieve this, but in my case doesn't make sense since I have the same pipes to work in those files.

To fix this problem, I just had to change the manifest base path to be the base of each file, and not the first one for all files.

I couldn't understand why you use a single path as base for all, but seems to me that this change doesn't affect how the manifest works and not the performance as well.

Please let me know if I misunderstood something or if there's any reason for this pull request couldn't be

Tanato commented 8 years ago

After dig a little better why is the motive for this "patch" in filename base to use the first one for every file, I saw the issue #103 and seems to me that the fix applied worked fine but only if you have a single base path.

I'll try to recreate the issue in my environment so I can fix both errors properly (seems to me that the issue is in relPath function).

Tanato commented 8 years ago

I create an environment with the structure bellow to simulate the issue #103 and my pull-request doesn't break the previous fix

app/
  ├ common/
  | ├ common-app.js
  | ├ component/
  | | ├ component.js
  | | ├ exceptions/
  | | | └ exception.js
  ├ core/
  | ├ core-app.js
  | ├ features/
  | | ├ animals/
  | | | └ animals-ctrl.js
  | | ├ donate/
  | | | └ donate-ctrl.js
gulp.task('teste', function () {
    gulp.src([
        'app/common/**/*.js', // first source dir
        'app/core/**/*.js' // second source dir
    ])
        .pipe(rev())
        .pipe(revReplace())
        .pipe(gulp.dest('teste/'))
        .pipe(rev.manifest('version.json', {
            merge: true
        }))
        .pipe(gulp.dest('teste/'));
});
{
  "common-app.js": "common-app-986b060995.js",
  "components/components.js": "components/components-1ce0abfcd5.js",
  "components/exceptions/exceptions.js": "components/exceptions/exceptions-c5ce7827eb.js",
  "core-app.js": "core-app-c8a28dd6f3.js",
  "features/animals/animals-ctrl.js": "features/animals/animals-ctrl-9ac224798d.js",
  "features/donate/donate-ctrl.js": "features/donate/donate-ctrl-1503f2123c.js",
}
webda2l commented 8 years ago

:+1:

silent-e commented 8 years ago

+1. this was driving me nuts.