Skip to content

Commit

Permalink
ref: Remove obsolete deps (r2, lodash) (#799)
Browse files Browse the repository at this point in the history
* ref: Remove obsolete deps (r2, lodash)

* fix PR no in changelog
  • Loading branch information
BYK authored Feb 21, 2025
1 parent 9edc8a5 commit 5705509
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 196 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- ref!: Bump main Node.js version to the earliest LTS v18 ([#793](https://github.com/getsentry/sentry-wizard/pull/793))
- ref!: Follow up to Node v18 changes ([#797](https://github.com/getsentry/sentry-wizard/pull/797))
- ref: Remove obsolete deps (r2, lodash) ([#799](https://github.com/getsentry/sentry-wizard/pull/799))

## 3.42.1

Expand Down
22 changes: 12 additions & 10 deletions lib/Helper/Package.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
import * as _ from 'lodash';
import { satisfies, subset, valid, validRange } from 'semver';

import { green, red } from './Logging';

export function checkPackageVersion(
appPackage: unknown,
appPackage: {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
},
packageName: string,
acceptableVersions: string,
canBeLatest: boolean,
): boolean {
const depsVersion = _.get(appPackage, ['dependencies', packageName]);
const devDepsVersion = _.get(appPackage, ['devDependencies', packageName]);
const depsVersion = appPackage?.dependencies?.[packageName] ?? '';
const devDepsVersion = appPackage?.devDependencies?.[packageName] ?? '';

if (!depsVersion && !devDepsVersion) {
red(`✗ ${packageName} isn't in your dependencies.`);
red(' Please install it with yarn/npm.');
return false;
} else if (
}
if (
!fulfillsVersionRange(depsVersion, acceptableVersions, canBeLatest) &&
!fulfillsVersionRange(devDepsVersion, acceptableVersions, canBeLatest)
) {
red(
`✗ Your \`package.json\` specifies a version of \`${packageName}\` outside of the compatible version range ${acceptableVersions}.\n`,
);
return false;
} else {
green(
`✓ A compatible version of \`${packageName}\` is specified in \`package.json\`.`,
);
return true;
}
green(
`✓ A compatible version of \`${packageName}\` is specified in \`package.json\`.`,
);
return true;
}

function fulfillsVersionRange(
Expand Down
45 changes: 18 additions & 27 deletions lib/Helper/SentryCli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as fs from 'fs';
import * as fs from 'node:fs';
import type { Answers } from 'inquirer';
import * as _ from 'lodash';
import * as path from 'path';
import * as path from 'node:path';

import type { Args } from '../Constants';
import { addToGitignore } from './Git';
Expand Down Expand Up @@ -30,9 +29,9 @@ export class SentryCli {
public convertAnswersToProperties(answers: Answers): SentryCliProps {
const props: SentryCliProps = {};
props['defaults/url'] = this._argv.url;
props['defaults/org'] = _.get(answers, 'config.organization.slug', null);
props['defaults/project'] = _.get(answers, 'config.project.slug', null);
props['auth/token'] = _.get(answers, 'config.auth.token', null);
props['defaults/org'] = answers.config?.organization?.slug ?? null;
props['defaults/project'] = answers.config?.project?.slug ?? null;
props['auth/token'] = answers.config?.auth?.token ?? null;
try {
const cliPath = this._resolve('@sentry/cli/bin/sentry-cli', {
paths: [process.cwd()],
Expand All @@ -41,25 +40,21 @@ export class SentryCli {
.relative(process.cwd(), cliPath)
.replace(/\\/g, '\\\\');
} catch (e) {
// we do nothing and leave everyting as it is
// we do nothing and leave everything as it is
}
return props;
}

/** Create the contents of a `sentry.properties` file */
public dumpProperties(props: SentryCliProps): string {
const rv = [];
for (let key in props) {
// eslint-disable-next-line no-prototype-builtins
if (props.hasOwnProperty(key)) {
const value = props[key];
key = key.replace(/\//g, '.');
if (value === undefined || value === null) {
// comment that property out since it has no value
rv.push(`#${key}=`);
} else {
rv.push(`${key}=${value}`);
}
for (const [key, value] of Object.entries(props)) {
const normalizedKey = key.replace(/\//g, '.');
if (value === undefined || value === null) {
// comment that property out since it has no value
rv.push(`#${normalizedKey}=`);
} else {
rv.push(`${normalizedKey}=${value}`);
}
}
// eslint-disable-next-line prefer-template
Expand All @@ -68,13 +63,10 @@ export class SentryCli {

public dumpConfig(config: SentryCliConfig): string {
const dumpedSections: string[] = [];
for (const sectionName in config) {
// eslint-disable-next-line no-prototype-builtins
if (config.hasOwnProperty(sectionName)) {
const props = this.dumpProperties(config[sectionName]);
const section = `[${sectionName}]\n${props}`;
dumpedSections.push(section);
}
for (const [sectionName, val] of Object.entries(config)) {
const props = this.dumpProperties(val);
const section = `[${sectionName}]\n${props}`;
dumpedSections.push(section);
}
return dumpedSections.join('\n');
}
Expand Down Expand Up @@ -127,8 +119,7 @@ export class SentryCli {

await addToGitignore(
SENTRYCLIRC_FILENAME,
`⚠ Could not add ${SENTRYCLIRC_FILENAME} to ${GITIGNORE_FILENAME}, ` +
'please add it to not commit your auth key.',
`⚠ Could not add ${SENTRYCLIRC_FILENAME} to ${GITIGNORE_FILENAME}, please add it to not commit your auth key.`,
);

try {
Expand Down
3 changes: 1 addition & 2 deletions lib/Helper/Wizard.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Answers } from 'inquirer';
import * as _ from 'lodash';

import type { Args } from '../Constants';
import type { IStep } from '../Steps/BaseStep';
Expand All @@ -24,7 +23,7 @@ function sanitizeAndValidateArgs(argv: Args): void {
}

export function getCurrentIntegration(answers: Answers): BaseIntegration {
return _.get(answers, 'integration') as BaseIntegration;
return answers.integration as BaseIntegration;
}

export async function startWizard<M extends IStep>(
Expand Down
12 changes: 6 additions & 6 deletions lib/Setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from 'lodash';
import { enableDebugLogs } from '../src/utils/debug';

import { readEnvironment } from './Helper/Env';
Expand All @@ -21,21 +20,22 @@ export async function run(argv: any): Promise<any> {
if (args.uninstall === undefined) {
args.uninstall = false;
}
let steps = [
const steps = [
Step.Initial,
Step.Welcome,
Step.ChooseIntegration,
Step.ShouldConfigure,
];
if (args.uninstall === false) {
steps = _.concat(
steps,
steps.push(
Step.OpenSentry,
Step.WaitForSentry,
Step.SentryProjectSelector,
Step.PromptForParameters,
);
}
steps = _.concat(steps, Step.ConfigureProject, Step.Result);
return startWizard(args, ...steps);
steps.push(Step.ConfigureProject, Step.Result);

// @ts-ignore
return startWizard(args, steps);
}
26 changes: 12 additions & 14 deletions lib/Steps/Initial.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import type { Answers } from 'inquirer';
import * as _ from 'lodash';
import * as path from 'path';
import { join, dirname } from 'node:path';

import { dim } from '../Helper/Logging';
import { BaseStep } from './BaseStep';

let wizardPackage: any = {};
let sentryCliPackage: any = {};
type PackageJSON = { version?: string };
let wizardPackage: PackageJSON = {};
let sentryCliPackage: PackageJSON = {};

try {
wizardPackage = require(path.join(
path.dirname(require.resolve('@sentry/wizard')),
wizardPackage = require(join(
dirname(require.resolve('@sentry/wizard')),
'..',
'package.json',
));
Expand All @@ -19,25 +19,23 @@ try {
}

try {
sentryCliPackage = require(path.join(
path.dirname(require.resolve('@sentry/cli')),
sentryCliPackage = require(join(
dirname(require.resolve('@sentry/cli')),
'..',
'package.json',
));
} catch {
// We don't need to have tahis
// We don't need to have this
}

export class Initial extends BaseStep {
// eslint-disable-next-line @typescript-eslint/require-await
public async emit(_answers: Answers): Promise<Answers> {
dim('Running Sentry Wizard...');
dim(
`version: ${_.get(
wizardPackage,
'version',
'DEV',
)} | sentry-cli version: ${_.get(sentryCliPackage, 'version', 'DEV')}`,
`version: ${wizardPackage.version ?? 'DEV'} | sentry-cli version: ${
sentryCliPackage.version ?? 'DEV'
}`,
);
return {};
}
Expand Down
43 changes: 23 additions & 20 deletions lib/Steps/Integrations/Electron.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as fs from 'fs';
import * as fs from 'node:fs';
import type { Answers } from 'inquirer';
import { prompt } from 'inquirer';
import * as _ from 'lodash';
import * as path from 'path';
import * as path from 'node:path';

import type { Args } from '../../Constants';
import { dim, green, l, nl, red } from '../../Helper/Logging';
Expand Down Expand Up @@ -31,7 +30,11 @@ const Sentry = require('@sentry/electron/renderer');
Sentry.init({});`;

let appPackage: any = {};
type PackageJSON = {
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
};
let appPackage: PackageJSON = {};

function printExample(example: string, title = ''): void {
if (title) {
Expand All @@ -44,7 +47,9 @@ function printExample(example: string, title = ''): void {
}

try {
appPackage = require(path.join(process.cwd(), 'package.json'));
appPackage = JSON.parse(
fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'),
) as PackageJSON;
} catch {
// We don't need to have this
}
Expand All @@ -59,7 +64,7 @@ export class Electron extends BaseIntegration {

// eslint-disable-next-line @typescript-eslint/require-await
public async emit(answers: Answers): Promise<Answers> {
const dsn = _.get(answers, ['config', 'dsn', 'public'], null);
const dsn = answers.config?.dsn?.public ?? null;
nl();

const sentryCliProps = this._sentryCli.convertAnswersToProperties(answers);
Expand Down Expand Up @@ -112,7 +117,7 @@ export class Electron extends BaseIntegration {

nl();

if (!_.get(continued, 'continue', false)) {
if (!continued?.continue) {
throw new Error('Please install the required dependencies to continue.');
}

Expand All @@ -123,25 +128,23 @@ export class Electron extends BaseIntegration {

private _checkDep(packageName: string, minVersion?: string): boolean {
const depVersion = parseInt(
_.get(appPackage, ['dependencies', packageName], '0').replace(/\D+/g, ''),
(appPackage.dependencies?.[packageName] || '0').replace(/\D+/g, ''),
10,
);
const devDepVersion = parseInt(
_.get(appPackage, ['devDependencies', packageName], '0').replace(
/\D+/g,
'',
),
(appPackage.devDependencies?.[packageName] || '0').replace(/\D+/g, ''),
10,
);

if (
!_.get(appPackage, `dependencies.${packageName}`, false) &&
!_.get(appPackage, `devDependencies.${packageName}`, false)
!appPackage.dependencies?.[packageName] &&
!appPackage.devDependencies?.[packageName]
) {
red(`✗ ${packageName} isn't in your dependencies`);
red(' please install it with yarn/npm');
return false;
} else if (
}
if (
minVersion &&
depVersion < MIN_ELECTRON_VERSION &&
devDepVersion < MIN_ELECTRON_VERSION
Expand All @@ -150,12 +153,12 @@ export class Electron extends BaseIntegration {
`✗ Your installed version of ${packageName} is to old, >${MIN_ELECTRON_VERSION_STRING} needed`,
);
return false;
}
if (minVersion) {
green(`✓ ${packageName} > ${minVersion} is installed`);
} else {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
minVersion
? green(`✓ ${packageName} > ${minVersion} is installed`)
: green(`✓ ${packageName} is installed`);
return true;
green(`✓ ${packageName} is installed`);
}
return true;
}
}
Loading

0 comments on commit 5705509

Please sign in to comment.