Giter VIP home page Giter VIP logo

gluejs's People

Contributors

emarschner avatar gabel avatar mixu avatar tmcinerney 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

gluejs's Issues

No API for transform

@mixu Is this intentional? Also, I see you could potentially activate multiple transforms but it isn't documented, or in tests (that I can see), how you might do this.

incorrect RegExp

the global handler uses the expression:

new RegExp('.*\.js$')

but you use a single-quoted string and you forgot to escape the backslash so it evaluates to:

/.*.js$/

which obviously doesn't do the same thing!

Paths should be relative to working directory

What Happened?

I've installed gluejs locally:

"devDependencies": {
  "gluejs": "~0.2.0"
}

Then I ran the following in node (with /my_project/ as the working directory):

new Glue()
  .basepath('./src')
  .include('./src')
  .replace({ jquery: 'window.jQuery' })
  .export('MyLibrary')
  .render(function (err, txt) {
    fs.writeFile('./assets/insistent_cat.js', txt);
  });

I get the following error:

Error: ENOENT, no such file or directory '/my_project/node_modules/gluejs/lib/src'
    at Object.fs.statSync (fs.js:524:18)
    at Group.include (/my_project/node_modules/gluejs/lib/group.js:21:26)
    at Array.forEach (native)
    at Group.include (/my_project/node_modules/gluejs/lib/group.js:19:9)
    at Renderer.include (/my_project/node_modules/gluejs/lib/glue.js:42:55)
    at repl:1:30
    at REPLServer.self.eval (repl.js:111:21)
    at rli.on.e (repl.js:260:20)
    at REPLServer.self.eval (repl.js:118:5)
    at Interface.<anonymous> (repl.js:250:12)

What Did You Expect?

I expected .basepath('./src'), .include('./src'), and fs.writeFile('./assets/insistent_cat.js', txt); all to be relative to the current working directory.

Glue.defaults does not work w/ replace parameter

Hi,

I'm currently writing a Grunt 0.4.x task for you library.

In the section Setting default values of your documentation replace is mentioned.
I tried something like this:

var Glue = require('gluejs');

Glue.defaults({
    replace: { jquery: 'window.$' }
});

var glue = new Glue();
glue.include('/path/to/some/directory');
glue.render(/*...*/);

In the output, I don't see any replacement for require('jquery').

If I do the following, it works:

var Glue = require('gluejs');

var glue = new Glue();
glue.include('/path/to/some/directory');
glue.replace({
    jquery: 'window.$'
});
glue.render(/*...*/);

Am I missing something with the defaults usage?

Thanks!

require() implementations makes mod a function

Hey, great library. The only problem is that for libraries like jQuery, which support the commonjs module definition, do this check to see if they should use module.exports:

if ( typeof module === "object" && typeof module.exports === "object" ) {

However, glue makes module the function that is being called currently. So the typeof module === "object" check does not work. My suggestion is to change lib/require/require.js (around line 40) from:

if (!mod.exports) {
      mod.exports = {};
      mod.call(mod.exports, mod /* mod is a function, cannot do */, 
        mod.exports, r.relative(path, context));
    }

to:

if (!mod.exports) {
      mod.exports = {};
      // make a clone object
      var modcl = {};
      // copy over
      for(var p in mod) modcl[p] = mod[p];
      mod.call(mod.exports, modcl /* give object, not function */, 
        mod.exports, r.relative(path, context));
    }

Including Backbone with a single copy of Underscore

Hey,

Trying out Gluejs in a real world context here, but having trouble understanding how it's supposed to be used.

Invoking it with, amongst other options, with:

        --basepath app/javascripts
        --include app/javascripts/node_modules/underscore/index.js
        --include app/javascripts/node_modules/backbone/index.js

Doing require("underscore") works from my own code, but when doing require("backbone"), it fails with Uncaught Error: failed to require "underscore" from index.js because of Backbone's attempt to load Underscore itself.

How should this be handled?

--include doesn't understand directories when using --transform

In fact, when doing:

node_modules/.bin/gluejs --verbose --transform coffeeify --global App --include client/app/ --out public/app.js

I get the output:

[===================] 2 / 2 100% 0.0s
Error in input pipe to pipe: 2 -> 3 { [Error: EISDIR, read] errno: 28, code: 'EISDIR' }

But without transform:

node_modules/.bin/gluejs --verbose --global App --include client/app/ --out public/app.js

I get:

commonjs info Excluded non-js/non-json file: client/app
commonjs info Excluded non-js/non-json file: client/app/index.coffee
commonjs info Processing package: root

gluejs2: add --remap

The way to remap requires into different internal things is a bit intricate:

"assert": function(module, exports, require) { module.exports=require('chai').assert; },

Add support for caching different --flags

Right now, caching is quite conservative: it will rebuild if any of the --flags change. However, a common use is to do two kinds of builds: 1) dev builds (no minification) and 2) production builds (minification).

I think it would be good to support caching with different options transparently so that if you alternate between a dev build and a production build, both will get cache hits.

"detective": "~2.4.0" Cannot Install

Looks [email protected] contains an invalid dependency on 'esprima-six', a package which does not exist. Therefore, npm installfails when gluejs 2.3.9 is listed as a dependency. Would bumping detective to latest (4.3.1) break anything?

Let `#exclude` accept a string as parameter

My use case being that I want to exclude the output file contained in the same directory of my includes.

For example:

var Glue = require('gluejs');

var glue = new Glue();
glue.include('test/server')
    .exclude('test/server/index.js')
    .render(err, output) {
        grunt.file.write('test/server/index.js', output);
    });

Add support for changing the directory structure while running a server

Right now, the caching layer assumes that the directory structure does not change during the lifetime of a Gluejs instance. It would be nice given new Gluejs().include(...) and a later .render(), file changes between the include and render would be taken into account.

One can work around this issue either by restarting the server after directory changes or by creating a new Gluejs instance when compiling to force a path refresh.

Log Level

I've got Glue.js building a package on every view when the environment is development. Functionally, everything works great. The usability isn't so hot, however, since the console spews out dozens of logging lines on every view served.

Requesting a log level option when using the JavaScript API to hide logging, except for errors.

Cannot run against files in `dist/`

Running

./node_modules/gluejs/bin/gluejs \
  --include ./dist/cjs/ \
  --main ./dist/cjs/i18n.js \
  --replace emberjs=window.Ember,handlebars=window.Handlebars,jquery=window.jQuery \
  --global Ember.I18n \
  --out ./dist/ember-i18n.js

yields

