Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Types #29

Merged
merged 26 commits into from
Aug 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ca922d1
fix: add types for the fs proxy
aminya Aug 8, 2021
e56d2ab
fix: fix Ci types and props
aminya Aug 8, 2021
ad3bff0
fix: fix Ci types and props
aminya Aug 8, 2021
9529ba0
fix: fix Command types and props
aminya Aug 8, 2021
9591692
fix: fix Config types and props
aminya Aug 8, 2021
acfdd59
fix: remove duplicate inherited npm property
aminya Aug 8, 2021
39876ca
fix: fix Dedupe types and props
aminya Aug 8, 2021
fd3dc63
fix: fix deprecated packages
aminya Aug 8, 2021
917e9ce
fix: fix Develop types and props
aminya Aug 8, 2021
63c05ac
fix: fix request types and functions
aminya Aug 8, 2021
5159a4b
fix: fix TextMateTheme types and props
aminya Aug 8, 2021
ae39596
fix: fix Upgrade types and props
aminya Aug 8, 2021
17583b3
fix: fix PackageConverter types and props
aminya Aug 8, 2021
8f8fabc
fix: fix RebuildModuleCache types and props
aminya Aug 8, 2021
bb63bc3
fix: fix Publish types and props
aminya Aug 8, 2021
c9031c9
fix: fix packages types
aminya Aug 8, 2021
6ac3bd4
fix: use PackageMetaData in other files
aminya Aug 8, 2021
c27b6c1
fix: fix CliOptions type
aminya Aug 8, 2021
e12b673
fix: fix RunCallback type
aminya Aug 8, 2021
85bf8c1
fix: fix Install props
aminya Aug 8, 2021
7cd4166
fix: fix Links props
aminya Aug 8, 2021
344214e
fix: fix List props
aminya Aug 8, 2021
9f5bc07
fix: fix Login constructor
aminya Aug 8, 2021
60e567a
fix: fix Rebuild props
aminya Aug 8, 2021
bc0a6e9
fix: fix ThemeConverter props
aminya Aug 8, 2021
2e3e54a
fix: fix Unlink props
aminya Aug 8, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
},
"devDependencies": {
"@types/async": "^3.2.7",
"@types/atom": "^1.40.11",
"@types/express": "^4.17.13",
"@types/first-mate": "^7.0.6",
"@types/fs-plus": "3.0.2",
Expand Down
14 changes: 9 additions & 5 deletions src/apm-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ const commands = {
show: viewClass,
}

function parseOptions(args = []) {
const options = yargs(args).wrap(Math.min(100, yargs.terminalWidth()))
export type CliOptions = yargs.Argv<{}> & { commandArgs: string[] } // TODO pass commandArgs directly

function parseOptions(args: string[] = []): CliOptions {
const options = yargs(args).wrap(Math.min(100, yargs.terminalWidth())) as CliOptions
options.usage(`\

apm - Atom Package Manager powered by https://atom.io
Expand All @@ -141,7 +143,7 @@ Run \`apm help <command>\` to see the more details about a specific command.\
return options
}

function showHelp(options) {
function showHelp(options: CliOptions) {
if (options == null) {
return
}
Expand Down Expand Up @@ -266,7 +268,9 @@ function getPythonVersion(callback) {
})
}

export function run(args, callback) {
export type RunCallback = (error?: string | Error | null) => any

export function run(args, callback: RunCallback) {
let Command
config.setupApmRcFile()
const options = parseOptions(args)
Expand All @@ -276,7 +280,7 @@ export function run(args, callback) {
}

let callbackCalled = false
const handleErrorCallback = (error) => {
const handleErrorCallback = (error?: string | Error) => {
if (callbackCalled) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/apm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function visualStudioIsInstalled(version) {
}
}

export function loadNpm(callback) {
export function loadNpm(callback: (config: null, npmVar: typeof npm) => void) {
const npmOptions = {
userconfig: getUserConfigPath(),
globalconfig: getGlobalConfigPath(),
Expand Down
16 changes: 9 additions & 7 deletions src/ci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import fs from "./fs"
import yargs from "yargs"
import async from "async"
import * as config from "./apm"
import Command from "./command"
import Command, { LogCommandResultsArgs } from "./command"
import type { CliOptions, RunCallback } from "./apm-cli"

export default class Ci extends Command {
private atomDirectory = config.getAtomDirectory()
private atomNpmPath = require.resolve("npm/bin/npm-cli")
private atomNodeDirectory: string
constructor() {
super()
this.atomDirectory = config.getAtomDirectory()
this.atomNodeDirectory = path.join(this.atomDirectory, ".node-gyp")
this.atomNpmPath = require.resolve("npm/bin/npm-cli")
}

parseOptions(argv) {
parseOptions(argv: string[]) {
const options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage(`\
Usage: apm ci
Expand Down Expand Up @@ -63,12 +65,12 @@ but cannot be used to install new packages or dependencies.\

const installOptions = { env, streaming: options.argv.verbose }

return this.fork(this.atomNpmPath, installArgs, installOptions, (...args) => {
return this.logCommandResults(callback, ...Array.from(args))
return this.fork(this.atomNpmPath, installArgs, installOptions, (...args: LogCommandResultsArgs) => {
return this.logCommandResults(callback, ...args)
})
}

run(options, callback) {
run(options: CliOptions, callback: RunCallback) {
const opts = this.parseOptions(options.commandArgs)

const commands = []
Expand Down
16 changes: 7 additions & 9 deletions src/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import yargs from "yargs"
import Command from "./command"
import Command, { LogCommandResultsArgs } from "./command"
import type { CliOptions, RunCallback } from "./apm-cli"

export default class Clean extends Command {
constructor() {
super()
this.atomNpmPath = require.resolve("npm/bin/npm-cli")
}
private atomNpmPath = require.resolve("npm/bin/npm-cli")

parseOptions(argv) {
parseOptions(argv: string[]) {
const options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))

options.usage(`\
Expand All @@ -25,10 +23,10 @@ as a dependency in the package.json file.\
return options.alias("h", "help").describe("help", "Print this usage message")
}

run(options, callback) {
run(options: CliOptions, callback: RunCallback) {
process.stdout.write("Removing extraneous modules ")
return this.fork(this.atomNpmPath, ["prune"], (...args) => {
return this.logCommandResults(callback, ...Array.from(args))
return this.fork(this.atomNpmPath, ["prune"], (...args: LogCommandResultsArgs) => {
return this.logCommandResults(callback, ...args)
})
}
}
24 changes: 17 additions & 7 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ import semver from "semver"
import * as config from "./apm"
import * as git from "./git"

export type LogCommandResultsArgs = [code: number, stderr?: string, stdout?: string]

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

logCommandResults(callback, code, stderr = "", stdout = "") {
logCommandResults(callback: (error?: string) => void, code: number, stderr = "", stdout = "") {
if (code === 0) {
this.logSuccess()
return callback()
Expand All @@ -99,7 +105,7 @@ export default class Command {
}
}

logCommandResultsIfFail(callback, code, stderr = "", stdout = "") {
logCommandResultsIfFail(callback: (error?: string) => void, code: number, stderr = "", stdout = "") {
if (code === 0) {
return callback()
} else {
Expand All @@ -108,7 +114,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 +125,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
12 changes: 7 additions & 5 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ import path from "path"
import yargs from "yargs"
import * as apm from "./apm"
import Command from "./command"
import type { CliOptions, RunCallback } from "./apm-cli"

export default class Config extends Command {
private atomDirectory = apm.getAtomDirectory()
private atomNpmPath = require.resolve("npm/bin/npm-cli")
private atomNodeDirectory: string
constructor() {
super()
const atomDirectory = apm.getAtomDirectory()
this.atomNodeDirectory = path.join(atomDirectory, ".node-gyp")
this.atomNpmPath = require.resolve("npm/bin/npm-cli")
this.atomNodeDirectory = path.join(this.atomDirectory, ".node-gyp")
}

parseOptions(argv) {
parseOptions(argv: string[]) {
const options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage(`\

Expand All @@ -30,7 +32,7 @@ Usage: apm config set <key> <value>
return options.alias("h", "help").describe("help", "Print this usage message")
}

run(options, callback) {
run(options: CliOptions, callback: RunCallback) {
options = this.parseOptions(options.commandArgs)

let configArgs = ["--globalconfig", apm.getGlobalConfigPath(), "--userconfig", apm.getUserConfigPath(), "config"]
Expand Down
17 changes: 10 additions & 7 deletions src/dedupe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ import path from "path"
import async from "async"
import yargs from "yargs"
import * as config from "./apm"
import Command from "./command"
import Command, { LogCommandResultsArgs } from "./command"
import fs from "./fs"
import type { CliOptions, RunCallback } from "./apm-cli"

export default class Dedupe extends Command {
private atomDirectory = config.getAtomDirectory()
private atomNpmPath = require.resolve("npm/bin/npm-cli")
atomPackagesDirectory: string
private atomNodeDirectory: string
constructor() {
super()
this.atomDirectory = config.getAtomDirectory()
this.atomPackagesDirectory = path.join(this.atomDirectory, "packages")
this.atomNodeDirectory = path.join(this.atomDirectory, ".node-gyp")
this.atomNpmPath = require.resolve("npm/bin/npm-cli")
}

parseOptions(argv) {
parseOptions(argv: string[]) {
const options = yargs(argv).wrap(Math.min(100, yargs.terminalWidth()))
options.usage(`\

Expand All @@ -36,8 +39,8 @@ This command is experimental.\
dedupeModules(options, callback) {
process.stdout.write("Deduping modules ")

return this.forkDedupeCommand(options, (...args) => {
return this.logCommandResults(callback, ...Array.from(args))
return this.forkDedupeCommand(options, (...args: LogCommandResultsArgs) => {
return this.logCommandResults(callback, ...args)
})
}

Expand Down Expand Up @@ -79,7 +82,7 @@ This command is experimental.\
return fs.makeTreeSync(this.atomNodeDirectory)
}

run(options, callback) {
run(options: CliOptions, callback: RunCallback) {
const { cwd } = options
options = this.parseOptions(options.commandArgs)
options.cwd = cwd
Expand Down
29 changes: 16 additions & 13 deletions src/deprecated-packages.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS104: Avoid inline assignments
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import semver from "semver"
let deprecatedPackages = null
let deprecatedPackages: DeprecatedPackages | undefined

export function isDeprecatedPackage(name, version) {
if (deprecatedPackages == null) {
let left
deprecatedPackages = (left = require("../deprecated-packages")) != null ? left : {}
type DeprecatedPackage = {
version?: string
hasDeprecations?: boolean
latestHasDeprecations?: boolean
message?: string
hasAlternative?: boolean
alternative?: string
}

type DeprecatedPackages = Record<string, DeprecatedPackage>

export function isDeprecatedPackage(name: string, version: string) {
if (deprecatedPackages === undefined) {
deprecatedPackages = require("../deprecated-packages") as DeprecatedPackages
}
if (!deprecatedPackages.hasOwnProperty(name)) {
if (!(name in deprecatedPackages)) {
return false
}

Expand Down
Loading