Cram help please!

273 views
Skip to first unread message

Gehan Gonsalkorale

unread,
Apr 12, 2013, 10:17:05 AM4/12/13
to cuj...@googlegroups.com
Hi Guys,

Trying to switch from using r.js to using cram.js so that I can use cram plugins, create plugins with text/css etc. However, no idea what's going on really! I'm gonna play around with the source but thought I might as was ask in case there's a quick answer to this!

I have installed cram using npm, so I have something like this as my app

          config.json
/node_modules
    /cram
        cram.js
/static
    /app
        
common.js
        core.js
        ModuleA.js
        ModuleB.js
    /lib
        /Q
/build

With r.js I'd then have a config.json like this

{
    appDir: './static/',
    baseUrl: './',
    packages: [
        { name: 'Q', location: 'lib/q/', main: 'q' }
    ]
    dir: './build/',
    modules: [
        {
            name: 'app/common',
            include: ['app/core', 'Q'] // Include these extra modules into init even though they aren't referenced
        },
        {
            name: 'app/ModuleA',
            exclude: ['app/common'] // Exclude everything inside common
        },
        {
            name: 'app/ModuleB',
            exclude: ['app/common'] // Exclude everything inside common
        }
    ]
}

I'd run :

node r.js -c config.json

It would then create the 3 modules specified. Our app is in 2 parts which is why we have 2 modules like this, which we'd run like this

curl(['app/common'], function() {
    curl(['app/ModuleA'], function(ModuleA) {
        // Run this part
    });
});

I'd assuming I'd have to run cram for each of these 3 modules, and include the extra bits using --include? I can't see how to exclude though. Also when running the below

node node_modules/cram/cram.js static/app/common.js  -c config.json

It seems to have all paths relative to node_modules/cram? as I get

Error: Cannot find module 'config.json'                                                                                   │                                                                                                                                       
 

Anyway, any help appreciated! When working I'll make a grunt plugin for this! 

 
 

unscriptable

unread,
Apr 12, 2013, 12:07:47 PM4/12/13
to cuj...@googlegroups.com
Hey Gehan!

A couple of notes:

1. A few times you mention "modules", but I think you mean built/concatenated files.  We call these "bundles".

2. cram.js doesn't use the same config options as r.js.  (I think you know this, but just confirming. :) )

3. I've never `npm install`ed cram.js locally and used it like this.  (Silly me.)  I've always used it globally `npm install -g cram`.  You will have to remove the local reference, iiuc, for the global one to work.  However, I have no reason to think that global-vs-local cram is a cause of the "Cannot find module" issue.

4. You are correct: cram does not build multiple bundles at once.  You will have to run it three times.

The `excludes` feature is not implemented, yet.  It's something I've been wanting to tackle and is already partly implemented.  Also, coordination of multiple bundles is a feature I've been itching to do, as well.  That could follow right after `excludes` (and is partially implemented, too).

I could probably get the `excludes` feature done fairly quickly.  You'd have to work with the dev branch of cram.js for a while, which is only slightly inconvenient, imho.  Also, you'd have to manually build the `excludes` lists until cram can coordinate multiple bundles.  Is this cool with you?

FYI: cram.js dev branch has another bug that mangles the output when you use the --loader option or point cram at an html file that uses the data-curl-run html attr.  We're working on that bug, so don't use those features, yet. :)

Anyway, any help appreciated! When working I'll make a grunt plugin for this! 
 
Very nice!  Looking forward to it!

Regards,

-- John

Gehan Gonsalkorale

unread,
Apr 12, 2013, 12:27:31 PM4/12/13
to cuj...@googlegroups.com
Great thanks will play again!

I installed cram globally but it doesn't seem to have an executable, so how are you running it? i.e. can't run cram, or node cram. are you adding node_modules/cram to your path then or something else?

unscriptable

unread,
Apr 12, 2013, 1:13:39 PM4/12/13
to
Doh!  I am such an idiot today.  You are right.  The version in npm can't be run globally.  I'll see if I can fix that soon, too.  Thanks for your patience. :)

-- J

Gehan Gonsalkorale

unread,
Apr 12, 2013, 6:22:16 PM4/12/13
to cuj...@googlegroups.com
This bin file should sort it?

Gehan Gonsalkorale

