Skip to content

Commit

Permalink
fixes #1699 - config.get is not a function (#1701)
Browse files Browse the repository at this point in the history
  • Loading branch information
GiladShoham authored Jun 3, 2019
1 parent c17f725 commit c6b2729
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [unreleased]

- [#1699](https://github.com/teambit/bit/issues/1699) fix config.get is not a function

## [14.1.2] - 2019-06-02

### New
Expand Down
34 changes: 21 additions & 13 deletions src/global-config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,32 @@ export default class Config extends Map<string, string> {

static loadSync(): Config {
try {
const contents = fs.readFileSync(getPath());
const configPath = getPath();
if (!fs.existsSync(configPath)) {
const config = new Config([]);
config.writeSync();
return config;
}
const contents = fs.readFileSync(configPath);
return new Config(objectToTupleArray(JSON.parse(contents.toString())));
} catch (err) {
if (err.code !== 'ENOENT') return err;
const config = new Config([]);
config.writeSync();
return config;
return err;
}
}

static load(): Promise<Config> {
return fs
.readFile(getPath())
.then(contents => new Config(objectToTupleArray(JSON.parse(contents.toString()))))
.catch((err) => {
if (err.code !== 'ENOENT') return err;
static async load(): Promise<Config> {
try {
const configPath = getPath();
const exists = await fs.exists(configPath);
if (!exists) {
const config = new Config([]);
return config.write().then(() => config);
});
await config.write();
return config;
}
const contents = await fs.readFile(configPath);
return new Config(objectToTupleArray(JSON.parse(contents.toString())));
} catch (err) {
return err;
}
}
}

0 comments on commit c6b2729

Please sign in to comment.