11import path from 'node:path' ;
22import { debuglog } from 'node:util' ;
33
4+ import { getFrameworkPath } from '@eggjs/utils' ;
45import { Flags } from '@oclif/core' ;
56
67import { BaseCommand } from '../baseCommand.ts' ;
78
89const debug = debuglog ( 'egg/bin/commands/bundle' ) ;
10+ const bundleModes = [ 'production' , 'development' ] as const ;
11+ type BundleMode = ( typeof bundleModes ) [ number ] ;
912
10- export default class Bundle < T extends typeof Bundle > extends BaseCommand < T > {
13+ function getBundleMode ( mode : string ) : BundleMode {
14+ if ( mode === 'production' || mode === 'development' ) {
15+ return mode ;
16+ }
17+ throw new Error ( `Unsupported bundle mode: ${ mode } ` ) ;
18+ }
19+
20+ export default class Bundle extends BaseCommand < typeof Bundle > {
1121 static override description = 'Bundle an egg app into a deployable artifact using @eggjs/egg-bundler' ;
1222
1323 static override examples = [
@@ -33,7 +43,7 @@ export default class Bundle<T extends typeof Bundle> extends BaseCommand<T> {
3343 } ) ,
3444 mode : Flags . string ( {
3545 description : 'build mode' ,
36- options : [ 'production' , 'development' ] ,
46+ options : [ ... bundleModes ] ,
3747 default : 'production' ,
3848 } ) ,
3949 'no-tegg' : Flags . boolean ( {
@@ -43,10 +53,12 @@ export default class Bundle<T extends typeof Bundle> extends BaseCommand<T> {
4353 'force-external' : Flags . string ( {
4454 description : 'package name to always mark as external (repeatable)' ,
4555 multiple : true ,
56+ default : [ ] ,
4657 } ) ,
4758 'inline-external' : Flags . string ( {
4859 description : 'package name to force-inline even if auto-detected as external (repeatable)' ,
4960 multiple : true ,
61+ default : [ ] ,
5062 } ) ,
5163 } ;
5264
@@ -74,8 +86,8 @@ export default class Bundle<T extends typeof Bundle> extends BaseCommand<T> {
7486 baseDir,
7587 outputDir,
7688 manifestPath,
77- framework : flags . framework ,
78- mode : flags . mode as 'production' | 'development' ,
89+ framework : getFrameworkPath ( { framework : flags . framework , baseDir } ) ,
90+ mode : getBundleMode ( flags . mode ) ,
7991 tegg : ! flags [ 'no-tegg' ] ,
8092 externals : {
8193 force : flags [ 'force-external' ] ,
0 commit comments