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

Generate SSR source map with environment variable #1571

Merged
merged 13 commits into from
Jan 3, 2024

Conversation

yunakim714
Copy link
Collaborator

@yunakim714 yunakim714 commented Nov 28, 2023

Description

W-14148180
In order to improve the readability of server-side errors in MRT logs, we need to generate and output a source map as part of the bundle. This PR aims to write a new script so that customers can generate this file, ssr.js.map, only when they run the script: npm run push:ssr-source-map. This file will not be publicly exposed or available to download.

In order to then enable source maps in Cloud Watch logs, we need to set the environment variable, NODE_OPTIONS=--enable-source-maps in AWS Lambda.

Types of Changes

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Documentation update
  • Breaking change (could cause existing functionality to not work as expected)
  • Other changes (non-breaking changes that does not fit any of the above)

Breaking changes include:

  • Removing a public function or component or prop
  • Adding a required argument to a function
  • Changing the data type of a function parameter or return value
  • Adding a new peer dependency to package.json

Changes

  • Create a new script npm run push:ssr-source-map that runs build with the environment variable SSR_SOURCE_MAP
  • If SSR_SOURCE_MAP is set to true then build will generate and output a ssr.js.map file as part of the bundle

How to Test-Drive This PR

  • (step1)

Checklists

General

  • Changes are covered by test cases
  • CHANGELOG.md updated with a short description of changes (not required for documentation updates)

Accessibility Compliance

You must check off all items in one of the follow two lists:

  • There are no changes to UI

or...

Localization

  • Changes include a UI text update in the Retail React App (which requires translation)

@bredmond-sf bredmond-sf self-requested a review November 28, 2023 19:27
@@ -20,6 +20,7 @@
"lint:fix": "npm run lint -- --fix",
"postinstall": "npm run compile-translations && npm run compile-translations:pseudo",
"push": "npm run build && pwa-kit-dev push",
"push:source-map": "cross-env SSR_SOURCE_MAP=true npm run build && pwa-kit-dev push",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd say push:ssr-source-map to be specific

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol, said the opposite over here, but I'm unclear on the "why" behind this

#1571 (comment)

packages/pwa-kit-dev/src/configs/webpack/config.js Outdated Show resolved Hide resolved
@@ -498,8 +498,13 @@ const ssr = (() => {
if (mode === production) {
return baseConfig('node')
.extend((config) => {
let additionalConfig = {}
if (process.env.SSR_SOURCE_MAP === 'true') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (process.env.SSR_SOURCE_MAP === 'true') {
if (process.env.PWA_KIT_SSR_SOURCE_MAP === 'true') {

Namespacing env vars is good/consistent 🙂

yunakim714 and others added 2 commits November 30, 2023 10:49
Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>
Signed-off-by: Yuna Kim <84923642+yunakim714@users.noreply.github.com>
@yunakim714 yunakim714 marked this pull request as ready for review November 30, 2023 15:49
@yunakim714 yunakim714 requested a review from a team as a code owner November 30, 2023 15:49
bfeister
bfeister previously approved these changes Nov 30, 2023
Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

Will's point about namespacing is not wrong, but not a blocker

@yunakim714
Copy link
Collaborator Author

@wjhsf @bfeister Should I add push:pwa-kit-ssr-source-map to this line here in smoke-test-npm-scripts.js?

bfeister
bfeister previously approved these changes Nov 30, 2023
@@ -20,6 +20,7 @@
"lint:fix": "npm run lint -- --fix",
"postinstall": "npm run compile-translations && npm run compile-translations:pseudo",
"push": "npm run build && pwa-kit-dev push",
"push:ssr-source-map": "cross-env PWA_KIT_SSR_SOURCE_MAP=true npm run build && pwa-kit-dev push",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"push:ssr-source-map": "cross-env PWA_KIT_SSR_SOURCE_MAP=true npm run build && pwa-kit-dev push",
"push:ssr-source-map": "cross-env PWA_KIT_SSR_SOURCE_MAP=true npm run push",

This actually makes me wonder, though, what is the point of having a specific npm script for this? Why not just document the feature and let people set the environment variable when they want to use it?

Another idea: We could add a flag to pwa-kit-dev build, copying the pattern for the buildDirectory flag.

Copy link
Collaborator

Choose a reason for hiding this comment

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

agreed with Will on point of having this script.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@wjhsf @alexvuong Will get back to this once I have approval on a new tech proposal from the platform MRT team.

@yunakim714
Copy link
Collaborator Author

@bfeister @alexvuong @wjhsf New implementation of enabling source maps will be merged with this PR. Users will be able to toggle the enable_source_maps field through the existing Target API's. When enable_source_maps is set to true, users will see an improved error stack in their logs if their bundle is uploaded with source maps.

Based on this implementation, I agree that we do not really need the script, but just documentation on the env var used in pwa-kit-dev to output the ssr.js.map. Wanted to get yalls feedback on this. Thank you!

@yunakim714 yunakim714 changed the title Generate SSR source map with script npm run push:source-map Generate SSR source map with environment variable Jan 3, 2024
Copy link
Collaborator

@bfeister bfeister left a comment

Choose a reason for hiding this comment

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

Minor caveat: we should have a documentation update that exposes this to customers, but not a blocker for this PR

@yunakim714 yunakim714 requested review from hajinsuha1 and removed request for hajinsuha1 January 3, 2024 18:42
Copy link
Collaborator

@hajinsuha1 hajinsuha1 left a comment

Choose a reason for hiding this comment

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

🚢 🚢 🚢

@yunakim714 yunakim714 merged commit 34ae8b5 into develop Jan 3, 2024
28 checks passed
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.

None yet

6 participants