aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-10 11:18:26 +0530
committerArpit Chakladar <54011232+arpitchakladar@users.noreply.github.com>2023-02-10 11:18:26 +0530
commit5bee39d850e42743c2396f2a1eb2891a8c7e3ff9 (patch)
tree096d3d49ffc252da5b564e6cf7ba72d4d25fc63a
parente674c14b08faae4fb2cb0ebf3c17029667af3c42 (diff)
downloadbanglar-bhumi-utils-5bee39d850e42743c2396f2a1eb2891a8c7e3ff9.tar.gz
banglar-bhumi-utils-5bee39d850e42743c2396f2a1eb2891a8c7e3ff9.zip
Using global object instead of process.env for common directory paths.
-rw-r--r--config/webpack.config.js20
-rw-r--r--config/webpack/loaders/scoped-loader.js2
-rw-r--r--config/webpack/plugins/create-manifest-webpack-plugin/index.js6
-rw-r--r--src/scripts/block-unnecessary.ts3
4 files changed, 16 insertions, 15 deletions
diff --git a/config/webpack.config.js b/config/webpack.config.js
index 2ff2059..aaee2f0 100644
--- a/config/webpack.config.js
+++ b/config/webpack.config.js
@@ -1,11 +1,11 @@
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
-process.env.ROOT_DIR = path.resolve(__dirname, "..");
-process.env.CONFIG_DIR = path.resolve(process.env.ROOT_DIR, "config");
-process.env.SOURCE_DIR = path.resolve(process.env.ROOT_DIR, "src");
+global.ROOT_DIR = path.resolve(__dirname, "..");
+global.CONFIG_DIR = path.resolve(ROOT_DIR, "config");
+global.SOURCE_DIR = path.resolve(ROOT_DIR, "src");
-global.webpackRequire = modulePath => require(path.resolve(process.env.CONFIG_DIR, "webpack", modulePath));
+global.webpackRequire = modulePath => require(path.resolve(CONFIG_DIR, "webpack", modulePath));
const CreateManifestPlugin = webpackRequire("plugins/create-manifest-webpack-plugin");
const SanitizeScriptsImportPlugin = webpackRequire("plugins/sanitize-scripts-import-webpack-plugin");
@@ -15,7 +15,7 @@ const { inlineJavascript } = webpackRequire("utils/inline-javascript");
const { getScriptRuntimeFromType } = webpackRequire("utils/script-runtime");
const { getFileNameHash } = webpackRequire("utils/file-name-hash");
-const scripts = require(path.resolve(process.env.SOURCE_DIR, "scripts.json"));
+const scripts = require(path.resolve(SOURCE_DIR, "scripts.json"));
const entries = {};
@@ -33,7 +33,7 @@ for (const scriptRuntime in _scripts) {
for (const script in scripts) {
const scriptPath = scripts[script];
entries[`${scriptRuntime} - "${scriptPath}"`] = {
- import: inlineJavascript(Object.keys(scripts).map(script => `import "${path.resolve(process.env.SOURCE_DIR, "scripts", script)}";`).join("\n")),
+ import: inlineJavascript(Object.keys(scripts).map(script => `import "${path.resolve(SOURCE_DIR, "scripts", script)}";`).join("\n")),
filename: `scripts/${getFileNameHash(scriptPath)}/${scriptRuntime}.js`
};
}
@@ -45,7 +45,7 @@ module.exports = {
resolve: {
extensions: ["", ".ts", ".js"],
alias: {
- "@": process.env.SOURCE_DIR
+ "@": global.SOURCE_DIR
}
},
module: {
@@ -58,8 +58,8 @@ module.exports = {
}
},
{
- test: new RegExp(`^${path.resolve(process.env.SOURCE_DIR, "scripts")}`),
- loader: path.resolve(process.env.CONFIG_DIR, "webpack/loaders/scoped-loader")
+ test: new RegExp(`^${path.resolve(SOURCE_DIR, "scripts")}`),
+ loader: path.resolve(CONFIG_DIR, "webpack/loaders/scoped-loader")
}
]
},
@@ -68,7 +68,7 @@ module.exports = {
new InjectScriptPlugin(),
new CopyPlugin({
patterns: [{
- from: path.resolve(process.env.ROOT_DIR, "static"),
+ from: path.resolve(ROOT_DIR, "static"),
to: "./"
}]
}),
diff --git a/config/webpack/loaders/scoped-loader.js b/config/webpack/loaders/scoped-loader.js
index 1be58a4..c2f9636 100644
--- a/config/webpack/loaders/scoped-loader.js
+++ b/config/webpack/loaders/scoped-loader.js
@@ -1,6 +1,6 @@
const path = require("path");
-const scripts = require(path.resolve(process.env.SOURCE_DIR, "scripts.json"));
+const scripts = require(path.resolve(SOURCE_DIR, "scripts.json"));
const getScriptType = scriptName => {
for (const scriptType in scripts) {
diff --git a/config/webpack/plugins/create-manifest-webpack-plugin/index.js b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
index 2e121da..7852d62 100644
--- a/config/webpack/plugins/create-manifest-webpack-plugin/index.js
+++ b/config/webpack/plugins/create-manifest-webpack-plugin/index.js
@@ -1,16 +1,16 @@
const { sources } = require("webpack");
const path = require("path");
-const scripts = require(path.resolve(process.env.SOURCE_DIR, "scripts.json"));
+const scripts = require(path.resolve(SOURCE_DIR, "scripts.json"));
-const { version } = require(path.resolve(process.env.ROOT_DIR, "package.json"));
+const { version } = require(path.resolve(ROOT_DIR, "package.json"));
const { getScriptRuntimeFromType } = webpackRequire("utils/script-runtime");
const { getFileNameHash } = webpackRequire("utils/file-name-hash");
class CreateManifestPlugin {
constructor() {
this.scripts = {};
- this.manifest = require("./manifest-template.json");
+ this.manifest = webpackRequire("plugins/create-manifest-webpack-plugin/manifest-template.json");
for (const scriptType in scripts) {
const scriptRuntime = getScriptRuntimeFromType(scriptType);
this.scripts[scriptRuntime] = { ...this.scripts[scriptRuntime], ...scripts[scriptType] };
diff --git a/src/scripts/block-unnecessary.ts b/src/scripts/block-unnecessary.ts
index bec90a5..65d610a 100644
--- a/src/scripts/block-unnecessary.ts
+++ b/src/scripts/block-unnecessary.ts
@@ -4,7 +4,7 @@ let replace: (any[] | undefined)[] = [
["head > script:nth-child(43)", { src: "" }]
];
let count = 0;
-let notDone = false;
+let notDone = true;
const observer = new MutationObserver(() => {
if (notDone) {
@@ -12,6 +12,7 @@ const observer = new MutationObserver(() => {
if (meta) {
meta.setAttribute("http-equiv", "Content-Security-Policy");
meta.setAttribute("content", "default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *");
+ notDone = false;
}
}
for (let i = 0; i < replace.length; i++) {