-
Notifications
You must be signed in to change notification settings - Fork 162
Add --localhost-port to port for --use-localhost flag #5630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
458a98b
3a7d7b8
9563130
32291cf
17590fc
7cdc129
31eb92a
22d320f
d719c89
de5a22d
3c7a750
c65b5bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@shopify/app': minor | ||
--- | ||
|
||
Improved how port selection works when using localhost development | ||
|
||
Added a `--localhost-port` flag. Use this to specify that you want to develop using localhost on a specific port. For example: `shopify app dev --localhost-port=4000` | ||
|
||
`shopify app dev --use-localhost` will always try to use port 3458. If port 3458 is not available the CLI will warn the user and select a different port. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import {appFlags} from '../../flags.js' | ||
import {dev, DevOptions, TunnelMode} from '../../services/dev.js' | ||
import {dev, DevOptions} from '../../services/dev.js' | ||
import {showApiKeyDeprecationWarning} from '../../prompts/deprecation-warnings.js' | ||
import {checkFolderIsValidApp} from '../../models/app/loader.js' | ||
import AppCommand, {AppCommandOutput} from '../../utilities/app-command.js' | ||
import {linkedAppContext} from '../../services/app-context.js' | ||
import {storeContext} from '../../services/store-context.js' | ||
import {generateCertificate} from '../../utilities/mkcert.js' | ||
import {generateCertificatePrompt} from '../../prompts/dev.js' | ||
import {getTunnelMode} from '../../services/dev/tunnel-mode.js' | ||
import {Flags} from '@oclif/core' | ||
import {normalizeStoreFqdn} from '@shopify/cli-kit/node/context/fqdn' | ||
import {globalFlags} from '@shopify/cli-kit/node/cli' | ||
import {addPublicMetadata} from '@shopify/cli-kit/node/metadata' | ||
import {renderInfo} from '@shopify/cli-kit/node/ui' | ||
|
||
export default class Dev extends AppCommand { | ||
static summary = 'Run the app.' | ||
|
@@ -91,11 +89,16 @@ If you're using the Ruby app template, then you need to complete the following s | |
'use-localhost': Flags.boolean({ | ||
hidden: true, | ||
description: | ||
"Service entry point will listen to localhost. A tunnel won't be used. Will work for testing many app features, but not Webhooks, Flow Action, App Proxy or POS", | ||
"Service entry point will listen to localhost. A tunnel won't be used. Will work for testing many app features, but not those that directly invoke your app (E.g: Webhooks)", | ||
env: 'SHOPIFY_FLAG_USE_LOCALHOST', | ||
default: false, | ||
exclusive: ['tunnel-url'], | ||
}), | ||
'localhost-port': Flags.integer({ | ||
hidden: true, | ||
description: 'Port to use for localhost.', | ||
env: 'SHOPIFY_FLAG_LOCALHOST_PORT', | ||
}), | ||
theme: Flags.string({ | ||
hidden: false, | ||
char: 't', | ||
|
@@ -139,46 +142,17 @@ If you're using the Ruby app template, then you need to complete the following s | |
await showApiKeyDeprecationWarning() | ||
} | ||
|
||
let tunnel: TunnelMode = {mode: 'auto'} | ||
let tunnelType = 'cloudflare' | ||
|
||
if (flags['use-localhost']) { | ||
tunnelType = 'use-localhost' | ||
tunnel = { | ||
mode: 'no-tunnel-use-localhost', | ||
provideCertificate: async (appDirectory) => { | ||
renderInfo({ | ||
headline: 'Localhost-based development is in developer preview.', | ||
body: [ | ||
'`--use-localhost` is not compatible with Shopify features which directly invoke your app', | ||
'(such as Webhooks, App proxy, and Flow actions), or those which require testing your app from another', | ||
'device (such as POS). Please report any issues and provide feedback on the dev community:', | ||
], | ||
link: { | ||
label: 'Create a feedback post', | ||
url: 'https://community.shopify.dev/new-topic?category=shopify-cli-libraries&tags=app-dev-on-localhost', | ||
}, | ||
}) | ||
|
||
return generateCertificate({ | ||
appDirectory, | ||
onRequiresConfirmation: generateCertificatePrompt, | ||
}) | ||
}, | ||
} | ||
} else if (flags['tunnel-url']) { | ||
tunnelType = 'custom' | ||
tunnel = { | ||
mode: 'provided', | ||
url: flags['tunnel-url'], | ||
} | ||
} | ||
const tunnelMode = await getTunnelMode({ | ||
useLocalhost: flags['use-localhost'], | ||
tunnelUrl: flags['tunnel-url'], | ||
localhostPort: flags['localhost-port'], | ||
}) | ||
|
||
await addPublicMetadata(() => { | ||
return { | ||
cmd_app_dependency_installation_skipped: flags['skip-dependencies-installation'], | ||
cmd_app_reset_used: flags.reset, | ||
cmd_dev_tunnel_type: tunnelType, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed this value has not changed: On this branch branchpnpm shopify app dev --path='../app-test-use-localhost' pnpm shopify app dev --path='../app-test-use-localhost' --use-localhost pnpm shopify app dev --path='../app-test-use-localhost' --tunnel-url="http://my-tunnel.com:3000" On mainpnpm shopify app dev --path='../app-test-use-localhost' pnpm shopify app dev --path='../app-test-use-localhost' --use-localhost pnpm shopify app dev --path='../app-test-use-localhost' --tunnel-url="http://my-tunnel.com:3000" |
||
cmd_dev_tunnel_type: tunnelMode.mode, | ||
} | ||
}) | ||
|
||
|
@@ -190,7 +164,6 @@ If you're using the Ruby app template, then you need to complete the following s | |
forceRelink: flags.reset, | ||
userProvidedConfigName: flags.config, | ||
}) | ||
|
||
const store = await storeContext({ | ||
appContextResult, | ||
storeFqdn: flags.store, | ||
|
@@ -211,7 +184,7 @@ If you're using the Ruby app template, then you need to complete the following s | |
notify: flags.notify, | ||
graphiqlPort: flags['graphiql-port'], | ||
graphiqlKey: flags['graphiql-key'], | ||
tunnel, | ||
tunnel: tunnelMode, | ||
} | ||
|
||
await dev(devOptions) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing since the previous list was non exhaustive. This new appraoch matches the approach we take elsewhere