revert: refactor: use a custom replacement build step instead of broccoli-replace

This reverts commit d5c528ac2b.
This commit is contained in:
Matias Niemelä 2015-06-06 00:58:57 -07:00
parent a418397174
commit 72736a1b09
7 changed files with 426 additions and 288 deletions

View File

@ -1374,6 +1374,87 @@
} }
} }
}, },
"broccoli-replace": {
"version": "0.2.0",
"resolved": "git://github.com/alexeagle/broccoli-replace.git#cd39a543b17b40db765a07762f099fbc85518290",
"dependencies": {
"minimatch": {
"version": "1.0.0",
"dependencies": {
"lru-cache": {
"version": "2.6.2"
},
"sigmund": {
"version": "1.0.0"
}
}
},
"applause": {
"version": "0.3.4",
"dependencies": {
"cson": {
"version": "1.6.2",
"dependencies": {
"ambi": {
"version": "2.2.0",
"dependencies": {
"typechecker": {
"version": "2.0.8"
}
}
},
"coffee-script": {
"version": "1.8.0",
"dependencies": {
"mkdirp": {
"version": "0.3.5"
}
}
},
"extract-opts": {
"version": "2.2.0",
"dependencies": {
"typechecker": {
"version": "2.0.8"
}
}
},
"js2coffee": {
"version": "0.3.5",
"dependencies": {
"coffee-script": {
"version": "1.7.1",
"dependencies": {
"mkdirp": {
"version": "0.3.5"
}
}
},
"file": {
"version": "0.2.2"
},
"nopt": {
"version": "3.0.1",
"dependencies": {
"abbrev": {
"version": "1.0.5"
}
}
},
"underscore": {
"version": "1.6.0"
}
}
},
"requirefresh": {
"version": "1.1.2"
}
}
}
}
}
}
},
"broccoli-slow-trees": { "broccoli-slow-trees": {
"version": "1.1.0" "version": "1.1.0"
}, },

520
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,7 @@
"broccoli-funnel": "igorminar/broccoli-funnel#perf-files", "broccoli-funnel": "igorminar/broccoli-funnel#perf-files",
"broccoli-lodash": "^0.1.1", "broccoli-lodash": "^0.1.1",
"broccoli-merge-trees": "^0.2.1", "broccoli-merge-trees": "^0.2.1",
"broccoli-replace": "alexeagle/broccoli-replace#angular_patch",
"broccoli-slow-trees": "^1.1.0", "broccoli-slow-trees": "^1.1.0",
"broccoli-stew": "^0.2.1", "broccoli-stew": "^0.2.1",
"broccoli-writer": "^0.1.1", "broccoli-writer": "^0.1.1",

View File

@ -1,56 +0,0 @@
import fs = require('fs');
import fse = require('fs-extra');
import path = require('path');
import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin';
var minimatch = require('minimatch');
var exec = require('child_process').exec;
var FILE_ENCODING = {encoding: 'utf-8'};
/**
* Intercepts each changed file and replaces its contents with
* the associated changes.
*/
class DiffingReplace implements DiffingBroccoliPlugin {
constructor(private inputPath, private cachePath, private options) {}
rebuild(treeDiff: DiffResult) {
var patterns = this.options.patterns;
var files = this.options.files;
treeDiff.changedPaths.forEach((changedFilePath) => {
var sourceFilePath = path.join(this.inputPath, changedFilePath)
var destFilePath = path.join(this.cachePath, changedFilePath);
var destDirPath = path.dirname(destFilePath);
if (!fs.existsSync(destDirPath)) {
fse.mkdirpSync(destDirPath);
}
var fileMatches = files.some((filePath) => minimatch(changedFilePath, filePath));
if (fileMatches) {
var content = fs.readFileSync(sourceFilePath, FILE_ENCODING);
patterns.forEach((pattern) => {
var replacement = pattern.replacement;
if (typeof replacement === 'function') {
replacement = function(content) {
return pattern.replacement(content, changedFilePath);
};
}
content = content.replace(pattern.match, replacement);
});
fs.writeFileSync(destFilePath, content, FILE_ENCODING);
} else {
fs.symlinkSync(sourceFilePath, destFilePath);
}
});
treeDiff.removedPaths.forEach((removedFilePath) => {
var destFilePath = path.join(this.cachePath, removedFilePath);
fs.unlinkSync(destFilePath);
});
}
}
export default wrapDiffingPlugin(DiffingReplace);

View File

