Skip to content

Commit

Permalink
Merge pull request #5040 from Shopify/jc.use-shopify-functions-javy-p…
Browse files Browse the repository at this point in the history
…lugin

Use Shopify Functions Javy plugin instead of default Javy plugin
  • Loading branch information
jeffcharles authored Dec 16, 2024
2 parents 720ad9c + d7153b8 commit cb09e4d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 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
22 changes: 14 additions & 8 deletions packages/app/src/cli/services/function/binaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ 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'
import {fileURLToPath} from 'node:url'

const FUNCTION_RUNNER_VERSION = 'v6.4.0'
const FUNCTION_RUNNER_VERSION = 'v6.5.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'
// The Javy plugin version should match the plugin version used in the
// function-runner version specified above.
const JAVY_PLUGIN_VERSION = 'v1'

const BINARYEN_VERSION = '120.0.0'

Expand Down Expand Up @@ -95,17 +96,22 @@ class JavyPlugin implements DownloadableBinary {
readonly path: string

constructor() {
this.name = 'javy_quickjs_provider_v3'
this.name = `shopify_functions_javy_${JAVY_PLUGIN_VERSION}`
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_${JAVY_PLUGIN_VERSION}.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 cb09e4d

Please sign in to comment.