Skip to content

Use Globs to Exclude Files - #2194

Merged
pmuens merged 13 commits into
serverless:masterfrom
craftship:globs-exclude
Oct 3, 2016
Merged

pmuens merged 13 commits into
serverless:masterfrom
craftship:globs-exclude

Conversation

@jonsharratt

@jonsharratt jonsharratt commented Sep 23, 2016 •

Copy link
Copy Markdown
Contributor

What did you implement:

_Implementing Issue:_ #2071

How did you implement it:

  • Added globs as a dependency of project
  • Updated to use globs for exclude
  • Update specs to test relevant changes

How can we verify it:

Add folder src to a project then use example config to verify they are not included. Other glob patterns can be tested.

Example config:

package:
  exclude:
    - "src/**"
    - "test/**"
    - "**/spec.js"

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config/commands/resources
  • Leave a comment that this is ready for review once you've finished the implementation

@jonsharratt

Copy link
Copy Markdown
Contributor Author

Ready for review 🚀

@demetriusnunes

Copy link
Copy Markdown

Awesome! Please merge this!

Comment thread lib/plugins/package/lib/zipService.js Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Happy to see this line gone, I timed it and it was taking about 400ms just to test every file in node_modules. Hopefully globe isn't as slow.

@tolbahadi

Copy link
Copy Markdown

Love this change. It will make deployment much faster, especially for people who exclude most of the root directories in their project, like if you have an src directory or built directory if you compile code using typescript or bable and want to ignore all other directories.

@pmuens pmuens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jonsharratt Thank you very much for this really great addition!

Tested it today and it works great! Way better than the old approach.

Could you look through the codebase and remove all those include references? There are e.g. some in the docs and some in the serverless.yml template files.

Thanks in advance and good job! 👍

Comment thread lib/plugins/package/README.md Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you change the file extension to .yml as this is the one which is used throughout the whole docs. Thanks!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@flomotlik do we even need this documentation as everything is moved in the docs directory? Feels like this a legacy doc which should be removed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you want me to delete this file, in the mean time I have reworded as per your feedback 👯

@pmuens pmuens added this to the v1.0-ideas milestone Sep 30, 2016
@jonsharratt

Copy link
Copy Markdown
Contributor Author

Should be all cleaned up and ready to go, thanks for the comments and feedback.

Ready for another look over and cheeky review 🚀

@pmuens

pmuens commented Sep 30, 2016 •

Copy link
Copy Markdown
Contributor

😂

Awesome! Thank you very much @jonsharratt 💯 👍

There's just one other location where I think we might can get rid of the include:
In classes/Service.js we say that.service.include = serverlessFile.package.include. Can we remove that as it's not considered anymore?

EDIT: Just found another minor one in tests/classes/Serverless.js on line 154.

@jonsharratt

Copy link
Copy Markdown
Contributor Author

Great spot! 👍

Ready for another review 🚀

@pmuens

pmuens commented Oct 3, 2016

Copy link
Copy Markdown
Contributor

@jonsharratt thanks for updating the PR and removing the final includes traces.

Great overall enhancement. Thanks for that 💃 🎉

@pmuens
pmuens merged commit 9ebf296 into serverless:master Oct 3, 2016
@jonsharratt
jonsharratt deleted the globs-exclude branch October 4, 2016 14:09
@demetriusnunes

Copy link
Copy Markdown

This was an awesome change, but I think removing the include might have been a mistake.
I have project where I package each function individually. I have 7 of them. So now, I have to the usual root exclusions and then 6 specific exclusions for all function directories, except the one being packaged. If I could exclude everything from the root and then include only the function directory would be much better. This is a very common use-case.

@demetriusnunes

Copy link
Copy Markdown

Also, not following symlinks breaks packages installed with "npm link"

@tolbahadi

Copy link
Copy Markdown

@demetriusnunes you can use the negate symbol ! to exclude everything except the function you're packaging instead of manually excluding individual directories.

  package:
    exclude:
      - !shared/**
  functions:
    hello:
      package:
        exclude: 
          - !src/hello/handler.js

@demetriusnunes

Copy link
Copy Markdown

I tried that, doesn't work. I think negation is deprecated.

ignore: exclude,
dot: true,
silent: true,
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

please include: follow: true, here

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It might actually be better to bring back the include option as you suggested and do:

glob.sync(include && include.length ? include || '**', {
        cwd: servicePath,
        ignore: exclude,
        dot: true,
        silent: true,
        follow: true,
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will take a look at this and amend accordingly if we wish to have the include option back, just drop a note on here to confirm and I will look to implement :)

@pmuens

pmuens commented Oct 4, 2016 •

Copy link
Copy Markdown
Contributor

Hey guys thank you for the valuable feedback!
Yes, bringing include back might be a good idea to get more flexibility here (and also the simlink support).

Could we open up a separate issue and a separate PR for that so that's it's easier to keep track? Thanks in advance!

@pmontrasio

pmontrasio commented Oct 12, 2016 •

Copy link
Copy Markdown

A glob on files in the current directory doesn't work

exclude:
- "*~"

The ~ files (emacs backups) get into the zip. I tried also with "**~", same thing.
BTW, without double quotes I get a YAML error `unidentified alias "~"``

I have to do this instead

exclude
- "handler.js~"
- "secrets.json~"

which doesn't scale well to many files.

$ serverless -v
1.0.0-rc.2

It would be nice if exclude would work like .gitignore.

Alternatively, exclude everything and force people to explicitly include files. Better at preventing accidental deployment of confidential information, but occasional problems when one forgets to update the whitelist.

@tolbahadi

Copy link
Copy Markdown

I dont think this change is available in 1.0.0-rc.2

@pmuens

pmuens commented Oct 12, 2016

Copy link
Copy Markdown
Contributor

Thanks for getting back!

@jonsharratt opened up a PR which replaces the glob package. It will also introduce the possibility to include files again (which was previously removed)

#2266

@asantibanez

Copy link
Copy Markdown

Hi! The include/ options was totally worth it. I used it to include shared libs and when packaging individually, i used it to include only the function i wanted.

It was really easy to understand also. Serverless would exclude all, and then include all. With globs, I haven't tested it out but this is a new concept for me. I have to know globs now. :(

@asantibanez

Copy link
Copy Markdown

@demetriusnunes the ! pattern seems to have been replaced by ignore. But I still think the include option was better.

@mthenw mthenw mentioned this pull request Oct 19, 2016
@mankins

mankins commented Oct 25, 2016

Copy link
Copy Markdown
Contributor

It's not clear what "include" was replaced with. It looks to have been stripped from the code but the residual documentation seems to still say it works. Am I understanding correctly that by default everything in the servicePath (the root service directory?) is included by default and only exclusions are excluded?

Consequently, If we wanted to include files from different locations we'd need to copy them to the servicePath?

@pmuens

pmuens commented Nov 17, 2016 •

Copy link
Copy Markdown
Contributor

Hey guys!

Just a quick update on this: We brought back include which is now also driven by globs (#2681). Will be released in the next couple of days.

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

Successfully merging this pull request may close these issues.

7 participants