Giter Club home page Giter Club logo

debowerify's Introduction

debowerify

A browserify transform to enable the easy use of bower components in browserify client javascript projects.

This can be used in conjunction with deamdify to require AMD components from bower as well.

NB: For more information about how to use debowerify to create stand-alone library bundles check out bower-resolve and the examples in the README.

build status

Installation

Installation is via npm:

$ npm install debowerify

How to use.

Install some bower components:

# creates files in components/screenfull/
$ bower install screenfull

Require the bower file by it's bower identifier (ie. in this case "screenfull"):

// public/scripts/app.js
var _screenfull = require('screenfull'); // the bower component
var domready = require('domready'); // a regular browserify npm component

domready(function () {
  var button = document.getElementById('fullscreen');
  button.addEventListener('click', function (evt) {
    // screenfull adds itself to window.screenfull - but we can get to it
    if (screenfull.enabled) {
      screenfull.toggle(this);
    }
  });
});

Build out your browserify bundle using the debowerify transform:

$ browserify -t debowerify  public/scripts/app.js -o public/scripts/build/bundle.js

Then include your bundle.js in your HTML file and you're done!

Options

preferNPM

Set preferNPM option to true, or an array of module names, to have debowerify prefer NPM modules over bower components. This is useful for when you have a module that is installed both as a node module and as a bower component.

How to use with AMD components

If your bower components are amd and they don't support commonjs modules than simply use debowerify with the excellent deamdify browserify transform. For example, the following AMD bower import:

# creates files in components/myamdcomponent/
$ bower install myamdcomponent
// public/scripts/amdapp.js
var myamdcomponent = require('myamdcomponent'); // the AMD bower component
var domready = require('domready'); // a regular browserify npm component

domready(function () {
  // call the amd component
  myamdcomponent.doStuff();
});

To make this all magically work and use the short-form bower name of "amdcomponent" chain both debowerify and deamdify together like this:

$ browserify -t debowerify -t deamdify public/scripts/amdapp.js -o public/scripts/build/bundle.js

Too easy!

Notes

The transform depends on the "main" entry in bower.json to be correct.

Some bower components may not have this set, or have it set incorrectly. In this case, either manually update the bower.json file yourself, of just do a require to the relevant full path of the bower javascript file - and then complain to the bower component repo owner! :-)

Contributing

debowerify is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the CONTRIBUTING.md file for more details.

Contributors

debowerify is only possible due to the excellent work of the following contributors:

Eugene WareGitHub/eugeneware
Justin HilemanGitHub/bobthecow
Liam CurryGitHub/liamcurry
andöGitHub/dre1080
Riku RouvilaGitHub/rikukissa
Frank WallisGitHub/frankwallis
Frédéric Langlade-BelloneGitHub/fredericlb
pjebyGitHub/pjeby
Dave MacGitHub/DveMac
Rhys EvansGitHub/wheresrhys
Adam KrebsGitHub/akre54
Matt KunzeGitHub/MattKunze
Francesc RosasGitHub/frosas
Toby HoGitHub/airportyh
Devin WeaverGitHub/sukima
Stein Martin HustadGitHub/smh
00DavoGitHub/00Davo
Max NordlundGitHub/maxnordlund
Christian TellnesGitHub/tellnes
Jorrit PosthumaGitHub/JorritPosthuma
Andrew SmithGitHub/ashrewdmint
Adam DuncanGitHub/microadam
Robert OvensGitHub/rovens

debowerify's People

Contributors

00dani avatar airportyh avatar akre54 avatar ashrewdmint avatar bobthecow avatar dre1080 avatar eugeneware avatar frosas avatar jorritposthuma avatar kahwee avatar maxnordlund avatar merott avatar pjeby avatar rikukissa avatar smh avatar sukima avatar tellnes avatar wheresrhys avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

debowerify's Issues

Dos this work with creating a bundle on the command line

Hello

Does debowerify work when just creating a bundle on command line like this

browserify.cmd -t debowerify -r jquery -r angular -r handlebars -o bundle.js

