Unexpected error when specifying a wildcarded path for linting on Windows
dmitri-trofimov opened this issue · 0 comments
Describe the bug
When trying to run @redocly/cli lint
and providing a wildcarded path on Windows the command exist with exit code 1
without any error text.
To Reproduce
Steps to reproduce the behavior:
- Make sure you are on Windows. I used v11, and Node 20, but it's also reproducible on Node v18. Haven't tried other Nodes.
- Create an empty Node.js project by running
npm init
in a directory of your choice - Add
@redocly/cli
to your project by runningnpm install @redocly/cli
- Create a very simple project structure:
<ROOT>
├─ api
│ └─ providers
│ └─ test-provider
│ └─ api.yaml (put "hello world" in this file, I know it's invalid YAML, but it doesn't matter)
- Run
npx @redocly/cli lint api/providers/*/api.yaml
in the root folder
Expected behavior
I would expect to see the following text with an error on screen:
No configurations were provided -- using built in recommended configuration by default.
validating api/providers/test-provider/api.yaml...
Something went wrong when processing api/providers/test-provider/api.yaml:
- Document must be JSON object, got string.
Actual behavior
Nothing is displayed. Command exits with exit code 1.
Node.js
Version(s)
20
Additional context
I managed to find the cause of this issue. When lint
is called we get the following sequence of calls:
handleLint // redocly-cli/packages/cli/src/commands/lint.ts: line 40
getgetFallbackApisOrExit // redocly-cli/packages/cli/src/commands/lint.ts: line 41
expandGlobsInEntrypoints // redocly-cli/packages/cli/src/utils/misceleneous.ts: line 51
And in the expandGlobsInEntrypoints
we have this line:
? (await glob.__promisify__(aliasOrPath)).map((g: string) => getAliasOrPath(config, g))
You can see the call to __promisify__
function which does not exist on glob
. I don't really know the reason why @types/glob
added this, but the function does not exist and the correct way to promisify this would be:
// redocly-cli/packages/cli/src/utils/misceleneous.ts
import { promisify } from 'utils';
// expandGlobsInEntrypoints
/* line 109 */ await promisify(glob)(aliasOrPath).map(...)