GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use glob for globbing by ariporad · Pull Request #275 · shelljs/shelljs

Conversation

@ariporad

@ariporad ariporad commented Jan 8, 2016

Copy link
Copy Markdown
Contributor

Fixes #225

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@TimothyGu

TimothyGu commented Jan 8, 2016

Copy link
Copy Markdown
Contributor

Doesn't shell.js have its own glob expansion function?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Jan 8, 2016

Copy link
Copy Markdown
Contributor Author

Oh yeah, I'll fix that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad ariporad changed the title Use glob for ls Use glob for globbing Jan 8, 2016
@ariporad
ariporad force-pushed the fix/225 branch from fc1b95e to 5bcebfa Compare January 8, 2016 04:28
@ariporad

ariporad commented Jan 8, 2016

Copy link
Copy Markdown
Contributor Author

Fixed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 8, 2016

Copy link
Copy Markdown
Member

@ariporad Could you ping this with a push to trigger the CI?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer nfischer mentioned this pull request Jan 8, 2016
Dir glob breaks when in the middle of path #245
Closed
@ariporad
ariporad force-pushed the fix/225 branch from 5bcebfa to c8f3bc0 Compare January 9, 2016 04:07
@ariporad

ariporad commented Jan 9, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad ariporad mentioned this pull request Jan 9, 2016
ls globbing does not behave like shell, consider using glob.sync #225
Closed
@boutell

boutell commented Jan 9, 2016

Copy link
Copy Markdown

Thank you!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nfischer
nfischer reviewed Jan 12, 2016
View reviewed changes
Comment thread package.json

@nfischer nfischer Jan 12, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use glob without adding it as a package dependency? I know some of the original maintainers wanted to keep dependencies at a minimum (#122 (comment)).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nfischer nfischer Jan 12, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind. Just tried it and saw that I do need to install it as a dependency. We might need to ping @arturadib and get his input on this in that case.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ariporad ariporad Jan 12, 2016

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nfischer: I think it's not that big a deal. If a user is installing us, then they have npm installed. The whole node world favors small focused modules, which mean dependencies. This means that deps are the norm. It's not out of the ordinary. (As a matter of fact, I'd like to try and split this module up into some smaller ones).

However, if @arturadib wants to chime in, that's more than welcome.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@nfischer nfischer Jan 12, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the philosophy of using modules where they make sense. I think we probably should take advantage of the glob module, since it seems to integrate fairly seemlessly with the existing code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@arturadib

arturadib commented Jan 12, 2016

Copy link
Copy Markdown
Collaborator

@nfischer @ariporad as you can probably tell from package.json, I have generally biased to avoid dependencies. I have no problem with leveraging dependencies – esp for larger projects so you can get to market more quickly etc – but the downside of dependencies is that you lose a lot of control, in particular nuanced features and updates, and more often than not packages are abandoned/unmaintained (cough cough :)), so you end up blocking your own work until someone lands a feature upstream, etc.

luckily in our case our package is pretty small and the problems low level enough that the Node core lib is mostly sufficient. when I do encounter cases where reinventing the wheel takes more than a dozen lines of code or so, I simply copy and paste the relevant snippet :) like this: https://github.com/shelljs/shelljs/blob/master/src/cp.js#L44-L51

(it's obviously a tradeoff as in this case we also don't benefit from a well maintained project upstream, but again, those are all tradeoffs)

all this being said..... glob does seem like a good, well maintained library, and I think our code is reinventing the wheel a bit too much (and not that well), so let's go ahead and see if this is a good solution going forward.

my main concern at this point is breaking existing users, so let's bump at least the minor when we release, and make sure glob is mostly shell-compliant. (I'm not too familiar with ** behavior on *nix, so we'll need to check that).

thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Jan 13, 2016

Copy link
Copy Markdown
Contributor Author

