Skip to content

Commit

Permalink
fix: imports error and webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
Teyk0o committed Nov 25, 2024
1 parent 5ebf132 commit f5bfcf1
Show file tree
Hide file tree
Showing 13 changed files with 2,602 additions and 101 deletions.
2,434 changes: 2,400 additions & 34 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 27 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@
],
"scripts": {
"clean": "rimraf dist dist-scripts",
"build:ts": "tsc",
"build:scripts": "tsc -p scripts/tsconfig.json",
"copy-static": "copyfiles -u 1 \"src/**/*.{json,png,svg,html,css}\" dist",
"build": "npm run clean && npm run build:ts && npm run copy-static",
"release": "tsx scripts/release.ts",
"release:no-git": "tsx scripts/release.ts",
"release:patch": "tsx scripts/release.ts patch",
"release:patch:no-git": "tsx scripts/release.ts patch --no-git",
"release:patch:skip-build": "tsx scripts/release.ts patch --no-git --skip-build",
"release:minor": "tsx scripts/release.ts minor",
"release:minor:no-git": "tsx scripts/release.ts minor --no-git",
"release:major": "tsx scripts/release.ts major",
"release:major:no-git": "tsx scripts/release.ts major --no-git",
"upload-only": "tsx scripts/release.ts patch --no-git --skip-build --upload-only",
"build": "webpack --mode=production",
"build:scripts": "webpack --config webpack.config.js --mode=production --env target=node-scripts",
"build:extension": "webpack --config webpack.config.js --mode=production --env target=extension",
"dev": "webpack --watch --mode=development --env target=extension",
"start": "web-ext run --source-dir ./dist/",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"lint:check": "eslint . --max-warnings 0"
"lint:check": "eslint . --max-warnings 0",
"package": "web-ext build --source-dir ./dist/",
"release": "node dist-scripts/release.js",
"release:no-git": "node dist-scripts/release.js patch --no-git",
"release:patch": "node dist-scripts/release.js patch",
"release:minor": "node dist-scripts/release.js minor",
"release:major": "node dist-scripts/release.js major"
},
"author": "",
"license": "ISC",
Expand All @@ -41,17 +38,32 @@
"@types/firefox-webext-browser": "^120.0.4",
"@types/node": "^20.10.0",
"@types/node-fetch": "^2.6.9",
"assert": "^2.1.0",
"buffer": "^6.0.3",
"copy-webpack-plugin": "^12.0.2",
"copyfiles": "^2.4.1",
"crypto-browserify": "^3.12.1",
"dotenv": "^16.4.5",
"eslint": "^9.15.0",
"form-data": "^4.0.0",
"globals": "^15.12.0",
"https-browserify": "^1.0.0",
"node-fetch": "^3.3.2",
"os-browserify": "^0.3.0",
"path-browserify": "^1.0.1",
"process": "^0.11.10",
"rimraf": "^6.0.1",
"stream-browserify": "^3.0.0",
"stream-http": "^3.2.0",
"terser-webpack-plugin": "^5.3.10",
"ts-loader": "^9.5.1",
"tsx": "^4.7.1",
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0",
"util": "^0.12.5",
"web-ext": "^7.8.0",
"webpack": "^5.96.1",
"webpack-cli": "^5.1.4",
"zx": "^7.2.3"
}
}
1 change: 0 additions & 1 deletion scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Description: TypeScript configuration for scripts, do not use this file for the main project and don't touch it.
{
"compilerOptions": {
"target": "ES2020",
Expand Down
4 changes: 1 addition & 3 deletions src/modules/mentions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { handleGlobalClick, handleInput, handleKeyDownGlobal } from "./mentions/event.handler.js";


import { handleGlobalClick, handleInput, handleKeyDownGlobal } from "./mentions/event.handler";

/**
* Initialize the mentions system by setting up event listeners
Expand Down
8 changes: 6 additions & 2 deletions src/modules/mentions/event.handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import suggestionBoxElem from "../suggestion/suggestionBox.element.js";
import { hideSuggestions, searchAndShowSuggestions, selectSuggestion } from "../suggestion/suggestionBox.module.js";
import suggestionBoxElem from "../suggestion/suggestionBox.element";
import {
hideSuggestions,
searchAndShowSuggestions,
selectSuggestion
} from "../suggestion/suggestionBox.module";

/**
* Handle keydown events on the input field
Expand Down
13 changes: 6 additions & 7 deletions src/modules/mentions/mention.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getActualUserName } from "../users/user.module.js";
import { getActualUserName } from "../users/user.module";

export function addClassMention(message: HTMLElement) {
// Add special styling class
Expand All @@ -7,9 +7,8 @@ export function addClassMention(message: HTMLElement) {
}

export function checkForMentions(message: HTMLElement, textContent: string | null) {
const actualUserName = getActualUserName();
if (textContent?.includes(`@${actualUserName}`)) {
addClassMention(message);
}
}

const actualUserName = getActualUserName();
if (textContent?.includes(`@${actualUserName}`)) {
addClassMention(message);
}
}
38 changes: 19 additions & 19 deletions src/modules/moderators/moderator.module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
export function checkForModeratorMessages(message: HTMLElement) {
if (message.hasAttribute('moderator-checked')) {
return;
}
message.setAttribute('moderator-checked', 'true');
if (message.hasAttribute('moderator-checked')) {
return;
}
message.setAttribute('moderator-checked', 'true');

// Look for moderator avatar
const moderatorAvatar = message.querySelector('[data-test="moderatorAvatar"]');
if (moderatorAvatar) {
addClassModerator(message);
}
// Look for moderator avatar
const moderatorAvatar = message.querySelector('[data-test="moderatorAvatar"]');
if (moderatorAvatar) {
addClassModerator(message);
}
}

export function addClassModerator(message: HTMLElement) {
// Add special styling class
message.classList.add('moderator-message');
// Add special styling class
message.classList.add('moderator-message');

// Add MOD badge
const username = message.querySelector('.sc-lmONJn span');
if (username && !username.querySelector('.moderator-badge')) {
const badge = document.createElement('span');
badge.className = 'moderator-badge';
badge.textContent = 'MOD';
username.appendChild(badge);
}
// Add MOD badge
const username = message.querySelector('.sc-lmONJn span');
if (username && !username.querySelector('.moderator-badge')) {
const badge = document.createElement('span');
badge.className = 'moderator-badge';
badge.textContent = 'MOD';
username.appendChild(badge);
}
}
5 changes: 2 additions & 3 deletions src/modules/question/question.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
export function addClassQuestion(message: HTMLElement) {
const messageContainer = message.closest('.sc-leYdVB');
// Add highlight class if not already present
messageContainer
&& !messageContainer.classList.contains('question-highlight')
messageContainer
&& !messageContainer.classList.contains('question-highlight')
&& messageContainer.classList.add('question-highlight');

}

export function checkForQuestions(message: HTMLElement, textContent: string | null) {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/suggestion/suggestionBox.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getCachedUsers } from "../users/user.module.js";
import suggestionBoxElem from "./suggestionBox.element.js";
import { getCachedUsers } from "../users/user.module";
import suggestionBoxElem from "./suggestionBox.element";

/**
* Hide the suggestion box
Expand Down
2 changes: 1 addition & 1 deletion src/modules/users/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { User } from '../../../types/user.js';
import type { User } from '../../../types/user';
const CACHE_DURATION = 3000;

/**
Expand Down
8 changes: 3 additions & 5 deletions src/utils/observer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkForMentions } from "../modules/mentions/mention.module.js";
import { checkForModeratorMessages } from "../modules/moderators/moderator.module.js";
import { checkForQuestions } from "../modules/question/question.module.js";
import { checkForMentions } from "../modules/mentions/mention.module";
import { checkForModeratorMessages } from "../modules/moderators/moderator.module";
import { checkForQuestions } from "../modules/question/question.module";

export const observer = new MutationObserver((mutations) => {
for (const mutation of mutations) {
Expand All @@ -12,7 +12,6 @@ export const observer = new MutationObserver((mutations) => {


export function checkNewMessages() {
console.log('[WWSNB] Start checking new messages for questions');
// Get all messages using data-test attribute
const messages = document.querySelectorAll('[data-test="chatUserMessageText"]') as unknown as HTMLElement[];

Expand All @@ -30,6 +29,5 @@ export function checkNewMessages() {


}
console.log('[WWSNB] New messages checked');

}
15 changes: 6 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"compilerOptions": {
"target": "ES2021",
"module": "NodeNext",
"module": "ESNext",
"moduleResolution": "Bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "NodeNext",
"moduleDetection": "force",
"allowImportingTsExtensions": false,
"resolveJsonModule": true,
"isolatedModules": true,
Expand All @@ -19,7 +18,8 @@
"@/*": ["./*"]
},
"lib": ["DOM", "ES2021"],
"types": ["firefox-webext-browser"]
"types": ["firefox-webext-browser"],
"sourceMap": true
},
"include": [
"src/**/*.ts",
Expand All @@ -28,10 +28,7 @@
"exclude": [
"node_modules",
"dist",
"scripts",
"web-ext-artifacts"
],
"ts-node": {
"esm": true,
"experimentalSpecifierResolution": "node"
}
]
}
129 changes: 129 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
import path from 'path';
import { fileURLToPath } from 'url';
import CopyPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Configuration de base
const baseConfig = {
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@': path.resolve(__dirname, 'src/')
}
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
pure_funcs: [], // Ne pas retirer les console.log
drop_console: false, // Garder les console.log
},
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
};

