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

ref(sveltekit): Improve auto-instrumentation applicability check #8083

Merged
merged 2 commits into from May 24, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented May 9, 2023

This PR improves the canWrapLoad check for our load auto-instrumentation. Previously, we used a few regexes to strip comments and match certain syntax for auto-wrapping. This proved to be quite brittle and we had to fix some cases (#8049). I just found another case that wasn't handled correctly before so I decided to switch to parsing the module and walking the AST. For this application, IMO AST walking is safer than some brittle regex check, so I vote we go with this approach.

I chose MagicAST despite the fact that we only inspect the AST and don't modify it because:

  • we already use it in the wizard and we might want/need to port this functionality over
  • it uses recast and babel under the hood which I would have chosen as an alternative anyway
  • we might actually revisit AST modification at some point so it doesn't hurt to already use magicast under the hood.

This check should now cover all possible export statement types that are permitted by SvelteKit. We don't need to handle the rest of the possibilites for export syntax because their not applicable in SvelteKit.

@Lms24 Lms24 self-assigned this May 9, 2023
@Lms24 Lms24 requested review from lforst and AbhiPrasad and removed request for lforst May 9, 2023 14:29
'function declaration with different string literal name',
`import { foo } from 'somewhere';
async function somethingElse(){};
export { somethingElse as "load", foo }`,
Copy link
Member Author

@Lms24 Lms24 May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL string literals are legal here

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2023

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.03 KB (+0.06% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 65.68 KB (+0.09% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 19.59 KB (+0.11% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 58.15 KB (+0.12% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.2 KB (+0.15% 🔺)
@sentry/browser - Webpack (minified) 69.07 KB (+0.05% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.22 KB (+0.16% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 49.16 KB (+0.09% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 28.67 KB (+0.1% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 26.9 KB (+0.1% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 48.25 KB (+1.33% 🔺)
@sentry/replay - Webpack (gzipped + minified) 42.1 KB (+1.55% 🔺)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 67.22 KB (+1.08% 🔺)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 60.11 KB (+1.24% 🔺)

@Lms24 Lms24 force-pushed the lms/sveltekit-improve-canWrapLoad branch from e955226 to 4eae534 Compare May 9, 2023 15:13
@Lms24 Lms24 marked this pull request as draft May 11, 2023 15:04
@Lms24
Copy link
Member Author

Lms24 commented May 11, 2023

draft until #8094 is merged, then we can adjust this PR accordingly.
Edit: Done

@Lms24 Lms24 force-pushed the lms/sveltekit-improve-canWrapLoad branch from 4eae534 to df5667a Compare May 24, 2023 07:02
@Lms24 Lms24 marked this pull request as ready for review May 24, 2023 07:03
@Lms24 Lms24 merged commit 1c4726c into develop May 24, 2023
62 checks passed
@Lms24 Lms24 deleted the lms/sveltekit-improve-canWrapLoad branch May 24, 2023 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants