Legal-and-General / canopy

Canopy, the design system from Legal and General implemented in Angular
https://legal-and-general.github.io/canopy/?path=/docs/welcome--docs
Apache License 2.0
23 stars 46 forks source link

Canopy and date-fns #1432

Open Xinchro opened 2 months ago

Xinchro commented 2 months ago

Prerequisites

Description

This bug affects:

Steps to Reproduce

  1. Have a project with date-fns 3.x installed
  2. Install Canopy 11.14.1
  3. Import and use beforeDateValidator or afterDateValidator on a form control with a null/undefined value. (i.e. make it so that control.value === null)
  4. Run the app
  5. Note it errors with TypeError: Cannot read properties of null (reading 'split') for parseISO

Expected behaviour:

Canopy should be using its own version of date-fns it relies on to run, when installed, and not the project's version of the dependency.

Actual behaviour:

Canopy uses the project's version of date-fns (3.x, in this case)

Recurrence frequency:

Package version

Configuration and environment

Additional Information

I think the solution may be to move date-fns from peerDependencies in projects/canopy/package.json to dependencies. Having tried this change locally, when running npm run build, I get this error/warning:

⚠ Distributing npm packages with 'dependencies' is not recommended. Please consider adding date-fns to 'peerDependencies' or remove it from 'dependencies'.
✖ Writing package manifest
Dependency date-fns must be explicitly allowed using the "allowedNonPeerDependencies" option.