Skip to content

Commit

Permalink
Fix port finder for MiniOxygen (#1267)
Browse files Browse the repository at this point in the history
* Fix port finder for MiniOxygen

* Changesets

* Bump mini-oxygen with the fix
  • Loading branch information
frandiox committed Aug 25, 2023
1 parent 423acee commit d67ce6a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-starfishes-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Fix development server port in some situations where it was set to a random number instead of the default 3000 or the `--port` flag value.
13 changes: 8 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@remix-run/dev": "1.19.1",
"@shopify/cli-kit": "3.48.0",
"@shopify/hydrogen-codegen": "^0.0.2",
"@shopify/mini-oxygen": "^2.1.1",
"@shopify/mini-oxygen": "^2.1.2",
"ansi-escapes": "^6.2.0",
"diff": "^5.1.0",
"fast-glob": "^3.2.12",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/hydrogen/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {addVirtualRoutes} from '../../lib/virtual-routes.js';
import {spawnCodegenProcess} from '../../lib/codegen.js';
import {getAllEnvironmentVariables} from '../../lib/environment-variables.js';
import {getConfig} from '../../lib/shopify-config.js';
import {findPort} from '../../lib/find-port.js';
import {setupLiveReload} from '../../lib/live-reload.js';
import {checkRemixVersions} from '../../lib/remix-version-check.js';

Expand Down Expand Up @@ -159,7 +158,7 @@ async function runDev({

miniOxygen = await startMiniOxygen({
root,
port: await findPort(portFlag),
port: portFlag,
watch: !liveReload,
buildPathWorkerFile,
buildPathClient,
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/commands/hydrogen/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {muteDevLogs} from '../../lib/log.js';
import {getProjectPaths} from '../../lib/remix-config.js';
import {commonFlags, DEFAULT_PORT} from '../../lib/flags.js';
import {startMiniOxygen} from '../../lib/mini-oxygen.js';
import {findPort} from '../../lib/find-port.js';

export default class Preview extends Command {
static description =
Expand Down Expand Up @@ -36,7 +35,7 @@ export async function runPreview({

const miniOxygen = await startMiniOxygen({
root,
port: await findPort(port),
port,
buildPathClient,
buildPathWorkerFile,
});
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/lib/find-port.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import getPort, {portNumbers} from 'get-port';

/**
*
* Finds an available port in the range of `portPreference` to `portPreference + range`.
* Note: do not use this utility to find a port for MiniOxygen since that will be
* handled by MiniOxygen itself. See https://github.com/Shopify/hydrogen/issues/1264
*/
export function findPort(portPreference: number, range = 100) {
return getPort({
port: portNumbers(portPreference, portPreference + range),
Expand Down

0 comments on commit d67ce6a

Please sign in to comment.