From 7b01d49577ca069dadf79e9822a8a6702954e626 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Sun, 28 Aug 2022 09:37:04 +0300 Subject: [PATCH 1/6] Experimenting around changing build artefact location to go to node_modules, so the content is retained across cached builds in various PAAS environments --- lib/server/app.js | 4 ++-- lib/server/enclave.js | 2 +- package.json | 2 +- webpack/webpack.config.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/server/app.js b/lib/server/app.js index bb68a2f711a..78df91ea158 100644 --- a/lib/server/app.js +++ b/lib/server/app.js @@ -320,7 +320,7 @@ function create (env, ctx) { } // Production bundling - const tmpFiles = express.static(resolvePath('/tmp/public'), { + const tmpFiles = express.static(resolvePath('/node_modules/_ns_cache/public'), { maxAge: maxAge }); @@ -343,7 +343,7 @@ function create (env, ctx) { , coffee_match: /coffeescript/ , json_match: /json/ , cssmin: myCssmin - , cache: resolvePath('/tmp/public') + , cache: resolvePath('/node_modules/_ns_cache/public') , onerror: undefined , })); diff --git a/lib/server/enclave.js b/lib/server/enclave.js index 2ae0ef2ebcb..6d403dbd546 100644 --- a/lib/server/enclave.js +++ b/lib/server/enclave.js @@ -19,7 +19,7 @@ const init = function init () { let apiKeySet = false; function readKey (filename) { - let filePath = path.resolve(__dirname + '/../../tmp/' + filename); + let filePath = path.resolve(__dirname + '/../../node_modules/_ns_cache/' + filename); if (fs.existsSync(filePath)) { return fs.readFileSync(filePath).toString().trim(); } diff --git a/package.json b/package.json index 98f24b87bb2..842f853c41a 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", - "generate-keys": "node bin/generateRandomString.js >tmp/randomString", + "generate-keys": "mkdir node_modules/_ns_cache | node bin/generateRandomString.js >node_modules/_ns_cache/randomString", "coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE", "dev": "env-cmd -f ./my.env nodemon --inspect lib/server/server.js 0.0.0.0", "dev-test": "env-cmd -f ./my.devtest.env nodemon --inspect lib/server/server.js 0.0.0.0", diff --git a/webpack/webpack.config.js b/webpack/webpack.config.js index a81a2f17dcf..82e623ad043 100644 --- a/webpack/webpack.config.js +++ b/webpack/webpack.config.js @@ -149,7 +149,7 @@ module.exports = { clock: clockEntry }, output: { - path: path.resolve(projectRoot, './tmp/public'), + path: path.resolve(projectRoot, './node_modules/_ns_cache/public'), publicPath, filename: 'js/bundle.[name].js', sourceMapFilename: 'js/bundle.[name].js.map', From 37a2a0d004343aabf516ef6ac75d6aaa729a8a33 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 29 Aug 2022 10:28:09 +0300 Subject: [PATCH 2/6] Try .cache in node_modules --- lib/server/app.js | 2 +- lib/server/enclave.js | 2 +- package.json | 2 +- webpack/webpack.config.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/server/app.js b/lib/server/app.js index 78df91ea158..d8489377391 100644 --- a/lib/server/app.js +++ b/lib/server/app.js @@ -343,7 +343,7 @@ function create (env, ctx) { , coffee_match: /coffeescript/ , json_match: /json/ , cssmin: myCssmin - , cache: resolvePath('/node_modules/_ns_cache/public') + , cache: resolvePath('/node_modules/.cache/_ns_cache/public') , onerror: undefined , })); diff --git a/lib/server/enclave.js b/lib/server/enclave.js index 6d403dbd546..3e62a04a0c6 100644 --- a/lib/server/enclave.js +++ b/lib/server/enclave.js @@ -19,7 +19,7 @@ const init = function init () { let apiKeySet = false; function readKey (filename) { - let filePath = path.resolve(__dirname + '/../../node_modules/_ns_cache/' + filename); + let filePath = path.resolve(__dirname + '/../../node_modules/.cache/_ns_cache/' + filename); if (fs.existsSync(filePath)) { return fs.readFileSync(filePath).toString().trim(); } diff --git a/package.json b/package.json index 842f853c41a..b32aee9db10 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", - "generate-keys": "mkdir node_modules/_ns_cache | node bin/generateRandomString.js >node_modules/_ns_cache/randomString", + "generate-keys": "mkdir node_modules/.cache/_ns_cache | node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", "coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE", "dev": "env-cmd -f ./my.env nodemon --inspect lib/server/server.js 0.0.0.0", "dev-test": "env-cmd -f ./my.devtest.env nodemon --inspect lib/server/server.js 0.0.0.0", diff --git a/webpack/webpack.config.js b/webpack/webpack.config.js index 82e623ad043..dfde535ef2f 100644 --- a/webpack/webpack.config.js +++ b/webpack/webpack.config.js @@ -149,7 +149,7 @@ module.exports = { clock: clockEntry }, output: { - path: path.resolve(projectRoot, './node_modules/_ns_cache/public'), + path: path.resolve(projectRoot, './node_modules/.cache/_ns_cache/public'), publicPath, filename: 'js/bundle.[name].js', sourceMapFilename: 'js/bundle.[name].js.map', From a6eb1561e9711ed646c9e2c561347eb101db0584 Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Mon, 29 Aug 2022 10:40:55 +0300 Subject: [PATCH 3/6] Fix app.js --- lib/server/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/server/app.js b/lib/server/app.js index d8489377391..b8a845999e9 100644 --- a/lib/server/app.js +++ b/lib/server/app.js @@ -320,7 +320,7 @@ function create (env, ctx) { } // Production bundling - const tmpFiles = express.static(resolvePath('/node_modules/_ns_cache/public'), { + const tmpFiles = express.static(resolvePath('/node_modules/.cache/_ns_cache/public'), { maxAge: maxAge }); From ec3cf94355031990d6604d6cd7890f1e85b31c7f Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Tue, 30 Aug 2022 12:49:01 +0300 Subject: [PATCH 4/6] =?UTF-8?q?*=20Fix=20tests=20*=20Change=20|=C2=A0to=20?= =?UTF-8?q?&&=20in=20package.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- tests/admintools.test.js | 2 +- tests/fixtures/headless.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b32aee9db10..a166d1f93ba 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", - "generate-keys": "mkdir node_modules/.cache/_ns_cache | node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", + "generate-keys": "mkdir node_modules/.cache/_ns_cache && node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", "coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE", "dev": "env-cmd -f ./my.env nodemon --inspect lib/server/server.js 0.0.0.0", "dev-test": "env-cmd -f ./my.devtest.env nodemon --inspect lib/server/server.js 0.0.0.0", diff --git a/tests/admintools.test.js b/tests/admintools.test.js index 59f10c720a7..4b7801419cd 100644 --- a/tests/admintools.test.js +++ b/tests/admintools.test.js @@ -70,7 +70,7 @@ describe('admintools', function ( ) { before(function (done) { benv.setup(function() { - benv.require(__dirname + '/../tmp/public/js/bundle.app.js'); + benv.require(__dirname + '/../node_modules/.cache/_ns_cache/public/js/bundle.app.js'); self.$ = $; diff --git a/tests/fixtures/headless.js b/tests/fixtures/headless.js index a3ad66b2424..310566e6132 100644 --- a/tests/fixtures/headless.js +++ b/tests/fixtures/headless.js @@ -25,7 +25,7 @@ function headless (benv, binding) { console.log('Setting up benv', Date.now() - t); - benv.require(__dirname + '/../../tmp/public/js/bundle.app.js'); + benv.require(__dirname + '/../../node_modules/.cache/_ns_cache/public/js/bundle.app.js'); console.log('Bundle loaded', Date.now() - t); From 6c03dcdc64e42aef60cb73ef41899c5fea0e9b2d Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Tue, 30 Aug 2022 12:54:10 +0300 Subject: [PATCH 5/6] Remove mkdir from package.json and change key generation to a post script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a166d1f93ba..9ebae2ce93f 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys", "bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", - "generate-keys": "mkdir node_modules/.cache/_ns_cache && node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", + "post-generate-keys": "node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", "coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE", "dev": "env-cmd -f ./my.env nodemon --inspect lib/server/server.js 0.0.0.0", "dev-test": "env-cmd -f ./my.devtest.env nodemon --inspect lib/server/server.js 0.0.0.0", From 6978a90083868ad11ccd180930c42d1c6878567b Mon Sep 17 00:00:00 2001 From: Sulka Haro Date: Tue, 30 Aug 2022 13:16:29 +0300 Subject: [PATCH 6/6] Fix package running the post script --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 9ebae2ce93f..1420e38ed03 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,9 @@ "test-single": "env-cmd -f ./my.test.env mocha --require ./tests/hooks.js --exit ./tests/$TEST.test.js", "test-ci": "env-cmd -f ./tests/ci.test.env nyc --reporter=lcov --reporter=text-summary mocha --require ./tests/hooks.js --exit ./tests/*.test.js", "env": "env", - "postinstall": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", - "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script generate-keys", - "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script generate-keys", + "postinstall": "webpack --mode production --config webpack/webpack.config.js && npm run-script post-generate-keys", + "bundle": "webpack --mode production --config webpack/webpack.config.js && npm run-script post-generate-keys", + "bundle-dev": "webpack --mode development --config webpack/webpack.config.js && npm run-script post-generate-keys", "bundle-analyzer": "webpack --mode development --config webpack/webpack.config.js --profile --json > stats.json && webpack-bundle-analyzer stats.json", "post-generate-keys": "node bin/generateRandomString.js >node_modules/.cache/_ns_cache/randomString", "coverage": "cat ./coverage/lcov.info | env-cmd -f ./tests/ci.test.env codacy-coverage || echo NO COVERAGE",