Skip to content

Commit

Permalink
Throttle transpiling to prevent crashes (#755)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Dec 5, 2022
1 parent 28d41fb commit 26fdbdf
Showing 1 changed file with 33 additions and 29 deletions.
62 changes: 33 additions & 29 deletions src/ProgramBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 26fdbdf

Please sign in to comment.