Skip to content

feat(remix): Add wizard for Remix. #387

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

Merged
merged 20 commits into from
Aug 18, 2023
Merged

feat(remix): Add wizard for Remix. #387

merged 20 commits into from
Aug 18, 2023

Conversation

onurtemizkan
Copy link
Collaborator

@onurtemizkan onurtemizkan commented Jul 31, 2023

Resolves: #364
Resolves: getsentry/sentry-javascript#8556
Resolves: getsentry/sentry-javascript#5486

Adds a wizard for auto-instrumenting Remix applications / generating and uploading sourcemaps.

  • Creates .sentryclirc
  • Updates build script in package.json to generate and upload sourcemaps.
  • Instruments root.tsx / root.jsx for Remix versions 1 and 2.
  • Instruments entry.client and entry.server for Remix versions 1 and 2.

Used recast for parts that magicast does not support yet.

@github-actions
Copy link

github-actions bot commented Jul 31, 2023

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Add wizard for Remix ([#387](https://github.com/getsentry/sentry-wizard/pull/387))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 9ac5e6f

@onurtemizkan onurtemizkan marked this pull request as draft July 31, 2023 14:44
@onurtemizkan onurtemizkan marked this pull request as ready for review August 9, 2023 10:52
@onurtemizkan onurtemizkan requested a review from Lms24 August 9, 2023 10:52
* Copied from sveltekit wizard
* We want to insert the init call on top of the file but after all import statements
*/
function getInitCallInsertionIndex(originalHooksModAST: Program): number {
Copy link
Member

Choose a reason for hiding this comment

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

If this is from the sveltekit wizard, @Lms24 do you think it's appropriate if we extract into a util?

return remixConfigModule?.default || {};
} catch (e: unknown) {
clack.log.error(
`Couldn't load ${REMIX_CONFIG_FILE}. Please make sure, you're running this wizard with Node 14 or newer`,
Copy link
Member

Choose a reason for hiding this comment

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

The wizard should we Node 14+ - is the another error message we can write?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Just removed it, but can't think of any other possible common issues to point out here.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Round 2 - thanks for sticking with this!

Comment on lines 59 to 67
const copiedBodyNodes = [...originalHooksModAST.body];
const lastImportDeclaration = copiedBodyNodes
.reverse()
.find((node) => node.type === 'ImportDeclaration');

const initCallInsertionIndex = lastImportDeclaration
? originalHooksModAST.body.indexOf(lastImportDeclaration) + 1
: 0;
return initCallInsertionIndex;
Copy link
Member

Choose a reason for hiding this comment

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

can we just run this in a for loop? More efficient than cloning, and iterating through twice.

for (let x = originalHooksModAST.body.length - 1; x >= 0; x--) {
  if (originalHooksModAST.body[x].type === 'ImportDeclaration') {
    return x + 1;
  }
}

return 0;

dsn: string,
originalHooksMod: ProxifiedModule<any>,
) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Copy link
Member

Choose a reason for hiding this comment

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

can we disable this lint rule for the entire file?

originalHooksModAST.body.splice(
initCallInsertionIndex,
0,
// @ts-ignore - string works here because the AST is proxified by magicast
Copy link
Member

Choose a reason for hiding this comment

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

let's make all these @ts-expect-error


if (hasSentryContent(originalEntryClient, originalEntryClientMod.$code)) {
// Bail out
clack.log.warn(
Copy link
Member

Choose a reason for hiding this comment

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

Since hasSentryContent already logs out, do we need to log out again here?

Comment on lines 158 to 159
} else {
if (
Copy link
Member

Choose a reason for hiding this comment

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

Can this become else if?

@@ -0,0 +1,509 @@
import type { ExportNamedDeclaration, Program } from '@babel/types';
Copy link
Member

Choose a reason for hiding this comment

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

Could we split up some of the utils in this file into their own files? Specifically I think anything using recast should live in their own file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved under codemods folder 👍

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

lgtm! lets wait till @Lms24 double checks though

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Looks great, thanks for figuring all of this out Onur! Really like the usage of recast whenever magicast doesn't work.

I still had a few comments but I think we're almost ready to get this in.

I also have a follow-up request but this should be done in a separate PR: SvelteKit and Next wizards automatically create a sample page that throws some client/server errors. Can we do something like this in the Remix wizard, too? If you think this is doable, I'll create an issue to track it.

await instrumentRootRoute(isV2, isTS);
} catch (e) {
clack.log.warn(`Could not instrument root route.
Please do it manually using instructions from https://docs.sentry.io/platforms/javascript/guides/remix/`);
Copy link
Member

Choose a reason for hiding this comment

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

I think for now this is fine. Once we put the wizard instructions into docs, I think it's likely that we'll refactor the remix docs so that the manual setup will be in its own page (similarly to Next and Svelte). We just have to adjust the links then. I added a task in the follow-up issue (getsentry/sentry#54615)

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Damn, almost missed that you also already created a sourcemaps wizard flow. Thanks a lot!

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

I just ran the wizard in a small remix app and found some more things (thanks for sticking with us here!):

  • Can we log out a clack.log.success for each file we touched/inserted code? I think this increases transparency for users so that they are informed what the wizard is doing (especially for those who ran it without being in a version controlled environment).

  • Let's make sure we're adding the file ending in this log:
    image

@onurtemizkan
Copy link
Collaborator Author

onurtemizkan commented Aug 14, 2023

@Lms24, @AbhiPrasad -- thanks for the reviews! Updated the PR.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for applying our feedback, Onur! Had one last comment then we can merge!

In preparation to merging, would you mind adding a note to CHANGELOG.md? In this repo, changelogs are semi-automatically generated. For each user-facing PR. we add an entry to CHANGELOG.md under (##Unreleased) and our release process will add it to the version entry for the version to be released. I think for this change, a small usage example would be nice. See the entry for the SvelteKit wizard.

Comment on lines 61 to 66
${chalk.dim(`
...
"scripts": {
"build": "remix build --sourcemap && sentry-upload-sourcemaps"
}
...`)}
Copy link
Member

Choose a reason for hiding this comment

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

Let's please directly use console.log here and adjust the colors to make the build line stand out. For reference, feel free to take a look at the other tools flows of the sourcemap wizard (for example, tsc).
Reason: By directly using console.log, users can more easily copy/paste the code as no clack UI border characters are in the line.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Perfect, thanks Onur!

@Lms24 Lms24 merged commit 9b401a9 into master Aug 18, 2023
@Lms24 Lms24 deleted the onur/remix-wizard branch August 18, 2023 08:09
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

Successfully merging this pull request may close these issues.

[sourcemaps] Remix Wizard Support Improve source maps upload for Remix Improve source maps UX for Remix SDK
3 participants