Repository navigation
#2388 stop empty lines accumulating at the start of ssjs files - #2691
Open
Pushpak731 wants to merge 1 commit into
Open
Pushpak731 wants to merge 1 commit into
Pushpak731 wants to merge 1 commit into
Conversation
Asset._mergeCode wrapped the deployed ssjs file content into the script tags without trimming it, while Util.getSsjs returned the content between the tags including the newlines the wrapper added. Each deploy/retrieve roundtrip therefore added another empty line to the stored script and to retrieved files, which is why every BU copy ended up with a different number of leading empty lines depending on how often it was deployed. - trim the file content when wrapping it for the API, matching what Script._mergeCode already does - strip leading newlines from the extracted code in Util.getSsjs so extracted files start with the first line of code - drop the now-redundant single-newline compensation in Script._buildForNested
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2388
ssjs files gained one leading empty line per deploy/retrieve roundtrip, so after deploying to multiple BUs each BU's copy showed a different number of empty lines at the top, depending on how many roundtrips it went through.
Root cause (two sides of the same roundtrip):
Asset._mergeCodewrapped the deployed.ssjsfile content into<script runat="server">…</script>without trimming it, so whatever empty lines the file had were carried into the API payload and stored in SFMC (Script._mergeCode already trims; Asset did not).Util.getSsjsreturned the content between the script tags including the newlines the wrapper adds around it, so retrieved/extracted files started with an empty line even for cleanly stored scripts. The Script build path worked around this withcode.replace(/^\n/, ''); prettier (when enabled) masked the rest, which is why tests never caught it.Changes
lib/metadataTypes/Asset.js: trim the file content when wrapping it for the API and close the tag on its own line, matching the formatScript._mergeCodeproduceslib/util/util.js:getSsjsstrips leading\n/\r\nfrom the extracted code, so extracted.ssjsfiles start with the first line of code and accumulated empty lines from previously stored scripts are cleaned up on the next retrievelib/metadataTypes/Script.js: drop the now-redundant single-leading-newline compensation in_buildForNested@types/lib/util/util.d.ts.map: regenerated via pre-commit hookHow Has This Been Tested?
local tests (new + existing):
test/general.test.js→getSsjsdescribe: 7 unit tests for the extraction (wrapper newlines, accumulated newlines, CRLF, code directly after the tag, no tags → null, nested script → null, empty input → null) plus a_mergeCoderoundtrip test proving the API payload is wrapped exactly once and unwraps back to the original file content (idempotent across further roundtrips)general+type.script+type.asset(96 passing) andtype.asset.mobile+type.asset.mobile.references+type.asset.references(93 passing)Additional context
Roundtrip before the fix (what gets stored in SFMC and grows per deployment):
after the fix: