chore: use es6-module-loader
Switch Traceur to use modules=“instantiate” and use es6-module-loader. This setup supports cyclic dependencies.
This commit is contained in:
parent
774901c225
commit
cfc5fdc60d
|
@ -9,10 +9,9 @@ function file2moduleName(filePath) {
|
|||
// module name should not include `src`, `test`, `lib`
|
||||
.replace(/\/src\//, '/')
|
||||
.replace(/\/lib\//, '/')
|
||||
.replace(/\/test\//, '/')
|
||||
// module name should not have a suffix
|
||||
.replace(/\.\w*$/, '');
|
||||
}
|
||||
if (typeof module !== 'undefined') {
|
||||
module.exports = file2moduleName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,15 @@ module.exports = function(config) {
|
|||
frameworks: ['jasmine'],
|
||||
|
||||
files: [
|
||||
// Sources and specs.
|
||||
// Loaded through the es6-module-loader, in `test-main.js`.
|
||||
{pattern: 'modules/**', included: false},
|
||||
{pattern: 'tools/transpiler/**', included: false},
|
||||
|
||||
'node_modules/traceur/bin/traceur-runtime.js',
|
||||
'modules/**/test_lib/**/*.es6',
|
||||
'modules/**/*.js',
|
||||
'modules/**/*.es6',
|
||||
'tools/transpiler/spec/**/*.js',
|
||||
'tools/transpiler/spec/**/*.es6',
|
||||
'node_modules/es6-module-loader/dist/es6-module-loader-sans-promises.src.js',
|
||||
'node_modules/systemjs/lib/extension-register.js',
|
||||
|
||||
'file2modulename.js',
|
||||
'test-main.js'
|
||||
],
|
||||
|
@ -29,7 +32,7 @@ module.exports = function(config) {
|
|||
options: {
|
||||
outputLanguage: 'es5',
|
||||
script: false,
|
||||
modules: 'register',
|
||||
modules: 'instantiate',
|
||||
types: true,
|
||||
typeAssertions: true,
|
||||
typeAssertionModule: 'rtts_assert/rtts_assert',
|
||||
|
@ -37,7 +40,7 @@ module.exports = function(config) {
|
|||
},
|
||||
resolveModuleName: file2moduleName,
|
||||
transformPath: function(fileName) {
|
||||
return fileName.replace('.es6', '');
|
||||
return fileName.replace(/\.es6$/, '.js');
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
import {assert} from 'rtts_assert/rtts_assert';
|
||||
|
||||
|
||||
export function main() {
|
||||
|
||||
// ## Basic Type Check
|
||||
// By default, `instanceof` is used to check the type.
|
||||
|
@ -375,3 +376,5 @@ describe('Traceur', function() {
|
|||
// <center><small>
|
||||
// This documentation was generated from [assert.spec.js](https://github.com/vojtajina/assert/blob/master/test/assert.spec.js) using [Docco](http://jashkenas.github.io/docco/).
|
||||
// </small></center>
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
"author": "Tobias Bosch <tbosch@google.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"es6-module-loader": "^0.9.2",
|
||||
"systemjs": "^0.9.1",
|
||||
"gulp": "^3.8.8",
|
||||
"gulp-rename": "^1.2.0",
|
||||
"gulp-watch": "^1.0.3",
|
||||
|
|
67
test-main.js
67
test-main.js
|
@ -1,11 +1,60 @@
|
|||
var TEST_REGEXP = /_spec.*/;
|
||||
// Use "register" extension from systemjs.
|
||||
// That's what Traceur outputs: `System.register()`.
|
||||
register(System);
|
||||
|
||||
Object.keys(window.__karma__.files).forEach(function(path) {
|
||||
if (TEST_REGEXP.test(path)) {
|
||||
var moduleName = window.file2moduleName(path);
|
||||
var mod = System.get(moduleName);
|
||||
if (mod && mod.main) {
|
||||
mod.main();
|
||||
}
|
||||
}
|
||||
|
||||
// Cancel Karma's synchronous start,
|
||||
// we will call `__karma__.start()` later, once all the specs are loaded.
|
||||
__karma__.loaded = function() {};
|
||||
|
||||
|
||||
System.baseURL = '/base/modules/';
|
||||
|
||||
// So that we can import packages like `core/foo`, instead of `core/src/foo`.
|
||||
System.paths = {
|
||||
'core/*': './core/src/*.js',
|
||||
'core/test/*': './core/test/*.js',
|
||||
|
||||
'change_detection/*': './change_detection/src/*.js',
|
||||
'change_detection/test/*': './change_detection/test/*.js',
|
||||
|
||||
'facade/*': './facade/src/*.js',
|
||||
'facade/test/*': './facade/test/*.js',
|
||||
|
||||
'di/*': './di/src/*.js',
|
||||
'di/test/*': './di/test/*.js',
|
||||
|
||||
'rtts_assert/*': './rtts_assert/src/*.js',
|
||||
'rtts_assert/test/*': './rtts_assert/test/*.js',
|
||||
|
||||
'test_lib/*': './test_lib/src/*.js',
|
||||
'test_lib/test/*': './test_lib/test/*.js',
|
||||
|
||||
'transpiler/*': '../tools/transpiler/*.js'
|
||||
}
|
||||
|
||||
|
||||
// Import all the specs, execute their `main()` method and kick off Karma (Jasmine).
|
||||
Promise.all(
|
||||
Object.keys(window.__karma__.files) // All files served by Karma.
|
||||
.filter(onlySpecFiles)
|
||||
.map(window.file2moduleName) // Normalize paths to module names.
|
||||
.map(function(path) {
|
||||
return System.import(path).then(function(module) {
|
||||
if (module.hasOwnProperty('main')) {
|
||||
module.main()
|
||||
} else {
|
||||
throw new Error('Module ' + path + ' does not implement main() method.');
|
||||
}
|
||||
});
|
||||
})).then(function() {
|
||||
__karma__.start();
|
||||
}, function(error) {
|
||||
console.error(error.stack || error)
|
||||
__karma__.start();
|
||||
});
|
||||
|
||||
|
||||
function onlySpecFiles(path) {
|
||||
return /_spec\.js$/.test(path);
|
||||
}
|
||||
|
|
|
@ -1,3 +1 @@
|
|||
function main() {
|
||||
assert(true);
|
||||
}
|
||||
export function main() {}
|
||||
|
|
Loading…
Reference in New Issue