Skip to content

feat: redesign Configuration class for v4#3484

Open
B4nan wants to merge 12 commits intov4from
refactor/configuration-class-redesign
Open

feat: redesign Configuration class for v4#3484
B4nan wants to merge 12 commits intov4from
refactor/configuration-class-redesign

Conversation

@B4nan
Copy link
Copy Markdown
Member

@B4nan B4nan commented Mar 13, 2026

Summary

  • Replaces get()/set() with direct property accessconfig.headless instead of config.get('headless'). Both methods are removed (v4 breaking change).
  • Constructor options now take highest prioritynew Configuration({ headless: false }) works even when CRAWLEE_HEADLESS=true is set. New priority: constructor > env vars > crawlee.json > schema defaults.
  • Immutable instances — assigning to a config property throws TypeError.
  • Zod-based field definitions — schema, env var mapping, and defaults defined in one place (crawleeConfigFields).
  • Extensible via subclassing — subclasses override protected static fields to register additional config fields (e.g. Apify SDK).

Closes #3080

🤖 Generated with Claude Code

@B4nan B4nan force-pushed the refactor/configuration-class-redesign branch from 9d915c7 to a2ae684 Compare March 16, 2026 09:31
B4nan and others added 4 commits March 16, 2026 10:33
Replace Map-based get()/set() API with Zod-based field definitions and
direct property access. Configuration is now immutable, and constructor
options take precedence over environment variables.

Priority order: constructor options > env vars > crawlee.json > defaults

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… and z

Allow `envVar` to accept `string | string[]` so the Apify SDK can map
ACTOR_/APIFY_/CRAWLEE_ prefixed env vars to a single config field.
Also export `coerceNumber` and `z` for SDK reuse.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@B4nan B4nan force-pushed the refactor/configuration-class-redesign branch from a2ae684 to 1a2f7f0 Compare March 16, 2026 09:33
B4nan and others added 8 commits March 16, 2026 11:04
Constructor options and crawlee.json values were returned raw from
_resolve(), bypassing schema validation that env vars already went
through. Now all four resolution paths (constructor, env, file,
defaults) consistently run through fieldDef.schema.parse().

Adds tests for crawlee.json loading and constructor option coercion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The declaration merging pattern is intentional — properties are defined
at runtime via Object.defineProperties in registerAccessors().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…link

The ConfigurationOptions interface was replaced by ConfigurationInput
type alias in v4. Updated docs to reference the Configuration class
directly and reflect the new immutable API (no more get/set methods).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…x broken refs

- Cache all resolved Configuration values at construction time instead of
  re-running Zod parsing on every property access (perf fix for hot paths
  like emitSystemInfoEvent which reads config every ~1s)
- Replace 13-method manual serviceLocator proxy with a Proxy object
- Fix broken Configuration.getStorageClient() calls in test and e2e files
  to use serviceLocator.getStorageClient()
- Move EventEmitter.defaultMaxListeners to module scope (run once, not per instance)
- Extract readEnvVar() helper, remove TOCTOU pathExistsSync before readFileSync
- Add systemInfoV2 to "Removed symbols" in upgrade guide

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Remove unnecessary exports (coerceNumber, logLevelSchema, z from zod)
- Add set trap to serviceLocator proxy for a helpful error message
- Document resetGlobalState() removal in upgrade guide
- Fix mock logger method name (internal → logWithLevel)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Revert the Proxy-based serviceLocator back to the explicit delegation
style. The proxy refactor is unrelated to the Configuration redesign
and has been split into its own PR (#3515) for separate discussion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants