${alternativeNotice}`);\n } else {\n stringParts.push(`
${thing} is deprecated`);\n }\n\n if (since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.
${reason}
`);\n }\n\n if (replacement) {\n stringParts.push(`Please use ${replacement} instead.
See ${mdl} for more information.
`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Whether the thing being deprecated is in the ignore list or not.\n *\n * Items in the ignore list will only trigger the notification if they are finally deprecated,\n * but will still log the deprecation in the console.\n *\n * @param {string} thing\n * @returns {boolean}\n */\nconst isIgnored = (thing) => {\n const ignored = Cfg.deprecationignorelist || [];\n return ignored.includes(thing);\n};\n\n/**\n * Check environment conditions to determine if a message can be emitted.\n *\n * @returns Whether a message can be emitted\n */\nconst canEmit = () => {\n if (Cfg.developerdebug) {\n return true;\n }\n\n if (document.querySelector('body.behat-site')) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Mark a thing as deprecated, emitting a warning to the console and optionally displaying a toast notification.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {Object} options\n * @param {String} [options.alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [options.replacement] The name of the replacement thing, if there is one.\n * @param {String} [options.since] The version since which this thing has been deprecated.\n * @param {String} [options.reason] The reason why this thing was deprecated.\n * @param {String} [options.mdl] The issue number with more information about this deprecation.\n * @param {Boolean} [options.final=false] Whether this deprecation is final,\n * meaning it should throw an error instead of just emitting a warning.\n * @param {Boolean} [options.emit=true] Whether to emit a toast notification about this deprecation (in addition to\n */\nexport default function (thing, {\n alternativeNotice = null,\n replacement = null,\n since = null,\n reason = null,\n mdl = null,\n final = false,\n emit = true,\n} = {}) {\n if (replacement === null && reason === null && mdl === null) {\n throw new Error('You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.');\n }\n\n const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl);\n\n // If developer debug is enabled display a modal.\n if (canEmit() && emit) {\n if (final || !isIgnored(thing)) {\n emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl));\n }\n }\n\n // If this is a final deprecation, throw an error to break the execution.\n if (final) {\n throw new Error(message);\n } else {\n console.error(message); // eslint-disable-line no-console\n }\n}\n"],"names":["thing","alternativeNotice","replacement","since","reason","mdl","final","emit","Error","message","getMessage","canEmit","isIgnored","getHTMLMessage","console","error","stringParts","push","join","url","Cfg","deprecationignorelist","includes","developerdebug","document","querySelector"],"mappings":"kdAqLyBA,WAAOC,kBAC5BA,kBAAoB,KADQC,YAE5BA,YAAc,KAFcC,MAG5BA,MAAQ,KAHoBC,OAI5BA,OAAS,KAJmBC,IAK5BA,IAAM,KALsBC,MAM5BA,OAAQ,EANoBC,KAO5BA,MAAO,0DACP,MACoB,OAAhBL,aAAmC,OAAXE,QAA2B,OAARC,UACrC,IAAIG,MAAM,iHAGdC,QAAUC,WAAWV,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,KAG7EM,WAAaJ,QACTD,OAAUM,UAAUZ,gCACT,sBAAuBa,eAAeb,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,UAK3GC,YACM,IAAIE,MAAMC,SAEhBK,QAAQC,MAAMN;;;;;;;;;;;;;;;iBAjKhBC,WAAa,CACfV,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,UACpBA,YAAYC,sBAERhB,kBACAe,YAAYC,KAAKhB,mBAEjBe,YAAYC,eAAQjB,+BAGX,OAAVG,OACCa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,KAEbb,QACAY,YAAYC,gBAASb,SAGrBF,aACAc,YAAYC,2BAAoBf,0BAGhCG,KACAW,YAAYC,oBAAaZ,+BAGtBW,YAAYE,KAAK,KAetBL,eAAiB,CACnBb,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,MAEpBA,YAAYC,6BACRhB,kBACAe,YAAYC,kBAAWhB,oBAEvBe,YAAYC,wBAAiBjB,gCAGnB,OAAVG,OACAa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,SAEbb,QACAY,YAAYC,kBAAWb,gBAGvBF,aACAc,YAAYC,mCAA4Bf,qCAGxCG,IAAK,OACCc,kDAA6Cd,KACnDW,YAAYC,+BAAwBE,2DAAkDd,8CAGnFW,YAAYE,KAAK,KAYtBN,UAAaZ,QACCoB,IAAIC,uBAAyB,IAC9BC,SAAStB,OAQtBW,QAAU,MACRS,IAAIG,kBAIJC,SAASC,cAAc"} \ No newline at end of file +{"version":3,"file":"deprecated.min.js","sources":["../src/deprecated.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see${alternativeNotice}`);\n } else {\n stringParts.push(`
${thing} is deprecated`);\n }\n\n if (since !== null) {\n stringParts.push(` since ${since}`);\n }\n\n stringParts.push('.
${reason}
`);\n }\n\n if (replacement) {\n stringParts.push(`Please use ${replacement} instead.
See ${mdl} for more information.
`);\n }\n\n return stringParts.join('');\n};\n\n/**\n * Whether the thing being deprecated is in the ignore list or not.\n *\n * Items in the ignore list will only trigger the notification if they are finally deprecated,\n * but will still log the deprecation in the console.\n *\n * @param {string} thing\n * @returns {boolean}\n */\nconst isIgnored = (thing) => {\n const ignored = Cfg.deprecationignorelist || [];\n return ignored.includes(thing);\n};\n\n/**\n * Check environment conditions to determine if a message can be emitted.\n *\n * @returns Whether a message can be emitted\n */\nconst canEmit = () => {\n if (Cfg.developerdebug) {\n return true;\n }\n\n if (document.querySelector('body.behat-site')) {\n return true;\n }\n\n return false;\n};\n\n/**\n * Mark a thing as deprecated, emitting a warning to the console and optionally displaying a toast notification.\n *\n * @param {String} thing The name of the deprecated thing.\n * @param {Object} options\n * @param {String} [options.alternativeNotice] An alternative to the first part of the deprecation message.\n * This is intended to be used where the simple form is not suited.\n * @param {String} [options.replacement] The name of the replacement thing, if there is one.\n * @param {String} [options.since] The version since which this thing has been deprecated.\n * @param {String} [options.reason] The reason why this thing was deprecated.\n * @param {String} [options.mdl] The issue number with more information about this deprecation.\n * @param {Boolean} [options.final=false] Whether this deprecation is final,\n * meaning it should throw an error instead of just emitting a warning.\n * @param {Boolean} [options.emit=true] Whether to emit a toast notification about this deprecation (in addition to\n */\nexport default function (thing, {\n alternativeNotice = null,\n replacement = null,\n since = null,\n reason = null,\n mdl = null,\n final = false,\n emit = true,\n} = {}) {\n if (replacement === null && reason === null && mdl === null) {\n throw new Error('You must provide at least one of replacement, reason or mdl=false when marking something as deprecated.');\n }\n\n const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl);\n\n // Always emit if the deprecation is final.\n // For non-final deprecations emit if the message does not prevent it, and the user has not ignored it.\n // Non-final deprecations are only shown.\n if (final || canEmit()) {\n if (final || (emit && !isIgnored(thing))) {\n emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl));\n }\n }\n\n // If this is a final deprecation, throw an error to break the execution.\n if (final) {\n throw new Error(message);\n } else {\n console.error(message); // eslint-disable-line no-console\n }\n}\n"],"names":["thing","alternativeNotice","replacement","since","reason","mdl","final","emit","Error","message","getMessage","canEmit","isIgnored","getHTMLMessage","console","error","stringParts","push","join","url","Cfg","deprecationignorelist","includes","developerdebug","document","querySelector"],"mappings":"kdAqLyBA,WAAOC,kBAC5BA,kBAAoB,KADQC,YAE5BA,YAAc,KAFcC,MAG5BA,MAAQ,KAHoBC,OAI5BA,OAAS,KAJmBC,IAK5BA,IAAM,KALsBC,MAM5BA,OAAQ,EANoBC,KAO5BA,MAAO,0DACP,MACoB,OAAhBL,aAAmC,OAAXE,QAA2B,OAARC,UACrC,IAAIG,MAAM,iHAGdC,QAAUC,WAAWV,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,MAK7EC,OAASK,aACLL,OAAUC,OAASK,UAAUZ,iCAClB,sBAAuBa,eAAeb,MAAOC,kBAAmBC,YAAaC,MAAOC,OAAQC,SAK3GC,YACM,IAAIE,MAAMC,SAEhBK,QAAQC,MAAMN;;;;;;;;;;;;;;;iBAnKhBC,WAAa,CACfV,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,UACpBA,YAAYC,sBAERhB,kBACAe,YAAYC,KAAKhB,mBAEjBe,YAAYC,eAAQjB,+BAGX,OAAVG,OACCa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,KAEbb,QACAY,YAAYC,gBAASb,SAGrBF,aACAc,YAAYC,2BAAoBf,0BAGhCG,KACAW,YAAYC,oBAAaZ,+BAGtBW,YAAYE,KAAK,KAetBL,eAAiB,CACnBb,MACAC,kBACAC,YACAC,MACAC,OACAC,aAEMW,YAAc,MAEpBA,YAAYC,6BACRhB,kBACAe,YAAYC,kBAAWhB,oBAEvBe,YAAYC,wBAAiBjB,gCAGnB,OAAVG,OACAa,YAAYC,sBAAed,QAG/Ba,YAAYC,KAAK,SAEbb,QACAY,YAAYC,kBAAWb,gBAGvBF,aACAc,YAAYC,mCAA4Bf,qCAGxCG,IAAK,OACCc,kDAA6Cd,KACnDW,YAAYC,+BAAwBE,2DAAkDd,8CAGnFW,YAAYE,KAAK,KAYtBN,UAAaZ,QACCoB,IAAIC,uBAAyB,IAC9BC,SAAStB,OAQtBW,QAAU,MACRS,IAAIG,kBAIJC,SAASC,cAAc"} \ No newline at end of file diff --git a/public/lib/amd/src/deprecated.js b/public/lib/amd/src/deprecated.js index b8cd9a05dfb..a033a953178 100644 --- a/public/lib/amd/src/deprecated.js +++ b/public/lib/amd/src/deprecated.js @@ -194,9 +194,11 @@ export default function (thing, { const message = getMessage(thing, alternativeNotice, replacement, since, reason, mdl); - // If developer debug is enabled display a modal. - if (canEmit() && emit) { - if (final || !isIgnored(thing)) { + // Always emit if the deprecation is final. + // For non-final deprecations emit if the message does not prevent it, and the user has not ignored it. + // Non-final deprecations are only shown. + if (final || canEmit()) { + if (final || (emit && !isIgnored(thing))) { emitNotice('Deprecation Warning', getHTMLMessage(thing, alternativeNotice, replacement, since, reason, mdl)); } }