One way to solve this is to use a regex replace, something like:

```
baseDir = ( baseDir || "" ).replace( /\/?$/, "/" );
```