// Configuration pour l'extension web
const extensionConfig = {
...baseConfig,
name: 'extension',
target: 'web',
entry: {
content: './src/content.ts'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
clean: {
keep: /icons|styles|manifest\.json/
}
},
plugins: [
new CopyPlugin({
patterns: [
{
from: "src/styles",
to: "styles"
},
{
from: "icons",
to: "icons"
},
{
from: "manifest.json",
to: "manifest.json",
transform(content) {
const manifest = JSON.parse(content);
manifest.content_scripts[0].js = ['content.js'];
manifest.content_scripts[0].css = ['styles/styles.css'];
return JSON.stringify(manifest, null, 2);
}
}
],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
Buffer: ['buffer', 'Buffer']
})
],
devtool: 'source-map',
resolve: {
...baseConfig.resolve,
fallback: {
"path": 'path-browserify',
"fs": false,
"crypto": 'crypto-browserify',
"buffer": 'buffer',
"stream": 'stream-browserify',
"util": 'util',
"url": 'url',
"assert": 'assert',
"http": 'stream-http',
"https": 'https-browserify',
"os": 'os-browserify/browser',
"process": 'process/browser'
}
}
};

// Configuration pour les scripts Node
const nodeConfig = {
...baseConfig,
name: 'node-scripts',
target: 'node',
entry: {
release: './scripts/release.ts'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist-scripts'),
clean: true
},
externals: {
'zx': 'commonjs zx',
'node-fetch': 'commonjs node-fetch',
'form-data': 'commonjs form-data'
}
};

export default [extensionConfig, nodeConfig];

0 comments on commit f5bfcf1

Please sign in to comment.