Skip to content

Packaging - Refactor package plugin logic #6007

Closed

Description

@pmuens

The package plugin logic is rather complicated which resulted in a lot of of uncertainty about enhancements and regressions in the past.

We should investigate how we can refactor the code so that it's more reliable and more easily extensible.

Related to #5938

/cc @ganeshvlrk @billfine @eahefnawy @dschep

Activity

  1. changed the title [-]Packagin - Refactor package plugin logic[/-] [+]Packaging - Refactor package plugin logic[/+] on Apr 8, 2019
  2. ryan-roemer commented on Aug 9, 2019

    @ryan-roemer
    Contributor

    Hi folks!

    Not sure if you're looking for opinions or suggestions from the community, but there are a few things I'd love to be discussed for a potential refactor for packaging.

    Background

    I'm part of the team that wrote the serverless-jetpack packaging plugin. The two main observations we'd had in analyzing a lot of serverless package-ing are:

    • Reading files from disk is super slow. (Serverless currently reads from disk to find devDependencies to exclude in node_modules via sync globby() calls and then reads files again for ** + service/function-level package.includes).
    • A lot of those files read from disk are then later excluded during the nanomatch() phase (where package.exclude is used and then package.include again).

    The Jetpack plugin speeds things up in typical cases by:

    1. Excluding all of node_modules
    2. Using a much-faster, async little library (inspectdep) to infer only the production dependencies.
    3. patching the include logic to basically insert prod dep patterns before package.include in the globby() and nanomatch() phases.

    The Jetpack plugin is drop-in compatible and typically, much faster than built-in packaging, but even then we're finding that creating the fastest possible build is hitting limitations from maintaining compatibility with built-in serverless package that I'd love to see re-considered:

    Suggestions

    1. Remove the starting ** glob when doing the first phase globby() matching. While certainly easier for projects that want to include "everything" it ends up making things harder (moreso for Jetpack) that want to just cherry-pick specific stuff right from the start and especially mono-repos.
      1. Jetpack has a harder case because we insert custom patterns before package.include for prod dependencies. After a lot of wrangling, we introduced a custom.jetpack.preInclude option that allows folks to insert stuff like: ** + custom.jetpack.preInclude + dynamic prod dependencies + built-in package.include to get the true flexibility we need.
    2. Remove or refactor package.exclude to have it such that one (or even multiple) set(s) of patterns apply for the globby() phase and consider just removing the later nanomatch() phase entirely. Reading from disk is just so expensive, that I think we could just give a little more flexibility and education around packaging patterns to allow folks to craft a set of patterns that just include what you need (with positive and negative ones).

    The motivation for putting these two things together is best illustrated in a private project I just helped with today: We recently had a project using Jetpack that had something simple like - exclude: ["**"] with lots of stuff brought back in via package.include -- this produced a package that excluded 17,000 files in the nanomatch() phase and took ~250 secs. Changing this to use the bespoke jetpack.custom.preInclude: ["!**"] (effectively starting with nothing in the globby()) phase) and not using package.exclude at all produced the same package with 0 files excluded in nanomatch() phase and taking only ~25 seconds.

    ... So that's a long-winded massive comment, but hopefully opens some points for consideration if the project is considering "all options" when approaching packaging. Keep up the great work and ❤️ all of the cool stuff that keeps coming out from the team!

  3. medikoo commented on Apr 27, 2020

    @medikoo
    Contributor

    @ryan-roemer great thanks for this write up! It's very valuable, and we'll definitely take all the points into account when refactoring our packaging logic.

    I will close this issue, as it appears as duplicate (I was unaware) of #6580 and we handle all discussion and link all related issues over there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions