fix(build): switch to cjs output for es5.

System output does not work at the current versions of TS and
system.js. Will revisit after upgrading TS.

Removes unused traceur tooling.

Closes #3974
This commit is contained in:
Rado Kirov
2015-09-02 20:58:02 -07:00
committed by Rado Kirov
parent b025f94351
commit e9ad100b1f
39 changed files with 25 additions and 1243 deletions

View File

@ -1,56 +0,0 @@
/// <reference path="../../typings/fs-extra/fs-extra.d.ts" />
/// <reference path="../../typings/node/node.d.ts" />
import fs = require('fs');
import fse = require('fs-extra');
import path = require('path');
import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from '../diffing-broccoli-plugin';
let traceur = require('../../../../tools/transpiler');
let xtend = require('xtend');
class DiffingTraceurCompiler implements DiffingBroccoliPlugin {
constructor(public inputPath: string, public cachePath: string, public options) {}
static includeExtensions = ['.js', '.cjs'];
rebuild(treeDiff: DiffResult) {
treeDiff.addedPaths.concat(treeDiff.changedPaths)
.forEach((changedFilePath) => {
var traceurOpts = xtend({filename: changedFilePath}, this.options.traceurOptions);
var fsOpts = {encoding: 'utf-8'};
var absoluteInputFilePath = path.join(this.inputPath, changedFilePath);
var sourcecode = fs.readFileSync(absoluteInputFilePath, fsOpts);
var result = traceur.compile(traceurOpts, changedFilePath, sourcecode);
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
// (but we might switch to typescript first)
var mapFilepath =
changedFilePath.replace(/\.\w+$/, '') + this.options.destSourceMapExtension;
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(mapFilepath);
var destFilepath = changedFilePath.replace(/\.\w+$/, this.options.destExtension);
var destFile = path.join(this.cachePath, destFilepath);
fse.mkdirsSync(path.dirname(destFile));
fs.writeFileSync(destFile, result.js, fsOpts);
var destMap = path.join(this.cachePath, mapFilepath);
result.sourceMap.file = destFilepath;
fs.writeFileSync(destMap, JSON.stringify(result.sourceMap), fsOpts);
});
treeDiff.removedPaths.forEach((removedFilePath) => {
var destFilepath = removedFilePath.replace(/\.\w+$/, this.options.destExtension);
var absoluteOuputFilePath = path.join(this.cachePath, destFilepath);
fs.unlinkSync(absoluteOuputFilePath);
});
}
}
let transpileWithTraceur = wrapDiffingPlugin(DiffingTraceurCompiler);
let TRACEUR_RUNTIME_PATH = traceur.RUNTIME_PATH;
export {transpileWithTraceur as default, TRACEUR_RUNTIME_PATH};

View File

@ -2,16 +2,16 @@
var Funnel = require('broccoli-funnel');
var htmlReplace = require('../html-replace');
var jsReplace = require("../js-replace");
var jsReplace = require('../js-replace');
var path = require('path');
var stew = require('broccoli-stew');
var traceur = require('traceur');
import compileWithTypescript from '../broccoli-typescript';
import destCopy from '../broccoli-dest-copy';
import flatten from '../broccoli-flatten';
import mergeTrees from '../broccoli-merge-trees';
import replace from '../broccoli-replace';
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
@ -83,13 +83,10 @@ module.exports = function makeBrowserTree(options, destinationPath) {
],
destDir: '/'
});
var es5ModulesTree = new Funnel('modules', {
include: ['**/**'],
exclude: [
'**/*.cjs',
'benchmarks/e2e_test/**'
],
exclude: ['**/*.cjs', 'angular1_router/**', 'benchmarks/e2e_test/**'],
destDir: '/'
});
@ -117,7 +114,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
sourceRoot: '.',
target: 'ES6'
});
// Use TypeScript to transpile the *.ts files to ES5
var es5Tree = compileWithTypescript(es5ModulesTree, {
allowNonTsExtensions: false,
@ -125,7 +122,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
emitDecoratorMetadata: true,
experimentalDecorators: true,
mapRoot: '', // force sourcemaps to use relative path
module: 'System',
module: 'CommonJS',
noEmitOnError: false,
rootDir: '.',
sourceMap: true,
@ -133,7 +130,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
target: 'ES5'
});
// Now we add a few more files to the es6 tree that Traceur should not see
// Now we add a few more files to the es6 tree that the es5 tree should not see
['angular2', 'rtts_assert'].forEach(function(destDir) {
var extras = new Funnel('tools/build', {files: ['es5build.js'], destDir: destDir});
es6Tree = mergeTrees([es6Tree, extras]);
@ -147,7 +144,7 @@ module.exports = function makeBrowserTree(options, destinationPath) {
'node_modules/rx/dist/rx.js',
'node_modules/base64-js/lib/b64.js',
'node_modules/reflect-metadata/Reflect.js',
path.relative(projectRootDir, TRACEUR_RUNTIME_PATH)
path.relative(projectRootDir, traceur.RUNTIME_PATH)
]
}));