diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-01-09 22:16:29 +0100 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-01-09 22:17:26 +0100 |
commit | fb7118ff1c8f0dcd61f15e51b193512283d83fa1 (patch) | |
tree | 721cee6a64b44a56b7f05f39750a65cda5fb4ef6 /packages/main/src/services | |
parent | build: Add eslint-plugin-jest (diff) | |
download | sophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.tar.gz sophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.tar.zst sophie-fb7118ff1c8f0dcd61f15e51b193512283d83fa1.zip |
build: Add eslint-plugin-unicorn
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/services')
-rw-r--r-- | packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts index e92f706..a11a9da 100644 --- a/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts +++ b/packages/main/src/services/impl/ConfigPersistenceServiceImpl.ts | |||
@@ -17,9 +17,9 @@ | |||
17 | * | 17 | * |
18 | * SPDX-License-Identifier: AGPL-3.0-only | 18 | * SPDX-License-Identifier: AGPL-3.0-only |
19 | */ | 19 | */ |
20 | import { watch } from 'fs'; | 20 | import { watch } from 'node:fs'; |
21 | import { readFile, stat, writeFile } from 'fs/promises'; | 21 | import { readFile, stat, writeFile } from 'node:fs/promises'; |
22 | import { join } from 'path'; | 22 | import path from 'node:path'; |
23 | 23 | ||
24 | import JSON5 from 'json5'; | 24 | import JSON5 from 'json5'; |
25 | import throttle from 'lodash-es/throttle'; | 25 | import throttle from 'lodash-es/throttle'; |
@@ -39,26 +39,26 @@ export default class ConfigPersistenceServiceImpl | |||
39 | 39 | ||
40 | private writingConfig = false; | 40 | private writingConfig = false; |
41 | 41 | ||
42 | private timeLastWritten: Date | null = null; | 42 | private timeLastWritten: Date | undefined; |
43 | 43 | ||
44 | constructor( | 44 | constructor( |
45 | private readonly userDataDir: string, | 45 | private readonly userDataDir: string, |
46 | private readonly configFileName: string = 'config.json5', | 46 | private readonly configFileName: string = 'config.json5', |
47 | ) { | 47 | ) { |
48 | this.configFileName = configFileName; | 48 | this.configFileName = configFileName; |
49 | this.configFilePath = join(this.userDataDir, this.configFileName); | 49 | this.configFilePath = path.join(this.userDataDir, this.configFileName); |
50 | } | 50 | } |
51 | 51 | ||
52 | async readConfig(): Promise<ReadConfigResult> { | 52 | async readConfig(): Promise<ReadConfigResult> { |
53 | let configStr; | 53 | let configStr; |
54 | try { | 54 | try { |
55 | configStr = await readFile(this.configFilePath, 'utf8'); | 55 | configStr = await readFile(this.configFilePath, 'utf8'); |
56 | } catch (err) { | 56 | } catch (error) { |
57 | if ((err as NodeJS.ErrnoException).code === 'ENOENT') { | 57 | if ((error as NodeJS.ErrnoException).code === 'ENOENT') { |
58 | log.debug('Config file', this.configFilePath, 'was not found'); | 58 | log.debug('Config file', this.configFilePath, 'was not found'); |
59 | return { found: false }; | 59 | return { found: false }; |
60 | } | 60 | } |
61 | throw err; | 61 | throw error; |
62 | } | 62 | } |
63 | log.info('Read config file', this.configFilePath); | 63 | log.info('Read config file', this.configFilePath); |
64 | return { | 64 | return { |
@@ -92,8 +92,8 @@ export default class ConfigPersistenceServiceImpl | |||
92 | const stats = await stat(this.configFilePath); | 92 | const stats = await stat(this.configFilePath); |
93 | mtime = stats.mtime; | 93 | mtime = stats.mtime; |
94 | log.trace('Config file last modified at', mtime); | 94 | log.trace('Config file last modified at', mtime); |
95 | } catch (err) { | 95 | } catch (error) { |
96 | if ((err as NodeJS.ErrnoException).code === 'ENOENT') { | 96 | if ((error as NodeJS.ErrnoException).code === 'ENOENT') { |
97 | log.debug( | 97 | log.debug( |
98 | 'Config file', | 98 | 'Config file', |
99 | this.configFilePath, | 99 | this.configFilePath, |
@@ -101,11 +101,11 @@ export default class ConfigPersistenceServiceImpl | |||
101 | ); | 101 | ); |
102 | return; | 102 | return; |
103 | } | 103 | } |
104 | throw err; | 104 | throw error; |
105 | } | 105 | } |
106 | if ( | 106 | if ( |
107 | !this.writingConfig && | 107 | !this.writingConfig && |
108 | (this.timeLastWritten === null || mtime > this.timeLastWritten) | 108 | (this.timeLastWritten === undefined || mtime > this.timeLastWritten) |
109 | ) { | 109 | ) { |
110 | log.debug( | 110 | log.debug( |
111 | 'Found a config file modified at', | 111 | 'Found a config file modified at', |