You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by Don Coleman <do...@gmail.com> on 2013/07/03 00:53:33 UTC

using node modules in cordova plugins?

I ripped a bunch of Javascript code out of my Cordova NFC plugin and
created a NPM so I could reuse the code elsewhere.

Now, that the code is improved and tested, I'd like the plugin to use the
code from the node package.

Are there good ways to do this? Have you seen any examples?

https://github.com/don/phonegap-nfc
https://github.com/don/ndef-js

Re: using node modules in cordova plugins?

Posted by Andrew Grieve <ag...@chromium.org>.
Hmm, I think it would work if you checked in the node_modules and then put
the paths to the js files you want in your plugin.xml. Our require paths
for the modules a bit different though, and might not work well if you have
one npm module requiring another one.

Maybe a better option in this case would be to package your plugin's JS
into a single .js file and use that in your plugin.xml.


On Tue, Jul 2, 2013 at 6:53 PM, Don Coleman <do...@gmail.com> wrote:

> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> created a NPM so I could reuse the code elsewhere.
>
> Now, that the code is improved and tested, I'd like the plugin to use the
> code from the node package.
>
> Are there good ways to do this? Have you seen any examples?
>
> https://github.com/don/phonegap-nfc
> https://github.com/don/ndef-js
>

Re: using node modules in cordova plugins?

Posted by Don Coleman <do...@gmail.com>.
I have minimal dependencies, so I will try Andrew's suggestion of
pre-building a single js file.


On Wed, Jul 3, 2013 at 1:38 PM, Brian LeRoux <b...@brian.io> wrote:

> Having just explored Bower for Topcoat I can say w/ confidence its
> simply not ready for primetime as a package manager. You can't remove
> an entry from its registry yet! (That and, its slow.)
>
>
> On Wed, Jul 3, 2013 at 10:25 AM, Andrew Grieve <ag...@chromium.org>
> wrote:
> > Using Bower instead of npm might be another route to explore. Either way
> I
> > think pre-building your js is the best option
> >
> >
> > On Wed, Jul 3, 2013 at 11:15 AM, Don Coleman <do...@gmail.com>
> wrote:
> >
> >> The code runs on a phone. https://github.com/don/phonegap-nfc
> >>
> >> I've moved some of the javascript from my cordova plugin into a node
> module
> >> so I could re-use it in other projects. I haven't integrated the node
> >> module back into the plugin *yet*.
> >>
> >> I'm hoping I can do this without making the plugin more difficult to
> >> install.
> >>
> >>
> >>
> >> On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:
> >>
> >> > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
> >> wrote:
> >> >
> >> >> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> >> >> created a NPM so I could reuse the code elsewhere.
> >> >>
> >> >
> >> > Is this something that runs on a phone? Does this mean you're running
> >> your
> >> > node module through browserify first?
> >> >
> >> > - Bryan
> >> > http://heybryan.org/
> >> > 1 512 203 0507
> >>
>

Re: using node modules in cordova plugins?

Posted by Brian LeRoux <b...@brian.io>.
Having just explored Bower for Topcoat I can say w/ confidence its
simply not ready for primetime as a package manager. You can't remove
an entry from its registry yet! (That and, its slow.)


On Wed, Jul 3, 2013 at 10:25 AM, Andrew Grieve <ag...@chromium.org> wrote:
> Using Bower instead of npm might be another route to explore. Either way I
> think pre-building your js is the best option
>
>
> On Wed, Jul 3, 2013 at 11:15 AM, Don Coleman <do...@gmail.com> wrote:
>
>> The code runs on a phone. https://github.com/don/phonegap-nfc
>>
>> I've moved some of the javascript from my cordova plugin into a node module
>> so I could re-use it in other projects. I haven't integrated the node
>> module back into the plugin *yet*.
>>
>> I'm hoping I can do this without making the plugin more difficult to
>> install.
>>
>>
>>
>> On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:
>>
>> > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
>> wrote:
>> >
>> >> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
>> >> created a NPM so I could reuse the code elsewhere.
>> >>
>> >
>> > Is this something that runs on a phone? Does this mean you're running
>> your
>> > node module through browserify first?
>> >
>> > - Bryan
>> > http://heybryan.org/
>> > 1 512 203 0507
>>

