mirror of
https://github.com/balena-io/etcher.git
synced 2025-07-16 15:56:33 +00:00
Merge pull request #4221 from balena-io/fix-analytics-imports
patch: fix injection of analytics key at build time
This commit is contained in:
commit
ae70c20779
@ -136,25 +136,6 @@ const config: ForgeConfig = {
|
|||||||
new sidecar.SidecarPlugin(),
|
new sidecar.SidecarPlugin(),
|
||||||
],
|
],
|
||||||
hooks: {
|
hooks: {
|
||||||
readPackageJson: async (_config, packageJson) => {
|
|
||||||
packageJson.analytics = {};
|
|
||||||
|
|
||||||
if (process.env.SENTRY_TOKEN) {
|
|
||||||
packageJson.analytics.sentry = {
|
|
||||||
token: process.env.SENTRY_TOKEN,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (process.env.AMPLITUDE_TOKEN) {
|
|
||||||
packageJson.analytics.amplitude = {
|
|
||||||
token: 'balena-etcher',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// packageJson.packageType = 'dmg' | 'AppImage' | 'rpm' | 'deb' | 'zip' | 'nsis' | 'portable'
|
|
||||||
|
|
||||||
return packageJson;
|
|
||||||
},
|
|
||||||
postPackage: async (_forgeConfig, options) => {
|
postPackage: async (_forgeConfig, options) => {
|
||||||
if (options.platform === 'linux') {
|
if (options.platform === 'linux') {
|
||||||
// symlink the etcher binary from balena-etcher to balenaEtcher to ensure compatibility with the wdio suite and the old name
|
// symlink the etcher binary from balena-etcher to balenaEtcher to ensure compatibility with the wdio suite and the old name
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as _ from 'lodash';
|
import { findLastIndex, once } from 'lodash';
|
||||||
import type { Client } from 'analytics-client';
|
import type { Client } from 'analytics-client';
|
||||||
import { createClient, createNoopClient } from 'analytics-client';
|
import { createClient, createNoopClient } from 'analytics-client';
|
||||||
import * as SentryRenderer from '@sentry/electron/renderer';
|
import * as SentryRenderer from '@sentry/electron/renderer';
|
||||||
import * as settings from '../models/settings';
|
import * as settings from '../models/settings';
|
||||||
import { store } from '../models/store';
|
import { store } from '../models/store';
|
||||||
import * as packageJSON from '../../../../package.json';
|
import { version } from '../../../../package.json';
|
||||||
|
|
||||||
type AnalyticsPayload = _.Dictionary<any>;
|
type AnalyticsPayload = _.Dictionary<any>;
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ export const anonymizePath = (input: string) => {
|
|||||||
const segments = mainPart.split(sep);
|
const segments = mainPart.split(sep);
|
||||||
|
|
||||||
// Moving from the end, find the first marker and cut the path from there.
|
// Moving from the end, find the first marker and cut the path from there.
|
||||||
const startCutIndex = _.findLastIndex(segments, (segment) =>
|
const startCutIndex = findLastIndex(segments, (segment) =>
|
||||||
etcherSegmentMarkers.includes(segment),
|
etcherSegmentMarkers.includes(segment),
|
||||||
);
|
);
|
||||||
return (
|
return (
|
||||||
@ -119,21 +119,19 @@ let analyticsClient: Client;
|
|||||||
/**
|
/**
|
||||||
* @summary Init analytics configurations
|
* @summary Init analytics configurations
|
||||||
*/
|
*/
|
||||||
export const initAnalytics = _.once(() => {
|
export const initAnalytics = once(() => {
|
||||||
const dsn =
|
const dsn =
|
||||||
settings.getSync('analyticsSentryToken') ||
|
settings.getSync('analyticsSentryToken') || process.env.SENTRY_TOKEN;
|
||||||
_.get(packageJSON, ['analytics', 'sentry', 'token']);
|
|
||||||
SentryRenderer.init({ dsn, beforeSend: anonymizeSentryData });
|
SentryRenderer.init({ dsn, beforeSend: anonymizeSentryData });
|
||||||
|
|
||||||
const projectName =
|
const projectName =
|
||||||
settings.getSync('analyticsAmplitudeToken') ||
|
settings.getSync('analyticsAmplitudeToken') || process.env.AMPLITUDE_TOKEN;
|
||||||
_.get(packageJSON, ['analytics', 'amplitude', 'token']);
|
|
||||||
|
|
||||||
const clientConfig = {
|
const clientConfig = {
|
||||||
projectName,
|
projectName,
|
||||||
endpoint: 'data.balena-cloud.com',
|
endpoint: 'data.balena-cloud.com',
|
||||||
componentName: 'etcher',
|
componentName: 'etcher',
|
||||||
componentVersion: packageJSON.version,
|
componentVersion: version,
|
||||||
};
|
};
|
||||||
analyticsClient = projectName
|
analyticsClient = projectName
|
||||||
? createClient(clientConfig)
|
? createClient(clientConfig)
|
||||||
|
@ -27,7 +27,7 @@ import { promises as fs } from 'fs';
|
|||||||
import { platform } from 'os';
|
import { platform } from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as semver from 'semver';
|
import * as semver from 'semver';
|
||||||
import * as lodash from 'lodash';
|
import { once } from 'lodash';
|
||||||
|
|
||||||
import './app/i18n';
|
import './app/i18n';
|
||||||
|
|
||||||
@ -37,7 +37,6 @@ import * as settings from './app/models/settings';
|
|||||||
import { buildWindowMenu } from './menu';
|
import { buildWindowMenu } from './menu';
|
||||||
import * as i18n from 'i18next';
|
import * as i18n from 'i18next';
|
||||||
import * as SentryMain from '@sentry/electron/main';
|
import * as SentryMain from '@sentry/electron/main';
|
||||||
import * as packageJSON from '../../package.json';
|
|
||||||
import { anonymizeSentryData } from './app/modules/analytics';
|
import { anonymizeSentryData } from './app/modules/analytics';
|
||||||
|
|
||||||
import { delay } from '../shared/utils';
|
import { delay } from '../shared/utils';
|
||||||
@ -115,12 +114,15 @@ async function getCommandLineURL(argv: string[]): Promise<string | undefined> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const initSentryMain = lodash.once(() => {
|
const initSentryMain = once(() => {
|
||||||
const dsn =
|
const dsn =
|
||||||
settings.getSync('analyticsSentryToken') ||
|
settings.getSync('analyticsSentryToken') || process.env.SENTRY_TOKEN;
|
||||||
lodash.get(packageJSON, ['analytics', 'sentry', 'token']);
|
|
||||||
|
|
||||||
SentryMain.init({ dsn, beforeSend: anonymizeSentryData });
|
SentryMain.init({
|
||||||
|
dsn,
|
||||||
|
beforeSend: anonymizeSentryData,
|
||||||
|
});
|
||||||
|
console.log(SentryMain.getCurrentScope());
|
||||||
});
|
});
|
||||||
|
|
||||||
const sourceSelectorReady = new Promise((resolve) => {
|
const sourceSelectorReady = new Promise((resolve) => {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
import type { Configuration, ModuleOptions } from 'webpack';
|
import type { Configuration, ModuleOptions } from 'webpack';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
|
|
||||||
import { BannerPlugin, IgnorePlugin } from 'webpack';
|
import { BannerPlugin, IgnorePlugin, DefinePlugin } from 'webpack';
|
||||||
|
|
||||||
const rules: Required<ModuleOptions>['rules'] = [
|
const rules: Required<ModuleOptions>['rules'] = [
|
||||||
// Add support for native node modules
|
// Add support for native node modules
|
||||||
@ -79,6 +79,15 @@ export const rendererConfig: Configuration = {
|
|||||||
banner: '__REACT_DEVTOOLS_GLOBAL_HOOK__ = { isDisabled: true };',
|
banner: '__REACT_DEVTOOLS_GLOBAL_HOOK__ = { isDisabled: true };',
|
||||||
raw: true,
|
raw: true,
|
||||||
}),
|
}),
|
||||||
|
// Inject the analytics key into the code
|
||||||
|
new DefinePlugin({
|
||||||
|
'process.env.SENTRY_TOKEN': JSON.stringify(
|
||||||
|
process.env.SENTRY_TOKEN || '',
|
||||||
|
),
|
||||||
|
'process.env.AMPLITUDE_TOKEN': JSON.stringify(
|
||||||
|
process.env.AMPLITUDE_TOKEN || '',
|
||||||
|
),
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user