diff --git a/src/ProgramBuilder.ts b/src/ProgramBuilder.ts index 56368da2d..a422713b9 100644 --- a/src/ProgramBuilder.ts +++ b/src/ProgramBuilder.ts @@ -12,6 +12,7 @@ import PluginInterface from './PluginInterface'; import * as diagnosticUtils from './diagnosticUtils'; import * as fsExtra from 'fs-extra'; import * as requireRelative from 'require-relative'; +import { Throttler } from './Throttler'; /** * A runner class that handles @@ -384,49 +385,52 @@ export class ProgramBuilder { } } + private transpileThrottler = new Throttler(0); /** * Transpiles the entire program into the staging folder */ public async transpile() { - let options = util.cwdWork(this.options.cwd, () => { - return rokuDeploy.getOptions({ - ...this.options, - logLevel: this.options.logLevel as LogLevel, - outDir: util.getOutDir(this.options), - outFile: path.basename(this.options.outFile) + await this.transpileThrottler.run(async () => { + let options = util.cwdWork(this.options.cwd, () => { + return rokuDeploy.getOptions({ + ...this.options, + logLevel: this.options.logLevel as LogLevel, + outDir: util.getOutDir(this.options), + outFile: path.basename(this.options.outFile) + }); }); - }); - //get every file referenced by the files array - let fileMap = await rokuDeploy.getFilePaths(options.files, options.rootDir); + //get every file referenced by the files array + let fileMap = await rokuDeploy.getFilePaths(options.files, options.rootDir); - //remove files currently loaded in the program, we will transpile those instead (even if just for source maps) - let filteredFileMap = [] as FileObj[]; - for (let fileEntry of fileMap) { - if (this.program.hasFile(fileEntry.src) === false) { - filteredFileMap.push(fileEntry); + //remove files currently loaded in the program, we will transpile those instead (even if just for source maps) + let filteredFileMap = [] as FileObj[]; + for (let fileEntry of fileMap) { + if (this.program.hasFile(fileEntry.src) === false) { + filteredFileMap.push(fileEntry); + } } - } - this.plugins.emit('beforePrepublish', this, filteredFileMap); + this.plugins.emit('beforePrepublish', this, filteredFileMap); - await this.logger.time(LogLevel.log, ['Copying to staging directory'], async () => { - //prepublish all non-program-loaded files to staging - await rokuDeploy.prepublishToStaging({ - ...options, - files: filteredFileMap + await this.logger.time(LogLevel.log, ['Copying to staging directory'], async () => { + //prepublish all non-program-loaded files to staging + await rokuDeploy.prepublishToStaging({ + ...options, + files: filteredFileMap + }); }); - }); - this.plugins.emit('afterPrepublish', this, filteredFileMap); - this.plugins.emit('beforePublish', this, fileMap); + this.plugins.emit('afterPrepublish', this, filteredFileMap); + this.plugins.emit('beforePublish', this, fileMap); - await this.logger.time(LogLevel.log, ['Transpiling'], async () => { - //transpile any brighterscript files - await this.program.transpile(fileMap, options.stagingDir); - }); + await this.logger.time(LogLevel.log, ['Transpiling'], async () => { + //transpile any brighterscript files + await this.program.transpile(fileMap, options.stagingDir); + }); - this.plugins.emit('afterPublish', this, fileMap); + this.plugins.emit('afterPublish', this, fileMap); + }); } private async deployPackageIfEnabled() {