@arturadib: Three things:

  1. Personally, I like lots of small modules, so I apologize in advance for when I forget on my PRs (Just remind me and I'll be more than happy to fix them. I'm not a fan of flame wars).
  2. glob is written by @isaacs, the creator and CEO of npm (I'm not mentioning him to reduce his spam). No need to worry about it being abandoned.
  3. According to semver, it should either be a patch bump if it doesn't break anything, or else a major bump (however, we're <1.0.0, which means that a instead of a major bump we would do a minor bump).
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@isaacs

isaacs commented Jan 13, 2016

Copy link
Copy Markdown

(I'm not mentioning him to reduce his spam)

Unfortunately, your clever and thoughtful plan failed. You need to put the \ between the @ and the name, or else GitHub will still send the notification. (Not to worry, I get basically an infinite amount of email, so one more or less makes no substantive difference ;)

The goal of the glob module is to match Bash 4.3 pattern matching as closely as possible, so it's probably a great fit for shelljs's needs. Since this will certainly change some of your existing edge cases, it seems like it probably should be a major version bump for shelljs, just to be on the safe side.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 13, 2016

Copy link
Copy Markdown
Member

all this being said..... glob does seem like a good, well maintained library, and I think our code isreinventing the wheel a bit too much (and not that well), so let's go ahead and see if this is a good solution going forward.

I agree. My vote is in favor of switching to glob. I think if reinventing the wheel is simple enough, it may be best to do it ourselves. In this case however, we're not very closely matching Bash globbing, so the switch is probably smart.

It seems like we all agree we should give glob a shot. My main concern with this PR is that I'd like to move all globbing into common.js. Globbing is normally handled by the shell, not the utilities, in *nix, so handling all globbing in that file will simplify our code and almost certainly get closer to *nix behavior.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Jan 13, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: the more I think about it, the more I think that I want to submit a PR moving all the command boilerplate into common.js.

I'm unfortunately extremely busy this week, but over the weekend I should have some time to do that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nfischer
nfischer reviewed Jan 13, 2016
View reviewed changes
Comment thread src/ls.js Outdated

@nfischer nfischer Jan 13, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we change this to files = common.expand(files, { dot: options.all }), and update expand() to take glob's options as a second parameter, this will eliminate the dependency on glob here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Jan 14, 2016
Bracket expansion not working #176
Closed
feat: add tilde expansion to expand() #293
Merged
cp -R dir/ target fails to copy hidden files in dir #140
Closed
@nfischer nfischer mentioned this pull request Jan 24, 2016
fix: regexes are more consistent with sed and grep #303
Merged
@ariporad ariporad assigned nfischer Jan 24, 2016
@ariporad
ariporad force-pushed the fix/225 branch 2 times, most recently from 17a33c5 to fd77b7e Compare January 24, 2016 22:36
@ariporad

ariporad commented Jan 24, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Ok, moved all the globbing into common, and fixed listing files with no dots.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad
ariporad force-pushed the fix/225 branch from fd77b7e to a2435fb Compare January 24, 2016 22:38
@ariporad

ariporad commented Jan 24, 2016

Copy link
Copy Markdown
Contributor Author

Also rebased onto master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Jan 31, 2016

Copy link
Copy Markdown
Member

@ariporad looks like there's some conflicts now (probably due to the -l option for ls). Once those are resolved, I can merge

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Hmm... I actually think that there's no way to salvage -l. It's really tightly coupled to the existing implementation. I think we'll have to re-implement it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

@ariporad could you push this into a branch on the main repo? I'll take a look at refactoring -l support. I'd prefer to not lose any features if it can be avoided.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: I did, but it won't work to update this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

@ariporad we would have to push to a new branch and open that as a PR to replace this one I think.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Yeah, or I can give you push access to my fork. Up to you. (I'd rather not loose all the discussion).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

Yeah, or I can give you push access to my fork. Up to you. (I'd rather not loose all the discussion).

^ even better idea, actually

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Ok, you've got push access.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

I'll take a look

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Ok, you've got push access.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

So it turns out that this PR actually is kind of far from working. It passes CI because run-tests doesn't actually run any tests (ls() is broken). I have most of the tests passing, but I'm still running into some nasty edge cases. I think it may be more worth-while to do some refactoring first, and then make a simpler change that swaps common.expand()'s implementation for one that uses glob.sync().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: that's what this does. (Take a look at the changes tab). What do you mean it doesn't work?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

@ariporad this completely modifies the behavior of ls() as well. Click on any run of the CI and notice how it says "all tests passed"... without listing any of the tests. Now click on any other PR and see that run-tests lists every test file (i.e. cat.js, cp.js, etc) before the words "all tests passed"

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Hmm... Let me look in to fixing that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

@ariporad I don't think you can wipe out all the ls() code. I think we would be much better off swapping the implementation of expand() with one using glob. I can add a call to expand() inside common.wrap(), which I where I think we should handle most expansion (it lifts the burden off utilities like rm(), which shouldn't need to worry about expand(), and vastly improves bash compatibility.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

+1 on doing globbing (I'll take care of it).
It looks like this problem can be simplified to five cases we need to be able to handle:

  1. foo (where ./foo is a directory, should be equivalent to foo/* [or foo/**/* if -r]).
  2. foo/*.bar
  3. foo/**/bar (where ./foo/<whatever>/bar is a directory, equivalent to foo/**/bar/*)
  4. foo/**/bar (where ./foo/<whatever>/bar is a file without an extension, equivalent to foo/**/bar)
  5. foo/**/bar/*.baz

Glob can handle 2, 4, 5, so we need to handle 1 and 3. I think the best way to do this is going to be to (pseudocode):

var output = [];
var results = glob(input);

for (var i = 0, len = results.length; i < len; ++i) {
    if (fs.statSync(results[i]).isDirectory()) {
        output.push(glob(results[i] + (options.recursive ? '/**/*' : '*')));    
    } else {
        output.push(results[i]);
    }
}
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nfischer

nfischer commented Feb 3, 2016

Copy link
Copy Markdown
Member

I think we should not handle cases 1 and 3 in common.expand(). The glob package works the way Bash would expand things at the command line. I think common.expand() should expand things just as the commandline would, and it should do that for every utility. Appending * to directory names is a pretty sloppy hack, and it's bound to cause us to deviate from Unix behavior sooner or later.

I'll write up a PR that puts a call to expand() inside common.wrap, and I'll take out extra expand() calls in the other utilities where possible. That way you can focus on swapping out the internals of common.expand() with glob.sync, and making sure we have compatibility.

Edit: I accidentally referred to common.extend() instead of common.expand() (and they're fairly different).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 3, 2016

Copy link
Copy Markdown
Contributor Author

@nfischer: Agreed. But don't submit the PR (I've already got 75% of it).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad ariporad closed this Feb 4, 2016
@ariporad ariporad reopened this Feb 4, 2016
@ariporad

ariporad commented Feb 4, 2016

Copy link
Copy Markdown
Contributor Author

Whoops, I didn't mean to close this. Nor post that last comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad

ariporad commented Feb 4, 2016

Copy link
Copy Markdown
Contributor Author

I'm going to demote this to v0.7.0, because we've got some kinks to work out.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad ariporad modified the milestones: v0.7.0, v0.6.0 Feb 4, 2016
This was referenced Feb 11, 2016
feat(glob): glob support for (almost) all commands #352
Merged
feat(glob): use glob module for globbing #359
Merged
@ariporad ariporad closed this in #359 Feb 16, 2016
@nfischer

nfischer commented Feb 16, 2016

Copy link
Copy Markdown
Member

Just for future reference, this was closed in favor of #359

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ariporad
ariporad deleted the fix/225 branch February 21, 2016 00:29
@ariporad
ariporad restored the fix/225 branch February 21, 2016 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@nfischer nfischer

Labels

fix Bug/defect, or a fix for such a problem

Projects

None yet

Milestone

v0.7.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@ariporad @TimothyGu @nfischer @boutell @arturadib @isaacs
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.