From 19800a16689210c13495bc1bd0949896500cfc52 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 20 Jun 2018 17:36:37 +0200 Subject: [PATCH] [FIX] Builders: Do not bundle debug files Temporary fix preventing '*-dbg' files from being included in preload bundles. Resolves #12 for the time being --- lib/tasks/createDebugFiles.js | 26 ++++---- lib/types/application/ApplicationBuilder.js | 22 +++---- lib/types/library/LibraryBuilder.js | 22 +++---- .../application.g/dest/Component-preload.js | 2 - .../dest/subcomponentA/Component-preload.js | 2 - .../dest/subcomponentB/Component-preload.js | 2 - test/lib/tasks/createDebugFiles.js | 65 +++++++++---------- 7 files changed, 65 insertions(+), 76 deletions(-) diff --git a/lib/tasks/createDebugFiles.js b/lib/tasks/createDebugFiles.js index 4ea35e99c..35b3b07e9 100644 --- a/lib/tasks/createDebugFiles.js +++ b/lib/tasks/createDebugFiles.js @@ -10,16 +10,18 @@ const dbg = require("../processors/debugFileCreator"); * @param {string} [parameters.options.pattern] Pattern to locate the files to be processed * @returns {Promise} Promise resolving with undefined once data has been written */ -module.exports = function({workspace, options}) { - return workspace.byGlob(options.pattern) - .then((allResources) => { - return dbg({ - resources: allResources - }); - }) - .then((processedResources) => { - return Promise.all(processedResources.map((resource) => { - return workspace.write(resource); - })); - }); +module.exports = async function({workspace, options}) { + let allResources; + if (workspace.byGlobSource) { // API only available on duplex collections + allResources = await workspace.byGlobSource(options.pattern); + } else { + allResources = await workspace.byGlob(options.pattern); + } + return dbg({ + resources: allResources + }).then((processedResources) => { + return Promise.all(processedResources.map((resource) => { + return workspace.write(resource); + })); + }); }; diff --git a/lib/types/application/ApplicationBuilder.js b/lib/types/application/ApplicationBuilder.js index 266bd0696..8bdf071b4 100644 --- a/lib/types/application/ApplicationBuilder.js +++ b/lib/types/application/ApplicationBuilder.js @@ -22,12 +22,12 @@ class ApplicationBuilder extends AbstractBuilder { this.availableTasks = [ "replaceCopyright", "replaceVersion", - "createDebugFiles", "generateFlexChangesBundle", "generateManifestBundle", "generateComponentPreload", "generateStandaloneAppBundle", "generateBundle", + "createDebugFiles", "uglify", "generateVersionInfo" ]; @@ -52,16 +52,6 @@ class ApplicationBuilder extends AbstractBuilder { }); }); - this.addTask("createDebugFiles", () => { - const createDebugFiles = tasks.createDebugFiles; - return createDebugFiles({ - workspace: resourceCollections.workspace, - options: { - pattern: "/**/*.js" - } - }); - }); - this.addTask("generateFlexChangesBundle", () => { const generateFlexChangesBundle = tasks.generateFlexChangesBundle; return generateFlexChangesBundle({ @@ -137,6 +127,16 @@ class ApplicationBuilder extends AbstractBuilder { }); } + this.addTask("createDebugFiles", () => { + const createDebugFiles = tasks.createDebugFiles; + return createDebugFiles({ + workspace: resourceCollections.workspace, + options: { + pattern: "/**/*.js" + } + }); + }); + this.addTask("uglify", () => { const uglify = tasks.uglify; return uglify({ diff --git a/lib/types/library/LibraryBuilder.js b/lib/types/library/LibraryBuilder.js index aea97a457..6cb0c2d20 100644 --- a/lib/types/library/LibraryBuilder.js +++ b/lib/types/library/LibraryBuilder.js @@ -22,11 +22,11 @@ class LibraryBuilder extends AbstractBuilder { this.availableTasks = [ "replaceCopyright", "replaceVersion", - "createDebugFiles", "generateComponentPreload", "generateBundle", "generateLibraryPreload", "buildThemes", + "createDebugFiles", "uglify" ]; @@ -52,16 +52,6 @@ class LibraryBuilder extends AbstractBuilder { }); }); - this.addTask("createDebugFiles", () => { - const createDebugFiles = tasks.createDebugFiles; - return createDebugFiles({ - workspace: resourceCollections.workspace, - options: { - pattern: "/resources/**/*.js" - } - }); - }); - const componentPreload = project.builder && project.builder.componentPreload; if (componentPreload) { const generateComponentPreload = tasks.generateComponentPreload; @@ -120,6 +110,16 @@ class LibraryBuilder extends AbstractBuilder { }); }); + this.addTask("createDebugFiles", () => { + const createDebugFiles = tasks.createDebugFiles; + return createDebugFiles({ + workspace: resourceCollections.workspace, + options: { + pattern: "/resources/**/*.js" + } + }); + }); + this.addTask("uglify", () => { const uglify = tasks.uglify; return uglify({ diff --git a/test/expected/build/application.g/dest/Component-preload.js b/test/expected/build/application.g/dest/Component-preload.js index 63306be75..a976c01f8 100644 --- a/test/expected/build/application.g/dest/Component-preload.js +++ b/test/expected/build/application.g/dest/Component-preload.js @@ -1,8 +1,6 @@ jQuery.sap.registerPreloadedModules({ "version":"2.0", "modules":{ - "application/g/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); -}, "application/g/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); }, "application/g/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' diff --git a/test/expected/build/application.g/dest/subcomponentA/Component-preload.js b/test/expected/build/application.g/dest/subcomponentA/Component-preload.js index 9571723f8..c30a66412 100644 --- a/test/expected/build/application.g/dest/subcomponentA/Component-preload.js +++ b/test/expected/build/application.g/dest/subcomponentA/Component-preload.js @@ -1,8 +1,6 @@ jQuery.sap.registerPreloadedModules({ "version":"2.0", "modules":{ - "application/g/subcomponentA/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); -}, "application/g/subcomponentA/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); }, "application/g/subcomponentA/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentA","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' diff --git a/test/expected/build/application.g/dest/subcomponentB/Component-preload.js b/test/expected/build/application.g/dest/subcomponentB/Component-preload.js index c00b76164..89aab0dd2 100644 --- a/test/expected/build/application.g/dest/subcomponentB/Component-preload.js +++ b/test/expected/build/application.g/dest/subcomponentB/Component-preload.js @@ -1,8 +1,6 @@ jQuery.sap.registerPreloadedModules({ "version":"2.0", "modules":{ - "application/g/subcomponentB/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); -}, "application/g/subcomponentB/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); }, "application/g/subcomponentB/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentB","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' diff --git a/test/lib/tasks/createDebugFiles.js b/test/lib/tasks/createDebugFiles.js index fa6548d59..186f8441e 100644 --- a/test/lib/tasks/createDebugFiles.js +++ b/test/lib/tasks/createDebugFiles.js @@ -6,7 +6,7 @@ const ui5Fs = require("@ui5/fs"); const resourceFactory = ui5Fs.resourceFactory; test("test.js: dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -16,15 +16,14 @@ test("test.js: dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg.js").then((resource) => { + return sourceAdapter.byPath("/test-dbg.js").then((resource) => { if (!resource) { t.fail("Could not find /test-dbg.js in target"); } else { @@ -38,7 +37,7 @@ test("test.js: dbg file creation", (t) => { }); test("test.view.js: dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -48,15 +47,14 @@ test("test.view.js: dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg.view.js").then((resource) => { + return sourceAdapter.byPath("/test-dbg.view.js").then((resource) => { if (!resource) { t.fail("Could not find /test-dbg.view.js in target"); } else { @@ -70,7 +68,7 @@ test("test.view.js: dbg file creation", (t) => { }); test("test.controller.js: dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -80,15 +78,14 @@ test("test.controller.js: dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg.controller.js").then((resource) => { + return sourceAdapter.byPath("/test-dbg.controller.js").then((resource) => { if (!resource) { t.fail("Could not find /test-dbg.controller.js in target"); } else { @@ -102,7 +99,7 @@ test("test.controller.js: dbg file creation", (t) => { }); test("test.fragment.js: dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -112,15 +109,14 @@ test("test.fragment.js: dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg.fragment.js").then((resource) => { + return sourceAdapter.byPath("/test-dbg.fragment.js").then((resource) => { if (!resource) { t.fail("Could not find /test-dbg.fragment.js in target locator"); } else { @@ -134,7 +130,7 @@ test("test.fragment.js: dbg file creation", (t) => { }); test("test-dbg.js: dbg-dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -144,15 +140,14 @@ test("test-dbg.js: dbg-dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg-dbg.js").then((resource) => { + return sourceAdapter.byPath("/test-dbg-dbg.js").then((resource) => { if (!resource) { t.fail("Could not find /test-dbg-dbg.js in target locator"); } else { @@ -166,7 +161,7 @@ test("test-dbg.js: dbg-dbg file creation", (t) => { }); test("test.xml: *no* dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = ""; @@ -176,15 +171,14 @@ test("test.xml: *no* dbg file creation", (t) => { string: content }); - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); - return workspace.write(resource).then(() => { + return sourceAdapter.write(resource).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { - return workspace.byPath("/test-dbg.xml").then((resource) => { + return sourceAdapter.byPath("/test-dbg.xml").then((resource) => { if (!resource) { t.pass("Could not find /test-dbg.xml in target locator as it is not a JavaScript file"); } else { @@ -196,7 +190,7 @@ test("test.xml: *no* dbg file creation", (t) => { }); test("test1.js, test2.js: dbg file creation", (t) => { - const sourceReader = resourceFactory.createAdapter({ + const sourceAdapter = resourceFactory.createAdapter({ virBasePath: "/" }); const content = "console.log('Hello World');"; @@ -212,19 +206,18 @@ test("test1.js, test2.js: dbg file creation", (t) => { }) ]; - const workspace = resourceFactory.createWorkspace({reader: sourceReader}); return Promise.all(resources.map((resource) => { - return workspace.write(resource); + return sourceAdapter.write(resource); })).then(() => { return tasks.createDebugFiles({ - workspace: workspace, + workspace: sourceAdapter, options: { pattern: "/**/*.js" } }).then(() => { return Promise.all([ - workspace.byPath("/test1-dbg.js"), - workspace.byPath("/test2-dbg.js") + sourceAdapter.byPath("/test1-dbg.js"), + sourceAdapter.byPath("/test2-dbg.js") ]).then((resources) => { if (!resources || !resources[0] || !resources[1]) { t.fail("Could not find /test1-dbg.js and/or /test2-dbg.js in target locator");