Slide 1

Slide 1 text

@knolleary Managing multiple npm modules in a single repo Nick O’Leary Node-RED Project Lead IBM Open Source Developer OpenJS Foundation CPC Member

Slide 2

Slide 2 text

@knolleary How we tore apart the internals of Node-RED and glued it back together without users knowing

Slide 3

Slide 3 text

@knolleary What is Node-RED? Many applications we build today, from Integration to IoT, often require pulling together different APIs, online services and hardware devices in new and interesting ways. Time spent figuring out how to access a Serial port, or to complete an OAuth flow against Twitter is not time spent on creating the real value of a solution. We need tools that make it easier for developers at all levels to create applications and allow them to focus on what is important.

Slide 4

Slide 4 text

@knolleary What is Node-RED? The Node-RED editor runs in a browser and allows you to create applications by drawing flows of events. Each node in a flow represents a well-defined piece of functionality, such as updating a value, making a database query or sending a tweet. The developer configures each node as required, focused on what it does, not how it does it. When the flow is deployed to the Node-RED runtime, each node becomes a running piece of code and messages start passing through the flow. “Flow-based programming for event-driven applications”

Slide 5

Slide 5 text

@knolleary

Slide 6

Slide 6 text

@knolleary node-red node.js based runtime browser based editor core nodes

Slide 7

Slide 7 text

@knolleary

Slide 8

Slide 8 text

@knolleary node-red runtime editor HTTP Admin API @node-red/editor-api Client-side Editor @node-red/editor-client Flow Runtime @node-red/runtime Node Registry @node-red/registry Common Utils @node-red/util core nodes Core Nodes @node-red/nodes

Slide 9

Slide 9 text

@knolleary Goals Be maintainable Not require lots of extra tooling Keep it all in one repository

Slide 10

Slide 10 text

@knolleary

Slide 11

Slide 11 text

@knolleary Git Submodules

Slide 12

Slide 12 text

@knolleary

Slide 13

Slide 13 text

@knolleary Roll Our Own

Slide 14

Slide 14 text

@knolleary

Slide 15

Slide 15 text

@knolleary

Slide 16

Slide 16 text

@knolleary

Slide 17

Slide 17 text

@knolleary

Slide 18

Slide 18 text

@knolleary All dependencies, both production and development, are declared in the top- level package.json. Each module has its own package.json that lists only its own production dependencies. At development time, npm install is only run at the top level.

Slide 19

Slide 19 text

@knolleary A list of five things to talk about 1. Managing Tests 2. Don’t ignore node_modules 3. Managing package versions 4. Managing dependencies 5. Building a release

Slide 20

Slide 20 text

@knolleary Managing tests

Slide 21

Slide 21 text

@knolleary Managing tests

Slide 22

Slide 22 text

@knolleary Managing tests

Slide 23

Slide 23 text

@knolleary Managing tests Using same node_modules-in-the-tree trick, we introduced nr-test-utils module that can be used by test files to access files in the main src tree. No point publishing as a standalone module as it is inherently tied to the code layout of the repository.

Slide 24

Slide 24 text

@knolleary

Slide 25

Slide 25 text

@knolleary Managing tests

Slide 26

Slide 26 text

@knolleary Don’t ignore node_modules Don’t put node_modules under version control. Unless it’s the node_modules you want to put under version control.

Slide 27

Slide 27 text

@knolleary Don’t ignore node_modules – GitHub edition GitHub will not show commit diffs for any files under node_modules. Unless you ask it nicely - but even then, only on the Desktop view.

Slide 28

Slide 28 text

@knolleary Managing package versions Script added to set version of all modules – keeping them in sync. Includes updating any references in the dependencies section of each package.json

Slide 29

Slide 29 text

@knolleary Managing dependencies When running locally, dependencies are installed from top-level package.json. Risk that the individual module dependency versions will get out of sync.

Slide 30

Slide 30 text

@knolleary Managing dependencies Script added to validate all dependencies. Added to the build so travis catches it when we don’t Two remaining issues: 1. doesn’t check optionalDeps 2. doesn’t catch if we forget to add a brand new dependency

Slide 31

Slide 31 text

@knolleary Building a release Existing grunt task for building a release was updated to build a tgz for each module. They can be tested and manually published to npm Really should write a script to do the publishing – ensuring the right tag is used if it’s a beta release.

Slide 32

Slide 32 text

@knolleary What’s next? Automate a few more chores around dependency checking and npm publishing

Slide 33

Slide 33 text

@knolleary What’s next? Forget about package management and get on developing Node-RED

Slide 34

Slide 34 text

@knolleary

Slide 35

Slide 35 text

@knolleary Credits Nolan Lawson – Why we dropped Lerna from PouchDB https://gist.github.com/nolanlawson/457cdb309c9ec5b39f0d420266a9faa4 “alle – monorepo publishing” https://github.com/boennemann/alle

Slide 36

Slide 36 text

@knolleary Managing multiple npm modules in a single repo Nick O’Leary Node-RED Project Lead IBM Open Source Developer http://nodered.org