oclif readme only searches for LF in regex, not CRLF, which makes it incompatible on windows
Author: LinderVIICreated Jan 11, 2022Updated Mar 5, 2024
Labelshelp wantedwindows
Expected result after running npx oclif readme is that all 3 tags are replaced. Actual result on windows with CRLF:
<!-- usage -->
sh-session
$ npm install -g package
$ package COMMAND
running command...
$ package(--version)
package/1.2.6 win32-x64 node-v16.13.1
$ package --help [COMMAND]
USAGE
$ package COMMAND
...
<!-- usagestop -->
sh-session
$ npm install -g package
$ package COMMAND
running command...
$ package (--version)
package/1.2.6 win32-x64 node-v16.13.1
$ package--help [COMMAND]
USAGE
$ package COMMAND
...
<!-- usagestop -->This is because the replace command dosent replace the tags and the body in the tags with <!-- usage -->. So when line 78 in readme.ts is executed it replaces the first tag and the rest of the body and the stop tag is left.
Possible mitigations: replace all occurences with \r\n with \n in commands/readme.ts. (readme = readme.replaceAll('\r\n', '\n')) or extends the regex to match \r\n as well.
Possible workarounds:
- Just use LF in vs code
- Make a script to replace CRLF with LF before running oclif readme. This can then be inserted into the prepack command in package.json. For example: "prepack": "yarn build && oclif manifest && node prepreadme.js && oclif readme" prepreadme.js:
const fs = require('fs')
const path = require('path')
const cwd = process.cwd()
const readmePath = path.resolve(cwd, 'README.md')
fs.readFile(readmePath, 'utf8', (err, readme) => {
readme = readme.replaceAll('\r\n', '\n')
fs.writeFile(readmePath, readme, () => console.log('replace \\r\\n with \\n readme.md'))
})Otherwise oclif works well on windows ^^
Source: oclif/oclif