Skip to content

Commit 4d62218

Browse files
Merge pull request #3739 from RedisInsight/release/2.54.1
Release/2.54.1
2 parents cabd403 + 6100239 commit 4d62218

File tree

13 files changed

+350
-14
lines changed

13 files changed

+350
-14
lines changed

.circleci/build/build_modules.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,49 @@ LICENSE \
4646

4747
mkdir -p release/web
4848
cp redisinsight/build.tar.gz release/web/"$FILENAME"
49+
50+
# Minify build via esbuild
51+
echo "Start minifing workflow"
52+
npm_config_arch="$ARCH" \
53+
npm_config_target_arch="$ARCH" \
54+
npm_config_platform="$PLATFORM" \
55+
npm_config_target_platform="$PLATFORM" \
56+
yarn --cwd ./redisinsight/api install
57+
yarn --cwd ./redisinsight/api minify:prod
58+
59+
60+
PACKAGE_JSON_PATH="./redisinsight/api/package.json"
61+
APP_PACKAGE_JSON_PATH="./redisinsight/package.json"
62+
63+
# Extract dependencies from the app package.json
64+
BINARY_PACKAGES=$(jq -r '.dependencies | keys[]' "$APP_PACKAGE_JSON_PATH" | jq -R -s -c 'split("\n")[:-1]')
65+
66+
echo "Binary packages to exclude during minify: $BINARY_PACKAGES"
67+
68+
# Modify the package.json
69+
jq --argjson keep "$BINARY_PACKAGES" \
70+
'del(.devDependencies) | .dependencies |= with_entries(select(.key as $k | $keep | index($k)))' \
71+
"$PACKAGE_JSON_PATH" > temp.json && mv temp.json "$PACKAGE_JSON_PATH"
72+
73+
npm_config_arch="$ARCH" \
74+
npm_config_target_arch="$ARCH" \
75+
npm_config_platform="$PLATFORM" \
76+
npm_config_target_platform="$PLATFORM" \
77+
yarn --cwd ./redisinsight/api install --production
78+
yarn --cwd ./redisinsight/api autoclean --force
79+
80+
# Compress minified build
81+
cd redisinsight && tar -czf build-mini.tar.gz \
82+
--exclude="api/node_modules/**/build/node_gyp_bins/python3" \
83+
api/node_modules \
84+
api/dist-minified \
85+
ui/dist \
86+
LICENSE \
87+
&& cd ..
88+
89+
mkdir -p release/web-mini
90+
cp redisinsight/build-mini.tar.gz release/web-mini/"$FILENAME"
91+
92+
# Restore the original package.json and yarn.lock
93+
git restore redisinsight/api/yarn.lock redisinsight/api/package.json
94+

