@@ -8,6 +8,7 @@ import { parsePlugin, getProcessTime, getDefaultInitLog, getLogPath, getPluginRe
88import { INIT_STEP_COUNT , INIT_STEP_NAME , COMPLETED_STEP_COUNT , DEFAULT_COMPLETED_LOG , SERVERLESS_CD_KEY , SERVERLESS_CD_VALUE } from './constants' ;
99import execDaemon from './exec-daemon' ;
1010import { filter , join } from 'lodash' ;
11+ import fs from 'fs' ;
1112
1213export { IStepOptions , IContext } from './types' ;
1314
@@ -382,6 +383,14 @@ class Engine {
382383 }
383384 }
384385 }
386+ private validateWorkingDirectory ( path : string ) {
387+ if ( ! fs . existsSync ( path ) ) {
388+ throw new Error ( `Invalid working directory: ${ path } ` ) ;
389+ }
390+ if ( ! fs . statSync ( path ) . isDirectory ( ) ) {
391+ throw new Error ( `Path is not a directory: ${ path } ` ) ;
392+ }
393+ }
385394 private outputErrorLog ( error : Error ) {
386395 const logConfig = this . options . logConfig as ILogConfig ;
387396 const { customLogger } = logConfig ;
@@ -398,6 +407,9 @@ class Engine {
398407 if ( runItem . run ) {
399408 debug ( `run: ${ runItem . run } ` ) ;
400409 let execPath = runItem [ 'working-directory' ] || this . context . cwd ;
410+ if ( execPath ) {
411+ this . validateWorkingDirectory ( execPath ) ;
412+ }
401413 execPath = path . isAbsolute ( execPath ) ? execPath : path . join ( this . context . cwd , execPath ) ;
402414 this . logName ( item ) ;
403415 runItem . run = this . doArtTemplateCompile ( runItem . run ) ;
0 commit comments