Skip to content

Commit

Permalink
feat: standard fs in most places, node16
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Aug 15, 2023
1 parent 757da69 commit 959dc93
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 323 deletions.
17 changes: 7 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "@oclif/plugin-update",
"version": "3.1.32",
"version": "4.0.0",
"author": "Salesforce",
"bugs": "https://github.com/oclif/plugin-update/issues",
"dependencies": {
"@oclif/color": "^1.0.10",
"@oclif/core": "^2.11.8",
"cross-spawn": "^7.0.3",
"chalk": "^4",
"debug": "^4.3.1",
"filesize": "^6.1.0",
"fs-extra": "^9.0.1",
"fs-extra": "^11.1.1",
"http-call": "^5.3.0",
"inquirer": "^8.2.6",
"lodash.throttle": "^4.1.1",
Expand All @@ -21,17 +20,15 @@
"@oclif/plugin-help": "^5.2.17",
"@oclif/test": "^2.4.4",
"@types/chai": "^4.3.5",
"@types/cross-spawn": "^6.0.2",
"@types/execa": "^0.9.0",
"@types/fs-extra": "^8.0.1",
"@types/fs-extra": "^11.0.1",
"@types/glob": "^7.1.3",
"@types/inquirer": "^8.2.0",
"@types/lodash.throttle": "^4.1.6",
"@types/mocha": "^9",
"@types/node": "^14.18.54",
"@types/node": "^16",
"@types/semver": "^7.5.0",
"@types/supports-color": "^7.2.0",
"@types/write-json-file": "^3.2.1",
"chai": "^4.3.7",
"eslint": "^7.32.0",
"eslint-config-oclif": "^4",
Expand All @@ -44,10 +41,10 @@
"sinon": "^12.0.1",
"ts-node": "^9.1.1",
"tslib": "^2.6.1",
"typescript": "4.4.3"
"typescript": "^5.1.6"
},
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"files": [
"oclif.manifest.json",
Expand Down
1 change: 1 addition & 0 deletions src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ export default class UpdateCommand extends Command {
return version
}
}

19 changes: 11 additions & 8 deletions src/hooks/init.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {ux, Interfaces} from '@oclif/core'
import spawn from 'cross-spawn'
import * as fs from 'fs-extra'
import {spawn} from 'child_process'
import {existsSync} from 'node:fs'

import {stat, open, writeFile} from 'node:fs/promises'
import * as path from 'path'

import {touch} from '../util'
Expand All @@ -13,7 +15,7 @@ function timestamp(msg: string): string {
}

async function mtime(f: string) {
const {mtime} = await fs.stat(f)
const {mtime} = await stat(f)
return mtime
}

Expand Down Expand Up @@ -49,23 +51,24 @@ export const init: Interfaces.Hook<'init'> = async function (opts) {

await touch(lastrunfile)
const clientDir = path.join(clientRoot, this.config.version)
if (await fs.pathExists(clientDir)) await touch(clientDir)
if (existsSync(clientDir)) await touch(clientDir)
if (!await autoupdateNeeded()) return

debug('autoupdate running')
await fs.outputFile(autoupdatefile, '')
await writeFile(autoupdatefile, '')

debug(`spawning autoupdate on ${binPath}`)

const fd = await fs.open(autoupdatelogfile, 'a')
fs.write(
const fd = await open(autoupdatelogfile, 'a')
await writeFile(
fd,
timestamp(`starting \`${binPath} update --autoupdate\` from ${process.argv.slice(1, 3).join(' ')}\n`),
)

const stream = fd.createWriteStream()
spawn(binPath, ['update', '--autoupdate'], {
detached: !this.config.windows,
stdio: ['ignore', fd, fd],
stdio: ['ignore', stream, stream],
env: autoupdateEnv,
})
.on('error', (e: Error) => process.emitWarning(e))
Expand Down
18 changes: 10 additions & 8 deletions src/tar.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'fs-extra'
import * as fs from 'node:fs/promises'
import {existsSync} from 'node:fs'
import * as path from 'path'

import {touch} from './util'
Expand All @@ -21,7 +22,7 @@ const ignore = (_: any, header: any) => {
export async function extract(stream: NodeJS.ReadableStream, basename: string, output: string, sha?: string): Promise<void> {
const getTmp = () => `${output}.partial.${Math.random().toString().split('.')[1].slice(0, 5)}`
let tmp = getTmp()
if (fs.pathExistsSync(tmp)) tmp = getTmp()
if (existsSync(tmp)) tmp = getTmp()
debug(`extracting to ${tmp}`)
try {
await new Promise((resolve, reject) => {
Expand Down Expand Up @@ -60,25 +61,26 @@ export async function extract(stream: NodeJS.ReadableStream, basename: string, o
stream.pipe(gunzip).pipe(extract)
})

if (await fs.pathExists(output)) {
if (existsSync(output)) {
try {
const tmp = getTmp()
await fs.move(output, tmp)
await fs.remove(tmp).catch(debug)
const {move} = await import('fs-extra')
await move(output, tmp)
await fs.rm(tmp, {recursive: true, force: true}).catch(debug)
} catch (error: any) {
debug(error)
await fs.remove(output)
await fs.rm(tmp, {recursive: true, force: true}).catch(debug)
}
}

const from = path.join(tmp, basename)
debug('moving %s to %s', from, output)
await fs.rename(from, output)
await fs.remove(tmp).catch(debug)
await fs.rm(tmp, {recursive: true, force: true}).catch(debug)
await touch(output)
debug('done extracting')
} catch (error: any) {
await fs.remove(tmp).catch(process.emitWarning)
await fs.rm(tmp, {recursive: true, force: true}).catch(process.emitWarning)
throw error
}
}
Loading

0 comments on commit 959dc93

Please sign in to comment.