-
Notifications
You must be signed in to change notification settings - Fork 8.6k
DEV: Deprecate Ember native array extensions #34394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
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
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.
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.
app/assets/javascripts/discourse/tests/helpers/deprecation-counter.js
Outdated
Show resolved
Hide resolved
davidtaylorhq
approved these changes
Aug 22, 2025
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.
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.
tyb-talks
reviewed
Aug 27, 2025
tyb-talks
reviewed
Aug 27, 2025
app/assets/javascripts/discourse/tests/helpers/deprecation-counter.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Kelv <kelv@discourse.org>
tyb-talks
approved these changes
Aug 27, 2025
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.
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.