-
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
Conversation
This comment has been minimized.
This comment has been minimized.
cb48f38
to
25ccd67
Compare
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success2217 tests passing in 966 suites. Report generated by 🧪jest coverage report action from c65b5bb |
|
||
// When | ||
const got = await generateFrontendURL(options) | ||
|
||
// Then | ||
expect(got).toEqual({frontendUrl: 'https://localhost', frontendPort: 3042, usingLocalhost: true}) | ||
expect(got).toEqual({frontendUrl: 'https://localhost', frontendPort: 1234, usingLocalhost: true}) |
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.
This change needs carefully reviewing. I think it's the correct test, and I think it hasn't changed behaviour because the previous test didn't match how this function was used. But we need to be sure.
Whoever reviews this please can you double check?
958ab68
to
bc25a68
Compare
@@ -91,11 +88,17 @@ 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)", |
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
bc25a68
to
06eaa06
Compare
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed this value has not changed:
On this branch branch
pnpm shopify app dev --path='../app-test-use-localhost'
auto
pnpm shopify app dev --path='../app-test-use-localhost' --use-localhost
use-localhost
pnpm shopify app dev --path='../app-test-use-localhost' --tunnel-url="http://my-tunnel.com:3000"
custom
On main
pnpm shopify app dev --path='../app-test-use-localhost'
auto
pnpm shopify app dev --path='../app-test-use-localhost' --use-localhost
use-localhost
pnpm shopify app dev --path='../app-test-use-localhost' --tunnel-url="http://my-tunnel.com:3000"
custom
I think this case should actually crash. If you are explicitly passing a setting (a specific port) and that port is not available it makes more sense to stop the execution than to ignore the setting |
yeah, completely fair. I mis-understood how the |
89766ce
to
edcd74c
Compare
/snapit |
🫰✨ Thanks @nickwesselman! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g @shopify/[email protected] Tip If you get an Caution After installing, validate the version by running just |
517a5d6
to
9ecfc35
Compare
There are 2 improvements: 1. --use-localhost will always try to use the same port if it is available. 2. A new --localhost-port flag has been added to specify a port. If neither the default port, or the one specified using --localhost-port is not available, we show a warning to the developer and choose a random available port.
… service. Add tests
Previously the options passed to generateFrontendURL were an object with a bunch of optional properties. But if noTunnelUseLocalhost is true then port is mandatory and it's alwasy passed. By switching options to a union typescriot understands this and we no longer need to have get an available TCP port for localhost... it would alwasy be passed
1. --localhost-port no longer requires the --use-localhost flag 2. If --localhost-port is specified, but the port is not free, the process exist with a warning message 3. Improve the argument typing for generateFrontendURL()
9ecfc35
to
fb1ba81
Compare
* Fix typo in changelog * If graphiql and localhost port is already in use, we will only show one renderWarning message. We do this by combining 2 messages into 1
20abc74
to
22d320f
Compare
// getTunnelMode can populate this array. This array is then passed to the dev function. | ||
// This allows the dev function to group port warnings into a single renderWarning | ||
const portWarnings: PortWarning[] = [] |
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.
I don't think you need to start this here and pass it to getTunnelMode
and the dev
service.
inside prepareForDev
before calling renderPortWarnings
you can just do:
if (tunnel.mode === 'use-localhost' && tunnel.port !== ports.localhost) {
portWarnings.push({
type: 'localhost',
requestedPort: tunnel.port,
flag: '--localhost-port',
})
}
* Move asHumanfriendlyTokenList to cli-kit/common/array, rename to asHumanFriendlyArray, update asHumanFriendlyArray to accept a generic so the return array can be explicitly typed if needed * Move getTunnelMode() into its own file * Move renderPortWarnings() into its own file
ca0216d
to
d719c89
Compare
…d, getTunnelMode() returns the requested and actual port, which dev pased to renderPortWarnings(). renderPortWarnings() then renders errors every time requested and actual ports mis-match
/snapit |
🫰✨ Thanks @nickwesselman! Your snapshot has been published to npm. Test the snapshot by installing your package globally: pnpm i -g @shopify/[email protected] Tip If you get an Caution After installing, validate the version by running just |
// beforeEach(() => { | ||
// vi.mocked(generateCertificate).mockResolvedValue(mockCertificate) | ||
// }) |
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.
remove this commented code please
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/common/array.d.ts@@ -45,4 +45,17 @@ export declare function uniqBy<T>(array: List<T> | null | undefined, iteratee: V
* @param values - The arrays of values to exclude.
* @returns Returns the new array of filtered values.
*/
-export declare function difference<T>(array: List<T> | null | undefined, ...values: List<T>[]): T[];
\ No newline at end of file
+export declare function difference<T>(array: List<T> | null | undefined, ...values: List<T>[]): T[];
+/**
+ * Converts an array of anything into a human friendly list.
+ *
+ * Returns a new array that contains the items separated by commas,
+ * except for the last item, which is separated by "and".
+ * This is useful for creating human-friendly sentences.
+ *
+ * @param items - Token[].
+ * @returns Token[].
+ * @example
+ *
+ */
+export declare function asHumanFriendlyArray<T>(items: T[]): (T | string)[];
\ No newline at end of file
|
WHY are these changes introduced?
We think controlling the localhost port is a very useful feature
WHAT is this pull request doing?
Changes the default behaviour for
--use-localhost
:--use-localhost
flag is present, the CLI always tries to use the same port. Previously it was random--use-localhost
flag is present but the default port is taken, it will take a random available port and warn the userAdds a
--localhost-port
flag. When--localhost-port=7000 --use-localhost
flags are present, the CLI will try to use port 7000. If it is not free, it will warn and take a random available portI also did some refactors:
/commands/dev.ts
into/services/dev.ts
and tested that logic (Previously this was untested)services/dev/url.ts
. Previously we had an interface with a bunch of optional properties. Now we have a union that more accurately describes when properties will be defined or undefined. This allowed me to delete some fallback code that was never required.How to test your changes?
pnpm shopify app dev --path='[PATH]'
should use a tunnelpnpm shopify app dev --path='[PATH]' --use-localhost
a few times. The port should not changepnpm shopify app dev --path='[PATH]' --use-localhost
in 2 separate terminals at once. The 2nd time you run it you should see a warning (see below) and a different port should be selected.pnpm shopify app dev --path='[PATH]' --use-localhost --localhost=[PORT]
. The port you passed should be used.pnpm shopify app dev --path='[PATH]' --use-localhost --localhost=[PORT]
in 2 separate terminals at once. The 2nd time you run it you should see a warning (see below) and a different port should be selected.Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist