From 18c65f22abbeed65291b005cf9b6df06cbf2132b Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Mon, 3 Jun 2024 16:26:16 +0200 Subject: [PATCH 1/3] Deprecate array prototype extensions --- packages/@ember/-internals/deprecations/index.ts | 10 ++++++++++ packages/@ember/-internals/environment/lib/env.ts | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/packages/@ember/-internals/deprecations/index.ts b/packages/@ember/-internals/deprecations/index.ts index 560d1355405..855ecf206a3 100644 --- a/packages/@ember/-internals/deprecations/index.ts +++ b/packages/@ember/-internals/deprecations/index.ts @@ -129,6 +129,16 @@ export const DEPRECATIONS = { enabled: '5.10.0', }, }), + DEPRECATE_ARRAY_PROTOTYPE_EXTENSIONS: deprecation({ + id: 'deprecate-array-prototype-extensions', + url: 'https://deprecations.emberjs.com/id/deprecate-deprecate-array-prototype-extensions', + until: '6.0.0', + for: 'ember-source', + since: { + available: '5.10.0', + enabled: '5.10.0', + }, + }), }; export function deprecateUntil(message: string, deprecation: DeprecationObject) { diff --git a/packages/@ember/-internals/environment/lib/env.ts b/packages/@ember/-internals/environment/lib/env.ts index ae161ca5a39..6547cbe9e6d 100644 --- a/packages/@ember/-internals/environment/lib/env.ts +++ b/packages/@ember/-internals/environment/lib/env.ts @@ -1,3 +1,4 @@ +import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations'; import { DEBUG } from '@glimmer/env'; import global from './global'; @@ -202,6 +203,14 @@ export const ENV = { } let { EXTEND_PROTOTYPES } = EmberENV; + + if (EXTEND_PROTOTYPES !== false) { + deprecateUntil( + 'Array prototype extensions are deprecated. Follow the deprecation guide for migration instructions, and set EmberENV.EXTEND_PROTOTYPES to false in your config/environment.js', + DEPRECATIONS.DEPRECATE_ARRAY_PROTOTYPE_EXTENSIONS + ); + } + if (EXTEND_PROTOTYPES !== undefined) { if (typeof EXTEND_PROTOTYPES === 'object' && EXTEND_PROTOTYPES !== null) { ENV.EXTEND_PROTOTYPES.Array = EXTEND_PROTOTYPES.Array !== false; From 1e686b7f962898e9e1d401b45a15b3457379c013 Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Mon, 3 Jun 2024 18:07:15 +0200 Subject: [PATCH 2/3] Move deprecation to avoid circular module imports --- packages/@ember/-internals/deprecations/index.ts | 11 +++++++++++ packages/@ember/-internals/environment/lib/env.ts | 9 --------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/@ember/-internals/deprecations/index.ts b/packages/@ember/-internals/deprecations/index.ts index 855ecf206a3..4f4d73260b5 100644 --- a/packages/@ember/-internals/deprecations/index.ts +++ b/packages/@ember/-internals/deprecations/index.ts @@ -154,3 +154,14 @@ export function deprecateUntil(message: string, deprecation: DeprecationObject) } deprecate(message, deprecation.test, options); } + +const { EXTEND_PROTOTYPES } = ENV as { + EXTEND_PROTOTYPES: { Array?: boolean }; +}; + +if (EXTEND_PROTOTYPES.Array !== false) { + deprecateUntil( + 'Array prototype extensions are deprecated. Follow the deprecation guide for migration instructions, and set EmberENV.EXTEND_PROTOTYPES to false in your config/environment.js', + DEPRECATIONS.DEPRECATE_ARRAY_PROTOTYPE_EXTENSIONS + ); +} diff --git a/packages/@ember/-internals/environment/lib/env.ts b/packages/@ember/-internals/environment/lib/env.ts index 6547cbe9e6d..ae161ca5a39 100644 --- a/packages/@ember/-internals/environment/lib/env.ts +++ b/packages/@ember/-internals/environment/lib/env.ts @@ -1,4 +1,3 @@ -import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations'; import { DEBUG } from '@glimmer/env'; import global from './global'; @@ -203,14 +202,6 @@ export const ENV = { } let { EXTEND_PROTOTYPES } = EmberENV; - - if (EXTEND_PROTOTYPES !== false) { - deprecateUntil( - 'Array prototype extensions are deprecated. Follow the deprecation guide for migration instructions, and set EmberENV.EXTEND_PROTOTYPES to false in your config/environment.js', - DEPRECATIONS.DEPRECATE_ARRAY_PROTOTYPE_EXTENSIONS - ); - } - if (EXTEND_PROTOTYPES !== undefined) { if (typeof EXTEND_PROTOTYPES === 'object' && EXTEND_PROTOTYPES !== null) { ENV.EXTEND_PROTOTYPES.Array = EXTEND_PROTOTYPES.Array !== false; From 09dc249887e8ec8540b6604be0fceb5c4dfd606b Mon Sep 17 00:00:00 2001 From: Simon Ihmig Date: Tue, 4 Jun 2024 23:36:01 +0200 Subject: [PATCH 3/3] Set RAISE_ON_DEPRECATION to false when EXTEND_PROTOTYPES is enabled --- .github/workflows/ci.yml | 5 ++++- bin/run-tests.js | 7 +++++-- index.html | 14 ++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 993a9245467..1bbbf0bc716 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: working-directory: smoke-tests/scenarios run: | matrix_json=$(pnpm scenario-tester list --require @swc-node/register --files "*-test.ts" --matrix "pnpm run test --filter %s" ) - echo "matrix=$matrix_json" >> $GITHUB_OUTPUT + echo "matrix=$matrix_json" >> $GITHUB_OUTPUT types: name: Type Checking (current version) @@ -105,9 +105,11 @@ jobs: ENABLE_OPTIONAL_FEATURES: "true" - name: "Extend prototypes" EXTEND_PROTOTYPES: "true" + RAISE_ON_DEPRECATION: "false" - name: "Extend prototypes, with optional features" EXTEND_PROTOTYPES: "true" ENABLE_OPTIONAL_FEATURES: "true" + RAISE_ON_DEPRECATION: "false" steps: - uses: actions/checkout@v3 @@ -120,6 +122,7 @@ jobs: OVERRIDE_DEPRECATION_VERSION: ${{ matrix.OVERRIDE_DEPRECATION_VERSION }} EXTEND_PROTOTYPES: ${{ matrix.EXTEND_PROTOTYPES }} ENABLE_OPTIONAL_FEATURES: ${{ matrix.ENABLE_OPTIONAL_FEATURES }} + RAISE_ON_DEPRECATION: ${{ matrix.RAISE_ON_DEPRECATION }} run: pnpm test diff --git a/bin/run-tests.js b/bin/run-tests.js index 2192e1502fc..83087ed9583 100755 --- a/bin/run-tests.js +++ b/bin/run-tests.js @@ -1,11 +1,11 @@ /* eslint-disable no-console */ 'use strict'; -/* +/* Test Variants These are all accepted as environment variables when running `ember test` or - as query params when directly invoking the test suite in the browser. + as query params when directly invoking the test suite in the browser. */ const variants = [ // When true, even deprecations that are not yet at the "enabled" version will @@ -25,6 +25,9 @@ const variants = [ // This enables all canary feature flags for unreleased feature within Ember // itself. 'ENABLE_OPTIONAL_FEATURES', + + // Throw on unexpected deprecations. Defaults to true if not set explicitly. + 'RAISE_ON_DEPRECATION', ]; const chalk = require('chalk'); diff --git a/index.html b/index.html index 373c6d99fbd..c6fad19b48a 100644 --- a/index.html +++ b/index.html @@ -32,15 +32,17 @@ EmberENV.ENABLE_OPTIONAL_FEATURES = true; } - EmberENV['RAISE_ON_DEPRECATION'] = true; + EmberENV['RAISE_ON_DEPRECATION'] = QUnit.urlParams.RAISE_ON_DEPRECATION + ? QUnit.urlParams.RAISE_ON_DEPRECATION === 'true' + : true; if (QUnit.urlParams.ALL_DEPRECATIONS_ENABLED) { - EmberENV['_ALL_DEPRECATIONS_ENABLED'] = true; - } + EmberENV['_ALL_DEPRECATIONS_ENABLED'] = true; + } - if (QUnit.urlParams.OVERRIDE_DEPRECATION_VERSION) { - EmberENV['_OVERRIDE_DEPRECATION_VERSION'] = QUnit.urlParams.OVERRIDE_DEPRECATION_VERSION; - } + if (QUnit.urlParams.OVERRIDE_DEPRECATION_VERSION) { + EmberENV['_OVERRIDE_DEPRECATION_VERSION'] = QUnit.urlParams.OVERRIDE_DEPRECATION_VERSION; + }