Skip to content

Commit

Permalink
fix: fix Command types and props
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Aug 8, 2021
1 parent ab20eea commit a1cb818
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import * as config from "./apm"
import * as git from "./git"

export default class Command {
private electronVersion: string
installedAtomVersion: string
private resourcePath: string
npm: typeof import("npm")
constructor() {
this.logCommandResults = this.logCommandResults.bind(this)
this.logCommandResultsIfFail = this.logCommandResultsIfFail.bind(this)
Expand Down Expand Up @@ -108,7 +112,7 @@ export default class Command {
}
}

normalizeVersion(version) {
normalizeVersion(version: string) {
if (typeof version === "string") {
// Remove commit SHA suffix
return version.replace(/-.*$/, "")
Expand All @@ -119,11 +123,15 @@ export default class Command {

loadInstalledAtomMetadata(callback) {
return this.getResourcePath((resourcePath) => {
let electronVersion
let electronVersion: string | undefined
try {
let left, version
;({ version, electronVersion } = (left = require(path.join(resourcePath, "package.json"))) != null ? left : {})
version = this.normalizeVersion(version)
const resourcePathJson: { version: string; electronVersion: string } & Record<string, any> =
require(path.join(resourcePath, "package.json")) ?? {}

electronVersion = resourcePath.electronVersion

const version = this.normalizeVersion(resourcePathJson.version)

if (semver.valid(version)) {
this.installedAtomVersion = version
}
Expand Down

0 comments on commit a1cb818

Please sign in to comment.