Re: using node modules in cordova plugins?

Posted by Andrew Grieve <ag...@chromium.org>.
Using Bower instead of npm might be another route to explore. Either way I
think pre-building your js is the best option


On Wed, Jul 3, 2013 at 11:15 AM, Don Coleman <do...@gmail.com> wrote:

> The code runs on a phone. https://github.com/don/phonegap-nfc
>
> I've moved some of the javascript from my cordova plugin into a node module
> so I could re-use it in other projects. I haven't integrated the node
> module back into the plugin *yet*.
>
> I'm hoping I can do this without making the plugin more difficult to
> install.
>
>
>
> On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:
>
> > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
> wrote:
> >
> >> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> >> created a NPM so I could reuse the code elsewhere.
> >>
> >
> > Is this something that runs on a phone? Does this mean you're running
> your
> > node module through browserify first?
> >
> > - Bryan
> > http://heybryan.org/
> > 1 512 203 0507
>

Re: using node modules in cordova plugins?

Posted by Don Coleman <do...@gmail.com>.
The code runs on a phone. https://github.com/don/phonegap-nfc

I've moved some of the javascript from my cordova plugin into a node module
so I could re-use it in other projects. I haven't integrated the node
module back into the plugin *yet*.

I'm hoping I can do this without making the plugin more difficult to
install.



On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:

> On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com> wrote:
>
>> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
>> created a NPM so I could reuse the code elsewhere.
>>
>
> Is this something that runs on a phone? Does this mean you're running your
> node module through browserify first?
>
> - Bryan
> http://heybryan.org/
> 1 512 203 0507

Re: using node modules in cordova plugins?

Posted by Michal Mocny <mm...@chromium.org>.
Sure, I was just commenting on its need for this case.


On Wed, Jul 3, 2013 at 10:51 AM, Anis KADRI <an...@gmail.com> wrote:

> I am not saying it's a good idea only for this reason. There could be other
> reasons. There are (or will be) cases where a plugin might require some
> some sort of build phase or additional steps that are not supported by the
> plugman specs out of the box. Besides npm supports it [1] so why not
> plugman ?
>
> [1] https://npmjs.org/doc/scripts.html
>
>
> On Wed, Jul 3, 2013 at 10:42 AM, Michal Mocny <mm...@chromium.org> wrote:
>
> > Andrew and I had that conversation as few days ago, and he convinced me
> > that shipping code to end users should mean shipping with node_modules
> > (this sentiment is repeated from the creators of npm it seems).  That
> way,
> > any given users' node setup/platform version issues don't affect your
> code.
> >  Thus, I don't think npm install as a hook for plugman for install time
> is
> > necessary, not a good idea (at least not for this reason).
> >
> > -Michal
> >
> >
> > On Wed, Jul 3, 2013 at 10:31 AM, Anis KADRI <an...@gmail.com>
> wrote:
> >
> > > You could also ship your plugin as a node package (with a package.json
> > and
> > > node_modules) and point your js paths to node_modules/ (just as +andrew
> > > said). Maybe plugman should also support before_ and after_ hooks as
> well
> > > in order to run "npm install" ?
> > >
> > >
> > > On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com>
> wrote:
> > >
> > > > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
> > > wrote:
> > > >
> > > > > I ripped a bunch of Javascript code out of my Cordova NFC plugin
> and
> > > > > created a NPM so I could reuse the code elsewhere.
> > > > >
> > > >
> > > > Is this something that runs on a phone? Does this mean you're running
> > > your
> > > > node module through browserify first?
> > > >
> > > > - Bryan
> > > > http://heybryan.org/
> > > > 1 512 203 0507
> > > >
> > >
> >
>

Re: using node modules in cordova plugins?

