feat: custom variable names for port and host#141
Open
Goketech wants to merge 2 commits intovercel-labs:mainfrom
Open
feat: custom variable names for port and host#141Goketech wants to merge 2 commits intovercel-labs:mainfrom
Goketech wants to merge 2 commits intovercel-labs:mainfrom
Conversation
|
@Goketech is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
|
Hey, I just opened #167 which adds Close in scope but no conflict. One overlap: placeholders could also handle env var renaming via A bit roundabout compared to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Previously, portless hardcoded
PORTandHOSTas the environment variable names injected into child processes. Some frameworks or monorepo setups use different conventions (e.g.APP_PORT,SERVER_PORT), making portless incompatible without workarounds. This PR addresses the feature request in #59 by allowing users to override the variable names via--port-var/--host-varflags orPORTLESS_PORT_VAR/PORTLESS_HOST_VARenvironment variables.Evidence
runApp()incli.tspreviously calledspawnCommandwith a hardcodedPORTandHOSTkey — no way to override without modifying sourceParsedRunArgsandParsedAppArgsinterfaces had no fields for custom var names--helpoutput listedPORTandHOSTas fixed injected variables with no indication they were configurablePORT/HOSTChanges
Core logic (
cli.ts):portVarNameandhostVarNameparameters torunApp(), defaulting to"PORT"and"HOST"portVarName/hostVarNamefields toParsedRunArgsandParsedAppArgsinterfacesENV_VAR_NAME_REregex (/^[A-Za-z_][A-Za-z0-9_]*$/) for validationparseEnvVarName()— validates a CLI-provided var name, exits with a descriptive error on invalid inputenvVarNameFromEnv()— readsPORTLESS_PORT_VAR/PORTLESS_HOST_VARfrom the environment with the same validationresolveChildEnvVarNames()— merges CLI overrides with env-based overrides, and rejects when--port-varand--host-varresolve to the same name--port-varand--host-varflags into bothparseRunArgs()andparseAppArgs()(including both the leading-flag and post-name sections of the latter)spawnCommandcall to use[portVarName]and[hostVarName]as computed keys--helpandRunning:log line to reflect the variable names in useDocumentation (
README.md):--port-var <n>and--host-var <n>to the CLI options tablePORTLESS_PORT_VARandPORTLESS_HOST_VARto the environment variables tablePORT or custom --port-varandHOST or custom --host-varPORTis now described as assigned "by default" to signal it's overridableTest plan
--port-varand--host-varaccepted in bothrunmode and named (app) mode — verified viaPORTLESS=0dry-run tests1BAD,BAD-NAME) cause exit code 1 with"Invalid environment variable name"error--port-varand--host-varcauses exit code 1 with"cannot use the same name"errorPORTLESS_PORT_VARenv value causes exit code 1 with"Invalid PORTLESS_PORT_VAR"error--helpoutput now includes--port-var,--host-var,PORTLESS_PORT_VAR,PORTLESS_HOST_VAR— asserted in existing help tests