Skip to content

Commit

Permalink
putting experimental nodeFallback back in
Browse files Browse the repository at this point in the history
  • Loading branch information
Singulariteehee committed Dec 21, 2016
1 parent c07735e commit f9a2f56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ SystemJS.config({
...
});
```

I also have included an experimental feature. If you use SystemJS in a node environment, try out "nodeFallback: true" under oneOptions. Once the plugin runs out of extensions to try, it will simply try to use node require instead, which might work if you have npm-installed what you were looking for.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ function fetch(load, systemFetch) {
var targetPluginName = targetPluginMeta && targetPluginMeta.loader;
if(targetPluginMeta && !targetPluginName) {
return systemFetch(load); // when loader is omitted, assume plain javascript
}
}

var targetPlugin = null;
if(!targetPluginName) return Promise.resolve()
.then(function(){
var extensions = Object.keys(oneOptions.meta).map(function(key){return key.replace("*","")});
return findFirstValidAddress(load.address,extensions,systemFetch)
}).then(function(targetAddress){
return "export * from '"+targetAddress.replace(SystemJS.baseURL,"")+"'";
}).catch(function(){
if(oneOptions.nodeFallback) {
return "export default SystemJS._nodeRequire && SystemJS._nodeRequire('"+load.address.replace(SystemJS.baseURL,"")+"')"
} else return Promise.reject('OnePlugin could not resolve', load)
});
else return Promise.resolve()
.then(function(){return SystemJS.import(targetPluginName)}).then(function(imported){targetPlugin = imported})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one-plugin",
"version": "0.0.2",
"version": "0.0.3",
"description": "One SystemJS plugin to rule them all.",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit f9a2f56

Please sign in to comment.