Bug 1878731 - Convert ASRouterTargeting to an ESM. r=emcminn,application-update-reviewers,omc-reviewers,bytesized

Differential Revision: https://phabricator.services.mozilla.com/D201133
This commit is contained in:
Mike Conley 2024-02-12 18:49:37 +00:00
Родитель 78b1c85ec9
Коммит 3e82da1fda
22 изменённых файлов: 55 добавлений и 67 удалений

Просмотреть файл

@ -15,9 +15,12 @@ const { XPCOMUtils } = ChromeUtils.importESModule(
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouter: "resource:///modules/asrouter/ASRouter.jsm",
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.jsm",
});
export const AWScreenUtils = {

Просмотреть файл

@ -5,13 +5,10 @@
ChromeUtils.defineESModuleGetters(this, {
FxAccounts: "resource://gre/modules/FxAccounts.sys.mjs",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
sinon: "resource://testing-common/Sinon.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.jsm",
});
// Set the content pref to make it available across tests
const ABOUT_WELCOME_OVERRIDE_CONTENT_PREF = "browser.aboutwelcome.screens";

Просмотреть файл

@ -219,7 +219,7 @@ module.exports = function (config) {
exclude: [
path.resolve("tests"),
path.resolve("../newtab"),
path.resolve("modules/ASRouterTargeting.jsm"),
path.resolve("modules/ASRouterTargeting.sys.mjs"),
path.resolve("modules/ASRouterTriggerListeners.sys.mjs"),
path.resolve("modules/CFRMessageProvider.sys.mjs"),
path.resolve("modules/CFRPageActions.sys.mjs"),

Просмотреть файл

@ -13,6 +13,7 @@ const { AppConstants } = ChromeUtils.importESModule(
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
ASRouterTriggerListeners:
"resource:///modules/asrouter/ASRouterTriggerListeners.sys.mjs",
Downloader: "resource://services-settings/Attachments.sys.mjs",
@ -38,7 +39,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.jsm",
ASRouterPreferences: "resource:///modules/asrouter/ASRouterPreferences.jsm",
TARGETING_PREFERENCES: "resource:///modules/asrouter/ASRouterPreferences.jsm",
});

Просмотреть файл

@ -23,9 +23,7 @@ const { SpecialMessageActions } = ChromeUtils.importESModule(
const { ASRouterPreferences } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterPreferences.jsm"
);
const { QueryCache } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
);
import { QueryCache } from "resource:///modules/asrouter/ASRouterTargeting.sys.mjs";
import { ActivityStreamStorage } from "resource://activity-stream/lib/ActivityStreamStorage.sys.mjs";
const createStorage = async telemetryFeed => {

Просмотреть файл

@ -6,15 +6,29 @@ const FXA_ENABLED_PREF = "identity.fxaccounts.enabled";
const DISTRIBUTION_ID_PREF = "distribution.id";
const DISTRIBUTION_ID_CHINA_REPACK = "MozillaOnline";
// We use importESModule here instead of static import so that
// the Karma test environment won't choke on this module. This
// is because the Karma test environment already stubs out
// XPCOMUtils, AppConstants, NewTabUtils and ShellService, and
// overrides importESModule to be a no-op (which can't be done
// for a static import statement).
// eslint-disable-next-line mozilla/use-static-import
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
// eslint-disable-next-line mozilla/use-static-import
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
// eslint-disable-next-line mozilla/use-static-import
const { NewTabUtils } = ChromeUtils.importESModule(
"resource://gre/modules/NewTabUtils.sys.mjs"
);
// eslint-disable-next-line mozilla/use-static-import
const { ShellService } = ChromeUtils.importESModule(
"resource:///modules/ShellService.sys.mjs"
);
@ -172,7 +186,7 @@ const jexlEvaluationCache = new Map();
* @param options {any=} Options passed to the method
* @param updateInterval {number?} Update interval for query. Defaults to FRECENT_SITES_UPDATE_INTERVAL
*/
function CachedTargetingGetter(
export function CachedTargetingGetter(
property,
options = null,
updateInterval = FRECENT_SITES_UPDATE_INTERVAL,
@ -269,7 +283,7 @@ function CheckBrowserNeedsUpdate(
return checker;
}
const QueryCache = {
export const QueryCache = {
expireAll() {
Object.keys(this.queries).forEach(query => {
this.queries[query].expire();
@ -376,7 +390,7 @@ function sortMessagesByWeightedRank(messages) {
* @param {boolean} options.ordered - Should .order be used instead of random weighted sorting?
* @returns {Array<Message>}
*/
function getSortedMessages(messages, options = {}) {
export function getSortedMessages(messages, options = {}) {
let { ordered } = { ordered: false, ...options };
let result = messages;
@ -1040,7 +1054,7 @@ const TargetingGetters = {
},
};
const ASRouterTargeting = {
export const ASRouterTargeting = {
Environment: TargetingGetters,
/**
@ -1282,10 +1296,3 @@ const ASRouterTargeting = {
return matching;
},
};
const EXPORTED_SYMBOLS = [
"ASRouterTargeting",
"QueryCache",
"CachedTargetingGetter",
"getSortedMessages",
];

Просмотреть файл

@ -21,7 +21,7 @@ EXTRA_JS_MODULES.asrouter += [
"modules/ASRouterNewTabHook.sys.mjs",
"modules/ASRouterParentProcessMessageHandler.sys.mjs",
"modules/ASRouterPreferences.jsm",
"modules/ASRouterTargeting.jsm",
"modules/ASRouterTargeting.sys.mjs",
"modules/ASRouterTriggerListeners.sys.mjs",
"modules/CFRMessageProvider.sys.mjs",
"modules/CFRPageActions.sys.mjs",

Просмотреть файл

@ -1,12 +1,9 @@
XPCOMUtils.defineLazyModuleGetters(this, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.jsm",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.jsm",
});
ChromeUtils.defineESModuleGetters(this, {
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
AddonTestUtils: "resource://testing-common/AddonTestUtils.sys.mjs",
AboutNewTab: "resource:///modules/AboutNewTab.sys.mjs",
AppConstants: "resource://gre/modules/AppConstants.sys.mjs",
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
AttributionCode: "resource:///modules/AttributionCode.sys.mjs",
BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.sys.mjs",
BuiltInThemes: "resource:///modules/BuiltInThemes.sys.mjs",
@ -19,6 +16,7 @@ ChromeUtils.defineESModuleGetters(this, {
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
ProfileAge: "resource://gre/modules/ProfileAge.sys.mjs",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
Region: "resource://gre/modules/Region.sys.mjs",
ShellService: "resource:///modules/ShellService.sys.mjs",
TargetingContext: "resource://messaging-system/targeting/Targeting.sys.mjs",

Просмотреть файл

@ -1,5 +1,5 @@
import { _ASRouter, MessageLoaderUtils } from "modules/ASRouter.jsm";
import { QueryCache } from "modules/ASRouterTargeting.jsm";
import { QueryCache } from "modules/ASRouterTargeting.sys.mjs";
import {
FAKE_LOCAL_MESSAGES,
FAKE_LOCAL_PROVIDER,

Просмотреть файл

@ -3,7 +3,7 @@ import {
CachedTargetingGetter,
getSortedMessages,
QueryCache,
} from "modules/ASRouterTargeting.jsm";
} from "modules/ASRouterTargeting.sys.mjs";
import { OnboardingMessageProvider } from "modules/OnboardingMessageProvider.sys.mjs";
import { ASRouterPreferences } from "modules/ASRouterPreferences.jsm";
import { GlobalOverrider } from "test/unit/utils";

Просмотреть файл

@ -1,4 +1,4 @@
import { ASRouterTargeting } from "modules/ASRouterTargeting.jsm";
import { ASRouterTargeting } from "modules/ASRouterTargeting.sys.mjs";
import docs from "docs/targeting-attributes.md";
// The following targeting parameters are either deprecated or should not be included in the docs for some reason.

Просмотреть файл

@ -7,8 +7,8 @@
const { AttributionCode } = ChromeUtils.importESModule(
"resource:///modules/AttributionCode.sys.mjs"
);
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
const { MacAttribution } = ChromeUtils.importESModule(
"resource:///modules/MacAttribution.sys.mjs"

Просмотреть файл

@ -4,8 +4,8 @@
"use strict";
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
add_task(async function should_ignore_rejections() {

Просмотреть файл

@ -7,8 +7,8 @@ const { ASRouter } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouter.jsm"
);
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
const { OnboardingMessageProvider } = ChromeUtils.importESModule(

Просмотреть файл

@ -10,10 +10,10 @@ ChromeUtils.defineESModuleGetters(this, {
"resource:///modules/asrouter/FeatureCalloutMessages.sys.mjs",
ObjectUtils: "resource://gre/modules/ObjectUtils.sys.mjs",
PlacesTestUtils: "resource://testing-common/PlacesTestUtils.sys.mjs",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(this, {
ASRouter: "resource:///modules/asrouter/ASRouter.jsm",
QueryCache: "resource:///modules/asrouter/ASRouterTargeting.jsm",
});
// We import sinon here to make it available across all mochitest test files

Просмотреть файл

@ -5,9 +5,7 @@
import { EXIT_CODE } from "resource://gre/modules/BackgroundTasksManager.sys.mjs";
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
);
import { ASRouterTargeting } from "resource:///modules/asrouter/ASRouterTargeting.sys.mjs";
// Background tasks are "live" with a temporary profile that doesn't map common
// network preferences to https://mochi.test in the way that regular testing

Просмотреть файл

@ -14,8 +14,8 @@
// 3. We verify that relevant opt-out prefs disable the Nimbus and Firefox
// Messaging System experience.
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
// These randomization IDs were extracted by hand from Firefox instances.

Просмотреть файл

@ -7,13 +7,10 @@
const { BackgroundTasksUtils } = ChromeUtils.importESModule(
"resource://gre/modules/BackgroundTasksUtils.sys.mjs"
);
const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.jsm",
ChromeUtils.defineESModuleGetters(lazy, {
ASRouterTargeting: "resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
});
setupProfileService();

Просмотреть файл

@ -2,12 +2,14 @@
* 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/. */
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
ClientEnvironment: "resource://normandy/lib/ClientEnvironment.sys.mjs",
ClientEnvironmentBase:
"resource://gre/modules/components-utils/ClientEnvironment.sys.mjs",
@ -18,12 +20,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
setTimeout: "resource://gre/modules/Timer.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.jsm",
});
const TARGETING_EVENT_CATEGORY = "messaging_experiments";
const TARGETING_EVENT_METHOD = "targeting";
const DEFAULT_TIMEOUT = 5000;

Просмотреть файл

@ -8,6 +8,9 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
_ExperimentFeature: "resource://nimbus/ExperimentAPI.sys.mjs",
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
CleanupManager: "resource://normandy/lib/CleanupManager.sys.mjs",
ExperimentManager: "resource://nimbus/lib/ExperimentManager.sys.mjs",
JsonSchema: "resource://gre/modules/JsonSchema.sys.mjs",
@ -16,12 +19,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
TargetingContext: "resource://messaging-system/targeting/Targeting.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.jsm",
});
ChromeUtils.defineLazyGetter(lazy, "log", () => {
const { Logger } = ChromeUtils.importESModule(
"resource://messaging-system/lib/Logger.sys.mjs"

Просмотреть файл

@ -11,6 +11,9 @@ const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs",
BackgroundTasksUtils: "resource://gre/modules/BackgroundTasksUtils.sys.mjs",
JSONFile: "resource://gre/modules/JSONFile.sys.mjs",
TaskScheduler: "resource://gre/modules/TaskScheduler.sys.mjs",
@ -18,12 +21,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
NimbusFeatures: "resource://nimbus/ExperimentAPI.sys.mjs",
});
XPCOMUtils.defineLazyModuleGetters(lazy, {
ASRouterTargeting:
// eslint-disable-next-line mozilla/no-browser-refs-in-toolkit
"resource:///modules/asrouter/ASRouterTargeting.jsm",
});
ChromeUtils.defineLazyGetter(lazy, "log", () => {
let { ConsoleAPI } = ChromeUtils.importESModule(
"resource://gre/modules/Console.sys.mjs"

Просмотреть файл

@ -6,8 +6,8 @@
"use strict";
const { ASRouterTargeting } = ChromeUtils.import(
"resource:///modules/asrouter/ASRouterTargeting.jsm"
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
const { BackgroundUpdate } = ChromeUtils.importESModule(