diff --git a/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-ignore.js b/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-ignore.js new file mode 100644 index 000000000..cb016b81b --- /dev/null +++ b/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-ignore.js @@ -0,0 +1,28 @@ +/* eslint-disable no-unused-vars */ +module.exports = function ({ log } = {}) { + const isBuiltInModule = function (module) { + try { + if (!require("path").isAbsolute(module) && require.resolve(module) === module) { + return true; + } + } catch (ex) { + /* */ + } + return false; + }; + return { + name: "polyfill-node-ignore", + resolveId: function (source) { + if (isBuiltInModule(source)) { + return { id: `${source}?polyfill-node-ignore`, moduleSideEffects: false }; + } + return null; + }, + load: function (source) { + if (source.endsWith("?polyfill-node-ignore")) { + return ""; + } + return null; + }, + }; +}; diff --git a/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-override.js b/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-override.js new file mode 100644 index 000000000..924c0dbc8 --- /dev/null +++ b/packages/ui5-tooling-modules/lib/rollup-plugin-polyfill-node-override.js @@ -0,0 +1,37 @@ +/* eslint-disable no-unused-vars */ +const nodePolyfills = require("rollup-plugin-polyfill-node"); +module.exports = function ({ log } = {}) { + const { resolveId } = nodePolyfills(); + return { + name: "polyfill-node-override", + resolveId: function (importee, importer, options) { + if (importee === "http2") { + return { id: "http2?node-polyfill-override", moduleSideEffects: false }; + } + if (importee === "async_hooks") { + return { id: "async_hooks?node-polyfill-override", moduleSideEffects: false }; + } + if (importee.startsWith("node:")) { + return resolveId.call(this, importee.substr("node:".length), importer, options); + } + return null; + }, + load: function (source) { + if (source === "http2?node-polyfill-override") { + return `export const constants = { + HTTP2_HEADER_AUTHORITY: "authority", + HTTP2_HEADER_METHOD: "method", + HTTP2_HEADER_PATH: "path", + HTTP2_HEADER_SCHEME: "scheme", + HTTP2_HEADER_CONTENT_LENGTH: "content-length", + HTTP2_HEADER_EXPECT: "expect", + HTTP2_HEADER_STATUS: "status" + };`; + } + if (source === "async_hooks?node-polyfill-override") { + return `export class AsyncResource {};`; + } + return null; + }, + }; +}; diff --git a/packages/ui5-tooling-modules/lib/util.js b/packages/ui5-tooling-modules/lib/util.js index dd6e1bd60..9d90b7230 100755 --- a/packages/ui5-tooling-modules/lib/util.js +++ b/packages/ui5-tooling-modules/lib/util.js @@ -8,6 +8,8 @@ const { nodeResolve } = require("@rollup/plugin-node-resolve"); const commonjs = require("@rollup/plugin-commonjs"); const json = require("@rollup/plugin-json"); const nodePolyfills = require("rollup-plugin-polyfill-node"); +const nodePolyfillsOverride = require("./rollup-plugin-polyfill-node-override"); +const nodePolyfillsIgnore = require("./rollup-plugin-polyfill-node-ignore"); const amdCustom = require("./rollup-plugin-amd-custom"); const skipAssets = require("./rollup-plugin-skip-assets"); const injectESModule = require("./rollup-plugin-inject-esmodule"); @@ -184,27 +186,24 @@ module.exports = function (log) { "process.env.NODE_ENV": JSON.stringify("development"), }, }), + nodePolyfillsOverride(), + nodePolyfills(), + nodePolyfillsIgnore(), injectESModule(), skipAssets({ log, extensions: ["css"], - modules: ["crypto"], }), commonjs({ defaultIsModuleExports: true, }), amdCustom(), - nodePolyfills(), json(), nodeResolve({ mainFields, preferBuiltins: false, }), pnpmResolve({ - options: { - cwd, - mainFields, - }, resolveModule: function (moduleName) { return that.resolveModule(moduleName, { cwd, depPaths, mainFields }); }, @@ -235,7 +234,7 @@ module.exports = function (log) { define: "sap.ui.define", }, entryFileNames: `${moduleName}.js`, - chunkFileNames: `${moduleName}-[hash].js`, + chunkFileNames: `${moduleName}/[hash].js`, sourcemap: false, // isMiddleware ? "inline" : true }); diff --git a/packages/ui5-tooling-modules/test/__snap__/jspdf.js b/packages/ui5-tooling-modules/test/__snap__/jspdf.js index b81d91b90..49c349484 100644 --- a/packages/ui5-tooling-modules/test/__snap__/jspdf.js +++ b/packages/ui5-tooling-modules/test/__snap__/jspdf.js @@ -1,4 +1,4 @@ -sap.ui.define(['exports', './jspdf-ZSsH8-2i'], (function (exports, jspdf_es_min) { 'use strict'; +sap.ui.define(['exports', './jspdf/Ho2Fpw1t'], (function (exports, jspdf_es_min) { 'use strict'; diff --git a/packages/ui5-tooling-modules/test/__snap__/jspdf-ZSsH8-2i.js b/packages/ui5-tooling-modules/test/__snap__/jspdf/Ho2Fpw1t.js similarity index 95% rename from packages/ui5-tooling-modules/test/__snap__/jspdf-ZSsH8-2i.js rename to packages/ui5-tooling-modules/test/__snap__/jspdf/Ho2Fpw1t.js index 41aeed49c..9d75df6fe 100644 --- a/packages/ui5-tooling-modules/test/__snap__/jspdf-ZSsH8-2i.js +++ b/packages/ui5-tooling-modules/test/__snap__/jspdf/Ho2Fpw1t.js @@ -877,7 +877,7 @@ sap.ui.define(['require', 'exports'], (function (require, exports) { 'use strict * Licensed under the MIT License. * http://opensource.org/licenses/mit-license */ - function(t){t.loadFile=function(t,e,r){return function(t,e,r){e=!1!==e,r="function"==typeof r?r:function(){};var n=void 0;try{n=function(t,e,r){var n=new XMLHttpRequest,i=0,a=function(t){var e=t.length,r=[],n=String.fromCharCode;for(i=0;iu&&(c=h,h=u,u=c);else {if("l"!==e&&"landscape"!==e)throw "Invalid orientation: "+e;e="l",u>h&&(c=h,h=u,u=c);}return {width:h,height:u,unit:r,k:a,orientation:e}},e.html=function(t,e){(e=e||{}).callback=e.callback||function(){},e.html2canvas=e.html2canvas||{},e.html2canvas.canvas=e.html2canvas.canvas||this.canvas,e.jsPDF=e.jsPDF||this,e.fontFaces=e.fontFaces?e.fontFaces.map(jt):null;var r=new s(e);return e.worker?r:r.from(t).doCallback()};}(E.API),E.API.addJS=function(t){return Ht=t,this.internal.events.subscribe("postPutResources",(function(){Ut=this.internal.newObject(),this.internal.out("<<"),this.internal.out("/Names [(EmbeddedJS) "+(Ut+1)+" 0 R]"),this.internal.out(">>"),this.internal.out("endobj"),zt=this.internal.newObject(),this.internal.out("<<"),this.internal.out("/S /JavaScript"),this.internal.out("/JS ("+Ht+")"),this.internal.out(">>"),this.internal.out("endobj");})),this.internal.events.subscribe("putCatalog",(function(){void 0!==Ut&&void 0!==zt&&this.internal.out("/Names <>");})),this}, + function(t){t.loadFile=function(t,e,r){return function(t,e,r){e=!1!==e,r="function"==typeof r?r:function(){};var n=void 0;try{n=function(t,e,r){var n=new XMLHttpRequest,i=0,a=function(t){var e=t.length,r=[],n=String.fromCharCode;for(i=0;iu&&(c=h,h=u,u=c);else {if("l"!==e&&"landscape"!==e)throw "Invalid orientation: "+e;e="l",u>h&&(c=h,h=u,u=c);}return {width:h,height:u,unit:r,k:a,orientation:e}},e.html=function(t,e){(e=e||{}).callback=e.callback||function(){},e.html2canvas=e.html2canvas||{},e.html2canvas.canvas=e.html2canvas.canvas||this.canvas,e.jsPDF=e.jsPDF||this,e.fontFaces=e.fontFaces?e.fontFaces.map(jt):null;var r=new s(e);return e.worker?r:r.from(t).doCallback()};}(E.API),E.API.addJS=function(t){return Ht=t,this.internal.events.subscribe("postPutResources",(function(){Ut=this.internal.newObject(),this.internal.out("<<"),this.internal.out("/Names [(EmbeddedJS) "+(Ut+1)+" 0 R]"),this.internal.out(">>"),this.internal.out("endobj"),zt=this.internal.newObject(),this.internal.out("<<"),this.internal.out("/S /JavaScript"),this.internal.out("/JS ("+Ht+")"),this.internal.out(">>"),this.internal.out("endobj");})),this.internal.events.subscribe("putCatalog",(function(){void 0!==Ut&&void 0!==zt&&this.internal.out("/Names <>");})),this}, /** * @license * Copyright (c) 2014 Steven Spungin (TwelveTone LLC) steven@twelvetone.tv @@ -1040,7 +1040,7 @@ sap.ui.define(['require', 'exports'], (function (require, exports) { 'use strict * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ==================================================================== */ - function(t){function e(){return (n.canvg?Promise.resolve(n.canvg):new Promise(function (resolve, reject) { require(['./jspdf-E7rnPhWU'], resolve, reject); }).then(function (n) { return n.index; })).catch((function(t){return Promise.reject(new Error("Could not load canvg: "+t))})).then((function(t){return t.default?t.default:t}))}E.API.addSvgAsImage=function(t,r,n,i,o,s,c,u){if(isNaN(r)||isNaN(n))throw a.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(i)||isNaN(o))throw a.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var h=document.createElement("canvas");h.width=i,h.height=o;var l=h.getContext("2d");l.fillStyle="#fff",l.fillRect(0,0,h.width,h.height);var f={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},d=this;return e().then((function(e){return e.fromString(l,t,f)}),(function(){return Promise.reject(new Error("Could not load canvg."))})).then((function(t){return t.render(f)})).then((function(){d.addImage(h.toDataURL("image/jpeg",1),r,n,i,o,c,u);}))};}(),E.API.putTotalPages=function(t){var e,r=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(t,"g"),r=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(t,this.internal.getFont()),"g"),r=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var n=1;n<=this.internal.getNumberOfPages();n++)for(var i=0;i1){for(l=0;l>");})),this.internal.viewerpreferences.isSubscribed=!0),this.internal.viewerpreferences.configuration=n,this}, + function(t){function e(){return (n.canvg?Promise.resolve(n.canvg):new Promise(function (resolve, reject) { require(['./BU31YdNB'], resolve, reject); }).then(function (n) { return n.index; })).catch((function(t){return Promise.reject(new Error("Could not load canvg: "+t))})).then((function(t){return t.default?t.default:t}))}E.API.addSvgAsImage=function(t,r,n,i,o,s,c,u){if(isNaN(r)||isNaN(n))throw a.error("jsPDF.addSvgAsImage: Invalid coordinates",arguments),new Error("Invalid coordinates passed to jsPDF.addSvgAsImage");if(isNaN(i)||isNaN(o))throw a.error("jsPDF.addSvgAsImage: Invalid measurements",arguments),new Error("Invalid measurements (width and/or height) passed to jsPDF.addSvgAsImage");var h=document.createElement("canvas");h.width=i,h.height=o;var l=h.getContext("2d");l.fillStyle="#fff",l.fillRect(0,0,h.width,h.height);var f={ignoreMouse:!0,ignoreAnimation:!0,ignoreDimensions:!0},d=this;return e().then((function(e){return e.fromString(l,t,f)}),(function(){return Promise.reject(new Error("Could not load canvg."))})).then((function(t){return t.render(f)})).then((function(){d.addImage(h.toDataURL("image/jpeg",1),r,n,i,o,c,u);}))};}(),E.API.putTotalPages=function(t){var e,r=0;parseInt(this.internal.getFont().id.substr(1),10)<15?(e=new RegExp(t,"g"),r=this.internal.getNumberOfPages()):(e=new RegExp(this.pdfEscape16(t,this.internal.getFont()),"g"),r=this.pdfEscape16(this.internal.getNumberOfPages()+"",this.internal.getFont()));for(var n=1;n<=this.internal.getNumberOfPages();n++)for(var i=0;i1){for(l=0;l>");})),this.internal.viewerpreferences.isSubscribed=!0),this.internal.viewerpreferences.configuration=n,this}, /** ==================================================================== * @license * jsPDF XMP metadata plugin