From 6f9995f5b47a6094fa93b5d433be849b1d3cdc7e Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Fri, 14 Jul 2023 09:39:52 +0200 Subject: [PATCH] [FIX] Bundling: Detect manifest.json dependency of libraries This solves the problem of missing manifest.json files of libraries in bundles, such as sap-ui-custom.js (self-contained build). It also eliminates the need to explicitly mention manifest.json files of libraries to be included in custom bundles. --- lib/lbt/resources/ResourcePool.js | 10 ++++ lib/tasks/bundlers/generateLibraryPreload.js | 8 +-- .../resources/library/d/library-dbg.js | 23 +++++++++ .../dest-deps/resources/library/d/library.js | 5 ++ .../resources/library/d/library.js.map | 1 + .../dest-deps/resources/library/d/some-dbg.js | 5 +- .../dest-deps/resources/library/d/some.js | 2 +- .../dest-deps/resources/library/d/some.js.map | 2 +- .../resources/library/d/library-dbg.js | 23 +++++++++ .../resources/library/d/library.js | 5 ++ .../resources/library/d/library.js.map | 1 + .../resources/library/d/some-dbg.js | 5 +- .../dest-depself/resources/library/d/some.js | 2 +- .../resources/library/d/some.js.map | 2 +- .../dest-depself/resources/sap-ui-custom.js | 8 ++- .../resources/sap-ui-custom.js.map | 2 +- .../dest-self/resources/sap-ui-custom.js | 9 +++- .../dest-self/resources/sap-ui-custom.js.map | 2 +- .../dest/resources/library/d/library-dbg.js | 23 +++++++++ .../dest/resources/library/d/library.js | 5 ++ .../dest/resources/library/d/library.js.map | 1 + .../dest/resources/library/d/manifest.json | 9 +++- .../dest/resources/library/d/some-dbg.js | 5 +- .../dest/resources/library/d/some.js | 2 +- .../dest/resources/library/d/some.js.map | 2 +- .../resources/library/d/library-preload.js | 34 ++++++++++--- .../library/d/library-preload.js.map | 2 +- .../preload/resources/library/d/library.js | 23 +++++++++ .../preload/resources/library/d/some.js | 5 +- .../resources/library/h/resources.json | 18 +++++-- .../library.d/main/src/library/d/library.js | 23 +++++++++ .../library.d/main/src/library/d/some.js | 5 +- test/lib/lbt/resources/ResourcePool.js | 50 +++++++++++++++++++ .../generateLibraryPreload.integration.js | 2 +- 34 files changed, 289 insertions(+), 35 deletions(-) create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/library-dbg.js create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/library.js create mode 100644 test/expected/build/application.a/dest-deps/resources/library/d/library.js.map create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/library-dbg.js create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/library.js create mode 100644 test/expected/build/application.a/dest-depself/resources/library/d/library.js.map create mode 100644 test/expected/build/library.d/dest/resources/library/d/library-dbg.js create mode 100644 test/expected/build/library.d/dest/resources/library/d/library.js create mode 100644 test/expected/build/library.d/dest/resources/library/d/library.js.map create mode 100644 test/expected/build/library.d/preload/resources/library/d/library.js create mode 100644 test/fixtures/library.d/main/src/library/d/library.js diff --git a/lib/lbt/resources/ResourcePool.js b/lib/lbt/resources/ResourcePool.js index 8bd68288f..ae9774642 100644 --- a/lib/lbt/resources/ResourcePool.js +++ b/lib/lbt/resources/ResourcePool.js @@ -95,6 +95,16 @@ async function determineDependencyInfo(resource, rawInfo, pool) { new ComponentAnalyzer(pool).analyze(resource, info), new SmartTemplateAnalyzer(pool).analyze(resource, info) ); + } else if ( /(?:^|\/)library\.js/.test(resource.name) ) { + promises.push( + (async () => { + const manifestName = resource.name.replace(/library\.js$/, "manifest.json"); + const manifestResource = await pool.findResource(manifestName).catch(() => null); + if (manifestResource) { + info.addDependency(manifestName); + } + })() + ); } await Promise.all(promises); diff --git a/lib/tasks/bundlers/generateLibraryPreload.js b/lib/tasks/bundlers/generateLibraryPreload.js index 6275c5e47..fd6b6b685 100644 --- a/lib/tasks/bundlers/generateLibraryPreload.js +++ b/lib/tasks/bundlers/generateLibraryPreload.js @@ -32,7 +32,11 @@ function getDefaultLibraryPreloadFilters(namespace, excludes) { } function getBundleDefinition(namespace, excludes) { - // TODO: move to config of actual core project + // Note: This configuration is only used when no bundle definition in ui5.yaml exists (see "skipBundles" parameter) + + // TODO: Remove this hardcoded bundle definition. + // sap.ui.core ui5.yaml contains a configuration since UI5 1.103.0 (specVersion 2.4) + // so this is still required to build UI5 versions <= 1.102.0. if (namespace === "sap/ui/core") { return { name: `${namespace}/library-preload.js`, @@ -51,8 +55,6 @@ function getBundleDefinition(namespace, excludes) { filters: [ // Note: Don't pass configured preload excludes for sap.ui.core // as they are already hardcoded below. - // In future the sap/ui/core/library-preload should be configured - // as a custom bundle in the ui5.yaml. ...getDefaultLibraryPreloadFilters(namespace), `!${namespace}/cldr/`, diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/library-dbg.js b/test/expected/build/application.a/dest-deps/resources/library/d/library-dbg.js new file mode 100644 index 000000000..c024ed2d0 --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/library-dbg.js @@ -0,0 +1,23 @@ +/* + * Some fancy copyright + */ + +sap.ui.define([ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "1.0.0", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/library.js b/test/expected/build/application.a/dest-deps/resources/library/d/library.js new file mode 100644 index 000000000..f9910ae65 --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/library.js @@ -0,0 +1,5 @@ +/* + * Some fancy copyright + */ +sap.ui.define(["sap/ui/core/Lib","sap/ui/core/library"],function(e){"use strict";return e.init({name:"library.d",version:"1.0.0",dependencies:["sap.ui.core"],types:[],interfaces:[],controls:[],elements:[],noLibraryCSS:true})}); +//# sourceMappingURL=library.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/library.js.map b/test/expected/build/application.a/dest-deps/resources/library/d/library.js.map new file mode 100644 index 000000000..41a43eb38 --- /dev/null +++ b/test/expected/build/application.a/dest-deps/resources/library/d/library.js.map @@ -0,0 +1 @@ +{"version":3,"file":"library.js","names":["sap","ui","define","Library","init","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS"],"sources":["library-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CACb,kBACA,uBACE,SAAUC,GACZ,aAEA,OAAOA,EAAQC,KAAK,CACnBC,KAAM,YACNC,QAAS,QACTC,aAAc,CACb,eAEDC,MAAO,GACPC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,MAEhB"} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/some-dbg.js b/test/expected/build/application.a/dest-deps/resources/library/d/some-dbg.js index 1e8c6a2f9..3699e1987 100644 --- a/test/expected/build/application.a/dest-deps/resources/library/d/some-dbg.js +++ b/test/expected/build/application.a/dest-deps/resources/library/d/some-dbg.js @@ -1,7 +1,8 @@ /*! * Some fancy copyright */ -(function() { + +sap.ui.define(["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); +}); diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/some.js b/test/expected/build/application.a/dest-deps/resources/library/d/some.js index 75aba1e23..8d85629bb 100644 --- a/test/expected/build/application.a/dest-deps/resources/library/d/some.js +++ b/test/expected/build/application.a/dest-deps/resources/library/d/some.js @@ -1,5 +1,5 @@ /*! * Some fancy copyright */ -(function(){var o="World";console.log("Hello "+o)})(); +sap.ui.define(["./library"],l=>{var o="World";console.log("Hello "+o)}); //# sourceMappingURL=some.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-deps/resources/library/d/some.js.map b/test/expected/build/application.a/dest-deps/resources/library/d/some.js.map index 8f900826d..760eb1a2a 100644 --- a/test/expected/build/application.a/dest-deps/resources/library/d/some.js.map +++ b/test/expected/build/application.a/dest-deps/resources/library/d/some.js.map @@ -1 +1 @@ -{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD"} \ No newline at end of file +{"version":3,"file":"some.js","names":["sap","ui","define","_library","someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CAAC,aAAeC,IAC7B,IAAIC,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EAAwB"} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/library-dbg.js b/test/expected/build/application.a/dest-depself/resources/library/d/library-dbg.js new file mode 100644 index 000000000..c024ed2d0 --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/library-dbg.js @@ -0,0 +1,23 @@ +/* + * Some fancy copyright + */ + +sap.ui.define([ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "1.0.0", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/library.js b/test/expected/build/application.a/dest-depself/resources/library/d/library.js new file mode 100644 index 000000000..f9910ae65 --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/library.js @@ -0,0 +1,5 @@ +/* + * Some fancy copyright + */ +sap.ui.define(["sap/ui/core/Lib","sap/ui/core/library"],function(e){"use strict";return e.init({name:"library.d",version:"1.0.0",dependencies:["sap.ui.core"],types:[],interfaces:[],controls:[],elements:[],noLibraryCSS:true})}); +//# sourceMappingURL=library.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/library.js.map b/test/expected/build/application.a/dest-depself/resources/library/d/library.js.map new file mode 100644 index 000000000..41a43eb38 --- /dev/null +++ b/test/expected/build/application.a/dest-depself/resources/library/d/library.js.map @@ -0,0 +1 @@ +{"version":3,"file":"library.js","names":["sap","ui","define","Library","init","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS"],"sources":["library-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CACb,kBACA,uBACE,SAAUC,GACZ,aAEA,OAAOA,EAAQC,KAAK,CACnBC,KAAM,YACNC,QAAS,QACTC,aAAc,CACb,eAEDC,MAAO,GACPC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,MAEhB"} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/some-dbg.js b/test/expected/build/application.a/dest-depself/resources/library/d/some-dbg.js index 1e8c6a2f9..3699e1987 100644 --- a/test/expected/build/application.a/dest-depself/resources/library/d/some-dbg.js +++ b/test/expected/build/application.a/dest-depself/resources/library/d/some-dbg.js @@ -1,7 +1,8 @@ /*! * Some fancy copyright */ -(function() { + +sap.ui.define(["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); +}); diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/some.js b/test/expected/build/application.a/dest-depself/resources/library/d/some.js index 75aba1e23..8d85629bb 100644 --- a/test/expected/build/application.a/dest-depself/resources/library/d/some.js +++ b/test/expected/build/application.a/dest-depself/resources/library/d/some.js @@ -1,5 +1,5 @@ /*! * Some fancy copyright */ -(function(){var o="World";console.log("Hello "+o)})(); +sap.ui.define(["./library"],l=>{var o="World";console.log("Hello "+o)}); //# sourceMappingURL=some.js.map \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/library/d/some.js.map b/test/expected/build/application.a/dest-depself/resources/library/d/some.js.map index 8f900826d..760eb1a2a 100644 --- a/test/expected/build/application.a/dest-depself/resources/library/d/some.js.map +++ b/test/expected/build/application.a/dest-depself/resources/library/d/some.js.map @@ -1 +1 @@ -{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD"} \ No newline at end of file +{"version":3,"file":"some.js","names":["sap","ui","define","_library","someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CAAC,aAAeC,IAC7B,IAAIC,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EAAwB"} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js b/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js index 55ccc970f..f6077a315 100644 --- a/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js +++ b/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js @@ -3,12 +3,18 @@ sap.ui.require.preload({ "id1/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"id1","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}', "id1/test.js":function(){ sap.ui.define(["library/d/some"],function(n){function o(n){var o=n;console.log(o)}o()}); +}, + "library/d/library.js":function(){ +/* + * Some fancy copyright + */ +sap.ui.define(["sap/ui/core/Lib","sap/ui/core/library"],function(e){"use strict";return e.init({name:"library.d",version:"1.0.0",dependencies:["sap.ui.core"],types:[],interfaces:[],controls:[],elements:[],noLibraryCSS:true})}); }, "library/d/some.js":function(){ /*! * Some fancy copyright */ -(function(){var o="World";console.log("Hello "+o)})(); +sap.ui.define(["./library"],l=>{var o="World";console.log("Hello "+o)}); } }); //# sourceMappingURL=sap-ui-custom.js.map diff --git a/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js.map b/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js.map index 6d6acf2d7..b4dbad94d 100644 --- a/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js.map +++ b/test/expected/build/application.a/dest-depself/resources/sap-ui-custom.js.map @@ -1 +1 @@ -{"version":3,"file":"sap-ui-custom.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["sap-ui-custom.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":4,"column":0},"map":{"version":3,"file":"test.js","names":["sap","ui","define","someObject","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,CACV,kBACD,SAASC,GACX,SAASC,EAAKC,GACb,IAAIC,EAAYD,EAChBE,QAAQC,IAAIF,EACb,CACAF,GACD","sourceRoot":"id1"}},{"offset":{"line":7,"column":0},"map":{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD","sourceRoot":"library/d"}}]} \ No newline at end of file +{"version":3,"file":"sap-ui-custom.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["sap-ui-custom.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":4,"column":0},"map":{"version":3,"file":"test.js","names":["sap","ui","define","someObject","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,CACV,kBACD,SAASC,GACX,SAASC,EAAKC,GACb,IAAIC,EAAYD,EAChBE,QAAQC,IAAIF,EACb,CACAF,GACD","sourceRoot":"id1"}},{"offset":{"line":7,"column":0},"map":{"version":3,"file":"library.js","names":["sap","ui","define","Library","init","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS"],"sources":["library-dbg.js"],"mappings":"AAAA;;;AAIAA,IAAIC,GAAGC,OAAO,CACb,kBACA,uBACE,SAAUC,GACZ,aAEA,OAAOA,EAAQC,KAAK,CACnBC,KAAM,YACNC,QAAS,QACTC,aAAc,CACb,eAEDC,MAAO,GACPC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,MAEhB","sourceRoot":"library/d"}},{"offset":{"line":13,"column":0},"map":{"version":3,"file":"some.js","names":["sap","ui","define","_library","someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;AAIAA,IAAIC,GAAGC,OAAO,CAAC,aAAeC,IAC7B,IAAIC,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EAAwB","sourceRoot":"library/d"}}]} \ No newline at end of file diff --git a/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js b/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js index 55ccc970f..33109b69c 100644 --- a/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js +++ b/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js @@ -4,11 +4,18 @@ sap.ui.require.preload({ "id1/test.js":function(){ sap.ui.define(["library/d/some"],function(n){function o(n){var o=n;console.log(o)}o()}); }, + "library/d/library.js":function(){ +/* + * Some fancy copyright + */ +sap.ui.define(["sap/ui/core/Lib","sap/ui/core/library"],function(e){"use strict";return e.init({name:"library.d",version:"1.0.0",dependencies:["sap.ui.core"],types:[],interfaces:[],controls:[],elements:[],noLibraryCSS:true})}); +}, + "library/d/manifest.json":'{"_version":"1.21.0","sap.app":{"id":"library.d","type":"library","embeds":[],"applicationVersion":{"version":"1.0.0"},"title":"Library D","description":"Library D","resources":"resources.json","offline":true},"sap.ui":{"technology":"UI5","supportedThemes":[]},"sap.ui5":{"dependencies":{"minUI5Version":"1.0","libs":{}},"library":{"i18n":false,"css":false,"content":{"controls":[],"elements":[],"types":[],"interfaces":[]}}}}', "library/d/some.js":function(){ /*! * Some fancy copyright */ -(function(){var o="World";console.log("Hello "+o)})(); +sap.ui.define(["./library"],l=>{var o="World";console.log("Hello "+o)}); } }); //# sourceMappingURL=sap-ui-custom.js.map diff --git a/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js.map b/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js.map index 6d6acf2d7..a425e0201 100644 --- a/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js.map +++ b/test/expected/build/application.a/dest-self/resources/sap-ui-custom.js.map @@ -1 +1 @@ -{"version":3,"file":"sap-ui-custom.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["sap-ui-custom.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":4,"column":0},"map":{"version":3,"file":"test.js","names":["sap","ui","define","someObject","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,CACV,kBACD,SAASC,GACX,SAASC,EAAKC,GACb,IAAIC,EAAYD,EAChBE,QAAQC,IAAIF,EACb,CACAF,GACD","sourceRoot":"id1"}},{"offset":{"line":7,"column":0},"map":{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD","sourceRoot":"library/d"}}]} \ No newline at end of file +{"version":3,"file":"sap-ui-custom.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["sap-ui-custom.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":4,"column":0},"map":{"version":3,"file":"test.js","names":["sap","ui","define","someObject","test","paramA","variableA","console","log"],"sources":["test-dbg.js"],"mappings":"AAAAA,IAAIC,GAAGC,OAAO,CACV,kBACD,SAASC,GACX,SAASC,EAAKC,GACb,IAAIC,EAAYD,EAChBE,QAAQC,IAAIF,EACb,CACAF,GACD","sourceRoot":"id1"}},{"offset":{"line":7,"column":0},"map":{"version":3,"file":"library.js","names":["sap","ui","define","Library","init","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS"],"sources":["library-dbg.js"],"mappings":"AAAA;;;AAIAA,IAAIC,GAAGC,OAAO,CACb,kBACA,uBACE,SAAUC,GACZ,aAEA,OAAOA,EAAQC,KAAK,CACnBC,KAAM,YACNC,QAAS,QACTC,aAAc,CACb,eAEDC,MAAO,GACPC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,MAEhB","sourceRoot":"library/d"}},{"offset":{"line":14,"column":0},"map":{"version":3,"file":"some.js","names":["sap","ui","define","_library","someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":"AAAA;;;AAIAA,IAAIC,GAAGC,OAAO,CAAC,aAAeC,IAC7B,IAAIC,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EAAwB","sourceRoot":"library/d"}}]} \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/library-dbg.js b/test/expected/build/library.d/dest/resources/library/d/library-dbg.js new file mode 100644 index 000000000..c024ed2d0 --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/library-dbg.js @@ -0,0 +1,23 @@ +/* + * Some fancy copyright + */ + +sap.ui.define([ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "1.0.0", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); diff --git a/test/expected/build/library.d/dest/resources/library/d/library.js b/test/expected/build/library.d/dest/resources/library/d/library.js new file mode 100644 index 000000000..f9910ae65 --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/library.js @@ -0,0 +1,5 @@ +/* + * Some fancy copyright + */ +sap.ui.define(["sap/ui/core/Lib","sap/ui/core/library"],function(e){"use strict";return e.init({name:"library.d",version:"1.0.0",dependencies:["sap.ui.core"],types:[],interfaces:[],controls:[],elements:[],noLibraryCSS:true})}); +//# sourceMappingURL=library.js.map \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/library.js.map b/test/expected/build/library.d/dest/resources/library/d/library.js.map new file mode 100644 index 000000000..41a43eb38 --- /dev/null +++ b/test/expected/build/library.d/dest/resources/library/d/library.js.map @@ -0,0 +1 @@ +{"version":3,"file":"library.js","names":["sap","ui","define","Library","init","name","version","dependencies","types","interfaces","controls","elements","noLibraryCSS"],"sources":["library-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CACb,kBACA,uBACE,SAAUC,GACZ,aAEA,OAAOA,EAAQC,KAAK,CACnBC,KAAM,YACNC,QAAS,QACTC,aAAc,CACb,eAEDC,MAAO,GACPC,WAAY,GACZC,SAAU,GACVC,SAAU,GACVC,aAAc,MAEhB"} \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/manifest.json b/test/expected/build/library.d/dest/resources/library/d/manifest.json index c4f9b3baa..facbd7f7d 100644 --- a/test/expected/build/library.d/dest/resources/library/d/manifest.json +++ b/test/expected/build/library.d/dest/resources/library/d/manifest.json @@ -22,7 +22,14 @@ "libs": {} }, "library": { - "i18n": false + "i18n": false, + "css": false, + "content": { + "controls": [], + "elements": [], + "types": [], + "interfaces": [] + } } } } \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/some-dbg.js b/test/expected/build/library.d/dest/resources/library/d/some-dbg.js index 1e8c6a2f9..3699e1987 100644 --- a/test/expected/build/library.d/dest/resources/library/d/some-dbg.js +++ b/test/expected/build/library.d/dest/resources/library/d/some-dbg.js @@ -1,7 +1,8 @@ /*! * Some fancy copyright */ -(function() { + +sap.ui.define(["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); +}); diff --git a/test/expected/build/library.d/dest/resources/library/d/some.js b/test/expected/build/library.d/dest/resources/library/d/some.js index 75aba1e23..8d85629bb 100644 --- a/test/expected/build/library.d/dest/resources/library/d/some.js +++ b/test/expected/build/library.d/dest/resources/library/d/some.js @@ -1,5 +1,5 @@ /*! * Some fancy copyright */ -(function(){var o="World";console.log("Hello "+o)})(); +sap.ui.define(["./library"],l=>{var o="World";console.log("Hello "+o)}); //# sourceMappingURL=some.js.map \ No newline at end of file diff --git a/test/expected/build/library.d/dest/resources/library/d/some.js.map b/test/expected/build/library.d/dest/resources/library/d/some.js.map index 8f900826d..760eb1a2a 100644 --- a/test/expected/build/library.d/dest/resources/library/d/some.js.map +++ b/test/expected/build/library.d/dest/resources/library/d/some.js.map @@ -1 +1 @@ -{"version":3,"file":"some.js","names":["someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;CAGA,WACC,IAAIA,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EACvB,EAHD"} \ No newline at end of file +{"version":3,"file":"some.js","names":["sap","ui","define","_library","someNonUglifiedVariable","console","log"],"sources":["some-dbg.js"],"mappings":";;;AAIAA,IAAIC,GAAGC,OAAO,CAAC,aAAeC,IAC7B,IAAIC,EAA0B,QAC9BC,QAAQC,IAAI,SAAWF,EAAwB"} \ No newline at end of file diff --git a/test/expected/build/library.d/preload/resources/library/d/library-preload.js b/test/expected/build/library.d/preload/resources/library/d/library-preload.js index 39e436d58..587515c70 100644 --- a/test/expected/build/library.d/preload/resources/library/d/library-preload.js +++ b/test/expected/build/library.d/preload/resources/library/d/library-preload.js @@ -1,14 +1,36 @@ //@ui5-bundle library/d/library-preload.js -sap.ui.require.preload({ - "library/d/legacy.js":'/*!\n * ${copyright}\n */\nvar topLevelVar = "Old World";\nconsole.log(\'Hello \' + topLevelVar);\n', - "library/d/some.js":function(){ +/* + * ${copyright} + */ + +sap.ui.predefine("library/d/library", [ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "${version}", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); /*! * ${copyright} */ -(function() { + +sap.ui.predefine("library/d/some", ["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); -} +}); +sap.ui.require.preload({ + "library/d/legacy.js":'/*!\n * ${copyright}\n */\nvar topLevelVar = "Old World";\nconsole.log(\'Hello \' + topLevelVar);\n' }); //# sourceMappingURL=library-preload.js.map diff --git a/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map b/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map index 7a8e99170..8356c9adf 100644 --- a/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map +++ b/test/expected/build/library.d/preload/resources/library/d/library-preload.js.map @@ -1 +1 @@ -{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}},{"offset":{"line":4,"column":0},"map":{"version":3,"names":[],"sources":["some.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}}]} \ No newline at end of file +{"version":3,"file":"library-preload.js","sections":[{"offset":{"line":1,"column":0},"map":{"version":3,"names":[],"sources":["library.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":24,"column":0},"map":{"version":3,"names":[],"sources":["some.js"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourceRoot":""}},{"offset":{"line":32,"column":0},"map":{"version":3,"names":[],"sources":["library-preload.js?bundle-code-0"],"mappings":"AAAA;AACA","sourcesContent":["sap.ui.require.preload({\n"],"sourceRoot":""}}]} \ No newline at end of file diff --git a/test/expected/build/library.d/preload/resources/library/d/library.js b/test/expected/build/library.d/preload/resources/library/d/library.js new file mode 100644 index 000000000..678cb8034 --- /dev/null +++ b/test/expected/build/library.d/preload/resources/library/d/library.js @@ -0,0 +1,23 @@ +/* + * ${copyright} + */ + +sap.ui.define([ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "${version}", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); diff --git a/test/expected/build/library.d/preload/resources/library/d/some.js b/test/expected/build/library.d/preload/resources/library/d/some.js index fa1d786f7..7c7022e46 100644 --- a/test/expected/build/library.d/preload/resources/library/d/some.js +++ b/test/expected/build/library.d/preload/resources/library/d/some.js @@ -1,7 +1,8 @@ /*! * ${copyright} */ -(function() { + +sap.ui.define(["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); +}); diff --git a/test/expected/build/library.h/dest-resources-json/resources/library/h/resources.json b/test/expected/build/library.h/dest-resources-json/resources/library/h/resources.json index b87948059..e1fb8f900 100644 --- a/test/expected/build/library.h/dest-resources-json/resources/library/h/resources.json +++ b/test/expected/build/library.h/dest-resources-json/resources/library/h/resources.json @@ -186,6 +186,9 @@ "size": 548, "isDebug": true, "merged": true, + "required": [ + "library/h/manifest.json" + ], "included": [ "library/h/file.js", "library/h/library.js", @@ -204,6 +207,9 @@ "module": "library/h/customBundle.js", "size": 540, "merged": true, + "required": [ + "library/h/manifest.json" + ], "included": [ "library/h/file.js", "library/h/library.js", @@ -283,13 +289,19 @@ "module": "library/h/library.js", "size": 58, "format": "raw", - "isDebug": true + "isDebug": true, + "required": [ + "library/h/manifest.json" + ] }, { "name": "library.js", "module": "library/h/library.js", "size": 93, - "format": "raw" + "format": "raw", + "required": [ + "library/h/manifest.json" + ] }, { "name": "library.js.map", @@ -321,7 +333,7 @@ }, { "name": "resources.json", - "size": 7327 + "size": 7539 }, { "name": "some-dbg.js", diff --git a/test/fixtures/library.d/main/src/library/d/library.js b/test/fixtures/library.d/main/src/library/d/library.js new file mode 100644 index 000000000..678cb8034 --- /dev/null +++ b/test/fixtures/library.d/main/src/library/d/library.js @@ -0,0 +1,23 @@ +/* + * ${copyright} + */ + +sap.ui.define([ + "sap/ui/core/Lib", + "sap/ui/core/library" +], function (Library) { + "use strict"; + + return Library.init({ + name: "library.d", + version: "${version}", + dependencies: [ + "sap.ui.core" + ], + types: [], + interfaces: [], + controls: [], + elements: [], + noLibraryCSS: true + }); +}); diff --git a/test/fixtures/library.d/main/src/library/d/some.js b/test/fixtures/library.d/main/src/library/d/some.js index fa1d786f7..7c7022e46 100644 --- a/test/fixtures/library.d/main/src/library/d/some.js +++ b/test/fixtures/library.d/main/src/library/d/some.js @@ -1,7 +1,8 @@ /*! * ${copyright} */ -(function() { + +sap.ui.define(["./library"], (_library) => { var someNonUglifiedVariable = "World"; console.log('Hello ' + someNonUglifiedVariable); -})(); +}); diff --git a/test/lib/lbt/resources/ResourcePool.js b/test/lib/lbt/resources/ResourcePool.js index 6485dd600..87c986ef1 100644 --- a/test/lib/lbt/resources/ResourcePool.js +++ b/test/lib/lbt/resources/ResourcePool.js @@ -160,6 +160,56 @@ test("getModuleInfo: determineDependencyInfo for raw js resources", async (t) => t.false(jsResource.requiresTopLevelScope); }); +test("getModuleInfo: determineDependencyInfo for library.js resource", async (t) => { + const {ResourcePool} = t.context; + + const resourcePool = new ResourcePool(); + const code = `sap.ui.define(["sap/ui/core/Lib"], (Library) => Library.init({ + name: "testlib" + }));`; + const libraryJsResource = { + name: "testlib/library.js", buffer: async () => code, + resource: { + getName: () => "testlib/library.js", + getBuffer: async () => code + } + }; + resourcePool.addResource(libraryJsResource); + + const manifestResource = {name: "testlib/manifest.json", buffer: async () => `{}`}; + resourcePool.addResource(manifestResource); + + const jsResource = await resourcePool.getModuleInfo("testlib/library.js"); + t.deepEqual(jsResource.dependencies, [ + "sap/ui/core/Lib.js", + "ui5loader-autoconfig.js", + "testlib/manifest.json" + ]); +}); + +test("getModuleInfo: determineDependencyInfo for library.js resource (no manifest.json)", async (t) => { + const {ResourcePool} = t.context; + + const resourcePool = new ResourcePool(); + const code = `sap.ui.define(["sap/ui/core/Lib"], (Library) => Library.init({ + name: "testlib" + }));`; + const libraryJsResource = { + name: "testlib/library.js", buffer: async () => code, + resource: { + getName: () => "testlib/library.js", + getBuffer: async () => code + } + }; + resourcePool.addResource(libraryJsResource); + + const jsResource = await resourcePool.getModuleInfo("testlib/library.js"); + t.deepEqual(jsResource.dependencies, [ + "sap/ui/core/Lib.js", + "ui5loader-autoconfig.js" + ]); +}); + test("getModuleInfo: determineDependencyInfo for js templateAssembler code", async (t) => { const {ResourcePool} = t.context; diff --git a/test/lib/tasks/bundlers/generateLibraryPreload.integration.js b/test/lib/tasks/bundlers/generateLibraryPreload.integration.js index d64d9fc68..76394a1e4 100644 --- a/test/lib/tasks/bundlers/generateLibraryPreload.integration.js +++ b/test/lib/tasks/bundlers/generateLibraryPreload.integration.js @@ -52,7 +52,7 @@ test.serial("integration: build library.d with library preload", async (t) => { assert.directoryDeepEqual(destPath, expectedPath); // Check for all file contents - t.is(expectedFiles.length, 6, "6 files are expected"); + t.is(expectedFiles.length, 7, "7 files are expected"); expectedFiles.forEach((expectedFile) => { const relativeFile = path.relative(expectedPath, expectedFile); const destFile = path.join(destPath, relativeFile);