refactor(12factor-env): centralize permissive env parsers#1372
Draft
Zetazzz wants to merge 1 commit into
Draft
Conversation
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
This PR moves the repository's shared permissive environment-value parsers into the neutral
12factor-envmechanism layer.parseEnvBoolean,parseEnvNumber, andparseEnvStringArray.12factor-env/parsersentry point.@pgpmjs/env.This changes parser ownership only. It does not move environment variables, defaults, configuration sections, output structures, or merge behavior between runtime packages.
Why
Several unrelated jobs and function packages depended on
@pgpmjs/envonly to reuse a generic boolean parser, while GraphQL and PostgreSQL packages maintained duplicate implementations.12factor-envis the neutral lower-level package for environment parsing and validation mechanics, so it can provide these pure conversions without making PGPM or GraphQL env a general-purpose utility package.Compatibility
The shared parsers intentionally preserve the existing permissive behavior:
parseEnvBoolean(undefined)returnsundefined. Onlytrue,1, andyesare true, case-insensitively and without trimming; every other defined string is false.parseEnvNumber()continues to use JavaScriptNumber()conversion and returnsundefinedonly when the result isNaN.parseEnvStringArray()continues to split on commas, trim entries, remove empty entries, and preserve ordering and duplicates.The
12factor-env/parsersentry is pure: it does not readprocess.env, access files or secrets, or load envalid.Existing envalid-backed strict validators and secret-file behavior remain unchanged. Parsers with different contracts remain local to their owners.
API impact
Consumers should import shared parsers from
12factor-env/parsers.@pgpmjs/envno longer publicly re-exportsparseEnvBooleanorparseEnvNumber.This is an API relocation only; PGPM, GraphQL, jobs, and function runtimes continue to own their respective variable names, defaults, configuration structures, and fallback policies.
Package exports
12factor-envnow declares explicit exports for:12factor-env/parsers;package.json;Published-package smoke tests build the distributable package and verify root and parser imports through CommonJS and native ESM.
Validation
12factor-env: 47 tests