Skip to content

Commit

Permalink
Updated the promises prefix and FileFactory to auto import it
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdp committed Jan 15, 2025
1 parent 8497348 commit 956efaa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions bsc-plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bsc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"dependencies": {
"roku-debug": "^0.21.10",
"roku-deploy": "^3.12.1",
"rooibospromises": "npm:@rokucommunity/promises@^0.5.0",
"rooibos_promises": "npm:@rokucommunity/promises@^0.5.0",
"source-map": "^0.7.3",
"undent": "^0.1.0",
"vscode-languageserver": "~6.1.1",
Expand Down
18 changes: 14 additions & 4 deletions bsc-plugin/src/lib/rooibos/FileFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class FileFactory {
this.coverageComponentBrsTemplate = fs.readFileSync(path.join(this.frameworkSourcePath, '/source/rooibos/CodeCoverage.brs'), 'utf8');
}

public addedSourceFrameworkFilePaths: string[] = [];
public sourceFilesToAutoImport: string[] = [];
public addedFrameworkFiles: BscFile[] = [];

public addFrameworkFiles(program: Program) {
Expand All @@ -43,10 +43,10 @@ export class FileFactory {
});

for (let filePath of globedFiles) {
if (/^source[/\\]rooibos[/\\]/g.test(filePath)) {
if (this.shouldAddFileToImportList(filePath)) {
// Save a list of all source files added to the program
// to be imported by node test components
this.addedSourceFrameworkFilePaths.push(filePath);
this.sourceFilesToAutoImport.push(filePath);
}
let sourcePath = path.resolve(this.frameworkSourcePath, filePath);
let fileContents = fs.readFileSync(sourcePath, 'utf8').toString();
Expand All @@ -67,7 +67,7 @@ export class FileFactory {

public createTestXML(name: string, baseName: string, suite?: TestSuite): string {
let scriptImports = [];
for (let filePath of this.addedSourceFrameworkFilePaths) {
for (let filePath of this.sourceFilesToAutoImport) {
scriptImports.push(`<script type="text/brighterscript" uri="pkg:/${filePath}" />`);
}

Expand Down Expand Up @@ -117,6 +117,16 @@ export class FileFactory {
return result !== undefined;
}

private shouldAddFileToImportList(destFilePath): boolean {
const pathDetails = path.parse(destFilePath);
if (pathDetails.dir === 'source' || pathDetails.dir.startsWith('source\\') || pathDetails.dir.startsWith('source/')) {
if (pathDetails.ext === '.brs' || (pathDetails.ext === '.bs' && !pathDetails.name.endsWith('.d'))) {
return true;
}
}
return false;
}

public addFile(program, projectPath: string, contents: string) {
try {
const file = program.setFile({
Expand Down

0 comments on commit 956efaa

Please sign in to comment.