From a7e6167a4974c3f1048d9c228d3fdac6bc5880c6 Mon Sep 17 00:00:00 2001 From: George Cook Date: Sun, 7 Nov 2021 21:49:12 +0100 Subject: [PATCH 1/5] version bump --- CHANGELOG.md | 13 ++++++++++++- package.json | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dfdb1a8..e93225b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -## [0.13.2](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.13.1...0.13.2) +## [0.13.3](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.13.2...0.13.3) + +### Merged + +- Fix/fix crash on chekcing functions [`#24`](https://github.com/georgejecook/maestro-roku-bsc-plugin/pull/24) + +### Commits + +- version bump [`350efaa`](https://github.com/georgejecook/maestro-roku-bsc-plugin/commit/350efaa123247f49286e693032e4f6a1c852f4dd) +- fix: fixes crash when changing types of functions [`67f1f94`](https://github.com/georgejecook/maestro-roku-bsc-plugin/commit/67f1f949357ce83684ab6bb5bf69eedc24e0af0d) + +## [0.13.2](https://github.com/georgejecook/maestro-roku-bsc-plugin/compare/0.13.1...0.13.2) - 2021-10-29 ### Merged diff --git a/package.json b/package.json index fc1f6cc..272bda1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "maestro-roku-bsc-plugin", - "version": "0.13.2", + "version": "0.13.3", "description": "Visual studio plugin for maestro brightscript development", "files": [ "dist/**/!(*.spec.*)*", From c3d1d366e03edc4be373e12f0155dd62133c9d13 Mon Sep 17 00:00:00 2001 From: George Cook Date: Tue, 4 Jan 2022 22:50:20 +0100 Subject: [PATCH 2/5] adds more options for tweaking validation/xml genearation --- package-lock.json | 4 +- scripts/run.js | 128 +++++++++++++++++---------------- src/lib/files/MaestroConfig.ts | 5 ++ src/plugin.ts | 128 ++++++++++++++++++++++----------- 4 files changed, 160 insertions(+), 105 deletions(-) diff --git a/package-lock.json b/package-lock.json index b8ecc7a..41c202a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "maestro-roku-bsc-plugin", - "version": "0.12.1", + "version": "0.13.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.12.1", + "version": "0.13.2", "license": "ISC", "dependencies": { "debounce": "^1.2.0", diff --git a/scripts/run.js b/scripts/run.js index 9c034f5..77d10de 100755 --- a/scripts/run.js +++ b/scripts/run.js @@ -3,7 +3,7 @@ const path = require('path'); // eslint-disable-next-line let zapp = { - 'rootDir': '/home/george/hope/applicaster/4/zapp-roku-app/src', + 'rootDir': '/home/george/hope/applicaster/zapp-roku-app/src', 'stagingFolderPath': 'build', 'retainStagingFolder': true, 'createPackage': false, @@ -13,6 +13,8 @@ let zapp = { 'source/**/*.*', 'components/**/*.*', 'images/**/*.*', + '!**/*.md', + '!asset-bundle/__MACOSX', { 'src': '../external/plugins-src/**/*.*', 'dest': '' @@ -28,46 +30,20 @@ let zapp = { { 'src': '../external/private-oc-src/**/*.*', 'dest': '' - }, - { - 'src': '!../external/plugins-src/**/*.spec.bs', - 'dest': '' - }, - { - 'src': '!../external/plugins-core-src/**/*.spec.*', - 'dest': '' - }, - { - 'src': '!../external/private-emmys-src/**/*.spec.*', - 'dest': '' - }, - { - 'src': '!../external/private-oc-src/**/*.spec.*', - 'dest': '' - }, - '!**/*.spec.bs' + } ], 'diagnosticFilters': [ { 'src': '**/roku_modules/**/*.*', - 'codes': [ - 1107, - 1009, - 1001, - 1067 - ] + 'codes': [1107, 1009, 1001, 1067] }, { 'src': '**/Whitelist.xml', - 'codes': [ - 1067 - ] + 'codes': [1067] }, { 'src': 'components/maestro/generated/**/*.*', - 'codes': [ - 1001 - ] + 'codes': [1001] }, 1013, { @@ -84,41 +60,68 @@ let zapp = { }, { 'src': '**/RALETrackerTask.*' + }, + { + 'src': '../external/plugins-src/source/google_analytics_roku/*.*' + }, + { + 'src': 'source/lib/rokuPromise.bs' + }, + { + 'src': '../external/plugins-src/components/google_analytics_roku/*.*' + }, + { + 'src': '**/roku_modules/**/*.*' + }, + { + 'src': '**/*spec.bs', + 'codes': ['LINT3011'] } ], 'plugins': [ '/home/george/hope/open-source/maestro/maestro-roku-bsc-plugin/dist/plugin.js', - '/home/george/hope/open-source/rooibos/bsc-plugin/dist/plugin.js' + '/home/george/hope/open-source/rooibos/bsc-plugin/dist/plugin.js', + '/home/george/hope/open-source/maestro/roku-log-bsc-plugin/dist/plugin.js' ], + 'ignore': ['maestro-roku-bsc-plugin'], + 'rokuLog': { + 'strip': false, + 'insertPkgPath': true, + 'removeComments': true + }, 'rooibos': { - 'isRecordingCodeCoverage': false, - 'testsFilePattern': null + 'tags': ['!integration', '!deprecated', '!fixme'], + 'showOnlyFailures': true, + 'catchCrashes': true, + 'lineWidth': 70, + 'failFast': false }, 'maestro': { - 'buildForIDE': false, - 'excludeFilters': [ - '**/roku_modules/**/*', - '**/rooibos/**/*', - '**/RALETrackerTask.xml' - ], + 'nodeClasses': { + 'buildForIDE': false, + 'generateTestUtils': true + }, + 'excludeFilters': ['**/roku_modules/**/*', '**/rooibos-roku/**/*'], 'buildTimeImports': { - 'IAuthProvider': [ - 'pkg:/source/zapp_oauth_plugin/ZappOAuthPlugin.bs' - ], - 'IEntitlementsProvider': [ - 'pkg:/source/simple_entitlements_roku/SimpleEntitlementsPlugin.bs' - ], + 'IAuthProvider': [], + 'IEntitlementsProvider': [], 'IBookmarksProvider': [], 'IPlayerAnalytics': [], - 'IAnalytics': [] + 'IAnalytics': [], + 'IBootstrapPlugin': [] + }, + 'mvvm': { + 'insertXmlBindingsEarly': false, + 'createCodeBehindFilesWhenNeeded': false, + 'insertCreateVMMethod': false, + 'callCreateVMMethodInInit': false, + 'callCreateNodeVarsInInit': true + }, + 'reflection': { + 'generateReflectionFunctions': true, + 'excludeFilters': ['**/roku_modules/**/*', '**/*.spec.bs'] } - }, - 'rokuLog': { - 'strip': false, - 'insertPkgPath': true, - 'removeComments': true - }, - 'sourceMap': true + } }; let z41 = { 'rootDir': '/home/george/hope/applicaster/4-1/zapp-roku-app/src', @@ -581,7 +584,13 @@ let nba = { } ], 'maestro': { - 'excludeFilters': ['**/roku_modules/**/*', '**/rooibos-roku/**/*'], + 'excludeFilters': [ + '**/roku_modules/**/*', + '**/rooibos-roku/**/*', + '**/bitmovinAnalytics/**/*.*', + '**/bitmovinPlayer/**/*.*', + '**/mediakind/**/*.*' + ], 'buildForIDE': true }, 'rooibos': { @@ -594,10 +603,7 @@ let nba = { 'removeComments': true }, 'logLevel': 'error', - 'retainStagingFolder': true, - 'transpileOptions': { - 'removeParameterTypes': true - } + 'retainStagingFolder': true }; @@ -605,9 +611,9 @@ let programBuilder = new ProgramBuilder(); programBuilder.run( // swv // zapp - // maestro + maestro // corco - nba + // nba // z41 // maestroSample // maestroList diff --git a/src/lib/files/MaestroConfig.ts b/src/lib/files/MaestroConfig.ts index cee1e81..c1206dd 100644 --- a/src/lib/files/MaestroConfig.ts +++ b/src/lib/files/MaestroConfig.ts @@ -18,6 +18,7 @@ export interface MaestroConfig { stripParamTypes?: boolean; paramStripExceptions?: string; applyStrictToAllClasses?: boolean; + processXMLFiles?: boolean; mvvm?: { insertXmlBindingsEarly?: boolean; createCodeBehindFilesWhenNeeded?: boolean; @@ -33,6 +34,10 @@ export interface MaestroConfig { generateReflectionFunctions?: boolean; //if true will generate the functions required to lookup classes by name excludeFilters?: string[]; // will exclude certain files from reflection }; + extraValidation?: { + doExtraValidation?: boolean; //if true will do additional maestro validation + excludeFilters?: string[]; // will exclude certain files from extra validation + }; } let docsLink = `\nPlease read the docs for usage details https://github.com/georgejecook/maestro/blob/master/docs/index.md#maestro-cli`; diff --git a/src/plugin.ts b/src/plugin.ts index 70727ee..b84bd88 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -99,19 +99,21 @@ export class MaestroPlugin implements CompilerPlugin { private getConfig(config: any) { //ignore roku modules by default - config = config?.maestro || { + config = config?.maestro ?? { buildTimeImports: {} }; - config.excludeFilters = config.excludeFilters || ['**/roku_modules/**/*']; - config.addFrameworkFiles = config.addFrameworkFiles || true; - config.stripParamTypes = config.stripParamTypes || true; - config.paramStripExceptions = config.paramStripExceptions || ['onKeyEvent']; - config.applyStrictToAllClasses = config.applyStrictToAllClasses || true; - config.nodeClasses = config.nodeClasses || {}; + config.excludeFilters = config.excludeFilters ?? ['**/roku_modules/**/*']; + config.addFrameworkFiles = config.addFrameworkFiles ?? true; + config.stripParamTypes = config.stripParamTypes ?? true; + config.processXMLFiles = config.processXMLFiles ?? true; + + config.paramStripExceptions = config.paramStripExceptions ?? ['onKeyEvent']; + config.applyStrictToAllClasses = config.applyStrictToAllClasses ?? true; + config.nodeClasses = config.nodeClasses ?? {}; config.nodeClasses.buildForIDE = config.buildForIDE; //legacy support config.nodeClasses.buildForIDE = config.nodeClasses.buildForIDE === undefined ? false : config.nodeClasses.buildForIDE; - config.mvvm = config.mvvm || {}; + config.mvvm = config.mvvm ?? {}; config.mvvm.insertXmlBindingsEarly = config.mvvm.insertXmlBindingsEarly === undefined ? false : config.mvvm.insertXmlBindingsEarly; config.mvvm.createCodeBehindFilesWhenNeeded = config.mvvm.createCodeBehindFilesWhenNeeded === undefined ? true : config.mvvm.createCodeBehindFilesWhenNeeded; @@ -119,9 +121,12 @@ export class MaestroPlugin implements CompilerPlugin { config.mvvm.callCreateVMMethodInInit = config.mvvm.callCreateVMMethodInInit === undefined ? true : config.mvvm.callCreateVMMethodInInit; config.mvvm.callCreateNodeVarsInInit = config.mvvm.callCreateNodeVarsInInit === undefined ? true : config.mvvm.callCreateNodeVarsInInit; - config.reflection = config.refelection || {}; + config.reflection = config.refelection ?? {}; config.reflection.generateReflectionFunctions = config.reflection.generateReflectionFunctions === undefined ? false : config.reflection.generateReflectionFunctions; config.reflection.excludeFilters = config.reflection.excludeFilters === undefined ? ['**/roku_modules/**/*', '**/*.spec.bs'] : config.reflection.excludeFilters; + config.extraValidation = config.extraValidation ?? {}; + config.extraValidation.doExtraValidation = config.extraValidation.doExtraValidation === undefined ? false : config.extraValidation.doExtraValidation; + config.extraValidation.excludeFilters = config.extraValidation.excludeFilters === undefined ? ['**/roku_modules/**/*'] : config.extraValidation.excludeFilters; return config; } @@ -198,29 +203,34 @@ export class MaestroPlugin implements CompilerPlugin { } // console.log('MAESTRO running stf.....'); let compFile = this.fileMap.allFiles.get(file.pathAbsolute); - if (compFile?.fileType === FileType.Xml && compFile?.vmClassName) { - this.bindingProcessor.parseBindings(compFile); - this.dirtyCompFilePaths.add(file.pathAbsolute); - } else { - for (let compFile of this.getCompFilesThatHaveFileInScope(file)) { - this.dirtyCompFilePaths.add(compFile.fullPath); + if (this.maestroConfig.processXMLFiles) { + + if (compFile?.fileType === FileType.Xml && compFile?.vmClassName) { + this.bindingProcessor.parseBindings(compFile); + this.dirtyCompFilePaths.add(file.pathAbsolute); + } else { + for (let compFile of this.getCompFilesThatHaveFileInScope(file)) { + this.dirtyCompFilePaths.add(compFile.fullPath); + } } } } beforeProgramValidate(program: Program) { // console.log('MAESTRO bpv-----'); - for (let filePath of [...this.dirtyCompFilePaths.values()]) { - console.time('Validate bindings'); - let file = this.fileMap.allFiles.get(filePath); - file.bscFile = this.builder.program.getFileByPathAbsolute(filePath); - file.resetDiagnostics(); - this.bindingProcessor.validateBindings(file); - if (this.maestroConfig.mvvm.insertXmlBindingsEarly && file.isValid) { - // console.log('adding xml transpiled code for ', file.bscFile.pkgPath); - this.bindingProcessor.generateCodeForXMLFile(file, this.builder.program); + if (this.maestroConfig.processXMLFiles) { + for (let filePath of [...this.dirtyCompFilePaths.values()]) { + console.time('Validate bindings'); + let file = this.fileMap.allFiles.get(filePath); + file.bscFile = this.builder.program.getFileByPathAbsolute(filePath); + file.resetDiagnostics(); + this.bindingProcessor.validateBindings(file); + if (this.maestroConfig.mvvm.insertXmlBindingsEarly && file.isValid) { + console.log('adding xml transpiled code for ', file.bscFile.pkgPath); + this.bindingProcessor.generateCodeForXMLFile(file, this.builder.program); + } + console.timeEnd('Validate bindings'); } - console.timeEnd('Validate bindings'); } if (!this.maestroConfig.nodeClasses.buildForIDE) { @@ -237,7 +247,6 @@ export class MaestroPlugin implements CompilerPlugin { } afterProgramValidate(program: Program) { - console.time('Do additional validations'); for (let f of Object.values(this.builder.program.files)) { if (f.pkgPath.startsWith('components/maestro/generated')) { (f as any).diagnostics = []; @@ -248,23 +257,30 @@ export class MaestroPlugin implements CompilerPlugin { } } } - for (let f of [...this.mFilesToValidate.values()]) { - let mFile = this.fileMap.allFiles.get(f.pathAbsolute); - if (mFile) { - this.checkMReferences(mFile); - this.doExtraValidations(f); + + if (this.maestroConfig.extraValidation.doExtraValidation) { + console.time('Do additional validations'); + for (let f of [...this.mFilesToValidate.values()]) { + let mFile = this.fileMap.allFiles.get(f.pathAbsolute); + if (mFile && this.shouldDoExtraValidationsOnFile(f)) { + this.checkMReferences(mFile); + this.doExtraValidations(f); + } } - } - console.timeEnd('Do additional validations'); - this.mFilesToValidate.clear(); - console.time('Validate node classes'); - for (let filePath of [...this.dirtyNodeClassPaths.values()]) { - for (let nc of this.fileMap.nodeClassesByPath.get(filePath)) { - nc.validate(); - nc.validateBaseComponent(this.builder, this.fileMap); + console.timeEnd('Do additional validations'); + + this.mFilesToValidate.clear(); + console.time('Validate node classes'); + for (let filePath of [...this.dirtyNodeClassPaths.values()]) { + for (let nc of this.fileMap.nodeClassesByPath.get(filePath)) { + if (this.shouldDoExtraValidationsOnFile(nc.file)) { + nc.validate(); + nc.validateBaseComponent(this.builder, this.fileMap); + } + } } + console.timeEnd('Validate node classes'); } - console.timeEnd('Validate node classes'); this.dirtyNodeClassPaths.clear(); } @@ -290,8 +306,27 @@ export class MaestroPlugin implements CompilerPlugin { } return true; } + shouldDoExtraValidationsOnFile(file: BscFile) { + if (!this.maestroConfig.extraValidation) { + return false; + } + if (this.shouldParseFile(file)) { + return false; + } + if (this.maestroConfig.extraValidation.excludeFilters) { + for (let filter of [...this.maestroConfig.extraValidation.excludeFilters, '**/components/maestro/generated/*']) { + if (minimatch(file.pathAbsolute, filter)) { + return false; + } + } + } + return true; + } beforeFileTranspile (entry: TranspileObj) { + if (!this.shouldParseFile(entry.file)) { + return; + } if (isBrsFile(entry.file) && this.shouldParseFile(entry.file)) { let classes = entry.file.parser.references.classStatements; for (let cs of classes) { @@ -329,7 +364,7 @@ export class MaestroPlugin implements CompilerPlugin { if (this.maestroConfig.stripParamTypes) { for (let fs of entry.file.parser.references.functionExpressions) { if (fs.returnType && !isVoidType(fs.returnType) && !isDynamicType(fs.returnType)) { - const name = fs.functionStatement?.name?.text || fs.parentFunction?.functionStatement?.name?.text; + const name = fs.functionStatement?.name?.text ?? fs.parentFunction?.functionStatement?.name?.text; if (!this.maestroConfig.paramStripExceptions.includes(name)) { fs.returnType = new DynamicType(); } @@ -347,7 +382,8 @@ export class MaestroPlugin implements CompilerPlugin { } beforeProgramTranspile(program: Program, entries: TranspileObj[]) { - if (!this.maestroConfig.mvvm.insertXmlBindingsEarly) { + console.log('++++++', this.maestroConfig.processXMLFiles); + if (!this.maestroConfig.mvvm.insertXmlBindingsEarly && this.maestroConfig.processXMLFiles) { console.time('Inject bindings into xml files'); for (let entry of entries) { @@ -455,6 +491,9 @@ export class MaestroPlugin implements CompilerPlugin { afterScopeValidate(scope: Scope, files: BscFile[], callables: CallableContainerMap) { + if (!this.maestroConfig.extraValidation.doExtraValidation) { + return; + } //validate the ioc calls let classMap = scope.getClassMap(); for (let mapItem of [...classMap.values()]) { @@ -463,6 +502,11 @@ export class MaestroPlugin implements CompilerPlugin { if (file.pkgPath.startsWith('components/maestro/generated')) { continue; } + if (!this.shouldDoExtraValidationsOnFile(file)) { + // console.log('skipping validation on ', file.pathAbsolute); + continue; + } + for (let f of cs.fields) { let annotation = (f.annotations || []).find((a) => a.name === 'inject' || a.name === 'injectClass' || a.name === 'createClass'); if (annotation) { From 2d2476f93e0902c8c62385531e414fbbcadb88a4 Mon Sep 17 00:00:00 2001 From: George Cook Date: Wed, 5 Jan 2022 09:20:30 +0100 Subject: [PATCH 3/5] fixes options settings --- package-lock.json | 17 ++++++++------- package.json | 1 + src/plugin.spec.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++- src/plugin.ts | 8 +++---- 4 files changed, 67 insertions(+), 13 deletions(-) diff --git a/package-lock.json b/package-lock.json index 41c202a..3c0f01f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "maestro-roku-bsc-plugin", - "version": "0.13.2", + "version": "0.13.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.13.2", + "version": "0.13.3", "license": "ISC", "dependencies": { "debounce": "^1.2.0", @@ -33,6 +33,7 @@ "mocha": "^8.1.3", "nyc": "^15.1.0", "sax": "^1.2.4", + "source-map-support": "^0.5.21", "typescript": "^4.1.3" } }, @@ -5070,9 +5071,9 @@ } }, "node_modules/source-map-support": { - "version": "0.5.19", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", - "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -9810,9 +9811,9 @@ "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==" }, "source-map-support": { - "version": "0.5.19", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", - "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "requires": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" diff --git a/package.json b/package.json index 272bda1..d48522d 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "mocha": "^8.1.3", "nyc": "^15.1.0", "sax": "^1.2.4", + "source-map-support": "^0.5.21", "typescript": "^4.1.3" }, "preferGlobal": true, diff --git a/src/plugin.spec.ts b/src/plugin.spec.ts index 9f5cc9d..397c57e 100644 --- a/src/plugin.spec.ts +++ b/src/plugin.spec.ts @@ -458,13 +458,45 @@ describe('MaestroPlugin', () => { `); expect(a).to.equal(b); + }); + it('does not manipulate xml files when xml processing is disabled', async () => { + plugin.maestroConfig.processXMLFiles = false; + plugin.afterProgramCreate(program); + program.addOrReplaceFile('components/comp.xml', ` + + + + + +`); + program.validate(); + expect(program.getDiagnostics()).to.be.empty; + await builder.transpile(); + console.log(builder.getDiagnostics()); + expect(builder.getDiagnostics()).to.be.empty; + + let a = getContents('components/comp.xml'); + //note - we still remove illegal vm attribute + let b = trimLeading(` + + +