Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong order #9

Closed
hoho opened this issue Oct 11, 2014 · 4 comments
Closed

Wrong order #9

hoho opened this issue Oct 11, 2014 · 4 comments

Comments

@hoho
Copy link

hoho commented Oct 11, 2014

Let's assume we have the following file structure:

tmptmp
    tmp1
        a.txt
        b.txt
    tmp2
        aa.txt
        bb.txt

And my pattern looks like:

var pattern = [
    'tmptmp/tmp1/a.txt',
    'tmptmp/tmp2/aa.txt',
    'tmptmp/tmp2/bb.txt',
    'tmptmp/tmp1/b.txt'
];

I call gulp.src(pattern).pipe(order(pattern)) and the result is:

tmptmp/tmp1/a.txt
tmptmp/tmp2/aa.txt
tmptmp/tmp1/b.txt
tmptmp/tmp2/bb.txt

Which is wrong.

@mrcljx
Copy link
Collaborator

mrcljx commented Oct 15, 2014

I just tried this by adding a test to tests.coffee and can't reproduce it.

    it "doesn't show the bug in #9", (done) ->
      patterns = [
        'tmptmp/tmp1/a.txt',
        'tmptmp/tmp2/aa.txt',
        'tmptmp/tmp2/bb.txt',
        'tmptmp/tmp1/b.txt'
      ]

      stream = order(patterns)

      files = []
      stream.on "data", files.push.bind(files)
      stream.on "end", ->
        expect(files.length).to.equal 4
        expect(files[0].relative).to.equal "tmptmp/tmp1/a.txt"
        expect(files[1].relative).to.equal "tmptmp/tmp2/aa.txt"
        expect(files[2].relative).to.equal "tmptmp/tmp2/bb.txt"
        expect(files[3].relative).to.equal "tmptmp/tmp1/b.txt"
        done()

      for pattern in patterns
        stream.write newFile(pattern)

      stream.end()

@mrcljx
Copy link
Collaborator

mrcljx commented Oct 15, 2014

Alright, reproduced it. The thing is, that order works based on the relative filename and gulp.src doesn't set base (which is required for the calculation of relative) as one might expect. Forcing the base in gulp.src (you could also use the base option for order) fixes the issue:

gulp
    .src(patterns, { base: process.cwd() })
    .pipe(order(patterns))

@mrcljx mrcljx mentioned this issue Oct 15, 2014
Closed
@hoho
Copy link
Author

hoho commented Oct 15, 2014

Ok, this case is fixed. But here is another one: the same file structure, nearly the same pattern:

var pattern = [
    'tmptmp/tmp1/a.txt',
    '/absolute/path/to/tmptmp/tmp2/aa.txt',
    '/absolute/path/to/tmptmp/tmp2/bb.txt',
    'tmptmp/tmp1/b.txt'
];

The result is ['a.txt', 'b.txt', 'aa.txt', 'bb.txt']. Absolute paths break it. And in this particular case our absolute path destination is inside process.cwd(). But it could be anywhere on the filesystem (say, I'm including npm dependencies using require.resolve(moduleName)).

@mrcljx
Copy link
Collaborator

mrcljx commented Oct 15, 2014

Allright. Moved that to #11 though.

@mrcljx mrcljx closed this as completed Oct 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants