Skip to content

Commit

Permalink
Deprecate importing inject from @ember/service
Browse files Browse the repository at this point in the history
  • Loading branch information
bertdeblock committed Dec 11, 2024
1 parent cb59342 commit 3b4db23
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/@ember/-internals/deprecations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ export const DEPRECATIONS = {
enabled: '5.10.0',
},
}),
DEPRECATE_IMPORT_INJECT: deprecation({
for: 'ember-source',
id: 'importing-inject-from-ember-service',
since: {
available: '6.2.0',
},
until: '7.0.0',
url: 'https://deprecations.emberjs.com/id/importing-inject-from-ember-service',
}),
};

export function deprecateUntil(message: string, deprecation: DeprecationObject) {
Expand Down
7 changes: 7 additions & 0 deletions packages/@ember/service/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FrameworkObject } from '@ember/object/-internals';
import { DEPRECATIONS, deprecateUntil } from '@ember/-internals/deprecations';
import type { DecoratorPropertyDescriptor, ElementDescriptor } from '@ember/-internals/metal';
import { inject as metalInject } from '@ember/-internals/metal';

Expand All @@ -16,6 +17,7 @@ import { inject as metalInject } from '@ember/-internals/metal';
the property's name
@return {ComputedDecorator} injection decorator instance
@public
@deprecated Please import `service` instead.
*/
export function inject(name: string): PropertyDecorator;
export function inject(...args: [ElementDescriptor[0], ElementDescriptor[1]]): void;
Expand All @@ -24,6 +26,11 @@ export function inject(): PropertyDecorator;
export function inject(
...args: [] | [name: string] | ElementDescriptor
): PropertyDecorator | DecoratorPropertyDescriptor | void {
deprecateUntil(
'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.',
DEPRECATIONS.DEPRECATE_IMPORT_INJECT
);

return metalInject('service', ...args);
}

Expand Down
21 changes: 18 additions & 3 deletions packages/@ember/service/tests/service_test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import Service, { inject, service } from '@ember/service';
import EmberObject from '@ember/object';
import { buildOwner, runDestroy } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers';
import { DEPRECATIONS } from '../../-internals/deprecations';

moduleFor(
'inject - decorator',
class extends AbstractTestCase {
['@test works with native decorators'](assert) {
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
)} @test works with native decorators`](assert) {
expectDeprecation(
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
);

let owner = buildOwner();

class MainService extends Service {}
Expand All @@ -25,7 +33,14 @@ moduleFor(
runDestroy(owner);
}

['@test uses the decorated property key if not provided'](assert) {
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
)} @test uses the decorated property key if not provided`](assert) {
expectDeprecation(
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
);

let owner = buildOwner();

class MainService extends Service {}
Expand Down
21 changes: 18 additions & 3 deletions packages/@ember/service/tests/service_ts_test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import Service, { inject, service } from '@ember/service';
import EmberObject from '@ember/object';
import { buildOwner, runDestroy } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase } from 'internal-test-helpers';
import { moduleFor, AbstractTestCase, testUnless } from 'internal-test-helpers';
import { DEPRECATIONS } from '../../-internals/deprecations';

moduleFor(
'inject - decorator (TS)',
class extends AbstractTestCase {
['@test works with native decorators'](assert: QUnit['assert']) {
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
)} @test works with native decorators`](assert: QUnit['assert']) {
expectDeprecation(

Check failure on line 13 in packages/@ember/service/tests/service_ts_test.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'expectDeprecation'.
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
);

let owner = buildOwner();

class MainService extends Service {}
Expand All @@ -25,7 +33,14 @@ moduleFor(
runDestroy(owner);
}

['@test uses the decorated property key if not provided'](assert: QUnit['assert']) {
[`${testUnless(
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isRemoved
)} @test uses the decorated property key if not provided`](assert: QUnit['assert']) {
expectDeprecation(

Check failure on line 39 in packages/@ember/service/tests/service_ts_test.ts

View workflow job for this annotation

GitHub Actions / Type Checking (current version)

Cannot find name 'expectDeprecation'.
/'Importing `inject` from `@ember\/service` is deprecated. Please import `service` instead.'/,
DEPRECATIONS.DEPRECATE_IMPORT_INJECT.isEnabled
);

let owner = buildOwner();

class MainService extends Service {}
Expand Down
2 changes: 1 addition & 1 deletion type-tests/@ember/routing-test/router.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Router from '@ember/routing/router';
import Service, { inject as service } from '@ember/service';
import Service, { service } from '@ember/service';
import EmberObject, { get } from '@ember/object';
import RouterService from '@ember/routing/router-service';
import RouteInfo, { RouteInfoWithAttributes } from '@ember/routing/route-info';
Expand Down

0 comments on commit 3b4db23

Please sign in to comment.