Skip to content

Commit

Permalink
0.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Aug 2, 2014
1 parent 14ce7dc commit 2d456d3
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 94 deletions.
32 changes: 20 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ Spec-compliant universal module loader - loads ES6 modules, AMD, CommonJS and gl

Designed as a collection of small extensions to the ES6 specification System loader, which can also be applied individually.

* Loads any module format, by detecting the format automatically. Modules can also [specify their format with meta syntax](#meta-configuration).
* Loads any module format, by detecting the format automatically. Modules can also [specify their format with meta config](#meta-configuration).
* Provides comprehensive and exact replications of AMD, CommonJS and ES6 circular reference handling.
* Loads [ES6 modules compiled into the `System.register` form for production](#es6-systemregister-compilation), maintaining full circular references support.
* Supports RequireJS-style [map](#map-configuration), [paths](https://github.com/ModuleLoader/es6-module-loader#paths-implementation), [bundles](#bundles), [shim](#global-module-format-support) and [plugins](#plugins).
* Tracks package versions, and resolves semver-compatibile requests through [package version syntax](#versions) - `package@x.y.z`, `package^@x.y.z`.
* [Loader plugins](#plugins) allow loading assets through the module naming system such as CSS, JSON or images.

Designed to work with the [ES6 Module Loader polyfill](https://github.com/ModuleLoader/es6-module-loader) (9KB) for a combined total footprint of 16KB minified and gzipped. In future, with native implementations, the ES6 Module Loader polyfill should no longer be necessary. As jQuery provides for the DOM, this library can smooth over inconsistiencies and missing practical functionality provided by the native System loader.
Designed to work with the [ES6 Module Loader polyfill](https://github.com/ModuleLoader/es6-module-loader) (8KB) for a combined total footprint of 16KB minified and gzipped. In future, with native implementations, the ES6 Module Loader polyfill should no longer be necessary. As jQuery provides for the DOM, this library can smooth over inconsistiencies and missing practical functionality provided by the native System loader.

Runs in IE8+ and NodeJS. ES6 modules are only supported in IE9+.
Runs in IE8+ and NodeJS.

For discussion, [see the Google Group](https://groups.google.com/group/systemjs).

Expand All @@ -23,7 +23,7 @@ Basic Configuration

### Setup

Download [`es6-module-loader.js`](https://github.com/ModuleLoader/es6-module-loader/blob/v0.7.1/dist/es6-module-loader.js) and [`traceur.js`](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.49/traceur.js) and locate them in the same folder as `system.js` from this repo.
Download [`es6-module-loader.js`](https://github.com/ModuleLoader/es6-module-loader/blob/v0.7.2/dist/es6-module-loader.js) and [`traceur.js`](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.51/traceur.js) and locate them in the same folder as `system.js` from this repo.

We then include `dist/system.js` with a script tag in the page.

Expand Down Expand Up @@ -52,12 +52,8 @@ index.html:
});
System.import('app/app')
.catch(function(e) {
// we add this since promises suppress all errors
setTimeout(function() {
throw e;
});
});
// we add this since promises suppress all errors
.catch(console.error.bind(console));
</script>
```

Expand Down Expand Up @@ -231,6 +227,8 @@ In IE8, automatic global detection does not work for globals declared as variabl
anotherGlobal = 'unless using an explicit shim';
```

IF IE8 support is needed, these exports will need to be declared manually with configuration.

### Versions

An optional syntax for version support can be used: `moduleName@version`.
Expand Down Expand Up @@ -317,7 +315,6 @@ Additional Plugins:

Creating custom plugins can be quite simple. See the plugins above, and [read the guide here](https://github.com/systemjs/systemjs/wiki/Creating-a-Plugin).


### ES6 System.register Compilation

If writing an application in ES6, we can compile into ES5 with Traceur:
Expand All @@ -334,7 +331,7 @@ This will compile all ES6 files in the directory `app` into corresponding ES5 `S

The `instantiate` modules option writes the modules out using a `System.register` call, which is supported by SystemJS.

Then include [`traceur-runtime.js`](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.49/traceur-runtimr.js) (also found inside traceur's `bin` folder when installed via npm) before es6-module-loader.js:
Then include [`traceur-runtime.js`](https://raw.githubusercontent.com/jmcriffey/bower-traceur/0.0.51/traceur-runtimr.js) (also found inside traceur's `bin` folder when installed via npm) before es6-module-loader.js:

```html
<script src="traceur-runtime.js"></script>
Expand Down Expand Up @@ -411,6 +408,17 @@ To make all module formats work with CSP, we need to ensure everything is built

See [SystemJS Builder](https://github.com/systemjs/builder) for a single-file build workflow that can wrap up all module formats.

### RequireJS Support

To use SystemJS side-by-side in a RequireJS project, make sure to include RequireJS before SystemJS.

Conversely, to have SystemJS provide a RequireJS-like API in an application set:

```javascript
window.define = loader.amdDefine;
window.require = window.requirejs = loader.amdRequire;
```

### NodeJS Usage

To load modules in NodeJS, install SystemJS with:
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "system.js",
"version": "0.6.7",
"version": "0.6.8",
"dependencies": {
"es6-module-loader": "~0.7.1"
"es6-module-loader": "~0.7.2"
},
"devDependencies": {
"qunit": "~1.12.0"
Expand Down
76 changes: 37 additions & 39 deletions dist/system-production-csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ function scriptLoader(loader) {
// call this functione everytime a wrapper executes
loader.onScriptLoad = function() {};

loader.amdDefine = true;

// override fetch to use script injection
loader.fetch = function(load) {
return new Promise(function(resolve, reject) {
Expand Down Expand Up @@ -1169,9 +1167,6 @@ function amd(loader) {

// by default we only enforce AMD noConflict mode in Node
var isNode = typeof module != 'undefined' && module.exports;

if (loader.amdDefine == undefined)
loader.amdDefine = false;

// AMD Module Format Detection RegEx
// define([.., .., ..], ...)
Expand Down Expand Up @@ -1213,7 +1208,7 @@ function amd(loader) {

/*
AMD-compatible require
To copy RequireJS, set window.require = window.requirejs = loader.require
To copy RequireJS, set window.require = window.requirejs = loader.amdRequire
*/
function require(names, callback, errback, referer) {
// 'this' is bound to the loader
Expand All @@ -1240,7 +1235,7 @@ function amd(loader) {
else
throw 'Invalid require';
};
loader.require = require;
loader.amdRequire = require;

function makeRequire(parentName, staticRequire, loader) {
return function(names, callback, errback) {
Expand All @@ -1250,30 +1245,8 @@ function amd(loader) {
}
}

var anonDefine;
// set to true of the current module turns out to be a named define bundle
var defineBundle;

var oldModule, oldExports, oldDefine;

function createDefine(loader) {
anonDefine = null;
defineBundle = null;

// ensure no NodeJS environment detection

var global = loader.global;

oldModule = global.module;
oldExports = global.exports;
oldDefine = global.define;

global.module = undefined;
global.exports = undefined;

if (global.define && global.define.loader == loader)
return;

// run once per loader
function generateDefine(loader) {
// script injection mode calls this function synchronously on load
var onScriptLoad = loader.onScriptLoad;
loader.onScriptLoad = function(load) {
Expand Down Expand Up @@ -1311,8 +1284,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
deps.splice(requireIndex, 1);
deps.splice(requireIndex, 1);

var factoryText = factory.toString();

Expand Down Expand Up @@ -1388,10 +1361,38 @@ function amd(loader) {
loader.register(name, define.deps, false, define.execute);
}
};
define.amd = {};
loader.amdDefine = define;
}

var anonDefine;
// set to true if the current module turns out to be a named define bundle
var defineBundle;

var oldModule, oldExports, oldDefine;

// adds define as a global (potentially just temporarily)
function createDefine(loader) {
if (!loader.amdDefine)
generateDefine(loader);

anonDefine = null;
defineBundle = null;

// ensure no NodeJS environment detection
var global = loader.global;

oldModule = global.module;
oldExports = global.exports;
oldDefine = global.define;

global.define = define;
global.define.amd = {};
global.define.loader = loader;
global.module = undefined;
global.exports = undefined;

if (global.define && global.define === loader.amdDefine)
return;

global.define = loader.amdDefine;
}

function removeDefine(loader) {
Expand Down Expand Up @@ -1443,9 +1444,6 @@ function amd(loader) {
throw e;
}

if (loader.amdDefine === false)
removeDefine(loader);

if (!anonDefine && !defineBundle && !isNode)
throw "AMD module " + load.name + " did not define";

Expand Down
2 changes: 1 addition & 1 deletion dist/system-production-csp.min.js

Large diffs are not rendered by default.

74 changes: 37 additions & 37 deletions dist/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -1105,9 +1105,6 @@ function amd(loader) {

// by default we only enforce AMD noConflict mode in Node
var isNode = typeof module != 'undefined' && module.exports;

if (loader.amdDefine == undefined)
loader.amdDefine = false;

// AMD Module Format Detection RegEx
// define([.., .., ..], ...)
Expand Down Expand Up @@ -1149,7 +1146,7 @@ function amd(loader) {

/*
AMD-compatible require
To copy RequireJS, set window.require = window.requirejs = loader.require
To copy RequireJS, set window.require = window.requirejs = loader.amdRequire
*/
function require(names, callback, errback, referer) {
// 'this' is bound to the loader
Expand All @@ -1176,7 +1173,7 @@ function amd(loader) {
else
throw 'Invalid require';
};
loader.require = require;
loader.amdRequire = require;

function makeRequire(parentName, staticRequire, loader) {
return function(names, callback, errback) {
Expand All @@ -1186,30 +1183,8 @@ function amd(loader) {
}
}

var anonDefine;
// set to true of the current module turns out to be a named define bundle
var defineBundle;

var oldModule, oldExports, oldDefine;

function createDefine(loader) {
anonDefine = null;
defineBundle = null;

// ensure no NodeJS environment detection

var global = loader.global;

oldModule = global.module;
oldExports = global.exports;
oldDefine = global.define;

global.module = undefined;
global.exports = undefined;

if (global.define && global.define.loader == loader)
return;

// run once per loader
function generateDefine(loader) {
// script injection mode calls this function synchronously on load
var onScriptLoad = loader.onScriptLoad;
loader.onScriptLoad = function(load) {
Expand Down Expand Up @@ -1247,8 +1222,8 @@ function amd(loader) {
var requireIndex, exportsIndex, moduleIndex;

if ((requireIndex = indexOf.call(deps, 'require')) != -1) {
deps.splice(requireIndex, 1);
deps.splice(requireIndex, 1);

var factoryText = factory.toString();

Expand Down Expand Up @@ -1324,10 +1299,38 @@ function amd(loader) {
loader.register(name, define.deps, false, define.execute);
}
};
define.amd = {};
loader.amdDefine = define;
}

var anonDefine;
// set to true if the current module turns out to be a named define bundle
var defineBundle;

var oldModule, oldExports, oldDefine;

// adds define as a global (potentially just temporarily)
function createDefine(loader) {
if (!loader.amdDefine)
generateDefine(loader);

anonDefine = null;
defineBundle = null;

// ensure no NodeJS environment detection
var global = loader.global;

oldModule = global.module;
oldExports = global.exports;
oldDefine = global.define;

global.define = define;
global.define.amd = {};
global.define.loader = loader;
global.module = undefined;
global.exports = undefined;

if (global.define && global.define === loader.amdDefine)
return;

global.define = loader.amdDefine;
}

function removeDefine(loader) {
Expand Down Expand Up @@ -1379,9 +1382,6 @@ function amd(loader) {
throw e;
}

if (loader.amdDefine === false)
removeDefine(loader);

if (!anonDefine && !defineBundle && !isNode)
throw "AMD module " + load.name + " did not define";

Expand Down
2 changes: 1 addition & 1 deletion dist/system.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "systemjs",
"version": "0.6.7",
"version": "0.6.8",
"description": "System loader extension for flexible AMD & CommonJS support",
"main": "dist/system.js",
"repository": {
Expand All @@ -10,7 +10,7 @@
"author": "Guy Bedford",
"license": "MIT",
"dependencies": {
"es6-module-loader": "~0.7.1"
"es6-module-loader": "~0.7.2"
},
"devDependencies": {
"qunit": "^0.6.2",
Expand Down

0 comments on commit 2d456d3

Please sign in to comment.