unread,
Apr 12, 2013, 6:24:02 PM4/12/13
to cuj...@googlegroups.com
Although this happens:

$ cram -c static/app/curlPaths.js 
cram failed:  Cannot find module 'static/app/curlPaths.js'
Error: Cannot find module 'static/app/curlPaths.js'

Even though static/app/curlPaths.js exists :)

Gehan Gonsalkorale

unread,
Apr 12, 2013, 6:24:42 PM4/12/13
to cuj...@googlegroups.com
Error: Cannot find module 'static/app/curlPaths.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at loadModule (/usr/local/lib/node_modules/cram/lib/io/json/require.js:15:23)
    at /usr/local/lib/node_modules/cram/lib/io/json/require.js:9:12
    at /usr/local/lib/node_modules/cram/cram.js:110:35
    at Object.then (/usr/local/lib/node_modules/cram/support/when/when.js:193:34)
    at when (/usr/local/lib/node_modules/cram/support/when/when.js:56:34)
    at resolveOne (/usr/local/lib/node_modules/cram/support/when/when.js:543:6)

Gehan Gonsalkorale

unread,
Apr 13, 2013, 5:56:15 AM4/13/13
to cuj...@googlegroups.com
Sorry to keep posting problems! Tried a run.js

define(['curl'], function (curl) {

    curl.config({
        baseUrl: "/money/static",

        packages: [
            { name: 'dojo', location: 'lib/dojo' }
            { name: 'ko',   location: 'lib/knockout/build/output', main: 'knockout-latest' }
            { name: 'curl', location: 'lib/curl/src/curl', main: 'curl' }
            { name: 'wire', location: 'lib/wire', main: 'wire' }
            { name: 'when', location: 'lib/when', main: 'when' }
            { name: 'meld', location: 'lib/meld', main: 'meld' }
            { name: 'poly', location: 'lib/poly', main: 'poly' }
        ]
    })
    curl(['wire!app/main/spec'])
})


But now get this

cram failed:  grokking "money/static/app/run.js": TypeError: Object function _curl() {
var args, config, includes, warnings;

warnings = [];

// parse params
args = Array.prototype.slice.call(arguments);
if (Object.prototype.toString.call(args[0]) == '[object Object]') {
config = args.shift();
}
if (Object.prototype.toString.call(args[0]) == '[object Array]') {
includes = args.shift();
}
if (typeof args[0] == 'function') {
warnings.push('Did not inspect code inside `curl()` callback(s).');
}

collectConfig(config, includes, warnings);

return {
// warn when .then() is called
then: function (cb, eb) {
warn('Did not inspect code inside `.then()` callback(s).');
},
// warn if .next() is called
next: function (modules) {
warn('Did not include any modules mentioned in `.next()`: ' + modules);
},
config: function(cfg) {
collectConfig(cfg);
}
};
} has no method 'config'

Which is confusing as the printed method clearly has a config function! :)

unscriptable

unread,
Apr 18, 2013, 9:56:15 AM4/18/13
to cuj...@googlegroups.com
Hey Gehan,

Lots of updates to cram over the past few days (including your bin addition).  Speaking of your bin addition, I simplified it.  A lot!  It seems to work for me.  Can you try it?

Thanks!

-- John

Gehan Gonsalkorale

unread,
Apr 19, 2013, 7:59:36 AM4/19/13
to cuj...@googlegroups.com
Oh yes, that is quite a lot simpler! I'll try, I would have thought it would work though yes!

Gehan Gonsalkorale

unread,
Apr 23, 2013, 5:33:13 AM4/23/13
to cuj...@googlegroups.com
Will have a play with new cram, although might want to update npm package as it's still 0.7.0

unscriptable

unread,
Apr 23, 2013, 9:04:08 AM4/23/13
to cuj...@googlegroups.com
Hey Gehan,

Yah, It's still at 0.7.0 in npm until I've added more tests.  In the mean time I've been installing cram globally by pointing at the local folder:

npm install -g path/to/cram

-- John

Gehan Gonsalkorale

unread,
Jun 4, 2013, 9:14:24 AM6/4/13
to cuj...@googlegroups.com
I'm going to have a play with this soon so will let you know how I get on, some questions though.

How does cram work through the dependencies of a wire spec? Does it just look for wire! plugin calls? If so then presumably if I always called wire() manually to access the error handler then it won't catch these?

