@shopify/cli-kit 3.36.2 → 3.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export * as output from './output.js';
2
- export * as store from './store.js';
3
2
  export * as ui from './ui.js';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export * as output from './output.js';
2
- export * as store from './store.js';
3
2
  export * as ui from './ui.js';
4
3
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,KAAK,MAAM,YAAY,CAAA;AACnC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA","sourcesContent":["export * as output from './output.js'\nexport * as store from './store.js'\nexport * as ui from './ui.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA","sourcesContent":["export * as output from './output.js'\nexport * as ui from './ui.js'\n"]}
@@ -0,0 +1,21 @@
1
+ import Conf, { Schema } from 'conf';
2
+ export { Conf, Schema };
3
+ export interface ConfSchema {
4
+ sessionStore: string;
5
+ }
6
+ /**
7
+ * Get session.
8
+ *
9
+ * @returns Session.
10
+ */
11
+ export declare function getSession(config?: Conf<ConfSchema>): string | undefined;
12
+ /**
13
+ * Set session.
14
+ *
15
+ * @param session - Session.
16
+ */
17
+ export declare function setSession(session: string, config?: Conf<ConfSchema>): void;
18
+ /**
19
+ * Remove session.
20
+ */
21
+ export declare function removeSession(config?: Conf<ConfSchema>): void;
@@ -0,0 +1,41 @@
1
+ import { content, debug } from '../../output.js';
2
+ import Conf from 'conf';
3
+ export { Conf };
4
+ let _instance;
5
+ /**
6
+ * CLIKIT Store.
7
+ *
8
+ * @returns CLIKitStore.
9
+ */
10
+ function cliKitStore() {
11
+ if (!_instance) {
12
+ _instance = new Conf({ projectName: 'shopify-cli-kit' });
13
+ }
14
+ return _instance;
15
+ }
16
+ /**
17
+ * Get session.
18
+ *
19
+ * @returns Session.
20
+ */
21
+ export function getSession(config = cliKitStore()) {
22
+ debug(content `Getting session store...`);
23
+ return config.get('sessionStore');
24
+ }
25
+ /**
26
+ * Set session.
27
+ *
28
+ * @param session - Session.
29
+ */
30
+ export function setSession(session, config = cliKitStore()) {
31
+ debug(content `Setting session store...`);
32
+ config.set('sessionStore', session);
33
+ }
34
+ /**
35
+ * Remove session.
36
+ */
37
+ export function removeSession(config = cliKitStore()) {
38
+ debug(content `Removing session store...`);
39
+ config.delete('sessionStore');
40
+ }
41
+ //# sourceMappingURL=conf-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conf-store.js","sourceRoot":"","sources":["../../../src/private/node/conf-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AAC9C,OAAO,IAAc,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAC,IAAI,EAAS,CAAA;AAMrB,IAAI,SAAuC,CAAA;AAE3C;;;;GAIG;AACH,SAAS,WAAW;IAClB,IAAI,CAAC,SAAS,EAAE;QACd,SAAS,GAAG,IAAI,IAAI,CAAa,EAAC,WAAW,EAAE,iBAAiB,EAAC,CAAC,CAAA;KACnE;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,SAA2B,WAAW,EAAE;IACjE,KAAK,CAAC,OAAO,CAAA,0BAA0B,CAAC,CAAA;IACxC,OAAO,MAAM,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,SAA2B,WAAW,EAAE;IAClF,KAAK,CAAC,OAAO,CAAA,0BAA0B,CAAC,CAAA;IACxC,MAAM,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAA;AACrC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,SAA2B,WAAW,EAAE;IACpE,KAAK,CAAC,OAAO,CAAA,2BAA2B,CAAC,CAAA;IACzC,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAA;AAC/B,CAAC","sourcesContent":["import {content, debug} from '../../output.js'\nimport Conf, {Schema} from 'conf'\n\nexport {Conf, Schema}\n\nexport interface ConfSchema {\n sessionStore: string\n}\n\nlet _instance: Conf<ConfSchema> | undefined\n\n/**\n * CLIKIT Store.\n *\n * @returns CLIKitStore.\n */\nfunction cliKitStore() {\n if (!_instance) {\n _instance = new Conf<ConfSchema>({projectName: 'shopify-cli-kit'})\n }\n return _instance\n}\n\n/**\n * Get session.\n *\n * @returns Session.\n */\nexport function getSession(config: Conf<ConfSchema> = cliKitStore()): string | undefined {\n debug(content`Getting session store...`)\n return config.get('sessionStore')\n}\n\n/**\n * Set session.\n *\n * @param session - Session.\n */\nexport function setSession(session: string, config: Conf<ConfSchema> = cliKitStore()): void {\n debug(content`Setting session store...`)\n config.set('sessionStore', session)\n}\n\n/**\n * Remove session.\n */\nexport function removeSession(config: Conf<ConfSchema> = cliKitStore()): void {\n debug(content`Removing session store...`)\n config.delete('sessionStore')\n}\n"]}
@@ -1,9 +1,9 @@
1
1
  import { SessionSchema } from './schema.js';
