Skip to content

Conversation

megothss
Copy link
Contributor

@megothss megothss commented Aug 18, 2025

Introduce a runtime initializer that surfaces deprecations when legacy Ember native array extension APIs are used, preserving behavior while making usage easy to find and migrate.

  • Add an initializer that wraps legacy Ember array extension methods to emit deprecation warnings.
  • Provide clear, centralized deprecation messages to aid discovery and migration.
  • Maintain functional parity while collecting usage signals for Ember 6+ compatibility.

Introduce an initializer to add deprecation warnings for Ember native
array extensions, now removed in Ember 6.0. This helps collect usage
data and enables tracking deprecated methods in the source code.
Introduce support for regular expression matching in the deprecation
workflow by encapsulating workflows in a new `DeprecationWorkflowList`
class. This enhancement allows more flexible and concise handling of
deprecation IDs, enabling patterns instead of strict string matching.
Refactor `DeprecationWorkflowList` to throw an `Error` instead of using
`assert` for invalid `matchId` types to prevent a 'could not find module `@ember/debug`' running code on MiniRacer
Refactor `DeprecationWorkflowList` to `DiscourseDeprecationWorkflow` and
introduce environment-based filtering for workflows. This ensures deprecations
are only applied in specified environments, improving granularity and control.

Updates include support for multiple handlers using a pipe-separated format and
enhanced deprecation counting logic. The new design better adheres to
environmental requirements and integrates seamlessly with the deprecation
warning infrastructure.
Wrap the `require` of `discourse/lib/environment` in a `try-catch` block to
prevent errors when running code on MiniRacer. This ensures that the
application gracefully handles cases where the environment module cannot
be loaded, maintaining stability.
Eliminate the `makeArray` import and usage in `DiscourseDeprecationWorkflow` to address compatibility issues with MiniRacer. Validation logic for `envs` has been refactored to simplify and ensure reliability.
Replace the `Map`-based configuration storage with an array-based approach using the `findConfig` method.

This supports both string and regex matching for `matchId`.

Adjust existing handlers to use
the new method, ensuring compatibility with the updated structure.
Simplify `matchId` for Ember native array extensions by removing dynamic
suffixes and adjusting the deprecation workflow handler configuration. This
ensures consistent tracking and silencing for related deprecations.
@megothss megothss marked this pull request as draft August 19, 2025 04:21
Streamline `DeprecationWorkflow` implementation by consolidating environment setup and enabling environment-specific deprecation filtering. Deprecation handlers now validate and restrict environments to predefined values (`VALID_ENVS`), with logic centralized for maintainability.

Remove the initializer for Ember native array extensions, replacing it with a standalone `deprecate-native-array-extensions.js` module.
Remove the `"throw"` handler for `native-array-extensions` deprecations in development and consolidate handling under the `"silence|counter"` configuration for the test environment.
Introduce deprecation warnings for the special case of `array["[]"]` in
`deprecate-native-array-extensions.js`. This change ensures usage of deprecated
Ember native array extensions is logged with clear guidance to switch to native
or Ember array methods.

New logic leverages `withSilencedDeprecations` for controlled handling of
setters while preserving backward compatibility.
Update comments and deprecation warning messaging in
`deprecate-native-array-extensions.js` to improve clarity around the special
case `array["[]"]`. Adjust warning prefix from `[].method` to `array.method`
for consistency. This ensures developers better understand the guidance for
replacing deprecated Ember native array methods.
Improve clarity and consistency in deprecation warnings within
`deprecate-native-array-extensions.js`. Update messaging for `array["[]"]`
and `array.${k}` to use standard phrasing (`array.method`)
Restructure `deprecate-native-array-extensions.js` to improve readability and maintainability. Extract helper functions (`isDeprecatedMethod`, `deprecateArrayMethod`, `wrapSquareBracketDescriptor`) to simplify method wrapping logic and better document behaviors.
Ensure consistency and clarity in deprecation messages in `deprecate-native-array-extensions.js`. Updated warnings now uniformly recommend using "native array methods, an Ember array, or a TrackedArray" for both `array.${methodName}` and `array["[]"]` cases. Adjustments improve developer guidance and align with previous refinement efforts.
Introduce a `warn` function in `deprecate-native-array-extensions.js` to unify deprecation message handling for Ember native array extensions. This ensures consistent formatting and phrasing across method, getter, and setter warnings, reducing repetition in the codebase.
Merge `deprecate-native-array-extensions.js` logic into `array-shim.js` to reduce duplication and streamline compatibility for deprecated Ember native array extensions.

The shim now ensures backward compatibility with added deprecation warnings for tracking and guidance.

Remove redundant `deprecate-native-array-extensions.js`, updating imports to reference `array-shim.js`.
Replace `Set` with an array for `disabledDeprecations` to support complex
matching, including `RegExp` comparisons. Update related methods such as
`isDeprecationSilenced` and callback handlers to accommodate this change.
This ensures more robust and customizable deprecation silencing.
Replace unnecessary `matchId` property access with a direct `instanceof`
check for `RegExp` in `disabledDeprecations`. This streamlines the
conditional logic, reducing ambiguity and improving code clarity. Scope is
limited to `app/lib/deprecated.js`. Risk is minimal; verify by ensuring
deprecations correctly match against `RegExp` without regression in tested
scenarios.
Update the `withSilencedDeprecations` and `withSilencedDeprecationsAsync` functions to accept `RegExp` or an array of `RegExp` for deprecation silencing. This enhancement increases flexibility, allowing developers to silence patterns of deprecations more effectively. Changes are scoped to `app/lib/deprecated.js`.
Update `array-shim.js` to incorporate `escapeRegExp` and enable silenced
deprecations using `RegExp` patterns. This improves flexibility in managing
deprecations, especially for dynamic identifiers like `[]`. Refactor
repeated `Array.prototype` references and enhance the `deprecateArrayMethod`
and `wrapSquareBracketDescriptor` functions to respect silenced patterns
using `withSilencedDeprecations`. Adjustments ensure compatibility with
Ember's evolving native array behaviors.

