From 6dd1af3f47c64298abf88af159c7d6b8d14694f8 Mon Sep 17 00:00:00 2001 From: Jesse MacFadyen Date: Mon, 8 Apr 2024 10:30:03 -0700 Subject: [PATCH] Display error on Apple Silicon --local and deprecation warning elsewhere (#785) --- src/commands/app/run.js | 13 ++++++++++++- test/commands/app/run.test.js | 27 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/commands/app/run.js b/src/commands/app/run.js index 9b7f2fb5..3ed611bf 100644 --- a/src/commands/app/run.js +++ b/src/commands/app/run.js @@ -16,6 +16,7 @@ const fs = require('fs-extra') const https = require('https') const getPort = require('get-port') const open = require('open') +const os = require('node:os') const { Flags, ux } = require('@oclif/core') const coreConfig = require('@adobe/aio-lib-core-config') @@ -35,6 +36,16 @@ class Run extends BaseCommand { // cli input const { flags } = await this.parse(Run) + if (flags.local) { + const [firstCpu] = os.cpus() + // note: the earliest versions of M1 macs return 'Apple processor' under model. + if (firstCpu?.model?.startsWith('Apple')) { + this.error('The --local flag is not supported on Apple Silicon Macs.') + } else { + this.warn('The --local flag is deprecated and will be removed in the next major release.') + } + } + const spinner = ora() const runConfigs = await this.getAppExtConfigs(flags) @@ -204,7 +215,7 @@ Run.args = {} Run.flags = { ...BaseCommand.flags, local: Flags.boolean({ - description: 'Run/debug actions locally (requires Docker running)', + description: '[deprecated] Run/debug actions locally (requires Docker running, not available on Apple Silicon Macs)', exclusive: ['no-actions'] }), serve: Flags.boolean({ diff --git a/test/commands/app/run.test.js b/test/commands/app/run.test.js index 548be477..ab006332 100644 --- a/test/commands/app/run.test.js +++ b/test/commands/app/run.test.js @@ -61,6 +61,9 @@ const mockConfig = require('@adobe/aio-lib-core-config') jest.mock('https') const https = require('https') +jest.mock('node:os') +const os = require('node:os') + jest.mock('get-port') const getPort = require('get-port') @@ -103,6 +106,8 @@ beforeEach(() => { open.mockReset() ux.wait = jest.fn() // .mockImplementation((ms = 1000) => { return new Promise(resolve => setTimeout(resolve, ms)) }) + os.cpus.mockImplementation(() => [{ model: 'Intel Pentium MMX' }]) + mockFindCommandLoad.mockClear() mockFindCommandRun.mockReset() @@ -315,11 +320,12 @@ describe('run', () => { }), expect.any(Function), expect.any(Function)) }) - test('app:run with --local', async () => { + test('app:run with --local NOT Apple Silicon', async () => { mockFSExists([PRIVATE_KEY_PATH, PUB_CERT_PATH]) mockRunDev.mockImplementation((config, dataDir, options, logFunc) => { expect(options.isLocal).toBe(true) }) + command.argv = ['--local'] command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig)) @@ -328,11 +334,29 @@ describe('run', () => { expect(mockRunDev).toHaveBeenCalledTimes(1) }) + test('app:run with --local with Apple Silicon', async () => { + mockFSExists([PRIVATE_KEY_PATH, PUB_CERT_PATH]) + mockRunDev.mockImplementation((config, dataDir, options, logFunc) => { + expect(options.isLocal).toBe(true) + }) + + os.cpus.mockImplementation(() => [{ model: 'Apple processor' }]) + command.argv = ['--local'] + command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig)) + + await command.run() + // this should be more like the following ... + // await expect(command.run().rejects.toThrow('The --local flag is not supported on Apple Silicon Macs.')) + expect(command.error).toHaveBeenCalledWith('The --local flag is not supported on Apple Silicon Macs.') + }) + test('app:run with --local --verbose', async () => { mockFSExists([PRIVATE_KEY_PATH, PUB_CERT_PATH]) command.argv = ['--local', '--verbose'] const appConfig = createAppConfig(command.appConfig) command.getAppExtConfigs.mockResolvedValueOnce(appConfig) + // apple silicon would block this test + os.cpus.mockImplementation(() => [{ model: 'Intel Pentium MMX' }]) await command.run() expect(command.error).toHaveBeenCalledTimes(0) @@ -684,6 +708,7 @@ describe('run', () => { command.argv = [] await command.run() + // await expect(command.run()).rejects.toThrow('Your app implements multiple extensions.') expect(command.error).toHaveBeenCalledTimes(1) expect(command.error).toHaveBeenCalledWith(expect.stringContaining('\'-e\' flag'))