@ -5,12 +5,12 @@ var flatten = require('broccoli-flatten');
var htmlReplace = require('../html-replace'); var htmlReplace = require('../html-replace');
import mergeTrees from '../broccoli-merge-trees'; import mergeTrees from '../broccoli-merge-trees';
var path = require('path'); var path = require('path');
var replace = require('broccoli-replace');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
import compileWithTypescript from '../broccoli-typescript'; import compileWithTypescript from '../broccoli-typescript';
import destCopy from '../broccoli-dest-copy'; import destCopy from '../broccoli-dest-copy';
import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index'; import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/index';
import replace from '../broccoli-replace';
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..')); var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
@ -146,36 +146,25 @@ module.exports = function makeBrowserTree(options, destinationPath) {
return funnels; return funnels;
} }
var scriptPathPatternReplacement = { function writeScriptsForPath(relativePath, result) {
match: '@@FILENAME_NO_EXT', return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, ''));
replacement: function(replacement, relativePath) { }
return relativePath.replace(/\.\w+$/, '');
}
};
var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'}); var htmlTree = new Funnel(modulesTree, {include: ['*/src/**/*.html'], destDir: '/'});
htmlTree = replace(htmlTree, { htmlTree = replace(htmlTree, {
files: ['examples*/**'], files: ['examples*/**'],
patterns: [ patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}],
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS')}, replaceWithPath: writeScriptsForPath
scriptPathPatternReplacement
]
}); });
htmlTree = replace(htmlTree, { htmlTree = replace(htmlTree, {
files: ['benchmarks/**'], files: ['benchmarks/**'],
patterns: [ patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')}],
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks')}, replaceWithPath: writeScriptsForPath
scriptPathPatternReplacement
]
}); });
htmlTree = replace(htmlTree, { htmlTree = replace(htmlTree, {
files: ['benchmarks_external/**'], files: ['benchmarks_external/**'],
patterns: [ patterns: [{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')}],
{match: /\$SCRIPTS\$/, replacement: htmlReplace('SCRIPTS_benchmarks_external')}, replaceWithPath: writeScriptsForPath
scriptPathPatternReplacement
]
}); });
var scripts = mergeTrees(servingTrees); var scripts = mergeTrees(servingTrees);

View File

@ -9,10 +9,10 @@ var glob = require('glob');
import mergeTrees from '../broccoli-merge-trees'; import mergeTrees from '../broccoli-merge-trees';
var path = require('path'); var path = require('path');
var renderLodashTemplate = require('broccoli-lodash'); var renderLodashTemplate = require('broccoli-lodash');
var replace = require('broccoli-replace');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
import ts2dart from '../broccoli-ts2dart'; import ts2dart from '../broccoli-ts2dart';
import dartfmt from '../broccoli-dartfmt'; import dartfmt from '../broccoli-dartfmt';
import replace from '../broccoli-replace';
/** /**
* A funnel starting at modules, including the given filters, and moving into the root. * A funnel starting at modules, including the given filters, and moving into the root.

View File

@ -7,7 +7,7 @@ var Funnel = require('broccoli-funnel');
import mergeTrees from '../broccoli-merge-trees'; import mergeTrees from '../broccoli-merge-trees';
var path = require('path'); var path = require('path');
var renderLodashTemplate = require('broccoli-lodash'); var renderLodashTemplate = require('broccoli-lodash');
import replace from '../broccoli-replace'; var replace = require('broccoli-replace');
var stew = require('broccoli-stew'); var stew = require('broccoli-stew');
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..')); var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
@ -84,16 +84,19 @@ module.exports = function makeNodeTree(destinationPath) {
// TODO: remove this when we no longer use traceur // TODO: remove this when we no longer use traceur
var traceurCompatibleTsModulesTree = replace(modulesTree, { var traceurCompatibleTsModulesTree = replace(modulesTree, {
files: ['**/*.ts'], files: ['**/*.ts'],
patterns: [{ patterns: [
match: /$/, {
replacement: function(_, relativePath) { // Empty replacement needed so that replaceWithPath gets triggered...
var content = ""; //we're matching an empty line match: /$/g,
if (!relativePath.endsWith('.d.ts')) { replacement: ""
content += '\r\nexport var __esModule = true;\n';
}
return content;
} }
}] ],
replaceWithPath: function(path, content) {
if (!path.endsWith('.d.ts')) {
content += '\r\nexport var __esModule = true;\n';
}
return content;
}
}); });
var typescriptTree = compileWithTypescript(traceurCompatibleTsModulesTree, { var typescriptTree = compileWithTypescript(traceurCompatibleTsModulesTree, {