diff --git a/packages/@ember/service/index.ts b/packages/@ember/service/index.ts index 5ae8075f5a0..b4946c341b3 100644 --- a/packages/@ember/service/index.ts +++ b/packages/@ember/service/index.ts @@ -1,3 +1,4 @@ +import { deprecate } from '@ember/debug'; import { FrameworkObject } from '@ember/object/-internals'; import type { DecoratorPropertyDescriptor, ElementDescriptor } from '@ember/-internals/metal'; import { inject as metalInject } from '@ember/-internals/metal'; @@ -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; @@ -24,6 +26,21 @@ export function inject(): PropertyDecorator; export function inject( ...args: [] | [name: string] | ElementDescriptor ): PropertyDecorator | DecoratorPropertyDescriptor | void { + deprecate( + 'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.', + false, + { + for: 'ember-source', + id: 'importing-inject-from-ember-service', + since: { + available: '5.4.0', + enabled: '5.4.0', + }, + until: '6.0.0', + url: 'TODO', + } + ); + return metalInject('service', ...args); } diff --git a/packages/@ember/service/tests/service_test.js b/packages/@ember/service/tests/service_test.js index 0bc2aac7ee4..559431a22f1 100644 --- a/packages/@ember/service/tests/service_test.js +++ b/packages/@ember/service/tests/service_test.js @@ -1,47 +1,51 @@ 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, expectDeprecation } from 'internal-test-helpers'; moduleFor( 'inject - decorator', class extends AbstractTestCase { ['@test works with native decorators'](assert) { - let owner = buildOwner(); + expectDeprecation(() => { + let owner = buildOwner(); - class MainService extends Service {} + class MainService extends Service {} - class Foo extends EmberObject { - @inject('main') main; - } + class Foo extends EmberObject { + @inject('main') main; + } - owner.register('service:main', MainService); - owner.register('foo:main', Foo); + owner.register('service:main', MainService); + owner.register('foo:main', Foo); - let foo = owner.lookup('foo:main'); + let foo = owner.lookup('foo:main'); - assert.ok(foo.main instanceof Service, 'service injected correctly'); + assert.ok(foo.main instanceof Service, 'service injected correctly'); - runDestroy(owner); + runDestroy(owner); + }, 'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.'); } ['@test uses the decorated property key if not provided'](assert) { - let owner = buildOwner(); + expectDeprecation(() => { + let owner = buildOwner(); - class MainService extends Service {} + class MainService extends Service {} - class Foo extends EmberObject { - @inject main; - } + class Foo extends EmberObject { + @inject main; + } - owner.register('service:main', MainService); - owner.register('foo:main', Foo); + owner.register('service:main', MainService); + owner.register('foo:main', Foo); - let foo = owner.lookup('foo:main'); + let foo = owner.lookup('foo:main'); - assert.ok(foo.main instanceof Service, 'service injected correctly'); + assert.ok(foo.main instanceof Service, 'service injected correctly'); - runDestroy(owner); + runDestroy(owner); + }, 'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.'); } } ); diff --git a/packages/@ember/service/tests/service_ts_test.ts b/packages/@ember/service/tests/service_ts_test.ts index fa36782b953..d23e5c90e2e 100644 --- a/packages/@ember/service/tests/service_ts_test.ts +++ b/packages/@ember/service/tests/service_ts_test.ts @@ -1,47 +1,51 @@ 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, expectDeprecation } from 'internal-test-helpers'; moduleFor( 'inject - decorator (TS)', class extends AbstractTestCase { ['@test works with native decorators'](assert: QUnit['assert']) { - let owner = buildOwner(); + expectDeprecation(() => { + let owner = buildOwner(); - class MainService extends Service {} + class MainService extends Service {} - class Foo extends EmberObject { - @inject('main') declare main: MainService; - } + class Foo extends EmberObject { + @inject('main') declare main: MainService; + } - owner.register('service:main', MainService); - owner.register('foo:main', Foo); + owner.register('service:main', MainService); + owner.register('foo:main', Foo); - let foo = owner.lookup('foo:main') as Foo; + let foo = owner.lookup('foo:main') as Foo; - assert.ok(foo.main instanceof Service, 'service injected correctly'); + assert.ok(foo.main instanceof Service, 'service injected correctly'); - runDestroy(owner); + runDestroy(owner); + }, 'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.'); } ['@test uses the decorated property key if not provided'](assert: QUnit['assert']) { - let owner = buildOwner(); + expectDeprecation(() => { + let owner = buildOwner(); - class MainService extends Service {} + class MainService extends Service {} - class Foo extends EmberObject { - @inject declare main: MainService; - } + class Foo extends EmberObject { + @inject declare main: MainService; + } - owner.register('service:main', MainService); - owner.register('foo:main', Foo); + owner.register('service:main', MainService); + owner.register('foo:main', Foo); - let foo = owner.lookup('foo:main') as Foo; + let foo = owner.lookup('foo:main') as Foo; - assert.ok(foo.main instanceof Service, 'service injected correctly'); + assert.ok(foo.main instanceof Service, 'service injected correctly'); - runDestroy(owner); + runDestroy(owner); + }, 'Importing `inject` from `@ember/service` is deprecated. Please import `service` instead.'); } } ); diff --git a/type-tests/@ember/routing-test/router.ts b/type-tests/@ember/routing-test/router.ts index 940f538e3b2..2a5818782aa 100755 --- a/type-tests/@ember/routing-test/router.ts +++ b/type-tests/@ember/routing-test/router.ts @@ -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';