Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throttle transpiling to prevent crashes #755

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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