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

Switch from an initializer to manual extendResolver usage #186

Merged
merged 5 commits into from
Sep 23, 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
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 {
mkszepp marked this conversation as resolved.
Show resolved Hide resolved
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