Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

Commit

Permalink
version 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MacRusher committed Jul 14, 2015
1 parent f967b8a commit b578265
Show file tree
Hide file tree
Showing 12 changed files with 316 additions and 164 deletions.
1 change: 0 additions & 1 deletion .npm/package/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions .npm/package/README

This file was deleted.

7 changes: 0 additions & 7 deletions .npm/package/npm-shrinkwrap.json

This file was deleted.

12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@

## 0.2
## 0.3

### 0.2.1
- Update SystemJS to 0.18.4
- Remove dependency on xhr2
- Use `meteor://` protocol on modules
- Alternative import name `foomodule.import` to allow TypeScript support
- Improve error reporting

## 0.2.1

- Update babel-compiler to 5.6.15

### 0.2.0
## 0.2.0

- Switch to MDG Babel compiler package

Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All `*.import.js` files **have full ES6 support** provided by Meteor's Babel.js
API is compatible with new ES6 modules spec.
Under the hood [Babel.js](https://babeljs.io) and [SystemJS](https://github.com/systemjs/systemjs) take care of everything, so you can use modules today!

This package adds SystemJS to your project.
*This package adds SystemJS to your project.*

## Benefits of this approach

Expand Down Expand Up @@ -48,7 +48,7 @@ If you want to see it in action, see our todo example app:

You can also check out great `meteor-react-example` app by [optilude](https://github.com/optilude).

- Source code: https://github.com/optilude/meteor-react-example/tree/modules
- Source code: https://github.com/optilude/meteor-react-example


### Basic usage
Expand Down Expand Up @@ -126,12 +126,11 @@ You can set alternative name for a module, below is an example from `universe:re

## Troubleshooting

- `Uncaught SyntaxError: Unexpected token <` or `Potentially unhandled rejection [2] Uncaught SyntaxError: Unexpected token <`
#### `[Universe Modules]: Module XXX does not exist!`

You misspelled import name/path. SystemJS tries to download this file from remote location and fails.

Check if all files are at their location and import paths are OK.
You'll find misspelled code in the error stack trace.



Expand Down
3 changes: 3 additions & 0 deletions build-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var handler = function (compileStep) {
moduleId = compileStep.packageName + '/' + moduleId;
}

// add meteor:// protocol to unify behavior between client/server/packages
moduleId = 'meteor://' + moduleId;

var extraWhitelist = ['es6.modules'];
if(path[1] === 'jsx'){
extraWhitelist.push('react');
Expand Down
14 changes: 5 additions & 9 deletions package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'universe:modules',
version: '0.2.1',
version: '0.3.0',
summary: 'Use ES6 / ES2015 modules in Meteor with SystemJS!',
git: 'https://github.com/vazco/universe-modules',
documentation: 'README.md'
Expand All @@ -12,20 +12,16 @@ Package.registerBuildPlugin({
sources: ['build-plugin.js']
});

Npm.depends({
'xhr2': '0.1.2'
});

Package.onUse(function (api) {

// We need XMLHttpRequest on the server side for SystemJS remote fetching (or SystemJS won't run)
// This may change in near future if we find better way to run SystemJS
api.addFiles('vendor/xhr2.js', 'server');
// we need this for System.js to run on the server side without core changes
api.addFiles('require-polyfill.js', 'server');

// Load SystemJS
api.addFiles([
'vendor/system-polyfills.js',
'vendor/system.js' // There is a core change in this file! Meteor uses `Npm.require` instead of `require`
'vendor/system.js',
'system-config.js'
]);

});
Expand Down
1 change: 1 addition & 0 deletions require-polyfill.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require = Npm.require;
89 changes: 89 additions & 0 deletions system-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// backup original SystemJS methods
var _System = {
normalize: System.normalize,
locate: System.locate,
fetch: System.fetch,
translate: System.translate,
instantiate: System.instantiate
};

System.baseURL = 'meteor://';
System.config({
meta: {
'meteor://*': {
format: 'register'
}
}
});

/*
* name: the unnormalized module name
* parentName: the canonical module name for the requesting module
* parentAddress: the address of the requesting module
*/
System.normalize = function (name, parentName, parentAddress) {
// add meteor prefix
if (name[0] !== '.' && name[0] !== '/' && name.indexOf('://') === -1) {
name = 'meteor://' + name;
}

// allow foomodule.import syntax in import name
if (name.slice(-7) === '.import') {
name = name.slice(0, -7);
}

// load original normalize
return _System.normalize.call(this, name, parentName, parentAddress);
};

/*
* load.name the canonical module name
* load.metadata a metadata object that can be used to store
* derived metadata for reference in other hooks
*/
//System.locate = function (load) {
// return _System.locate.call(this, load);
//};

/*
* load.name: the canonical module name
* load.address: the URL returned from locate
* load.metadata: the same metadata object by reference, which
* can be modified
*/
System.fetch = function (load) {
var promise = _System.fetch.call(this, load);

if (!promise) {
// not really a promise
return promise;
}

if(load.name.slice(0, 9) !== 'meteor://'){
// not our protocol, ignore
return promise;
}

// show our warning
return promise.catch(function (err) {
console.warn('[Universe Modules]: Module ' + load.name.slice(9) + ' does not exist! You will probably see other errors in the console because of that.');
});
};

/*
* load.name
* load.address
* load.metadata
* load.source: the fetched source
*/
//System.translate = function (load) {
// return _System.translate.call(this, load);
//};

/*
* load identical to previous hooks, but load.source
* is now the translated source
*/
//System.instantiate = function (load) {
// return _System.instantiate.call(this, load);
//};
130 changes: 66 additions & 64 deletions vendor/system-polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,75 @@
* SystemJS Polyfills for URL and Promise providing IE8+ Support
*/
// from https://gist.github.com/Yaffle/1088850
function URLPolyfill(url, baseURL) {
if (typeof url != 'string')
throw new TypeError('URL must be a string');
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
var protocol = m[1] || "";
var username = m[2] || "";
var password = m[3] || "";
var host = m[4] || "";
var hostname = m[5] || "";
var port = m[6] || "";
var pathname = m[7] || "";
var search = m[8] || "";
var hash = m[9] || "";
if (baseURL !== undefined) {
var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL);
var flag = protocol === "" && host === "" && username === "";
if (flag && pathname === "" && search === "") {
search = base.search;
}
if (flag && pathname.charAt(0) !== "/") {
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
(function(global) {
function URLPolyfill(url, baseURL) {
if (typeof url != 'string')
throw new TypeError('URL must be a string');
var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@\/?#]*)(?::([^:@\/?#]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
if (!m) {
throw new RangeError();
}
// dot segments removal
var output = [];
pathname.replace(/^(\.\.?(\/|$))+/, "")
.replace(/\/(\.(\/|$))+/g, "/")
.replace(/\/\.\.$/, "/../")
.replace(/\/?[^\/]*/g, function (p) {
if (p === "/..") {
output.pop();
} else {
output.push(p);
}
});
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
if (flag) {
port = base.port;
hostname = base.hostname;
host = base.host;
password = base.password;
username = base.username;
}
if (protocol === "") {
protocol = base.protocol;
var protocol = m[1] || "";
var username = m[2] || "";
var password = m[3] || "";
var host = m[4] || "";
var hostname = m[5] || "";
var port = m[6] || "";
var pathname = m[7] || "";
var search = m[8] || "";
var hash = m[9] || "";
if (baseURL !== undefined) {
var base = baseURL instanceof URLPolyfill ? baseURL : new URLPolyfill(baseURL);
var flag = protocol === "" && host === "" && username === "";
if (flag && pathname === "" && search === "") {
search = base.search;
}
if (flag && pathname.charAt(0) !== "/") {
pathname = (pathname !== "" ? (((base.host !== "" || base.username !== "") && base.pathname === "" ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + pathname) : base.pathname);
}
// dot segments removal
var output = [];
pathname.replace(/^(\.\.?(\/|$))+/, "")
.replace(/\/(\.(\/|$))+/g, "/")
.replace(/\/\.\.$/, "/../")
.replace(/\/?[^\/]*/g, function (p) {
if (p === "/..") {
output.pop();
} else {
output.push(p);
}
});
pathname = output.join("").replace(/^\//, pathname.charAt(0) === "/" ? "/" : "");
if (flag) {
port = base.port;
hostname = base.hostname;
host = base.host;
password = base.password;
username = base.username;
}
if (protocol === "") {
protocol = base.protocol;
}
}
}

// convert windows file URLs to use /
if (protocol == 'file:')
pathname = pathname.replace(/\\/g, '/');

this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
this.protocol = protocol;
this.username = username;
this.password = password;
this.host = host;
this.hostname = hostname;
this.port = port;
this.pathname = pathname;
this.search = search;
this.hash = hash;
}
(typeof self != 'undefined' ? self : global).URLPolyfill = URLPolyfill;!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
// convert windows file URLs to use /
if (protocol == 'file:')
pathname = pathname.replace(/\\/g, '/');

this.origin = protocol + (protocol !== "" || host !== "" ? "//" : "") + host;
this.href = protocol + (protocol !== "" || host !== "" ? "//" : "") + (username !== "" ? username + (password !== "" ? ":" + password : "") + "@" : "") + host + pathname + search + hash;
this.protocol = protocol;
this.username = username;
this.password = password;
this.host = host;
this.hostname = hostname;
this.port = port;
this.pathname = pathname;
this.search = search;
this.hash = hash;
}
global.URLPolyfill = URLPolyfill;
})(typeof self != 'undefined' ? self : global);!function(e){"object"==typeof exports?module.exports=e():"function"==typeof define&&define.amd?define(e):"undefined"!=typeof window?window.Promise=e():"undefined"!=typeof global?global.Promise=e():"undefined"!=typeof self&&(self.Promise=e())}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
/** @license MIT License (c) copyright 2010-2014 original author or authors */
/** @author Brian Cavalier */
/** @author John Hann */
Expand Down
Loading

0 comments on commit b578265

Please sign in to comment.