Skip to content

Commit

Permalink
fix(cli): use temp file to prevent empty config
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 12, 2024
1 parent 2e7e3e5 commit b714847
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Awaitable, defineProperty, Time } from 'cosmokit'
import { Bot, h, Schema, Universal } from '@satorijs/core'
import { Bot, Fragment, h, Schema, Universal } from '@satorijs/core'
import { Command } from './command'
import { Argv } from './parser'
import validate from './validate'
Expand All @@ -25,7 +25,7 @@ declare module '../context' {
'command-updated'(command: Command): void
'command-removed'(command: Command): void
'command-error'(argv: Argv, error: any): void
'command/before-execute'(argv: Argv): Awaitable<void | string>
'command/before-execute'(argv: Argv): Awaitable<void | Fragment>
'command/before-attach-channel'(argv: Argv, fields: Set<Channel.Field>): void
'command/before-attach-user'(argv: Argv, fields: Set<User.Field>): void
}
Expand Down
5 changes: 3 additions & 2 deletions packages/loader/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ export abstract class Loader {
throw new Error(`cannot overwrite readonly config`)
}
if (this.mime === 'application/yaml') {
await fs.writeFile(this.filename, yaml.dump(this.config))
await fs.writeFile(this.filename + '.tmp', yaml.dump(this.config))
} else if (this.mime === 'application/json') {
await fs.writeFile(this.filename, JSON.stringify(this.config, null, 2))
await fs.writeFile(this.filename + '.tmp', JSON.stringify(this.config, null, 2))
}
await fs.rename(this.filename + '.tmp', this.filename)
if (!silent) this.app.emit('config')
}

Expand Down

0 comments on commit b714847

Please sign in to comment.