diff --git a/packages/app/src/cli/models/extensions/extension-instance.ts b/packages/app/src/cli/models/extensions/extension-instance.ts index 009c8b8038..addb7eba72 100644 --- a/packages/app/src/cli/models/extensions/extension-instance.ts +++ b/packages/app/src/cli/models/extensions/extension-instance.ts @@ -28,9 +28,9 @@ import {constantize, slugify} from '@shopify/cli-kit/common/string' import {hashString, randomUUID} from '@shopify/cli-kit/node/crypto' import {partnersFqdn} from '@shopify/cli-kit/node/context/fqdn' import {joinPath} from '@shopify/cli-kit/node/path' -import {useThemebundling} from '@shopify/cli-kit/node/context/local' -import {fileExists, touchFile, writeFile} from '@shopify/cli-kit/node/fs' +import {fileExists, touchFile, writeFile, copyFile} from '@shopify/cli-kit/node/fs' import {getPathValue} from '@shopify/cli-kit/common/object' +import {useThemebundling} from '@shopify/cli-kit/node/context/local' export const CONFIG_EXTENSION_IDS = [ AppAccessSpecIdentifier, @@ -205,6 +205,7 @@ export class ExtensionInstance { + // To ensure this is not a breaking change we will delete this upload line on a second pass after we've ensured the new file upload process from core is working. const {moduleId} = await uploadWasmBlob(this.localIdentifier, this.outputPath, developerPlatformClient) return this.specification.deployConfig?.(this.configuration, this.directory, apiKey, moduleId) } @@ -335,11 +336,13 @@ export class ExtensionInstance ['function'], + appModuleFeatures: (_) => ['function', 'bundling'], deployConfig: async (config, directory, apiKey, moduleId) => { let inputQuery: string | undefined const inputQueryPath = joinPath(directory, 'input.graphql') diff --git a/packages/app/src/cli/services/deploy.test.ts b/packages/app/src/cli/services/deploy.test.ts index 162903f1a6..d8b1ade536 100644 --- a/packages/app/src/cli/services/deploy.test.ts +++ b/packages/app/src/cli/services/deploy.test.ts @@ -243,7 +243,7 @@ describe('deploy', () => { expect(updateAppIdentifiers).toHaveBeenCalledOnce() }) - test('uploads the extension bundle with 1 function', async () => { + test('uploads the extension bundle with 1 function extension', async () => { // Given const functionExtension = await testFunctionExtension() vi.spyOn(functionExtension, 'preDeployValidation').mockImplementation(async () => {}) @@ -290,7 +290,7 @@ describe('deploy', () => { ], developerPlatformClient, extensionIds: {}, - bundlePath: undefined, + bundlePath: expect.stringMatching(/bundle.zip$/), release: true, }) expect(bundleAndBuildExtensions).toHaveBeenCalledOnce() diff --git a/packages/app/src/cli/services/deploy/bundle.test.ts b/packages/app/src/cli/services/deploy/bundle.test.ts index 1d62b5256e..bf4b2055c9 100644 --- a/packages/app/src/cli/services/deploy/bundle.test.ts +++ b/packages/app/src/cli/services/deploy/bundle.test.ts @@ -1,5 +1,5 @@ import {bundleAndBuildExtensions} from './bundle.js' -import {testApp, testThemeExtensions, testUIExtension} from '../../models/app/app.test-data.js' +import {testApp, testFunctionExtension, testThemeExtensions, testUIExtension} from '../../models/app/app.test-data.js' import {AppInterface} from '../../models/app/app.js' import {describe, expect, test, vi} from 'vitest' import * as file from '@shopify/cli-kit/node/fs' @@ -107,4 +107,35 @@ describe('bundleAndBuildExtensions', () => { await expect(file.fileExists(bundlePath)).resolves.toBeTruthy() }) }) + + test.only('creates a zip file with wasm file in it for a function extension', async () => { + await file.inTemporaryDirectory(async (tmpDir: string) => { + // Given + const bundlePath = joinPath(tmpDir, 'bundle.zip') + + const functionExtension = await testFunctionExtension() + const extensionBundleMock = vi.fn().mockImplementation(async (options, bundleDirectory, identifiers) => { + file.writeFileSync(joinPath(bundleDirectory, 'index.wasm'), '') + }) + functionExtension.buildForBundle = extensionBundleMock + const app = testApp({allExtensions: [functionExtension]}) + + const extensions: {[key: string]: string} = {} + for (const extension of app.allExtensions) { + extensions[extension.localIdentifier] = extension.localIdentifier + } + const identifiers = { + app: 'app-id', + extensions, + extensionIds: {}, + extensionsNonUuidManaged: {}, + } + + // When + await bundleAndBuildExtensions({app, identifiers, bundlePath}, {}) + + // Then + await expect(file.fileExists(bundlePath)).resolves.toBeTruthy() + }) + }) }) diff --git a/packages/app/src/cli/services/deploy/bundle.ts b/packages/app/src/cli/services/deploy/bundle.ts index dd533a895b..065e522535 100644 --- a/packages/app/src/cli/services/deploy/bundle.ts +++ b/packages/app/src/cli/services/deploy/bundle.ts @@ -8,6 +8,7 @@ import {joinPath} from '@shopify/cli-kit/node/path' import {isTruthy} from '@shopify/cli-kit/node/context/utilities' import {renderConcurrent} from '@shopify/cli-kit/node/ui' import {Writable} from 'stream' +import {readdirSync} from 'fs' interface BundleOptions { app: AppInterface @@ -49,6 +50,7 @@ export async function bundleAndBuildExtensions(options: BundleOptions, systemEnv }) if (options.bundlePath) { + const files = readdirSync(bundleDirectory) await zip({ inputDirectory: bundleDirectory, outputZipPath: options.bundlePath,