Redwood: `yarn rw dev` fails when base path includes space

Created on 25 May 2020  路  3Comments  路  Source: redwoodjs/redwood

_original forum topic "Yarn rw dev throwing AssertionError (Windows10)"_

On both Windows and Mac (reproduced on my machine), when there is a space in the project path, yarn rw dev is throwing a Yargs assertion error that no command options are found in dev.js:


See Error Details

$ yarn rw dev                       
yarn run v1.22.4
$ '/Users/price/Repos/xx delete/xx-delete-again/node_modules/.bin/rw' dev
Dev BASE_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again
Dev API_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again/api
Dev WEB_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again/web
rw dev [app..]

Run development servers for db, api, and web.

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --app              [choices: "db", "api", "web"] [default: ["db","api","web"]]

AssertionError [ERR_ASSERTION]: [concurrently] no commands provided
    at module.exports (/Users/price/Repos/redwoodjs-redwood/node_modules/concurrently/src/concurrently.js:24:12)
    at module.exports (/Users/price/Repos/redwoodjs-redwood/node_modules/concurrently/index.js:21:12)
    at Object.handler (/Users/price/Repos/redwoodjs-redwood/packages/cli/dist/commands/dev.js:80:29)
    at Object.runCommand (/Users/price/Repos/redwoodjs-redwood/node_modules/yargs/lib/command.js:240:40)
    at Object.parseArgs [as _parseArgs] (/Users/price/Repos/redwoodjs-redwood/node_modules/yargs/yargs.js:1154:41)
    at Object.get [as argv] (/Users/price/Repos/redwoodjs-redwood/node_modules/yargs/yargs.js:1088:21)
    at Object.<anonymous> (/Users/price/Repos/redwoodjs-redwood/packages/cli/dist/index.js:20:171)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: 0,
  expected: 0,
  operator: 'notStrictEqual'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I confirmed all paths are correct per console.log:

BASE_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again
API_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again/api
WEB_DIR:  /Users/price/Repos/xx\ delete/xx-delete-again/web

Diagnoses

It seems the error was introduced in #490 with the use of fs.existsSync(). For our use, when checking a path including a space, it returns false. This explains why Yargs is complaining there are no commands.

Tests confirm the following:

  • given API_DIR = '/Users/price/Repos/xx\ delete/xx-delete-again/api'
  • fs.existsSync(API_DIR) returns false
    ...however...
  • 馃憠fs.existsSync('/Users/price/Repos/xx\ delete/xx-delete-again/api') returns true

So the method _can_ handle spaces. It's just not happy with the way we are passing in the variable

I'm at a bit of a loss 馃

Other CLI uses of fs.existsSync

This method is also used in the following commands. After determining a fix (or replacement), we should check the following and update as needed:

  • [ ] redwoodtools.js
  • [ ] build.js
  • [ ] auth.js
  • [ ] scaffold.js
  • [ ] index.js
  • [ ] create-redwood-app.js
bu2-confirmed cli

All 3 comments

I think the problem is this line: https://github.com/redwoodjs/redwood/blob/22ba0bd97ffd171db262ab55a2026e51df48fa49/packages/cli/src/commands/dev.js#L16-L18

We need to pass an unescaped version of BASE_DIR into the fs.existsSync command. I've recently added getPaths().api.base and getPaths().web.base, so we could use that instead of the "sanitised version."

I think the root cause here is with concurrently, since it doesn't allow us to programatically set the cwd, we pass in a command like so: cd ${API_DIR} && yarn dev-server

I added an issue to concurrently.

The error is coming from these lines:

https://github.com/redwoodjs/redwood/blob/22ba0bd97ffd171db262ab55a2026e51df48fa49/packages/cli/src/commands/dev.js#L27

https://github.com/redwoodjs/redwood/blob/22ba0bd97ffd171db262ab55a2026e51df48fa49/packages/cli/src/commands/dev.js#L36

https://github.com/redwoodjs/redwood/blob/22ba0bd97ffd171db262ab55a2026e51df48fa49/packages/cli/src/commands/dev.js#L45

For some reason, fs.existsSync(X_DIR) _always_ returns false if the variable path contains a space (or an escaped space, i.e. \). This is why the Yargs command option array ends up being empty -- no jobs are added to the run on this line:
https://github.com/redwoodjs/redwood/blob/22ba0bd97ffd171db262ab55a2026e51df48fa49/packages/cli/src/commands/dev.js#L52

Update

I'm making some progress using getPaths().api.base and getPaths().web.base. Need to iron out a few remaining issues and then test on Windows.

@thedavidprice I think this was fixed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterp picture peterp  路  4Comments

josteph picture josteph  路  3Comments

weaversam8 picture weaversam8  路  4Comments

jtoar picture jtoar  路  4Comments

jeliasson picture jeliasson  路  3Comments