Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Ins-and-Outs of Publishing a Module to npm

Steve Kinney
July 30, 2016
120

The Ins-and-Outs of Publishing a Module to npm

Steve Kinney

July 30, 2016
Tweet

Transcript

  1. I'm Steve.
    @stevekinney

    View full-size slide

  2. I'm Steve.
    @stevekinney

    View full-size slide

  3. http://turing.io

    View full-size slide

  4. http://bit.ly/electronjs

    View full-size slide

  5. Once upon a time…

    View full-size slide

  6. “How did you get
    permission to publish
    a module on npm?”

    View full-size slide

  7. >250,000

    registered users

    View full-size slide

  8. ~4.5 million

    estimated users

    View full-size slide

  9. ~84,000

    have ever published a module

    View full-size slide

  10. Let's make a little module
    for working with rectangles.

    View full-size slide

  11. Option A: Scoped modules.

    View full-size slide

  12. @stevekinney/rectangle

    View full-size slide

  13. Option B: Get creative.

    View full-size slide

  14. All you have to do is make
    yourself a package.json.

    View full-size slide

  15. “Steve, JSON is tedious.
    I'm afraid.”

    View full-size slide

  16. Fair enough.

    View full-size slide

  17. Do I seriously have to type my
    name in every single time?

    View full-size slide

  18. But, I really don't want to
    have to go get the URL for
    my Git repository.

    View full-size slide

  19. Good news! You don't
    have to, necessarily.

    View full-size slide

  20. “I'm going to be honest
    with you, Steve. I just
    keep hitting enter—can I
    just skip all of this?”

    View full-size slide

  21. Remember: This code is
    going to be used by other
    people. Write tests,
    please.

    View full-size slide

  22. Remember: This code is
    going to be used by other
    people. Write tests,
    please.

    View full-size slide

  23. What if we wanted to get fancy?

    View full-size slide

  24. Cool story, but the boss
    comes in and reminds
    you that Node 0.10 is a
    thing.

    View full-size slide

  25. It's totally cool to write a
    module in your favorite
    language.
    But, you should publish it for
    the widest possible audience.

    View full-size slide

  26. You’re never going to
    remember to do this.

    View full-size slide

  27. npm run build

    View full-size slide

  28. You’ll probably
    forget to do this too.

    View full-size slide

  29. publish test
    start
    install

    View full-size slide

  30. publish test
    start
    install
    prepublish
    postinstall
    preinstall
    poststart
    prestart
    posttest
    prestest

    View full-size slide

  31. npm run sandwich

    View full-size slide

  32. npm run sandwich
    presandwich

    View full-size slide

  33. npm run sandwich
    presandwich
    postsandwich

    View full-size slide

  34. Problem: We want to commit our fancy
    ES6 code to git, but we don't need to ship
    it with our module.

    View full-size slide

  35. Don't forget to
    include a README.

    View full-size slide

  36. 1.0.1
    npm version patch

    View full-size slide

  37. 1.1.0
    npm version minor

    View full-size slide

  38. 2.0.0
    npm version major

    View full-size slide

  39. http://turing.io http://bit.ly/electronjs

    View full-size slide