2
+ import { getSession, removeSession, setSession } from '../conf-store.js';
2
3
  import { keychainConstants } from '../constants.js';
3
4
  import { platformAndArch } from '../../../public/node/os.js';
4
5
  import { secureStoreSave, secureStoreFetch, secureStoreRemove } from '../secure-store.js';
5
6
  import { content, debug } from '../../../output.js';
6
- import { getSession, removeSession, setSession, clearAllAppInfo } from '../../../store.js';
7
7
  /**
8
8
  * The identifier of the session in the secure store.
9
9
  */
@@ -61,7 +61,6 @@ export async function remove() {
61
61
  else {
62
62
  removeSession();
63
63
  }
64
- clearAllAppInfo();
65
64
  }
66
65
  /**
67
66
  * Returns true if the secure store is available on the system.
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAA;AACzC,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAC,eAAe,EAAC,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAC,eAAe,EAAE,gBAAgB,EAAE,iBAAiB,EAAC,MAAM,oBAAoB,CAAA;AACvF,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAA;AAGxF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAA;AAEnC;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,OAAgB;IAC1C,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;IAC3C,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,eAAe,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;KAC/C;SAAM;QACL,UAAU,CAAC,WAAW,CAAC,CAAA;KACxB;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK;IACzB,IAAI,OAAO,CAAA;IACX,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,OAAO,GAAG,MAAM,gBAAgB,CAAC,UAAU,CAAC,CAAA;KAC7C;SAAM;QACL,OAAO,GAAG,UAAU,EAAE,CAAA;KACvB;IAED,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,SAAS,CAAA;KACjB;IACD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;IACrE,IAAI,aAAa,CAAC,OAAO,EAAE;QACzB,OAAO,aAAa,CAAC,IAAI,CAAA;KAC1B;SAAM;QACL,MAAM,MAAM,EAAE,CAAA;QACd,OAAO,SAAS,CAAA;KACjB;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAA;KACpC;SAAM;QACL,aAAa,EAAE,CAAA;KAChB;IAED,eAAe,EAAE,CAAA;AACnB,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB;IACjC,IAAI;QACF,IAAI,eAAe,EAAE,CAAC,QAAQ,KAAK,SAAS,EAAE;YAC5C,KAAK,CAAC,OAAO,CAAA,uCAAuC,CAAC,CAAA;YACrD,OAAO,KAAK,CAAA;SACb;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC/D,KAAK,CAAC,OAAO,CAAA,2BAA2B,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,OAAO,MAAM,EAAE;QACf,KAAK,CAAC,OAAO,CAAA,6BAA6B,CAAC,CAAA;QAC3C,OAAO,KAAK,CAAA;KACb;AACH,CAAC","sourcesContent":["import {SessionSchema} from './schema.js'\nimport {keychainConstants} from '../constants.js'\nimport {platformAndArch} from '../../../public/node/os.js'\nimport {secureStoreSave, secureStoreFetch, secureStoreRemove} from '../secure-store.js'\nimport {content, debug} from '../../../output.js'\nimport {getSession, removeSession, setSession, clearAllAppInfo} from '../../../store.js'\nimport type {Session} from './schema.js'\n\n/**\n * The identifier of the session in the secure store.\n */\nexport const identifier = 'session'\n\n/**\n * Serializes the session as a JSON and stores it securely in the system.\n * If the secure store is not available, the session is stored in the local config.\n * @param session - the session to store.\n */\nexport async function store(session: Session) {\n const jsonSession = JSON.stringify(session)\n if (await secureStoreAvailable()) {\n await secureStoreSave(identifier, jsonSession)\n } else {\n setSession(jsonSession)\n }\n}\n\n/**\n * Fetches the session from the secure store and returns it.\n * If the secure store is not available, the session is fetched from the local config.\n * If the format of the session is invalid, the method will discard it.\n * In the future might add some logic for supporting migrating the schema\n * of already-persisted sessions.\n * @returns Returns a promise that resolves with the session if it exists and is valid.\n */\nexport async function fetch(): Promise<Session | undefined> {\n let content\n if (await secureStoreAvailable()) {\n content = await secureStoreFetch(identifier)\n } else {\n content = getSession()\n }\n\n if (!content) {\n return undefined\n }\n const contentJson = JSON.parse(content)\n const parsedSession = await SessionSchema.safeParseAsync(contentJson)\n if (parsedSession.success) {\n return parsedSession.data\n } else {\n await remove()\n return undefined\n }\n}\n\n/**\n * Removes a session from the system.\n */\nexport async function remove() {\n if (await secureStoreAvailable()) {\n await secureStoreRemove(identifier)\n } else {\n removeSession()\n }\n\n clearAllAppInfo()\n}\n\n/**\n * Returns true if the secure store is available on the system.\n * Keytar it's not supported on some Linux environments or Windows.\n * More details: https://github.com/Shopify/shopify-cli-planning/issues/261\n * @returns a boolean indicating if the secure store is available.\n */\nasync function secureStoreAvailable(): Promise<boolean> {\n try {\n if (platformAndArch().platform === 'windows') {\n debug(content`Secure store not supported on Windows`)\n return false\n }\n const keytar = await import('keytar')\n await keytar.default.findCredentials(keychainConstants.service)\n debug(content`Secure store is available`)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (_error) {\n debug(content`Failed to load secure store`)\n return false\n }\n}\n"]}
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../../../src/private/node/session/store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aA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AS,CAAA;KACjB;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,IAAI,MAAM,oBAAoB,EAAE,EAAE;QAChC,MAAM,iBAAiB,CAAC,UAAU,CAAC,CAAA;KACpC;SAAM;QACL,aAAa,EAAE,CAAA;KAChB;AACH,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB;IACjC,IAAI;QACF,IAAI,eAAe,EAAE,CAAC,QAAQ,KAAK,SAAS,EAAE;YAC5C,KAAK,CAAC,OAAO,CAAA,uCAAuC,CAAC,CAAA;YACrD,OAAO,KAAK,CAAA;SACb;QACD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAA;QAC/D,KAAK,CAAC,OAAO,CAAA,2BAA2B,CAAC,CAAA;QACzC,OAAO,IAAI,CAAA;QACX,qDAAqD;KACtD;IAAC,OAAO,MAAM,EAAE;QACf,KAAK,CAAC,OAAO,CAAA,6BAA6B,CAAC,CAAA;QAC3C,OAAO,KAAK,CAAA;KACb;AACH,CAAC","sourcesContent":["import {SessionSchema} from './schema.js'\nimport {getSession, removeSession, setSession} from '../conf-store.js'\nimport {keychainConstants} from '../constants.js'\nimport {platformAndArch} from '../../../public/node/os.js'\nimport {secureStoreSave, secureStoreFetch, secureStoreRemove} from '../secure-store.js'\nimport {content, debug} from '../../../output.js'\nimport type {Session} from './schema.js'\n\n/**\n * The identifier of the session in the secure store.\n */\nexport const identifier = 'session'\n\n/**\n * Serializes the session as a JSON and stores it securely in the system.\n * If the secure store is not available, the session is stored in the local config.\n * @param session - the session to store.\n */\nexport async function store(session: Session) {\n const jsonSession = JSON.stringify(session)\n if (await secureStoreAvailable()) {\n await secureStoreSave(identifier, jsonSession)\n } else {\n setSession(jsonSession)\n }\n}\n\n/**\n * Fetches the session from the secure store and returns it.\n * If the secure store is not available, the session is fetched from the local config.\n * If the format of the session is invalid, the method will discard it.\n * In the future might add some logic for supporting migrating the schema\n * of already-persisted sessions.\n * @returns Returns a promise that resolves with the session if it exists and is valid.\n */\nexport async function fetch(): Promise<Session | undefined> {\n let content\n if (await secureStoreAvailable()) {\n content = await secureStoreFetch(identifier)\n } else {\n content = getSession()\n }\n\n if (!content) {\n return undefined\n }\n const contentJson = JSON.parse(content)\n const parsedSession = await SessionSchema.safeParseAsync(contentJson)\n if (parsedSession.success) {\n return parsedSession.data\n } else {\n await remove()\n return undefined\n }\n}\n\n/**\n * Removes a session from the system.\n */\nexport async function remove() {\n if (await secureStoreAvailable()) {\n await secureStoreRemove(identifier)\n } else {\n removeSession()\n }\n}\n\n/**\n * Returns true if the secure store is available on the system.\n * Keytar it's not supported on some Linux environments or Windows.\n * More details: https://github.com/Shopify/shopify-cli-planning/issues/261\n * @returns a boolean indicating if the secure store is available.\n */\nasync function secureStoreAvailable(): Promise<boolean> {\n try {\n if (platformAndArch().platform === 'windows') {\n debug(content`Secure store not supported on Windows`)\n return false\n }\n const keytar = await import('keytar')\n await keytar.default.findCredentials(keychainConstants.service)\n debug(content`Secure store is available`)\n return true\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (_error) {\n debug(content`Failed to load secure store`)\n return false\n }\n}\n"]}
@@ -1 +1 @@
1
- export declare const CLI_KIT_VERSION = "3.36.2";
1
+ export declare const CLI_KIT_VERSION = "3.37.0";
@@ -1,2 +1,2 @@
1
- export const CLI_KIT_VERSION = '3.36.2';
1
+ export const CLI_KIT_VERSION = '3.37.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.36.2'\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/public/common/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,eAAe,GAAG,QAAQ,CAAA","sourcesContent":["export const CLI_KIT_VERSION = '3.37.0'\n"]}
@@ -0,0 +1,2 @@
1
+ import Conf, { Schema } from 'conf';
2
+ export { Conf, Schema };
@@ -0,0 +1,3 @@
1
+ import Conf from 'conf';
2
+ export { Conf };
3
+ //# sourceMappingURL=conf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conf.js","sourceRoot":"","sources":["../../../src/public/node/conf.ts"],"names":[],"mappings":"AAAA,OAAO,IAAc,MAAM,MAAM,CAAA;AAEjC,OAAO,EAAC,IAAI,EAAS,CAAA","sourcesContent":["import Conf, {Schema} from 'conf'\n\nexport {Conf, Schema}\n"]}
@@ -8,6 +8,7 @@ interface ExecCLI2Options {
8
8
  token?: string;
9
9
  directory?: string;
10
10
  signal?: AbortSignal;
11
+ stdout?: Writable;
11
12
  }
12
13
  /**
13
14
  * Execute CLI 2.0 commands.
@@ -1,5 +1,4 @@
1
1
  import { coerceSemverVersion } from './semver.js';
2
- import { renderTasks } from './ui.js';
3
2
  import { platformAndArch } from './os.js';
4
3
  import { captureOutput, exec } from './system.js';
5
4
  import * as file from './fs.js';
@@ -7,6 +6,7 @@ import { joinPath, cwd } from './path.js';
7
6
  import { AbortError, AbortSilentError } from './error.js';
8
7
  import { pathConstants } from '../../private/node/constants.js';
9
8
  import { content, token } from '../../output.js';
9
+ import { isTruthy } from '../../private/node/environment/utilities.js';
10
10
  import { Writable } from 'stream';
11
11
  const RubyCLIVersion = '2.34.0';
12
12
  const ThemeCheckVersion = '1.14.0';
@@ -21,7 +21,7 @@ const MinRubyVersion = '2.7.5';
21
21
  * @param options - Options to customize the execution of cli2.
22
22
  */
23
23
  export async function execCLI2(args, options = {}) {
24
- await installCLIDependencies();
24
+ await installCLIDependencies(options.stdout ?? process.stdout);
25
25
  const env = {
26
26
  ...process.env,
27
27
  SHOPIFY_CLI_STOREFRONT_RENDERER_AUTH_TOKEN: options.storefrontToken,
@@ -107,32 +107,25 @@ async function installThemeCheckCLIDependencies(stdout) {
107
107
  * Install RubyCLI and its dependencies
108
108
  * Shows a loading spinner if it's the first time installing dependencies
109
109
  * or if we are installing a new version of RubyCLI.
110
+ *
111
+ * @param stdout - The Writable stream on which to write the standard output.
110
112
  */
111
- async function installCLIDependencies() {
113
+ async function installCLIDependencies(stdout) {
112
114
  const exists = await file.fileExists(shopifyCLIDirectory());
113
- const tasks = [
114
- {
115
- title: 'Installing theme dependencies',
116
- task: async () => {
117
- const usingLocalCLI2 = Boolean(process.env.SHOPIFY_CLI_2_0_DIRECTORY);
118
- await validateRubyEnv();
119
- if (usingLocalCLI2) {
120
- await bundleInstallLocalShopifyCLI();
121
- }
122
- else {
123
- await createShopifyCLIWorkingDirectory();
124
- await createShopifyCLIGemfile();
125
- await bundleInstallShopifyCLI();
126
- }
127
- },
128
- },
129
- ];
130
- if (exists) {
131
- await tasks[0].task();
115
+ if (!exists)
116
+ stdout.write('Installing theme dependencies...');
117
+ const usingLocalCLI2 = isTruthy(process.env.SHOPIFY_CLI_2_0_DIRECTORY);
118
+ await validateRubyEnv();
119
+ if (usingLocalCLI2) {
120
+ await bundleInstallLocalShopifyCLI();
132
121
  }
133
122
  else {
134
- await renderTasks(tasks);
123
+ await createShopifyCLIWorkingDirectory();
124
+ await createShopifyCLIGemfile();
125
+ await bundleInstallShopifyCLI();
135
126
  }
127
+ if (!exists)
128
+ stdout.write('Installed theme dependencies!');
136
129
  }
137
130
  /**
138
131
  * A function that validates if the environment in which the CLI is running is set up with Ruby and Bundler.
@@ -1 +1 @@
1
- {"version":3,"file":"ruby.js","sourceRoot":"","sources":["../../../src/public/node/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAA;AAC/C,OAAO,EAAC,WAAW,EAAC,MAAM,SAAS,CAAA;AAEnC,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AACvC,OAAO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/D,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACzD,CAAC","sourcesContent":["import {coerceSemverVersion} from './semver.js'\nimport {renderTasks} from './ui.js'\nimport {AbortSignal} from './abort.js'\nimport {platformAndArch} from './os.js'\nimport {captureOutput, exec} from './system.js'\nimport * as file from './fs.js'\nimport {joinPath, cwd} from './path.js'\nimport {AbortError, AbortSilentError} from './error.js'\nimport {pathConstants} from '../../private/node/constants.js'\nimport {AdminSession} from '../../public/node/session.js'\nimport {content, token} from '../../output.js'\nimport {Writable} from 'stream'\n\nconst RubyCLIVersion = '2.34.0'\nconst ThemeCheckVersion = '1.14.0'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.7.5'\n\ninterface ExecCLI2Options {\n // Contains token and store to pass to CLI 2.0, which will be set as environment variables\n adminSession?: AdminSession\n // Contains token for storefront access to pass to CLI 2.0 as environment variable\n storefrontToken?: string\n // Contains token for partners access to pass to CLI 2.0 as environment variable\n token?: string\n // Directory in which to execute the command. Otherwise the current directory will be used.\n directory?: string\n // A signal to stop the process execution.\n signal?: AbortSignal\n}\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args - List of argumets to execute. (ex: ['theme', 'pull']).\n * @param options - Options to customize the execution of cli2.\n */\nexport async function execCLI2(args: string[], options: ExecCLI2Options = {}): Promise<void> {\n await installCLIDependencies()\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n SHOPIFY_CLI_STOREFRONT_RENDERER_AUTH_TOKEN: options.storefrontToken,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: options.adminSession?.token,\n SHOPIFY_SHOP: options.adminSession?.storeFqdn,\n SHOPIFY_CLI_AUTH_TOKEN: options.token,\n SHOPIFY_CLI_RUN_AS_SUBPROCESS: 'true',\n // Bundler uses this Gemfile to understand which gems are available in the\n // environment. We use this to specify our own Gemfile for CLI2, which exists\n // outside the user's project directory.\n BUNDLE_GEMFILE: joinPath(shopifyCLIDirectory(), 'Gemfile'),\n }\n\n try {\n await exec(bundleExecutable(), ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: options.directory ?? cwd(),\n env,\n signal: options.signal,\n })\n } catch (error) {\n // CLI2 will show it's own errors, we don't need to show an additional CLI3 error\n throw new AbortSilentError()\n }\n}\n\ninterface ExecThemeCheckCLIOptions {\n /** A list of directories in which theme-check should run. */\n directories: string[]\n /** Arguments to pass to the theme-check CLI. */\n args?: string[]\n /** Writable to send standard output content through. */\n stdout: Writable\n /** Writable to send standard error content through. */\n stderr: Writable\n}\n\n/**\n * A function that installs (if needed) and runs the theme-check CLI.\n *\n * @param options - Options to customize the execution of theme-check.\n * @returns A promise that resolves or rejects depending on the result of the underlying theme-check process.\n */\nexport async function execThemeCheckCLI(options: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(options.stdout)\n\n const processes = options.directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await file.glob(joinPath(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n options.stdout.write(chunk, ...args)\n } else {\n options.stderr.write(chunk, ...args)\n }\n },\n })\n await exec(bundleExecutable(), ['exec', 'theme-check'].concat([directory, ...(options.args || [])]), {\n stdout: options.stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI.\n *\n * @param stdout - The Writable stream on which to write the standard output.\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.fileExists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI.\n */\nasync function installCLIDependencies() {\n const exists = await file.fileExists(shopifyCLIDirectory())\n const tasks = [\n {\n title: 'Installing theme dependencies',\n task: async () => {\n const usingLocalCLI2 = Boolean(process.env.SHOPIFY_CLI_2_0_DIRECTORY)\n await validateRubyEnv()\n if (usingLocalCLI2) {\n await bundleInstallLocalShopifyCLI()\n } else {\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n }\n },\n },\n ]\n\n if (exists) {\n await tasks[0]!.task()\n } else {\n await renderTasks(tasks)\n }\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby and Bundler.\n */\nasync function validateRubyEnv() {\n await validateRuby()\n await validateBundler()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby.\n */\nasync function validateRuby() {\n let version\n try {\n const stdout = await captureOutput(rubyExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new AbortError(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new AbortError(\n `Ruby version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Bundler.\n */\nasync function validateBundler() {\n let version\n try {\n const stdout = await captureOutput(bundleExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new AbortError(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new AbortError(\n `Bundler version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n}\n\n/**\n * It creates the directory where the Ruby CLI will be downloaded along its dependencies.\n */\nasync function createShopifyCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(shopifyCLIDirectory())\n}\n\n/**\n * It creates the directory where the theme-check CLI will be downloaded along its dependencies.\n */\nasync function createThemeCheckCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(themeCheckDirectory())\n}\n\n/**\n * It creates the Gemfile to install The Ruby CLI and the dependencies.\n */\nasync function createShopifyCLIGemfile(): Promise<void> {\n const gemPath = joinPath(shopifyCLIDirectory(), 'Gemfile')\n const gemFileContent = [\"source 'https://rubygems.org'\", `gem 'shopify-cli', '${RubyCLIVersion}'`]\n const {platform} = platformAndArch()\n if (platform === 'windows') {\n // 'wdm' is required by 'listen', see https://github.com/Shopify/cli/issues/780\n gemFileContent.push(\"gem 'wdm', '>= 0.1.0'\")\n }\n await file.writeFile(gemPath, gemFileContent.join('\\n'))\n}\n\n/**\n * It creates the Gemfile to install theme-check and its dependencies.\n */\nasync function createThemeCheckGemfile(): Promise<void> {\n const gemPath = joinPath(themeCheckDirectory(), 'Gemfile')\n await file.writeFile(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\n/**\n * It runs bundle install for the dev-managed copy of the Ruby CLI.\n */\nasync function bundleInstallLocalShopifyCLI(): Promise<void> {\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of the Ruby CLI.\n */\nasync function bundleInstallShopifyCLI() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {\n cwd: shopifyCLIDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of theme-check.\n */\nasync function bundleInstallThemeCheck() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', themeCheckDirectory()], {\n cwd: themeCheckDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: themeCheckDirectory()})\n}\n\n/**\n * It returns the directory where the Ruby CLI is located.\n *\n * @returns The absolute path to the directory.\n */\nfunction shopifyCLIDirectory(): string {\n return (\n process.env.SHOPIFY_CLI_2_0_DIRECTORY ??\n joinPath(pathConstants.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n )\n}\n\n/**\n * It returns the path to the directory containing the theme-check CLI.\n *\n * @returns The absolute path to the theme-check directory.\n */\nfunction themeCheckDirectory(): string {\n return joinPath(pathConstants.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\n/**\n * It returns the Ruby version present in the envirronment.\n */\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return captureOutput(rubyExecutable(), ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n\n/**\n * It returns the Ruby binary path set through the environment variable SHOPIFY_RUBY_BINDIR.\n * This is useful when the CLI is managed by an installer like a Homebrew where we need to\n * point the CLI to the Ruby installation managed by Homebrew.\n *\n * @returns The value of the environment variable.\n */\nfunction getRubyBinDir(): string | undefined {\n return process.env.SHOPIFY_RUBY_BINDIR\n}\n\n/**\n * It returns the path to the \"ruby\" executable.\n *\n * @returns The path to the executable.\n */\nfunction rubyExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'ruby') : 'ruby'\n}\n\n/**\n * It returns the path to the \"bundle\" executable.\n *\n * @returns The path to the executable.\n */\nfunction bundleExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'bundle') : 'bundle'\n}\n\n/**\n * It returns the path to the \"gem\"\" executable.\n *\n * @returns The path to the executable.\n */\nfunction gemExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'gem') : 'gem'\n}\n"]}
1
+ {"version":3,"file":"ruby.js","sourceRoot":"","sources":["../../../src/public/node/ruby.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAC,eAAe,EAAC,MAAM,SAAS,CAAA;AACvC,OAAO,EAAC,aAAa,EAAE,IAAI,EAAC,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,IAAI,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAC,QAAQ,EAAE,GAAG,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,EAAC,UAAU,EAAE,gBAAgB,EAAC,MAAM,YAAY,CAAA;AACvD,OAAO,EAAC,aAAa,EAAC,MAAM,iCAAiC,CAAA;AAE7D,OAAO,EAAC,OAAO,EAAE,KAAK,EAAC,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,6CAA6C,CAA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Aa,EAAE,iBAAiB,CAAC,CAAA;AAClG,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO;IAC3B,MAAM,WAAW,GAAG,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACnF,OAAO,aAAa,CAAC,cAAc,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;SAC3C,IAAI,CAAC,WAAW,CAAC;SACjB,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAA;AAC3B,CAAC;AAED;;;;;;GAMG;AACH,SAAS,aAAa;IACpB,OAAO,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,SAAS,cAAc;IACrB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AAC3D,CAAC;AAED;;;;GAIG;AACH,SAAS,gBAAgB;IACvB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAA;AAC/D,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa;IACpB,MAAM,UAAU,GAAG,aAAa,EAAE,CAAA;IAClC,OAAO,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AACzD,CAAC","sourcesContent":["import {coerceSemverVersion} from './semver.js'\nimport {AbortSignal} from './abort.js'\nimport {platformAndArch} from './os.js'\nimport {captureOutput, exec} from './system.js'\nimport * as file from './fs.js'\nimport {joinPath, cwd} from './path.js'\nimport {AbortError, AbortSilentError} from './error.js'\nimport {pathConstants} from '../../private/node/constants.js'\nimport {AdminSession} from '../../public/node/session.js'\nimport {content, token} from '../../output.js'\nimport {isTruthy} from '../../private/node/environment/utilities.js'\nimport {Writable} from 'stream'\n\nconst RubyCLIVersion = '2.34.0'\nconst ThemeCheckVersion = '1.14.0'\nconst MinBundlerVersion = '2.3.8'\nconst MinRubyVersion = '2.7.5'\n\ninterface ExecCLI2Options {\n // Contains token and store to pass to CLI 2.0, which will be set as environment variables\n adminSession?: AdminSession\n // Contains token for storefront access to pass to CLI 2.0 as environment variable\n storefrontToken?: string\n // Contains token for partners access to pass to CLI 2.0 as environment variable\n token?: string\n // Directory in which to execute the command. Otherwise the current directory will be used.\n directory?: string\n // A signal to stop the process execution.\n signal?: AbortSignal\n // Stream to pipe the command's stdout to.\n stdout?: Writable\n}\n/**\n * Execute CLI 2.0 commands.\n * Installs a version of RubyCLI as a vendor dependency in a hidden folder in the system.\n * User must have a valid ruby+bundler environment to run any command.\n *\n * @param args - List of argumets to execute. (ex: ['theme', 'pull']).\n * @param options - Options to customize the execution of cli2.\n */\nexport async function execCLI2(args: string[], options: ExecCLI2Options = {}): Promise<void> {\n await installCLIDependencies(options.stdout ?? process.stdout)\n const env: NodeJS.ProcessEnv = {\n ...process.env,\n SHOPIFY_CLI_STOREFRONT_RENDERER_AUTH_TOKEN: options.storefrontToken,\n SHOPIFY_CLI_ADMIN_AUTH_TOKEN: options.adminSession?.token,\n SHOPIFY_SHOP: options.adminSession?.storeFqdn,\n SHOPIFY_CLI_AUTH_TOKEN: options.token,\n SHOPIFY_CLI_RUN_AS_SUBPROCESS: 'true',\n // Bundler uses this Gemfile to understand which gems are available in the\n // environment. We use this to specify our own Gemfile for CLI2, which exists\n // outside the user's project directory.\n BUNDLE_GEMFILE: joinPath(shopifyCLIDirectory(), 'Gemfile'),\n }\n\n try {\n await exec(bundleExecutable(), ['exec', 'shopify'].concat(args), {\n stdio: 'inherit',\n cwd: options.directory ?? cwd(),\n env,\n signal: options.signal,\n })\n } catch (error) {\n // CLI2 will show it's own errors, we don't need to show an additional CLI3 error\n throw new AbortSilentError()\n }\n}\n\ninterface ExecThemeCheckCLIOptions {\n /** A list of directories in which theme-check should run. */\n directories: string[]\n /** Arguments to pass to the theme-check CLI. */\n args?: string[]\n /** Writable to send standard output content through. */\n stdout: Writable\n /** Writable to send standard error content through. */\n stderr: Writable\n}\n\n/**\n * A function that installs (if needed) and runs the theme-check CLI.\n *\n * @param options - Options to customize the execution of theme-check.\n * @returns A promise that resolves or rejects depending on the result of the underlying theme-check process.\n */\nexport async function execThemeCheckCLI(options: ExecThemeCheckCLIOptions): Promise<void[]> {\n await installThemeCheckCLIDependencies(options.stdout)\n\n const processes = options.directories.map(async (directory): Promise<void> => {\n // Check that there are files aside from the extension TOML config file,\n // otherwise theme-check will return a false failure.\n const files = await file.glob(joinPath(directory, '/**/*'))\n const fileCount = files.filter((file) => !file.match(/\\.toml$/)).length\n if (fileCount === 0) return\n\n const customStderr = new Writable({\n write(chunk, ...args) {\n // For some reason, theme-check reports this initial status line to stderr\n // See https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/diagnostics_engine.rb#L31\n // which leads to https://github.com/Shopify/theme-check/blob/1092737cfb58a73ca397ffb1371665dc55df2976/lib/theme_check/language_server/io_messenger.rb#L65\n if (chunk.toString('ascii').match(/^Checking/)) {\n options.stdout.write(chunk, ...args)\n } else {\n options.stderr.write(chunk, ...args)\n }\n },\n })\n await exec(bundleExecutable(), ['exec', 'theme-check'].concat([directory, ...(options.args || [])]), {\n stdout: options.stdout,\n stderr: customStderr,\n cwd: themeCheckDirectory(),\n })\n })\n return Promise.all(processes)\n}\n\n/**\n * Validate Ruby Enviroment\n * Install Theme Check CLI and its dependencies\n * Shows a loading message if it's the first time installing dependencies\n * or if we are installing a new version of Theme Check CLI.\n *\n * @param stdout - The Writable stream on which to write the standard output.\n */\nasync function installThemeCheckCLIDependencies(stdout: Writable) {\n const exists = await file.fileExists(themeCheckDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n await validateRubyEnv()\n await createThemeCheckCLIWorkingDirectory()\n await createThemeCheckGemfile()\n await bundleInstallThemeCheck()\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * Validate Ruby Enviroment\n * Install RubyCLI and its dependencies\n * Shows a loading spinner if it's the first time installing dependencies\n * or if we are installing a new version of RubyCLI.\n *\n * @param stdout - The Writable stream on which to write the standard output.\n */\nasync function installCLIDependencies(stdout: Writable) {\n const exists = await file.fileExists(shopifyCLIDirectory())\n\n if (!exists) stdout.write('Installing theme dependencies...')\n const usingLocalCLI2 = isTruthy(process.env.SHOPIFY_CLI_2_0_DIRECTORY)\n await validateRubyEnv()\n if (usingLocalCLI2) {\n await bundleInstallLocalShopifyCLI()\n } else {\n await createShopifyCLIWorkingDirectory()\n await createShopifyCLIGemfile()\n await bundleInstallShopifyCLI()\n }\n\n if (!exists) stdout.write('Installed theme dependencies!')\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby and Bundler.\n */\nasync function validateRubyEnv() {\n await validateRuby()\n await validateBundler()\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Ruby.\n */\nasync function validateRuby() {\n let version\n try {\n const stdout = await captureOutput(rubyExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new AbortError(\n 'Ruby environment not found',\n `Make sure you have Ruby installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinRubyVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new AbortError(\n `Ruby version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `Make sure you have at least Ruby ${content`${token.yellow(MinRubyVersion)}`.value} installed on your system. ${\n content`${token.link('Documentation.', 'https://www.ruby-lang.org/en/documentation/installation/')}`.value\n }`,\n )\n }\n}\n\n/**\n * A function that validates if the environment in which the CLI is running is set up with Bundler.\n */\nasync function validateBundler() {\n let version\n try {\n const stdout = await captureOutput(bundleExecutable(), ['-v'])\n version = coerceSemverVersion(stdout)\n } catch {\n throw new AbortError(\n 'Bundler not found',\n `To install the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n\n const isValid = version?.compare(MinBundlerVersion)\n if (isValid === -1 || isValid === undefined) {\n throw new AbortError(\n `Bundler version ${content`${token.yellow(version.raw)}`.value} is not supported`,\n `To update to the latest version of Bundler, run ${\n content`${token.genericShellCommand(`${gemExecutable()} install bundler`)}`.value\n }`,\n )\n }\n}\n\n/**\n * It creates the directory where the Ruby CLI will be downloaded along its dependencies.\n */\nasync function createShopifyCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(shopifyCLIDirectory())\n}\n\n/**\n * It creates the directory where the theme-check CLI will be downloaded along its dependencies.\n */\nasync function createThemeCheckCLIWorkingDirectory(): Promise<void> {\n return file.mkdir(themeCheckDirectory())\n}\n\n/**\n * It creates the Gemfile to install The Ruby CLI and the dependencies.\n */\nasync function createShopifyCLIGemfile(): Promise<void> {\n const gemPath = joinPath(shopifyCLIDirectory(), 'Gemfile')\n const gemFileContent = [\"source 'https://rubygems.org'\", `gem 'shopify-cli', '${RubyCLIVersion}'`]\n const {platform} = platformAndArch()\n if (platform === 'windows') {\n // 'wdm' is required by 'listen', see https://github.com/Shopify/cli/issues/780\n gemFileContent.push(\"gem 'wdm', '>= 0.1.0'\")\n }\n await file.writeFile(gemPath, gemFileContent.join('\\n'))\n}\n\n/**\n * It creates the Gemfile to install theme-check and its dependencies.\n */\nasync function createThemeCheckGemfile(): Promise<void> {\n const gemPath = joinPath(themeCheckDirectory(), 'Gemfile')\n await file.writeFile(gemPath, `source 'https://rubygems.org'\\ngem 'theme-check', '${ThemeCheckVersion}'`)\n}\n\n/**\n * It runs bundle install for the dev-managed copy of the Ruby CLI.\n */\nasync function bundleInstallLocalShopifyCLI(): Promise<void> {\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of the Ruby CLI.\n */\nasync function bundleInstallShopifyCLI() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', shopifyCLIDirectory()], {\n cwd: shopifyCLIDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: shopifyCLIDirectory()})\n}\n\n/**\n * It runs bundle install for the CLI-managed copy of theme-check.\n */\nasync function bundleInstallThemeCheck() {\n await exec(bundleExecutable(), ['config', 'set', '--local', 'path', themeCheckDirectory()], {\n cwd: themeCheckDirectory(),\n })\n await exec(bundleExecutable(), ['install'], {cwd: themeCheckDirectory()})\n}\n\n/**\n * It returns the directory where the Ruby CLI is located.\n *\n * @returns The absolute path to the directory.\n */\nfunction shopifyCLIDirectory(): string {\n return (\n process.env.SHOPIFY_CLI_2_0_DIRECTORY ??\n joinPath(pathConstants.directories.cache.vendor.path(), 'ruby-cli', RubyCLIVersion)\n )\n}\n\n/**\n * It returns the path to the directory containing the theme-check CLI.\n *\n * @returns The absolute path to the theme-check directory.\n */\nfunction themeCheckDirectory(): string {\n return joinPath(pathConstants.directories.cache.vendor.path(), 'theme-check', ThemeCheckVersion)\n}\n\n/**\n * It returns the Ruby version present in the envirronment.\n */\nexport async function version(): Promise<string | undefined> {\n const parseOutput = (version: string) => version.match(/ruby (\\d+\\.\\d+\\.\\d+)/)?.[1]\n return captureOutput(rubyExecutable(), ['-v'])\n .then(parseOutput)\n .catch(() => undefined)\n}\n\n/**\n * It returns the Ruby binary path set through the environment variable SHOPIFY_RUBY_BINDIR.\n * This is useful when the CLI is managed by an installer like a Homebrew where we need to\n * point the CLI to the Ruby installation managed by Homebrew.\n *\n * @returns The value of the environment variable.\n */\nfunction getRubyBinDir(): string | undefined {\n return process.env.SHOPIFY_RUBY_BINDIR\n}\n\n/**\n * It returns the path to the \"ruby\" executable.\n *\n * @returns The path to the executable.\n */\nfunction rubyExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'ruby') : 'ruby'\n}\n\n/**\n * It returns the path to the \"bundle\" executable.\n *\n * @returns The path to the executable.\n */\nfunction bundleExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'bundle') : 'bundle'\n}\n\n/**\n * It returns the path to the \"gem\"\" executable.\n *\n * @returns The path to the executable.\n */\nfunction gemExecutable(): string {\n const rubyBinDir = getRubyBinDir()\n return rubyBinDir ? joinPath(rubyBinDir, 'gem') : 'gem'\n}\n"]}