Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chosen not in npm? #1433

Closed
chenglou opened this issue Jul 31, 2013 · 25 comments
Closed

Chosen not in npm? #1433

chenglou opened this issue Jul 31, 2013 · 25 comments

Comments

@chenglou
Copy link

There's the package.json file, but npm returns no corresponding 'chosen' package.

@stof
Copy link
Collaborator

stof commented Jul 31, 2013

Currently, the package.json file is mainly meant to install the dev requirements of Chosen for developers.

As it is a library working only in the browser, not on the server side, does it make sense to have it on npm ? (this is a real question, I'm not a node.js developer at all but a PHP guy, so I don't know the npm conventions)

@chenglou
Copy link
Author

The main reason is to use Browserify so that in JS we can do var Chosen = require('Chosen'); instead of dropping script tag a bit everywhere. Server-side JS already uses the require format, browserify simply parses the requires (to simulate the nice module definition node.js got, but for front-end) and converts it into a big final build.js (with all the dependencies bundled) file to serve to index.html.

@andreypopp
Copy link

+1 on this issue — I use browserify and use chosen in my app but currently I have to put it in vendor directory which is really annoying

@cranesandcaff
Copy link

+1 on this as well. With Browserify it makes a lot of sense to be on NPM.

@ragulka
Copy link

ragulka commented Jun 30, 2014

+1 from me, too :) Also using browserify

@abdula
Copy link

abdula commented Jul 22, 2014

+1

3 similar comments
@cleer73
Copy link

cleer73 commented Jul 25, 2014

+1

@rhobot
Copy link

rhobot commented Aug 11, 2014

+1

@taylor-smith
Copy link

+1

@EdgarVaguencia
Copy link

If you need this plugin only can do $ and jQuery into global scope and later chosen = require(../path/chosen.min.js)

example:

 var $ = require('jquery');
 window.$ = $;
 window.jQuery = $;
 var chosen = require(./chosen.jquery.min.js)

and you can use in your code $('select').chosen();

Source: http://www.codefornow.com/2014/06/08/browserify-jquery-and-jquery-plugins/

@guigrpa
Copy link

guigrpa commented Oct 23, 2014

+1

1 similar comment
@fbaiodias
Copy link

+1

@skysteve
Copy link

+1 for browserify support please

@jamesplease
Copy link
Contributor

The fix here is pretty easy, I think.

  1. Add a UMD wrapper
  2. Add the built files to the repo
  3. Publish the built files to npm

If the chosen team is interested in such a PR, let me know and I'll put something together. The built files could also be put on Bower, and then there shouldn't be any problems with developers using Chosen.

@tjschuck
Copy link
Member

@jmeas

Add the built files to the repo

This is not going to happen. We used to do this, and it was a nightmare for the team. The compiled JS + CSS will not be added to the repo -- this has been discussed many times on the issue tracker.

Pre-compiled versions are provided via the releases page. If your package manager of choice supports specifying packages via ZIPs, you should use them. See the bower instructions for an example.

If your package manager of choice does not support ZIPs or using the GitHub releases API, you should open an issue with them to add support for this.

@jamesplease
Copy link
Contributor

Browserify users, you have two choices that I know of. The first is described above, but I'll summarize it once more:

Solution one: use Bower and the window

Follow the instructions in the README. Unfortunately, you cannot use npm, as far as I know, so set up bower in your project and install the zip. Add a module to your code with the following stuff:

var $ = require('jquery');

// Chosen requires this :(
window.jQuery = $;

require('path/to/bower_components/chosen_v1.3.0/chosen.jquery');

And it works! jQuery will, as you'd expect, be permanently modified, so you won't need to require chosen anywhere else in the app.

I recommend that you ensure that your linter throws an error if you try to access browser globals to ensure that you don't start referencing this window.jQuery anywhere else in your code.

Uninterested in bower and the window? I feel ya. A second option is to...

Solution two: wrap it yourself

My apps often have vendor directories for the handful of libraries that aren't packaged to handle module loaders. If you add this UMD wrapper around chosen, then you can require it in as usual. This wrapper will also work for AMD users.

Why not just use browserify-shim?

This is definitely an option. My app's tests run in Node+JSDom, so it needs to work without shimming or aliasing the libraries.

By the end of the week I hope to have a build of Chosen on npm and bower that is UMD wrapped, so folks can just install from there in the future w.o. any problems. I'll keep it up to date if you remind me, so if you're some future reader and my fork is out of date, just open an issue and I can cut a release.

@jamesplease jamesplease mentioned this issue Jan 30, 2015
@kadishmal
Copy link

👍 for native bower component. Would like to be able to import scss files directly.

@JustBlackBird
Copy link

+1 for adding Chosen package to npm.

@5ay3h
Copy link

5ay3h commented Oct 6, 2015

+9001 for adding Chosen package to npm.

@jamesplease
Copy link
Contributor

It seems like development on Chosen is at a slow point (for now, at least) and the maintainers don't seem interested in updating the environments that Chosen works in.

The best way forward would prob. be to just fork this project to add npm support (and, if you wanted, UMD support, too!). You could publish a new release on npm/Bower (maybe under modern-chosen?) then open a PR to upstream the changes.

If they merge it, great – you can deprecate your module. Otherwise people will start using your fork instead.

(I'm using "you" in the sense of "whomever," rather than any particular person :P )

@Shaazaam
Copy link

What is the difficulty is adding a package definition in the bower-chosen fork? Is it laziness or incompetency? At the very lease you can satisfy node users to a degree instead of hosing them completely.

@koenpunt
Copy link
Collaborator

What is the difficulty is adding a package definition in the bower-chosen fork? Is it laziness or incompetency? At the very lease you can satisfy node users to a degree instead of hosing them completely.

Such a thoughtful comment.. Remember that it's open source, and everybody is contributing in their free time. Besides that, every extra feature has to be maintained, which costs time. But sure, since there is the bower-chosen repo, a npm package shouldn't be far away.

@pfiller maybe we should rename bower-chosen to chosen-packaged (or something else that isn't related to a specific manager) and include a package.json in the repo.

@koenpunt
Copy link
Collaborator

I've setup a PR (#2550) which should take care of an npm package, please review is the example package attached to that PR is how this package should look like. Thanks!

@stof stof mentioned this issue Jun 21, 2016
@koenpunt
Copy link
Collaborator

#2550 is merged and Chosen is now also on NPM as chosen-js

@codeclown
Copy link

@koenpunt Thanks! Problem is the package contains built files, so can't import raw scss.

Related: #2347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests