diff --git a/ember-can/package.json b/ember-can/package.json index 02e21a6..af38513 100644 --- a/ember-can/package.json +++ b/ember-can/package.json @@ -91,6 +91,7 @@ "@typescript-eslint/parser": "^7.8.0", "babel-plugin-ember-template-compilation": "^2.2.5", "concurrently": "^8.2.2", + "ember-resolver": "^12.0.1", "ember-source": "^5.8.0", "ember-template-lint": "^6.0.0", "eslint": "^8.56.0", @@ -120,11 +121,13 @@ "app-js": { "./helpers/can.js": "./dist/_app_/helpers/can.js", "./helpers/cannot.js": "./dist/_app_/helpers/cannot.js", + "./initializers/setup-ember-can.js": "./dist/_app_/initializers/setup-ember-can.js", "./services/abilities.js": "./dist/_app_/services/abilities.js" } }, "peerDependencies": { "@ember/string": "^3.1.1", - "ember-source": "^3.28.0 || ^4.0.0 || >=5.0.0" + "ember-source": "^3.28.0 || ^4.0.0 || >=5.0.0", + "ember-resolver": ">= 8.0.0" } } diff --git a/ember-can/rollup.config.mjs b/ember-can/rollup.config.mjs index 80c5f04..2efaac2 100644 --- a/ember-can/rollup.config.mjs +++ b/ember-can/rollup.config.mjs @@ -21,6 +21,7 @@ export default { // is aligned to the config here. // See https://github.com/embroider-build/embroider/blob/main/docs/v2-faq.md#how-can-i-define-the-public-exports-of-my-addon addon.publicEntrypoints([ + 'initializers/**/*.js', 'index.js', 'ability.ts', 'helpers/**/*.js', @@ -30,7 +31,11 @@ export default { // These are the modules that should get reexported into the traditional // "app" tree. Things in here should also be in publicEntrypoints above, but // not everything in publicEntrypoints necessarily needs to go here. - addon.appReexports(['helpers/**/*.js', 'services/**/*.js']), + addon.appReexports([ + 'helpers/**/*.js', + 'initializers/**/*.js', + 'services/**/*.js', + ]), // Follow the V2 Addon rules about dependencies. Your code can import from // `dependencies` and `peerDependencies` as well as standard Ember-provided diff --git a/ember-can/src/initializers/setup-ember-can.js b/ember-can/src/initializers/setup-ember-can.js new file mode 100644 index 0000000..c94d232 --- /dev/null +++ b/ember-can/src/initializers/setup-ember-can.js @@ -0,0 +1,14 @@ +import Resolver from 'ember-resolver'; + +Resolver.reopen({ + init() { + this._super(); + this.pluralizedTypes = { + ...this.pluralizedTypes, + ability: 'abilities', + }; + }, +}); + +export function initialize() {} +export default { initialize }; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 58107c3..3738c88 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -153,6 +153,9 @@ importers: concurrently: specifier: ^8.2.2 version: 8.2.2 + ember-resolver: + specifier: ^12.0.1 + version: 12.0.1(ember-source@5.8.0) ember-source: specifier: ^5.8.0 version: 5.8.0(@babel/core@7.24.5)(@glimmer/component@1.1.2)(@glint/template@1.4.0)(rsvp@4.8.5)(webpack@5.91.0) @@ -362,8 +365,8 @@ importers: specifier: ^8.0.2 version: 8.0.2(@ember/test-helpers@3.3.0)(@glint/template@1.4.0)(ember-source@5.8.0)(qunit@2.20.1) ember-resolver: - specifier: ^11.0.1 - version: 11.0.1(ember-source@5.8.0) + specifier: ^12.0.1 + version: 12.0.1(ember-source@5.8.0) ember-source: specifier: ~5.8.0 version: 5.8.0(@babel/core@7.24.5)(@glimmer/component@1.1.2)(@glint/template@1.4.0)(rsvp@4.8.5)(webpack@5.91.0) @@ -7015,11 +7018,11 @@ packages: - supports-color dev: true - /ember-resolver@11.0.1(ember-source@5.8.0): - resolution: {integrity: sha512-ucBk3oM+PR+AfYoSUXeQh8cDQS1sSiEKp4Pcgbew5cFMSqPxJfqd1zyZsfQKNTuyubeGmWxBOyMVSTvX2LeCyg==} + /ember-resolver@12.0.1(ember-source@5.8.0): + resolution: {integrity: sha512-U+ZBdbEHMhmvcZly1xhZKwqeH5/igjT93p9bbD6x+mQVg7hm4jrsQA4jsxHu3BqgL5MmqOVx0gtAuYEWV1x2MQ==} engines: {node: 14.* || 16.* || >= 18} peerDependencies: - ember-source: ^4.8.3 || >= 5.0.0 + ember-source: ^4.12.0 || >= 5.0.0 peerDependenciesMeta: ember-source: optional: true diff --git a/test-app/app/abilities/post.ts b/test-app/app/abilities/post.ts new file mode 100644 index 0000000..208117b --- /dev/null +++ b/test-app/app/abilities/post.ts @@ -0,0 +1,7 @@ +import { Ability } from 'ember-can'; + +export default class extends Ability { + get canCreate() { + return true; + } +} diff --git a/test-app/app/templates/application.hbs b/test-app/app/templates/application.hbs new file mode 100644 index 0000000..433b242 --- /dev/null +++ b/test-app/app/templates/application.hbs @@ -0,0 +1,7 @@ +

ember-can tests

+ +{{#if (can "create post")}} +

+ This only shows up if the ability was loaded. +

+{{/if}} \ No newline at end of file diff --git a/test-app/config/ember-try.js b/test-app/config/ember-try.js index a824cc6..768503b 100644 --- a/test-app/config/ember-try.js +++ b/test-app/config/ember-try.js @@ -32,6 +32,7 @@ module.exports = async function () { name: 'ember-lts-4.8', npm: { devDependencies: { + 'ember-resolver': '^11.0.0', 'ember-source': '~4.8.0', }, }, diff --git a/test-app/package.json b/test-app/package.json index f58ab89..cbcef40 100644 --- a/test-app/package.json +++ b/test-app/package.json @@ -78,7 +78,7 @@ "ember-modifier": "^4.1.0", "ember-page-title": "^8.2.3", "ember-qunit": "^8.0.2", - "ember-resolver": "^11.0.1", + "ember-resolver": "^12.0.1", "ember-source": "~5.8.0", "ember-source-channel-url": "^3.0.0", "ember-template-lint": "^6.0.0", diff --git a/test-app/tests/acceptance/application-test.ts b/test-app/tests/acceptance/application-test.ts new file mode 100644 index 0000000..f47932e --- /dev/null +++ b/test-app/tests/acceptance/application-test.ts @@ -0,0 +1,14 @@ +import { module, test } from 'qunit'; +import { visit, currentURL } from '@ember/test-helpers'; +import { setupApplicationTest } from 'test-app/tests/helpers'; + +module('Acceptance | application', function (hooks) { + setupApplicationTest(hooks); + + test('visiting /', async function (assert) { + await visit('/'); + + assert.strictEqual(currentURL(), '/'); + assert.dom('#post-ability').exists(); + }); +}); diff --git a/test-app/tests/unit/abilities/post-test.ts b/test-app/tests/unit/abilities/post-test.ts new file mode 100644 index 0000000..e3af88a --- /dev/null +++ b/test-app/tests/unit/abilities/post-test.ts @@ -0,0 +1,11 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module('Unit | Ability | post', function (hooks) { + setupTest(hooks); + + test('it exists', function (assert) { + const ability = this.owner.lookup('ability:post'); + assert.ok(ability); + }); +});