CanJS AMD Build

I’m trying to make an AMD build of canjs 3.0 by modifying the build script. Here’s what I’ve got so far:

var stealTools = require('steal-tools');
var globalJS = require('steal-tools/lib/build/helpers/global').js;
var amdJS = require('steal-tools/lib/build/helpers/amd');
var baseNormalize = globalJS.normalize();
stealTools.export({
    system: {
        config: __dirname + '/package.json!npm',
        main: 'can/all'
    },
    options: {
        useNormalizedDependencies: false,
        verbose: true
    },
    outputs: {
        'all': {
            modules: ['can/all'],
            format: 'amd',
            dest: amdJS.dest({}, __dirname + '/dist/amd'),
            useNormalizedDependencies: true,
            normalize: function (depName, depLoad, curName, curLoad, loader) {
                return baseNormalize.call(this, depName, depLoad, curName, curLoad, loader, true);
            },
            // ignore jquery
            ignore: [function (name) {
                if (name.indexOf('jquery') === 0 || name.indexOf('kefir') === 0) {
                    return true;
                } else {
                    return false;
                }
            }],
            removeDevelopmentCode: false
        }
    }
}).catch(function (e) {

    setTimeout(function () {
        throw e;
    }, 1);

});

This isn’t working at the moment though, so I’ve also tried using the +amd helper in steal-tools. This results in a call stack exceeded error. So I’m not sure what’s going on here.

You probably also need to update it to use the AMD version of normalize instead of return baseNormalize.call(. I’m not sure this will solve your problem though.

I tried setting that to the amd’s normalize, but there were still errors. From what I read in the docs, using the +amd tag should set up the output object to use the correct functions, but it results in this error message…do you know why this would happen? A steal-tools bug?

C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs>node build
  added helpers: amd
OPENING: can/all
-local+ npm
..........
-local+ can-fixture@1.0.11#helpers/getid
OUTPUT: +amd
Transpiling...
Output Modules:
+ can@3.3.0#all
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\all.js
Transpiling...
Output Modules:
+ can@3.3.0#can
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\can.js
Transpiling...
Output Modules:
+ can@3.3.0#ecosystem
> C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\dist\amd\ecosystem.js
Potentially unhandled rejection [1] RangeError: Maximum call stack size exceeded

    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5
    at Array.forEach (native)
    at visit (C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\
steal-tools\lib\graph\each_dependencies.js:19:22)
    at C:\www\gis\static_apps\cmv-app\viewer\js\bower\canjs\node_modules\steal-t
ools\lib\graph\each_dependencies.js:20:5

Here’s the script to produce this error:

var stealTools = require('steal-tools');
stealTools.export({
    system: {
        config: __dirname + '/package.json!npm',
        main: 'can/all'
    },
    options: {
        useNormalizedDependencies: false,
        verbose: true
    },
    outputs: {
        '+amd': {
            modules: ['can/all'],
            format: 'amd',
            useNormalizedDependencies: true,
            // ignore jquery
            ignore: [function (name) {
                if (name.indexOf('jquery') === 0 || name.indexOf('kefir') === 0) {
                    return true;
                } else {
                    return false;
                }
            }],
            removeDevelopmentCode: false
        }
    }
}).catch(function (e) {

    setTimeout(function () {
        throw e;
    }, 1);

});

Hey @roemhildtg, did you figure out the issue or a workaround?

@chasen I didn’t figure this out yet. In the meantime I’m just using steal to load my canjs app.

@roemhildtg Would you mind filing a bug in steal-tools on that. I don’t see anything in your code that should trigger a maximum call stack.

@matthewp, sure no problem. Here’s the issue I created: https://github.com/stealjs/steal-tools/issues/582

Would that be cause by a circular dependency tree?