From 41de13c449eebfdbf5023cb2e3725b4144c37bc9 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 15 Nov 2018 09:23:18 +0100 Subject: [PATCH 1/5] [INTERNAL] ESLint: Allow strings to use backticks --- .eslintrc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 480a895ce..ae146528b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -18,7 +18,8 @@ module.exports = { ], "quotes": [ "error", - "double" + "double", + { "allowTemplateLiterals": true } ], "semi": [ "error", From a6dd8e8b3b7058b33bfffbd8f8b04c5c035b324a Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 15 Nov 2018 13:36:47 +0100 Subject: [PATCH 2/5] [INTERNAL] package.json scripts: Update verbose logging params debug-module is not used in the tooling anymore --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e0e7cecaa..8f4edf4fc 100644 --- a/package.json +++ b/package.json @@ -21,10 +21,10 @@ "test": "npm run lint && npm run jsdoc-generate && npm run coverage", "lint": "eslint ./", "unit": "rimraf test/tmp && ava", + "unit-verbose": "rimraf test/tmp && cross-env UI5_LOG_LVL=verbose ava --verbose --serial", "unit-watch": "rimraf test/tmp && ava --watch", "unit-nyan": "npm run unit -- --tap | tnyan", - "unit-debug": "rimraf test/tmp && cross-env DEBUG=*,-babel,-ava ava", - "unit-inspect": "cross-env DEBUG=*,-babel,-ava node --inspect-brk node_modules/ava/profile.js", + "unit-inspect": "cross-env UI5_LOG_LVL=verbose node --inspect-brk node_modules/ava/profile.js", "coverage": "nyc npm run unit", "jsdoc": "npm run jsdoc-generate && opn jsdocs/index.html", "jsdoc-generate": "node_modules/.bin/jsdoc -c ./jsdoc.json ./lib/ || (echo 'Error during JSDoc generation! Check log.' && exit 1)", From cd5827963149eae807ce32defd215b1ef9ee10d1 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 15 Nov 2018 13:46:51 +0100 Subject: [PATCH 3/5] [INTERNAL] ESLint: prefer-const ESLint rule update will follow with eslint-config-google dependency bump. See https://github.com/google/eslint-config-google/pull/52 --- lib/builder/builder.js | 6 +- lib/lbt/analyzer/ComponentAnalyzer.js | 20 +-- lib/lbt/analyzer/FioriElementsAnalyzer.js | 28 ++--- lib/lbt/analyzer/JSModuleAnalyzer.js | 22 ++-- lib/lbt/analyzer/SmartTemplateAnalyzer.js | 22 ++-- lib/lbt/analyzer/XMLCompositeAnalyzer.js | 8 +- lib/lbt/analyzer/analyzeLibraryJS.js | 12 +- lib/lbt/bundle/AutoSplitter.js | 12 +- lib/lbt/bundle/Builder.js | 48 ++++---- lib/lbt/bundle/BundleWriter.js | 2 +- lib/lbt/bundle/ResolvedBundleDefinition.js | 2 +- lib/lbt/bundle/Resolver.js | 13 +- lib/lbt/calls/SapUiDefine.js | 2 +- lib/lbt/graph/dependencyGraph.js | 6 +- lib/lbt/graph/dominatorTree.js | 18 +-- lib/lbt/resources/LibraryFileAnalyzer.js | 12 +- lib/lbt/resources/ModuleInfo.js | 2 +- lib/lbt/resources/ResourceFilterList.js | 6 +- lib/lbt/resources/ResourcePool.js | 22 ++-- lib/lbt/utils/ModuleName.js | 4 +- lib/processors/bundlers/flexChangesBundler.js | 4 +- lib/processors/bundlers/manifestBundler.js | 4 +- lib/processors/manifestCreator.js | 116 +++++++++--------- lib/processors/themeBuilder.js | 8 +- lib/types/AbstractBuilder.js | 4 +- lib/types/library/LibraryFormatter.js | 2 +- lib/types/module/ModuleFormatter.js | 2 +- lib/types/typeRepository.js | 4 +- test/lib/builder/builder.js | 2 +- 29 files changed, 206 insertions(+), 207 deletions(-) diff --git a/lib/builder/builder.js b/lib/builder/builder.js index f57c9c377..50e3bb13d 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -65,7 +65,7 @@ function build({tree, destPath, buildDependencies = false, dev = false, selfCont " including dependencies..." + (dev ? " [dev mode]" : "")); log.verbose(`Building to ${destPath}...`); - let selectedTasks = composeTaskList({dev, selfContained, includedTasks, excludedTasks}); + const selectedTasks = composeTaskList({dev, selfContained, includedTasks, excludedTasks}); const fsTarget = resourceFactory.createAdapter({ fsBasePath: destPath, @@ -201,7 +201,7 @@ function composeTaskList({dev, selfContained, includedTasks, excludedTasks}) { // Exclude tasks for (let i = 0; i < excludedTasks.length; i++) { - let taskName = excludedTasks[i]; + const taskName = excludedTasks[i]; if (taskName === "*") { Object.keys(selectedTasks).forEach((sKey) => { selectedTasks[sKey] = false; @@ -215,7 +215,7 @@ function composeTaskList({dev, selfContained, includedTasks, excludedTasks}) { // Include tasks for (let i = 0; i < includedTasks.length; i++) { - let taskName = includedTasks[i]; + const taskName = includedTasks[i]; if (taskName === "*") { Object.keys(selectedTasks).forEach((sKey) => { selectedTasks[sKey] = true; diff --git a/lib/lbt/analyzer/ComponentAnalyzer.js b/lib/lbt/analyzer/ComponentAnalyzer.js index accb2ec39..4abcae7ec 100644 --- a/lib/lbt/analyzer/ComponentAnalyzer.js +++ b/lib/lbt/analyzer/ComponentAnalyzer.js @@ -56,11 +56,11 @@ class ComponentAnalyzer { return info; } - let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); + const manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); try { - let manifestResource = await this._pool.findResource(manifestName).catch(() => null); + const manifestResource = await this._pool.findResource(manifestName).catch(() => null); if ( manifestResource ) { - let fileContent = await manifestResource.buffer(); + const fileContent = await manifestResource.buffer(); this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } else { log.verbose("No manifest found for '%s', skipping analysis", resource.name); @@ -82,7 +82,7 @@ class ComponentAnalyzer { * @private */ _analyzeManifest( manifest, info ) { - let ui5 = (manifest && manifest["sap.ui5"]) || {}; + const ui5 = (manifest && manifest["sap.ui5"]) || {}; if ( ui5.resources && ui5.resources.css ) { // TODO how to handle CSS dependencies? @@ -93,7 +93,7 @@ class ComponentAnalyzer { } if ( ui5.rootView ) { - let module = ModuleName.fromUI5LegacyName( + const module = ModuleName.fromUI5LegacyName( ui5.rootView.viewName, ".view." + ui5.rootView.type.toLowerCase() ); log.verbose("adding root view dependency ", module); @@ -101,13 +101,13 @@ class ComponentAnalyzer { } each( ui5.dependencies && ui5.dependencies.libs, (options, lib) => { - let module = ModuleName.fromUI5LegacyName(lib, "/library.js"); + const module = ModuleName.fromUI5LegacyName(lib, "/library.js"); log.verbose("adding library dependency ", module, options.lazy || false); info.addDependency( module, options.lazy ); // lazy -> conditional dependency }); each( ui5.dependencies && ui5.dependencies.components, (options, component) => { - let module = ModuleName.fromUI5LegacyName(component, "/Component.js"); + const module = ModuleName.fromUI5LegacyName(component, "/Component.js"); log.verbose("adding component dependency ", module, options.lazy || false); info.addDependency( module, options.lazy ); // lazy -> conditional dependency }); @@ -116,18 +116,18 @@ class ComponentAnalyzer { each( ui5.models, (options, model) => { if ( options.type ) { - let module = ModuleName.fromUI5LegacyName( options.type ); + const module = ModuleName.fromUI5LegacyName( options.type ); log.verbose("derived model implementation dependency ", module); info.addDependency(module); } }); - let routing = ui5.routing; + const routing = ui5.routing; if ( routing ) { if (Array.isArray(routing.routes)) { routing.routes.forEach((route) => this._visitRoute(route, routing, info)); } else { - for (let key in routing.routes) { + for (const key in routing.routes) { if (!routing.routes.hasOwnProperty(key)) { continue; } diff --git a/lib/lbt/analyzer/FioriElementsAnalyzer.js b/lib/lbt/analyzer/FioriElementsAnalyzer.js index f1b00194f..f4beceb23 100644 --- a/lib/lbt/analyzer/FioriElementsAnalyzer.js +++ b/lib/lbt/analyzer/FioriElementsAnalyzer.js @@ -93,11 +93,11 @@ class FioriElementsAnalyzer { return info; } - let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); + const manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); try { - let manifestResource = await this._pool.findResource(manifestName).catch(() => null); + const manifestResource = await this._pool.findResource(manifestName).catch(() => null); if ( manifestResource ) { - let fileContent = await manifestResource.buffer(); + const fileContent = await manifestResource.buffer(); await this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } else { log.verbose("No manifest found for '%s', skipping analysis", resource.name); @@ -119,8 +119,8 @@ class FioriElementsAnalyzer { * @private */ async _analyzeManifest( manifest, info ) { - let promises = []; - let st = (manifest && manifest["sap.fe"]) || {}; + const promises = []; + const st = (manifest && manifest["sap.fe"]) || {}; each(st.entitySets, (entitySetCfg) => { each(entitySetCfg, (activityCfg, activity) => { @@ -144,14 +144,14 @@ class FioriElementsAnalyzer { async _analyzeTemplateComponent(moduleName, pageConfig, appInfo) { // console.log("analyzing template component %s", moduleName); - let resource = await this._pool.findResource(moduleName); - let code = await resource.buffer(); - let ast = esprima.parse(code); - let defaultTemplateName = this._analyzeAST(moduleName, ast); - let templateName = (pageConfig.component && pageConfig.component.settings && + const resource = await this._pool.findResource(moduleName); + const code = await resource.buffer(); + const ast = esprima.parse(code); + const defaultTemplateName = this._analyzeAST(moduleName, ast); + const templateName = (pageConfig.component && pageConfig.component.settings && pageConfig.component.settings.templateName) || defaultTemplateName; if ( templateName ) { - let templateModuleName = ModuleName.fromUI5LegacyName( templateName, ".view.xml" ); + const templateModuleName = ModuleName.fromUI5LegacyName( templateName, ".view.xml" ); log.verbose("template app: add dependency to template view %s", templateModuleName); appInfo.addDependency(templateModuleName); } @@ -161,8 +161,8 @@ class FioriElementsAnalyzer { let templateName = ""; if ( ast.body.length > 0 && (isMethodCall(ast.body[0].expression, CALL_SAP_UI_DEFINE) || isMethodCall(ast.body[0].expression, CALL_DEFINE)) ) { - let defineCall = new SapUiDefine(ast.body[0].expression, moduleName); - let TA = defineCall.findImportName("sap/fe/core/TemplateAssembler.js"); + const defineCall = new SapUiDefine(ast.body[0].expression, moduleName); + const TA = defineCall.findImportName("sap/fe/core/TemplateAssembler.js"); // console.log("local name for TemplateAssembler: %s", TA); if ( TA && defineCall.factory ) { defineCall.factory.body.body.forEach( (stmt) => { @@ -179,7 +179,7 @@ class FioriElementsAnalyzer { } _analyzeTemplateClassDefinition(clazz) { - let defaultValue = getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]); + const defaultValue = getValue(clazz, ["metadata", "properties", "templateName", "defaultValue"]); if ( isString(defaultValue) ) { return defaultValue.value; } diff --git a/lib/lbt/analyzer/JSModuleAnalyzer.js b/lib/lbt/analyzer/JSModuleAnalyzer.js index 70e85f4eb..3549889a7 100644 --- a/lib/lbt/analyzer/JSModuleAnalyzer.js +++ b/lib/lbt/analyzer/JSModuleAnalyzer.js @@ -164,7 +164,7 @@ const EnrichedVisitorKeys = (function() { }; // check for unknown keys in our configuration - for ( let type in TempKeys ) { + for ( const type in TempKeys ) { if ( VisitorKeys[type] === undefined ) { throw new Error("configuration contains unknown node type '" + type + "'"); } @@ -172,8 +172,8 @@ const EnrichedVisitorKeys = (function() { // merge with 'official' visitor keys Object.keys(VisitorKeys).forEach( (type) => { - let visitorKeys = VisitorKeys[type]; - let condKeys = TempKeys[type]; + const visitorKeys = VisitorKeys[type]; + const condKeys = TempKeys[type]; if ( condKeys === undefined ) { // configuration missing in ConditionalKeys, maybe a new syntax ? throw new Error(`unknown estree node type '${type}', new syntax?`); @@ -269,7 +269,7 @@ class JSModuleAnalyzer { return; } - let condKeys = EnrichedVisitorKeys[node.type]; + const condKeys = EnrichedVisitorKeys[node.type]; switch (node.type) { case Syntax.CallExpression: if ( !conditional && isMethodCall(node, CALL_JQUERY_SAP_DECLARE) ) { @@ -336,7 +336,7 @@ class JSModuleAnalyzer { || isMethodCall(node, CALL_REQUIRE_PRELOAD) || isMethodCall(node, CALL_SAP_UI_REQUIRE_PRELOAD) ) { // recognizes a call to jQuery.sap.registerPreloadedModules - let legacyCall = isMethodCall(node, CALL_JQUERY_SAP_REGISTER_PRELOADED_MODULES); + const legacyCall = isMethodCall(node, CALL_JQUERY_SAP_REGISTER_PRELOADED_MODULES); info.setFormat( legacyCall ? ModuleFormat.UI5_LEGACY : ModuleFormat.UI5_DEFINE); onRegisterPreloadedModules(node, legacyCall); } else if ( isCallableExpression(node.callee) ) { @@ -346,7 +346,7 @@ class JSModuleAnalyzer { visit(node.callee.body, conditional); } else { // default visit - for ( let key of condKeys ) { + for ( const key of condKeys ) { visit(node[key.key], key.conditional || conditional); } } @@ -366,7 +366,7 @@ class JSModuleAnalyzer { visit(node.alternate, true); } else { // default visit - for ( let key of condKeys ) { + for ( const key of condKeys ) { visit(node[key.key], key.conditional || conditional); } } @@ -378,7 +378,7 @@ class JSModuleAnalyzer { throw new Error(`Unhandled AST node type ${node.type}`); } // default visit - for ( let key of condKeys ) { + for ( const key of condKeys ) { visit(node[key.key], key.conditional || conditional); } break; @@ -454,7 +454,7 @@ class JSModuleAnalyzer { } else { // UI5 signature with one or many required modules for (let i = 0; i < nArgs; i++) { - let arg = args[i]; + const arg = args[i]; if ( isString(arg) ) { const requiredModuleName = ModuleName.fromUI5LegacyName( arg.value ); info.addDependency(requiredModuleName, conditional); @@ -475,7 +475,7 @@ class JSModuleAnalyzer { function onSapUiRequireSync(node, conditional) { const args = node.arguments; const nArgs = args.length; - let i = 0; + const i = 0; if ( i < nArgs && isString(args[i]) ) { const moduleName = ModuleName.fromRequireJSName( args[i].value ); @@ -509,7 +509,7 @@ class JSModuleAnalyzer { if ( legacyCall ) { const obj = args[0]; isNewSyntax = false; - let version = findOwnProperty(obj, "version"); + const version = findOwnProperty(obj, "version"); if ( version && isString(version) && parseFloat(version.value) >= 2.0 ) { isNewSyntax = true; } diff --git a/lib/lbt/analyzer/SmartTemplateAnalyzer.js b/lib/lbt/analyzer/SmartTemplateAnalyzer.js index 28f9ccbd9..52da97d42 100644 --- a/lib/lbt/analyzer/SmartTemplateAnalyzer.js +++ b/lib/lbt/analyzer/SmartTemplateAnalyzer.js @@ -52,11 +52,11 @@ class TemplateComponentAnalyzer { return info; } - let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); + const manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); try { - let manifestResource = await this._pool.findResource(manifestName).catch(() => null); + const manifestResource = await this._pool.findResource(manifestName).catch(() => null); if ( manifestResource ) { - let fileContent = await manifestResource.buffer(); + const fileContent = await manifestResource.buffer(); await this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } else { log.verbose("No manifest found for '%s', skipping analysis", resource.name); @@ -78,14 +78,14 @@ class TemplateComponentAnalyzer { * @private */ async _analyzeManifest( manifest, info ) { - let promises = []; - let that = this; - let st = (manifest && manifest["sap.ui.generic.app"]) || {}; + const promises = []; + const that = this; + const st = (manifest && manifest["sap.ui.generic.app"]) || {}; function recurse(ctx) { if ( ctx.pages ) { ctx.pages.forEach((page) => { if ( page.component && page.component.name ) { - let module = ModuleName.fromUI5LegacyName( page.component.name + ".Component" ); + const module = ModuleName.fromUI5LegacyName( page.component.name + ".Component" ); log.verbose("template app: add dependency to template component %s", module); info.addDependency(module); promises.push( that._analyzeTemplateComponent(module, page, info) ); @@ -101,8 +101,8 @@ class TemplateComponentAnalyzer { async _analyzeTemplateComponent(moduleName, pageConfig, appInfo) { // console.log("analyzing template component %s", moduleName); - let resource = await this._pool.findResource(moduleName); - let code = await resource.buffer(); + const resource = await this._pool.findResource(moduleName); + const code = await resource.buffer(); const ast = esprima.parse(code); const defaultTemplateName = this._analyzeAST(moduleName, ast); const templateName = (pageConfig.component && pageConfig.component.settings && @@ -118,8 +118,8 @@ class TemplateComponentAnalyzer { let templateName = ""; if ( ast.body.length > 0 && (isMethodCall(ast.body[0].expression, CALL_SAP_UI_DEFINE) || isMethodCall(ast.body[0].expression, CALL_DEFINE)) ) { - let defineCall = new SapUiDefine(ast.body[0].expression, moduleName); - let TA = defineCall.findImportName("sap/suite/ui/generic/template/lib/TemplateAssembler.js"); + const defineCall = new SapUiDefine(ast.body[0].expression, moduleName); + const TA = defineCall.findImportName("sap/suite/ui/generic/template/lib/TemplateAssembler.js"); // console.log("local name for TemplateAssembler: %s", TA); if ( TA && defineCall.factory ) { defineCall.factory.body.body.forEach( (stmt) => { diff --git a/lib/lbt/analyzer/XMLCompositeAnalyzer.js b/lib/lbt/analyzer/XMLCompositeAnalyzer.js index aeffca808..ee127e1d6 100644 --- a/lib/lbt/analyzer/XMLCompositeAnalyzer.js +++ b/lib/lbt/analyzer/XMLCompositeAnalyzer.js @@ -16,8 +16,8 @@ class XMLCompositeAnalyzer { if ( ast.body.length > 0 && ast.body[0].type === Syntax.ExpressionStatement && (isMethodCall(ast.body[0].expression, CALL_SAP_UI_DEFINE) || isMethodCall(ast.body[0].expression, CALL_DEFINE)) ) { - let defineCall = new SapUiDefine(ast.body[0].expression, moduleName); - let XMLC = defineCall.findImportName("sap/ui/core/XMLComposite.js"); + const defineCall = new SapUiDefine(ast.body[0].expression, moduleName); + const XMLC = defineCall.findImportName("sap/ui/core/XMLComposite.js"); // console.log("local name for XMLComposite: %s", XMLC); if ( XMLC && defineCall.factory ) { defineCall.factory.body.body.forEach( (stmt) => { @@ -31,7 +31,7 @@ class XMLCompositeAnalyzer { } }); if ( fragmentName ) { - let fragmentModule = ModuleName.fromUI5LegacyName( fragmentName, ".control.xml" ); + const fragmentModule = ModuleName.fromUI5LegacyName( fragmentName, ".control.xml" ); log.verbose("fragment control: add dependency to template fragment %s", fragmentModule); info.addDependency(fragmentModule); } @@ -55,7 +55,7 @@ class XMLCompositeAnalyzer { _analyzeXMLCClassDefinition(clazz) { // log.verbose(clazz); - let fragmentName = getValue(clazz, ["fragment"]); + const fragmentName = getValue(clazz, ["fragment"]); if ( isString(fragmentName) ) { return fragmentName.value; } diff --git a/lib/lbt/analyzer/analyzeLibraryJS.js b/lib/lbt/analyzer/analyzeLibraryJS.js index d2b88ff70..f995ac34f 100644 --- a/lib/lbt/analyzer/analyzeLibraryJS.js +++ b/lib/lbt/analyzer/analyzeLibraryJS.js @@ -11,7 +11,7 @@ const CALL__SAP_UI_GETCORE = ["sap", "ui", "getCore"]; * call in a library.js module. */ async function analyze(resource) { - let libInfo = { + const libInfo = { noLibraryCSS: false, types: [], controls: [], @@ -27,8 +27,8 @@ async function analyze(resource) { && node.arguments.length === 1 && node.arguments[0].type === Syntax.ObjectExpression ) { node.arguments[0].properties.forEach( (prop) => { - let key = getPropertyKey(prop); - let value = prop.value; + const key = getPropertyKey(prop); + const value = prop.value; if ( key === "noLibraryCSS" && (value.type === Syntax.Literal && typeof value.value === "boolean") ) { libInfo.noLibraryCSS = value.value; @@ -46,8 +46,8 @@ async function analyze(resource) { return true; // abort, we're done } - for ( let key of VisitorKeys[node.type] ) { - let child = node[key]; + for ( const key of VisitorKeys[node.type] ) { + const child = node[key]; if ( Array.isArray(child) ) { if ( child.some(visit) ) { return true; @@ -62,7 +62,7 @@ async function analyze(resource) { return false; } - let code = await resource.getBuffer(); + const code = await resource.getBuffer(); visit( esprima.parse(code) ); return libInfo; diff --git a/lib/lbt/bundle/AutoSplitter.js b/lib/lbt/bundle/AutoSplitter.js index d08ad3178..39a9fa37f 100644 --- a/lib/lbt/bundle/AutoSplitter.js +++ b/lib/lbt/bundle/AutoSplitter.js @@ -74,7 +74,7 @@ class AutoSplitter { totalSize, numberOfParts, partSize); // ---- create a separate module definition for each part - let splittedModules = []; + const splittedModules = []; let moduleNameWithPart = moduleDef.name; if ( !/__part__/.test(moduleNameWithPart) ) { moduleNameWithPart = ModuleName.toRequireJSName(moduleNameWithPart) + "-__part__.js"; @@ -126,7 +126,7 @@ class AutoSplitter { currentSection.name = section.name; currentModule.sections.push( currentSection ); section.modules.forEach( (module) => { - let moduleSize = moduleSizes[module]; + const moduleSize = moduleSizes[module]; if ( part + 1 < numberOfParts && totalSize + moduleSize / 2 > partSize ) { part++; // start a new module @@ -172,7 +172,7 @@ class AutoSplitter { } async _calcMinSize(module) { - let resource = await this.pool.findResourceWithInfo(module); + const resource = await this.pool.findResourceWithInfo(module); if ( resource != null ) { if ( resource.info && resource.info.compressedSize && resource.info.compressedSize !== resource.info.size ) { @@ -184,7 +184,7 @@ class AutoSplitter { let fileContent = await resource.buffer(); if ( this.optimize ) { // console.log("uglify %s start", module); - let result = uglify.minify({ + const result = uglify.minify({ [resource.name]: String(fileContent) }, { warnings: false, // TODO configure? @@ -204,7 +204,7 @@ class AutoSplitter { // trace.debug("analyzed %s:%d%n", module, mw.getTargetLength()); return fileContent.length; } else if ( /\.properties$/.test(module) ) { - let fileContent = await resource.buffer(); + const fileContent = await resource.buffer(); /* NODE-TODO minimize *.properties Properties props = new Properties(); props.load(in); @@ -230,7 +230,7 @@ class AutoSplitter { // if there is no precompiled information about the resource, just determine its length if ( !resource.info && /\.(js|json|xml)$/.test(module) ) { - let fileContent = await resource.buffer(); + const fileContent = await resource.buffer(); return fileContent.length; } } diff --git a/lib/lbt/bundle/Builder.js b/lib/lbt/bundle/Builder.js index 64ce29b02..99faa2624 100644 --- a/lib/lbt/bundle/Builder.js +++ b/lib/lbt/bundle/Builder.js @@ -105,9 +105,9 @@ class BundleBuilder { async createBundle(module, options) { await this._prepare(); if ( options.numberOfParts > 1 ) { - let bundleInfos = []; - let submodules = await this.splitter.run( module, options ); - for ( let submodule of submodules ) { + const bundleInfos = []; + const submodules = await this.splitter.run( module, options ); + for ( const submodule of submodules ) { bundleInfos.push( await this._createBundle(submodule, options) ); } return bundleInfos; @@ -128,7 +128,7 @@ class BundleBuilder { } async _createBundle(module, options) { - let resolvedModule = await this.resolver.resolve(module /* NODE-TODO, vars */); + const resolvedModule = await this.resolver.resolve(module /* NODE-TODO, vars */); log.verbose(" create '%s'", resolvedModule.name); this.options = options || {}; @@ -146,7 +146,7 @@ class BundleBuilder { this.writeConfiguration(resolvedModule.configuration); // NODE-TODO configuration currently will be undefined // create all sections in sequence - for ( let section of resolvedModule.sections ) { + for ( const section of resolvedModule.sections ) { log.verbose(" adding section%s of type %s", section.name ? " '" + section.name + "'" : "", section.mode); await this.addSection(section); @@ -154,7 +154,7 @@ class BundleBuilder { this.closeModule(resolvedModule); - let bundleInfo = await resolvedModule.createModuleInfo(this.pool); + const bundleInfo = await resolvedModule.createModuleInfo(this.pool); bundleInfo.size = this.outW.length; return { @@ -250,8 +250,8 @@ class BundleBuilder { // TODO check that there are only JS modules contained async writeRaw(section) { // write all modules in sequence - for ( let module of section.modules ) { - let resource = await this.pool.findResourceWithInfo(module); + for ( const module of section.modules ) { + const resource = await this.pool.findResourceWithInfo(module); if ( resource != null ) { this.outW.startSegment(module); await this.writeRawModule(module, resource); @@ -292,8 +292,8 @@ class BundleBuilder { if ( sequence.length > 0 ) { this.targetBundleFormat.beforePreloads(outW, section); let i = 0; - for ( let module of sequence ) { - let resource = await this.pool.findResourceWithInfo(module); + for ( const module of sequence ) { + const resource = await this.pool.findResourceWithInfo(module); if ( resource != null ) { if ( i>0 ) { outW.writeln(","); @@ -322,7 +322,7 @@ class BundleBuilder { compressJS(fileContent, resource) { if ( this.optimize ) { - let result = uglify.minify({ + const result = uglify.minify({ [resource.name]: String(fileContent) }, { warnings: false, // TODO configure? @@ -346,7 +346,7 @@ class BundleBuilder { } async compressJSAsync(resource) { - let content = await resource.buffer(); + const content = await resource.buffer(); return this.compressJS( content, resource ); } @@ -357,19 +357,19 @@ class BundleBuilder { async rewriteAMDModules(sequence, avoidLazyParsing) { if ( this.options.usePredefineCalls ) { - let outW = this.outW; + const outW = this.outW; - let remaining = []; - for ( let module of sequence ) { + const remaining = []; + for ( const module of sequence ) { if ( /\.js$/.test(module) ) { // console.log("Processing " + module); - let resource = await this.pool.findResourceWithInfo(module); - let code = await resource.buffer(); + const resource = await this.pool.findResourceWithInfo(module); + const code = await resource.buffer(); const ast = rewriteDefine(this.targetBundleFormat, code, module, avoidLazyParsing); if ( ast ) { outW.startSegment(module); outW.ensureNewLine(); - let astAsCode = escodegen.generate(ast); + const astAsCode = escodegen.generate(ast); const fileContent = this.compressJS(astAsCode, resource); outW.write( fileContent ); outW.ensureNewLine(); @@ -400,7 +400,7 @@ class BundleBuilder { const outW = this.outW; if ( /\.js$/.test(module) && (info == null || !info.requiresTopLevelScope) ) { - let compressedContent = await this.compressJSAsync( resource ); + const compressedContent = await this.compressJSAsync( resource ); if ( avoidLazyParsing ) { outW.write(`(`); } @@ -415,10 +415,10 @@ class BundleBuilder { } else if ( /\.js$/.test(module) /* implicitly: && info != null && info.requiresTopLevelScope */ ) { log.warn("**** warning: module %s requires top level scope" + " and can only be embedded as a string (requires 'eval')", module); - let compressedContent = await this.compressJSAsync( resource ); + const compressedContent = await this.compressJSAsync( resource ); outW.write( makeStringLiteral( compressedContent ) ); } else if ( /\.html$/.test(module) ) { - let fileContent = await resource.buffer(); + const fileContent = await resource.buffer(); outW.write( makeStringLiteral( fileContent ) ); } else if ( /\.json$/.test(module) ) { let fileContent = await resource.buffer(); @@ -443,7 +443,7 @@ class BundleBuilder { outW.write( makeStringLiteral( fileContent ) ); } else if ( /\.properties$/.test(module) ) { // same as for other text files, but input encoding is ISO_8859_1 - let fileContent = await resource.buffer(); + const fileContent = await resource.buffer(); outW.write( makeStringLiteral( fileContent.toString("latin1") ) ); } else { log.error("don't know how to embed module " + module); // TODO throw? @@ -522,7 +522,7 @@ function rewriteDefine(targetBundleFormat, code, moduleName, avoidLazyParsing) { && ast.body[0].type === Syntax.ExpressionStatement ) { // rewrite define to require.predefine if ( targetBundleFormat.supportsNativeDefine() && isMethodCall(ast.body[0].expression, CALL_DEFINE) ) { - let defineCall = ast.body[0].expression; + const defineCall = ast.body[0].expression; if ( defineCall.callee.type === Syntax.Identifier && defineCall.callee.name === "define" ) { @@ -565,7 +565,7 @@ function rewriteDefine(targetBundleFormat, code, moduleName, avoidLazyParsing) { if ( isMethodCall(ast.body[0].expression, CALL_SAP_UI_DEFINE) ) { - let defineCall = ast.body[0].expression; + const defineCall = ast.body[0].expression; // rewrite sap.ui.define to sap.ui.predefine if ( defineCall.callee.type === Syntax.MemberExpression diff --git a/lib/lbt/bundle/BundleWriter.js b/lib/lbt/bundle/BundleWriter.js index 20c45ff98..2862fb35a 100644 --- a/lib/lbt/bundle/BundleWriter.js +++ b/lib/lbt/bundle/BundleWriter.js @@ -67,7 +67,7 @@ class BundleWriter { } this.currentSegment.endIndex = this.length; this.segments.push(this.currentSegment); - let targetSize = this.currentSegment.endIndex - this.currentSegment.startIndex; + const targetSize = this.currentSegment.endIndex - this.currentSegment.startIndex; this.currentSegment = null; this.currentSourceIndex = -1; return targetSize; diff --git a/lib/lbt/bundle/ResolvedBundleDefinition.js b/lib/lbt/bundle/ResolvedBundleDefinition.js index a84b77d0d..6eb600c1d 100644 --- a/lib/lbt/bundle/ResolvedBundleDefinition.js +++ b/lib/lbt/bundle/ResolvedBundleDefinition.js @@ -39,7 +39,7 @@ class ResolvedBundleDefinition { } createModuleInfo(pool) { - let bundleInfo = new ModuleInfo(); + const bundleInfo = new ModuleInfo(); bundleInfo.name = this.name; let promise = Promise.resolve(true); diff --git a/lib/lbt/bundle/Resolver.js b/lib/lbt/bundle/Resolver.js index 98826bb66..661d22761 100644 --- a/lib/lbt/bundle/Resolver.js +++ b/lib/lbt/bundle/Resolver.js @@ -45,10 +45,11 @@ class BundleResolver { * @returns {Collection} */ function collectModulesForSection(section) { - let filters; let prevLength; let newKeys; + const filters = new ResourceFilterList( section.filters ); // resolvePlaceholders(section.getFilters()); + function isAccepted(resourceName, required) { let match = required; // evaluate module filters only when global filters match @@ -75,7 +76,7 @@ class BundleResolver { visitedResources[resourceName] = resourceName; done = pool.findResourceWithInfo(resourceName).then( function(resource) { - let dependencyInfo = resource && resource.info; + const dependencyInfo = resource && resource.info; let promises = []; if ( isMultiModule(dependencyInfo) ) { @@ -134,8 +135,6 @@ class BundleResolver { return done; } - filters = new ResourceFilterList( section.filters ); // resolvePlaceholders(section.getFilters()); - let oldSelectedResources; let oldIgnoredResources; let oldSelectedResourcesSequence; @@ -191,7 +190,7 @@ class BundleResolver { */ // scan all known resources - let promises = pool.resources.map( function(resource) { + const promises = pool.resources.map( function(resource) { return checkAndAddResource(resource.name, 0); }); @@ -244,7 +243,7 @@ class BundleResolver { log.verbose(" resolving bundle definition %s", bundle.name); - let resolved = new ResolvedBundleDefinition(bundle /* , vars*/); + const resolved = new ResolvedBundleDefinition(bundle /* , vars*/); let previous = Promise.resolve(true); @@ -254,7 +253,7 @@ class BundleResolver { section.name ? " '" + section.name + "'" : "", section.mode); // NODE-TODO long t0=System.nanoTime(); - let resolvedSection = resolved.sections[index]; + const resolvedSection = resolved.sections[index]; return collectModulesForSection(section). then( (modules) => { diff --git a/lib/lbt/calls/SapUiDefine.js b/lib/lbt/calls/SapUiDefine.js index 6651aae4b..50695b2fe 100644 --- a/lib/lbt/calls/SapUiDefine.js +++ b/lib/lbt/calls/SapUiDefine.js @@ -64,7 +64,7 @@ class SapUiDefineCall { }*/ findImportName(module) { - let idx = this.dependencies ? this.dependencies.indexOf(module) : -1; + const idx = this.dependencies ? this.dependencies.indexOf(module) : -1; if ( idx >= 0 ) { return this.paramNames[idx]; } diff --git a/lib/lbt/graph/dependencyGraph.js b/lib/lbt/graph/dependencyGraph.js index 6b8b16178..76ddcbc64 100644 --- a/lib/lbt/graph/dependencyGraph.js +++ b/lib/lbt/graph/dependencyGraph.js @@ -29,7 +29,7 @@ function createDependencyGraph(pool, roots, options) { node.visited = true; return pool.getModuleInfo( name ).then( (module) => { - let p = module.dependencies.map( (dep) => { + const p = module.dependencies.map( (dep) => { if ( includeConditionalDependencies || !module.isConditionalDependency(dep) ) { return visitNode(dep).then( (child) => child.pred.add( node ) ); } @@ -41,9 +41,9 @@ function createDependencyGraph(pool, roots, options) { } // create artificial root node and link it with roots - let n0 = new Node(""); + const n0 = new Node(""); nodes.set("", n0); - let p = roots.map( (root) => { + const p = roots.map( (root) => { // console.log(" entry point %s", root.name); return visitNode(root.name).then( (child) => child.pred.add( n0 ) ); }); diff --git a/lib/lbt/graph/dominatorTree.js b/lib/lbt/graph/dominatorTree.js index 28f8951de..aa975a294 100644 --- a/lib/lbt/graph/dominatorTree.js +++ b/lib/lbt/graph/dominatorTree.js @@ -18,7 +18,7 @@ function calculateDominatorTree({n0, nodes}) { const log = require("@ui5/logger").getLogger("lbt:graph:dominatorTree"); // initialize set of dominators for each node - for ( let n of nodes.values() ) { + for ( const n of nodes.values() ) { if ( n === n0 ) { // dominator of the start node is the start node itself n.dominators = new Set().add(n); @@ -32,7 +32,7 @@ function calculateDominatorTree({n0, nodes}) { function countEdges(nodes) { let count = 0; - for ( let n of nodes.values() ) { + for ( const n of nodes.values() ) { count += n.dominators.size; } return count; @@ -46,12 +46,12 @@ function calculateDominatorTree({n0, nodes}) { log.verbose("%d remaining edges", countEdges(nodes)); modified = false; - for ( let n of nodes.values() ) { + for ( const n of nodes.values() ) { if ( n === n0 ) { continue; // no processing for the root node } // Dom(n) = {n} union with intersection over Dom(p) for all p in pred(n) */ - for ( let d of n.dominators ) { + for ( const d of n.dominators ) { if ( d === n ) { continue; // by definition, n is always a dominator of its own } @@ -60,7 +60,7 @@ function calculateDominatorTree({n0, nodes}) { // is implemented by checking each current dominator of n whether it is contained // in the dominator sets of all predecessors. If not, it is removed from the // set of dominotors of n. - for ( let p of n.pred ) { + for ( const p of n.pred ) { if ( !p.dominators.has(d) ) { n.dominators.delete(d); modified = true; @@ -72,8 +72,8 @@ function calculateDominatorTree({n0, nodes}) { } while (modified); // build the inverse of the 'strictly-dominated-by' graph ('strictly-dominates' graph) - for ( let n of nodes.values() ) { - for ( let d of n.dominators ) { + for ( const n of nodes.values() ) { + for ( const d of n.dominators ) { if ( d !== n ) { // ignore edge to self ('strict') d.succ.add(n); } @@ -91,13 +91,13 @@ function calculateDominatorTree({n0, nodes}) { // is marked as 'immediately dominated' function dfs(node) { // visit children, thereby identifying non-immediately dominated nodes - for ( let child of node.succ ) { + for ( const child of node.succ ) { if ( !child.visited ) { // console.log("visit %s->%s (visited:%s)", node.name, child.name, child.visited); dfs(child); } } - for ( let child of node.succ ) { + for ( const child of node.succ ) { if ( child.visited ) { // console.log("delete %s -> %s", node.name, child.name) node.succ.delete(child); diff --git a/lib/lbt/resources/LibraryFileAnalyzer.js b/lib/lbt/resources/LibraryFileAnalyzer.js index 1bb27923e..c69af7d2a 100644 --- a/lib/lbt/resources/LibraryFileAnalyzer.js +++ b/lib/lbt/resources/LibraryFileAnalyzer.js @@ -21,16 +21,16 @@ function getAttribute(node, attr) { } function makeModuleInfo(rawModule) { - let name = getAttribute(rawModule, "name"); - let deps = getAttribute(rawModule, "depends"); + const name = getAttribute(rawModule, "name"); + const deps = getAttribute(rawModule, "depends"); if ( name ) { - let info = new ModuleInfo(name); + const info = new ModuleInfo(name); if ( deps != null ) { deps.trim().split(/\s*,\s*/).forEach( (dep) => info.addDependency(dep) ); } info.rawModule = true; info.requiresTopLevelScope = getAttribute(rawModule, "requiresTopLevelScope") === "true"; - let ignoredGlobals = getAttribute(rawModule, "ignoredGlobals"); + const ignoredGlobals = getAttribute(rawModule, "ignoredGlobals"); if ( ignoredGlobals ) { info.ignoredGlobals = ignoredGlobals.trim().split(/\s*,\s*/); } @@ -40,7 +40,7 @@ function makeModuleInfo(rawModule) { } function getDependencyInfos( content ) { - let infos = {}; + const infos = {}; parser.parseString(content, (err, result) => { // console.log(JSON.stringify(result, null, '\t')); if ( result @@ -54,7 +54,7 @@ function getDependencyInfos( content ) { && Array.isArray(packaging["module-infos"]) ) { packaging["module-infos"].forEach( function(moduleInfos) { moduleInfos["raw-module"] && moduleInfos["raw-module"].forEach( (rawModule) => { - let info = makeModuleInfo(rawModule); + const info = makeModuleInfo(rawModule); if ( info ) { infos[info.name] = info; } diff --git a/lib/lbt/resources/ModuleInfo.js b/lib/lbt/resources/ModuleInfo.js index 2a9ea4925..ff4caa39a 100644 --- a/lib/lbt/resources/ModuleInfo.js +++ b/lib/lbt/resources/ModuleInfo.js @@ -149,7 +149,7 @@ class ModuleInfo { if ( other instanceof ModuleInfo ) { this.addSubModule( other.name ); // accumulate dependencies - for ( let dep in other._dependencies ) { + for ( const dep in other._dependencies ) { if (other._dependencies.hasOwnProperty(dep)) { this._addDependency(dep, other._dependencies[dep]); } diff --git a/lib/lbt/resources/ResourceFilterList.js b/lib/lbt/resources/ResourceFilterList.js index c5213e4fa..cef22f699 100644 --- a/lib/lbt/resources/ResourceFilterList.js +++ b/lib/lbt/resources/ResourceFilterList.js @@ -3,7 +3,7 @@ const log = require("@ui5/logger").getLogger("lbt:resources:ResourceFilterList"); function makeMatcher(globPattern) { - let result = { + const result = { pattern: globPattern, include: true }; @@ -20,7 +20,7 @@ function makeMatcher(globPattern) { globPattern = globPattern.replace(/\/$/, "/**/"); } - let regexp = globPattern.replace(/\*\*\/|\*|[[\]{}()+?.\\^$|]/g, function(match) { + const regexp = globPattern.replace(/\*\*\/|\*|[[\]{}()+?.\\^$|]/g, function(match) { switch (match) { case "**/": return "(?:[^/]+/)*"; case "*": return "[^/]*"; @@ -144,7 +144,7 @@ class ResourceFilterList { } ResourceFilterList.fromString = function(filterStr) { - let result = new ResourceFilterList(); + const result = new ResourceFilterList(); if ( filterStr != null ) { result.addFilters( filterStr.trim().split(/\s*,\s*/) ); } diff --git a/lib/lbt/resources/ResourcePool.js b/lib/lbt/resources/ResourcePool.js index 992d57ac8..7d3d7712c 100644 --- a/lib/lbt/resources/ResourcePool.js +++ b/lib/lbt/resources/ResourcePool.js @@ -64,11 +64,11 @@ async function determineDependencyInfo(resource, rawInfo, pool) { rawInfo.dependencies.forEach( (dep) => info.addDependency(dep) ); } else { // console.log("analyzing %s", resource.file); - let code = await resource.buffer(); + const code = await resource.buffer(); info.size = code.length; - let promises = []; + const promises = []; try { - let ast = esprima.parse(code); + const ast = esprima.parse(code); jsAnalyzer.analyze(ast, resource.name, info); new XMLCompositeAnalyzer(pool).analyze(ast, resource.name, info); } catch (error) { @@ -86,15 +86,15 @@ async function determineDependencyInfo(resource, rawInfo, pool) { } // console.log(info); } else if ( /\.view.xml$/.test(resource.name) ) { - let xmlView = await resource.buffer(); + const xmlView = await resource.buffer(); info.size = xmlView.length; new XMLTemplateAnalyzer(pool).analyzeView(xmlView, info); } else if ( /\.control.xml$/.test(resource.name) ) { - let xmlView = await resource.buffer(); + const xmlView = await resource.buffer(); info.size = xmlView.length; new XMLTemplateAnalyzer(pool).analyzeFragment(xmlView, info); } else if ( /\.fragment.xml$/.test(resource.name) ) { - let xmlView = await resource.buffer(); + const xmlView = await resource.buffer(); info.size = xmlView.length; new XMLTemplateAnalyzer(pool).analyzeFragment(xmlView, info); } @@ -118,7 +118,7 @@ class ResourcePool { prefix: prefix }); log.verbose(" scanning <%s> for resources (prefix='%s')", fileOrFolder, prefix); - let p = scanFileOrDir(fileOrFolder, prefix, this); + const p = scanFileOrDir(fileOrFolder, prefix, this); this.whenReady = this.whenReady.then( () => p ); } @@ -134,8 +134,8 @@ class ResourcePool { if ( /\.library$/.test(resource.name) ) { // read raw-module info from .library files return resource.buffer().then( (buffer) => { - let infos = LibraryFileAnalyzer.getDependencyInfos( buffer ); - for ( let name in infos ) { + const infos = LibraryFileAnalyzer.getDependencyInfos( buffer ); + for ( const name in infos ) { if (infos.hasOwnProperty(name)) { this._rawModuleInfos.set(name, infos[name]); } @@ -148,7 +148,7 @@ class ResourcePool { let info = this._dependencyInfos.get(name); if ( info == null ) { // console.log("analyzing ", name); - let resource = await this.findResource(name); + const resource = await this.findResource(name); info = await determineDependencyInfo( resource, this._rawModuleInfos.get(name), this ); // console.log("finished analyzing ", name); this._dependencyInfos.set(name, info); @@ -157,7 +157,7 @@ class ResourcePool { } async findResource(name) { - let resource = this._resourcesByName.get(name); + const resource = this._resourcesByName.get(name); if ( resource == null ) { throw new Error("resource not found in pool: '" + name + "'"); } diff --git a/lib/lbt/utils/ModuleName.js b/lib/lbt/utils/ModuleName.js index d9ea66931..2da798621 100644 --- a/lib/lbt/utils/ModuleName.js +++ b/lib/lbt/utils/ModuleName.js @@ -48,7 +48,7 @@ function toRequireJSName(path) { const KNOWN_TYPES = /\.(properties|css|(?:(?:view\.|fragment\.)?(?:html|json|xml|js))|(?:(?:controller\.)?js))$/; function getDebugName(name) { - let m = KNOWN_TYPES.exec(name); + const m = KNOWN_TYPES.exec(name); if ( m && ( m[0].endsWith(".css") || m[0].endsWith(".js") ) && !name.slice(0, m.index).endsWith("-dbg") ) { return name.slice(0, m.index) + "-dbg" + m[0]; } @@ -56,7 +56,7 @@ function getDebugName(name) { } function getNonDebugName(name) { - let m = KNOWN_TYPES.exec(name); + const m = KNOWN_TYPES.exec(name); if ( m && ( m[0].endsWith(".css") || m[0].endsWith(".js") ) && name.slice(0, m.index).endsWith("-dbg") ) { return name.slice(0, m.index - "-dbg".length) + m[0]; } diff --git a/lib/processors/bundlers/flexChangesBundler.js b/lib/processors/bundlers/flexChangesBundler.js index d4b7d24cb..42b6caa0d 100644 --- a/lib/processors/bundlers/flexChangesBundler.js +++ b/lib/processors/bundlers/flexChangesBundler.js @@ -43,9 +43,9 @@ module.exports = function({resources, options}) { return JSON.parse(buffer.toString()); }); })).then((changesContent) => { - let nNumberOfChanges = changesContent.length; + const nNumberOfChanges = changesContent.length; log.verbose("Changes collected. Number of changes: " + nNumberOfChanges); - let result = []; + const result = []; if (nNumberOfChanges > 0) { changesContent = sortAndStringify(changesContent); result.push(resourceFactory.createResource({ diff --git a/lib/processors/bundlers/manifestBundler.js b/lib/processors/bundlers/manifestBundler.js index 5788b9e7b..7757699f5 100644 --- a/lib/processors/bundlers/manifestBundler.js +++ b/lib/processors/bundlers/manifestBundler.js @@ -56,7 +56,7 @@ class I18nResourceList { module.exports = ({resources, options}) => { function getDescriptorI18nInfo(manifest) { const content = JSON.parse(manifest.content); - let i18nFullPath = content["sap.app"]["i18n"] || "i18n/i18n.properties"; + const i18nFullPath = content["sap.app"]["i18n"] || "i18n/i18n.properties"; return { path: path.join(path.dirname(manifest.path), path.dirname(i18nFullPath)), rootName: path.basename(i18nFullPath, options.propertiesExtension) @@ -106,7 +106,7 @@ module.exports = ({resources, options}) => { }); zip.finalize(); - let res = resourceFactory.createResource({ + const res = resourceFactory.createResource({ path: "/" + options.bundleName, stream: zip }); diff --git a/lib/processors/manifestCreator.js b/lib/processors/manifestCreator.js index bf743aae5..cd3e10d3b 100644 --- a/lib/processors/manifestCreator.js +++ b/lib/processors/manifestCreator.js @@ -45,7 +45,7 @@ function findChild(node, tagName, namespaceURI) { } function findChildren(node, tagName, namespaceURI) { - let children = node && node[tagName]; + const children = node && node[tagName]; if ( Array.isArray(children) ) { return children.filter((child) => (namespaceURI == null || (child.$ns && child.$ns.uri === namespaceURI))); } @@ -53,7 +53,7 @@ function findChildren(node, tagName, namespaceURI) { } function getChildTextContent(node, tagName, defaultValue) { - let child = findChild(node, tagName); + const child = findChild(node, tagName); return child ? (child._ || "") : defaultValue; } @@ -97,18 +97,18 @@ class Library { } getDependencies() { - let container = findChild(this.xml, "dependencies"); - let deps = findChildren(container, "dependency") || []; + const container = findChild(this.xml, "dependencies"); + const deps = findChildren(container, "dependency") || []; return deps.map((dep) => new Dependency(dep)); } getAppData(tagName, namespace) { - let appData = findChild(this.xml, "appData", XMLNS_UILIB); + const appData = findChild(this.xml, "appData", XMLNS_UILIB); return findChild(appData, tagName, namespace); } static async from(resource) { - let content = await resource.getString(); + const content = await resource.getString(); return new Promise( (resolve, reject) => { parser.parseString(content, (err, xml) => { if ( err ) { @@ -139,13 +139,13 @@ class LibraryBundle { */ async function createManifest(libraryResource, libBundle, descriptorVersion, _include3rdParty) { // create a Library wrapper around the .library XML - let library = await Library.from(libraryResource); + const library = await Library.from(libraryResource); // collect information from library.js file - let libraryJSInfo = await analyzeLibraryJS(libBundle.findResource("library.js")); + const libraryJSInfo = await analyzeLibraryJS(libBundle.findResource("library.js")); - let manifestAppData = library.getAppData("manifest", XMLNS_MANIFEST); - let sapFioriAppData = findChild(manifestAppData, "sap.fiori"); + const manifestAppData = library.getAppData("manifest", XMLNS_MANIFEST); + const sapFioriAppData = findChild(manifestAppData, "sap.fiori"); function sectionVersion(candidateVersion) { // _version property for nested sections became optional with AppDescriptor V5 @@ -157,11 +157,11 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in function createSapApp() { function findComponentPaths() { - let result = []; - let prefix = libraryResource.getPath().slice(0, - ".library".length); - let components = libBundle.getResources(/(?:[^/]+\/)*Component\.js$/); + const result = []; + const prefix = libraryResource.getPath().slice(0, - ".library".length); + const components = libBundle.getResources(/(?:[^/]+\/)*Component\.js$/); components.forEach((comp) => { - let relativePath = comp.getPath().slice(prefix.length); + const relativePath = comp.getPath().slice(prefix.length); if ( relativePath.lastIndexOf("/") >= 0 ) { result.push( relativePath.slice(0, relativePath.lastIndexOf("/")) ); } else if ( prefix !== "/resources/sap/ui/core/" ) { @@ -178,7 +178,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function getProjectVersion() { - let project = libraryResource._project; + const project = libraryResource._project; if ( project ) { return project.version; } @@ -193,15 +193,15 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in // remove all tags desc = desc.replace(/\\s+/g, " ").replace(/<\/?[a-zA-Z][a-zA-Z0-9_$.]*(\s[^>]*)>/g, ""); // extract summary (first sentence) - let m = /^([\w\W]+?[.;!?])[^a-zA-Z0-9_$]/.exec(desc); + const m = /^([\w\W]+?[.;!?])[^a-zA-Z0-9_$]/.exec(desc); return m ? m[1] : desc; } return library.getName(); } function getDefaultACH() { - let ownership = library.getAppData("ownership", XMLNS_OWNERSHIP); - for (let comp of findChildren(ownership, "component")) { + const ownership = library.getAppData("ownership", XMLNS_OWNERSHIP); + for (const comp of findChildren(ownership, "component")) { if ( comp._ ) { return comp._; } @@ -210,7 +210,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in function offline() { let result = sapFioriAppData == null ? true : false; - let offlineElement = findChild(manifestAppData, "offline"); + const offlineElement = findChild(manifestAppData, "offline"); if ( offlineElement ) { result = offlineElement._ === "true"; } @@ -218,7 +218,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function sourceTemplate() { - let sourceTemplateElement = findChild(manifestAppData, "sourceTemplate"); + const sourceTemplateElement = findChild(manifestAppData, "sourceTemplate"); if ( sourceTemplateElement ) { return { "id": getChildTextContent(sourceTemplateElement, "id"), @@ -228,11 +228,11 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function openSourceComponents() { - let embeddedOSComponents = new Set(); - let osComponents = []; - for (let osCompElem of findChildren(manifestAppData, "openSourceComponent")) { - let name = getAttribute(osCompElem, "name"); - let packagedWithMySelf = getBooleanAttribute(osCompElem, "packagedWithMySelf"); + const embeddedOSComponents = new Set(); + const osComponents = []; + for (const osCompElem of findChildren(manifestAppData, "openSourceComponent")) { + const name = getAttribute(osCompElem, "name"); + const packagedWithMySelf = getBooleanAttribute(osCompElem, "packagedWithMySelf"); osComponents.push({ name: name, packagedWithMySelf, @@ -246,9 +246,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in if ( _include3rdParty ) { // also merge all thirdparty libs, but only with the name - version info is not available // only merge in if no lib with the same name has been declared already - let thirdpartyAppData = library.getAppData("thirdparty", XMLNS_THIRDPARTY); - for (let thirdPartyElem of findChildren(thirdpartyAppData, "lib")) { - let osCompName = getAttribute(thirdPartyElem, "name"); + const thirdpartyAppData = library.getAppData("thirdparty", XMLNS_THIRDPARTY); + for (const thirdPartyElem of findChildren(thirdpartyAppData, "lib")) { + const osCompName = getAttribute(thirdPartyElem, "name"); if ( !embeddedOSComponents.has(osCompName) ) { embeddedOSComponents.add(osCompName); osComponents.push({ @@ -263,7 +263,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in return osComponents.length > 0 ? osComponents : undefined; } - let sapApp = { + const sapApp = { _version: sectionVersion(APP_DESCRIPTOR_V3_SECTION_SAP_APP), id: library.getName(), type: "library", @@ -291,7 +291,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in function createSapUi() { function deviceTypes() { - let deviceTypesElement = findChild(manifestAppData, "deviceTypes"); + const deviceTypesElement = findChild(manifestAppData, "deviceTypes"); if ( deviceTypesElement ) { return { desktop: getBooleanAttribute(deviceTypesElement, "desktop"), @@ -302,18 +302,18 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function collectThemes() { - let themes = {}; + const themes = {}; // find theme resources and determine theme names from their paths libBundle.getResources(/(?:[^/]+\/)*themes\//).forEach((res) => { - let match = /\/themes\/([^/]+)\//.exec(res.getPath()); + const match = /\/themes\/([^/]+)\//.exec(res.getPath()); if ( match ) { themes[match[1]] = true; } }); // merge with supporteTheme info from .library file - let elems = findChildren(manifestAppData, "supportedTheme"); + const elems = findChildren(manifestAppData, "supportedTheme"); if ( elems ) { elems.forEach((elem) => { if ( elem._ ) { @@ -324,7 +324,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in return Object.keys(themes).sort(); } - let sapUi = { + const sapUi = { _version: sectionVersion(APP_DESCRIPTOR_V3_OTHER_SECTIONS), technology: "UI5", deviceTypes: deviceTypes(), @@ -343,7 +343,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in return ui5Version; } - let dummy = new Dependency({ + const dummy = new Dependency({ libraryName: [{ _: "sap.ui.core" }] @@ -352,13 +352,13 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function dependencies() { - let dependencies = { + const dependencies = { minUI5Version: getUI5Version(), libs: { } }; if ( library.getDependencies() != null ) { - for (let dep of library.getDependencies()) { + for (const dep of library.getDependencies()) { dependencies.libs[dep.getLibraryName()] = { minVersion: getVersion(dep), lazy: dep.isLazy() || undefined // suppress default (false) @@ -370,9 +370,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function contentDensities() { - let contentDensitiesElement = findChild(manifestAppData, "contentDensities"); + const contentDensitiesElement = findChild(manifestAppData, "contentDensities"); if ( contentDensitiesElement != null ) { - let contentDensities = { + const contentDensities = { cozy: getBooleanAttribute(contentDensitiesElement, "cozy"), compact: getBooleanAttribute(contentDensitiesElement, "compact") }; @@ -389,16 +389,16 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in log.info(" target descriptor version %s: include sap.ui5/library information", descriptorVersion); - let sapUi5AppData = findChild(manifestAppData, "sap.ui5"); - let libraryAppData = findChild(sapUi5AppData, "library"); + const sapUi5AppData = findChild(manifestAppData, "sap.ui5"); + const libraryAppData = findChild(sapUi5AppData, "library"); // i18n: // - from .library/appData/manifest/sap.ui5/library/i18n // - from library resources (if "messagebundle.properties" exists) function i18n() { - let i18nElement = findChild(libraryAppData, "i18n"); + const i18nElement = findChild(libraryAppData, "i18n"); if ( i18nElement ) { - let i18n = i18nElement._; + const i18n = i18nElement._; if ( i18n === "false" ) { return false; } else if ( i18n === "true" ) { @@ -421,9 +421,9 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in // - from .library/appData/manifest/sap.ui5/library/css // - from library.js/initLibrary/noLibraryCSS function css() { - let cssElement = findChild(libraryAppData, "css"); + const cssElement = findChild(libraryAppData, "css"); if ( cssElement != null ) { - let css = cssElement._; + const css = cssElement._; if ( css === "false" ) { log.verbose(" sap.ui5/library/css property taken from .library appData: '%s'", false); return false; @@ -437,7 +437,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in // content // - from library.js/initLibrary/ (types|elements|controls|interfaces) function content() { - let libraryJS = libraryJSInfo; + const libraryJS = libraryJSInfo; if ( libraryJS.controls || libraryJS.elements || libraryJS.interfaces || libraryJS.types ) { return { controls: libraryJS.controls, @@ -455,7 +455,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in }; } - let sapUI5 = { + const sapUI5 = { _version: sectionVersion(APP_DESCRIPTOR_V3_OTHER_SECTIONS), dependencies: dependencies(), contentDensities: contentDensities(), @@ -468,8 +468,8 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in function createSapFiori() { // collect registrationIds if present function registrationIds() { - let ids = []; - for (let regid of findChildren(sapFioriAppData, "registrationId")) { + const ids = []; + for (const regid of findChildren(sapFioriAppData, "registrationId")) { ids.push(regid._); } return ids.length > 0 ? ids : undefined; @@ -485,7 +485,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function createSapPlatformABAP() { - let sapPlatformABAPElement = findChild(manifestAppData, "sap.platform.abap"); + const sapPlatformABAPElement = findChild(manifestAppData, "sap.platform.abap"); if ( sapPlatformABAPElement ) { return { _version: sectionVersion(APP_DESCRIPTOR_V3_OTHER_SECTIONS), @@ -495,7 +495,7 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in } function createSapPlatformHCP() { - let sapPlatformHCPElement = findChild(manifestAppData, "sap.platform.hcp"); + const sapPlatformHCPElement = findChild(manifestAppData, "sap.platform.hcp"); if ( sapPlatformHCPElement ) { return { _version: sectionVersion(APP_DESCRIPTOR_V3_OTHER_SECTIONS), @@ -508,12 +508,12 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in if ( version == null ) { return version; } - let v = new Version(version); + const v = new Version(version); return v.major + "." + v.minor; } function getVersion(dependency) { - let version = dependency.getVersion(); + const version = dependency.getVersion(); if ( version != null ) { return version; } @@ -522,10 +522,10 @@ async function createManifest(libraryResource, libBundle, descriptorVersion, _in return entity.metadata && entity.metadata.name === dependency.getLibraryName(); } - let project = libraryResource._project; + const project = libraryResource._project; if ( project ) { if ( Array.isArray(project.dependencies) ) { - let lib = project.dependencies.find(hasName); + const lib = project.dependencies.find(hasName); if ( lib ) { return lib.version; } @@ -558,11 +558,11 @@ module.exports = function({libraryResource, resources, options}) { prettyPrint: true }, options); - let resourcePathPrefix = libraryResource.getPath().slice(0, -".library".length); - let libBundle = new LibraryBundle(resourcePathPrefix, resources); + const resourcePathPrefix = libraryResource.getPath().slice(0, -".library".length); + const libBundle = new LibraryBundle(resourcePathPrefix, resources); // check whether a manifest exists already - let manifestResource = libBundle.findResource("manifest.json"); + const manifestResource = libBundle.findResource("manifest.json"); if ( manifestResource != null ) { log.info("Library manifest already exists at '%s', skipping generation", manifestResource.getPath()); return Promise.resolve(null); // a fulfillment of null indicates that no manifest has been created diff --git a/lib/processors/themeBuilder.js b/lib/processors/themeBuilder.js index 653ac7544..163d9676b 100644 --- a/lib/processors/themeBuilder.js +++ b/lib/processors/themeBuilder.js @@ -27,7 +27,7 @@ class ThemeBuilder { * @returns {Promise} Resolving with array of created files */ build(resources) { - let files = []; + const files = []; const compile = (resource) => { log.verbose("Compiling %s", resource.getPath()); @@ -46,17 +46,17 @@ class ThemeBuilder { }).then((result) => { const themeDir = path.dirname(resource.getPath()); - let libCss = new Resource({ + const libCss = new Resource({ path: themeDir + "/library.css", string: result.css }); - let libCssRtl = new Resource({ + const libCssRtl = new Resource({ path: themeDir + "/library-RTL.css", string: result.cssRtl }); - let libParams = new Resource({ + const libParams = new Resource({ path: themeDir + "/library-parameters.json", string: JSON.stringify(result.variables, null, "\t") }); diff --git a/lib/types/AbstractBuilder.js b/lib/types/AbstractBuilder.js index b07e261a5..c37cd1976 100644 --- a/lib/types/AbstractBuilder.js +++ b/lib/types/AbstractBuilder.js @@ -45,13 +45,13 @@ class AbstractBuilder { let taskChain = Promise.resolve(); for (let i = 0; i < this.availableTasks.length; i++) { - let taskName = this.availableTasks[i]; + const taskName = this.availableTasks[i]; if (!tasksToRun.includes(taskName)) { continue; } - let taskFunction = this.tasks[taskName]; + const taskFunction = this.tasks[taskName]; if (typeof taskFunction === "function") { taskChain = taskChain.then(this.wrapTask(taskName, taskFunction)); diff --git a/lib/types/library/LibraryFormatter.js b/lib/types/library/LibraryFormatter.js index e607de1f9..afc6da849 100644 --- a/lib/types/library/LibraryFormatter.js +++ b/lib/types/library/LibraryFormatter.js @@ -42,7 +42,7 @@ class LibraryFormatter extends AbstractFormatter { throw new Error(`Found multiple (${dotLibraryResources.length}) .library files ` + `for project ${project.id}`); } - let fsPath = path.join(basePath, dotLibraryResources[0]); + const fsPath = path.join(basePath, dotLibraryResources[0]); return readFile(fsPath) .then((content) => xmlParse(content)) .then((result) => { diff --git a/lib/types/module/ModuleFormatter.js b/lib/types/module/ModuleFormatter.js index 0507ef3d3..a74acfae2 100644 --- a/lib/types/module/ModuleFormatter.js +++ b/lib/types/module/ModuleFormatter.js @@ -35,7 +35,7 @@ class ModuleFormatter extends AbstractFormatter { } const paths = project.resources.configuration.paths; const dirChecks =[]; - for (let virPath in paths) { + for (const virPath in paths) { if (paths.hasOwnProperty(virPath)) { const absolutePath = path.join(project.path, paths[virPath]); dirChecks.push(this.dirExists(absolutePath).then((bExists) => { diff --git a/lib/types/typeRepository.js b/lib/types/typeRepository.js index b4186ba59..41258806b 100644 --- a/lib/types/typeRepository.js +++ b/lib/types/typeRepository.js @@ -2,14 +2,14 @@ const applicationType = require("./application/applicationType"); const libraryType = require("./library/libraryType"); const moduleType = require("./module/moduleType"); -let types = { +const types = { application: applicationType, library: libraryType, module: moduleType }; function getType(typeName) { - let type = types[typeName]; + const type = types[typeName]; if (!type) { throw new Error("Unkown type '" + typeName + "'"); diff --git a/test/lib/builder/builder.js b/test/lib/builder/builder.js index 9b10e8915..9cc5a4c09 100644 --- a/test/lib/builder/builder.js +++ b/test/lib/builder/builder.js @@ -30,7 +30,7 @@ const findFiles = (folder) => { }; function cloneProjectTree(tree) { - let clone = JSON.parse(JSON.stringify(tree)); + const clone = JSON.parse(JSON.stringify(tree)); function increaseDepth(node) { node._level++; if ( Array.isArray(node.dependencies) ) { From 3ffa4a71484baac84528efd18edf66fc5bbfab97 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 15 Nov 2018 14:00:41 +0100 Subject: [PATCH 4/5] [INTERNAL] GitHub ISSUE_TEMPLATE: Request UI5 module version info --- .github/ISSUE_TEMPLATE.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 504d1f58b..89eb96924 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -10,13 +10,14 @@ 3. {...} ## Context +- UI5 Module Version *(output of `ui5 --version` when using the CLI)*: `{...}` +- Node.js Version: `{...}` +- npm Version: `{...}` - OS/Platform: {...} -- Node.js Version: {...} -- npm Version: {...} - Browser *(if relevant)*: {...} - Other information: {...} -## Affected components +## Affected components *(if known)* - [ ] [ui5-builder](https://github.com/SAP/ui5-builder) - [ ] [ui5-server](https://github.com/SAP/ui5-server) - [ ] [ui5-cli](https://github.com/SAP/ui5-cli) @@ -24,7 +25,7 @@ - [ ] [ui5-project](https://github.com/SAP/ui5-project) - [ ] [ui5-logger](https://github.com/SAP/ui5-logger) -## Stack trace/log output +## Log Output / Stack Trace ``` -{logs} +{...} ``` From 5389e1853527d005c78fe344fb5ff8fd7f49528d Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Thu, 15 Nov 2018 14:32:09 +0100 Subject: [PATCH 5/5] [INTERNAL] GitHub: Add PULL_REQUEST_TEMPLATE --- .github/PULL_REQUEST_TEMPLATE.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 000000000..a102a83fc --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,9 @@ +**Thank you for your contribution!** 🙌 + +To get it merged faster, kindly review the checklist below: + +## Pull Request Checklist +- [ ] Reviewed the [Contributing Guidelines](https://github.com/SAP/ui5-tooling/blob/master/CONTRIBUTING.md#-contributing-code) + + Especially the [How to Contribute](https://github.com/SAP/ui5-tooling/blob/master/CONTRIBUTING.md#how-to-contribute) section +- [ ] [No merge commits](https://github.com/SAP/ui5-tooling/blob/master/docs/Guidelines.md#no-merge-commits) +- [ ] [Correct commit message style](https://github.com/SAP/ui5-tooling/blob/master/docs/Guidelines.md#commit-message-style)