Skip to content

Commit a74f729

Browse files
committed
Deprecate importing inject from @ember/service
1 parent cb59342 commit a74f729

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,5 +400,6 @@
400400
"volta": {
401401
"node": "16.20.0",
402402
"pnpm": "8.10.0"
403-
}
403+
},
404+
"packageManager": "[email protected]+sha512.c8180b3fbe4e4bca02c94234717896b5529740a6cbadf19fa78254270403ea2f27d4e1d46a08a0f56c89b63dc8ebfd3ee53326da720273794e6200fcf0d184ab"
404405
}

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: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import Service, { inject, service } from '@ember/service';
22
import EmberObject from '@ember/object';
33
import { buildOwner, runDestroy } from 'internal-test-helpers';
4-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
4+
import { moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers';
5+
import { DEPRECATIONS } from '../../-internals/deprecations';
56

67
moduleFor(
78
'inject - decorator',
89
class extends AbstractTestCase {
9-
['@test works with native decorators'](assert) {
10+
[`${testUnless(
11+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
12+
)} @test works with native decorators`](assert) {
13+
expectDeprecation(
14+
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
15+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
16+
);
17+
1018
let owner = buildOwner();
1119

1220
class MainService extends Service {}
@@ -25,7 +33,14 @@ moduleFor(
2533
runDestroy(owner);
2634
}
2735

28-
['@test uses the decorated property key if not provided'](assert) {
36+
[`${testUnless(
37+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
38+
)} @test uses the decorated property key if not provided`](assert) {
39+
expectDeprecation(
40+
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
41+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
42+
);
43+
2944
let owner = buildOwner();
3045

3146
class MainService extends Service {}

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import Service, { inject, service } from '@ember/service';
22
import EmberObject from '@ember/object';
33
import { buildOwner, runDestroy } from 'internal-test-helpers';
4-
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
4+
import { moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers';
5+
import { DEPRECATIONS } from '../../-internals/deprecations';
56

67
moduleFor(
78
'inject - decorator (TS)',
89
class extends AbstractTestCase {
9-
['@test works with native decorators'](assert: QUnit['assert']) {
10+
[`${testUnless(
11+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
12+
)} @test works with native decorators`](assert: QUnit['assert']) {
13+
expectDeprecation(
14+
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
15+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
16+
);
17+
1018
let owner = buildOwner();
1119

1220
class MainService extends Service {}
@@ -25,7 +33,14 @@ moduleFor(
2533
runDestroy(owner);
2634
}
2735

28-
['@test uses the decorated property key if not provided'](assert: QUnit['assert']) {
36+
[`${testUnless(
37+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
38+
)} @test uses the decorated property key if not provided`](assert: QUnit['assert']) {
39+
expectDeprecation(
40+
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
41+
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
42+
);
43+
2944
let owner = buildOwner();
3045

3146
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)