Skip to content

Commit

Permalink
fix(cli): support export default
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Apr 6, 2021
1 parent 27da2e5 commit 8a20fa7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const displayWarning = display(yellow('warning:'))
let code = 0

function bundle(options: BuildOptions) {
for (const path of options.entryPoints) {
for (const path of options.entryPoints as string[]) {
if (process.env.CI) console.log('entry:', path)
}
return build(options).then(({ warnings }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async function writeConfig(config: any, path: string, type: SourceType) {
if (type === 'js') {
output = '// ' + rootComment + '\nmodule.exports = ' + output
} else if (type === 'ts') {
output = '// ' + rootComment + '\nexport = ' + output
output = '// ' + rootComment + '\nexport default ' + output
}

// write to file
Expand Down
5 changes: 4 additions & 1 deletion packages/koishi/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function tryCallback<T>(callback: () => T) {
}
}

const config: AppConfig = tryCallback(() => require(configFile))
const config: AppConfig = tryCallback(() => {
const exports = require(configFile)
return exports.__esModule ? exports.default : exports
})

if (!config) {
throw new Error(`config file not found. use ${yellow('koishi init')} command to initialize a config file.`)
Expand Down

0 comments on commit 8a20fa7

Please sign in to comment.