Trevor and Daniel, thanks for your reply.
How would you structure the code that is to be shared? Should it be a
separate NPM package, referenced from the extension package.json via git
url, and have a small file in the extension's lib/ dir with a oneliner -
"require('...')" that browserify could pick up? And have a script
command
in package.json to build that file?
There are many implementations of URL parsing - from mw.Url to
require('url'). They differ slightly, but that is not the main problem -
how should the shared code use the right one? Should they be passed as
functional function params? Should there be some "lib init" that sets lib's
global functions?
On Fri, Dec 18, 2015 at 8:22 PM, Daniel Friesen <daniel(a)nadir-seen-fire.com>
wrote:
On 2015-12-18 8:41 AM, Trevor Parscal wrote:
Be careful when doing this with NPM modules, as
their contents are
subject
to change, and only their index file is
configured and trying to
automatically know the paths and inclusion order is more of a mad science
than an art. Your best bet would be hard-coding and using very specific
versions in your package.json to protect from unexpected changes dues to
subtle NPM module version differences.
npm modules are modules, not scripts. Even
if you knew their execution
order you can't just "include" them in any order at all.
Using browserify to build a standalone script with a UMD that exposes a
global might be the best bet.
Though you'll have to be wary of requiring a module that pulls in a
bunch of dependencies.
As for needing some $.extend, URL parsing and
reconstructing, and
logging.
I'm assuming you mean taking client code to
the server where jQuery and
common browser functionally might not be present. There are many NPM
modules that provide shims for these things, including full-on
server-side
jQuery. Usually the differences are subtle if
any. Members of the Paraoid
team are very familiar with this space and are probably good people to
talk
to about this.
URL - Built in to node.
Browserify comes with a browser compatible
version of the module for when you require('url') it.
extend:
- lodash.merge (as part of lodash or the dedicated 'lodash.merge' module)
- Some people use xtend or extend
- There is also a new native Object.assign built into ES6, which you
could include a simple polyfill for
Logging varies very much by what you need. So there's wilson, debug, and
a bunch of others.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [
http://danielfriesen.name/]
_______________________________________________
Wikitech-l mailing list
Wikitech-l(a)lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l