From c2e5b304fac708b55ef67a1add061e51257b5c81 Mon Sep 17 00:00:00 2001 From: George Cook Date: Tue, 21 Feb 2023 16:50:13 +0100 Subject: [PATCH] Fix/crash stagingdir (#215) * fix: fixes crash when stagingFolderPath and stagingDir is not present * fix: fixes crash when stagingFolderPath and stagingDir is not present * Adds important missing method t mock node * fix * udpate bsc --- bsc-plugin/package.json | 4 ++-- bsc-plugin/src/lib/rooibos/RooibosSession.ts | 12 +++++++++--- bsc-plugin/src/lib/utils/Diagnostics.ts | 9 +++++++++ bsc-plugin/src/plugin.ts | 2 +- framework/src/source/Utils.bs | 4 ++++ 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/bsc-plugin/package.json b/bsc-plugin/package.json index 77ad9aaa..037c5e39 100644 --- a/bsc-plugin/package.json +++ b/bsc-plugin/package.json @@ -27,7 +27,7 @@ "@types/node": "^17.0.29", "@typescript-eslint/eslint-plugin": "^5.27.0", "@typescript-eslint/parser": "^5.27.0", - "brighterscript": "0.61.2", + "brighterscript": "^0.61.3", "chai": "^4.2.0", "chai-subset": "^1.6.0", "coveralls": "^3.0.0", @@ -110,4 +110,4 @@ "ts" ] } -} \ No newline at end of file +} diff --git a/bsc-plugin/src/lib/rooibos/RooibosSession.ts b/bsc-plugin/src/lib/rooibos/RooibosSession.ts index d42f3d32..fe14a4f9 100644 --- a/bsc-plugin/src/lib/rooibos/RooibosSession.ts +++ b/bsc-plugin/src/lib/rooibos/RooibosSession.ts @@ -9,7 +9,7 @@ import { TestSuiteBuilder } from './TestSuiteBuilder'; import { RawCodeStatement } from './RawCodeStatement'; import type { FileFactory } from './FileFactory'; import type { TestSuite } from './TestSuite'; -import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound } from '../utils/Diagnostics'; +import { diagnosticErrorNoMainFound as diagnosticWarnNoMainFound, diagnosticNoStagingDir } from '../utils/Diagnostics'; import undent from 'undent'; import { BrsTranspileState } from 'brighterscript/dist/parser/BrsTranspileState'; import * as fsExtra from 'fs-extra'; @@ -76,8 +76,14 @@ export class RooibosSession { } if (!mainFunction) { diagnosticWarnNoMainFound(files[0]); - const filePath = path.join(this._builder.options.stagingDir, 'source/rooibosMain.brs'); - fsExtra.writeFileSync(filePath, `function main()\n Rooibos_init()\nend function`); + if (!this._builder.options.stagingDir && !this._builder.options.stagingFolderPath) { + console.error('this plugin requires that stagingDir or the deprecated stagingFolderPath bsconfig option is set'); + diagnosticNoStagingDir(files[0]); + } else { + const filePath = path.join(this._builder.options.stagingDir ?? this._builder.options.stagingFolderPath, 'source/rooibosMain.brs'); + fsExtra.writeFileSync(filePath, `function main()\n Rooibos_init()\nend function`); + + } } } diff --git a/bsc-plugin/src/lib/utils/Diagnostics.ts b/bsc-plugin/src/lib/utils/Diagnostics.ts index f51e718b..e967b7e7 100644 --- a/bsc-plugin/src/lib/utils/Diagnostics.ts +++ b/bsc-plugin/src/lib/utils/Diagnostics.ts @@ -254,3 +254,12 @@ export function diagnosticCorruptTestProduced(file: BrsFile, annotation: Annotat annotation ); } + +export function diagnosticNoStagingDir(file: BscFile) { + addDiagnostic( + file, + 2221, + `The bsconfig must define stagingDir, or the deprecated stagingFolderPath options`, 1, 1, 1, 1, DiagnosticSeverity.Error + ); +} + diff --git a/bsc-plugin/src/plugin.ts b/bsc-plugin/src/plugin.ts index ae872a64..f0bf5ebe 100644 --- a/bsc-plugin/src/plugin.ts +++ b/bsc-plugin/src/plugin.ts @@ -83,7 +83,7 @@ export class RooibosPlugin implements CompilerPlugin { return; } - console.log('processing ', file.pkgPath); + // console.log('processing ', file.pkgPath); if (isBrsFile(file)) { if (this.session.processFile(file)) { // diff --git a/framework/src/source/Utils.bs b/framework/src/source/Utils.bs index beefae93..2a8e49fb 100644 --- a/framework/src/source/Utils.bs +++ b/framework/src/source/Utils.bs @@ -18,6 +18,10 @@ namespace rooibos.utils return m._subType end function + function isSubType(name) + return false + end function + function createObject(nodeType) node = new rooibos.utils.MockNode("", nodeType) m.createdNodes.push(node)