diff options
| author | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 23:17:25 +0530 |
|---|---|---|
| committer | Arpit Chakladar <arpitchakladar+git@gmail.com> | 2026-07-13 23:17:25 +0530 |
| commit | 68777ec421d41be0da27013afd4165ae7d658d26 (patch) | |
| tree | 4c1cc6af7acfeac54b2e54372944344d3f5b9a26 /config/webpack | |
| parent | 20c3b38f24d79df8843f17985a7d13533d4e0d10 (diff) | |
| download | banglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.tar.gz banglar-bhumi-utils-68777ec421d41be0da27013afd4165ae7d658d26.zip | |
refactor: added linting with esling and also resolved warnings for it
Diffstat (limited to 'config/webpack')
10 files changed, 38 insertions, 31 deletions
diff --git a/config/webpack/loader/arrange-shared-module-loader.js b/config/webpack/loader/arrange-shared-module-loader.js index d4c22a9..31c5d61 100644 --- a/config/webpack/loader/arrange-shared-module-loader.js +++ b/config/webpack/loader/arrange-shared-module-loader.js @@ -1,4 +1,5 @@ import path from "path"; + import { ImportManager } from "import-manager"; import sharedModules from "../utils/shared-modules.js"; diff --git a/config/webpack/loader/count-imports-loader.js b/config/webpack/loader/count-imports-loader.js index 3342921..ef832bf 100644 --- a/config/webpack/loader/count-imports-loader.js +++ b/config/webpack/loader/count-imports-loader.js @@ -1,4 +1,5 @@ import { ImportManager } from "import-manager"; + import sharedModules from "../utils/shared-modules.js"; /** diff --git a/config/webpack/loader/to-string-loader.js b/config/webpack/loader/to-string-loader.js index 244ae7a..025ea5e 100644 --- a/config/webpack/loader/to-string-loader.js +++ b/config/webpack/loader/to-string-loader.js @@ -11,7 +11,7 @@ export default function(source) { source = source .replaceAll("\\", "\\\\") - .replaceAll("`","\\`") + .replaceAll("`", "\\`") .replaceAll("${", "\\${"); const replacements = {}; diff --git a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js index 21cff34..6cd8523 100644 --- a/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js +++ b/config/webpack/plugins/create-injected-shared-modules-webpack-plugin.js @@ -1,4 +1,5 @@ import path from "path"; + import webpack from "webpack"; import { getFileName } from "../utils/build-file.js"; @@ -22,7 +23,7 @@ class CreateInjectedSharedModulesPlugin { * @param {import("webpack").Compiler} compiler */ apply(compiler) { - compiler.hooks.compilation.tap("CreateInjectedSharedModulesPlugin", compilation => { + compiler.hooks.compilation.tap("CreateInjectedSharedModulesPlugin", (compilation) => { compilation.hooks.processAssets.tap( { name: "CreateInjectedSharedModulesPlugin", @@ -30,13 +31,13 @@ class CreateInjectedSharedModulesPlugin { }, (_assets) => { const injectedSharedScripts = this.sortedSharedModules - .filter(sharedModule => this.injectedSharedModulesImportedCount[sharedModule] > 0) - .map(sharedModule => `shared/${getFileName(sharedModule, "shared")}.js`); + .filter((sharedModule) => this.injectedSharedModulesImportedCount[sharedModule] > 0) + .map((sharedModule) => `shared/${getFileName(sharedModule, "shared")}.js`); if (injectedSharedScripts.length > 0) { const scriptInjectorModuleName = getFileName("script-injector", "shared", true); const injectionCode = injectedSharedScripts - .map(injectedScript => `$${scriptInjectorModuleName}.injectScriptHead("shared/${path.basename(injectedScript)}");`) + .map((injectedScript) => `$${scriptInjectorModuleName}.injectScriptHead("shared/${path.basename(injectedScript)}");`) .join(""); compilation.emitAsset( `shared/${getFileName("injected-shared-modules", "shared")}.js`, diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js index 7328d5d..f5a4963 100644 --- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js +++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js @@ -1,14 +1,16 @@ -import webpack from "webpack"; -import path from "path"; import fs from "fs"; +import path from "path"; + +import webpack from "webpack"; -import { getScriptRuntimeFromType } from "../../utils/script-runtime.js"; import { getFileName } from "../../utils/build-file.js"; +import { getScriptRuntimeFromType } from "../../utils/script-runtime.js"; import scripts from "../../utils/scripts.js"; + const manifest = JSON.parse( fs.readFileSync( - path.resolve("config/webpack/plugins/create-manifest-webpack-plugin/manifest-template.json"), - ), + path.resolve("config/webpack/plugins/create-manifest-webpack-plugin/manifest-template.json") + ) ); /** @@ -44,7 +46,7 @@ class CreateManifestPlugin { name: "CreateManifestPlugin", stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL }, - assets => { + (assets) => { manifest.version = JSON.parse(fs.readFileSync((path.resolve(ROOT_DIR, "package.json")))).version; manifest.content_scripts = []; let resources = []; @@ -69,12 +71,12 @@ class CreateManifestPlugin { } manifest.content_scripts.push({ - matches: [`*://banglarbhumi.gov.in/BanglarBhumi/*`], + matches: ["*://banglarbhumi.gov.in/BanglarBhumi/*"], js: this.sortedSharedModules - .filter(sharedModule => this.sharedModulesImportedCount[sharedModule] > 0) - .map(sharedModule => `shared/${getFileName(sharedModule, "shared")}.js`) + .filter((sharedModule) => this.sharedModulesImportedCount[sharedModule] > 0) + .map((sharedModule) => `shared/${getFileName(sharedModule, "shared")}.js`) .concat(arrangedScripts["*"]["document_start"]) - .filter(x => x != null), + .filter((x) => x != null), run_at: "document_start" }); @@ -102,8 +104,8 @@ class CreateManifestPlugin { } const injectedSharedModules = this.sortedSharedModules - .filter(sharedModule => this.injectedSharedModulesImportedCount[sharedModule] > 0) - .map(sharedModule => `shared/${getFileName(sharedModule, "shared")}.js`); + .filter((sharedModule) => this.injectedSharedModulesImportedCount[sharedModule] > 0) + .map((sharedModule) => `shared/${getFileName(sharedModule, "shared")}.js`); if (injectedSharedModules.length > 0) { resources = resources.concat(injectedSharedModules); diff --git a/config/webpack/plugins/create-rules-webpack-plugin.js b/config/webpack/plugins/create-rules-webpack-plugin.js index 993ac31..10e5fdd 100644 --- a/config/webpack/plugins/create-rules-webpack-plugin.js +++ b/config/webpack/plugins/create-rules-webpack-plugin.js @@ -1,5 +1,6 @@ -import path from "path"; import fs from "fs"; +import path from "path"; + import webpack from "webpack"; /** @@ -12,7 +13,7 @@ class CreateRulesPlugin { * @param {import("webpack").Compiler} compiler */ apply(compiler) { - compiler.hooks.compilation.tap("CreateRulesPlugin", compilation => { + compiler.hooks.compilation.tap("CreateRulesPlugin", (compilation) => { compilation.hooks.processAssets.tap( { name: "CreateRulesPlugin", diff --git a/config/webpack/plugins/inject-script-webpack-plugin.js b/config/webpack/plugins/inject-script-webpack-plugin.js index 4f76ca8..0a5d784 100644 --- a/config/webpack/plugins/inject-script-webpack-plugin.js +++ b/config/webpack/plugins/inject-script-webpack-plugin.js @@ -1,6 +1,7 @@ -import webpack from "webpack"; import path from "path"; +import webpack from "webpack"; + import { getFileName } from "../utils/build-file.js"; import { getInjectedCode } from "../utils/injected-code.js"; @@ -15,17 +16,17 @@ class InjectScriptPlugin { * @param {import("webpack").Compiler} compiler */ apply(compiler) { - compiler.hooks.compilation.tap("InjectScriptPlugin", compilation => { + compiler.hooks.compilation.tap("InjectScriptPlugin", (compilation) => { compilation.hooks.processAssets.tapPromise( { name: "InjectScriptPlugin", stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL, additionalAssets: true }, - async (assets) => { + async(assets) => { for (const assetName in assets) { if (/\.js$/.test(assetName)) { - const injectedCodeResponse = getInjectedCode(compilation.getAsset(assetName).source.source()) + const injectedCodeResponse = getInjectedCode(compilation.getAsset(assetName).source.source()); const scriptInjectorModuleName = getFileName("script-injector", "shared", true); compilation.updateAsset( assetName, diff --git a/config/webpack/utils/injected-code.js b/config/webpack/utils/injected-code.js index f91fd4a..f2e51c8 100644 --- a/config/webpack/utils/injected-code.js +++ b/config/webpack/utils/injected-code.js @@ -7,7 +7,7 @@ import crypto from "crypto"; * @param {string} url - The URL to hash. * @returns {string} A 16-character hex hash. */ -const getHash = url => +const getHash = (url) => crypto .createHash("md5") .update(url) @@ -50,7 +50,7 @@ export function getInjectedCode(code) { } const extensionAssetsCode = Object.entries(extensionAssets).map( - asset => `"${asset[0]}": chrome.runtime.getURL("${asset[1]}")` + (asset) => `"${asset[0]}": chrome.runtime.getURL("${asset[1]}")` ).join(","); return [code, `{${extensionAssetsCode}}`]; diff --git a/config/webpack/utils/scripts.js b/config/webpack/utils/scripts.js index 09a2fc0..d5a0cdc 100644 --- a/config/webpack/utils/scripts.js +++ b/config/webpack/utils/scripts.js @@ -1,5 +1,5 @@ -import path from "path"; import fs from "fs"; +import path from "path"; /** * Reads `src/scripts.json` and re-indexes it so the outer key is the @@ -11,8 +11,8 @@ import fs from "fs"; */ const scripts = JSON.parse( fs.readFileSync( - path.resolve("./src/scripts.json"), - ), + path.resolve("./src/scripts.json") + ) ); const formattedScripts = {}; diff --git a/config/webpack/utils/shared-modules.js b/config/webpack/utils/shared-modules.js index 74ee555..c9c9618 100644 --- a/config/webpack/utils/shared-modules.js +++ b/config/webpack/utils/shared-modules.js @@ -1,5 +1,5 @@ -import path from "path"; import fs from "fs"; +import path from "path"; /** * Scans `src/shared/` and returns the list of shared module filenames @@ -8,5 +8,5 @@ import fs from "fs"; * @returns {string[]} e.g. `["generate-web-page", "intercept-jquery-ajax", …]` */ export default fs.readdirSync(path.resolve("src/shared")) - .filter(sharedModule => !sharedModule.endsWith("import-shared.js")) - .map(sharedModule => sharedModule.substring(0, sharedModule.length - 3)); + .filter((sharedModule) => !sharedModule.endsWith("import-shared.js")) + .map((sharedModule) => sharedModule.substring(0, sharedModule.length - 3)); |
