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

🐛 Bug: SyntaxError on description with regexp characters #803

Closed
3 tasks done
JoshuaKGoldberg opened this issue Sep 5, 2023 · 3 comments · Fixed by #861
Closed
3 tasks done

🐛 Bug: SyntaxError on description with regexp characters #803

JoshuaKGoldberg opened this issue Sep 5, 2023 · 3 comments · Fixed by #861
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(

Comments

@JoshuaKGoldberg
Copy link
Owner

Bug Report Checklist

  • I have tried restarting my IDE and the issue persists.
  • I have pulled the latest main branch of the repository.
  • I have searched for related issues and found none that matched my issue.

Expected

Setup scripts such as --mode migrate should be able to plop in descriptions with special characters like ^ and $.

Actual

┌  Welcome to create-typescript-app ! 🎉
│
│  ⚠️ This template is early stage, opinionated, and not endorsed by the TypeScript team. ⚠️
│  ⚠️ If any tooling it sets displeases you, you can always remove that portion manually. ⚠️
│
◇  What organization or user will the repository be under?
│  JoshuaKGoldberg
│
◇  What will the kebab-case name of the repository be?
│  eslint-plugin-expect-type
│
◇  ✅ Passed checking GitHub authentication.
│
◇  How would you describe the new package?
│  ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩
│
◇  What will the Title Case title of the repository be?
│  eslint-plugin-expect-type
│
◇  Migrating repository structure...
│   - Clearing unnecessary files ✔️
│   - Writing structure ✔️
│   - Writing README.md ✔️
│   - Updating local files.│  ❌ Error migrating repository structure > updating local files.
│
Error: Failed migrating repository structure > updating local files
    at withSpinners (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/shared/cli/spinners.js:42:11)
    at async migrateWithOptions (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/migrate/migrateWithOptions.js:15:3)
    ... 4 lines matching cause stack trace ...
    at async file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/bin/index.js:4:20 {
  [cause]: SyntaxError: Invalid regular expression: /ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩/g: Nothing to repeat
      at new RegExp (<anonymous>)
      at updateLocalFiles (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/steps/updateLocalFiles.js:31:7)
      at async file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/migrate/migrateWithOptions.js:32:9
      at async withSpinners (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/shared/cli/spinners.js:28:7)
      at async migrateWithOptions (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/migrate/migrateWithOptions.js:15:3)
      at async run (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/migrate/index.js:19:9)
      at async runOrRestore (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/shared/runOrRestore.js:7:5)
      at async Object.migrate (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/migrate/index.js:17:11)
      at async bin (file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/lib/bin/index.js:44:29)
      at async file:///Users/josh/.npm/_npx/4aa729db9999bfc4/node_modules/create-typescript-app/bin/index.js:4:20
}
│
◇  Do you want to restore the repository to how it was?
│  No
│
●  Tip: to run again with the same input values, use: npx create-typescript-app --mode migrate --author JoshuaKGoldberg --base everything --description "ESLint plugin with ^? Twoslash, $ExpectError, and $ExpectType type assertions. 🧩" --email npm@joshuakgoldberg.com --owner JoshuaKGoldberg --repository eslint-plugin-expect-type --title eslint-plugin-expect-type
│
└  Operation cancelled. Exiting - maybe another time? 👋

Additional Info

Discovered working on JoshuaKGoldberg/eslint-plugin-expect-type#70.

@JoshuaKGoldberg JoshuaKGoldberg added type: bug Something isn't working :( status: accepting prs Please, send a pull request to resolve this! labels Sep 5, 2023
@JoshuaKGoldberg JoshuaKGoldberg added this to the Post-Rename Migration milestone Sep 5, 2023
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Sep 5, 2023
@JoshuaKGoldberg JoshuaKGoldberg removed their assignment Sep 5, 2023
@JoshuaKGoldberg
Copy link
Owner Author

JoshuaKGoldberg commented Sep 5, 2023

Interestingly, I think there are two touch points that make this a nontrivial issue:

  • The input regular expression in updateLocalFiles needs escaping.
  • The output description also needs some kind of escaping or swapping from regexp to plain text.
    • It kept getting printed as ESLint plugin with ^? Twoslash, , and type assertions. 🧩 (note the lack of $-prefixed words)...

Edit: OH the CLI output for a rerun suggestion was corrupting the description too! 😂

npx create-typescript-app --mode migrate --author JoshuaKGoldberg --base everything --description "ESLint plugin with ^? Twoslash, , and  type assertions. 🧩" --email npm@joshuakgoldberg.com --exclude-contributors true --owner JoshuaKGoldberg --repository eslint-plugin-expect-type --skip-github-api true --skip-install true --title eslint-plugin-expect-type

@JoshuaKGoldberg
Copy link
Owner Author

Properly escaping $s in the description on the CLI actually fixed the latter.

node ~/repos/create-typescript-app/bin/index.js --mode migrate --author JoshuaKGoldberg --base everything --description "ESLint plugin with ^? Twoslash, \$ExpectError, and \$ExpectType type assertions. <0001f9e9>" --email npm@joshuakgoldberg.com --owner JoshuaKGoldberg --repository eslint-plugin-expect-type --title eslint-plugin-expect-type --skip-github-api --exclude-contributors --skip-install

JoshuaKGoldberg added a commit that referenced this issue Sep 21, 2023
## PR Checklist

- [x] Addresses an existing open issue: fixes #803
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/create-typescript-app/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/create-typescript-app/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Applies two tangentially related fixes:

* The original description can be replaced with a plain string - it
doesn't need a regular expression
* The rerun suggestion for descriptions should escape `$`s
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

🎉 This is included in version v1.32.0 🎉

The release is available on:

Cheers! 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Please, send a pull request to resolve this! type: bug Something isn't working :(
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant