caolan/jam — pull request #135 by maxpeterson (2013-03-18 15:44:04+00:00)
Title: Add shim to compile optimiser config (with test).

This is the same issue as caolan/jam/#113 with the addition of a test.

>Issue: the compile command currently doesn't include shim config the project is using, so optimized output breaks
>Solution: include shim config from jam/require.config.js in the optimize call

The crux of this issue is that if you use shim to define that a package `exports` a variable (e.g. Backbone or in mytest PackageOne) then this shim is needed by require's optimiser to defines the package such that it returns the exported variable.

My test includes a module with main.js:

var PackageOne = {
name: 'Package One'
}

and package.js:

{
"name": "package-one",
"version": "0.0.1",
"description": "Test package one shim",
"jam": {
"shim": {
"exports": "PackageOne"
}
}
}

If the shim is not passed to the optimiser then it will define `package-one/main` as:

`define("package-one/main",function(){})`

If shim is passed to the optimiser then it will define `package-one/main` as:

`define("package-one/main",function(e){return function(){var t,n;return t||e.PackageOne}}(this));`

In both cases `package-one` is defined as

`define("package-one",["package-one/main"],function(e){return e})`

The result is that without the shim any package that requires `package-one` as a dependency will not get passed PackageOne:

define('mypackage', ['package-one'], function (one) {
// one will only be defined as PackageOne if shim is included
}

In addition I fixed some typos in the other integration tests,