feat: implement strategy for optional peer deps#289
Open
sjinks wants to merge 4 commits into
Open
Conversation
Adopt a hybrid dependency model aligning with ESLint shareable config and plugin packaging guidance. This allows consumers to opt in to optional framework/tooling packages (TypeScript, React, Jest, Prettier) while keeping runtime-required parser/plugin packages reliable and always installed. Changes: - Move typescript, react, jest, and prettier from devDependencies to peerDependencies and mark as optional via peerDependenciesMeta - Expand is-package-installed() to detect optional peers in consumer package.json, enabling graceful handling in library contexts - Add utils/load-optional-config.js for guarded loading of optional config stacks, preventing MODULE_NOT_FOUND crashes when optional peers are absent - Refactor configs/recommended.js to use guarded loader for conditional TypeScript, testing, React, and Prettier config composition - Create public init.js entrypoint to preload optional packages for consumers requiring upfront resolution - Add comprehensive unit test coverage for guarded loader behavior Package classification: - Keep in dependencies: all runtime-loaded parsers, plugins, resolvers, eslint-config-prettier, globals, find-package-json, typescript-eslint - Add as optional peers: typescript, react, jest, prettier - Keep as peerDependency: eslint Benefits: - Consumers only install framework/tooling packages they actually use - Backward compatible: existing consumers with all packages installed continue working without changes - Clearer intent: optional ecosystem boundaries are explicit - Low setup friction: recommended config still works with minimal consumer configuration - Reliable defaults: parser/plugin stack remains guaranteed available Documentation: - Update README to clarify optional peer behavior and usage patterns - Document init entrypoint for consumers requiring preloading - Add guidance for JS-only consumers and framework-specific setups
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the package/dependency model to support optional peer dependencies (TypeScript, React, Jest, Prettier) and introduces guarded config loading so consumers can opt into integrations without runtime crashes when those optional packages are absent.
Changes:
- Add a guarded optional-config loader and refactor
recommendedconfig composition to use it. - Expand package detection to consider
peerDependenciesin the consumer’spackage.json. - Update packaging/docs and add unit tests + an
init.jsentrypoint for preloading optional stacks.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/load-optional-config.js | New helper to conditionally load optional config stacks and avoid hard crashes on missing modules. |
| utils/is-package-installed.js | Extends dependency detection to include peerDependencies in the resolved parent package.json. |
| configs/recommended.js | Refactors recommended config to compose optional stacks via the guarded loader. |
| init.js | Adds an entrypoint that attempts to preload optional config stacks when the corresponding optional peer is present. |
| tests/load-optional-config.js | Adds unit tests for guarded-loader behavior. |
| package.json | Moves TypeScript/React/Jest/Prettier to optional peer dependencies (via peerDependenciesMeta). |
| package-lock.json | Updates lockfile metadata to reflect new peer dependency configuration. |
| README.md | Documents optional peer behavior and the init entrypoint usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Only swallow MODULE_NOT_FOUND when the missing module is the optional peer itself or a subpath of it. Rethrow errors for unrelated modules to prevent masking real packaging/config bugs. - Update load-optional-config to parse error.message and check the missing module name against the optional peer package name - Add test cases to verify unrelated module errors are rethrown - Add test case to verify subpath modules are correctly swallowed
fe3341e to
056ace3
Compare
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.
Adopt a hybrid dependency model aligning with ESLint shareable config and plugin packaging guidance. This allows consumers to opt in to optional framework/tooling packages (TypeScript, React, Jest, Prettier) while keeping runtime-required parser/plugin packages reliable and always installed.
Changes:
Package classification:
Benefits:
Documentation: