gluejsでlodashが読み込めない問題


## 原因特定

lib/runner/package-commonjs/index.js:227:

            // require.m[n]['foo'] = { c: 1, m: 'lib/index.js' }
            out.write(
              JSON.stringify(name) + ': ' + JSON.stringify({
                c: index,
                m: list.packages[index].main
              }));
            out.write(',\n');

ここで `list.packages[index].main` が `undefined`

`dist`をignoreしてるけどlodash/package.jsonではmain:dist/lodash.jsとしているから問題なのでは…

## 解決策は `--reset-exclude`

`gluejs --include app --include node_modules/lodash --basepath app --main main.js --out dist/app.js --verbose --reset-exclude` ならOK。

## 副作用

ただし無駄にlodashが二回読み込まれる。`lodash/lodash.js`と`lodash/dist/lodash.js`で。

---

    $ node debug ../gluejs/bin/gluejs --include app --include node_modules/lodash --basepath app --main main.js --out dist/app.js --verbose
    < debugger listening on port 5858
    connecting… ok
    break in /Users/ishibashi/dev/gluejs/bin/gluejs:2
      1 
      2 var fs = require('fs'),
      3     path = require('path'),
      4     Glue = require('../index.js'),
    debug> setBreakpoint('index.js', 234);
    Warning: script 'index.js' was not loaded yet.
      1 
      2 var fs = require('fs'),
      3     path = require('path'),
      4     Glue = require('../index.js'),
      5     Minilog = require('minilog');
      6 
      7 var opts = require('optimist')
    debug> cont
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.compat.js
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.compat.min.js
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.js
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.min.js
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.underscore.js
    < filter-regex info Excluded by regexp  //dist// : /Users/ishibashi/dev/gluejs_test/node_modules/lodash/dist/lodash.underscore.min.js
    < filter-packages info Excluded by .{git,npm}ignore: /Users/ishibashi/dev/gluejs_test/node_modules/lodash/README.md
    < filter-packages info Excluded by .{git,npm}ignore: /Users/ishibashi/dev/gluejs_test/node_modules/lodash/package.json
    < package-commonjs info Excluded non-js/non-json file: LICENSE.txt
    < package-commonjs info Processing package: root
    break in /Users/ishibashi/dev/gluejs/lib/runner/package-commonjs/index.js:234
     232           }));
     233         out.write(',\n');
     234         debugger;
     235       });
     236 
    debug> repl
    Press Ctrl + C to leave debug repl
    > list
    { files: 
       [ { name: '/Users/ishibashi/dev/gluejs_test/app/main.js',
           stat: [Object] },
         { name: '/Users/ishibashi/dev/gluejs_test/node_modules/lodash/lodash.js',
           stat: [Object] } ],
      packages: 
       [ { files: [Object],
           dependenciesById: [Object],
           basepath: '/Users/ishibashi/dev/gluejs_test/app',
           main: 'main.js' },
         { name: 'lodash',
           uid: 1,
           basepath: '/Users/ishibashi/dev/gluejs_test/node_modules/lodash/',
           main: undefined,
           files: [Object],
           dependenciesById: {} } ] }
    > index
    1