Changes are confined to `array-shim.js` with minimal risk. Verify by
ensuring methods like `[]` and other deprecated extensions trigger warnings
unless silenced via configured patterns.
Update `DeprecationCounter` to incorporate the `isDeprecationSilenced` method, enhancing support for dynamic deprecation silencing logic. Refactor the conditionals in `handleEmberDeprecation` to respect silenced states, ensuring counters are only incremented when appropriate.
Update the `setupToolbar` function in `setup-tests.js` to replace `reject` with `filter` when removing unnecessary URL config options in QUnit.
Update the `deprecation-workflow` configuration to silence native array
extension deprecations in both `development` and `production` environments.
This ensures consistent behavior during local development and production
builds, reducing noise while maintaining focus on actionable warnings.
Remove the unused configuration logic from `DeprecationCounter`, including the `findConfig` method and associated private property. Replace direct config access with calls to `DeprecationWorkflow.find`, streamlining deprecation handler management. Adjust related conditional logic to respect silenced states and maintain proper counter increments.
Extract conditional logic into a new `shouldCount` helper method to enhance code clarity and reuse in `handleEmberDeprecation` and `handleDiscourseDeprecation`. Simplify `incrementDeprecation` logic, renamed to `incrementCount`, and update its Testem reporting function. Adjust table formatting in `generateTable` for better alignment and readability.
Update `DeprecationCounter` to sort table output alphabetically by ID for
improved readability. Adjust the iteration logic in `generateTable` to use
a sorted array of entries, ensuring consistent ordering of deprecation IDs
in reports. This change affects only the table generation and has minimal
risk. Verify by checking the alphabetical order of entries in test
outputs.
…entCount`

Adjust unit tests in `deprecated-test.js` to align with the recent refactor
renaming `incrementDeprecation` to `incrementCount`. This ensures test
assertions and stubs correctly reference the updated method name, avoiding
potential confusion. Scope is limited to test code changes, with no runtime
impact or risk introduced.
Expand `deprecated-test.js` to include coverage for silencing deprecations
using `RegExp` patterns in both sync and async contexts. New tests verify
that `withSilencedDeprecations` and `withSilencedDeprecationsAsync` handle
`RegExp` and mixed pattern arrays correctly, avoiding unnecessary warnings
and counter increments.

These additions ensure the recent enhancements to deprecation silencing are
well-tested, reducing risk and improving confidence in handling dynamic
patterns.
Add handler and environment validation logic to `DiscourseDeprecationWorkflow`, ensuring inputs conform to expected formats. Normalize and verify handler combinations, disallowing invalid or conflicting states such as both `log` and `silence`. Introduce methods like `shouldLog`, `shouldSilence`, and `shouldThrow` to streamline deprecation checks. Replace split-pipe handler logic with an array-based format.

Update related files to utilize the new helper methods, improving clarity and reducing duplication. Expand test coverage with unit tests for all workflow scenarios and helper behaviors, ensuring robust validation and compatibility.
Introduce detailed JSDoc comments across `DiscourseDeprecationWorkflow` to
document class properties, methods, and usage. The comments improve code
readability, aiding maintainers in understanding handler validation,
environment-specific workflows, and deprecation management logic.
Improve JSDoc comments for `withSilencedDeprecations` and `withSilencedDeprecationsAsync` to reflect support for mixed arrays of strings and `RegExp` patterns. These changes enhance developer understanding of acceptable `deprecationIds` formats, making the API more accessible and reducing ambiguity.
Fix inverted conditional in `DiscourseDeprecationWorkflow` that caused deprecations to be incorrectly silenced.
@megothss megothss marked this pull request as ready for review August 26, 2025 02:55
Change the `DEPRECATION_ID_PREFIX` constant in `array-shim.js` to remove the redundant `ember` namespace, for a simplified deprecation naming scheme.
Simplify deprecation ID patterns in `DiscourseDeprecationWorkflow` by
removing the redundant `ember` namespace. This aligns with recent refactors
to streamline deprecation naming and maintains consistency across test,
development, and production environments.
Update deprecation messages in `array-shim.js` to remove references to `EmberArray`
…flow`

Add a JSDoc comment emphasizing that the order of workflows in
`DiscourseDeprecationWorkflow` is crucial since the first matching rule
takes precedence. This clarification helps developers avoid unintended
priority issues when configuring deprecation handlers.
Co-authored-by: Kelv <kelv@discourse.org>
@megothss megothss changed the title DEV: Add deprecation warnings for Ember native array extensions DEV: Deprecate Ember native array extensions Aug 27, 2025
@megothss megothss merged commit c7f6108 into main Aug 27, 2025
18 checks passed
@megothss megothss deleted the dev/deprecate-ember-array-extensions branch August 27, 2025 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants