@shopify/cli-kit 3.58.1 → 3.59.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/assets/cli-ruby/Gemfile +0 -2
- package/assets/cli-ruby/lib/project_types/theme/cli.rb +0 -2
- package/assets/cli-ruby/lib/shopify_cli/constants.rb +6 -0
- package/assets/cli-ruby/lib/shopify_cli/environment.rb +7 -0
- package/assets/cli-ruby/lib/shopify_cli/theme/dev_server/proxy.rb +6 -1
- package/assets/cli-ruby/lib/shopify_cli/theme/repl/api.rb +1 -1
- package/assets/cli-ruby/lib/shopify_cli/theme/theme_access_api.rb +3 -3
- package/assets/cli-ruby/shopify-cli.gemspec +0 -8
- package/dist/private/common/ts/overloaded-parameters.d.ts +0 -1
- package/dist/private/common/ts/overloaded-parameters.js.map +1 -1
- package/dist/private/node/analytics.d.ts +1 -0
- package/dist/private/node/analytics.js +2 -0
- package/dist/private/node/analytics.js.map +1 -1
- package/dist/private/node/api/graphql.d.ts +1 -1
- package/dist/private/node/api/graphql.js.map +1 -1
- package/dist/private/node/api/headers.js +1 -1
- package/dist/private/node/api/headers.js.map +1 -1
- package/dist/private/node/api/rest.d.ts +2 -1
- package/dist/private/node/api/rest.js +4 -2
- package/dist/private/node/api/rest.js.map +1 -1
- package/dist/private/node/constants.d.ts +2 -3
- package/dist/private/node/constants.js +2 -3
- package/dist/private/node/constants.js.map +1 -1
- package/dist/private/node/session/authorize.js +1 -1
- package/dist/private/node/session/authorize.js.map +1 -1
- package/dist/private/node/session/device-authorization.js +1 -1
- package/dist/private/node/session/device-authorization.js.map +1 -1
- package/dist/private/node/session/exchange.d.ts +2 -1
- package/dist/private/node/session/exchange.js.map +1 -1
- package/dist/private/node/session/post-auth.d.ts +0 -3
- package/dist/private/node/session/post-auth.js +1 -2
- package/dist/private/node/session/post-auth.js.map +1 -1
- package/dist/private/node/session/store.d.ts +0 -4
- package/dist/private/node/session/store.js +0 -4
- package/dist/private/node/session/store.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.js +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.js.map +1 -1
- package/dist/private/node/ui/components/AutocompletePrompt.test.js.map +1 -1
- package/dist/private/node/ui/components/ConcurrentOutput.d.ts +0 -3
- package/dist/private/node/ui/components/ConcurrentOutput.js.map +1 -1
- package/dist/private/node/ui/components/FatalError.d.ts +1 -1
- package/dist/private/node/ui/components/FatalError.js.map +1 -1
- package/dist/private/node/ui/components/Prompts/PromptLayout.d.ts +1 -1
- package/dist/private/node/ui/components/Prompts/PromptLayout.js.map +1 -1
- package/dist/private/node/ui/components/Scrollbar.d.ts +1 -1
- package/dist/private/node/ui/components/Scrollbar.js.map +1 -1
- package/dist/private/node/ui/components/SelectPrompt.test.js +0 -2
- package/dist/private/node/ui/components/SelectPrompt.test.js.map +1 -1
- package/dist/private/node/ui/hooks/use-select-state.js.map +1 -1
- package/dist/public/common/version.d.ts +1 -1
- package/dist/public/common/version.js +1 -1
- package/dist/public/common/version.js.map +1 -1
- package/dist/public/node/api/business-platform.d.ts +1 -1
- package/dist/public/node/api/business-platform.js +1 -1
- package/dist/public/node/api/business-platform.js.map +1 -1
- package/dist/public/node/cli.d.ts +1 -1
- package/dist/public/node/cli.js +5 -6
- package/dist/public/node/cli.js.map +1 -1
- package/dist/public/node/custom-oclif-loader.js +23 -0
- package/dist/public/node/custom-oclif-loader.js.map +1 -1
- package/dist/public/node/is-global.d.ts +31 -0
- package/dist/public/node/is-global.js +69 -0
- package/dist/public/node/is-global.js.map +1 -1
- package/dist/public/node/monorail.d.ts +2 -1
- package/dist/public/node/monorail.js +15 -2
- package/dist/public/node/monorail.js.map +1 -1
- package/dist/public/node/tcp.d.ts +8 -1
- package/dist/public/node/tcp.js +8 -2
- package/dist/public/node/tcp.js.map +1 -1
- package/dist/public/node/themes/utils.d.ts +1 -0
- package/dist/public/node/themes/utils.js +9 -0
- package/dist/public/node/themes/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -12
- package/assets/cli-ruby/lib/project_types/theme/commands/check.rb +0 -38
- package/assets/cli-ruby/lib/project_types/theme/commands/language_server.rb +0 -18
- package/dist/private/common/lodash.d.ts +0 -47
- package/dist/private/common/lodash.js +0 -2
- package/dist/private/common/lodash.js.map +0 -1
- package/dist/private/node/ui/components/FullScreen.d.ts +0 -8
- package/dist/private/node/ui/components/FullScreen.js +0 -33
- package/dist/private/node/ui/components/FullScreen.js.map +0 -1
|
@@ -6,7 +6,6 @@ import { AbortController } from '../../../../public/node/abort.js';
|
|
|
6
6
|
import { beforeEach, describe, expect, test, vi } from 'vitest';
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import { useStdout } from 'ink';
|
|
9
|
-
import { platformAndArch } from '@shopify/cli-kit/node/os';
|
|
10
9
|
vi.mock('ink', async () => {
|
|
11
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
11
|
const original = await vi.importActual('ink');
|
|
@@ -124,7 +123,6 @@ describe('SelectPrompt', async () => {
|
|
|
124
123
|
"
|
|
125
124
|
`);
|
|
126
125
|
});
|
|
127
|
-
const runningOnWindows = platformAndArch().platform === 'windows';
|
|
128
126
|
test('supports an info message', async () => {
|
|
129
127
|
const items = [
|
|
130
128
|
{ label: 'first', value: 'first' },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SelectPrompt.test.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/SelectPrompt.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAC,wBAAwB,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,EAAC,MAAM,qBAAqB,CAAA;AACvH,OAAO,EAAC,QAAQ,EAAC,MAAM,mCAAmC,CAAA;AAC1D,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAClC,OAAO,EAAC,eAAe,EAAC,MAAM,kCAAkC,C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AAE,GAAE,CAAC,EAClB,OAAO,EAAC,gBAAgB,EACxB,WAAW,EAAE,eAAe,CAAC,MAAM,GACnC,CACH,CAAA;QAED,MAAM,OAAO,GAAG,cAAc,CAAC,aAAa,EAAE,CAAA;QAE9C,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,SAAS,EAAG,CAAC,CAAC,CAAC,qBAAqB,CAAC;;;;;;;;KAQnE,CAAC,CAAA;QAEF,eAAe,CAAC,KAAK,EAAE,CAAA;QAEvB,0CAA0C;QAC1C,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;QAEtD,MAAM,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC5D,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {SelectPrompt} from './SelectPrompt.js'\nimport {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady, render} from '../../testing/ui.js'\nimport {unstyled} from '../../../../public/node/output.js'\nimport {Stdout} from '../../ui.js'\nimport {AbortController} from '../../../../public/node/abort.js'\nimport {beforeEach, describe, expect, test, vi} from 'vitest'\nimport React from 'react'\nimport {useStdout} from 'ink'\nimport {platformAndArch} from '@shopify/cli-kit/node/os'\n\nvi.mock('ink', async () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const original: any = await vi.importActual('ink')\n return {\n ...original,\n useStdout: vi.fn(),\n }\n})\n\nconst ARROW_DOWN = '\\u001B[B'\nconst ARROW_UP = '\\u001B[A'\nconst ENTER = '\\r'\n\nbeforeEach(() => {\n vi.mocked(useStdout).mockReturnValue({\n stdout: new Stdout({\n columns: 80,\n rows: 80,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n write: () => {},\n })\n})\n\ndescribe('SelectPrompt', async () => {\n test('choose an answer', async () => {\n const onEnter = vi.fn()\n\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n ]\n\n const infoTable = {Add: ['new-ext'], Remove: ['integrated-demand-ext', 'order-discount']}\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={onEnter}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n \u001b[36m✔\u001b[39m \u001b[36msecond\u001b[39m\n \"\n `)\n\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('renders groups', async () => {\n const items = [\n {label: 'first', value: 'first', group: 'Automations'},\n {label: 'second', value: 'second', group: 'Automations'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n\n \u001b[1mMerchant Admin\u001b[22m\n third\n fourth\n\n \u001b[1mOther\u001b[22m\n fifth\n sixth\n seventh\n eighth\n ninth\n tenth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('supports an info table', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoTable = [\n {\n header: 'Add',\n items: ['new-ext'],\n bullet: '+',\n },\n {\n header: 'Remove',\n items: ['integrated-demand-ext', ['order-discount', {subdued: '(1)'}]],\n bullet: '-',\n },\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n ┃ \\u001b[1mAdd\\u001b[22m\n ┃ + new-ext\n ┃\n ┃ \\u001b[1mRemove\\u001b[22m\n ┃ - integrated-demand-ext\n ┃ - order-discount \u001b[2m(1)\u001b[22m\n\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n third\n fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n const runningOnWindows = platformAndArch().platform === 'windows'\n\n test('supports an info message', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoMessage = {\n title: {\n color: 'red',\n text: 'Info message title',\n },\n body: 'Info message body',\n }\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoMessage={infoMessage}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n ┃ \u001b[31mInfo message title\u001b[39m\n ┃\n ┃ Info message body\n\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n third\n fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test(\"it doesn't submit if there are no choices\", async () => {\n const onEnter = vi.fn()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items: any[] = []\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={onEnter}\n />,\n )\n\n expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toContain(\n 'ERROR SelectPrompt requires at least one choice',\n )\n })\n\n test(\"doesn't append a colon to the message if it ends with a question mark\", async () => {\n const {lastFrame} = render(\n <SelectPrompt choices={[{label: 'a', value: 'a'}]} onSubmit={() => {}} message=\"Test question?\" />,\n )\n\n expect(unstyled(lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n })\n\n test('accepts a default value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" defaultValue=\"b\" />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n a\n > b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('can submit the initial value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36ma\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[0]!.value)\n })\n\n test('allow submitting with a shortcut directly', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a', key: 'a'},\n {label: 'b', value: 'b', key: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (a) a\n (b) b\n\n Press ↑↓ arrows to select, enter or a shortcut to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, 'b')\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('adapts to the height of the container', async () => {\n vi.mocked(useStdout).mockReturnValue({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stdout: new Stdout({rows: 10}) as any,\n write: () => {},\n })\n\n const items = [\n {label: 'first', value: 'first', group: 'Automations'},\n {label: 'second', value: 'second', group: 'Automations'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m \u001b[46m \u001b[49m\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m \u001b[100m \u001b[49m\n second \u001b[100m \u001b[49m\n \u001b[100m \u001b[49m\n \u001b[1mMerchant Admin\u001b[22m \u001b[100m \u001b[49m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('allows passing false as the default value', async () => {\n const items = [\n {label: 'yes', value: true},\n {label: 'no', value: false},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n defaultValue={false}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n yes\n \u001b[36m>\u001b[39m \u001b[36mno\u001b[39m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('allows selecting a different option after having selected an option with a falsy value', async () => {\n const items = [\n {label: 'yes', value: true},\n {label: 'no', value: false},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n yes\n \u001b[36m>\u001b[39m \u001b[36mno\u001b[39m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n\n await sendInputAndWaitForChange(renderInstance, ARROW_UP)\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[36m>\u001b[39m \u001b[36myes\u001b[39m\n no\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('abortController can be used to exit the prompt from outside', async () => {\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const abortController = new AbortController()\n\n const renderInstance = render(\n <SelectPrompt\n choices={items}\n onSubmit={() => {}}\n message=\"Test question?\"\n abortSignal={abortController.signal}\n />,\n )\n\n const promise = renderInstance.waitUntilExit()\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n abortController.abort()\n\n // wait for the onAbort promise to resolve\n await new Promise((resolve) => setTimeout(resolve, 0))\n\n expect(getLastFrameAfterUnmount(renderInstance)).toEqual('')\n await expect(promise).resolves.toEqual(undefined)\n })\n})\n"]}
|
|
1
|
+
{"version":3,"file":"SelectPrompt.test.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/components/SelectPrompt.test.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAC,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EAAC,wBAAwB,EAAE,yBAAyB,EAAE,sBAAsB,EAAE,MAAM,EAAC,MAAM,qBAAqB,CAAA;AACvH,OAAO,EAAC,QAAQ,EAAC,MAAM,mCAAmC,CAAA;AAC1D,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAA;AAClC,OAAO,EAAC,eAAe,EAAC,MAAM,kCAAkC,CAAA;AAChE,OAAO,EAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAC,MAAM,QAAQ,CAAA;AAC7D,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAC,SAAS,EAAC,MAAM,KAAK,CAAA;AAE7B,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE;IACxB,8DAA8D;IAC9D,MAAM,QAAQ,GAAQ,MAAM,EAAE,CAAC,YAAY,CAA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AAC,wBAAwB,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;QAC5D,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAA;IACnD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA","sourcesContent":["import {SelectPrompt} from './SelectPrompt.js'\nimport {getLastFrameAfterUnmount, sendInputAndWaitForChange, waitForInputsToBeReady, render} from '../../testing/ui.js'\nimport {unstyled} from '../../../../public/node/output.js'\nimport {Stdout} from '../../ui.js'\nimport {AbortController} from '../../../../public/node/abort.js'\nimport {beforeEach, describe, expect, test, vi} from 'vitest'\nimport React from 'react'\nimport {useStdout} from 'ink'\n\nvi.mock('ink', async () => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const original: any = await vi.importActual('ink')\n return {\n ...original,\n useStdout: vi.fn(),\n }\n})\n\nconst ARROW_DOWN = '\\u001B[B'\nconst ARROW_UP = '\\u001B[A'\nconst ENTER = '\\r'\n\nbeforeEach(() => {\n vi.mocked(useStdout).mockReturnValue({\n stdout: new Stdout({\n columns: 80,\n rows: 80,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n }) as any,\n write: () => {},\n })\n})\n\ndescribe('SelectPrompt', async () => {\n test('choose an answer', async () => {\n const onEnter = vi.fn()\n\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n ]\n\n const infoTable = {Add: ['new-ext'], Remove: ['integrated-demand-ext', 'order-discount']}\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={onEnter}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n \u001b[36m✔\u001b[39m \u001b[36msecond\u001b[39m\n \"\n `)\n\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('renders groups', async () => {\n const items = [\n {label: 'first', value: 'first', group: 'Automations'},\n {label: 'second', value: 'second', group: 'Automations'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n\n \u001b[1mMerchant Admin\u001b[22m\n third\n fourth\n\n \u001b[1mOther\u001b[22m\n fifth\n sixth\n seventh\n eighth\n ninth\n tenth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('supports an info table', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoTable = [\n {\n header: 'Add',\n items: ['new-ext'],\n bullet: '+',\n },\n {\n header: 'Remove',\n items: ['integrated-demand-ext', ['order-discount', {subdued: '(1)'}]],\n bullet: '-',\n },\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoTable={infoTable}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n ┃ \\u001b[1mAdd\\u001b[22m\n ┃ + new-ext\n ┃\n ┃ \\u001b[1mRemove\\u001b[22m\n ┃ - integrated-demand-ext\n ┃ - order-discount \u001b[2m(1)\u001b[22m\n\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n third\n fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('supports an info message', async () => {\n const items = [\n {label: 'first', value: 'first'},\n {label: 'second', value: 'second'},\n {label: 'third', value: 'third'},\n {label: 'fourth', value: 'fourth'},\n ]\n\n const infoMessage = {\n title: {\n color: 'red',\n text: 'Info message title',\n },\n body: 'Info message body',\n }\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n infoMessage={infoMessage}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n ┃ \u001b[31mInfo message title\u001b[39m\n ┃\n ┃ Info message body\n\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m\n second\n third\n fourth\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test(\"it doesn't submit if there are no choices\", async () => {\n const onEnter = vi.fn()\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const items: any[] = []\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={onEnter}\n />,\n )\n\n expect(unstyled(getLastFrameAfterUnmount(renderInstance)!)).toContain(\n 'ERROR SelectPrompt requires at least one choice',\n )\n })\n\n test(\"doesn't append a colon to the message if it ends with a question mark\", async () => {\n const {lastFrame} = render(\n <SelectPrompt choices={[{label: 'a', value: 'a'}]} onSubmit={() => {}} message=\"Test question?\" />,\n )\n\n expect(unstyled(lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n })\n\n test('accepts a default value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(\n <SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" defaultValue=\"b\" />,\n )\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n a\n > b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('can submit the initial value', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ENTER)\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36ma\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[0]!.value)\n })\n\n test('allow submitting with a shortcut directly', async () => {\n const onEnter = vi.fn()\n const items = [\n {label: 'a', value: 'a', key: 'a'},\n {label: 'b', value: 'b', key: 'b'},\n ]\n\n const renderInstance = render(<SelectPrompt choices={items} onSubmit={onEnter} message=\"Test question?\" />)\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > (a) a\n (b) b\n\n Press ↑↓ arrows to select, enter or a shortcut to confirm.\n \"\n `)\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, 'b')\n\n expect(getLastFrameAfterUnmount(renderInstance)).toMatchInlineSnapshot(`\n \"? Test question?\n \u001b[36m✔\u001b[39m \u001b[36mb\u001b[39m\n \"\n `)\n expect(onEnter).toHaveBeenCalledWith(items[1]!.value)\n })\n\n test('adapts to the height of the container', async () => {\n vi.mocked(useStdout).mockReturnValue({\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n stdout: new Stdout({rows: 10}) as any,\n write: () => {},\n })\n\n const items = [\n {label: 'first', value: 'first', group: 'Automations'},\n {label: 'second', value: 'second', group: 'Automations'},\n {label: 'third', value: 'third', group: 'Merchant Admin'},\n {label: 'fourth', value: 'fourth', group: 'Merchant Admin'},\n {label: 'fifth', value: 'fifth'},\n {label: 'sixth', value: 'sixth'},\n {label: 'seventh', value: 'seventh'},\n {label: 'eighth', value: 'eighth'},\n {label: 'ninth', value: 'ninth'},\n {label: 'tenth', value: 'tenth'},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[1mAutomations\u001b[22m \u001b[46m \u001b[49m\n \u001b[36m>\u001b[39m \u001b[36mfirst\u001b[39m \u001b[100m \u001b[49m\n second \u001b[100m \u001b[49m\n \u001b[100m \u001b[49m\n \u001b[1mMerchant Admin\u001b[22m \u001b[100m \u001b[49m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('allows passing false as the default value', async () => {\n const items = [\n {label: 'yes', value: true},\n {label: 'no', value: false},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n defaultValue={false}\n />,\n )\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n yes\n \u001b[36m>\u001b[39m \u001b[36mno\u001b[39m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('allows selecting a different option after having selected an option with a falsy value', async () => {\n const items = [\n {label: 'yes', value: true},\n {label: 'no', value: false},\n ]\n\n const renderInstance = render(\n <SelectPrompt\n message=\"Associate your project with the org Castile Ventures?\"\n choices={items}\n onSubmit={() => {}}\n />,\n )\n\n await waitForInputsToBeReady()\n await sendInputAndWaitForChange(renderInstance, ARROW_DOWN)\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n yes\n \u001b[36m>\u001b[39m \u001b[36mno\u001b[39m\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n\n await sendInputAndWaitForChange(renderInstance, ARROW_UP)\n\n expect(renderInstance.lastFrame()).toMatchInlineSnapshot(`\n \"? Associate your project with the org Castile Ventures?\n\n \u001b[36m>\u001b[39m \u001b[36myes\u001b[39m\n no\n\n \u001b[2mPress ↑↓ arrows to select, enter to confirm.\u001b[22m\n \"\n `)\n })\n\n test('abortController can be used to exit the prompt from outside', async () => {\n const items = [\n {label: 'a', value: 'a'},\n {label: 'b', value: 'b'},\n ]\n\n const abortController = new AbortController()\n\n const renderInstance = render(\n <SelectPrompt\n choices={items}\n onSubmit={() => {}}\n message=\"Test question?\"\n abortSignal={abortController.signal}\n />,\n )\n\n const promise = renderInstance.waitUntilExit()\n\n expect(unstyled(renderInstance.lastFrame()!)).toMatchInlineSnapshot(`\n \"? Test question?\n\n > a\n b\n\n Press ↑↓ arrows to select, enter to confirm.\n \"\n `)\n\n abortController.abort()\n\n // wait for the onAbort promise to resolve\n await new Promise((resolve) => setTimeout(resolve, 0))\n\n expect(getLastFrameAfterUnmount(renderInstance)).toEqual('')\n await expect(promise).resolves.toEqual(undefined)\n })\n})\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-select-state.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/hooks/use-select-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAChE,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAU3C,MAAM,CAAC,OAAO,OAAO,SAAa,SAAQ,GAAwB;IAGhE,YAAY,OAAoB;QAC9B,MAAM,KAAK,GAA4B,EAAE,CAAA;QACzC,IAAI,SAAuC,CAAA;QAC3C,IAAI,QAAsC,CAAA;QAC1C,IAAI,KAAK,GAAG,CAAC,CAAA;QAEb,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,IAAI,GAAG;gBACX,GAAG,MAAM;gBACT,QAAQ;gBACR,IAAI,EAAE,SAAS;gBACf,KAAK;aACN,CAAA;YAED,IAAI,QAAQ,EAAE;gBACZ,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAA;aACrB;YAED,IAAI,CAAC,SAAS,EAAE;gBACd,SAAS,GAAG,IAAI,CAAA;aACjB;YAED,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;YAChC,KAAK,EAAE,CAAA;YACP,QAAQ,GAAG,IAAI,CAAA;SAChB;QAED,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;CACF;AAsDD,MAAM,OAAO,GAAG,CAAI,KAAe,EAAE,MAAiB,EAAY,EAAE;IAClE,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,oBAAoB,CAAC,CAAC;YACzB,IAAI,OAAO,KAAK,CAAC,KAAK,KAAK,WAAW,EAAE;gBACtC,OAAO,KAAK,CAAA;aACb;YAED,MAAM,IAAI,GAAG,KAAK,CAAC,S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aAAa,EAAE,KAAK,CAAC,aAAa;KACnC,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {Item} from '../components/SelectInput.js'\nimport {useReducer, useCallback, useMemo, useState} from 'react'\nimport {isDeepStrictEqual} from 'node:util'\n\ntype Option<T> = Item<T>\n\ntype OptionMapItem<T> = Option<T> & {\n previous: OptionMapItem<T> | undefined\n next: OptionMapItem<T> | undefined\n index: number\n}\n\nexport default class OptionMap<T> extends Map<T, OptionMapItem<T>> {\n readonly first: OptionMapItem<T> | undefined\n\n constructor(options: Option<T>[]) {\n const items: [T, OptionMapItem<T>][] = []\n let firstItem: OptionMapItem<T> | undefined\n let previous: OptionMapItem<T> | undefined\n let index = 0\n\n for (const option of options) {\n const item = {\n ...option,\n previous,\n next: undefined,\n index,\n }\n\n if (previous) {\n previous.next = item\n }\n\n if (!firstItem) {\n firstItem = item\n }\n\n items.push([option.value, item])\n index++\n previous = item\n }\n\n super(items)\n this.first = firstItem\n }\n}\n\ninterface State<T> {\n /**\n * Map where key is option's value and value is option's index.\n */\n optionMap: OptionMap<T>\n\n /**\n * Number of visible options.\n */\n visibleOptionCount: number\n\n /**\n * Index of the first visible option.\n */\n visibleFromIndex: number\n\n /**\n * Index of the last visible option.\n */\n visibleToIndex: number\n\n /**\n * Value of the previously selected option.\n */\n previousValue: T | undefined\n\n /**\n * Value of the selected option.\n */\n value: T | undefined\n}\n\ntype Action<T> = SelectNextOptionAction<T> | SelectPreviousOptionAction<T> | SelectOptionAction<T> | ResetAction<T>\n\ninterface SelectNextOptionAction<T> {\n type: 'select-next-option'\n}\n\ninterface SelectPreviousOptionAction<T> {\n type: 'select-previous-option'\n}\n\ninterface SelectOptionAction<T> {\n type: 'select-option'\n option: Option<T>\n}\n\ninterface ResetAction<T> {\n type: 'reset'\n state: State<T>\n}\n\nconst reducer = <T>(state: State<T>, action: Action<T>): State<T> => {\n switch (action.type) {\n case 'select-next-option': {\n if (typeof state.value === 'undefined') {\n return state\n }\n\n const item = state.optionMap.get(state.value)\n\n if (!item) {\n return state\n }\n\n let next = item.next\n\n while (next && next.disabled) {\n next = next.next\n }\n\n if (!next) {\n return state\n }\n\n const needsToScroll = next.index > state.visibleToIndex\n\n if (!needsToScroll) {\n return {\n ...state,\n value: next.value,\n }\n }\n\n const nextVisibleToIndex = next.index\n const nextVisibleFromIndex = nextVisibleToIndex - state.visibleOptionCount + 1\n\n return {\n ...state,\n value: next.value,\n visibleFromIndex: nextVisibleFromIndex,\n visibleToIndex: nextVisibleToIndex,\n previousValue: state.value,\n }\n }\n\n case 'select-previous-option': {\n if (typeof state.value === 'undefined') {\n return state\n }\n\n const item = state.optionMap.get(state.value)\n\n if (!item) {\n return state\n }\n\n let previous = item.previous\n\n while (previous && previous.disabled) {\n previous = previous.previous\n }\n\n if (!previous) {\n return state\n }\n\n const needsToScroll = previous.index < state.visibleFromIndex\n\n if (!needsToScroll) {\n return {\n ...state,\n value: previous.value,\n }\n }\n\n const nextVisibleFromIndex = previous.index\n const nextVisibleToIndex = nextVisibleFromIndex + state.visibleOptionCount - 1\n\n return {\n ...state,\n value: previous.value,\n visibleFromIndex: nextVisibleFromIndex,\n visibleToIndex: nextVisibleToIndex,\n previousValue: state.value,\n }\n }\n\n case 'select-option': {\n const item = state.optionMap.get(action.option.value)\n\n if (!item) {\n return state\n }\n\n return {\n ...state,\n value: item.value,\n previousValue: state.value,\n }\n }\n\n case 'reset': {\n return action.state\n }\n\n default: {\n return state\n }\n }\n}\n\nexport interface UseSelectStateProps<T> {\n /**\n * Number of items to display.\n *\n */\n visibleOptionCount: number\n\n /**\n * Options.\n */\n options: Option<T>[]\n\n /**\n * Initially selected option's value.\n */\n defaultValue?: T\n}\n\nexport type SelectState<T> = Pick<State<T>, 'visibleOptionCount' | 'visibleFromIndex' | 'visibleToIndex' | 'value'> & {\n /**\n * Visible options.\n */\n visibleOptions: (Option<T> & {index: number})[]\n\n /**\n * Select next option and scroll the list down, if needed.\n */\n selectNextOption: () => void\n\n /**\n * Select previous option and scroll the list up, if needed.\n */\n selectPreviousOption: () => void\n\n /**\n * Select option directly.\n */\n selectOption: (option: Option<T>) => void\n}\n\ntype CreateDefaultStateProps<T> = Pick<UseSelectStateProps<T>, 'visibleOptionCount' | 'defaultValue' | 'options'>\n\nconst createDefaultState = <T>({\n visibleOptionCount: customVisibleOptionCount,\n defaultValue,\n options,\n}: CreateDefaultStateProps<T>) => {\n const visibleOptionCount =\n typeof customVisibleOptionCount === 'number' ? Math.min(customVisibleOptionCount, options.length) : options.length\n const optionMap = new OptionMap(options)\n const defaultOption = typeof defaultValue === 'undefined' ? undefined : optionMap.get(defaultValue)\n let option = defaultOption && !defaultOption.disabled ? defaultOption : optionMap.first\n\n while (option && option.disabled) {\n option = option.next\n }\n\n return {\n optionMap,\n visibleOptionCount,\n visibleFromIndex: 0,\n visibleToIndex: visibleOptionCount - 1,\n value: option?.value,\n previousValue: option?.value,\n }\n}\n\nexport const useSelectState = <T>({visibleOptionCount, options, defaultValue}: UseSelectStateProps<T>) => {\n const [state, dispatch] = useReducer(reducer, {visibleOptionCount, defaultValue, options}, createDefaultState)\n const [lastOptions, setLastOptions] = useState(options)\n const [lastVisibleOptionCount, setLastVisibleOptionCount] = useState(visibleOptionCount)\n\n if (options !== lastOptions && !isDeepStrictEqual(options, lastOptions)) {\n dispatch({\n type: 'reset',\n state: createDefaultState({visibleOptionCount, defaultValue, options}),\n })\n\n setLastOptions(options)\n }\n\n if (visibleOptionCount !== lastVisibleOptionCount) {\n dispatch({\n type: 'reset',\n state: createDefaultState({visibleOptionCount, defaultValue, options}),\n })\n\n setLastVisibleOptionCount(visibleOptionCount)\n }\n\n const selectNextOption = useCallback(() => {\n dispatch({\n type: 'select-next-option',\n })\n }, [])\n\n const selectPreviousOption = useCallback(() => {\n dispatch({\n type: 'select-previous-option',\n })\n }, [])\n\n const selectOption = useCallback(({option}: {option: Option<T>}) => {\n dispatch({\n type: 'select-option',\n option,\n })\n }, [])\n\n const visibleOptions = useMemo(() => {\n return options.slice(state.visibleFromIndex)\n }, [options, state.visibleFromIndex])\n\n return {\n visibleFromIndex: state.visibleFromIndex,\n visibleToIndex: state.visibleToIndex,\n value: state.value,\n visibleOptions,\n selectNextOption,\n selectPreviousOption,\n selectOption,\n previousValue: state.previousValue,\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-select-state.js","sourceRoot":"","sources":["../../../../../src/private/node/ui/hooks/use-select-state.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAA;AAChE,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAA;AAU3C,MAAM,CAAC,OAAO,OAAO,SAAa,SAAQ,GAAwB;IAGhE,YAAY,OAAoB;QAC9B,MAAM,KAAK,GAA4B,EAAE,CAAA;QACzC,IAAI,SAAuC,CAAA;QAC3C,IAAI,QAAsC,CAAA;QAC1C,IAAI,KAAK,GAAG,CAAC,CAAA;QAEb,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;YAC5B,MAAM,IAAI,GAAG;gBACX,GAAG,MAAM;gBACT,QAAQ;gBACR,IAAI,EAAE,SAAS;gBACf,KAAK;aACN,CAAA;YAED,IAAI,QAAQ,EAAE;gBACZ,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAA;aACrB;YAED,IAAI,CAAC,SAAS,EAAE;gBACd,SAAS,GAAG,IAAI,CAAA;aACjB;YAED,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAA;YAChC,KAAK,EAAE,CAAA;YACP,QAAQ,GAAG,IAAI,CAAA;SAChB;QAED,KAAK,CAAC,KAAK,CAAC,CAAA;QACZ,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;CACF;AAsDD,MAAM,OAAO,GAAG,CAAI,KAAe,EAAE,MAAiB,EAAY,EAAE;IAClE,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,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K,CAAC,gBAAgB;QACxC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,cAAc;QACd,gBAAgB;QAChB,oBAAoB;QACpB,YAAY;QACZ,aAAa,EAAE,KAAK,CAAC,aAAa;KACnC,CAAA;AACH,CAAC,CAAA","sourcesContent":["import {Item} from '../components/SelectInput.js'\nimport {useReducer, useCallback, useMemo, useState} from 'react'\nimport {isDeepStrictEqual} from 'node:util'\n\ntype Option<T> = Item<T>\n\ntype OptionMapItem<T> = Option<T> & {\n previous: OptionMapItem<T> | undefined\n next: OptionMapItem<T> | undefined\n index: number\n}\n\nexport default class OptionMap<T> extends Map<T, OptionMapItem<T>> {\n readonly first: OptionMapItem<T> | undefined\n\n constructor(options: Option<T>[]) {\n const items: [T, OptionMapItem<T>][] = []\n let firstItem: OptionMapItem<T> | undefined\n let previous: OptionMapItem<T> | undefined\n let index = 0\n\n for (const option of options) {\n const item = {\n ...option,\n previous,\n next: undefined,\n index,\n }\n\n if (previous) {\n previous.next = item\n }\n\n if (!firstItem) {\n firstItem = item\n }\n\n items.push([option.value, item])\n index++\n previous = item\n }\n\n super(items)\n this.first = firstItem\n }\n}\n\ninterface State<T> {\n /**\n * Map where key is option's value and value is option's index.\n */\n optionMap: OptionMap<T>\n\n /**\n * Number of visible options.\n */\n visibleOptionCount: number\n\n /**\n * Index of the first visible option.\n */\n visibleFromIndex: number\n\n /**\n * Index of the last visible option.\n */\n visibleToIndex: number\n\n /**\n * Value of the previously selected option.\n */\n previousValue: T | undefined\n\n /**\n * Value of the selected option.\n */\n value: T | undefined\n}\n\ntype Action<T> = SelectNextOptionAction | SelectPreviousOptionAction | SelectOptionAction<T> | ResetAction<T>\n\ninterface SelectNextOptionAction {\n type: 'select-next-option'\n}\n\ninterface SelectPreviousOptionAction {\n type: 'select-previous-option'\n}\n\ninterface SelectOptionAction<T> {\n type: 'select-option'\n option: Option<T>\n}\n\ninterface ResetAction<T> {\n type: 'reset'\n state: State<T>\n}\n\nconst reducer = <T>(state: State<T>, action: Action<T>): State<T> => {\n switch (action.type) {\n case 'select-next-option': {\n if (typeof state.value === 'undefined') {\n return state\n }\n\n const item = state.optionMap.get(state.value)\n\n if (!item) {\n return state\n }\n\n let next = item.next\n\n while (next && next.disabled) {\n next = next.next\n }\n\n if (!next) {\n return state\n }\n\n const needsToScroll = next.index > state.visibleToIndex\n\n if (!needsToScroll) {\n return {\n ...state,\n value: next.value,\n }\n }\n\n const nextVisibleToIndex = next.index\n const nextVisibleFromIndex = nextVisibleToIndex - state.visibleOptionCount + 1\n\n return {\n ...state,\n value: next.value,\n visibleFromIndex: nextVisibleFromIndex,\n visibleToIndex: nextVisibleToIndex,\n previousValue: state.value,\n }\n }\n\n case 'select-previous-option': {\n if (typeof state.value === 'undefined') {\n return state\n }\n\n const item = state.optionMap.get(state.value)\n\n if (!item) {\n return state\n }\n\n let previous = item.previous\n\n while (previous && previous.disabled) {\n previous = previous.previous\n }\n\n if (!previous) {\n return state\n }\n\n const needsToScroll = previous.index < state.visibleFromIndex\n\n if (!needsToScroll) {\n return {\n ...state,\n value: previous.value,\n }\n }\n\n const nextVisibleFromIndex = previous.index\n const nextVisibleToIndex = nextVisibleFromIndex + state.visibleOptionCount - 1\n\n return {\n ...state,\n value: previous.value,\n visibleFromIndex: nextVisibleFromIndex,\n visibleToIndex: nextVisibleToIndex,\n previousValue: state.value,\n }\n }\n\n case 'select-option': {\n const item = state.optionMap.get(action.option.value)\n\n if (!item) {\n return state\n }\n\n return {\n ...state,\n value: item.value,\n previousValue: state.value,\n }\n }\n\n case 'reset': {\n return action.state\n }\n\n default: {\n return state\n }\n }\n}\n\nexport interface UseSelectStateProps<T> {\n /**\n * Number of items to display.\n *\n */\n visibleOptionCount: number\n\n /**\n * Options.\n */\n options: Option<T>[]\n\n /**\n * Initially selected option's value.\n */\n defaultValue?: T\n}\n\nexport type SelectState<T> = Pick<State<T>, 'visibleOptionCount' | 'visibleFromIndex' | 'visibleToIndex' | 'value'> & {\n /**\n * Visible options.\n */\n visibleOptions: (Option<T> & {index: number})[]\n\n /**\n * Select next option and scroll the list down, if needed.\n */\n selectNextOption: () => void\n\n /**\n * Select previous option and scroll the list up, if needed.\n */\n selectPreviousOption: () => void\n\n /**\n * Select option directly.\n */\n selectOption: (option: Option<T>) => void\n}\n\ntype CreateDefaultStateProps<T> = Pick<UseSelectStateProps<T>, 'visibleOptionCount' | 'defaultValue' | 'options'>\n\nconst createDefaultState = <T>({\n visibleOptionCount: customVisibleOptionCount,\n defaultValue,\n options,\n}: CreateDefaultStateProps<T>) => {\n const visibleOptionCount =\n typeof customVisibleOptionCount === 'number' ? Math.min(customVisibleOptionCount, options.length) : options.length\n const optionMap = new OptionMap(options)\n const defaultOption = typeof defaultValue === 'undefined' ? undefined : optionMap.get(defaultValue)\n let option = defaultOption && !defaultOption.disabled ? defaultOption : optionMap.first\n\n while (option && option.disabled) {\n option = option.next\n }\n\n return {\n optionMap,\n visibleOptionCount,\n visibleFromIndex: 0,\n visibleToIndex: visibleOptionCount - 1,\n value: option?.value,\n previousValue: option?.value,\n }\n}\n\nexport const useSelectState = <T>({visibleOptionCount, options, defaultValue}: UseSelectStateProps<T>) => {\n const [state, dispatch] = useReducer(reducer, {visibleOptionCount, defaultValue, options}, createDefaultState)\n const [lastOptions, setLastOptions] = useState(options)\n const [lastVisibleOptionCount, setLastVisibleOptionCount] = useState(visibleOptionCount)\n\n if (options !== lastOptions && !isDeepStrictEqual(options, lastOptions)) {\n dispatch({\n type: 'reset',\n state: createDefaultState({visibleOptionCount, defaultValue, options}),\n })\n\n setLastOptions(options)\n }\n\n if (visibleOptionCount !== lastVisibleOptionCount) {\n dispatch({\n type: 'reset',\n state: createDefaultState({visibleOptionCount, defaultValue, options}),\n })\n\n setLastVisibleOptionCount(visibleOptionCount)\n }\n\n const selectNextOption = useCallback(() => {\n dispatch({\n type: 'select-next-option',\n })\n }, [])\n\n const selectPreviousOption = useCallback(() => {\n dispatch({\n type: 'select-previous-option',\n })\n }, [])\n\n const selectOption = useCallback(({option}: {option: Option<T>}) => {\n dispatch({\n type: 'select-option',\n option,\n })\n }, [])\n\n const visibleOptions = useMemo(() => {\n return options.slice(state.visibleFromIndex)\n }, [options, state.visibleFromIndex])\n\n return {\n visibleFromIndex: state.visibleFromIndex,\n visibleToIndex: state.visibleToIndex,\n value: state.value,\n visibleOptions,\n selectNextOption,\n selectPreviousOption,\n selectOption,\n previousValue: state.previousValue,\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const CLI_KIT_VERSION = "3.
|
|
1
|
+
export declare const CLI_KIT_VERSION = "3.59.0";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CLI_KIT_VERSION = '3.
|
|
1
|
+
export const CLI_KIT_VERSION = '3.59.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.
|
|
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.59.0'\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { GraphQLVariables } from './graphql.js';
|
|
2
2
|
/**
|
|
3
|
-
* Executes a GraphQL query against the Business Platform API.
|
|
3
|
+
* Executes a GraphQL query against the Business Platform Destinations API.
|
|
4
4
|
*
|
|
5
5
|
* @param query - GraphQL query to execute.
|
|
6
6
|
* @param token - Business Platform token.
|
|
@@ -2,7 +2,7 @@ import { graphqlRequest } from './graphql.js';
|
|
|
2
2
|
import { handleDeprecations } from './partners.js';
|
|
3
3
|
import { businessPlatformFqdn } from '../context/fqdn.js';
|
|
4
4
|
/**
|
|
5
|
-
* Executes a GraphQL query against the Business Platform API.
|
|
5
|
+
* Executes a GraphQL query against the Business Platform Destinations API.
|
|
6
6
|
*
|
|
7
7
|
* @param query - GraphQL query to execute.
|
|
8
8
|
* @param token - Business Platform token.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"business-platform.js","sourceRoot":"","sources":["../../../../src/public/node/api/business-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAC,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAA;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAEvD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAa,EACb,KAAa,EACb,SAA4B;IAE5B,MAAM,GAAG,GAAG,kBAAkB,CAAA;IAC9B,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;IACzC,MAAM,GAAG,GAAG,WAAW,IAAI,mCAAmC,CAAA;IAC9D,OAAO,cAAc,CAAC;QACpB,KAAK;QACL,GAAG;QACH,GAAG;QACH,KAAK;QACL,SAAS;QACT,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {GraphQLVariables, graphqlRequest} from './graphql.js'\nimport {handleDeprecations} from './partners.js'\nimport {businessPlatformFqdn} from '../context/fqdn.js'\n\n/**\n * Executes a GraphQL query against the Business Platform API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformRequest<T>(\n query: string,\n token: string,\n variables?: GraphQLVariables,\n): Promise<T> {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/destinations/api/2020-07/graphql`\n return graphqlRequest({\n query,\n api,\n url,\n token,\n variables,\n responseOptions: {onResponse: handleDeprecations},\n })\n}\n"]}
|
|
1
|
+
{"version":3,"file":"business-platform.js","sourceRoot":"","sources":["../../../../src/public/node/api/business-platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,cAAc,EAAC,MAAM,cAAc,CAAA;AAC7D,OAAO,EAAC,kBAAkB,EAAC,MAAM,eAAe,CAAA;AAChD,OAAO,EAAC,oBAAoB,EAAC,MAAM,oBAAoB,CAAA;AAEvD;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAa,EACb,KAAa,EACb,SAA4B;IAE5B,MAAM,GAAG,GAAG,kBAAkB,CAAA;IAC9B,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAA;IACzC,MAAM,GAAG,GAAG,WAAW,IAAI,mCAAmC,CAAA;IAC9D,OAAO,cAAc,CAAC;QACpB,KAAK;QACL,GAAG;QACH,GAAG;QACH,KAAK;QACL,SAAS;QACT,eAAe,EAAE,EAAC,UAAU,EAAE,kBAAkB,EAAC;KAClD,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import {GraphQLVariables, graphqlRequest} from './graphql.js'\nimport {handleDeprecations} from './partners.js'\nimport {businessPlatformFqdn} from '../context/fqdn.js'\n\n/**\n * Executes a GraphQL query against the Business Platform Destinations API.\n *\n * @param query - GraphQL query to execute.\n * @param token - Business Platform token.\n * @param variables - GraphQL variables to pass to the query.\n * @returns The response of the query of generic type <T>.\n */\nexport async function businessPlatformRequest<T>(\n query: string,\n token: string,\n variables?: GraphQLVariables,\n): Promise<T> {\n const api = 'BusinessPlatform'\n const fqdn = await businessPlatformFqdn()\n const url = `https://${fqdn}/destinations/api/2020-07/graphql`\n return graphqlRequest({\n query,\n api,\n url,\n token,\n variables,\n responseOptions: {onResponse: handleDeprecations},\n })\n}\n"]}
|
package/dist/public/node/cli.js
CHANGED
|
@@ -62,23 +62,23 @@ export async function runCLI(options) {
|
|
|
62
62
|
*/
|
|
63
63
|
const { errorHandler } = await import('./error-handler.js');
|
|
64
64
|
const { isDevelopment } = await import('./context/local.js');
|
|
65
|
-
const
|
|
65
|
+
const oclif = await import('@oclif/core');
|
|
66
66
|
const { ShopifyConfig } = await import('./custom-oclif-loader.js');
|
|
67
67
|
if (isDevelopment()) {
|
|
68
|
-
settings.debug = true;
|
|
68
|
+
oclif.default.settings.debug = true;
|
|
69
69
|
}
|
|
70
70
|
try {
|
|
71
71
|
// Use a custom OCLIF config to customize the behavior of the CLI
|
|
72
72
|
const config = new ShopifyConfig({ root: fileURLToPath(options.moduleURL) });
|
|
73
73
|
await config.load();
|
|
74
|
-
await run(undefined, config);
|
|
75
|
-
await flush();
|
|
74
|
+
await oclif.default.run(undefined, config);
|
|
75
|
+
await oclif.default.flush();
|
|
76
76
|
printEventsJson();
|
|
77
77
|
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
78
78
|
}
|
|
79
79
|
catch (error) {
|
|
80
80
|
await errorHandler(error);
|
|
81
|
-
return Errors.handle(error);
|
|
81
|
+
return oclif.default.Errors.handle(error);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -165,5 +165,4 @@ export const globalFlags = {
|
|
|
165
165
|
env: 'SHOPIFY_FLAG_VERBOSE',
|
|
166
166
|
}),
|
|
167
167
|
};
|
|
168
|
-
export default runCLI;
|
|
169
168
|
//# sourceMappingURL=cli.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,2EAA2E;AAC3E,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAA;AAajC,KAAK,UAAU,oBAAoB;IACjC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,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAC3C,qDAAqD;KACtD;IAAC,OAAO,GAAG,EAAE;QACZ,OAAM;KACP;IACD,MAAM,gBAAgB,GAAG;QACvB,GAAG,eAAe,CAAC,gBAAgB;QACnC,GAAG,eAAe,CAAC,eAAe;QAClC,GAAG,eAAe,CAAC,YAAY;KAChC,CAAA;IACD,OAAO,gBAAgB,CAAC,cAAc,CAAC,CAAA;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,uBAAuB;QACpC,GAAG,EAAE,uBAAuB;KAC7B,CAAC;IACF,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,qCAAqC;QAClD,GAAG,EAAE,sBAAsB;KAC5B,CAAC;CACH,CAAA;AAED,eAAe,MAAM,CAAA","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {Flags} from '@oclif/core'\n// eslint-disable-next-line @shopify/cli/specific-imports-in-bootstrap-code\nimport {fileURLToPath} from 'url'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n}\n\nasync function warnIfOldNodeVersion() {\n const nodeVersion = process.versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderWarning} = await import('./ui.js')\n renderWarning({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n }\n}\n\nfunction setupEnvironmentVariables(options: Pick<RunCLIOptions, 'development'>) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (process.argv.includes('--verbose')) {\n process.env.DEBUG = process.env.DEBUG ?? '*'\n }\n if (options.development) {\n process.env.SHOPIFY_CLI_ENV = process.env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor() {\n if (\n process.argv.includes('--no-color') ||\n isTruthy(process.env.NO_COLOR) ||\n isTruthy(process.env.SHOPIFY_FLAG_NO_COLOR) ||\n process.env.TERM === 'dumb'\n ) {\n process.env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n forceNoColor()\n await warnIfOldNodeVersion()\n /**\n * These imports need to be dynamic because if they are static\n * they are loaded before we set the DEBUG=* environment variable\n * and therefore it has no effect.\n */\n const {errorHandler} = await import('./error-handler.js')\n const {isDevelopment} = await import('./context/local.js')\n const {run, settings, flush, Errors} = await import('@oclif/core')\n const {ShopifyConfig} = await import('./custom-oclif-loader.js')\n\n if (isDevelopment()) {\n settings.debug = true\n }\n\n try {\n // Use a custom OCLIF config to customize the behavior of the CLI\n const config = new ShopifyConfig({root: fileURLToPath(options.moduleURL)})\n await config.load()\n\n await run(undefined, config)\n await flush()\n printEventsJson()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n await errorHandler(error as Error)\n return Errors.handle(error as Error)\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = process.argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex =\n process.argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n process.argv.splice(initIndex, 0, 'init')\n }\n await runCLI(options)\n}\n\nexport async function useLocalCLIIfDetected(filepath: string): Promise<boolean> {\n const {environmentVariables} = await import('../../private/node/constants.js')\n const {joinPath: join} = await import('./path.js')\n const {exec} = await import('./system.js')\n\n // Temporary flag while we test out this feature and ensure it won't break anything!\n if (!isTruthy(process.env[environmentVariables.enableCliRedirect])) return false\n\n // Setting an env variable in the child process prevents accidental recursion.\n if (isTruthy(process.env[environmentVariables.skipCliRedirect])) return false\n\n // If already running via package manager, we can assume it's running correctly already.\n if (process.env.npm_config_user_agent) return false\n\n const cliPackage = await localCliPackage()\n if (!cliPackage) return false\n\n const correctExecutablePath = join(cliPackage.path, cliPackage.bin.shopify)\n if (correctExecutablePath === filepath) return false\n try {\n await exec(correctExecutablePath, process.argv.slice(2, process.argv.length), {\n stdio: 'inherit',\n env: {[environmentVariables.skipCliRedirect]: '1'},\n })\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n process.exit(processError.exitCode)\n }\n return true\n}\n\ninterface CliPackageInfo {\n path: string\n bin: {shopify: string}\n}\n\ninterface PackageJSON {\n dependencies?: {[packageName: string]: CliPackageInfo}\n devDependencies?: {[packageName: string]: CliPackageInfo}\n peerDependencies?: {[packageName: string]: CliPackageInfo}\n}\n\nexport async function localCliPackage(): Promise<CliPackageInfo | undefined> {\n const {captureOutput} = await import('./system.js')\n\n let npmListOutput = ''\n let localShopifyCLI: PackageJSON = {}\n try {\n npmListOutput = await captureOutput('npm', ['list', '@shopify/cli', '--json', '-l'])\n localShopifyCLI = JSON.parse(npmListOutput)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n return\n }\n const dependenciesList = {\n ...localShopifyCLI.peerDependencies,\n ...localShopifyCLI.devDependencies,\n ...localShopifyCLI.dependencies,\n }\n return dependenciesList['@shopify/cli']\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the logs.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n\nexport default runCLI\n"]}
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/public/node/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAC,MAAM,wBAAwB,CAAA;AAC/C,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAC,KAAK,EAAC,MAAM,aAAa,CAAA;AACjC,2EAA2E;AAC3E,OAAO,EAAC,aAAa,EAAC,MAAM,KAAK,CAAA;AAajC,KAAK,UAAU,oBAAoB;IACjC,MAAM,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAA;IACzC,MAAM,gBAAgB,GAAG,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;IAE1D,MAAM,2BAA2B,GAAG,EAAE,CAAA;IACtC,IAAI,gBAAgB,GAAG,2BAA2B,EAAE;QAClD,MAAM,EAAC,aAAa,EAAC,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAA;QAC/C,aAAa,CAAC;YACZ,QAAQ,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CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC;QACxB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,uBAAuB;QACpC,GAAG,EAAE,uBAAuB;KAC7B,CAAC;IACF,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,KAAK;QACb,WAAW,EAAE,qCAAqC;QAClD,GAAG,EAAE,sBAAsB;KAC5B,CAAC;CACH,CAAA","sourcesContent":["import {isTruthy} from './context/utilities.js'\nimport {printEventsJson} from '../../private/node/demo-recorder.js'\nimport {Flags} from '@oclif/core'\n// eslint-disable-next-line @shopify/cli/specific-imports-in-bootstrap-code\nimport {fileURLToPath} from 'url'\n\n/**\n * IMPORTANT NOTE: Imports in this module are dynamic to ensure that \"setupEnvironmentVariables\" can dynamically\n * set the DEBUG environment variable before the 'debug' package sets up its configuration when modules\n * are loaded statically.\n */\ninterface RunCLIOptions {\n /** The value of import.meta.url of the CLI executable module */\n moduleURL: string\n development: boolean\n}\n\nasync function warnIfOldNodeVersion() {\n const nodeVersion = process.versions.node\n const nodeMajorVersion = Number(nodeVersion.split('.')[0])\n\n const currentSupportedNodeVersion = 18\n if (nodeMajorVersion < currentSupportedNodeVersion) {\n const {renderWarning} = await import('./ui.js')\n renderWarning({\n headline: 'Upgrade to a supported Node version now.',\n body: [\n `Node ${nodeMajorVersion} has reached end-of-life and poses security risks. When you upgrade to a`,\n {\n link: {\n url: 'https://nodejs.dev/en/about/previous-releases',\n label: 'supported version',\n },\n },\n {char: ','},\n \"you'll be able to use Shopify CLI without interruption.\",\n ],\n })\n }\n}\n\nfunction setupEnvironmentVariables(options: Pick<RunCLIOptions, 'development'>) {\n /**\n * By setting DEBUG=* when --verbose is passed we are increasing the\n * verbosity of oclif. Oclif uses debug (https://www.npmjs.com/package/debug)\n * for logging, and it's configured through the DEBUG= environment variable.\n */\n if (process.argv.includes('--verbose')) {\n process.env.DEBUG = process.env.DEBUG ?? '*'\n }\n if (options.development) {\n process.env.SHOPIFY_CLI_ENV = process.env.SHOPIFY_CLI_ENV ?? 'development'\n }\n}\n\nfunction forceNoColor() {\n if (\n process.argv.includes('--no-color') ||\n isTruthy(process.env.NO_COLOR) ||\n isTruthy(process.env.SHOPIFY_FLAG_NO_COLOR) ||\n process.env.TERM === 'dumb'\n ) {\n process.env.FORCE_COLOR = '0'\n }\n}\n\n/**\n * A function that abstracts away setting up the environment and running\n * a CLI\n * @param options - Options.\n */\nexport async function runCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n forceNoColor()\n await warnIfOldNodeVersion()\n /**\n * These imports need to be dynamic because if they are static\n * they are loaded before we set the DEBUG=* environment variable\n * and therefore it has no effect.\n */\n const {errorHandler} = await import('./error-handler.js')\n const {isDevelopment} = await import('./context/local.js')\n const oclif = await import('@oclif/core')\n const {ShopifyConfig} = await import('./custom-oclif-loader.js')\n\n if (isDevelopment()) {\n oclif.default.settings.debug = true\n }\n\n try {\n // Use a custom OCLIF config to customize the behavior of the CLI\n const config = new ShopifyConfig({root: fileURLToPath(options.moduleURL)})\n await config.load()\n\n await oclif.default.run(undefined, config)\n await oclif.default.flush()\n printEventsJson()\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (error) {\n await errorHandler(error as Error)\n return oclif.default.Errors.handle(error as Error)\n }\n}\n\n/**\n * A function for create-x CLIs that automatically runs the \"init\" command.\n */\nexport async function runCreateCLI(options: RunCLIOptions): Promise<void> {\n setupEnvironmentVariables(options)\n\n const {findUpAndReadPackageJson} = await import('./node-package-manager.js')\n const {moduleDirectory} = await import('./path.js')\n\n const packageJson = await findUpAndReadPackageJson(moduleDirectory(options.moduleURL))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const packageName = (packageJson.content as any).name as string\n const name = packageName.replace('@shopify/create-', '')\n const initIndex = process.argv.findIndex((arg) => arg.includes('init'))\n if (initIndex === -1) {\n const initIndex =\n process.argv.findIndex((arg) => arg.match(new RegExp(`bin(\\\\/|\\\\\\\\)+(create-${name}|dev|run)`))) + 1\n process.argv.splice(initIndex, 0, 'init')\n }\n await runCLI(options)\n}\n\nexport async function useLocalCLIIfDetected(filepath: string): Promise<boolean> {\n const {environmentVariables} = await import('../../private/node/constants.js')\n const {joinPath: join} = await import('./path.js')\n const {exec} = await import('./system.js')\n\n // Temporary flag while we test out this feature and ensure it won't break anything!\n if (!isTruthy(process.env[environmentVariables.enableCliRedirect])) return false\n\n // Setting an env variable in the child process prevents accidental recursion.\n if (isTruthy(process.env[environmentVariables.skipCliRedirect])) return false\n\n // If already running via package manager, we can assume it's running correctly already.\n if (process.env.npm_config_user_agent) return false\n\n const cliPackage = await localCliPackage()\n if (!cliPackage) return false\n\n const correctExecutablePath = join(cliPackage.path, cliPackage.bin.shopify)\n if (correctExecutablePath === filepath) return false\n try {\n await exec(correctExecutablePath, process.argv.slice(2, process.argv.length), {\n stdio: 'inherit',\n env: {[environmentVariables.skipCliRedirect]: '1'},\n })\n // eslint-disable-next-line no-catch-all/no-catch-all, @typescript-eslint/no-explicit-any\n } catch (processError: any) {\n process.exit(processError.exitCode)\n }\n return true\n}\n\ninterface CliPackageInfo {\n path: string\n bin: {shopify: string}\n}\n\ninterface PackageJSON {\n dependencies?: {[packageName: string]: CliPackageInfo}\n devDependencies?: {[packageName: string]: CliPackageInfo}\n peerDependencies?: {[packageName: string]: CliPackageInfo}\n}\n\nexport async function localCliPackage(): Promise<CliPackageInfo | undefined> {\n const {captureOutput} = await import('./system.js')\n\n let npmListOutput = ''\n let localShopifyCLI: PackageJSON = {}\n try {\n npmListOutput = await captureOutput('npm', ['list', '@shopify/cli', '--json', '-l'])\n localShopifyCLI = JSON.parse(npmListOutput)\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch (err) {\n return\n }\n const dependenciesList = {\n ...localShopifyCLI.peerDependencies,\n ...localShopifyCLI.devDependencies,\n ...localShopifyCLI.dependencies,\n }\n return dependenciesList['@shopify/cli']\n}\n\n/**\n * An object that contains the flags that\n * are shared across all the commands.\n */\nexport const globalFlags = {\n 'no-color': Flags.boolean({\n hidden: false,\n description: 'Disable color output.',\n env: 'SHOPIFY_FLAG_NO_COLOR',\n }),\n verbose: Flags.boolean({\n hidden: false,\n description: 'Increase the verbosity of the logs.',\n env: 'SHOPIFY_FLAG_VERBOSE',\n }),\n}\n"]}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
import { cwd, joinPath } from './path.js';
|
|
2
|
+
import { fileExistsSync } from './fs.js';
|
|
1
3
|
import { Config } from '@oclif/core';
|
|
2
4
|
export class ShopifyConfig extends Config {
|
|
3
5
|
constructor(options) {
|
|
6
|
+
const path = sniffForPath() ?? cwd();
|
|
7
|
+
if (fileExistsSync(joinPath(`${path}`, 'package.json'))) {
|
|
8
|
+
options.pluginAdditions = {
|
|
9
|
+
core: ['@shopify/cli-hydrogen'],
|
|
10
|
+
path,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
4
13
|
super(options);
|
|
5
14
|
// eslint-disable-next-line dot-notation
|
|
6
15
|
this['determinePriority'] = this.customPriority;
|
|
@@ -51,4 +60,18 @@ export class ShopifyConfig extends Config {
|
|
|
51
60
|
return commandPlugins[0];
|
|
52
61
|
}
|
|
53
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* Tries to get the value of the `--path` argument, if provided.
|
|
65
|
+
*
|
|
66
|
+
* @returns The value of the `--path` argument, if provided.
|
|
67
|
+
*/
|
|
68
|
+
function sniffForPath() {
|
|
69
|
+
const pathFlagIndex = process.argv.indexOf('--path');
|
|
70
|
+
if (pathFlagIndex === -1)
|
|
71
|
+
return;
|
|
72
|
+
const pathFlag = process.argv[pathFlagIndex + 1];
|
|
73
|
+
if (!pathFlag || pathFlag.startsWith('-'))
|
|
74
|
+
return;
|
|
75
|
+
return pathFlag;
|
|
76
|
+
}
|
|
54
77
|
//# sourceMappingURL=custom-oclif-loader.js.map
|
|
@@ -1 +1 @@
|
|
|
1
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xD,OAAO,MAAM,GAAG,MAAM,CAAA;aACvB;YAED,kDAAkD;YAClD,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,OAAO,CAAC,CAAA;aACT;YAED,kDAAkD;YAClD,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAA;aACT;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,qDAAqD;YACrD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF","sourcesContent":["import {Command, Config} from '@oclif/core'\nimport {Options} from '@oclif/core/lib/interfaces/plugin.js'\n\nexport class ShopifyConfig extends Config {\n constructor(options: Options) {\n super(options)\n // eslint-disable-next-line dot-notation\n this['determinePriority'] = this.customPriority\n }\n\n customPriority(commands: Command.Loadable[]): Command.Loadable | undefined {\n const oclifPlugins = this.pjson.oclif?.plugins ?? []\n const commandPlugins = commands.sort((aCommand, bCommand) => {\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasA = aCommand.pluginAlias ?? 'A-Cannot-Find-This'\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasB = bCommand.pluginAlias ?? 'B-Cannot-Find-This'\n const aIndex = oclifPlugins.indexOf(pluginAliasA)\n const bIndex = oclifPlugins.indexOf(pluginAliasB)\n\n // Hydrogen has higher priority than core plugins to override the custom init method.\n if (aCommand.pluginType === 'core' && bCommand.pluginAlias === '@shopify/cli-hydrogen') {\n // If b is hydrogen and a is core sort b first\n return 1\n }\n\n if (aCommand.pluginAlias === '@shopify/cli-hydrogen' && bCommand.pluginType === 'core') {\n // If a is hydrogen and b is core sort a first\n return -1\n }\n\n // All other cases are the default implementation from the private `determinePriority` method\n // When both plugin types are 'core' plugins sort based on index\n if (aCommand.pluginType === 'core' && bCommand.pluginType === 'core') {\n // If b appears first in the pjson.plugins sort it first\n return aIndex - bIndex\n }\n\n // if b is a core plugin and a is not sort b first\n if (bCommand.pluginType === 'core' && aCommand.pluginType !== 'core') {\n return 1\n }\n\n // if a is a core plugin and b is not sort a first\n if (aCommand.pluginType === 'core' && bCommand.pluginType !== 'core') {\n return -1\n }\n\n // if a is a jit plugin and b is not sort b first\n if (aCommand.pluginType === 'jit' && bCommand.pluginType !== 'jit') {\n return 1\n }\n\n // if b is a jit plugin and a is not sort a first\n if (bCommand.pluginType === 'jit' && aCommand.pluginType !== 'jit') {\n return -1\n }\n\n // neither plugin is core, so do not change the order\n return 0\n })\n return commandPlugins[0]\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"custom-oclif-loader.js","sourceRoot":"","sources":["../../../src/public/node/custom-oclif-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAE,QAAQ,EAAC,MAAM,WAAW,CAAA;AACvC,OAAO,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AACtC,OAAO,EAAU,MAAM,EAAC,MAAM,aAAa,CAAA;AAG3C,MAAM,OAAO,aAAc,SAAQ,MAAM;IACvC,YAAY,OAAgB;QAC1B,MAAM,IAAI,GAAG,YAAY,EAAE,IAAI,GAAG,EAAE,CAAA;QACpC,IAAI,cAAc,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,EAAE,cAAc,CAAC,CAAC,EAAE;YACvD,OAAO,CAAC,eAAe,GAAG;gBACxB,IAAI,EAAE,CAAC,uBAAuB,CAAC;gBAC/B,IAAI;aACL,CAAA;S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I,QAAQ,CAAC,UAAU,KAAK,MAAM,IAAI,QAAQ,CAAC,UAAU,KAAK,MAAM,EAAE;gBACpE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAA;aACT;YAED,iDAAiD;YACjD,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,IAAI,QAAQ,CAAC,UAAU,KAAK,KAAK,EAAE;gBAClE,OAAO,CAAC,CAAC,CAAA;aACV;YAED,qDAAqD;YACrD,OAAO,CAAC,CAAA;QACV,CAAC,CAAC,CAAA;QACF,OAAO,cAAc,CAAC,CAAC,CAAC,CAAA;IAC1B,CAAC;CACF;AAED;;;;GAIG;AACH,SAAS,YAAY;IACnB,MAAM,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACpD,IAAI,aAAa,KAAK,CAAC,CAAC;QAAE,OAAM;IAChC,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,CAAA;IAChD,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,OAAM;IACjD,OAAO,QAAQ,CAAA;AACjB,CAAC","sourcesContent":["import {cwd, joinPath} from './path.js'\nimport {fileExistsSync} from './fs.js'\nimport {Command, Config} from '@oclif/core'\nimport {Options} from '@oclif/core/lib/interfaces/plugin.js'\n\nexport class ShopifyConfig extends Config {\n constructor(options: Options) {\n const path = sniffForPath() ?? cwd()\n if (fileExistsSync(joinPath(`${path}`, 'package.json'))) {\n options.pluginAdditions = {\n core: ['@shopify/cli-hydrogen'],\n path,\n }\n }\n super(options)\n // eslint-disable-next-line dot-notation\n this['determinePriority'] = this.customPriority\n }\n\n customPriority(commands: Command.Loadable[]): Command.Loadable | undefined {\n const oclifPlugins = this.pjson.oclif?.plugins ?? []\n const commandPlugins = commands.sort((aCommand, bCommand) => {\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasA = aCommand.pluginAlias ?? 'A-Cannot-Find-This'\n // eslint-disable-next-line no-restricted-syntax\n const pluginAliasB = bCommand.pluginAlias ?? 'B-Cannot-Find-This'\n const aIndex = oclifPlugins.indexOf(pluginAliasA)\n const bIndex = oclifPlugins.indexOf(pluginAliasB)\n\n // Hydrogen has higher priority than core plugins to override the custom init method.\n if (aCommand.pluginType === 'core' && bCommand.pluginAlias === '@shopify/cli-hydrogen') {\n // If b is hydrogen and a is core sort b first\n return 1\n }\n\n if (aCommand.pluginAlias === '@shopify/cli-hydrogen' && bCommand.pluginType === 'core') {\n // If a is hydrogen and b is core sort a first\n return -1\n }\n\n // All other cases are the default implementation from the private `determinePriority` method\n // When both plugin types are 'core' plugins sort based on index\n if (aCommand.pluginType === 'core' && bCommand.pluginType === 'core') {\n // If b appears first in the pjson.plugins sort it first\n return aIndex - bIndex\n }\n\n // if b is a core plugin and a is not sort b first\n if (bCommand.pluginType === 'core' && aCommand.pluginType !== 'core') {\n return 1\n }\n\n // if a is a core plugin and b is not sort a first\n if (aCommand.pluginType === 'core' && bCommand.pluginType !== 'core') {\n return -1\n }\n\n // if a is a jit plugin and b is not sort b first\n if (aCommand.pluginType === 'jit' && bCommand.pluginType !== 'jit') {\n return 1\n }\n\n // if b is a jit plugin and a is not sort a first\n if (bCommand.pluginType === 'jit' && aCommand.pluginType !== 'jit') {\n return -1\n }\n\n // neither plugin is core, so do not change the order\n return 0\n })\n return commandPlugins[0]\n }\n}\n\n/**\n * Tries to get the value of the `--path` argument, if provided.\n *\n * @returns The value of the `--path` argument, if provided.\n */\nfunction sniffForPath(): string | undefined {\n const pathFlagIndex = process.argv.indexOf('--path')\n if (pathFlagIndex === -1) return\n const pathFlag = process.argv[pathFlagIndex + 1]\n if (!pathFlag || pathFlag.startsWith('-')) return\n return pathFlag\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { PackageManager } from './node-package-manager.js';
|
|
2
3
|
/**
|
|
3
4
|
* Returns true if the current process is running in a global context.
|
|
4
5
|
*
|
|
@@ -6,3 +7,33 @@
|
|
|
6
7
|
* @returns `true` if the current process is running in a global context.
|
|
7
8
|
*/
|
|
8
9
|
export declare function currentProcessIsGlobal(env?: NodeJS.ProcessEnv): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if the global CLI is installed.
|
|
12
|
+
*
|
|
13
|
+
* @returns `true` if the global CLI is installed.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isGlobalCLIInstalled(): Promise<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Installs the global Shopify CLI, using the provided package manager.
|
|
18
|
+
*
|
|
19
|
+
* @param packageManager - The package manager to use.
|
|
20
|
+
*/
|
|
21
|
+
export declare function installGlobalShopifyCLI(packageManager: PackageManager): Promise<void>;
|
|
22
|
+
export interface InstallGlobalCLIPromptResult {
|
|
23
|
+
install: boolean;
|
|
24
|
+
alreadyInstalled: boolean;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Prompts the user to install the global CLI.
|
|
28
|
+
*
|
|
29
|
+
* @returns `true` if the user has installed the global CLI.
|
|
30
|
+
*/
|
|
31
|
+
export declare function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPromptResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Infers the package manager used by the global CLI.
|
|
34
|
+
*
|
|
35
|
+
* @param argv - The arguments passed to the process.
|
|
36
|
+
* @param env - The environment to check. Defaults to `process.env`.
|
|
37
|
+
* @returns The package manager used by the global CLI.
|
|
38
|
+
*/
|
|
39
|
+
export declare function inferPackageManagerForGlobalCLI(argv?: string[], env?: NodeJS.ProcessEnv): PackageManager;
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { outputInfo } from './output.js';
|
|
2
|
+
import { captureOutput, exec, terminalSupportsRawMode } from './system.js';
|
|
3
|
+
import { renderSelectPrompt } from './ui.js';
|
|
1
4
|
/**
|
|
2
5
|
* Returns true if the current process is running in a global context.
|
|
3
6
|
*
|
|
@@ -9,4 +12,70 @@ export function currentProcessIsGlobal(env = process.env) {
|
|
|
9
12
|
// If undefined, we can assume it's global (But there is no foolproof way to know)
|
|
10
13
|
return env.npm_config_user_agent === undefined;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns true if the global CLI is installed.
|
|
17
|
+
*
|
|
18
|
+
* @returns `true` if the global CLI is installed.
|
|
19
|
+
*/
|
|
20
|
+
export async function isGlobalCLIInstalled() {
|
|
21
|
+
try {
|
|
22
|
+
const output = await captureOutput('shopify', ['app']);
|
|
23
|
+
// Installed if `app dev` is available globally
|
|
24
|
+
return output.includes('app dev');
|
|
25
|
+
// eslint-disable-next-line no-catch-all/no-catch-all
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Installs the global Shopify CLI, using the provided package manager.
|
|
33
|
+
*
|
|
34
|
+
* @param packageManager - The package manager to use.
|
|
35
|
+
*/
|
|
36
|
+
export async function installGlobalShopifyCLI(packageManager) {
|
|
37
|
+
const args = packageManager === 'yarn' ? ['global', 'add', '@shopify/cli@latest'] : ['install', '-g', '@shopify/cli@latest'];
|
|
38
|
+
outputInfo(`Running ${packageManager} ${args.join(' ')}...`);
|
|
39
|
+
await exec(packageManager, args, { stdio: 'inherit' });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Prompts the user to install the global CLI.
|
|
43
|
+
*
|
|
44
|
+
* @returns `true` if the user has installed the global CLI.
|
|
45
|
+
*/
|
|
46
|
+
export async function installGlobalCLIPrompt() {
|
|
47
|
+
if (!terminalSupportsRawMode())
|
|
48
|
+
return { install: false, alreadyInstalled: false };
|
|
49
|
+
if (await isGlobalCLIInstalled()) {
|
|
50
|
+
return { install: false, alreadyInstalled: true };
|
|
51
|
+
}
|
|
52
|
+
const result = await renderSelectPrompt({
|
|
53
|
+
message: 'We recommend installing Shopify CLI globally in your system. Would you like to install it now?',
|
|
54
|
+
choices: [
|
|
55
|
+
{ value: 'yes', label: 'Yes' },
|
|
56
|
+
{ value: 'no', label: 'No, just for this project' },
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
return { install: result === 'yes', alreadyInstalled: false };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Infers the package manager used by the global CLI.
|
|
63
|
+
*
|
|
64
|
+
* @param argv - The arguments passed to the process.
|
|
65
|
+
* @param env - The environment to check. Defaults to `process.env`.
|
|
66
|
+
* @returns The package manager used by the global CLI.
|
|
67
|
+
*/
|
|
68
|
+
export function inferPackageManagerForGlobalCLI(argv = process.argv, env = process.env) {
|
|
69
|
+
if (!currentProcessIsGlobal(env))
|
|
70
|
+
return 'unknown';
|
|
71
|
+
// argv[1] contains the path of the executed binary
|
|
72
|
+
const processArgv = argv[1] ?? '';
|
|
73
|
+
if (processArgv.includes('yarn'))
|
|
74
|
+
return 'yarn';
|
|
75
|
+
if (processArgv.includes('pnpm'))
|
|
76
|
+
return 'pnpm';
|
|
77
|
+
if (processArgv.includes('bun'))
|
|
78
|
+
return 'bun';
|
|
79
|
+
return 'npm';
|
|
80
|
+
}
|
|
12
81
|
//# sourceMappingURL=is-global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-global.js","sourceRoot":"","sources":["../../../src/public/node/is-global.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"is-global.js","sourceRoot":"","sources":["../../../src/public/node/is-global.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAA;AACtC,OAAO,EAAC,aAAa,EAAE,IAAI,EAAE,uBAAuB,EAAC,MAAM,aAAa,CAAA;AACxE,OAAO,EAAC,kBAAkB,EAAC,MAAM,SAAS,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O,EAAE,gGAAgG;QACzG,OAAO,EAAE;YACP,EAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAC;YAC5B,EAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,2BAA2B,EAAC;SAClD;KACF,CAAC,CAAA;IAEF,OAAO,EAAC,OAAO,EAAE,MAAM,KAAK,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAC,CAAA;AAC7D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,+BAA+B,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG;IACpF,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IAElD,mDAAmD;IACnD,MAAM,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IACjC,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAC/C,IAAI,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IAC/C,IAAI,WAAW,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IAC7C,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import {PackageManager} from './node-package-manager.js'\nimport {outputInfo} from './output.js'\nimport {captureOutput, exec, terminalSupportsRawMode} from './system.js'\nimport {renderSelectPrompt} from './ui.js'\n\n/**\n * Returns true if the current process is running in a global context.\n *\n * @param env - The environment to check. Defaults to `process.env`.\n * @returns `true` if the current process is running in a global context.\n */\nexport function currentProcessIsGlobal(env = process.env): boolean {\n // npm, yarn, pnpm and bun define this if run locally.\n // If undefined, we can assume it's global (But there is no foolproof way to know)\n return env.npm_config_user_agent === undefined\n}\n\n/**\n * Returns true if the global CLI is installed.\n *\n * @returns `true` if the global CLI is installed.\n */\nexport async function isGlobalCLIInstalled(): Promise<boolean> {\n try {\n const output = await captureOutput('shopify', ['app'])\n // Installed if `app dev` is available globally\n return output.includes('app dev')\n // eslint-disable-next-line no-catch-all/no-catch-all\n } catch {\n return false\n }\n}\n\n/**\n * Installs the global Shopify CLI, using the provided package manager.\n *\n * @param packageManager - The package manager to use.\n */\nexport async function installGlobalShopifyCLI(packageManager: PackageManager): Promise<void> {\n const args =\n packageManager === 'yarn' ? ['global', 'add', '@shopify/cli@latest'] : ['install', '-g', '@shopify/cli@latest']\n outputInfo(`Running ${packageManager} ${args.join(' ')}...`)\n await exec(packageManager, args, {stdio: 'inherit'})\n}\n\nexport interface InstallGlobalCLIPromptResult {\n install: boolean\n alreadyInstalled: boolean\n}\n/**\n * Prompts the user to install the global CLI.\n *\n * @returns `true` if the user has installed the global CLI.\n */\nexport async function installGlobalCLIPrompt(): Promise<InstallGlobalCLIPromptResult> {\n if (!terminalSupportsRawMode()) return {install: false, alreadyInstalled: false}\n if (await isGlobalCLIInstalled()) {\n return {install: false, alreadyInstalled: true}\n }\n const result = await renderSelectPrompt({\n message: 'We recommend installing Shopify CLI globally in your system. Would you like to install it now?',\n choices: [\n {value: 'yes', label: 'Yes'},\n {value: 'no', label: 'No, just for this project'},\n ],\n })\n\n return {install: result === 'yes', alreadyInstalled: false}\n}\n\n/**\n * Infers the package manager used by the global CLI.\n *\n * @param argv - The arguments passed to the process.\n * @param env - The environment to check. Defaults to `process.env`.\n * @returns The package manager used by the global CLI.\n */\nexport function inferPackageManagerForGlobalCLI(argv = process.argv, env = process.env): PackageManager {\n if (!currentProcessIsGlobal(env)) return 'unknown'\n\n // argv[1] contains the path of the executed binary\n const processArgv = argv[1] ?? ''\n if (processArgv.includes('yarn')) return 'yarn'\n if (processArgv.includes('pnpm')) return 'pnpm'\n if (processArgv.includes('bun')) return 'bun'\n return 'npm'\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import { JsonMap } from '../../private/common/json.js';
|
|
|
2
2
|
import { DeepRequired } from '../common/ts/deep-required.js';
|
|
3
3
|
export { DeepRequired };
|
|
4
4
|
type Optional<T> = T | null;
|
|
5
|
-
export declare const MONORAIL_COMMAND_TOPIC: "app_cli3_command/1.
|
|
5
|
+
export declare const MONORAIL_COMMAND_TOPIC: "app_cli3_command/1.12";
|
|
6
6
|
export interface Schemas {
|
|
7
7
|
[MONORAIL_COMMAND_TOPIC]: {
|
|
8
8
|
sensitive: {
|
|
@@ -119,6 +119,7 @@ export interface Schemas {
|
|
|
119
119
|
env_shell?: Optional<string>;
|
|
120
120
|
env_web_ide?: Optional<string>;
|
|
121
121
|
env_cloud?: Optional<string>;
|
|
122
|
+
env_is_global?: Optional<boolean>;
|
|
122
123
|
};
|
|
123
124
|
};
|
|
124
125
|
[schemaId: string]: {
|
|
@@ -2,7 +2,7 @@ import { fetch } from './http.js';
|
|
|
2
2
|
import { outputDebug, outputContent, outputToken } from '../../public/node/output.js';
|
|
3
3
|
const url = 'https://monorail-edge.shopifysvc.com/v1/produce';
|
|
4
4
|
// This is the topic name of the main event we log to Monorail, the command tracker
|
|
5
|
-
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.
|
|
5
|
+
export const MONORAIL_COMMAND_TOPIC = 'app_cli3_command/1.12';
|
|
6
6
|
const publishedCommandNames = new Set();
|
|
7
7
|
/**
|
|
8
8
|
* Publishes an event to Monorail.
|
|
@@ -28,7 +28,7 @@ export async function publishMonorailEvent(schemaId, publicData, sensitiveData)
|
|
|
28
28
|
const headers = buildHeaders(currentTime);
|
|
29
29
|
const response = await fetch(url, { method: 'POST', body, headers });
|
|
30
30
|
if (response.status === 200) {
|
|
31
|
-
outputDebug(outputContent `Analytics event sent: ${outputToken.json(payload)}`);
|
|
31
|
+
outputDebug(outputContent `Analytics event sent: ${outputToken.json(sanitizePayload(payload))}`);
|
|
32
32
|
return { type: 'ok' };
|
|
33
33
|
}
|
|
34
34
|
else {
|
|
@@ -46,6 +46,19 @@ export async function publishMonorailEvent(schemaId, publicData, sensitiveData)
|
|
|
46
46
|
return { type: 'error', message };
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Sanitizies the api_key from the payload and returns a new hash.
|
|
51
|
+
*
|
|
52
|
+
* @param payload - The public and sensitive data.
|
|
53
|
+
* @returns A copy of the payload with the api_key sanitized.
|
|
54
|
+
*/
|
|
55
|
+
function sanitizePayload(payload) {
|
|
56
|
+
const result = { ...payload };
|
|
57
|
+
if ('api_key' in result) {
|
|
58
|
+
result.api_key = '****';
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
49
62
|
const buildHeaders = (currentTime) => {
|
|
50
63
|
return {
|
|
51
64
|
'Content-Type': 'application/json; charset=utf-8',
|