Skip to content

Commit

Permalink
feat: Add Ability to use cjs file extenstion for config file (#169)
Browse files Browse the repository at this point in the history
* Update constants.ts

* Update createBuildConfigs.ts

* chore: apply dts lint --fix

Co-authored-by: 唯然 <weiran.zsd@outlook.com>
  • Loading branch information
The-Code-Monkey and aladdin-add committed Aug 15, 2022
1 parent 1b214df commit 15929a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const paths = {
appDist: resolveApp('dist'),
appConfigJs: resolveApp('dts.config.js'),
appConfigTs: resolveApp('dts.config.ts'),
appConfigCjs: resolveApp('dts.config.cjs'),
jestConfig: resolveApp('jest.config.js'),
progressEstimatorCache: resolveApp('node_modules/.cache/.progress-estimator'),
};
6 changes: 6 additions & 0 deletions src/createBuildConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ function getDtsConfig(): DtsConfig {
dtsConfig = loadDtsConfigTs();
} else if (fs.existsSync(paths.appConfigJs)) {
dtsConfig = loadDtsConfigJs();
} else if (fs.existsSync(paths.appConfigCjs)) {
dtsConfig = loadDtsConfigCjs();
}

return isDtsConfig(dtsConfig) ? dtsConfig : configDefaults;
Expand Down Expand Up @@ -144,6 +146,10 @@ function loadDtsConfigJs(): DtsConfig | undefined {
return require(paths.appConfigJs);
}

function loadDtsConfigCjs(): DtsConfig | undefined {
return require(paths.appConfigCjs);
}

function isDtsConfig(required: any): required is DtsConfig {
return isDefined(required) && isDefined(required);
}
Expand Down

0 comments on commit 15929a3

Please sign in to comment.