Posted by Anis KADRI <an...@gmail.com>.
I am not saying it's a good idea only for this reason. There could be other
reasons. There are (or will be) cases where a plugin might require some
some sort of build phase or additional steps that are not supported by the
plugman specs out of the box. Besides npm supports it [1] so why not
plugman ?

[1] https://npmjs.org/doc/scripts.html


On Wed, Jul 3, 2013 at 10:42 AM, Michal Mocny <mm...@chromium.org> wrote:

> Andrew and I had that conversation as few days ago, and he convinced me
> that shipping code to end users should mean shipping with node_modules
> (this sentiment is repeated from the creators of npm it seems).  That way,
> any given users' node setup/platform version issues don't affect your code.
>  Thus, I don't think npm install as a hook for plugman for install time is
> necessary, not a good idea (at least not for this reason).
>
> -Michal
>
>
> On Wed, Jul 3, 2013 at 10:31 AM, Anis KADRI <an...@gmail.com> wrote:
>
> > You could also ship your plugin as a node package (with a package.json
> and
> > node_modules) and point your js paths to node_modules/ (just as +andrew
> > said). Maybe plugman should also support before_ and after_ hooks as well
> > in order to run "npm install" ?
> >
> >
> > On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:
> >
> > > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
> > wrote:
> > >
> > > > I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> > > > created a NPM so I could reuse the code elsewhere.
> > > >
> > >
> > > Is this something that runs on a phone? Does this mean you're running
> > your
> > > node module through browserify first?
> > >
> > > - Bryan
> > > http://heybryan.org/
> > > 1 512 203 0507
> > >
> >
>

Re: using node modules in cordova plugins?

Posted by Michal Mocny <mm...@chromium.org>.
Andrew and I had that conversation as few days ago, and he convinced me
that shipping code to end users should mean shipping with node_modules
(this sentiment is repeated from the creators of npm it seems).  That way,
any given users' node setup/platform version issues don't affect your code.
 Thus, I don't think npm install as a hook for plugman for install time is
necessary, not a good idea (at least not for this reason).

-Michal


On Wed, Jul 3, 2013 at 10:31 AM, Anis KADRI <an...@gmail.com> wrote:

> You could also ship your plugin as a node package (with a package.json and
> node_modules) and point your js paths to node_modules/ (just as +andrew
> said). Maybe plugman should also support before_ and after_ hooks as well
> in order to run "npm install" ?
>
>
> On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:
>
> > On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com>
> wrote:
> >
> > > I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> > > created a NPM so I could reuse the code elsewhere.
> > >
> >
> > Is this something that runs on a phone? Does this mean you're running
> your
> > node module through browserify first?
> >
> > - Bryan
> > http://heybryan.org/
> > 1 512 203 0507
> >
>

Re: using node modules in cordova plugins?

Posted by Anis KADRI <an...@gmail.com>.
You could also ship your plugin as a node package (with a package.json and
node_modules) and point your js paths to node_modules/ (just as +andrew
said). Maybe plugman should also support before_ and after_ hooks as well
in order to run "npm install" ?


On Wed, Jul 3, 2013 at 9:59 AM, Bryan Bishop <ka...@gmail.com> wrote:

> On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com> wrote:
>
> > I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> > created a NPM so I could reuse the code elsewhere.
> >
>
> Is this something that runs on a phone? Does this mean you're running your
> node module through browserify first?
>
> - Bryan
> http://heybryan.org/
> 1 512 203 0507
>

Re: using node modules in cordova plugins?

Posted by Bryan Bishop <ka...@gmail.com>.
On Tue, Jul 2, 2013 at 5:53 PM, Don Coleman <do...@gmail.com> wrote:

> I ripped a bunch of Javascript code out of my Cordova NFC plugin and
> created a NPM so I could reuse the code elsewhere.
>

Is this something that runs on a phone? Does this mean you're running your
node module through browserify first?

- Bryan
http://heybryan.org/
1 512 203 0507