Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundled cli-ruby used by default #1346

Merged
merged 2 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/spotty-ways-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': patch
---

Use bundled Ruby CLI by default
25 changes: 14 additions & 11 deletions packages/cli-kit/src/public/node/ruby.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {execCLI2, RubyCLIVersion} from './ruby.js'
import {execCLI2} from './ruby.js'
import {captureOutput} from './system.js'
import * as system from './system.js'
import * as file from './fs.js'
import {pathConstants} from '../../private/node/constants.js'
import {describe, expect, it, vi} from 'vitest'

vi.mock('./fs.js')
Expand Down Expand Up @@ -54,15 +53,13 @@ describe('execCLI', () => {
// Given
const rubyVersion = '2.7.5'
const bundlerVersion = '2.4.0'

process.env = {...originalEnv, SHOPIFY_CLI_BUNDLED_THEME_CLI: '1'}

vi.mocked(file.fileExists).mockResolvedValue(true)
vi.mocked(captureOutput).mockResolvedValueOnce(rubyVersion)
vi.mocked(captureOutput).mockResolvedValueOnce(bundlerVersion)
vi.mocked(file.mkdir).mockRejectedValue({message: 'Error'})
process.env = {...originalEnv, SHOPIFY_RUN_AS_USER: '1'}

// When / Then
// When/Then
await expect(() => execCLI2(['args'])).rejects.toThrowError('Error')

// Teardown
Expand All @@ -75,10 +72,9 @@ describe('execCLI', () => {
const originalEnv = process.env

// Given
vi.spyOn(pathConstants.directories.cache.vendor, 'path').mockImplementation(() => '/bundled')
const execSpy = vi.spyOn(system, 'exec')

process.env = {...originalEnv, SHOPIFY_CLI_BUNDLED_THEME_CLI: '1'}
process.env = {...originalEnv, SHOPIFY_CLI_2_0_DIRECTORY: './CLI2', SHOPIFY_RUN_AS_USER: '1'}

vi.mocked(file.fileExists).mockResolvedValue(true)
vi.mocked(captureOutput).mockResolvedValueOnce('2.7.5')
Expand All @@ -101,7 +97,7 @@ describe('execCLI', () => {
SHOPIFY_CLI_STORE: undefined,
SHOPIFY_CLI_AUTH_TOKEN: 'token_0000_1111_2222_3333',
SHOPIFY_CLI_RUN_AS_SUBPROCESS: 'true',
BUNDLE_GEMFILE: `/bundled/ruby-cli/${RubyCLIVersion}/Gemfile`,
BUNDLE_GEMFILE: 'CLI2/Gemfile',
},
})

Expand All @@ -116,7 +112,7 @@ describe('execCLI', () => {
// Given
const execSpy = vi.spyOn(system, 'exec')

process.env = {...originalEnv, SHOPIFY_CLI_2_0_DIRECTORY: '/manual'}
process.env = {...originalEnv, SHOPIFY_CLI_2_0_DIRECTORY: '/manual', SHOPIFY_RUN_AS_USER: '1'}

vi.mocked(file.fileExists).mockResolvedValue(true)
vi.mocked(captureOutput).mockResolvedValueOnce('2.7.5')
Expand Down Expand Up @@ -147,9 +143,13 @@ describe('execCLI', () => {
process.env = originalEnv
})

it('run embbed CLI2 when active', async () => {
it('run embbed CLI2 when shopify user', async () => {
// Setup
const originalEnv = process.env

// Given
const execSpy = vi.spyOn(system, 'exec')
process.env = {...originalEnv, SHOPIFY_RUN_AS_USER: '0'}

vi.mocked(file.fileExists).mockResolvedValue(true)
vi.mocked(file.findPathUp).mockResolvedValue('/embed/internal')
Expand Down Expand Up @@ -177,5 +177,8 @@ describe('execCLI', () => {
},
signal: undefined,
})

// Teardown
process.env = originalEnv
})
})
3 changes: 2 additions & 1 deletion packages/cli-kit/src/public/node/ruby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {captureOutput, exec} from './system.js'
import * as file from './fs.js'
import {joinPath, dirname, cwd} from './path.js'
import {AbortError, AbortSilentError} from './error.js'
import {isShopify} from './context/local.js'
import {pathConstants} from '../../private/node/constants.js'
import {AdminSession} from '../../public/node/session.js'
import {outputContent, outputToken} from '../../public/node/output.js'
Expand Down Expand Up @@ -40,7 +41,7 @@ interface ExecCLI2Options {
* @param options - Options to customize the execution of cli2.
*/
export async function execCLI2(args: string[], options: ExecCLI2Options = {}): Promise<void> {
const embedded = !isTruthy(process.env.SHOPIFY_CLI_BUNDLED_THEME_CLI) && !process.env.SHOPIFY_CLI_2_0_DIRECTORY
const embedded = (await isShopify()) || isTruthy(process.env.SHOPIFY_CLI_EMBEDDED_THEME_CLI)

await installCLIDependencies(options.stdout ?? process.stdout, embedded)
const env: NodeJS.ProcessEnv = {
Expand Down