From 2775d1829d7c41116b0557995a01ea34f7f84e6f Mon Sep 17 00:00:00 2001 From: Joabesv Date: Tue, 13 Feb 2024 02:00:06 -0300 Subject: [PATCH] chore: change default module detection to ESSM --- package.json | 9 +++-- postcss.config.js => postcss.config.cjs | 0 src/lib/{init.js => init.cjs} | 0 ...lStorage.min.js => xdLocalStorage.min.cjs} | 0 ...s => xdLocalStoragePostMessageApi.min.cjs} | 0 src/{manifest.mjs => manifest.js} | 0 src/scripts/contentscript.js | 2 +- src/services/NextAPI.js | 6 +-- .../{NextStorage.mjs => NextStorage.js} | 0 src/utils/Matricula.js | 6 +-- src/utils/convertUfabcDisciplina.js | 10 ++--- src/utils/disciplinaIdentifier.js | 11 +++--- src/utils/extensionUtils.js | 4 +- src/utils/removeDiacritics.js | 8 ++-- src/utils/season.js | 12 ++---- src/utils/setupStorage.js | 6 +-- src/utils/setupStorageESM.mjs | 39 ------------------- src/utils/toJSON.js | 8 +--- src/views/Popup/Popup.vue | 4 +- tasks/{manifest.dev.mjs => manifest.dev.js} | 4 +- tasks/{manifest.prod.mjs => manifest.prod.js} | 4 +- tasks/{mvsw.dev.mjs => mvsw.dev.js} | 2 +- tasks/{mvsw.prod.mjs => mvsw.prod.js} | 2 +- tasks/{prepare.dev.mjs => prepare.dev.js} | 6 +-- tasks/{prepare.prod.mjs => prepare.prod.js} | 2 +- tasks/{utils.mjs => utils.js} | 0 tsup.config.mjs => tsup.config.js | 2 +- vite.config.mjs => vite.config.js | 0 28 files changed, 43 insertions(+), 104 deletions(-) rename postcss.config.js => postcss.config.cjs (100%) rename src/lib/{init.js => init.cjs} (100%) rename src/lib/{xdLocalStorage.min.js => xdLocalStorage.min.cjs} (100%) rename src/lib/{xdLocalStoragePostMessageApi.min.js => xdLocalStoragePostMessageApi.min.cjs} (100%) rename src/{manifest.mjs => manifest.js} (100%) rename src/services/{NextStorage.mjs => NextStorage.js} (100%) delete mode 100644 src/utils/setupStorageESM.mjs rename tasks/{manifest.dev.mjs => manifest.dev.js} (85%) rename tasks/{manifest.prod.mjs => manifest.prod.js} (85%) rename tasks/{mvsw.dev.mjs => mvsw.dev.js} (97%) rename tasks/{mvsw.prod.mjs => mvsw.prod.js} (97%) rename tasks/{prepare.dev.mjs => prepare.dev.js} (87%) rename tasks/{prepare.prod.mjs => prepare.prod.js} (54%) rename tasks/{utils.mjs => utils.js} (100%) rename tsup.config.mjs => tsup.config.js (95%) rename vite.config.mjs => vite.config.js (100%) diff --git a/package.json b/package.json index ed2c1b5..1d85dec 100644 --- a/package.json +++ b/package.json @@ -2,17 +2,18 @@ "name": "UFABC-Next-Extension", "private": true, "version": "1.1.7", + "type": "module", "description": "Adiciona funcionalidades novas ao sistema de matricula da UFABC", "scripts": { "dev": "rimraf extension/dev && run-p dev:*", - "dev:prepare": "node --no-warnings=ExperimentalWarning tasks/prepare.dev.mjs dev", + "dev:prepare": "node --no-warnings=ExperimentalWarning tasks/prepare.dev.js dev", "dev:web": "vite", "dev:js": "yarn run build:dev --watch src", "build": "NODE_ENV=prod run-s clear build:web build:prepare build:prod", - "build:prepare": "node tasks/prepare.prod.mjs build", + "build:prepare": "node tasks/prepare.prod.js build", "build:web": "vite build", - "build:dev": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.mjs'", - "build:prod": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.mjs'", + "build:dev": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.dev.js'", + "build:prod": "tsup --onSuccess 'node --no-warnings=ExperimentalWarning tasks/mvsw.prod.js'", "clear": "rimraf extension/prod" }, "standard": { diff --git a/postcss.config.js b/postcss.config.cjs similarity index 100% rename from postcss.config.js rename to postcss.config.cjs diff --git a/src/lib/init.js b/src/lib/init.cjs similarity index 100% rename from src/lib/init.js rename to src/lib/init.cjs diff --git a/src/lib/xdLocalStorage.min.js b/src/lib/xdLocalStorage.min.cjs similarity index 100% rename from src/lib/xdLocalStorage.min.js rename to src/lib/xdLocalStorage.min.cjs diff --git a/src/lib/xdLocalStoragePostMessageApi.min.js b/src/lib/xdLocalStoragePostMessageApi.min.cjs similarity index 100% rename from src/lib/xdLocalStoragePostMessageApi.min.js rename to src/lib/xdLocalStoragePostMessageApi.min.cjs diff --git a/src/manifest.mjs b/src/manifest.js similarity index 100% rename from src/manifest.mjs rename to src/manifest.js diff --git a/src/scripts/contentscript.js b/src/scripts/contentscript.js index 67b129a..5151fee 100644 --- a/src/scripts/contentscript.js +++ b/src/scripts/contentscript.js @@ -54,7 +54,7 @@ async function load() { Utils.injectScript("lib/init.js"); setupStorage(); - require("./contentScriptPortal"); + await import("./contentScriptPortal"); if (matricula_url.some((url) => currentUrl.indexOf(url) != -1)) { // update teachers locally diff --git a/src/services/NextAPI.js b/src/services/NextAPI.js index c9fafa9..70c1a01 100644 --- a/src/services/NextAPI.js +++ b/src/services/NextAPI.js @@ -10,7 +10,7 @@ function resolveEndpoint(env) { ); } -function NextAPI() { +export function NextAPI() { const baseURL = resolveEndpoint(process.env.NODE_ENV); const REQUEST_TIMEOUT = 5000; const nextAPI = Axios.create({ @@ -24,7 +24,3 @@ function NextAPI() { return nextAPI; } - -module.exports = { - NextAPI, -}; diff --git a/src/services/NextStorage.mjs b/src/services/NextStorage.js similarity index 100% rename from src/services/NextStorage.mjs rename to src/services/NextStorage.js diff --git a/src/utils/Matricula.js b/src/utils/Matricula.js index 04cbf22..94ac196 100644 --- a/src/utils/Matricula.js +++ b/src/utils/Matricula.js @@ -1,14 +1,12 @@ import Axios from "axios"; import { NextAPI } from "../services/NextAPI"; -import toJSON from "./toJSON"; +import { toJSON } from "./toJSON"; import _ from "lodash"; import $ from "jquery"; import Utils from "./extensionUtils"; const nextApi = NextAPI(); -module.exports = new Matricula(); - function Matricula() { const MATRICULAS_URL = { @@ -154,3 +152,5 @@ function Matricula() { sendAlunoData, }; } + +export default new Matricula(); diff --git a/src/utils/convertUfabcDisciplina.js b/src/utils/convertUfabcDisciplina.js index f308eb6..4284909 100644 --- a/src/utils/convertUfabcDisciplina.js +++ b/src/utils/convertUfabcDisciplina.js @@ -1,8 +1,8 @@ -const _ = require("lodash"); -const removeDiacritics = require("./removeDiacritics"); +import _ from "lodash"; +import removeDiacritics from "./removeDiacritics"; // This convert an disciplina from the .json from matriculas.ufabc -function convertDisciplina(d) { +export function convertDisciplina(d) { const obj = _.defaults(_.clone(d)); // specific for .json @@ -114,7 +114,3 @@ function extractCampus(d) { return null; } - -module.exports = { - convertDisciplina, -}; diff --git a/src/utils/disciplinaIdentifier.js b/src/utils/disciplinaIdentifier.js index b8b4f1b..2640edf 100644 --- a/src/utils/disciplinaIdentifier.js +++ b/src/utils/disciplinaIdentifier.js @@ -1,4 +1,4 @@ -import { createHash } from "crypto"; +import { createHash } from "node:crypto"; import _ from "lodash"; const DEFAULT_FIELDS_TO_ENCODE = ["disciplina", "turno", "campus", "turma"]; @@ -6,7 +6,10 @@ const DEFAULT_FIELDS_TO_ENCODE = ["disciplina", "turno", "campus", "turma"]; /** * Generates a unique identifier for a given disciplina * */ -function generateIdentifier(disciplina, keys = DEFAULT_FIELDS_TO_ENCODE) { +export function generateIdentifier( + disciplina, + keys = DEFAULT_FIELDS_TO_ENCODE +) { const unorderedDisciplinas = keys.map((key) => String(disciplina[key])); const disciplinaToEncode = unorderedDisciplinas .map((disciplina) => _.camelCase(disciplina)) @@ -14,7 +17,3 @@ function generateIdentifier(disciplina, keys = DEFAULT_FIELDS_TO_ENCODE) { return createHash("md5").update(disciplinaToEncode).digest("hex"); } - -module.exports = { - generateIdentifier, -}; diff --git a/src/utils/extensionUtils.js b/src/utils/extensionUtils.js index 0a30cf5..0657e3d 100644 --- a/src/utils/extensionUtils.js +++ b/src/utils/extensionUtils.js @@ -3,8 +3,6 @@ import Axios from "axios"; import is from "is_js"; import _ from "lodash"; -module.exports = new ExtensionUtils(); - function ExtensionUtils() { // force initialization of xdLocalStorage // window.xdLocalStorage.init({ @@ -131,3 +129,5 @@ function ExtensionUtils() { storage, }; } + +export default new ExtensionUtils(); diff --git a/src/utils/removeDiacritics.js b/src/utils/removeDiacritics.js index 6989bdf..73ced50 100644 --- a/src/utils/removeDiacritics.js +++ b/src/utils/removeDiacritics.js @@ -109,8 +109,8 @@ } // "what?" version ... http://jsperf.com/diacritics/12 - module.exports = function removeDiacritics (str) { - return str.replace(/[^\u0000-\u007E]/g, function(a){ - return diacriticsMap[a] || a; + export default function removeDiacritics (str) { + return str.replace(/[^\u0000-\u007E]/g, function(a){ + return diacriticsMap[a] || a; }); - } \ No newline at end of file + } diff --git a/src/utils/season.js b/src/utils/season.js index d07483b..d680b2b 100644 --- a/src/utils/season.js +++ b/src/utils/season.js @@ -10,7 +10,7 @@ function findQuadFromDate(month) { } } -function findSeason(date = new Date()) { +export function findSeason(date = new Date()) { const month = date.getMonth(); return { 1: { @@ -28,12 +28,12 @@ function findSeason(date = new Date()) { }[findQuadFromDate(date.getMonth() || month)]; } -function findSeasonKey(date) { +export function findSeasonKey(date) { const { year, quad } = findSeason(date); return `${year}:${quad}`; } -function findIdeais(date) { +export function findIdeais(date) { return { 1: [ "BCM0506-15", // COMUNICACAO E REDES @@ -76,9 +76,3 @@ function findIdeais(date) { ], }[findQuadFromDate(date || new Date().getMonth())]; } - -module.exports = { - findSeason, - findSeasonKey, - findIdeais, -}; diff --git a/src/utils/setupStorage.js b/src/utils/setupStorage.js index f90fd93..301ec93 100644 --- a/src/utils/setupStorage.js +++ b/src/utils/setupStorage.js @@ -1,4 +1,4 @@ -function setupStorage() { +export function setupStorage() { document.addEventListener("requestStorage", (event) => { const key = event.detail.key; const date = event.detail.date; @@ -63,7 +63,3 @@ function setupStorage() { } }); } - -module.exports = { - setupStorage, -}; diff --git a/src/utils/setupStorageESM.mjs b/src/utils/setupStorageESM.mjs deleted file mode 100644 index 5d3268c..0000000 --- a/src/utils/setupStorageESM.mjs +++ /dev/null @@ -1,39 +0,0 @@ -// will only support chrome storage for now -export function setupStorageESM() { - document.addEventListener("requestStorage", (event) => { - const key = event.detail.key; - const date = event.detail.date; - const value = event.detail.value; - const method = event.detail.method.split("-")[0]; - const eventType = event.type; - if (!key || !date || !method || eventType != "requestStorage") return; - - const eventMethod = event.detail.method; - - console.log(`[${method} | ${key}] Using chrome.storage 🔵`); - // maybe below is actually resolve(data && data[key]) - please check - - if (method == "setStorage") { - chrome.storage.local.set({ [key]: value }); - return document.dispatchEvent( - new CustomEvent(eventMethod, { - detail: { - key: key, - value: value, - }, - }) - ); - } else if (method == "getStorage") { - return chrome.storage.local.get(key, (data) => { - document.dispatchEvent( - new CustomEvent(eventMethod, { - detail: { - key: key, - value: data && data[key], - }, - }) - ); - }); - } - }); -} diff --git a/src/utils/toJSON.js b/src/utils/toJSON.js index 56f5bd2..cd1862a 100644 --- a/src/utils/toJSON.js +++ b/src/utils/toJSON.js @@ -1,6 +1,6 @@ import _ from "lodash"; -const toJSON = (payload, max) => { +export function toJSON(payload, max) { const json = JSON.parse( _.get(new RegExp(/^\w*=(.*)/).exec(payload), "[1]", {}) ); @@ -10,8 +10,4 @@ const toJSON = (payload, max) => { } return json; -}; - -module.exports = { - toJSON, -}; +} diff --git a/src/views/Popup/Popup.vue b/src/views/Popup/Popup.vue index 0cc9d78..5579433 100644 --- a/src/views/Popup/Popup.vue +++ b/src/views/Popup/Popup.vue @@ -81,9 +81,9 @@