.circleci/deps-licenses-report.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ async function runLicenseCheck(path) {
7878
new Promise((resolve, reject) => {
7979
exec(command, (error, stdout, stderr) => {
8080
if (error) {
81-
console.error(`Failed command: ${commandProd}, error:`, stderr);
81+
console.error(`Failed command: ${command}, error:`, stderr);
8282
reject(error);
8383
}
8484
resolve();

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ redisinsight/ui/style.css.map
4848
redisinsight/ui/dist
4949
redisinsight/api/commands
5050
redisinsight/api/guides
51+
redisinsight/api/dist-minified
5152
redisinsight/api/tutorials
5253
redisinsight/api/content
5354
redisinsight/ui/dist-stats.html

configs/webpack.config.main.prod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default merge(baseConfig, {
6262
RI_SERVE_STATICS: false,
6363
RI_APP_FOLDER_NAME: process.env.RI_APP_FOLDER_NAME || '',
6464
RI_UPGRADES_LINK: process.env.RI_UPGRADES_LINK || '',
65+
RI_ANALYTICS_START_EVENTS: 'true',
6566
RI_APP_HOST: '127.0.0.1',
6667
RI_BUILD_TYPE: 'ELECTRON',
6768
RI_APP_VERSION: version,

redisinsight/api/.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
'max-classes-per-file': 'off',
1515
'class-methods-use-this': 'off', // should be ignored since NestJS allow inheritance without using "this" inside class methods
1616
'no-await-in-loop': 'off',
17+
'import/no-extraneous-dependencies': 'off',
1718
},
1819
parserOptions: {
1920
project: './tsconfig.json',

redisinsight/api/config/default.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ const staticDir = process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resources
1212
? join(process['resourcesPath'], 'static')
1313
: join(__dirname, '..', 'static');
1414

15-
const defaultsDir = process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resourcesPath']
16-
? join(process['resourcesPath'], 'defaults')
17-
: join(__dirname, '..', 'defaults');
15+
const defaultsDir = process.env.RI_DEFAULTS_DIR
16+
|| ((process.env.RI_BUILD_TYPE === 'ELECTRON' && process['resourcesPath'])
17+
? join(process['resourcesPath'], 'defaults')
18+
: join(__dirname, '..', 'defaults'));
1819

1920
const proxyPath = trim(process.env.RI_PROXY_PATH, '/');
2021

@@ -71,6 +72,7 @@ export default {
7172
base: process.env.RI_BASE || '/',
7273
proxyPath,
7374
secretStoragePassword: process.env.RI_SECRET_STORAGE_PASSWORD,
75+
agreementsPath: process.env.RI_AGREEMENTS_PATH,
7476
encryptionKey: process.env.RI_ENCRYPTION_KEY,
7577
tlsCert: process.env.RI_SERVER_TLS_CERT,
7678
tlsKey: process.env.RI_SERVER_TLS_KEY,
@@ -84,6 +86,7 @@ export default {
8486
excludeAuthRoutes: [],
8587
},
8688
encryption: {
89+
keytar: process.env.RI_ENCRYPTION_KEYTAR ? process.env.RI_ENCRYPTION_KEYTAR === 'true' : true, // enabled by default
8790
encryptionIV: process.env.RI_ENCRYPTION_IV || Buffer.alloc(16, 0),
8891
encryptionAlgorithm: process.env.RI_ENCRYPTION_ALGORYTHM || 'aes-256-cbc',
8992
},
@@ -128,6 +131,7 @@ export default {
128131
analytics: {
129132
writeKey: process.env.RI_SEGMENT_WRITE_KEY || 'SOURCE_WRITE_KEY',
130133
flushInterval: parseInt(process.env.RI_ANALYTICS_FLUSH_INTERVAL, 10) || 3000,
134+
startEvents: process.env.RI_ANALYTICS_START_EVENTS ? process.env.RI_ANALYTICS_START_EVENTS === 'true' : false,
131135
},
132136
logger: {
133137
logLevel: process.env.RI_LOG_LEVEL || 'info', // log level

redisinsight/api/esbuild.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const esbuild = require('esbuild');
2+
const fs = require('fs-extra');
3+
const path = require('path');
4+
require('dotenv').config();
5+
const { dependencies } = require('../package.json');
6+
7+
const production = process.argv.includes('--production');
8+
const watch = process.argv.includes('--watch');
9+
10+
const outDir = 'dist-minified';
11+
const define = {
12+
'process.env.NODE_ENV': JSON.stringify(production ? 'production' : 'development'),
13+
};
14+
15+
const external = [
16+
'@nestjs/microservices',
17+
'@fastify/static',
18+
// packages with binaries
19+
...Object.keys(dependencies),
20+
];
21+
22+
async function main() {
23+
const ctx = await esbuild.context({
24+
entryPoints: ['dist/src/main.js'],
25+
bundle: true,
26+
format: 'cjs',
27+
minifyWhitespace: true,
28+
// if true - some nestjs decorators are not working
29+
minifyIdentifiers: false,
30+
sourcemap: !production,
31+
sourcesContent: false,
32+
platform: 'node',
33+
outfile: `${outDir}/main.js`,
34+
define,
35+
external,
36+
logLevel: 'silent',
37+
plugins: [
38+
/* add to the end of plugins array */
39+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
40+
esbuildProblemMatcherPlugin,
41+
],
42+
});
43+
if (watch) {
44+
await ctx.watch();
45+
} else {
46+
await ctx.rebuild();
47+
await ctx.dispose();
48+
}
49+
}
50+
51+
function copySource(source, destination) {
52+
try {
53+
if (fs.pathExistsSync(source)) {
54+
fs.copySync(source, destination);
55+
}
56+
} catch (error) {
57+
console.error('✘ [esbuild ERROR copySource]', error);
58+
}
59+
}
60+
61+
/**
62+
* @type {import('esbuild').Plugin}
63+
*/
64+
const esbuildProblemMatcherPlugin = {
65+
name: 'esbuild-problem-matcher',
66+
67+
setup(build) {
68+
build.onStart(() => {
69+
console.debug('[esbuild] build started');
70+
});
71+
build.onEnd((result) => {
72+
result.errors.forEach(({ text, location }) => {
73+
console.error(`✘ [esbuild ERROR] ${text}`);
74+
console.error(` ${location.file}:${location.line}:${location.column}:`);
75+
});
76+
console.debug('[esbuild] build finished');
77+
78+
copySource(
79+
path.resolve(__dirname, 'defaults'),
80+
path.resolve(__dirname, outDir, 'defaults'),
81+
);
82+
console.debug('[esbuild] copied "defaults" folder');
83+
});
84+
},
85+
};
86+
87+
main().catch((e) => {
88+
console.error(e);
89+
process.exit(1);
90+
});

redisinsight/api/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
"build:prod": "rimraf dist && nest build -p ./tsconfig.build.prod.json && cross-env NODE_ENV=production",
1919
"build:stage": "rimraf dist && nest build && cross-env NODE_ENV=staging",
2020
"format": "prettier --write \"src/**/*.ts\"",
21+
"minify:prod": "node ./esbuild.js --production",
22+
"minify:dev": "node ./esbuild.js --watch",
2123
"lint": "eslint --ext .ts .",
2224
"start": "nest start",
2325
"start:dev": "cross-env NODE_ENV=development nest start --watch",
@@ -111,6 +113,7 @@
111113
"chai": "^4.3.4",
112114
"concurrently": "^5.3.0",
113115
"cross-env": "^7.0.3",
116+
"esbuild": "^0.23.0",
114117
"eslint": "^7.1.0",
115118
"eslint-config-airbnb-typescript": "^12.3.1",
116119
"eslint-config-prettier": "^6.10.0",

redisinsight/api/src/modules/encryption/strategies/keytar-encryption.strategy.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class KeytarEncryptionStrategy implements IEncryptionStrategy {
2626

2727
constructor() {
2828
try {
29+
if (!ENCRYPTION_CONFIG.keytar) {
30+
return;
31+
}
32+
2933
// Have to require keytar here since during tests of keytar module
3034
// at some point it threw an error when OS secure storage was unavailable
3135
// Since it is difficult to reproduce we keep module require here to be
@@ -100,6 +104,10 @@ export class KeytarEncryptionStrategy implements IEncryptionStrategy {
100104
* Basically just try to get a password and checks if this call fails
101105
*/
102106
async isAvailable(): Promise<boolean> {
107+
if (!ENCRYPTION_CONFIG.keytar) {
108+
return false;
109+
}
110+
103111
try {
104112
await this.keytar.getPassword(SERVICE, ACCOUNT);
105113
return true;

redisinsight/api/src/modules/server/server.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { GetServerInfoResponse } from 'src/modules/server/dto/server.dto';
1313
import { FeaturesConfigService } from 'src/modules/feature/features-config.service';
1414

1515
const SERVER_CONFIG = config.get('server') as Config['server'];
16+
const ANALYTICS_CONFIG = config.get('analytics') as Config['analytics'];
1617
const REDIS_STACK_CONFIG = config.get('redisStack') as Config['redisStack'];
1718

1819
@Injectable()
@@ -58,7 +59,7 @@ export class ServerService implements OnApplicationBootstrap {
5859
});
5960

6061
// do not track start events for non-electron builds
61-
if (SERVER_CONFIG?.buildType.toUpperCase() === 'ELECTRON') {
62+
if (ANALYTICS_CONFIG.startEvents) {
6263
this.eventEmitter.emit(AppAnalyticsEvents.Track, {
6364
event: startEvent,
6465
eventData: {

0 commit comments

Comments
 (0)