From adcce6d6642ab42ed1b25a331fc8c12d650a80b0 Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Thu, 5 Dec 2024 11:46:43 -0500 Subject: [PATCH 1/3] Use Shopify Functions Javy plugin instead of default Javy plugin --- .changeset/seven-seahorses-bake.md | 5 +++++ .gitignore | 1 + .../app/src/cli/services/function/binaries.test.ts | 10 ++++++---- packages/app/src/cli/services/function/binaries.ts | 11 ++++++----- 4 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 .changeset/seven-seahorses-bake.md diff --git a/.changeset/seven-seahorses-bake.md b/.changeset/seven-seahorses-bake.md new file mode 100644 index 00000000000..9117786fef0 --- /dev/null +++ b/.changeset/seven-seahorses-bake.md @@ -0,0 +1,5 @@ +--- +'@shopify/app': minor +--- + +Use Shopify Functions Javy plugin instead of default Javy plugin for building JS Shopify Functions diff --git a/.gitignore b/.gitignore index 13df16cc1c8..499fc2c132b 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ packaging/dist cloudflared* function-runner* javy* +shopify_functions_javy_v*.wasm # Vitest vscode extension autogenerated files index.d.ts diff --git a/packages/app/src/cli/services/function/binaries.test.ts b/packages/app/src/cli/services/function/binaries.test.ts index 7656cd9e2f0..80bc845d5cd 100644 --- a/packages/app/src/cli/services/function/binaries.test.ts +++ b/packages/app/src/cli/services/function/binaries.test.ts @@ -135,9 +135,9 @@ 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', () => { @@ -145,7 +145,9 @@ describe('javy-plugin', () => { 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 () => { diff --git a/packages/app/src/cli/services/function/binaries.ts b/packages/app/src/cli/services/function/binaries.ts index 153e143f427..612b7b246bd 100644 --- a/packages/app/src/cli/services/function/binaries.ts +++ b/packages/app/src/cli/services/function/binaries.ts @@ -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' @@ -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 @@ -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, outputStream: fs.WriteStream): Promise { - return gunzipResponse(responseStream, outputStream) + return pipeline(responseStream, outputStream) } } From b4eda0235dc469019e9514b6e5ad1219f99de677 Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Tue, 10 Dec 2024 11:02:51 -0500 Subject: [PATCH 2/3] Update Shopify Functions to version with plugin --- packages/app/src/cli/services/function/binaries.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/app/src/cli/services/function/binaries.ts b/packages/app/src/cli/services/function/binaries.ts index 612b7b246bd..dd67c06fe75 100644 --- a/packages/app/src/cli/services/function/binaries.ts +++ b/packages/app/src/cli/services/function/binaries.ts @@ -10,10 +10,10 @@ import fs from 'node:fs' import * as gzip from 'node:zlib' import {fileURLToPath} from 'node:url' -const FUNCTION_RUNNER_VERSION = 'v6.3.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. +// The Javy plugin version should match the plugin version used in the +// function-runner version specified above. const JAVY_PLUGIN_VERSION = 'v1' interface DownloadableBinary { From 07f8394e4f398c6064353ae30a531d0879144670 Mon Sep 17 00:00:00 2001 From: Jeff Charles Date: Tue, 10 Dec 2024 11:06:35 -0500 Subject: [PATCH 3/3] Use version constant in plugin name and path --- packages/app/src/cli/services/function/binaries.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/app/src/cli/services/function/binaries.ts b/packages/app/src/cli/services/function/binaries.ts index dd67c06fe75..092a8085747 100644 --- a/packages/app/src/cli/services/function/binaries.ts +++ b/packages/app/src/cli/services/function/binaries.ts @@ -94,9 +94,14 @@ class JavyPlugin implements DownloadableBinary { readonly path: string constructor() { - this.name = 'shopify_functions_javy_v1' + this.name = `shopify_functions_javy_${JAVY_PLUGIN_VERSION}` this.version = JAVY_PLUGIN_VERSION - this.path = joinPath(dirname(fileURLToPath(import.meta.url)), '..', 'bin', 'shopify_functions_javy_v1.wasm') + this.path = joinPath( + dirname(fileURLToPath(import.meta.url)), + '..', + 'bin', + `shopify_functions_javy_${JAVY_PLUGIN_VERSION}.wasm`, + ) } downloadUrl(_processPlatform: string, _processArch: string) {