Last active
August 29, 2015 14:09
-
-
Save OliverJAsh/22a3bb5f5e6bd6aa5194 to your computer and use it in GitHub Desktop.
sandboxed-module error with transitive ES6 deps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default 'bar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = 'bar'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bar from './bar'; | |
console.log('foo: bar:', bar); | |
export default 'foo'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import traceurAPI from 'traceur/src/node/api.js'; | |
import SandboxedModule from 'sandboxed-module'; | |
var es6 = source => { | |
var compiler = new traceurAPI.NodeCompiler({ modules: 'commonjs' }); | |
return compiler.compile(source); | |
}; | |
// ES6 modules translate to a CJS module with a default property | |
var sandboxEs6Require = (moduleId, options) => { | |
let defaultOptions = { sourceTransformers: { es6 } }; | |
return SandboxedModule.require( | |
moduleId, | |
Object.assign({}, defaultOptions, options)).default; | |
}; | |
var foo = sandboxEs6Require('./foo', { requires: { http: 'mocked http' } }); | |
console.log('main: foo:', foo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "sandbox-test", | |
"version": "0.0.0", | |
"dependencies": { | |
"sandboxed-module": "^1.0.2" | |
}, | |
"devDependencies": { | |
"traceur": "0.0.72", | |
"traceur-source-maps": "^1.0.5" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var traceur = require('traceur'); | |
require('traceur-source-maps').install(traceur); | |
var path = require('path'); | |
traceur.require.makeDefault(function (modulePath) { | |
var isDependency = modulePath.indexOf('node_modules') !== -1; | |
return ! isDependency; | |
}); | |
require(path.resolve(process.cwd(), process.argv[2])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment