Skip to content

Commit

Permalink
Display error on Apple Silicon --local and deprecation warning elsewh…
Browse files Browse the repository at this point in the history
…ere (#785)
  • Loading branch information
purplecabbage authored Apr 8, 2024
1 parent a4bf919 commit 6dd1af3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/commands/app/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand Down Expand Up @@ -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({
Expand Down
27 changes: 26 additions & 1 deletion test/commands/app/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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))

Expand All @@ -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)
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 6dd1af3

Please sign in to comment.