Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oclif readme only searches for LF in regex, not CRLF, which makes it incompatible on windows #793

Open
LinderVII opened this issue Jan 11, 2022 · 0 comments
Labels
help wanted Accepting PRs windows Windows-only issue

Comments

@LinderVII
Copy link

readme = readme.replace(new RegExp(`<!-- ${tag} -->(.|\n)*<!-- ${tag}stop -->`, 'm'), `<!-- ${tag} -->`)

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:

  1. Just use LF in vs code
  2. 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 ^^

@mdonnalley mdonnalley added help wanted Accepting PRs windows Windows-only issue labels Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Accepting PRs windows Windows-only issue
Projects
None yet
Development

No branches or pull requests

2 participants