Skip to content

Commit

Permalink
fix(LiteStorage): 修复 filepath 为目录时无效的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
renxia committed Jan 23, 2024
1 parent 2bc6e73 commit cd4842f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/common/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function safeJsonParse<T extends Record<string, string>>(input: string, u
if (typeof input === 'object') return input;
return (useJSON5 ? JSON5 : JSON).parse(input) as T;
} catch (error: any) {
if (useJSON5 && !JSON5) console.error('[safeJsonParse]JSON5 尚未加载, 请先调用方法 `tryLoadJSON5`');
if (!ignoreError) console.error('[safeJsonParse]parse error', error.message, error.stack);
}

Expand Down
10 changes: 5 additions & 5 deletions src/node/LiteStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ export class LiteStorage<T extends object = Record<string, unknown>> {
this.reload().then(() => this.barrier.open());
}
private init() {
const { filepath = 'ls.json', uuid, version } = this.options;
if (!filepath.endsWith('.json') && !filepath.endsWith('.toml')) {
this.options.filepath = resolve(this.baseDir, filepath, 'ls.json');
let { filepath = 'ls.json', uuid, version } = this.options;
if (!/\.(json5?|toml)$/i.test(filepath)) {
filepath = resolve(this.baseDir, filepath, 'ls.json');
}
this.isJson5 = /\.json5$/i.test(filepath);
this.isToml = /\.toml$/i.test(filepath);
this.options.filepath = resolve(this.baseDir, filepath);
this.isJson5 = /\.json5$/i.test(this.options.filepath);
this.isToml = /\.toml$/i.test(this.options.filepath);

this.cache = {
version,
Expand Down

0 comments on commit cd4842f

Please sign in to comment.