Skip to content

Commit

Permalink
Use Shopify Functions Javy plugin instead of default Javy plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles committed Dec 5, 2024
1 parent 2926cb0 commit adcce6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-seahorses-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/app': minor
---

Use Shopify Functions Javy plugin instead of default Javy plugin for building JS Shopify Functions
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ packaging/dist
cloudflared*
function-runner*
javy*
shopify_functions_javy_v*.wasm

# Vitest vscode extension autogenerated files
index.d.ts
Expand Down
10 changes: 6 additions & 4 deletions packages/app/src/cli/services/function/binaries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,19 @@ describe('javy', () => {

describe('javy-plugin', () => {
test('properties are set correctly', () => {
expect(javyPlugin.name).toBe('javy_quickjs_provider_v3')
expect(javyPlugin.version).match(/^v\d.\d.\d$/)
expect(javyPlugin.path).toMatch(/(\/|\\)javy_quickjs_provider_v3.wasm$/)
expect(javyPlugin.name).toBe('shopify_functions_javy_v1')
expect(javyPlugin.version).match(/^v\d+$/)
expect(javyPlugin.path).toMatch(/(\/|\\)shopify_functions_javy_v1.wasm$/)
})

test('downloadUrl returns the correct URL', () => {
// When
const url = javyPlugin.downloadUrl('', '')

// Then
expect(url).toMatch(/https:\/\/github.com\/bytecodealliance\/javy\/releases\/download\/v\d\.\d\.\d\/plugin.wasm.gz/)
expect(url).toMatch(
/^https:\/\/cdn\.shopify\.com\/shopifycloud\/shopify-functions-javy-plugin\/shopify_functions_javy_v\d+\.wasm$/,
)
})

test('downloads javy-plugin', async () => {
Expand Down
11 changes: 6 additions & 5 deletions packages/app/src/cli/services/function/binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {outputDebug} from '@shopify/cli-kit/node/output'
import {performActionWithRetryAfterRecovery} from '@shopify/cli-kit/common/retry'
import {fetch} from '@shopify/cli-kit/node/http'
import {PipelineSource} from 'stream'
import {pipeline} from 'stream/promises'
import stream from 'node:stream/promises'
import fs from 'node:fs'
import * as gzip from 'node:zlib'
Expand All @@ -13,7 +14,7 @@ const FUNCTION_RUNNER_VERSION = 'v6.3.0'
const JAVY_VERSION = 'v4.0.0'
// The Javy plugin version does not need to match the Javy version. It should
// match the plugin version used in the function-runner version specified above.
const JAVY_PLUGIN_VERSION = 'v3.2.0'
const JAVY_PLUGIN_VERSION = 'v1'

interface DownloadableBinary {
path: string
Expand Down Expand Up @@ -93,17 +94,17 @@ class JavyPlugin implements DownloadableBinary {
readonly path: string

constructor() {
this.name = 'javy_quickjs_provider_v3'
this.name = 'shopify_functions_javy_v1'
this.version = JAVY_PLUGIN_VERSION
this.path = joinPath(dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'javy_quickjs_provider_v3.wasm')
this.path = joinPath(dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'shopify_functions_javy_v1.wasm')
}

downloadUrl(_processPlatform: string, _processArch: string) {
return `https://github.com/bytecodealliance/javy/releases/download/${this.version}/plugin.wasm.gz`
return `https://cdn.shopify.com/shopifycloud/shopify-functions-javy-plugin/shopify_functions_javy_${JAVY_PLUGIN_VERSION}.wasm`
}

async processResponse(responseStream: PipelineSource<unknown>, outputStream: fs.WriteStream): Promise<void> {
return gunzipResponse(responseStream, outputStream)
return pipeline(responseStream, outputStream)
}
}

Expand Down

0 comments on commit adcce6d

Please sign in to comment.