/.../node_modules/gluejs/lib/runner/package-commonjs/index.js:93
    throw new Error('No files were included in the build. Check your `.include
          ^
Error: No files were included in the build. Check your `.include()` call paths.
    at module.exports (/.../node_modules/gluejs/lib/runner/package-commonjs/index.js:93:11)
    at API.render (/.../node_modules/gluejs/index.js:37:5)
    at Object.<anonymous> (/.../node_modules/gluejs/bin/gluejs:161:5)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

I don't have a .npmignore file and dist/ doesn't appear in my .gitignore. Moving the ./dist/ structure to ./tmp/ solves the problem.

Error: failed to require "undefined" from undefined

I'm considering gluejs for a project, rendering to an express/connect response. The 2nd-to-the-last line in the resulting file has myModuleName = require('undefined'); but all the other scripts appear to concatenated in there fine. What am I missing?

app.get('/js/model.js', function(req, res) {
    new Glue()
        .basepath('./model')
        .include('./')
        .export('myModuleName')
        .render(function(err, js) {
            res.setHeader('content-type', 'application/javascript');
            res.send(js);
        });
});

.npm() ignores package.json "main" property and .npmignore for module "sax"

Reduced test case here:

https://github.com/jbeard4/gluejs-issue-9

Consider build.js which includes module sax in node_modules:

new Glue()
    .npm('sax','.') // output paths are relative to this
    .exclude(new RegExp('examples')) // excludes rhino
    .exclude(new RegExp('dist')) // excludes rhino
    .exclude(new RegExp('test')) // excludes rhino
    .render(function (err, txt) {
        // write the result to a file
        fs.writeFile('out.js', txt);
    });

sax's package.json includes a "main" property:

{
  "name": "gluejs",
  "description": "Build CommonJS modules for the browser via a chainable API",
  "version": "0.2.0",
  "author": {
    "name": "Mikito Takada",
    "email": "[email protected]",
    "url": "http://blog.mixu.net/"
  },
  "keywords": [
    "browser",
    "require",
    "bundle",
    "commonjs",
    "npm",
    "module",
    "package"
  ],
  "main": "lib/index.js",
  "bin": {
    "gluejs": "./bin/gluejs"
  },
  "dependencies": {
    "package-json-resolver": "0.0.1",
    "minilog": "0.0.4",
    "argsparser": "0.0.6"
  },
  "devDependencies": {
    "mocha": "1.x"
  }
}

Furthermore, I've added a .npmignore file to the sax module:

examples
test

Nevertheless, the javascript files inside of /examples' gets compiled intoout.js`:

jbeard@jbeard-VirtualBox:~/tmp/test-gluejs$ node build.js 
package info Package total: 0.00k
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/.npmignore
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/AUTHORS
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/LICENSE
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/LICENSE-W3C.html
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/README.md
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/big-not-pretty.xml
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/not-pretty.xml
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/shopping.xml
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/strict.dtd
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/test.html
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/test.xml
package warn Excluded: /home/jbeard/tmp/test-gluejs/node_modules/sax/package.json
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/buffer-overrun.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/case.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cdata-chunked.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cdata-end-split.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cdata-fake-end.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cdata-multiple.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cdata.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/cyrillic.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/duplicate-attribute.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/entities.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/entity-mega.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/index.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-23.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-30.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-35.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-47.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-49.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/issue-84.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/parser-position.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/script-close-better.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/script.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/self-closing-child-strict.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/self-closing-child.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/self-closing-tag.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/stray-ending.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/trailing-attribute-no-value.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/trailing-non-whitespace.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/unclosed-root.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/unquoted.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-issue-41.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-rebinding.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-strict.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-unbound.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-xml-default-ns.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-xml-default-prefix-attribute.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-xml-default-prefix.js
package warn Lazy exclude (test.js, /test, /dist): /home/jbeard/tmp/test-gluejs/node_modules/sax/test/xmlns-xml-default-redefine.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/example.js as /examples/example.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/get-products.js as /examples/get-products.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/hello-world.js as /examples/hello-world.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/pretty-print.js as /examples/pretty-print.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/examples/switch-bench.js as /examples/switch-bench.js
package debug Processing (sax): /home/jbeard/tmp/test-gluejs/node_modules/sax/lib/sax.js as /lib/sax.js
package info 1. /lib/sax.js 35.42k (87 %)
package info 2. /examples/get-products.js 1.51k (3 %)
package info 3. /examples/pretty-print.js 1.45k (3 %)
package info 4. /examples/switch-bench.js 1.04k (2 %)
package info 5. /examples/example.js 0.77k (1 %)
package info 6. /examples/hello-world.js 0.16k (0 %)
package info Package total: 40.36k

Don't assume environment variables exist

Our deployments started failing after upgrading from version 2.0.

Turns out this was because our environment did not define HOME during deployment.

var homePath = process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'];

Probably best to use a more reliable path in Linux for the default.

indirection breaks API relative paths

commit 6656c05 changed package.json's main from lib/glue.js to lib/index.js (which in turn requires lib/glue.js)

while using the API rather than the binary, that causes this line:

reqpath: path.dirname(require.cache[__filename].parent.filename)

in lib/glue.js to evaluate to ./gluejs/lib/index.js as opposed to the path of the js file in which new Glue() is invoked...
that messes up relative includes in gluejs's API (e.g.: new Glue().include('../somedir')).

I tried simply changing the line to

reqpath: path.dirname(require.cache[__filename].parent.parent.filename)

so that the proper filename is fetched by following the indirection (main is lib/index.js now which then requires lib/glue.js so we have to reach to the parent of the parent... parent.parent), but that breaks the new gluejs binary (bin/gluejs).
sorry if the issue isn't too clear hehe.

Custom filtering + custom watching

I would like to be able to apply custom filter on a per module basis. For example:

new Glue()
  .include('./core')
  .filter(new RegExp('.+\.handlebars'), function(data, render) {
    var template = Handlebars.precompile(data);
    return render(template);
  })
  .export('Core')
  .watch(function (err, txt) {
    fs.writeFile('./core.js', txt);
  });

render refers to the stock implementation which wraps everything inside a closure:

(function(){
...
})();

This will let me add preprocessing steps prior to concatenation. However, in order for this to work, I would also need to be able to exclude *.handlebars files from the output, but still be able to filter them into the output via preprocessing.

Results don't pass JSHint

Running JSHint v2.0.1 results in the following violations in the definition of require:

tmp/out.js: line 1, col 44, Expected an assignment or function call and instead saw an expression.
tmp/out.js: line 1, col 248, Missing semicolon.
tmp/out.js: line 1, col 343, Missing semicolon.
tmp/out.js: line 1, col 456, Missing semicolon.
tmp/out.js: line 1, col 663, Expected an assignment or function call and instead saw an expression.
tmp/out.js: line 1, col 664, Missing semicolon.
tmp/out.js: line 1, col 696, Missing semicolon.
tmp/out.js: line 1, col 697, Missing semicolon.

Additionally, if the unused flag is set and any module doesn't require another module (is a leaf node in the dependency tree), the follow violations also occur:

tmp/out.js: line ..., col 48, 'require' is defined but never used.
tmp/out.js: line ..., col 39, 'exports' is defined but never used.

The alternative is to run JSHint on the inputs to gluejs and just assume that gluejs doesn't cause any problems. I like the extra assurance of being able to run JSHint on the file I'm actually delivering to the client, though.

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.