зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1881817 - Move all asrouter/content-src/*.js files which are modules to use .mjs extensions. r=aminomancer,omc-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D202622
This commit is contained in:
Родитель
fb52e933e4
Коммит
c1641790d9
|
@ -15,7 +15,7 @@ module.exports = {
|
|||
{
|
||||
// TODO: Bug 1773467 - Move these to .mjs or figure out a generic way
|
||||
// to identify these as modules.
|
||||
files: ["content-src/**/*.js", "tests/unit/**/*.js"],
|
||||
files: ["tests/unit/**/*.js"],
|
||||
parserOptions: {
|
||||
sourceType: "module",
|
||||
},
|
||||
|
|
|
@ -2,23 +2,25 @@
|
|||
* 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 { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.sys.mjs";
|
||||
import { actionCreators as ac } from "common/Actions.sys.mjs";
|
||||
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
|
||||
import { MESSAGE_TYPE_HASH as msg } from "../modules/ActorConstants.sys.mjs";
|
||||
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
|
||||
import { actionCreators as ac } from "../../newtab/common/Actions.sys.mjs";
|
||||
|
||||
export const ASRouterUtils = {
|
||||
addListener(listener) {
|
||||
if (global.ASRouterAddParentListener) {
|
||||
global.ASRouterAddParentListener(listener);
|
||||
if (globalThis.ASRouterAddParentListener) {
|
||||
globalThis.ASRouterAddParentListener(listener);
|
||||
}
|
||||
},
|
||||
removeListener(listener) {
|
||||
if (global.ASRouterRemoveParentListener) {
|
||||
global.ASRouterRemoveParentListener(listener);
|
||||
if (globalThis.ASRouterRemoveParentListener) {
|
||||
globalThis.ASRouterRemoveParentListener(listener);
|
||||
}
|
||||
},
|
||||
sendMessage(action) {
|
||||
if (global.ASRouterMessage) {
|
||||
return global.ASRouterMessage(action);
|
||||
if (globalThis.ASRouterMessage) {
|
||||
return globalThis.ASRouterMessage(action);
|
||||
}
|
||||
throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`);
|
||||
},
|
|
@ -10,108 +10,97 @@ var ASRouterAdminRenderUtils;
|
|||
/******/ var __webpack_modules__ = ([
|
||||
/* 0 */,
|
||||
/* 1 */
|
||||
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
||||
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
||||
|
||||
__webpack_require__.r(__webpack_exports__);
|
||||
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
||||
/* harmony export */ "ASRouterUtils": () => (/* binding */ ASRouterUtils)
|
||||
/* harmony export */ });
|
||||
/* harmony import */ var modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
||||
/* harmony import */ var common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
||||
/* harmony import */ var _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
|
||||
/* harmony import */ var _newtab_common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* 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/. */
|
||||
|
||||
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
|
||||
|
||||
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
|
||||
|
||||
|
||||
const ASRouterUtils = {
|
||||
addListener(listener) {
|
||||
if (__webpack_require__.g.ASRouterAddParentListener) {
|
||||
__webpack_require__.g.ASRouterAddParentListener(listener);
|
||||
if (globalThis.ASRouterAddParentListener) {
|
||||
globalThis.ASRouterAddParentListener(listener);
|
||||
}
|
||||
},
|
||||
removeListener(listener) {
|
||||
if (__webpack_require__.g.ASRouterRemoveParentListener) {
|
||||
__webpack_require__.g.ASRouterRemoveParentListener(listener);
|
||||
if (globalThis.ASRouterRemoveParentListener) {
|
||||
globalThis.ASRouterRemoveParentListener(listener);
|
||||
}
|
||||
},
|
||||
sendMessage(action) {
|
||||
if (__webpack_require__.g.ASRouterMessage) {
|
||||
return __webpack_require__.g.ASRouterMessage(action);
|
||||
if (globalThis.ASRouterMessage) {
|
||||
return globalThis.ASRouterMessage(action);
|
||||
}
|
||||
throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`);
|
||||
},
|
||||
blockById(id, options) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_MESSAGE_BY_ID,
|
||||
data: {
|
||||
id,
|
||||
...options
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_MESSAGE_BY_ID,
|
||||
data: { id, ...options },
|
||||
});
|
||||
},
|
||||
modifyMessageJson(content) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.MODIFY_MESSAGE_JSON,
|
||||
data: {
|
||||
content
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.MODIFY_MESSAGE_JSON,
|
||||
data: { content },
|
||||
});
|
||||
},
|
||||
executeAction(button_action) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.USER_ACTION,
|
||||
data: button_action
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.USER_ACTION,
|
||||
data: button_action,
|
||||
});
|
||||
},
|
||||
unblockById(id) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_MESSAGE_BY_ID,
|
||||
data: {
|
||||
id
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_MESSAGE_BY_ID,
|
||||
data: { id },
|
||||
});
|
||||
},
|
||||
blockBundle(bundle) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_BUNDLE,
|
||||
data: {
|
||||
bundle
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_BUNDLE,
|
||||
data: { bundle },
|
||||
});
|
||||
},
|
||||
unblockBundle(bundle) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_BUNDLE,
|
||||
data: {
|
||||
bundle
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_BUNDLE,
|
||||
data: { bundle },
|
||||
});
|
||||
},
|
||||
overrideMessage(id) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.OVERRIDE_MESSAGE,
|
||||
data: {
|
||||
id
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.OVERRIDE_MESSAGE,
|
||||
data: { id },
|
||||
});
|
||||
},
|
||||
editState(key, value) {
|
||||
return ASRouterUtils.sendMessage({
|
||||
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.EDIT_STATE,
|
||||
data: {
|
||||
[key]: value
|
||||
}
|
||||
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.EDIT_STATE,
|
||||
data: { [key]: value },
|
||||
});
|
||||
},
|
||||
sendTelemetry(ping) {
|
||||
return ASRouterUtils.sendMessage(common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__.actionCreators.ASRouterUserEvent(ping));
|
||||
return ASRouterUtils.sendMessage(_newtab_common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__.actionCreators.ASRouterUserEvent(ping));
|
||||
},
|
||||
getPreviewEndpoint() {
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
/* 2 */
|
||||
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
||||
|
|
|
@ -124,7 +124,7 @@ module.exports = function (config) {
|
|||
devtool: "inline-source-map",
|
||||
// This resolve config allows us to import with paths relative to the root directory
|
||||
resolve: {
|
||||
extensions: [".js", ".jsx"],
|
||||
extensions: [".mjs", ".js", ".jsx"],
|
||||
modules: [
|
||||
PATHS.moduleResolveDirectory,
|
||||
"node_modules",
|
||||
|
@ -181,7 +181,7 @@ module.exports = function (config) {
|
|||
},
|
||||
{
|
||||
enforce: "post",
|
||||
test: /\.js[mx]?$/,
|
||||
test: /\.js[x]?$/,
|
||||
loader: "@jsdevtools/coverage-istanbul-loader",
|
||||
options: { esModules: true },
|
||||
include: [path.resolve("content-src"), path.resolve("modules")],
|
||||
|
|
|
@ -1,22 +1,12 @@
|
|||
/*eslint max-nested-callbacks: ["error", 10]*/
|
||||
import { ASRouterChild } from "actors/ASRouterChild.sys.mjs";
|
||||
import { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.sys.mjs";
|
||||
import { GlobalOverrider } from "test/unit/utils";
|
||||
|
||||
describe("ASRouterChild", () => {
|
||||
let asRouterChild = null;
|
||||
let globals = null;
|
||||
let overrider = null;
|
||||
let sandbox = null;
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
globals = {
|
||||
Cu: {
|
||||
cloneInto: sandbox.stub().returns(Promise.resolve()),
|
||||
},
|
||||
};
|
||||
overrider = new GlobalOverrider();
|
||||
overrider.set(globals);
|
||||
asRouterChild = new ASRouterChild();
|
||||
asRouterChild.telemetry = {
|
||||
sendTelemetry: sandbox.stub(),
|
||||
|
@ -26,7 +16,6 @@ describe("ASRouterChild", () => {
|
|||
});
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
overrider.restore();
|
||||
asRouterChild = null;
|
||||
});
|
||||
describe("asRouterMessage", () => {
|
||||
|
|
|
@ -1,30 +1,22 @@
|
|||
import { ASRouterUtils } from "content-src/asrouter-utils";
|
||||
import { GlobalOverrider } from "test/unit/utils";
|
||||
import { ASRouterUtils } from "../../content-src/asrouter-utils.mjs";
|
||||
|
||||
describe("ASRouterUtils", () => {
|
||||
let globals = null;
|
||||
let overrider = null;
|
||||
let sandbox = null;
|
||||
beforeEach(() => {
|
||||
sandbox = sinon.createSandbox();
|
||||
globals = {
|
||||
ASRouterMessage: sandbox.stub().resolves({}),
|
||||
};
|
||||
overrider = new GlobalOverrider();
|
||||
overrider.set(globals);
|
||||
globalThis.ASRouterMessage = sandbox.stub().resolves({});
|
||||
});
|
||||
afterEach(() => {
|
||||
sandbox.restore();
|
||||
overrider.restore();
|
||||
});
|
||||
describe("sendMessage", () => {
|
||||
it("default", () => {
|
||||
ASRouterUtils.sendMessage({ foo: "bar" });
|
||||
assert.calledOnce(globals.ASRouterMessage);
|
||||
assert.calledWith(globals.ASRouterMessage, { foo: "bar" });
|
||||
assert.calledOnce(globalThis.ASRouterMessage);
|
||||
assert.calledWith(globalThis.ASRouterMessage, { foo: "bar" });
|
||||
});
|
||||
it("throws if ASRouterMessage is not defined", () => {
|
||||
overrider.set("ASRouterMessage", undefined);
|
||||
globalThis.ASRouterMessage = null;
|
||||
assert.throws(() => ASRouterUtils.sendMessage({ foo: "bar" }));
|
||||
});
|
||||
it("can accept the legacy NEWTAB_MESSAGE_REQUEST message without throwing", async () => {
|
||||
|
@ -41,7 +33,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.blockById(1, { foo: "bar" });
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { foo: "bar", id: 1 } })
|
||||
);
|
||||
});
|
||||
|
@ -50,7 +42,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.modifyMessageJson({ foo: "bar" });
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { content: { foo: "bar" } } })
|
||||
);
|
||||
});
|
||||
|
@ -59,7 +51,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.executeAction({ foo: "bar" });
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { foo: "bar" } })
|
||||
);
|
||||
});
|
||||
|
@ -68,7 +60,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.unblockById(2);
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { id: 2 } })
|
||||
);
|
||||
});
|
||||
|
@ -77,7 +69,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.blockBundle(2);
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { bundle: 2 } })
|
||||
);
|
||||
});
|
||||
|
@ -86,7 +78,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.unblockBundle(2);
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { bundle: 2 } })
|
||||
);
|
||||
});
|
||||
|
@ -95,7 +87,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.overrideMessage(12);
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { id: 12 } })
|
||||
);
|
||||
});
|
||||
|
@ -104,7 +96,7 @@ describe("ASRouterUtils", () => {
|
|||
it("default", () => {
|
||||
ASRouterUtils.editState("foo", "bar");
|
||||
assert.calledWith(
|
||||
globals.ASRouterMessage,
|
||||
globalThis.ASRouterMessage,
|
||||
sinon.match({ data: { foo: "bar" } })
|
||||
);
|
||||
});
|
||||
|
@ -112,7 +104,7 @@ describe("ASRouterUtils", () => {
|
|||
describe("sendTelemetry", () => {
|
||||
it("default", () => {
|
||||
ASRouterUtils.sendTelemetry({ foo: "bar" });
|
||||
assert.calledOnce(globals.ASRouterMessage);
|
||||
assert.calledOnce(globalThis.ASRouterMessage);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@ module.exports = Object.assign({}, config(), {
|
|||
plugins: [new webpack.BannerPlugin(banner)],
|
||||
// This resolve config allows us to import with paths relative to the root directory
|
||||
resolve: {
|
||||
extensions: [".js", ".jsx"],
|
||||
extensions: [".js", ".jsx", ".mjs"],
|
||||
alias: {
|
||||
newtab: absolute("../newtab"),
|
||||
common: absolute("../newtab/common"),
|
||||
|
|
Загрузка…
Ссылка в новой задаче