Skip to content

Commit d5c2f93

Browse files
Deprecate importing inject from @ember/service (#20526)
Co-authored-by: Katie Gengler <[email protected]>
1 parent cb59342 commit d5c2f93

File tree

5 files changed

+67
-9
lines changed

5 files changed

+67
-9
lines changed

packages/@ember/-internals/deprecations/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ export const DEPRECATIONS = {
139139
enabled: '5.10.0',
140140
},
141141
}),
142+
DEPRECATE_IMPORT_INJECT: deprecation({
143+
for: 'ember-source',
144+
id: 'importing-inject-from-ember-service',
145+
since: {
146+
available: '6.2.0',
147+
},
148+
until: '7.0.0',
149+
url: 'https://deprecations.emberjs.com/id/importing-inject-from-ember-service',
150+
}),
142151
};
143152

144153
export function deprecateUntil(message: string, deprecation: DeprecationObject) {

packages/@ember/service/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { FrameworkObject } from '@ember/object/-internals';
2+
import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations';
23
import type { DecoratorPropertyDescriptor, ElementDescriptor } from '@ember/-internals/metal';
34
import { inject as metalInject } from '@ember/-internals/metal';
45

@@ -16,6 +17,7 @@ import { inject as metalInject } from '@ember/-internals/metal';
1617
the property's name
1718
@return {ComputedDecorator} injection decorator instance
1819
@public
20+
@deprecated Please import `service` instead.
1921
*/
2022
export function inject(name: string): PropertyDecorator;
2123
export function inject(...args: [ElementDescriptor[0], ElementDescriptor[1]]): void;
@@ -24,6 +26,11 @@ export function inject(): PropertyDecorator;
2426
export function inject(
2527
...args: [] | [name: string] | ElementDescriptor
2628
): PropertyDecorator | DecoratorPropertyDescriptor | void {
29+
deprecateUntil(
30+
'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.',
31+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT
32+
);
33+
2734
return metalInject('service', ...args);
2835
}
2936

packages/@ember/service/tests/service_test.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import Service, { inject, service } from '@ember/service';
22
import EmberObject from '@ember/object';
3-
import { buildOwner, runDestroy } from 'internal-test-helpers';
4-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
3+
import {
4+
AbstractTestCase,
5+
buildOwner,
6+
expectDeprecation,
7+
moduleFor,
8+
runDestroy,
9+
testUnless,
10+
} from 'internal-test-helpers';
11+
import { DEPRECATIONS } from '../../-internals/deprecations';
512

613
moduleFor(
714
'inject - decorator',
815
class extends AbstractTestCase {
9-
['@test works with native decorators'](assert) {
16+
[`${testUnless(
17+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
18+
)} @test works with native decorators`](assert) {
19+
expectDeprecation(
20+
/Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead./,
21+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
22+
);
23+
1024
let owner = buildOwner();
1125

1226
class MainService extends Service {}
@@ -25,7 +39,14 @@ moduleFor(
2539
runDestroy(owner);
2640
}
2741

28-
['@test uses the decorated property key if not provided'](assert) {
42+
[`${testUnless(
43+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
44+
)} @test uses the decorated property key if not provided`](assert) {
45+
expectDeprecation(
46+
/Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead./,
47+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
48+
);
49+
2950
let owner = buildOwner();
3051

3152
class MainService extends Service {}

packages/@ember/service/tests/service_ts_test.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import Service, { inject, service } from '@ember/service';
22
import EmberObject from '@ember/object';
3-
import { buildOwner, runDestroy } from 'internal-test-helpers';
4-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
3+
import {
4+
AbstractTestCase,
5+
buildOwner,
6+
expectDeprecation,
7+
moduleFor,
8+
runDestroy,
9+
testUnless,
10+
} from 'internal-test-helpers';
11+
import { DEPRECATIONS } from '../../-internals/deprecations';
512

613
moduleFor(
714
'inject - decorator (TS)',
815
class extends AbstractTestCase {
9-
['@test works with native decorators'](assert: QUnit['assert']) {
16+
[`${testUnless(
17+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
18+
)} @test works with native decorators`](assert: QUnit['assert']) {
19+
expectDeprecation(
20+
/Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead./,
21+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
22+
);
23+
1024
let owner = buildOwner();
1125

1226
class MainService extends Service {}
@@ -25,7 +39,14 @@ moduleFor(
2539
runDestroy(owner);
2640
}
2741

28-
['@test uses the decorated property key if not provided'](assert: QUnit['assert']) {
42+
[`${testUnless(
43+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
44+
)} @test uses the decorated property key if not provided`](assert: QUnit['assert']) {
45+
expectDeprecation(
46+
/Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead./,
47+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
48+
);
49+
2950
let owner = buildOwner();
3051

3152
class MainService extends Service {}

type-tests/@ember/routing-test/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Router from '@ember/routing/router';
2-
import Service, { inject as service } from '@ember/service';
2+
import Service, { service } from '@ember/service';
33
import EmberObject, { get } from '@ember/object';
44
import RouterService from '@ember/routing/router-service';
55
import RouteInfo, { RouteInfoWithAttributes } from '@ember/routing/route-info';

0 commit comments

Comments
 (0)