refactor(build): explicitly mention src folder in imports

Export files are now directly under the module folder,
e.g. `core/core.js`. With this, an import like `core/core`
won’t need a path mapping (e.g. via `System.paths`) any more.
This adds the `src` folder to all other import statements as well.
This commit is contained in:
Tobias Bosch
2015-02-02 16:25:34 -08:00
committed by Alex Eagle
parent 9db13be4c7
commit 05ffdc9b44
160 changed files with 612 additions and 620 deletions

View File

@ -4,7 +4,6 @@ var spawn = require('child_process').spawn;
var path = require('path');
var glob = require('glob');
var fs = require('fs');
var util = require('./util');
module.exports = function(gulp, plugins, config) {
return function() {
@ -12,7 +11,7 @@ module.exports = function(gulp, plugins, config) {
var tempFile = '_analyzer.dart';
// analyze in parallel!
return Q.all(dartModuleFolders.map(function(dir) {
var srcFiles = [].slice.call(glob.sync(util.filterByFile(config.srcFolderMapping, dir + '/pubspec.yaml') + '/**/*.dart', {
var srcFiles = [].slice.call(glob.sync(dir + '{/lib,/web}/**/*.dart', {
cwd: dir
}));
var testFiles = [].slice.call(glob.sync('test/**/*_spec.dart', {

View File

@ -3,10 +3,9 @@ function file2moduleName(filePath) {
// module name should be relative to `modules` and `tools` folder
.replace(/.*\/modules\//, '')
.replace(/.*\/tools\//, '')
// module name should not include `src`, `test`, `lib`
.replace(/\/src\//, '/')
// module name should not include `lib`, `web` folders
// as they are wrapper packages for dart
.replace(/\/web\//, '/')
.replace(/\/perf_tmp\//, '/')
.replace(/\/lib\//, '/')
// module name should not have a suffix
.replace(/\.\w*$/, '');

View File

@ -6,7 +6,7 @@ var path = require('path');
module.exports = function(gulp, plugins, config) {
return function() {
return gulp.src(config.src)
.pipe(util.renameSrcFolder(plugins, config.srcFolderMapping))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(through2.obj(function(file, enc, done) {
var fileName = file.relative;
var moduleName = file2moduleName(fileName);

View File

@ -4,6 +4,7 @@ var spawn = require('child_process').spawn;
var through2 = require('through2');
var path = require('path');
var glob = require('glob');
var fs = require('fs');
module.exports = function(gulp, plugins, config) {
return function() {
@ -21,6 +22,8 @@ module.exports = function(gulp, plugins, config) {
cwd: folder
})).then(function() {
return replaceDartWithJsScripts(gulp, destFolder);
}).then(function() {
return removeWebFolder(gulp, destFolder);
}).then(nextFolder);
}
};
@ -37,4 +40,11 @@ function replaceDartWithJsScripts(gulp, folder) {
done();
}))
.pipe(gulp.dest(folder)));
}
}
function removeWebFolder(gulp, folder) {
fs.renameSync(path.join(folder, 'web', 'src'), path.join(folder, 'src'));
fs.renameSync(path.join(folder, 'web', 'packages'), path.join(folder, 'packages'));
fs.rmdirSync(path.join(folder, 'web'));
return Q.resolve();
}

View File

@ -1,17 +1,4 @@
System.paths = {
'angular/*': '/angular/lib/*.js',
'core/*': '/core/lib/*.js',
'change_detection/*': '/change_detection/lib/*.js',
'facade/*': '/facade/lib/*.js',
'di/*': '/di/lib/*.js',
'directives/*': '/directives/lib/*.js',
'rtts_assert/*': '/rtts_assert/lib/*.js',
'test_lib/*': '/test_lib/lib/*.js',
'reflection/*': '/reflection/lib/*.js',
'benchpress/*': '/benchpress/lib/*.js',
'examples/*': '/examples/web/*.js',
'e2e_test_lib/*': '/e2e_test_lib/lib/*.js',
'benchmarks/*': '/benchmarks/web/*.js',
'benchmarks_external/*': '/benchmarks_external/web/*.js',
'*': '/*.js'
};
register(System);

View File

@ -7,7 +7,7 @@ module.exports = function(gulp, plugins, config) {
return function() {
var transpile = gulp.src(config.src)
.pipe(plugins.rename({extname: '.'+config.outputExt}))
.pipe(util.renameSrcFolder(plugins, config.srcFolderMapping))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(gulpTraceur(
config.options,
file2moduleName)
@ -16,7 +16,7 @@ module.exports = function(gulp, plugins, config) {
var copy = gulp.src(config.copy)
.pipe(plugins.rename({extname: '.'+config.outputExt}))
.pipe(util.renameSrcFolder(plugins, config.srcFolderMapping))
.pipe(util.insertSrcFolder(plugins, config.srcFolderInsertion, config.modulesFolder))
.pipe(gulp.dest(config.dest));
return mergeStreams(transpile, copy);

View File

@ -1,22 +1,14 @@
var Q = require('q');
var path = require('path');
var minimatch = require('minimatch');
module.exports = {
processToPromise: processToPromise,
streamToPromise: streamToPromise,
renameSrcFolder: renameSrcFolder,
insertSrcFolder: insertSrcFolder,
filterByFile: filterByFile
};
function filterByFile(valuesWithPatterns, fileName) {
var match = null;
for (var pattern in valuesWithPatterns) {
if (pattern !== 'default' && minimatch(fileName, pattern)) {
match = valuesWithPatterns[pattern];
}
}
return match || valuesWithPatterns['default'];
}
function processToPromise(process) {
var defer = Q.defer();
@ -37,9 +29,33 @@ function streamToPromise(stream) {
return defer.promise;
}
function renameSrcFolder(plugins, srcFolderMapping) {
function filterByFile(pathMapping, folder) {
var folderParts = folder.split(path.sep);
var match;
var lastPattern;
for (var pattern in pathMapping) {
if (minimatch(folder, pattern)) {
if (!lastPattern || lastPattern.length < pattern.length) {
match = pathMapping[pattern];
lastPattern = pattern;
}
}
}
if (match !== undefined) {
return match;
} else {
throw new Error('No entry for folder '+folder+' found in '+JSON.stringify(pathMapping));
}
}
function insertSrcFolder(plugins, srcFolderInsertion) {
return plugins.rename(function(file) {
var srcOutputFolder = filterByFile(srcFolderMapping, file.dirname);
file.dirname = file.dirname.replace(/\bsrc\b/, srcOutputFolder);
var folder = file.dirname;
var srcDir = filterByFile(srcFolderInsertion, folder);
if (srcDir) {
var folderParts = file.dirname.split(path.sep);
folder = [folderParts[0], srcDir].concat(folderParts.slice(1)).join(path.sep);
}
file.dirname = folder;
});
}

View File

@ -1,6 +1,6 @@
import {describe, it, expect, iit} from 'test_lib/test_lib';
import {readFirstAnnotation} from './fixtures/annotations';
import {CONST} from 'facade/lang';
import {CONST} from 'facade/src/lang';
class Inject {}
class Bar {}

View File

@ -1,5 +1,5 @@
import {describe, it, expect} from 'test_lib/test_lib';
import {ListWrapper, MapWrapper} from 'facade/collection';
import {ListWrapper, MapWrapper} from 'facade/src/collection';
import {IterableList} from './fixtures/facade';
export function main() {

View File

@ -7,7 +7,7 @@ import * as fooModule from './foo';
import * as exportModule from './export';
import {Type} from 'facade/lang';
import {Type} from 'facade/src/lang';
import {Baz} from './reexport';