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

Creating JavaScript modules

Creating JavaScript modules

Presentation given at Sthlm.js June 18, 2014

Jakob Mattsson

June 18, 2014

More Decks by Jakob Mattsson

Other Decks in Programming


  1. FishBrain is the fastest, easiest way to log and share

    your fishing. ! Get instant updates from anglers on nearby lakes, rivers, and the coast.
  2. baxter bucketful bucketful-loopia buffet-brunch cellsynt chalcogen commonjs-jquery confirm connect-rewrite dinode

    express-jit-coffee fn ftp-replace iota.js jakobmattsson-client-cookies jakobmattsson-cucumber jakobmattsson-serenade jakobmattsson-swfobject jscov json-request jsonrpc-http jsonrpc-http-browser-client jsonrpc-http-client-browserify jsonrpc-http-client-node jsonrpc-http-server locke locke-api locke-client locke-client-jsonrpc locke-consumer locke-store-mem locke-store-mongo locke-store-test loopia-api manikin manikin-mem manikin-mongodb manikin-tools mocha-http mocha-term-cov-reporter mongocmd nameify node-auther opra opra-compiler path-router path-router-decorator piescore plusone-mongohq plusone-nodejitsu powerfs rester rester-tools runr selenian trester underscore.plus viaduct-client viaduct-server wd-tools z-builtins z-core z-std-pack z-underscore zee Author of some modules
  3. Your tools do You can use npm in the browser

    ”But I’m a fronted dev!” ”I don’t care for Node.js!”
  4. #1

  5. #1

  6. package.json { "name": "z-core", "version": "0.6.0" } Then run ”npm

    publish” and you’re done. Collect fame and fortune.
  7. { "name": "z-core", "version": "0.6.0", "description": "Utility library for JavaScript

    promises", "keywords": [ "promises", "util", "functional" ], "author": "Jakob Mattsson <[email protected]> (jakobm.com)", "license": "MIT", "main": "./lib/index.js", "repository": { "type": "git", "url": "http://github.com/jakobmattsson/z-core" }, "bugs": ”http://github.com/jakobmattsson/z-core/issues", "private": false,
  8. "files": [ "lib", "LICENSE" ], "engines": { "npm": ">= 1.3

    < 2", "node": ">= 0.10 <= 0.11" }, "devDependencies": { "mocha": "^1.18.0", "coffee-script": "^1.7.1" }, "dependencies": { "underscore": "*" }, "optionalDependencies": { "es6-promise": "^0.1.1" } } Files to be included Where does it work? Required to build/ test/etc Required to use Not required, but nice to have
  9. Scripts "scripts": { "test": "mocha tests/*.js", "run": "node lib/server.js", "publish":

    "...", "install": "...", "stop": "...", "restart": ”...", ! "prepublish": ”...", "postpublish": ”..." }
  10. #2

  11. Given a version number MAJOR.MINOR.PATCH, increment the: ! MAJOR version

    when you make incompatible API changes ! MINOR version when you add functionality in a backwards- compatible manner. ! PATCH version when you make backwards-compatible bug fixes. ! Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format. Summary
  12. Note Software using Semantic Versioning MUST declare a public API.

    ! This API could be declared in the code itself or exist strictly in documentation. However it is done, it should be precise and comprehensive.
  13. Note Major version zero (0.y.z) is for initial development. !

    Anything may change at any time. The public API should not be considered stable.
  14. Note Once a versioned package has been released, the contents

    of that version MUST NOT be modified. ! Any modifications MUST be released as a new version.
  15. IRL Things change, break, disappear and rules are bent. !

    People can’t be controlled. This is open source. ! And there are crazy rebels out there…
  16. Why? Bug fixes won’t propagate ! Features take longer to

    reach developers ! Tons of ”version bump” commits
  17. Keep up-to-date npmedge $ npmedge es6-promise has 1.0.0, but ^0.1.1

    is specified jsontool has 7.0.2, but 7.0.1 is specified jscov has 0.6.14, but ^0.5.7 is specified chai-as-promised has 4.1.1, but ^3.3.1 is specified
  18. So… Use semver when versioning your module ! Mind it

    when you depend on something ! Use shrinkwrap and npmedge
  19. #3

  20. #4

  21. So: Test all browsers in CI - not manually !

    Don’t publish by hand ! Travis + Sauce Labs = *drewl*
  22. #5

  23. Instrumentation Mocha recommends JSCoverage ! It does the job, but

    is a little messy ! I implemented a drop-replacement: jscov
  24. mocha chai sinon selenium sauce labs browserify bucketful chalcogen jscov

    mocha-term-cov-reporter npmedge coveralls travis ci jsontool