Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix looking up abilities #176

Merged
merged 6 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ember-can/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
7 changes: 6 additions & 1 deletion ember-can/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions ember-can/src/initializers/setup-ember-can.js
Original file line number Diff line number Diff line change
@@ -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 };
13 changes: 8 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions test-app/app/abilities/post.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Ability } from 'ember-can';

export default class extends Ability {
get canCreate() {
return true;
}
}
7 changes: 7 additions & 0 deletions test-app/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h1>ember-can tests</h1>

{{#if (can "create post")}}
<p id="post-ability">
This only shows up if the ability was loaded.
</p>
{{/if}}
1 change: 1 addition & 0 deletions test-app/config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
Expand Down
2 changes: 1 addition & 1 deletion test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 14 additions & 0 deletions test-app/tests/acceptance/application-test.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
11 changes: 11 additions & 0 deletions test-app/tests/unit/abilities/post-test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});