From bc3e9431cb240c08b8e4c1a5b1e8b4ff9f6c8f70 Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Fri, 6 Oct 2023 12:10:08 +0100 Subject: [PATCH 1/6] increase max-old-space-size value for postbuild --- package.json | 2 +- scripts/old_space_size.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 scripts/old_space_size.sh diff --git a/package.json b/package.json index 3c7d7cf6f..3eb77a9de 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lint": "yarn flow", "start": "unset HOST && react-scripts start", "build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build", - "postbuild": "node scripts/patchUrls.js", + "postbuild": "./scripts/old_space_size.sh && export NODE_OPTIONS=--max-old-space-size=8192 && node scripts/patchUrls.js", "ppostbuild": "react-snap", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/scripts/old_space_size.sh b/scripts/old_space_size.sh new file mode 100644 index 000000000..c5ef11b7d --- /dev/null +++ b/scripts/old_space_size.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +node -e 'console.log(`*** NODE HEAP LIMIT = ${require("v8").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)' From 51845c463f4d5f23c9855d7d2c9784d98badf85d Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Fri, 6 Oct 2023 12:38:40 +0100 Subject: [PATCH 2/6] remove recently adde unneeded script --- package.json | 2 +- scripts/old_space_size.sh | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 scripts/old_space_size.sh diff --git a/package.json b/package.json index 3eb77a9de..16b4c67b0 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lint": "yarn flow", "start": "unset HOST && react-scripts start", "build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build", - "postbuild": "./scripts/old_space_size.sh && export NODE_OPTIONS=--max-old-space-size=8192 && node scripts/patchUrls.js", + "postbuild": "export NODE_OPTIONS=--max-old-space-size=8192 && node scripts/patchUrls.js", "ppostbuild": "react-snap", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/scripts/old_space_size.sh b/scripts/old_space_size.sh deleted file mode 100644 index c5ef11b7d..000000000 --- a/scripts/old_space_size.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -node -e 'console.log(`*** NODE HEAP LIMIT = ${require("v8").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)' From 6edf235bbf1f915f84ddd32b9ae1df4c32392e6f Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Mon, 9 Oct 2023 15:28:59 +0100 Subject: [PATCH 3/6] add some test code --- package.json | 2 +- scripts/node_heap_size.sh | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100755 scripts/node_heap_size.sh diff --git a/package.json b/package.json index 16b4c67b0..97f7c7efa 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lint": "yarn flow", "start": "unset HOST && react-scripts start", "build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build", - "postbuild": "export NODE_OPTIONS=--max-old-space-size=8192 && node scripts/patchUrls.js", + "postbuild": "chmod +x scripts/node_heap_size.sh && ./scripts/node_heap_size.sh && node scripts/patchUrls.js --max-old-space-size=8192", "ppostbuild": "react-snap", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/scripts/node_heap_size.sh b/scripts/node_heap_size.sh new file mode 100755 index 000000000..25659189e --- /dev/null +++ b/scripts/node_heap_size.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +node -e 'console.log(`*** NODE HEAP LIMIT = ${require("v8").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)' \ No newline at end of file From 2dde37d295430eab1cea4f2602cb146ceae140e7 Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Tue, 10 Oct 2023 14:00:36 +0100 Subject: [PATCH 4/6] add some changes for testing --- package.json | 2 +- scripts/patchUrls.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 97f7c7efa..0a2741939 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lint": "yarn flow", "start": "unset HOST && react-scripts start", "build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build", - "postbuild": "chmod +x scripts/node_heap_size.sh && ./scripts/node_heap_size.sh && node scripts/patchUrls.js --max-old-space-size=8192", + "postbuild": "chmod +x scripts/node_heap_size.sh && ./scripts/node_heap_size.sh && node scripts/patchUrls.js --max-old-space-size=3072", "ppostbuild": "react-snap", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/scripts/patchUrls.js b/scripts/patchUrls.js index 4e0c9e866..1be9be0ce 100644 --- a/scripts/patchUrls.js +++ b/scripts/patchUrls.js @@ -97,7 +97,15 @@ const main = async () => { ...process.env }; + console.log("+++ extractEnvVars():", extractEnvVars()) + console.log("+++ process.env:", process.env) + console.log("+++ Number of files =", files.length) + + let counter = 0; + for ( const file of files ) { + counter += 1; + console.log(counter, " - ", file) const tmpFile = `${ file }.tmp`; From f8bcddb3c64faa94a86d206e60332fa308fdd77f Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Wed, 11 Oct 2023 09:56:18 +0100 Subject: [PATCH 5/6] add env vars filtering --- scripts/patchUrls.js | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/scripts/patchUrls.js b/scripts/patchUrls.js index 1be9be0ce..b85243875 100644 --- a/scripts/patchUrls.js +++ b/scripts/patchUrls.js @@ -81,6 +81,36 @@ const getFiles = (directory) => { }; // getFiles +/** + * The function filters environment variables and returns only the important ones. + * + * @returns {object} + */ +const filterEnvVars = () => { + const vars = process.env; + const valid_keys = [ + "BASE_URL", + "MAIN_CDN", + "DOWNLOADS_CDN", + "API_ENDPOINT", + "USER_API_ENDPOINT", + "APPINSIGHTS_INSTRUMENTATIONKEY" + ] + const filteredVars = {} + + Object.keys(vars).forEach(key => { + // Check if it can be one of the vars to use. + valid_keys.forEach(valid_key => { + if(vars.hasOwnProperty(key) && key.includes(valid_key)) { + filteredVars[key] = vars[key] + } + }) + }) + + return filteredVars +} + + /** * Replaces placeholders formatted as `%key%` with environment * variables defined using the same key. @@ -94,18 +124,17 @@ const main = async () => { files = getFiles(directory), Replacements = { ...extractEnvVars(), - ...process.env + ...filterEnvVars() }; - console.log("+++ extractEnvVars():", extractEnvVars()) - console.log("+++ process.env:", process.env) - console.log("+++ Number of files =", files.length) + console.log("vars:", Replacements) + console.log("vars number:", Object.keys(Replacements).length) let counter = 0; for ( const file of files ) { counter += 1; - console.log(counter, " - ", file) + console.log(counter, " - processing file:", file) const tmpFile = `${ file }.tmp`; From 29bcfca56dece2cd85596ac9837642abd5439362 Mon Sep 17 00:00:00 2001 From: Jaroslaw Michalski Date: Wed, 11 Oct 2023 11:43:30 +0100 Subject: [PATCH 6/6] remove unwanted code --- package.json | 2 +- scripts/node_heap_size.sh | 3 --- scripts/patchUrls.js | 7 ------- 3 files changed, 1 insertion(+), 11 deletions(-) delete mode 100755 scripts/node_heap_size.sh diff --git a/package.json b/package.json index 0a2741939..64c12dbf7 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "lint": "yarn flow", "start": "unset HOST && react-scripts start", "build": "unset HOST && export NODE_OPTIONS=--max-old-space-size=8192 && react-scripts build", - "postbuild": "chmod +x scripts/node_heap_size.sh && ./scripts/node_heap_size.sh && node scripts/patchUrls.js --max-old-space-size=3072", + "postbuild": "node scripts/patchUrls.js --max-old-space-size=3072", "ppostbuild": "react-snap", "test": "react-scripts test", "eject": "react-scripts eject" diff --git a/scripts/node_heap_size.sh b/scripts/node_heap_size.sh deleted file mode 100755 index 25659189e..000000000 --- a/scripts/node_heap_size.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -node -e 'console.log(`*** NODE HEAP LIMIT = ${require("v8").getHeapStatistics().heap_size_limit / (1024 * 1024)} Mb`)' \ No newline at end of file diff --git a/scripts/patchUrls.js b/scripts/patchUrls.js index b85243875..6b3ff6527 100644 --- a/scripts/patchUrls.js +++ b/scripts/patchUrls.js @@ -127,14 +127,7 @@ const main = async () => { ...filterEnvVars() }; - console.log("vars:", Replacements) - console.log("vars number:", Object.keys(Replacements).length) - - let counter = 0; - for ( const file of files ) { - counter += 1; - console.log(counter, " - processing file:", file) const tmpFile = `${ file }.tmp`;