Skip to content

Commit

Permalink
Merge pull request #20702 from simonihmig/array-prototype-deprecation
Browse files Browse the repository at this point in the history
Deprecate array prototype extensions
  • Loading branch information
ef4 authored Jun 14, 2024
2 parents 438ff67 + 09dc249 commit 756f0e3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
7 changes: 5 additions & 2 deletions bin/run-tests.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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');
Expand Down
14 changes: 8 additions & 6 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</script>

<script type="module">
Expand Down
21 changes: 21 additions & 0 deletions packages/@ember/-internals/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -144,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
);
}

0 comments on commit 756f0e3

Please sign in to comment.