Skip to content

Commit

Permalink
6.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldenning committed Feb 1, 2020
1 parent a2dc029 commit c0a3aa2
Show file tree
Hide file tree
Showing 17 changed files with 234 additions and 223 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
SystemJS 6.2.0
* Adding new createScript / fetch / shouldFetch hooks (https://github.com/systemjs/systemjs/pull/2058)
* Fixing race conditions with named register modules (https://github.com/systemjs/systemjs/pull/2114)

SystemJS 6.1.10
* Fixing bug where named AMD modules were instantiated twice (https://github.com/systemjs/systemjs/pull/2104)
* Save bytes with setTimeout (https://github.com/systemjs/systemjs/pull/2105)
Expand Down
19 changes: 10 additions & 9 deletions dist/extras/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,23 +83,27 @@
if (tmpRegister)
return tmpRegister;

const _firstNamedDefine = firstNamedDefine;
firstNamedDefine = null;

const register = getRegister.call(this);
// if its an actual System.register leave it
if (register && register[1] === lastRegisterDeclare)
return register;

const _amdDefineDeps = amdDefineDeps;
amdDefineDeps = null;

// If the script registered a named module, return that module instead of re-instantiating it.
if (firstNamedDefine)
return firstNamedDefine;
if (_firstNamedDefine)
return _firstNamedDefine;

// otherwise AMD takes priority
// no registration -> attempt AMD detection
if (!amdDefineDeps)
if (!_amdDefineDeps)
return register || emptyInstantiation;

const registration = createAMDRegister(amdDefineDeps, amdDefineExec);
amdDefineDeps = null;
return registration;
return createAMDRegister(_amdDefineDeps, amdDefineExec);
};
let amdDefineDeps, amdDefineExec;
global.define = function (name, deps, execute) {
Expand Down Expand Up @@ -141,9 +145,6 @@
function addToRegisterRegistry(name, define) {
if (!firstNamedDefine) {
firstNamedDefine = define;
setTimeout(function () {
firstNamedDefine = null;
});
}

// We must call System.getRegister() here to give other extras, such as the named-exports extra,
Expand Down
2 changes: 1 addition & 1 deletion dist/extras/amd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/extras/amd.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 81 additions & 81 deletions dist/extras/module-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,92 @@
const systemJSPrototype = global.System.constructor.prototype;
const instantiate = systemJSPrototype.instantiate;

systemJSPrototype.instantiate = function (url, parent) {
const loader = this;
const moduleTypesRegEx = /\.(css|html|json|wasm)$/;
systemJSPrototype.shouldFetch = function (url) {
const path = url.split('?')[0].split('#')[0];
const ext = path.slice(path.lastIndexOf('.'));
return ext.match(moduleTypesRegEx);
}
systemJSPrototype.fetch = function (url) {
return fetch(url);
};

switch (ext) {
case '.css':
return loadDynamicModule(function (_export, source) {
// Relies on a Constructable Stylesheet polyfill
const stylesheet = new CSSStyleSheet();
stylesheet.replaceSync(source);
_export('default', stylesheet);
});
case '.html':
return getSourceRes().then(function (res) {
return maybeJSFallback(res) || loadError("'.html' modules not implemented");
});
case '.json':
return loadDynamicModule(function (_export, source) {
_export('default', JSON.parse(source));
});
case '.wasm':
return getSourceRes().then(function (res) {
return maybeJSFallback(res) ||
(WebAssembly.compileStreaming ? WebAssembly.compileStreaming(res) : res.arrayBuffer().then(WebAssembly.compile));
})
.then(function (module) {
const deps = [];
const setters = [];
const importObj = {};

// we can only set imports if supported (eg early Safari doesnt support)
if (WebAssembly.Module.imports)
WebAssembly.Module.imports(module).forEach(function (impt) {
const key = impt.module;
if (deps.indexOf(key) === -1) {
deps.push(key);
setters.push(function (m) {
importObj[key] = m;
});
}
});

return [deps, function (_export) {
return {
setters: setters,
execute: function () {
return WebAssembly.instantiate(module, importObj)
.then(function (instance) {
_export(instance.exports);
});
}
};
}];
});
}
return instantiate.apply(this, arguments);

function getSourceRes () {
return fetch(url).then(function (res) {
systemJSPrototype.instantiate = function (url, parent) {
const loader = this;
if (this.shouldFetch(url)) {
return this.fetch(url)
.then(function (res) {
if (!res.ok)
loadError(res.status + ' ' + res.statusText);
return res;
throw Error(res.status + ' ' + res.statusText + ', loading ' + url + (parent ? ' from ' + parent : ''));
const contentType = res.headers.get('content-type');
if (contentType.match(/^(text|application)\/(x-)?javascript(;|$)/)) {
return res.text().then(function (source) {
(0, eval)(source);
return loader.getRegister();
});
}
else if (contentType.match(/^application\/json(;|$)/)) {
return res.text().then(function (source) {
return [[], function (_export) {
return {
execute: function () {
_export('default', JSON.parse(source));
}
};
}];
});
}
else if (contentType.match(/^text\/css(;|$)/)) {
return res.text().then(function (source) {
return [[], function (_export) {
return {
execute: function () {
// Relies on a Constructable Stylesheet polyfill
const stylesheet = new CSSStyleSheet();
stylesheet.replaceSync(source);
_export('default', stylesheet);
}
};
}];
});
}
else if (contentType.match(/^application\/wasm(;|$)/)) {
return (WebAssembly.compileStreaming ? WebAssembly.compileStreaming(res) : res.arrayBuffer().then(WebAssembly.compile))
.then(function (module) {
const deps = [];
const setters = [];
const importObj = {};

// we can only set imports if supported (eg early Safari doesnt support)
if (WebAssembly.Module.imports)
WebAssembly.Module.imports(module).forEach(function (impt) {
const key = impt.module;
if (deps.indexOf(key) === -1) {
deps.push(key);
setters.push(function (m) {
importObj[key] = m;
});
}
});

return [deps, function (_export) {
return {
setters: setters,
execute: function () {
return WebAssembly.instantiate(module, importObj)
.then(function (instance) {
_export(instance.exports);
});
}
};
}];
});
}
else {
throw new Error('Unknown module type "' + contentType + '"');
}
});
}
function maybeJSFallback (res) {
const contentType = res.headers.get('content-type');
// if the resource is sent as application/javascript, support eval-based execution
if (contentType && contentType.match(/^application\/javascript(;|$)/)) {
return res.text().then(function (source) {
(0, eval)(source);
return loader.getRegister();
});
}
}
function loadDynamicModule (createExec) {
return getSourceRes().then(function (res) {
return maybeJSFallback(res) || res.text().then(function (source) {
return [[], function (_export) {
return { execute: createExec(_export, source) };
}];
});
});
}
function loadError (msg) {
throw Error(msg + ', loading ' + url + (parent ? ' from ' + parent : ''));
}
return instantiate.apply(this, arguments);
};
})(typeof self !== 'undefined' ? self : global);
2 changes: 1 addition & 1 deletion dist/extras/module-types.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0a3aa2

Please sign in to comment.