Skip to content

Commit

Permalink
Switch from an initializer to manual extendResolver usage (#186)
Browse files Browse the repository at this point in the history
* Add support for ember-resolver v13

* Update README.md (provide full example)

* Update README.md

* Make changes braking & update readme

* Update README.md

---------

Co-authored-by: Robbie Wagner <rwwagner90@gmail.com>
  • Loading branch information
mkszepp and RobbieTheWagner authored Sep 23, 2024
1 parent 7a58baa commit 8feb0c2
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 127 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ jobs:
- ember-lts-4.12
- ember-lts-5.4
- ember-lts-5.8
- ember-resolver-12
- ember-release
- ember-beta
- ember-canary
Expand Down
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ Install this addon via ember-cli:
ember install ember-can
```

After installation you will need to add the following import to your app.js or app.ts:

```js
import { extendResolver } from 'ember-can';
```

Next, replace `Resolver = Resolver;` with:

```js
Resolver = extendResolver(Resolver);
```

Without this update, the app will encounter an error where it cannot find your abilities.

After these changes your app file should look something like:
```js
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'my-app/config/environment';
import { extendResolver } from 'ember-can';

export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = extendResolver(Resolver);
}

loadInitializers(App, config.modulePrefix);
```


## Compatibility

* Ember.js v3.28 or above
Expand Down
3 changes: 1 addition & 2 deletions ember-can/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"babel-plugin-ember-template-compilation": "^2.2.5",
"concurrently": "^8.2.2",
"ember-inflector": "^5.0.1",
"ember-resolver": "^12.0.1",
"ember-resolver": "^13.0.1",
"ember-source": "^5.8.0",
"ember-template-lint": "^6.0.0",
"eslint": "^8.56.0",
Expand Down Expand Up @@ -121,7 +121,6 @@
"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"
}
},
Expand Down
7 changes: 1 addition & 6 deletions ember-can/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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 @@ -31,11 +30,7 @@ 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',
'initializers/**/*.js',
'services/**/*.js',
]),
addon.appReexports(['helpers/**/*.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
12 changes: 12 additions & 0 deletions ember-can/src/-private/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type Resolver from 'ember-resolver';

export default function extendResolver(
resolver: typeof Resolver,
): typeof Resolver {
return class EmberCanResolver extends resolver {
pluralizedTypes: Record<string, string> = {
...this.pluralizedTypes,
ability: 'abilities',
};
};
}
3 changes: 2 additions & 1 deletion ember-can/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Ability from './ability.ts';
import extendResolver from './-private/resolver.ts';

export { Ability };
export { Ability, extendResolver };
14 changes: 0 additions & 14 deletions ember-can/src/initializers/setup-ember-can.js

This file was deleted.

Loading

0 comments on commit 8feb0c2

Please sign in to comment.