Bug 1881816 - Move all newtab/content-src/*.js files which are modules to use .mjs extensions. r=amy

Differential Revision: https://phabricator.services.mozilla.com/D202623
This commit is contained in:
Mark Banner 2024-03-19 17:01:38 +00:00
parent 1bb7ccda05
commit ca1465e265
28 changed files with 451 additions and 314 deletions

View file

@ -15,11 +15,7 @@ module.exports = {
{ {
// TODO: Bug 1773467 - Move these to .mjs or figure out a generic way // TODO: Bug 1773467 - Move these to .mjs or figure out a generic way
// to identify these as modules. // to identify these as modules.
files: [ files: ["test/schemas/**/*.js", "test/unit/**/*.js"],
"content-src/**/*.js",
"test/schemas/**/*.js",
"test/unit/**/*.js",
],
parserOptions: { parserOptions: {
sourceType: "module", sourceType: "module",
}, },

View file

@ -73,7 +73,7 @@ export class _Base extends React.PureComponent {
] ]
.filter(v => v) .filter(v => v)
.join(" "); .join(" ");
global.document.body.className = bodyClassName; globalThis.document.body.className = bodyClassName;
} }
render() { render() {

View file

@ -119,7 +119,7 @@ export class _CollapsibleSection extends React.PureComponent {
} }
_CollapsibleSection.defaultProps = { _CollapsibleSection.defaultProps = {
document: global.document || { document: globalThis.document || {
addEventListener: () => {}, addEventListener: () => {},
removeEventListener: () => {}, removeEventListener: () => {},
visibilityState: "hidden", visibilityState: "hidden",

View file

@ -26,12 +26,12 @@ export class ContextMenu extends React.PureComponent {
componentDidMount() { componentDidMount() {
this.onShow(); this.onShow();
setTimeout(() => { setTimeout(() => {
global.addEventListener("click", this.hideContext); globalThis.addEventListener("click", this.hideContext);
}, 0); }, 0);
} }
componentWillUnmount() { componentWillUnmount() {
global.removeEventListener("click", this.hideContext); globalThis.removeEventListener("click", this.hideContext);
} }
onClick(event) { onClick(event) {

View file

@ -442,9 +442,9 @@ export class CollapseToggle extends React.PureComponent {
setBodyClass() { setBodyClass() {
if (this.renderAdmin && !this.state.collapsed) { if (this.renderAdmin && !this.state.collapsed) {
global.document.body.classList.add("no-scroll"); globalThis.document.body.classList.add("no-scroll");
} else { } else {
global.document.body.classList.remove("no-scroll"); globalThis.document.body.classList.remove("no-scroll");
} }
} }
@ -457,7 +457,7 @@ export class CollapseToggle extends React.PureComponent {
} }
componentWillUnmount() { componentWillUnmount() {
global.document.body.classList.remove("no-scroll"); globalThis.document.body.classList.remove("no-scroll");
} }
render() { render() {

View file

@ -8,19 +8,19 @@ export class SimpleHashRouter extends React.PureComponent {
constructor(props) { constructor(props) {
super(props); super(props);
this.onHashChange = this.onHashChange.bind(this); this.onHashChange = this.onHashChange.bind(this);
this.state = { hash: global.location.hash }; this.state = { hash: globalThis.location.hash };
} }
onHashChange() { onHashChange() {
this.setState({ hash: global.location.hash }); this.setState({ hash: globalThis.location.hash });
} }
componentWillMount() { componentWillMount() {
global.addEventListener("hashchange", this.onHashChange); globalThis.addEventListener("hashchange", this.onHashChange);
} }
componentWillUnmount() { componentWillUnmount() {
global.removeEventListener("hashchange", this.onHashChange); globalThis.removeEventListener("hashchange", this.onHashChange);
} }
render() { render() {

View file

@ -384,6 +384,6 @@ export const DiscoveryStreamBase = connect(state => ({
DiscoveryStream: state.DiscoveryStream, DiscoveryStream: state.DiscoveryStream,
Prefs: state.Prefs, Prefs: state.Prefs,
Sections: state.Sections, Sections: state.Sections,
document: global.document, document: globalThis.document,
App: state.App, App: state.App,
}))(_DiscoveryStreamBase); }))(_DiscoveryStreamBase);

View file

@ -28,7 +28,7 @@ export function DSSubHeader({ children }) {
); );
} }
export function OnboardingExperience({ dispatch, windowObj = global }) { export function OnboardingExperience({ dispatch, windowObj = globalThis }) {
const [dismissed, setDismissed] = useState(false); const [dismissed, setDismissed] = useState(false);
const [maxHeight, setMaxHeight] = useState(null); const [maxHeight, setMaxHeight] = useState(null);
const heightElement = useRef(null); const heightElement = useRef(null);

View file

@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
import { cardContextTypes } from "../../Card/types.js"; import { cardContextTypes } from "../../Card/types.mjs";
import { SponsoredContentHighlight } from "../FeatureHighlight/SponsoredContentHighlight"; import { SponsoredContentHighlight } from "../FeatureHighlight/SponsoredContentHighlight";
import { CSSTransition, TransitionGroup } from "react-transition-group"; import { CSSTransition, TransitionGroup } from "react-transition-group";
import { FluentOrText } from "../../FluentOrText/FluentOrText.jsx"; import { FluentOrText } from "../../FluentOrText/FluentOrText.jsx";

View file

@ -241,8 +241,8 @@ export class ImpressionStats extends React.PureComponent {
} }
ImpressionStats.defaultProps = { ImpressionStats.defaultProps = {
IntersectionObserver: global.IntersectionObserver, IntersectionObserver: globalThis.IntersectionObserver,
document: global.document, document: globalThis.document,
rows: [], rows: [],
source: "", source: "",
}; };

View file

@ -53,4 +53,4 @@ export class ModalOverlayWrapper extends React.PureComponent {
} }
} }
ModalOverlayWrapper.defaultProps = { document: global.document }; ModalOverlayWrapper.defaultProps = { document: globalThis.document };

View file

@ -30,7 +30,7 @@ export class Section extends React.PureComponent {
let cardsPerRow = CARDS_PER_ROW_DEFAULT; let cardsPerRow = CARDS_PER_ROW_DEFAULT;
if ( if (
props.compactCards && props.compactCards &&
global.matchMedia(`(min-width: 1072px)`).matches globalThis.matchMedia(`(min-width: 1072px)`).matches
) { ) {
// If the section has compact cards and the viewport is wide enough, we show // If the section has compact cards and the viewport is wide enough, we show
// 4 columns instead of 3. // 4 columns instead of 3.
@ -323,7 +323,7 @@ export class Section extends React.PureComponent {
} }
Section.defaultProps = { Section.defaultProps = {
document: global.document, document: globalThis.document,
rows: [], rows: [],
emptyState: {}, emptyState: {},
pref: {}, pref: {},

View file

@ -142,8 +142,8 @@ export class TopSiteImpressionWrapper extends React.PureComponent {
} }
TopSiteImpressionWrapper.defaultProps = { TopSiteImpressionWrapper.defaultProps = {
IntersectionObserver: global.IntersectionObserver, IntersectionObserver: globalThis.IntersectionObserver,
document: global.document, document: globalThis.document,
actionType: null, actionType: null,
tile: null, tile: null,
}; };

View file

@ -90,7 +90,7 @@ export class _TopSites extends React.PureComponent {
// We hide 2 sites per row when not in the wide layout. // We hide 2 sites per row when not in the wide layout.
let sitesPerRow = TOP_SITES_MAX_SITES_PER_ROW; let sitesPerRow = TOP_SITES_MAX_SITES_PER_ROW;
// $break-point-widest = 1072px (from _variables.scss) // $break-point-widest = 1072px (from _variables.scss)
if (!global.matchMedia(`(min-width: 1072px)`).matches) { if (!globalThis.matchMedia(`(min-width: 1072px)`).matches) {
sitesPerRow -= 2; sitesPerRow -= 2;
} }
return this.props.TopSites.rows.slice( return this.props.TopSites.rows.slice(

View file

@ -3,7 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
export const IS_NEWTAB = export const IS_NEWTAB =
global.document && global.document.documentURI === "about:newtab"; globalThis.document && globalThis.document.documentURI === "about:newtab";
export const NEWTAB_DARK_THEME = { export const NEWTAB_DARK_THEME = {
ntp_background: { ntp_background: {
r: 42, r: 42,

View file

@ -2,8 +2,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
import { actionCreators as ac, actionTypes as at } from "common/Actions.mjs"; import {
import { perfService as perfSvc } from "content-src/lib/perf-service"; actionCreators as ac,
actionTypes as at,
} from "../../common/Actions.mjs";
import { perfService as perfSvc } from "./perf-service.mjs";
const VISIBLE = "visible"; const VISIBLE = "visible";
const VISIBILITY_CHANGE_EVENT = "visibilitychange"; const VISIBILITY_CHANGE_EVENT = "visibilitychange";
@ -12,7 +15,7 @@ export class DetectUserSessionStart {
constructor(store, options = {}) { constructor(store, options = {}) {
this._store = store; this._store = store;
// Overrides for testing // Overrides for testing
this.document = options.document || global.document; this.document = options.document || globalThis.document;
this._perfService = options.perfService || perfSvc; this._perfService = options.perfService || perfSvc;
this._onVisibilityChange = this._onVisibilityChange.bind(this); this._onVisibilityChange = this._onVisibilityChange.bind(this);
} }

View file

@ -8,7 +8,10 @@ import {
actionCreators as ac, actionCreators as ac,
actionTypes as at, actionTypes as at,
actionUtils as au, actionUtils as au,
} from "common/Actions.mjs"; } from "../../common/Actions.mjs";
// We disable import checking here as redux is installed via the npm packages
// at the newtab level, rather than in the top-level package.json.
// eslint-disable-next-line import/no-unresolved
import { applyMiddleware, combineReducers, createStore } from "redux"; import { applyMiddleware, combineReducers, createStore } from "redux";
export const MERGE_STORE_ACTION = "NEW_TAB_INITIAL_STATE"; export const MERGE_STORE_ACTION = "NEW_TAB_INITIAL_STATE";
@ -117,12 +120,12 @@ export function initStore(reducers, initialState) {
const store = createStore( const store = createStore(
mergeStateReducer(combineReducers(reducers)), mergeStateReducer(combineReducers(reducers)),
initialState, initialState,
global.RPMAddMessageListener && globalThis.RPMAddMessageListener &&
applyMiddleware(rehydrationMiddleware, messageMiddleware) applyMiddleware(rehydrationMiddleware, messageMiddleware)
); );
if (global.RPMAddMessageListener) { if (globalThis.RPMAddMessageListener) {
global.RPMAddMessageListener(INCOMING_MESSAGE_NAME, msg => { globalThis.RPMAddMessageListener(INCOMING_MESSAGE_NAME, msg => {
try { try {
store.dispatch(msg.data); store.dispatch(msg.data);
} catch (ex) { } catch (ex) {

View file

@ -2,7 +2,10 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
import { actionCreators as ac, actionTypes as at } from "common/Actions.mjs"; import {
actionCreators as ac,
actionTypes as at,
} from "../../common/Actions.mjs";
const _OpenInPrivateWindow = site => ({ const _OpenInPrivateWindow = site => ({
id: "newtab-menu-open-new-private-window", id: "newtab-menu-open-new-private-window",

View file

@ -2,8 +2,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file, * 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/. */ * You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
let usablePerfObj = window.performance; let usablePerfObj = window.performance;
export function _PerfService(options) { export function _PerfService(options) {
@ -37,8 +35,8 @@ _PerfService.prototype = {
* @param {String} type eg "mark" * @param {String} type eg "mark"
* @return {Array} Performance* objects * @return {Array} Performance* objects
*/ */
getEntriesByName: function getEntriesByName(name, type) { getEntriesByName: function getEntriesByName(entryName, type) {
return this._perf.getEntriesByName(name, type); return this._perf.getEntriesByName(entryName, type);
}, },
/** /**
@ -89,11 +87,11 @@ _PerfService.prototype = {
* See [bug 1369303](https://bugzilla.mozilla.org/show_bug.cgi?id=1369303) * See [bug 1369303](https://bugzilla.mozilla.org/show_bug.cgi?id=1369303)
* for more info. * for more info.
*/ */
getMostRecentAbsMarkStartByName(name) { getMostRecentAbsMarkStartByName(entryName) {
let entries = this.getEntriesByName(name, "mark"); let entries = this.getEntriesByName(entryName, "mark");
if (!entries.length) { if (!entries.length) {
throw new Error(`No marks with the name ${name}`); throw new Error(`No marks with the name ${entryName}`);
} }
let mostRecentEntry = entries[entries.length - 1]; let mostRecentEntry = entries[entries.length - 1];

View file

@ -30,7 +30,7 @@ export const ScreenshotUtils = {
} }
if (this.isBlob(false, remoteImage)) { if (this.isBlob(false, remoteImage)) {
return { return {
url: global.URL.createObjectURL(remoteImage.data), url: globalThis.URL.createObjectURL(remoteImage.data),
path: remoteImage.path, path: remoteImage.path,
}; };
} }
@ -41,7 +41,7 @@ export const ScreenshotUtils = {
// This should always be called with a local image and not a remote image. // This should always be called with a local image and not a remote image.
maybeRevokeBlobObjectURL(localImage) { maybeRevokeBlobObjectURL(localImage) {
if (this.isBlob(true, localImage)) { if (this.isBlob(true, localImage)) {
global.URL.revokeObjectURL(localImage.url); globalThis.URL.revokeObjectURL(localImage.url);
} }
}, },

View file

@ -211,7 +211,7 @@ module.exports = function (config) {
devtool: "inline-source-map", devtool: "inline-source-map",
// This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.sys.mjs" // This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.sys.mjs"
resolve: { resolve: {
extensions: [".js", ".jsx"], extensions: [".js", ".jsx", ".mjs"],
modules: [PATHS.moduleResolveDirectory, "node_modules"], modules: [PATHS.moduleResolveDirectory, "node_modules"],
alias: { alias: {
asrouter: path.join(__dirname, "../asrouter"), asrouter: path.join(__dirname, "../asrouter"),
@ -260,7 +260,7 @@ module.exports = function (config) {
}, },
{ {
enforce: "post", enforce: "post",
test: /\.js[mx]?$/, test: /\.js[x]?$/,
loader: "@jsdevtools/coverage-istanbul-loader", loader: "@jsdevtools/coverage-istanbul-loader",
options: { esModules: true }, options: { esModules: true },
include: [ include: [

View file

@ -389,7 +389,7 @@ export const SectionsManager = {
/** /**
* Sets each card in highlights' context menu options based on the card's type. * Sets each card in highlights' context menu options based on the card's type.
* (See types.js for a list of types) * (See types.mjs for a list of types)
* *
* @param rows section rows containing a type for each card * @param rows section rows containing a type for each card
*/ */

View file

@ -5,7 +5,7 @@ import {
} from "content-src/components/DiscoveryStreamComponents/DSContextFooter/DSContextFooter"; } from "content-src/components/DiscoveryStreamComponents/DSContextFooter/DSContextFooter";
import React from "react"; import React from "react";
import { mount } from "enzyme"; import { mount } from "enzyme";
import { cardContextTypes } from "content-src/components/Card/types.js"; import { cardContextTypes } from "content-src/components/Card/types.mjs";
import { FluentOrText } from "content-src/components/FluentOrText/FluentOrText.jsx"; import { FluentOrText } from "content-src/components/FluentOrText/FluentOrText.jsx";
describe("<DSContextFooter>", () => { describe("<DSContextFooter>", () => {

View file

@ -48,7 +48,7 @@ module.exports = (env = {}) => ({
}, },
// This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.sys.mjs" // This resolve config allows us to import with paths relative to the root directory, e.g. "lib/ActivityStream.sys.mjs"
resolve: { resolve: {
extensions: [".js", ".jsx"], extensions: [".js", ".jsx", ".mjs"],
modules: ["node_modules", "."], modules: ["node_modules", "."],
}, },
externals: { externals: {