Skip to content

Commit c164179

Browse files
committed
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
1 parent fb52e93 commit c164179

File tree

7 files changed

+59
-87
lines changed

7 files changed

+59
-87
lines changed

browser/components/asrouter/.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
{
1616
// TODO: Bug 1773467 - Move these to .mjs or figure out a generic way
1717
// to identify these as modules.
18-
files: ["content-src/**/*.js", "tests/unit/**/*.js"],
18+
files: ["tests/unit/**/*.js"],
1919
parserOptions: {
2020
sourceType: "module",
2121
},

browser/components/asrouter/content-src/asrouter-utils.js renamed to browser/components/asrouter/content-src/asrouter-utils.mjs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
* You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
import { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.sys.mjs";
6-
import { actionCreators as ac } from "common/Actions.sys.mjs";
5+
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
6+
import { MESSAGE_TYPE_HASH as msg } from "../modules/ActorConstants.sys.mjs";
7+
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
8+
import { actionCreators as ac } from "../../newtab/common/Actions.sys.mjs";
79

810
export const ASRouterUtils = {
911
addListener(listener) {
10-
if (global.ASRouterAddParentListener) {
11-
global.ASRouterAddParentListener(listener);
12+
if (globalThis.ASRouterAddParentListener) {
13+
globalThis.ASRouterAddParentListener(listener);
1214
}
1315
},
1416
removeListener(listener) {
15-
if (global.ASRouterRemoveParentListener) {
16-
global.ASRouterRemoveParentListener(listener);
17+
if (globalThis.ASRouterRemoveParentListener) {
18+
globalThis.ASRouterRemoveParentListener(listener);
1719
}
1820
},
1921
sendMessage(action) {
20-
if (global.ASRouterMessage) {
21-
return global.ASRouterMessage(action);
22+
if (globalThis.ASRouterMessage) {
23+
return globalThis.ASRouterMessage(action);
2224
}
2325
throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`);
2426
},

browser/components/asrouter/content/asrouter-admin.bundle.js

Lines changed: 31 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,108 +10,97 @@ var ASRouterAdminRenderUtils;
1010
/******/ var __webpack_modules__ = ([
1111
/* 0 */,
1212
/* 1 */
13-
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
13+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
1414

1515
__webpack_require__.r(__webpack_exports__);
1616
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
1717
/* harmony export */ "ASRouterUtils": () => (/* binding */ ASRouterUtils)
1818
/* harmony export */ });
19-
/* harmony import */ var modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
20-
/* harmony import */ var common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
19+
/* harmony import */ var _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(2);
20+
/* harmony import */ var _newtab_common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
2121
/* This Source Code Form is subject to the terms of the Mozilla Public
2222
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
2323
* You can obtain one at http://mozilla.org/MPL/2.0/. */
2424

25+
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
26+
27+
// eslint-disable-next-line mozilla/reject-import-system-module-from-non-system
2528

2629

2730
const ASRouterUtils = {
2831
addListener(listener) {
29-
if (__webpack_require__.g.ASRouterAddParentListener) {
30-
__webpack_require__.g.ASRouterAddParentListener(listener);
32+
if (globalThis.ASRouterAddParentListener) {
33+
globalThis.ASRouterAddParentListener(listener);
3134
}
3235
},
3336
removeListener(listener) {
34-
if (__webpack_require__.g.ASRouterRemoveParentListener) {
35-
__webpack_require__.g.ASRouterRemoveParentListener(listener);
37+
if (globalThis.ASRouterRemoveParentListener) {
38+
globalThis.ASRouterRemoveParentListener(listener);
3639
}
3740
},
3841
sendMessage(action) {
39-
if (__webpack_require__.g.ASRouterMessage) {
40-
return __webpack_require__.g.ASRouterMessage(action);
42+
if (globalThis.ASRouterMessage) {
43+
return globalThis.ASRouterMessage(action);
4144
}
4245
throw new Error(`Unexpected call:\n${JSON.stringify(action, null, 3)}`);
4346
},
4447
blockById(id, options) {
4548
return ASRouterUtils.sendMessage({
46-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_MESSAGE_BY_ID,
47-
data: {
48-
id,
49-
...options
50-
}
49+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_MESSAGE_BY_ID,
50+
data: { id, ...options },
5151
});
5252
},
5353
modifyMessageJson(content) {
5454
return ASRouterUtils.sendMessage({
55-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.MODIFY_MESSAGE_JSON,
56-
data: {
57-
content
58-
}
55+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.MODIFY_MESSAGE_JSON,
56+
data: { content },
5957
});
6058
},
6159
executeAction(button_action) {
6260
return ASRouterUtils.sendMessage({
63-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.USER_ACTION,
64-
data: button_action
61+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.USER_ACTION,
62+
data: button_action,
6563
});
6664
},
6765
unblockById(id) {
6866
return ASRouterUtils.sendMessage({
69-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_MESSAGE_BY_ID,
70-
data: {
71-
id
72-
}
67+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_MESSAGE_BY_ID,
68+
data: { id },
7369
});
7470
},
7571
blockBundle(bundle) {
7672
return ASRouterUtils.sendMessage({
77-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_BUNDLE,
78-
data: {
79-
bundle
80-
}
73+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.BLOCK_BUNDLE,
74+
data: { bundle },
8175
});
8276
},
8377
unblockBundle(bundle) {
8478
return ASRouterUtils.sendMessage({
85-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_BUNDLE,
86-
data: {
87-
bundle
88-
}
79+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.UNBLOCK_BUNDLE,
80+
data: { bundle },
8981
});
9082
},
9183
overrideMessage(id) {
9284
return ASRouterUtils.sendMessage({
93-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.OVERRIDE_MESSAGE,
94-
data: {
95-
id
96-
}
85+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.OVERRIDE_MESSAGE,
86+
data: { id },
9787
});
9888
},
9989
editState(key, value) {
10090
return ASRouterUtils.sendMessage({
101-
type: modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.EDIT_STATE,
102-
data: {
103-
[key]: value
104-
}
91+
type: _modules_ActorConstants_sys_mjs__WEBPACK_IMPORTED_MODULE_0__.MESSAGE_TYPE_HASH.EDIT_STATE,
92+
data: { [key]: value },
10593
});
10694
},
10795
sendTelemetry(ping) {
108-
return ASRouterUtils.sendMessage(common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__.actionCreators.ASRouterUserEvent(ping));
96+
return ASRouterUtils.sendMessage(_newtab_common_Actions_sys_mjs__WEBPACK_IMPORTED_MODULE_1__.actionCreators.ASRouterUserEvent(ping));
10997
},
11098
getPreviewEndpoint() {
11199
return null;
112-
}
100+
},
113101
};
114102

103+
115104
/***/ }),
116105
/* 2 */
117106
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {

browser/components/asrouter/karma.mc.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ module.exports = function (config) {
124124
devtool: "inline-source-map",
125125
// This resolve config allows us to import with paths relative to the root directory
126126
resolve: {
127-
extensions: [".js", ".jsx"],
127+
extensions: [".mjs", ".js", ".jsx"],
128128
modules: [
129129
PATHS.moduleResolveDirectory,
130130
"node_modules",
@@ -181,7 +181,7 @@ module.exports = function (config) {
181181
},
182182
{
183183
enforce: "post",
184-
test: /\.js[mx]?$/,
184+
test: /\.js[x]?$/,
185185
loader: "@jsdevtools/coverage-istanbul-loader",
186186
options: { esModules: true },
187187
include: [path.resolve("content-src"), path.resolve("modules")],

browser/components/asrouter/tests/unit/ASRouterChild.test.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
/*eslint max-nested-callbacks: ["error", 10]*/
22
import { ASRouterChild } from "actors/ASRouterChild.sys.mjs";
33
import { MESSAGE_TYPE_HASH as msg } from "modules/ActorConstants.sys.mjs";
4-
import { GlobalOverrider } from "test/unit/utils";
54

65
describe("ASRouterChild", () => {
76
let asRouterChild = null;
8-
let globals = null;
9-
let overrider = null;
107
let sandbox = null;
118
beforeEach(() => {
129
sandbox = sinon.createSandbox();
13-
globals = {
14-
Cu: {
15-
cloneInto: sandbox.stub().returns(Promise.resolve()),
16-
},
17-
};
18-
overrider = new GlobalOverrider();
19-
overrider.set(globals);
2010
asRouterChild = new ASRouterChild();
2111
asRouterChild.telemetry = {
2212
sendTelemetry: sandbox.stub(),
@@ -26,7 +16,6 @@ describe("ASRouterChild", () => {
2616
});
2717
afterEach(() => {
2818
sandbox.restore();
29-
overrider.restore();
3019
asRouterChild = null;
3120
});
3221
describe("asRouterMessage", () => {
Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,22 @@
1-
import { ASRouterUtils } from "content-src/asrouter-utils";
2-
import { GlobalOverrider } from "test/unit/utils";
1+
import { ASRouterUtils } from "../../content-src/asrouter-utils.mjs";
32

43
describe("ASRouterUtils", () => {
5-
let globals = null;
6-
let overrider = null;
74
let sandbox = null;
85
beforeEach(() => {
96
sandbox = sinon.createSandbox();
10-
globals = {
11-
ASRouterMessage: sandbox.stub().resolves({}),
12-
};
13-
overrider = new GlobalOverrider();
14-
overrider.set(globals);
7+
globalThis.ASRouterMessage = sandbox.stub().resolves({});
158
});
169
afterEach(() => {
1710
sandbox.restore();
18-
overrider.restore();
1911
});
2012
describe("sendMessage", () => {
2113
it("default", () => {
2214
ASRouterUtils.sendMessage({ foo: "bar" });
23-
assert.calledOnce(globals.ASRouterMessage);
24-
assert.calledWith(globals.ASRouterMessage, { foo: "bar" });
15+
assert.calledOnce(globalThis.ASRouterMessage);
16+
assert.calledWith(globalThis.ASRouterMessage, { foo: "bar" });
2517
});
2618
it("throws if ASRouterMessage is not defined", () => {
27-
overrider.set("ASRouterMessage", undefined);
19+
globalThis.ASRouterMessage = null;
2820
assert.throws(() => ASRouterUtils.sendMessage({ foo: "bar" }));
2921
});
3022
it("can accept the legacy NEWTAB_MESSAGE_REQUEST message without throwing", async () => {
@@ -41,7 +33,7 @@ describe("ASRouterUtils", () => {
4133
it("default", () => {
4234
ASRouterUtils.blockById(1, { foo: "bar" });
4335
assert.calledWith(
44-
globals.ASRouterMessage,
36+
globalThis.ASRouterMessage,
4537
sinon.match({ data: { foo: "bar", id: 1 } })
4638
);
4739
});
@@ -50,7 +42,7 @@ describe("ASRouterUtils", () => {
5042
it("default", () => {
5143
ASRouterUtils.modifyMessageJson({ foo: "bar" });
5244
assert.calledWith(
53-
globals.ASRouterMessage,
45+
globalThis.ASRouterMessage,
5446
sinon.match({ data: { content: { foo: "bar" } } })
5547
);
5648
});
@@ -59,7 +51,7 @@ describe("ASRouterUtils", () => {
5951
it("default", () => {
6052
ASRouterUtils.executeAction({ foo: "bar" });
6153
assert.calledWith(
62-
globals.ASRouterMessage,
54+
globalThis.ASRouterMessage,
6355
sinon.match({ data: { foo: "bar" } })
6456
);
6557
});
@@ -68,7 +60,7 @@ describe("ASRouterUtils", () => {
6860
it("default", () => {
6961
ASRouterUtils.unblockById(2);
7062
assert.calledWith(
71-
globals.ASRouterMessage,
63+
globalThis.ASRouterMessage,
7264
sinon.match({ data: { id: 2 } })
7365
);
7466
});
@@ -77,7 +69,7 @@ describe("ASRouterUtils", () => {
7769
it("default", () => {
7870
ASRouterUtils.blockBundle(2);
7971
assert.calledWith(
80-
globals.ASRouterMessage,
72+
globalThis.ASRouterMessage,
8173
sinon.match({ data: { bundle: 2 } })
8274
);
8375
});
@@ -86,7 +78,7 @@ describe("ASRouterUtils", () => {
8678
it("default", () => {
8779
ASRouterUtils.unblockBundle(2);
8880
assert.calledWith(
89-
globals.ASRouterMessage,
81+
globalThis.ASRouterMessage,
9082
sinon.match({ data: { bundle: 2 } })
9183
);
9284
});
@@ -95,7 +87,7 @@ describe("ASRouterUtils", () => {
9587
it("default", () => {
9688
ASRouterUtils.overrideMessage(12);
9789
assert.calledWith(
98-
globals.ASRouterMessage,
90+
globalThis.ASRouterMessage,
9991
sinon.match({ data: { id: 12 } })
10092
);
10193
});
@@ -104,15 +96,15 @@ describe("ASRouterUtils", () => {
10496
it("default", () => {
10597
ASRouterUtils.editState("foo", "bar");
10698
assert.calledWith(
107-
globals.ASRouterMessage,
99+
globalThis.ASRouterMessage,
108100
sinon.match({ data: { foo: "bar" } })
109101
);
110102
});
111103
});
112104
describe("sendTelemetry", () => {
113105
it("default", () => {
114106
ASRouterUtils.sendTelemetry({ foo: "bar" });
115-
assert.calledOnce(globals.ASRouterMessage);
107+
assert.calledOnce(globalThis.ASRouterMessage);
116108
});
117109
});
118110
});

browser/components/asrouter/webpack.asrouter-admin.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = Object.assign({}, config(), {
2525
plugins: [new webpack.BannerPlugin(banner)],
2626
// This resolve config allows us to import with paths relative to the root directory
2727
resolve: {
28-
extensions: [".js", ".jsx"],
28+
extensions: [".js", ".jsx", ".mjs"],
2929
alias: {
3030
newtab: absolute("../newtab"),
3131
common: absolute("../newtab/common"),

0 commit comments

Comments
 (0)