We are using wire for our new developments, but haven't deployed any yet. We're getting close but now optimising the build is the next step!

unscriptable

unread,
Jun 4, 2013, 5:23:33 PM6/4/13
to cuj...@googlegroups.com
Hey Gehan,

Yes, cram only uses the wire! plugin to dig into dependencies, atm (via the wire/builder/cram module).  We're contemplating a solution that uses the wire/builder/cram from the command line. https://github.com/cujojs/wire/issues/102  Feedback welcome!

-- John

Gehan Gonsalkorale

unread,
Jun 24, 2013, 4:51:01 AM6/24/13
to cuj...@googlegroups.com
Hey finally got round to giving this a go...

However I still can't get it to run with a config file!

I installed via npm globally then tried running this:

cram static/app/managementDashboard/spec.js  build-options.json 

However I still just get this

cram failed:  Cannot find module 'build-options.json'

I will try using a run.js next although we construct some of our html at runtime so being able to use a config file would be much better for us!

Also can I just point to a wire spec and build that? That would ideal.

Gehan Gonsalkorale

unread,
Jun 24, 2013, 5:03:13 AM6/24/13
to cuj...@googlegroups.com
Can't get a run.js working either, I get this error. Strange as the object it prints out has a method called config which you can see

(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ cram static/app/dashboard.js
cram failed:  grokking "static/app/dashboard.js": TypeError: Object function _curl() {
                                        var args, config, includes, warnings;

                                        warnings = [];

                                        // parse params
                                        args = Array.prototype.slice.call(arguments);
                                        if (Object.prototype.toString.call(args[0]) == '[object Object]') {
                                                config = args.shift();
                                        }
                                        if (Object.prototype.toString.call(args[0]) == '[object Array]') {
                                                includes = args.shift();
                                        }
                                        if (typeof args[0] == 'function') {
                                                warnings.push('Did not inspect code inside `curl()` callback(s).');
                                        }

                                        collectConfig(config, includes, warnings);

                                        return {
                                                // warn when .then() is called
                                                then: function (cb, eb) {
                                                        warn('Did not inspect code inside `.then()` callback(s).');
                                                },
                                                // warn if .next() is called
                                                next: function (modules) {
                                                        warn('Did not include any modules mentioned in `.next()`: ' + modules);
                                                },
                                                config: function(cfg) {
                                                        collectConfig(cfg);
                                                }
                                        };
                                } has no method 'config'

Dashboard.js is this:

define(['curl'], function(curl) {
    curl.config({
        "baseUrl": "static/",
        "paths": {
            "sandbox": "app/sandbox",
            "lib": "js/lib",
            "domReady": "js/lib/domReady",
            "jquery": "lib/jquery/jquery"
        },
        "packages": [
            { "name": "bags", "location": "lib/bags/dist" },
            { "name": "curl", "location": "lib/curl/src/curl"},
            { "name": "Q", "location": "lib/q/", "main": "q" },
            { "name": "wire", "location": "lib/wire", "main": "wire" },
            { "name": "meld", "location": "lib/meld", "main": "meld" },
            { "name": "when", "location": "lib/when", "main": "when" },
            { "name": "poly", "location": "lib/poly" },
            { "name": "ko", "location": "lib/knockout/build/output", "main": "knockout-latest" },
            { "name": "knockout", "location": "lib/knockout/build/output", "main": "knockout-latest" },
            { "name": "backbone", "location": "lib/backbone", "main": "backbone", "config": {
                "moduleLoader": "curl/loader/cjsm11"
            }},
            { "name": "underscore", "location": "js/lib", "main": "lodash.compat"},
            { "name": "lodash", "location": "js/lib", "main": "lodash.compat"},
            { "name": "knockback", "location": "lib/knockback", "main": "knockback", "config": {
                "moduleLoader": "curl/loader/cjsm11"
            }},
            { "name": "dojo", "location": "lib/dojo"},
            { "name": "mout", "location": "lib/mout/src"}
        ],
        "preloads": ["poly/array", "poly/object"]
    });
    curl(['wire!app/managementDashboard/spec']);
});

Gehan Gonsalkorale

unread,
Jun 24, 2013, 5:13:55 AM6/24/13
to cuj...@googlegroups.com
Got a bit further, however still not working and driving me a bit insane so going to stop now! Do you have a example repo of cram working I could base things off? Either I'm not getting it at all or it's rather brittle...

(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ cram static/app/dashboard.js
`baseUrl` resolved to static
`output` resolved to .cram/linked/bundle.js
Compiling preloads
Compiling modules
cram failed:  Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec
Error: Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at loadScriptViaRequire (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:1506:4)
    at Object.priv.core.loadScript (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:1488:11)
    at Object.core.fetchResDef (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:934:9)
    at Object.core.fetchDep (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:1017:10)
    at getDep (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:889:21)
    at Object.core.getDeps (/usr/local/lib/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:871:6)
(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ 

dashboard.js is:

define(['curl'], function(curl) {
    var config = {
        "baseUrl": "static",
    };
    curl(config, ['wire!app/managementDashboard/spec']);
});


The spec file exists:

static/app/managementDashboard/spec.js

Also all the mentioned modules are def present in the static directory

e.g.
static/lib/wire/wire.js

unscriptable

unread,
Jun 24, 2013, 1:57:35 PM6/24/13
to cuj...@googlegroups.com
Hey Gehan,

You've tried lots of different things.  Let me see if I can understand each scenario...


On Monday, June 24, 2013 4:51:01 AM UTC-4, Gehan Gonsalkorale wrote:
Hey finally got round to giving this a go...

However I still can't get it to run with a config file!

I installed via npm globally then tried running this:

cram static/app/managementDashboard/spec.js  build-options.json 

However I still just get this

cram failed:  Cannot find module 'build-options.json'

If build-options.json is in the current folder, node may not be able to find it.  Did you try specifying ./build-options.json ?

-- J

unscriptable

unread,
Jun 24, 2013, 2:04:30 PM6/24/13
to cuj...@googlegroups.com
Hey Gehan,

This looks like a cram bug.  Will fix asap.  -- J

unscriptable

unread,
Jun 24, 2013, 2:07:14 PM6/24/13
to cuj...@googlegroups.com
Hey Gehan,

I see you got around the missing curl.config bug in cram.  Cool.

The following error might be happening if you are using wire 0.9.x.  Have you upgraded to 0.10.x?  

-- John

Gehan Gonsalkorale

unread,
Jun 24, 2013, 3:31:21 PM6/24/13
to cuj...@googlegroups.com
./build-options didn't work, but it was fine with the full path. however requiring a full path seems a bit excessive..!

Not sure if using local cram is a problem but this still can't find build-options
 
(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ node_modules/.bin/cram ~/conversocial/static/app/dashboard.js  -c ./build-options.json 

But this can

(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ node_modules/.bin/cram ~/conversocial/static/app/dashboard.js  -c ~/conversocial/build-options.json 

Although cram then falls over here, mentioned in another post :)

cram failed:  Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec
Error: Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec

Gehan Gonsalkorale

unread,
Jun 24, 2013, 3:32:48 PM6/24/13
to cuj...@googlegroups.com
Yep I'm using wire 0.10.0!

Gehan Gonsalkorale

unread,
Jun 24, 2013, 3:44:19 PM6/24/13
to cuj...@googlegroups.com
Ok I wondered is there was a path problem causing this error

cram failed:  Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec
Error: Cannot find module 'static/lib/wire/wire' wire/wire!app/managementDashboard/spec

So I change the baseUrl to "./static" and now I have an error to do with the cjsm11 loader defined for backbone/knockback. 

cram failed:  ENOENT, open '/home/vagrant/conversocial/static/lib/knockback/knockback' curl/loader/cjsm11!knockback/knockback app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
Error: ENOENT, open '/home/vagrant/conversocial/static/lib/knockback/knockback' curl/loader/cjsm11!knockback/knockback app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec

If I remove the moduleLoader config bits then it has a problem with dojo I think?

Compiling modules
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 1 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 2 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 3 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 1 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 2 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 3 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.' ]
cram failed:  navigator is not defined dojo/i18n!./cldr/nls/number dojo/number app/managementDashboard/components/IncomingMessages/views/Graph wire/wire!app/managementDashboard/spec
ReferenceError: navigator is not defined dojo/i18n!./cldr/nls/number dojo/number app/managementDashboard/components/IncomingMessages/views/Graph wire/wire!app/managementDashboard/spec
    at /home/vagrant/conversocial/static/lib/dojo/_base/config.js:188:20
    at Object.core.executeDefFunc (/home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:804:23)
    at /home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:363:18
    at /home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:238:50
    at /home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:374:55
    at /home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:1202:29
    at then (/home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:175:49)
    at Promise.then (/home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:189:4)
    at when (/home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:214:26)
    at CurlApi.then.then.then (/home/vagrant/conversocial/node_modules/cram/amd_modules/curl/dist/curl-for-ssjs/curl.js:1199:4)

Gehan Gonsalkorale

unread,
Jun 24, 2013, 3:55:36 PM6/24/13
to cuj...@googlegroups.com
If I remove dojo then it fails on a module that doesn't actually exist (data/allSources.js). We actually define that module in a script tag in some server-generated html. Is there any way to tell cram to ignore it?

Anyway I can be told which files the warnings apply to? also what is the sync require problem exactly?

Getting further now at least! Albeit taking bits out :D

cram failed:  ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
Error: ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec

unscriptable

unread,
Jun 25, 2013, 8:00:01 AM6/25/13
to cuj...@googlegroups.com
Interesting. As you said, I wonder if this is a local cram problem.  I'll investigate. -- J

unscriptable

unread,
Jun 25, 2013, 8:20:47 AM6/25/13
to cuj...@googlegroups.com
Wow, you've got a lot going on here.

Unfortunately, I've just about given up on dojo until 1.9.  Supposedly, they're concentrating on better third-part AMD compatibility in 1.9.  A few of them have reached out to me to ask questions about the details of curl and cram to ensure dojo 1.9 is compatible.  

I wonder if it makes sense to use dojo's build tool to build the dojo-specific bits?  Does this sound like a reasonable option to you?

Ah, I see the immediate problem: the dojo/i18n module is executing code that relies on a browser environment when it is loaded.  While this isn't prohibited by the spec, it's widely regarded as a bad idea -- especially for plugins that may be loaded in non-browser environments.  We've been considering a change to cram to accommodate this type of bad behavior.  I can open an issue and probably get a fix in rather quickly.  

It's possible that the cjsm11 problem is also due to my insufficient testing of local cram.  I'll try it out later today.  

-- John

unscriptable

unread,
Jun 25, 2013, 8:39:16 AM6/25/13
to cuj...@googlegroups.com


On Monday, June 24, 2013 3:55:36 PM UTC-4, Gehan Gonsalkorale wrote:
If I remove dojo then it fails on a module that doesn't actually exist (data/allSources.js). We actually define that module in a script tag in some server-generated html. Is there any way to tell cram to ignore it?

It's recently documented. You can use `"excludes": ["data/allSources"]` in the build options file.


 

Anyway I can be told which files the warnings apply to? also what is the sync require problem exactly?

I'll see if I can figure out why cram isn't outputting the module id when it encounters a warning.

The sync require warning is probably due to cram's inability to detect a `define` signature correctly.  There are a few parsing bugs I recently fixed in my local sandbox.  It's possible that the modules are doing something whacky, too.  We'll be able to investigate better when I get the module ids to output.

-- John

Gehan Gonsalkorale

unread,
Jun 25, 2013, 9:21:16 AM6/25/13
to cuj...@googlegroups.com
Oh cool! I tried using a build options file. It works for using "baseUrl" but then it falls over when I try to use the "excludes" options. Here is my build options file

{
    "baseUrl": "./static",
    "excludes": [
        "data/allSources",
        "dojo"
    ]
}

It seems to not like having anything in the excludes array and only works if it's empty. If it has any options is has this error :)

(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ node_modules/.bin/cram static/app/dashboard.js ~/conversocial/build-options.json 
cram failed:  Cannot read property 'id' of undefined
TypeError: Cannot read property 'id' of undefined
    at compareNames (/home/vagrant/conversocial/node_modules/cram/lib/config/merge.js:83:42)
    at /home/vagrant/conversocial/node_modules/cram/lib/config/merge.js:66:9
    at Array.forEach (native)
    at /home/vagrant/conversocial/node_modules/cram/lib/config/merge.js:65:11
    at Array.forEach (native)
    at Object.mergeArrays [as arrays] (/home/vagrant/conversocial/node_modules/cram/lib/config/merge.js:63:7)
    at /home/vagrant/conversocial/node_modules/cram/cram.js:170:25
    at Array.reduce (native)
    at mergeConfigsOntoGrokResults (/home/vagrant/conversocial/node_modules/cram/cram.js:164:48)
    at /home/vagrant/conversocial/node_modules/cram/amd_modules/when/when.js:191:25



--
You received this message because you are subscribed to a topic in the Google Groups "cujojs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cujojs/CGW52iV5MJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cujojs+un...@googlegroups.com.
To post to this group, send email to cuj...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs.
To view this discussion on the web visit https://groups.google.com/d/msgid/cujojs/9b73928f-d592-47a4-8dcc-df41183e60b7%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

Gehan Gonsalkorale

unread,
Jun 25, 2013, 9:30:15 AM6/25/13
to cuj...@googlegroups.com
Ok I see it's a config merge problem. If I add a empty excludes array to dashboard.js then it runs again!

However it seems to ignore my excludes list  now, whether its in the run.js or the build options

build-options.json is now:

{
    "baseUrl": "./static",
    "excludes": [
        "data/allSources"
    ]
}

Running cram results in:

Running "shell:cram" (shell) task
`baseUrl` resolved to /home/vagrant/conversocial/static
`output` resolved to .cram/linked/bundle.js
Compiling preloads
Compiling modules
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 1 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 2 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 3 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 0 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 1 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 2 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]
warning: sync require() found in the global scope or in an external factory. 3 [ 'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.',
  'sync require() found in the global scope or in an external factory.' ]

unscriptable

unread,
Jun 25, 2013, 10:38:02 AM6/25/13
to cuj...@googlegroups.com
Sorry for pushing out a new feature without tests.  I totally fail.

I have pushed some fixes for this merge bug (as well as some other fixes) to the dev branch on github.  I'll be testing it later, but if you're feeling lucky, you could try it out.

-- John

Gehan Gonsalkorale

unread,
Jun 25, 2013, 10:45:45 AM6/25/13
to cuj...@googlegroups.com
Cool, would that also fix the next problem I mentioned after I got it working?


unscriptable

unread,
Jun 25, 2013, 11:54:18 AM6/25/13
to cuj...@googlegroups.com
It should, iiuc. -- J

Gehan Gonsalkorale

unread,
Jun 25, 2013, 12:22:17 PM6/25/13
to cuj...@googlegroups.com
As in this error? I'll try anyway!

cram failed:  Cannot read property 'id' of undefined
TypeError: Cannot read property 'id' of undefined

Gehan Gonsalkorale

unread,
Jun 25, 2013, 12:27:43 PM6/25/13
to cuj...@googlegroups.com
I tried the dev branch. Config merge is fine and warnings print out where now which is good! However my exclude lists doesn't seem to work:

build-options.json

{
    "baseUrl": "./static",
    "excludes": [
        "data/allSources"
    ]
}


output:

Compiling preloads
Compiling modules
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [backbone/backbone] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [knockback/knockback] sync require() found in the global scope or in an external factory.
warning: [backbone/backbone] sync require() found in the global scope or in an external factory.
cram failed:  ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
Error: ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec

Gehan Gonsalkorale

unread,
Jul 16, 2013, 8:00:16 AM7/16/13
to cuj...@googlegroups.com
Hi

Just wondering about the exclude options problem I'm having below, can you reproduce it? ie the exclude list doesn't seem to do anything

Gehan
To unsubscribe from this group and all its topics, send an email to cujojs+unsubscribe@googlegroups.com.

To post to this group, send email to cuj...@googlegroups.com.
Visit this group at http://groups.google.com/group/cujojs.

unscriptable

unread,
Jul 16, 2013, 10:45:50 AM7/16/13
to cuj...@googlegroups.com
Hey Gehan,

Sorry. Got distracted on other things.

I just pushed a new version to the dev branch.  It now processes excludes just like it processes other command-line and build_options configuration options.

Care to try it?

-- John

Gehan Gonsalkorale

unread,
Jul 24, 2013, 5:15:27 AM7/24/13
to cuj...@googlegroups.com
Doesn't seems to have done anything :( I still get this

cram failed:  ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
Error: ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec

Where I have set build-options as

{
    "baseUrl": "./static",
    "excludes": [
        "data/allSources"
    ]
}


Gehan Gonsalkorale

unread,
Jul 31, 2013, 8:28:21 AM7/31/13
to cuj...@googlegroups.com
I tried using the command line option, using every path I can think of but still get the below!

cram failed:  ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
Error: ENOENT, open '/home/vagrant/conversocial/static/data/allSources.js' data/allSources app/managementDashboard/components/SLA/viewmodels/SLA app/managementDashboard/components/SLA/viewmodels/SLAList wire/wire!app/managementDashboard/spec
(conversocial)vagrant@vagrant-ubuntu:~/conversocial$ node_modules/.bin/cram static/app/dashboard.js ~/conversocial/build-options.json --exclude data/allSources

I'm doing this in one of the files, if it helps

allSources = require 'data/allSources'

Any ideas welcome as we will soon be wanting to put some wire stuff into production and at the moment we can't optimise it! :(

Gehan Gonsalkorale

unread,
Jul 31, 2013, 9:49:43 AM7/31/13
to cuj...@googlegroups.com
I'm having a poke through the code, the excludes are added to the excludesIds map properly. However what does that actually do - am I misunderstanding what excludes does?

I'm assuming that no matter where the modules is required, be in in a define() or an inline require(), that that module id should be ignored by cram if it's in the exclude list. We define some modules dynamically, and we want to exclude dojo too, so it's quite essential for us! :)

I've got into cram/lib/compile.js, and I can get the build to go further if I ignore modules by intercepting them at the top of the compile function :D. Even thought data/allSources is in the excludes list it still gets passed through to compile(). I don't know if returning here is a good idea but it gets further.

function compile (ids, io, parentCtx) {

return when.map(ids, function (id) {
var plugin, read, write, parse, deps, absId, tasks;

absId = parentCtx.toAbsId(id);
if (absId.substr(0,5) == 'data/' || absId.substr(0,7) == 'config/' || absId.substr(0,5) == 'dojo/') {
return;
}




On Wednesday, 24 July 2013 10:15:27 UTC+1, Gehan Gonsalkorale wrote:

Gehan Gonsalkorale

unread,
Jul 31, 2013, 1:14:16 PM7/31/13
to cuj...@googlegroups.com
Ok guys I got something working as an example: https://github.com/gehan/cram/pull/1

I didn't dig too deep into cram but this seems to do the job. I assume there is a place where you combine depList and requires, which would be a better place to do the excludes :)

I did have a problem where cram got into a look and I had to exclude an extra module..

Also using the cjs module loader doesn't work - "moduleLoader": "curl/loader/cjsm11"

Gehan Gonsalkorale

unread,
Jul 31, 2013, 1:15:13 PM7/31/13
to cuj...@googlegroups.com
Sorry I meant this PR - https://github.com/cujojs/cram/pull/23

Gehan Gonsalkorale

unread,
Jul 31, 2013, 1:29:36 PM7/31/13
to cuj...@googlegroups.com
Sorry for the spam, however I've realised that doesn't work. It doesn't try to include the file in the bundle, but it also completely ignores it in the module definition output.!

e.g. i excluded backbone and got this

define('app/Agent', ['lodash/lodash.compat'], function (Backbone, _)

instead of :

define('app/Agent', ['backbone', 'lodash/lodash.compat'], function (Backbone, _)

oops.

Gehan Gonsalkorale

unread,
Jul 31, 2013, 7:46:13 PM7/31/13
to cuj...@googlegroups.com
Ok I finally figured out what was happening and understand how this excludes business works!

As I understand it, cram runs a compile step which steps through all the modules from the source and writes load of meta data about each module in .cram/meta. However, if you are excluding a module then this step still happens and the source file is still read, as the excluding of modules is actually done during the link step. 

This means however if you are excluding a module because it doesn't exist as a file, then it'll try to read it anyway and then explode when it can't find it! It may sounds odd that you'd have modules that don't exist as files, it's just at the moment we write a config module dynamically which contains config info and is written to the first template.

The options then are to create blank files for the modules that don't exist but will be excluded, or deal with this in the compile step. I updated the pull req to show my changes. It feels a bit wrong but if a module is in the exclude list then it returns it's contents as ''


I'm sure there is a better way but excluding the module outright in compile causes problems as then its meta data doesn't exist and the linking goes a bit pear shaped.

Anyway, let me know your thoughts! At least I can use cram, albeit my fork of it :)
Reply all
Reply to author
Forward
0 new messages