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

Entry point incorrectly parsed with prettiered index.html #353

Open
5 tasks done
geoffgscott opened this issue May 29, 2023 · 0 comments
Open
5 tasks done

Entry point incorrectly parsed with prettiered index.html #353

geoffgscott opened this issue May 29, 2023 · 0 comments

Comments

@geoffgscott
Copy link

Describe the bug

When prettier formats the index.html the regex to detect entrypoint seems to fail and falls back to src/main.ts. Looks to be directly related to the scriptsSrcRegex. Test case below:

const reg =
  /<script(?:.*?)src=["'](.+?)["'](?!<)(?:.*)>(?:[\n\r\s]*?)(?:<\/script>)/gim

const htmlPrettier = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <link
      rel="icon"
      href="favicon.ico" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0" />
    <title>Published</title>
  </head>
  <body>
    <div
      id="app"
      class="app"></div>
    <script
      type="module"
      src="./main.ts"></script>
  </body>
</html>`

const html = `<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <link rel="icon" href="favicon.ico">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Published</title>
  </head>
  <body>
    <div id="app" class="app"></div>
    <script type="module" src="./main.ts"></script>
  </body>
</html>`

console.log('Multiline', ...htmlPrettier.matchAll(reg))
console.log('SingleLine', ...html.matchAll(reg))

Reproduction

See above test case

System Info

System:
    OS: Linux 6.3 Arch Linux
    CPU: (16) x64 Intel(R) Xeon(R) W-11955M CPU @ 2.60GHz
    Memory: 43.84 GB / 62.54 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  Browsers:
    Chromium: 114.0.5735.45
    Firefox: 113.0.2

Used Package Manager

pnpm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant