@@ -26,14 +26,23 @@ const helpers = require('./helpers.js');
2626class spawnpoint extends EventEmitter {
2727 /**
2828 * Creates new instance of spawnpoint
29- * @param {string } [configFile] Sets the JSON file spawnpoint uses to setup the framework.
29+ * @param {string|Object } [configFile] Sets the JSON file spawnpoint uses to setup the framework, or an options object.
30+ * @param {string } [configFile.configFile='/config/app.json'] Path to the config file when using options object.
31+ * @param {string } [configFile.cwd=process.cwd()] Working directory for the applicationndash avoids needing process.chdir().
3032 * @return {this }
3133 */
3234 constructor ( configFile = '/config/app.json' ) {
3335 // init EventEmitter
3436 super ( ) ;
3537
36- if ( typeof ( configFile ) !== 'string' ) {
38+ // Support options object for more flexibility
39+ let options = { } ;
40+ if ( typeof configFile === 'object' && configFile !== null && ! Array . isArray ( configFile ) ) {
41+ options = configFile ;
42+ configFile = options . configFile || '/config/app.json' ;
43+ }
44+
45+ if ( typeof configFile !== 'string' ) {
3746 throw new TypeError ( '`configFile` must be a path string to a Spawnpoint config file.' ) ;
3847 }
3948 if ( ! configFile . endsWith ( '.json' ) && ! configFile . endsWith ( '.js' ) ) {
@@ -51,8 +60,8 @@ class spawnpoint extends EventEmitter {
5160 stopAttempts : 0 , // how many attempts to stop have been triggered
5261 } ;
5362
54- // app CWD
55- this . cwd = process . cwd ( ) ;
63+ // app CWD - can be passed via options to avoid process.chdir()
64+ this . cwd = options . cwd || process . cwd ( ) ;
5665
5766 // detect if we are in a container (lazy-loaded on first access)
5867 this . _containerized = null ;
@@ -283,6 +292,8 @@ class spawnpoint extends EventEmitter {
283292 if ( typeof ( exts ) === 'string' ) {
284293 exts = [ exts ] ;
285294 }
295+ // normalize path separators for cross-platform support
296+ dir = dir . replaceAll ( '\\' , '/' ) ;
286297 const list = [ ] ;
287298 let stat ;
288299 try {
@@ -293,8 +304,8 @@ class spawnpoint extends EventEmitter {
293304 if ( ! stat || ! stat . isDirectory ( ) ) {
294305 return list ;
295306 }
296- // ensure proper trailing slash and normalize path separators
297- dir = String ( dir + '/' ) . replaceAll ( '\\' , '/' ) ;
307+ // ensure proper trailing slash
308+ dir = String ( dir + '/' ) ;
298309
299310 // Use withFileTypes to avoid a stat for every entry (significantly faster)
300311 const stack = [ dir ] ;
0 commit comments