balderdashy / balderdashy/sails
Can't run scripts by `script\name.js` on Windows
- Dominant language
- JavaScript
- Stars
- 22.8k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
**Sails version**: 1.0.2
**Node version**: 11.5.0
**NPM version**: 6.5.0
**DB adapter name**: N/A
**DB adapter version**: N/A
**Operating system**: Windows 10
According to the documentation for scripts, they can be run using either the name (i.e. `sails run script-name`) or the folder path and full filename (i.e. `sails run scripts/script-name.js`).
However, the RegEx [here](https://github.com/balderdashy/sails/blob/d5775cdb68fe12680e87652c23bf300c75417b15/bin/sails-run.js#L68) only checks for a forward slash, meaning that this code does not work on Windows:
```
scriptName = scriptName.replace(/^scripts\//, '');
```
If you try to run `sails run scripts\script-name.js`, you get the following error:
> ```
> Unknown script: `scripts\script-name`
> No matching script is defined at `scripts/scripts\script-name.js`.
> (And there is no matching NPM script in the package.json file.)
> ```
Fixing this is very simple, the RegEx needs to be changed to this, which checks for either type of slash:
```
scriptName = scriptName.replace(/^scripts[\\/]/, '');
```
Contributor guide
Research direction
Start in bin/sails-run.js at the scriptName normalization shown in the issue, and compare behavior for forward- and backslash paths on Windows. Reproduce with `sails run scripts\script-name.js`; done means the script is found and runs using the documented folder-path form without the unknown-script error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100