jquery and angular being bower installed modules while handlebars is the npm installed version (I know I could in that use case use only bower modules (not sure if there is a properly maintained angular npm style module to do it the other way) but I am trying this as a test for more complex bundling.

Or do it only work inside the "require" clause of a "main-build.js" module ?

Should I achieve that using the API style of browserify ?

Context : I try do build bundle one for infrequently updated base libraries (angular and co, lodash, d3 and a few others), one for thematic libraries and one for my code at least so that only my code is to be browserified when doing compile / test cycles.

graceful-fs@2 and @3 support will be removed soon

Hi. debowerify is currently #69 in my list of modules that would likely be broken when nodejs/node#6413 lands (which is anticipated to happen before v7.0).

Note that graceful-fs@1 and graceful-fs@4 are ok and would not be broken by this, but a require() on graceful-fs@2 or graceful-fs@3 would cause an error soon.

That is, runtime warning fs: re-evaluating native module sources is not supported. would be turned into a throw.

If you or your deps use graceful-fs@2 or graceful-fs@3 in runtime — you are affected.

Tracking: nodejs/node#5213.

debowerify is now an Open Open Source Project

Hi everyone,

I've just released debowerify as an Open Open Source Project

This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the CONTRIBUTING.md file for more details.

This has been done in order to scale the maintenance of small but popular node.js modules like debowerify and also to put the governance and control of the project into the hands of it's user and greatest stakeholders.

As a result, all past contributors (ie. you've landed a commit into debowerify) have been given contributor (ie. commit access) to this repo.

The includes the following fine people, which are also listed on the README under the contributor list.

debowerify is only possible due to the excellent work of the following contributors:

Eugene Ware@eugeneware
Justin Hileman@bobthecow
Liam Curry@liamcurry
andö@dre1080
Riku Rouvila@rikukissa
Frank Wallis@frankwallis
Frédéric Langlade-Bellone@fredericlb
pjeby@pjeby
Dave Mac@DveMac
Rhys Evans@wheresrhys
Adam Krebs@akre54
Matt Kunze@MattKunze
Francesc Rosas@frosas
Toby Ho@airportyh
Devin Weaver@sukima
Stein Martin Hustad@smh
00Davo@00Davo
Max Nordlund@maxnordlund

I've been personally struggling to stay across the open issues for this project, so as contributors, please feel free to help to triage, review, resolve issues as you see fit :-)

And once again, a huge thanks for all your support and contributions of this project!

error when using debowerify 0.3 with momentjs

When applying debowerify 0.3 on a build that includes moment, browserify throws this error:

Warning: TypeCannot call method 'split' of undefined
(path/to/moment/moment.js)

Changing the version back to 0.2.x, makes the error go away.

I will try to dig a bit deeper, but maybe you can immediately think of something that might cause this?

Maximum call stack size exceeded

package.json

{
    ...
    "browserify": {
        "transform": [
            "browserify-shim",
            "debowerify"
        ]
    }
    ...
}

bower.json

"dependencies": {
    ...
    "angular-strap": "~2.0.5",
    ...
}

app.js

...
require('angular-strap');
...

Exception thrown:

.../websync/node_modules/debowerify/node_modules/bower/node_modules/q/q.js:126
                    throw e;
                          ^
RangeError: Maximum call stack size exceeded

debowerify ignores browserify expose option

I want to use backbone with lodash instead of underscore.
So i added
.require('lodash', {expose: 'underscore'})
and it works fine if i load backbone with npm.
Installed with debowerify underscore is included in the script.

update re-evaluating module

(node:6292) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.

How to use sourcemaps from bower_components?

Is there a way to include the sourcemaps from bower_components into the current bundle?

My dependencies have an external sourcemap (and are in bower), however it would be nice if I was able to have it's sourcemap carry over so that I could see the non-minified bower_component.

Perhaps this is the wrong place to ask this, but some direction would be awesome.

threejs not making it into the scope.

For some reason I'm not seeing threejs make it to the other side of my build pipeline in the browser.

Other bower packages such as 'animation-frame' (AnimationFrame) make it over fine and it is showing up in the bundled .js file as well as the sourcemaps also referencing the file correctly.

Any ideas?

Dependencies of installed packages?

Hi,

I've got a question about how debowerify works with dependencies. I'm struggling with that issue and maybe I'm just misunderstanding it.

I have a application.js which contains one thing: require('magnific-popup'). I've installed magnific-popup via bower and it has one dependency: jQuery.

When I browserify the file (browserify -t debowerify app/assets/javascripts/application.js > public/js/application.js) the resulting file doesn't contain the jQuery dependency. Am I doing something wrong or is this how debowerify is supposed to work?

Bundle only vendor libs

Hey Guys,

is there a way to "debowerify" all vendor libs from my bower_component folder and create a bundle of it via grunt?

Does not work with react-bootstrap

Simple test with react-bootstrap

https://github.com/EvanCarroll/debowerify-fail

$ sh FAIL.sh 
Error: Cannot find module './joinClasses' from '/tmp/fail/public/bower_components/react-bootstrap'
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:42:25
    at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:66:22
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:93:15)

react-bootstrap/index.js has a series of requires

Accordion: require('./Accordion')

While the file, ./Acordion.js has itself a series of requires.

var joinClasses = require('./utils/joinClasses');

These don't seem to be resolvable with react-bootstrap.

Doesn't seem to refer to bower.json dependencies.

I have a heap of Bower packages which I want to exclude from debowerify, so I tried to list them in bower.json as devDependencies, but then I realised that debowerify simply walks the entire directory.

Debowerifying Ember causes error

I have installed ember as a bower component: bower install ember

The debowerify transform is applied like so:

var debowerify = require('debowerify');
      browserify().
      .transform(debowerify)
     .require('./bower_components/ember/ember.js')
    .bundle()
    .pipe(source('vendor.js'))
    .pipe(gulp.dest('./build'));

When I run the above as a gulp task, it shows me the error:

 [07:38:56] Starting 'browserify'... [07:38:56] Running 'bundle'...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: Cannot find module '../package.json' from 'app_root/bower_components/ember'
    at app_root/node_modules/browserify/node_modules/resolve/lib/async.js:43:25
    at load (app_root/node_modules/browserify/node_modules/resolve/lib/async.js:61:43)
    at app_root/node_modules/browserify/node_modules/resolve/lib/async.js:67:22
    at app_root/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
    at Object.oncomplete (fs.js:107:15)

On inspecting the ember.js file from the bower_components/ember directory, saw the following code: var packageVersion = require('../package.json').version;

I am not sure how to resolve this issue and make debowerify play nice with Ember. I have created a repo that demonstrates the problem: https://github.com/saravanak/ember-debowerify

Add support fox tsx files

Debowerify doesn't process tsx files.

Modifying the following line in index.js
if (!/\.(_?js|c?jsx|(lit)?coffee(\.md)?|ls|ts)$/.test(file)) return through();
to this
if (!/\.(_?js|c?jsx|(lit)?coffee(\.md)?|ls|ts|tsx)$/.test(file)) return through();
fixes the issue.

support for ES6 syntax

When using debowerify in conjunction with 6to5ify it results in parse error:

Unexpected reserved word

Maybe using esprima-fb solves the problem, which supports ES6 syntax.

Incorrectly assuming bower is using current working directory

bower.commands.install([], {}, {cwd: "/tmp/xxx"})
var browserify = new Browserify();
browserify.transform(require('debowerify'));

debowerify calls bower.commands.list with the default configuration, which may be incompatible with the configuration that's been used to install components.

I'm creating a web service that builds browserified JS files on-demand, so there can be several bower installations running at the same time, so I can't rely on the globally shared current working directory.

It'd be nice if it was possible to pass configuration or list of modules to debowerify somehow (in my case passing bowerModules is preferred, since I have that cached already).

e.g.

browserify.transform(require('debowerify').create({bowerModules:mymodules}));

custom bower directory in browserify result js

I have a custom .bowerrc and in the resulting "bundle.js" including the complete path (see bundle.js below). Everything else looks good, except this path related problem.

$ browserify index.js -o bundle.js

Result

bundle.js

...
function(require,module,exports){
require("./../../../../projectname/vendor/bower_components/seiyria-bootstrap-slider/js/bootstrap-slider.js");
...
-- all good from here --
/*! =========================================================
 * bootstrap-slider.js
....

Setup

index.js

require("seiyria-bootstrap-slider");

.bowerrc

{
  "directory": "../../../../projectname/vendor/bower_components",
  "json": "bower.json",
  "analtycs": false
}

package.json

{
  "name": "Projectname",
  "version": "1.0.0",
  "dependencies": {
  },
  "browserify": {
    "transform": [
      "debowerify"
    ]
  },
  "devDependencies": {
    "browserify": "^4.1.5",
    "debowerify": "^0.9.1"
  }
}

I have the same issue with all other require statements related to bower as well.

Updates for Bower 1.0

bower.commands.ls doesn't appear to exist anymore. It seems the task fails silently, at least when run within grunt-browserify. Also, just changing ls to bower.commands.list doesn't fix the problem.

Command line options -u or -x doesn't work with debowerify

I'm using something like:

require('angular');

And I use browserify -t debowerify -x angular input.js > output.js.

The angular dependency is still be loaded into output.js. How would you make angular which is from Bower a common dependency?

Caching `bower.commands.list` result to `bowerModules` variable causes problems with constantly running build systems

Caching bower.commands.list result to bowerModules variable causes problems with constantly running build systems (for example gulp, most likely with others too) since the variable is located outside the exported function scope.

At the moment it's necessary to restart the entire build system process every you install new bower module which is a bit annoying especially when this could be quite easily prevented. Also, it's possible to npm install and require stuff without getting errors about missing files.

All of this would be fixed just by placing the bowerModules variable inside the exported function. I don't think this would effect the performance in a noticeable way since fetching the bower modules would only happen once per build and the possible performance hit would only exist when multiple browserify builds are created in one process.

Print a useful message when debowerify can't read a bower.json file

Currently if there's an empty bower.json somewhere, my watch process just quits with the message SyntaxError: Unexpected end of input.

(Empty bower.json files do happen occasionally, after a bower install gone wrong.)

The problem is there is no indication of which file has a syntax error. If you're not expecting a bower.json to be broken, and you're editing JS files at the time you get the error, you spend a long time looking for bugs in the wrong place...

Please update debowerify so whenever you JSON.parse() a file, you do it in a try/catch block, so you can catch any syntax error and then print out a useful message including the path to the bad JSON file, before exiting.

Shouldn't debowerify take package.json's "main" field into account?

I have tried to use debowerify on Knockout.js. It didn't work because debowerify does not look at the main field of the package.json file, which states that the path to the main file is actually build/output/knockout-latest.js, and instead falls back to trying just knockout.js.

I looked at the code, and the reason for this behavior is that debowerify uses the bower "list paths" command to obtain its paths.

Incidentally, adding a main field to .bower.json would solve the problem - unfortunately, Knockout doesn't have that field in its .bower.json file.

So I guess this brings up a couple of questions:

  1. Is it up to a module implementor (or the party packaging that module for bower) to provide the main path in .bower.json, even when the same information could already be obtained from package.json? This may violate the DRY principle - the question is whether .bower.json is supposed to replace package.json in browser environments, or just add to it.
  2. Supposing information from package.json really should be taken into account, that leaves the question whether the problem should be fixed in bower itself or in debowerify - or possibly in both ?

Don't filter files with .es6 extensions

Lots of people use .es6 as their file extension to explicitly signal which version of ECMAScript they're supporting. But if the entrypoint passed to browserify is such a file, debowerify will ignore it even if it's been transformed through a transpiler first.

Debowerify breaks if given no options?

When trying to run $ browserify -t debowerify path/to/files/*.js -o path/to/output.js I get this:

/.../node_modules/debowerify/index.js:79
    var bowerOptions = options.bowerOptions || {};
                              ^
TypeError: Cannot read property 'bowerOptions' of undefined

If I make these changes to debowerify's index.js, it works:

8 | module.exports = function (file, options) {
9 |   if (!options) options = {};

I have upgraded to the latest version of node and npm but it still doesn't seem to work as-is.

Is this repo maintained?

I know every repo maintainer hates seeing one of these, but...

I ask because of #86, #85, #83 have been open for almost a year now, and are seemingly really simple fixes to warnings being thrown.

If the maintainers don't intend to continue supporting this project, it should be stated in the README so new users are adequately warned.

Debowerify doesn't seems to work

I have installed through bower

$ bower install bootstrap-daterangepicker --save-dev

In my app.js, I try to include it with

var rangePicker = require('bootstrap3-daterangepicker');

Please not that the bower_components is into the folder ./client/ but I have a .bowerrc file with

{
"cwd": "client"
}

The bower.json of this library as all the required attributes. (see :
https://github.com/dangrossman/bootstrap-daterangepicker/blob/master/bower.json )

Gulp is in charge to do the browserify bundle for me, but I can't make it work, I always got this error :

[18:06:53] Browserify Error { [Error: Cannot find module 'bootstrap3-daterangepicker' from ...

Any suggestion on how to debug this ?

debowerify npm package mismatch

Hi everyone,
I could be completely missing something here, but it looks the debowerify package at npm has drifted from the current master. Specifically, it does not include the preferNPM property to favor npm dependencies over bower ones.

Version 1.3.1 was published to NPM 9 months ago. The pull request for preferNPM occurred 4 months ago.
@eugeneware Are you able to publish to npm, so the latest package has this feature? Or if i'm doing something stoopid, correct my stoopid?

Thanks! :-)

Fails to rewrite paths in nested dependencies

debowerify fails to rewrite the require statements correctly where the component being required is not a direct dependency of the containing project. So if I have a project A which requires B and B requires C, the require in B referring to C will not be resolved by browserify because debowerify doesn't rewrite it.

I believe this to be because using the programmatic interface to bower in the way that debowerify does will only ever return data about A, even if the file passed to debowerify from browserify is a member of B.

I have fixed this by refactoring debowerify to remove the bower dependency and instead simply read the bower.json files using fs, but there may be a better method.

Bump bower dependency version

Are there any issues with bumping the bower dependency up to at least 1.7.3?

There is an issue with installing debowerify through yarn as a result of optional dependencies. Although the issue is documented and in the process of being fixed I think we can avoid it here by bumping the bower version.

If anyone wants to look into this for themselves, the issues is aws-sign2 not being installed due to an older version of request which is required by the older bower.

Support bower@~1.2.3

When I try to install this plugin I get the following error in my console:

npm ERR! peerinvalid The package bower does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants bower@~1.1.0

When I have bower@~1.2.3 installed.

Illegal require generation

e.g.

// Generated by LiveScript 1.4.0
var $, Sortable, uploadFile, sncompleter, postContentInitializer, postCompiler, subPostCompiler, AlbumDialog, userCard, Post, Timeline;
$ = require("./..\\..\\..\\..\\..\\bower_components\\jquery\\dist\\jquery");
require("./..\\..\\..\\..\\..\\bower_components\\jquery.transit\\jquery.transit.js");
Sortable = require("./..\\..\\..\\..\\..\\bower_components\\Sortable\\Sortable.js")
require("./..\\..\\..\\..\\..\\bower_components\\Sortable\\ng-sortable.js")
require("./..\\..\\..\\..\\..\\bower_components\\Sortable\\knockout-sortable.js")
require("./..\\..\\..\\..\\..\\bower_components\\Sortable\\react-sortable-mixin.js")ploadFile = require('../../../common/upload-file.ls');
sncompleter = require('./sncompleter.ls');
postContentInitializer = require('./post-content-initializer.ls');
postCompiler = require('../views/post/smart/render.jade');
subPostCompiler = require('../views/post/smart/sub-post-render.jade');
AlbumDialog = require('./album-dialog.ls');
userCard = require('./user-card.ls');

HERE

require("./..\\..\\..\\..\\..\\bower_components\\Sortable\\react-sortable-mixin.js")ploadFile = require('../../../common/upload-file.ls');
                                                                                    ^

Sorry my bad English. Thanks.

Allow ignore specific bower components

Hello , currently i am developing angular.js application with browserify . I am using both NPM + Bower, but i am facing problem that i have installed angular both in bower and npm , but i want to force load it from npm, because bower repo is broken for browserify. Also some modules has newer version in npm repos than bower (but some other modules has its dependecy so it is force loaded via bower)

Currently i made this changes to debowerify

https://github.com/eugeneware/debowerify/blob/master/index.js#L8

module.exports = function (file, options, module_options) {

  var defaultConfig = {
      ignoreModules : []
  };
  var bowerModules;
  if (!options) options = {};
  module_options = module_options || defaultConfig;

i made new function parameter to set debowerify options , so i can pass my new ignoreModules parameter.

Then i skipped this module here

https://github.com/eugeneware/debowerify/blob/master/index.js#L100

      //break if module should be ignored
      if(module_options.ignoreModules.indexOf(moduleName) !== -1) return;

then i adjusted my browserify build to :

  bundler.transform(function(file,options) {
    var config = { ignoreModules : [
        'angular'
    ]};
    return debowerify(file,options,config)
  });

Let me know if this is worth of PR or i should make own forked version of debowerify. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.