Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('stageFile', () => {
const uploadedBlob = fileAppendCall?.[1] as Blob
const uploadedContent = await uploadedBlob?.text()

expect(uploadedContent).toBe('{"input":{"id":"gid://shopify/Product/123","tags":["test"]}}\n')
expect(uploadedContent).toBe('{"input":{"id":"gid://shopify/Product/123","tags":["test"]}}')
})

test('handles JSONL with multiple lines correctly', async () => {
Expand All @@ -94,7 +94,6 @@ describe('stageFile', () => {
'{"input":{"id":"gid://shopify/Product/1","title":"New Shirt"}}',
'{"input":{"id":"gid://shopify/Product/2","title":"Cool Pants"}}',
'{"input":{"id":"gid://shopify/Product/3","title":"Nice Hat"}}',
'',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(This empty string right here should've been a smoking gun indicating a bug before, but we all missed it in review!)

].join('\n')

expect(uploadedContent).toBe(expectedContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface StageFileOptions {
export async function stageFile(options: StageFileOptions): Promise<string> {
const {adminSession, variablesJsonl} = options

const buffer = Buffer.from(variablesJsonl ? `${variablesJsonl}\n` : '', 'utf-8')
const buffer = Buffer.from(variablesJsonl ?? '', 'utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we add an extra ? here?

Copy link
Contributor Author

@jordanverasamy jordanverasamy Jan 22, 2026

Choose a reason for hiding this comment

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

Good question!! That is the nullish coalescing operator.

Basically, I first removed the \n, and I got this:

variablesJsonl ? variablesJsonl : ''

This is a common pattern, and is of course equivalent to:

variablesJsonl || ''

?? is an operator that works like ||, except that if the left value is defined-but-falsy (like e.g. ''), || will fall back to the right value, whereas ?? will respect that defined value.

In this case the only falsy value you'll reasonably get here is '', in which case whether we use that or the fallback we'll get an empty string either way. So, ?? and || are going to behave equivalently in all cases here.

I lean towards ?? by default because I don't want to think about JS's weird falsy values unless I have to, so I ended up with:

variablesJsonl ?? ''

const filename = 'bulk-variables.jsonl'
const size = buffer.length

Expand Down
Loading