diff --git a/.eslintignore b/.eslintignore index 0a47ebaba7..02b85a1ef0 100644 --- a/.eslintignore +++ b/.eslintignore @@ -50,8 +50,8 @@ mail/branding/nightly/pref/thunderbird-branding.js mail/branding/thunderbird/pref/thunderbird-branding.js # This file is split into two in order to keep it as a valid json file # for documentation purposes (policies.json) but to be accessed by the -# code as a .jsm (schema.jsm) -mail/components/enterprisepolicies/schemas/schema.jsm +# code as a JS module (schema.sys.mjs) +mail/components/enterprisepolicies/schemas/schema.sys.mjs mail/components/im/all-im.js mail/extensions/am-e2e/prefs/e2e-prefs.js mail/locales/en-US/all-l10n.js diff --git a/.prettierignore b/.prettierignore index 10efbeb0f7..b355666d2e 100644 --- a/.prettierignore +++ b/.prettierignore @@ -19,8 +19,8 @@ mailnews/mailnews.js # This file is split into two in order to keep it as a valid json file # for documentation purposes (policies.json) but to be accessed by the -# code as a .jsm (schema.jsm). -mail/components/enterprisepolicies/schemas/schema.jsm +# code as a JS module (schema.sys.mjs). +mail/components/enterprisepolicies/schemas/schema.sys.mjs # Third-party code. calendar/base/modules/Ical.jsm diff --git a/mail/components/enterprisepolicies/content/aboutPolicies.js b/mail/components/enterprisepolicies/content/aboutPolicies.js index fb3ad8a7e6..4615d9f462 100644 --- a/mail/components/enterprisepolicies/content/aboutPolicies.js +++ b/mail/components/enterprisepolicies/content/aboutPolicies.js @@ -8,8 +8,9 @@ const { XPCOMUtils } = ChromeUtils.importESModule( "resource://gre/modules/XPCOMUtils.sys.mjs" ); -XPCOMUtils.defineLazyModuleGetters(this, { - schema: "resource:///modules/policies/schema.jsm", +const lazy = {}; +ChromeUtils.defineESModuleGetters(lazy, { + schema: "resource:///modules/policies/schema.sys.mjs", }); function col(text, className) { @@ -62,7 +63,7 @@ function generateActivePolicies(data) { for (let policyName in data) { const color_class = ++policy_count % 2 === 0 ? "even" : "odd"; - if (schema.properties[policyName].type == "array") { + if (lazy.schema.properties[policyName].type == "array") { for (let count in data[policyName]) { let isFirstRow = count == 0; let isLastRow = count == data[policyName].length - 1; @@ -78,7 +79,7 @@ function generateActivePolicies(data) { data[policyName].length > 1 ); } - } else if (schema.properties[policyName].type == "object") { + } else if (lazy.schema.properties[policyName].type == "object") { let count = 0; for (let obj in data[policyName]) { let isFirstRow = count == 0; @@ -277,7 +278,7 @@ function generateDocumentation() { Certificates: "CertificatesDescription", }; - for (let policyName in schema.properties) { + for (let policyName in lazy.schema.properties) { let main_tbody = document.createElement("tbody"); main_tbody.classList.add("collapsible"); main_tbody.addEventListener("click", function() { @@ -295,32 +296,35 @@ function generateDocumentation() { sec_tbody.classList.add("content"); sec_tbody.classList.add("content-style"); let schema_row = document.createElement("tr"); - if (schema.properties[policyName].properties) { + if (lazy.schema.properties[policyName].properties) { let column = col( - JSON.stringify(schema.properties[policyName].properties, null, 1), + JSON.stringify(lazy.schema.properties[policyName].properties, null, 1), "schema" ); column.colSpan = "2"; schema_row.appendChild(column); sec_tbody.appendChild(schema_row); - } else if (schema.properties[policyName].items) { + } else if (lazy.schema.properties[policyName].items) { let column = col( - JSON.stringify(schema.properties[policyName], null, 1), + JSON.stringify(lazy.schema.properties[policyName], null, 1), "schema" ); column.colSpan = "2"; schema_row.appendChild(column); sec_tbody.appendChild(schema_row); } else { - let column = col("type: " + schema.properties[policyName].type, "schema"); + let column = col( + "type: " + lazy.schema.properties[policyName].type, + "schema" + ); column.colSpan = "2"; schema_row.appendChild(column); sec_tbody.appendChild(schema_row); - if (schema.properties[policyName].enum) { + if (lazy.schema.properties[policyName].enum) { let enum_row = document.createElement("tr"); column = col( "enum: " + - JSON.stringify(schema.properties[policyName].enum, null, 1), + JSON.stringify(lazy.schema.properties[policyName].enum, null, 1), "schema" ); column.colSpan = "2"; diff --git a/mail/components/enterprisepolicies/schemas/moz.build b/mail/components/enterprisepolicies/schemas/moz.build index 45c242ed1e..658f0b1ed7 100644 --- a/mail/components/enterprisepolicies/schemas/moz.build +++ b/mail/components/enterprisepolicies/schemas/moz.build @@ -8,5 +8,5 @@ with Files("**"): BUG_COMPONENT = ("Thunderbird", "OS Integration") EXTRA_PP_JS_MODULES.policies += [ - "schema.jsm", + "schema.sys.mjs", ] diff --git a/mail/components/enterprisepolicies/schemas/schema.jsm b/mail/components/enterprisepolicies/schemas/schema.sys.mjs similarity index 53% rename from mail/components/enterprisepolicies/schemas/schema.jsm rename to mail/components/enterprisepolicies/schemas/schema.sys.mjs index fba69c56c9..671a8cfca1 100644 --- a/mail/components/enterprisepolicies/schemas/schema.jsm +++ b/mail/components/enterprisepolicies/schemas/schema.sys.mjs @@ -2,9 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ -"use strict"; - -const EXPORTED_SYMBOLS = ["schema"]; - -var schema = +const initialSchema = #include policies-schema.json + +export let schema = initialSchema; + +export function modifySchemaForTests(customSchema) { + if (customSchema) { + schema = customSchema; + } else { + schema = initialSchema; + } +} diff --git a/mail/components/enterprisepolicies/tests/xpcshell/test_sorted_alphabetically.js b/mail/components/enterprisepolicies/tests/xpcshell/test_sorted_alphabetically.js index b56a69a1b3..088e4fcb7e 100644 --- a/mail/components/enterprisepolicies/tests/xpcshell/test_sorted_alphabetically.js +++ b/mail/components/enterprisepolicies/tests/xpcshell/test_sorted_alphabetically.js @@ -19,8 +19,8 @@ function checkArrayIsSorted(array, msg) { } add_task(async function test_policies_sorted() { - let { schema } = ChromeUtils.import( - "resource:///modules/policies/schema.jsm" + let { schema } = ChromeUtils.importESModule( + "resource:///modules/policies/schema.sys.mjs" ); let { Policies } = ChromeUtils.importESModule( "resource:///modules/policies/Policies.sys.mjs" @@ -37,8 +37,8 @@ add_task(async function test_policies_sorted() { }); add_task(async function check_naming_conventions() { - let { schema } = ChromeUtils.import( - "resource:///modules/policies/schema.jsm" + let { schema } = ChromeUtils.importESModule( + "resource:///modules/policies/schema.sys.mjs" ); equal( Object.keys(schema.properties).some(key => key.includes("__")), diff --git a/tools/esmify/mach_commands.py b/tools/esmify/mach_commands.py index 311bd82922..fb02f4982e 100644 --- a/tools/esmify/mach_commands.py +++ b/tools/esmify/mach_commands.py @@ -56,7 +56,7 @@ excluded_from_imports_prefix = list( "mail/app/profile/all-thunderbird.js", "mail/branding/thunderbird/pref/thunderbird-branding.js", "mail/components/compose/composer.js", - "mail/components/enterprisepolicies/schemas/schema.jsm", + "mail/components/enterprisepolicies/schemas/schema.sys.mjs", "mail/locales/en-US/all-l10n.js", "mail/extensions/am-e2e/prefs/e2e-prefs.js", "mailnews/extensions/mdn/mdn.js", diff --git a/tools/esmify/map.json b/tools/esmify/map.json index af34d0bb4c..d3ee88359b 100644 --- a/tools/esmify/map.json +++ b/tools/esmify/map.json @@ -415,7 +415,6 @@ "resource:///modules/matrixTextForEvent.jsm": "comm/chat/protocols/matrix/matrixTextForEvent.jsm", "resource:///modules/mimeParser.jsm": "comm/mailnews/mime/src/mimeParser.jsm", "resource:///modules/odnoklassniki.jsm": "comm/chat/protocols/odnoklassniki/odnoklassniki.jsm", - "resource:///modules/policies/schema.jsm": "comm/mail/components/enterprisepolicies/schemas/schema.jsm", "resource:///modules/sax.jsm": "comm/chat/protocols/xmpp/sax.jsm", "resource:///modules/socket.jsm": "comm/chat/modules/socket.jsm", "resource:///modules/twitter.jsm": "comm/chat/protocols/twitter/twitter.jsm",