From 928ec1c5f88c791af39dd737237382d3f4ecf08b Mon Sep 17 00:00:00 2001 From: Caitlin Potter Date: Fri, 5 Jun 2015 03:19:34 -0400 Subject: [PATCH] fix(broccoli): ensure that inputTrees are stable --- tools/broccoli/diffing-broccoli-plugin.ts | 7 ++- tools/broccoli/trees/browser_tree.ts | 65 ++++++++++++++++++----- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/tools/broccoli/diffing-broccoli-plugin.ts b/tools/broccoli/diffing-broccoli-plugin.ts index a4fe8f6397..1c38d208bc 100644 --- a/tools/broccoli/diffing-broccoli-plugin.ts +++ b/tools/broccoli/diffing-broccoli-plugin.ts @@ -136,7 +136,12 @@ class DiffingPluginWrapper implements BroccoliTree { private stabilizeTrees(trees: BroccoliTree[]) { - return trees.map((tree) => this.stabilizeTree(tree)); + // Prevent extensions to prevent array from being mutated from the outside. + // For-loop used to avoid re-allocating a new array. + for (let i = 0; i < trees.length; ++i) { + trees[i] = this.stabilizeTree(trees[i]); + } + return Object.freeze(trees); } diff --git a/tools/broccoli/trees/browser_tree.ts b/tools/broccoli/trees/browser_tree.ts index e3abe11d23..8d957b116c 100644 --- a/tools/broccoli/trees/browser_tree.ts +++ b/tools/broccoli/trees/browser_tree.ts @@ -16,6 +16,45 @@ import {default as transpileWithTraceur, TRACEUR_RUNTIME_PATH} from '../traceur/ var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..')); +const kServedPaths = [ + // Relative (to /modules) paths to benchmark directories + 'benchmarks/src', + 'benchmarks/src/change_detection', + 'benchmarks/src/compiler', + 'benchmarks/src/costs', + 'benchmarks/src/di', + 'benchmarks/src/element_injector', + 'benchmarks/src/largetable', + 'benchmarks/src/naive_infinite_scroll', + 'benchmarks/src/tree', + + // Relative (to /modules) paths to external benchmark directories + 'benchmarks_external/src', + 'benchmarks_external/src/compiler', + 'benchmarks_external/src/largetable', + 'benchmarks_external/src/naive_infinite_scroll', + 'benchmarks_external/src/tree', + 'benchmarks_external/src/tree/react', + + // Relative (to /modules) paths to example directories + 'examples/src/benchpress', + 'examples/src/forms', + 'examples/src/gestures', + 'examples/src/hello_world', + 'examples/src/key_events', + 'examples/src/sourcemap', + 'examples/src/todo', + 'examples/src/material/button', + 'examples/src/material/checkbox', + 'examples/src/material/dialog', + 'examples/src/material/grid_list', + 'examples/src/material/input', + 'examples/src/material/progress-linear', + 'examples/src/material/radio', + 'examples/src/material/switcher' +]; + + module.exports = function makeBrowserTree(options, destinationPath) { var modulesTree = new Funnel( 'modules', @@ -84,26 +123,30 @@ module.exports = function makeBrowserTree(options, destinationPath) { path.relative(projectRootDir, TRACEUR_RUNTIME_PATH) ] })); + var vendorScripts_benchmark = new Funnel('tools/build/snippets', {files: ['url_params_to_form.js'], destDir: '/'}); var vendorScripts_benchmarks_external = new Funnel('node_modules/angular', {files: ['angular.js'], destDir: '/'}); - var servingTrees = []; - - function copyVendorScriptsTo(destDir) { - servingTrees.push(new Funnel(vendorScriptsTree, {srcDir: '/', destDir: destDir})); + // Get scripts for each benchmark or example + let servingTrees = kServedPaths.reduce(getServedFunnels, []); + function getServedFunnels(funnels, destDir) { + let options = { + srcDir: '/', + destDir: destDir + }; + funnels.push(new Funnel(vendorScriptsTree, options)); if (destDir.indexOf('benchmarks') > -1) { - servingTrees.push(new Funnel(vendorScripts_benchmark, {srcDir: '/', destDir: destDir})); + funnels.push(new Funnel(vendorScripts_benchmark, options)); } if (destDir.indexOf('benchmarks_external') > -1) { - servingTrees.push( - new Funnel(vendorScripts_benchmarks_external, {srcDir: '/', destDir: destDir})); + funnels.push(new Funnel(vendorScripts_benchmarks_external, options)); } + return funnels; } function writeScriptsForPath(relativePath, result) { - copyVendorScriptsTo(path.dirname(relativePath)); return result.replace('@@FILENAME_NO_EXT', relativePath.replace(/\.\w+$/, '')); } @@ -124,11 +167,7 @@ module.exports = function makeBrowserTree(options, destinationPath) { replaceWithPath: writeScriptsForPath }); - // Copy all vendor scripts into all examples and benchmarks - ['benchmarks/src', 'benchmarks_external/src', 'examples/src/benchpress'].forEach( - copyVendorScriptsTo); - - var scripts = mergeTrees(servingTrees, {overwrite: true}); + var scripts = mergeTrees(servingTrees); var css = new Funnel(modulesTree, {include: ["**/*.css"]}); var polymerFiles = new Funnel('.', { files: [