Skip to content

Commit

Permalink
Merge pull request #48 from gjsify/main
Browse files Browse the repository at this point in the history
Fix config file loading
  • Loading branch information
JumpLink authored Feb 3, 2022
2 parents e1dacad + 93fcf1e commit 355c62f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Refactor Ava test

# v2.0.0
- Fix config file loading, see #48
- The browser example now uses ESM for Gjs and Node.js
- Upgrade all dependencies to latest
- [node-gtk] don't add $obj parameter in connect() method either, thanks to @peat-psuwit
Expand Down Expand Up @@ -37,7 +38,7 @@

## Breaking Changes
- Node.js minimum version is now 16 for ESM support
- The config files must now also be in ESM format, if they are not in json format:
- The config files must also be in ESM format if you are inside a ESM Package, this is the case if `"type": "module"` is defined in your package.json. Alternatively, the file can be saved in json format, then it works in both cases.


See PR [#44](https://github.com/sammydre/ts-for-gjs/pull/44)
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ In addition to the option of passing options as a CLI flag, you can also write t
To do that, create a new config file called `.ts-for-girrc.js` in your project root directory, like this:
```js
// or on CommonJs: exports.default = {
export default {
pretty: false,
print: false,
Expand All @@ -170,6 +171,8 @@ export default {
}
```
The javascript config files must also be in ESM format if you are inside a ESM Package, this is the case if `"type": "module"` is defined in your package.json. Alternatively, the file can be saved in json format, then it works in both cases.
### About the `--moduleType esm` option
Gjs now supports ES modules, which can be activated with its `gjs -m` flag. Using this in conjunction with `"module": "es6"` in tsconfig.json is generally more
Expand Down
13 changes: 10 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,16 @@ export class Config {
'.js': async (filepath) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const file = await import(filepath)
if (file.default) {

// Files with `exports.default = { ... }`
if (file?.default?.default) {
return file.default.default as Partial<UserConfig>
}
// Files with `export default { ... }`
if (file?.default) {
return file.default as Partial<UserConfig>
}
// Files with `export { ... }`
return file as Partial<UserConfig>
},
},
Expand Down Expand Up @@ -293,11 +300,11 @@ export class Config {
config.environments = configFile.config.environments
}
// buildType
if (configFile.config.buildType) {
if (config.buildType === Config.options.buildType.default && configFile.config.buildType) {
config.buildType = configFile.config.buildType
}
// moduleType
if (configFile.config.moduleType) {
if (config.moduleType === Config.options.moduleType.default && configFile.config.moduleType) {
config.moduleType = configFile.config.moduleType
}
// verbose
Expand Down

0 comments on commit 355c62f

Please sign in to comment.