Skip to content

Commit b673008

Browse files
committed
Base implementation
1 parent 4214f2c commit b673008

6 files changed

Lines changed: 67 additions & 7 deletions

File tree

eslint.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default [
1010
'@typescript-eslint/unbound-method': 'off',
1111
'@typescript-eslint/no-unsafe-member-access': 'off',
1212
'@typescript-eslint/no-unsafe-assignment': 'off',
13+
'@typescript-eslint/no-unsafe-argument': 'off',
1314
},
1415
},
1516
];

src/index.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
import EmberApplication from '@ember/application';
22
import { StrictResolver } from './strict-resolver.ts';
33

4-
export class Application extends EmberApplication {
4+
export default class EmberApp extends EmberApplication {
5+
Resolver = {
6+
create: ({
7+
namespace,
8+
}: {
9+
namespace: {
10+
modules: Record<string, Record<string, unknown>>;
11+
plurals?: Record<string, string>;
12+
};
13+
}) => {
14+
const resolver = new StrictResolver(namespace.modules, namespace.plurals);
15+
16+
return resolver;
17+
},
18+
};
19+
520
/**
621
Set this to opt-in to using a strict resolver that will only return the
722
given set of ES modules. The names of the modules should all be relative to

src/strict-resolver.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ export class StrictResolver implements Resolver {
44
#modules = new Map<string, Record<string, unknown>>();
55
#plurals = new Map<string, string>();
66
original: any;
7+
8+
static create(...args: any[]) {
9+
new StrictResolver(...args);
10+
}
11+
712
constructor(
813
modules: Record<string, Record<string, unknown>>,
914
plurals: Record<string, string> | undefined = undefined,

tests/registry-test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { module, test } from 'qunit';
2+
import { setupTest } from 'ember-qunit';
3+
4+
module('Registry', function (hooks) {
5+
setupTest(hooks);
6+
7+
test('has the router', function (assert) {
8+
// eslint-disable-next-line ember/no-private-routing-service
9+
const router = this.owner.lookup('router:main');
10+
11+
assert.ok(router);
12+
});
13+
14+
test('has a manually registered service', function (assert) {
15+
const manual = this.owner.lookup('service:manual') as { weDidIt: boolean };
16+
17+
assert.ok(manual);
18+
assert.ok(manual.weDidIt);
19+
});
20+
21+
test('has a service from import.meta.glob', function (assert) {
22+
const metaGlob = this.owner.lookup('service:from-meta-glob') as {
23+
weDidIt: boolean;
24+
};
25+
26+
assert.ok(metaGlob);
27+
assert.ok(metaGlob.weDidIt);
28+
});
29+
});

tests/services/from-meta-glob.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Service from '@ember/service';
2+
3+
export default class FromMetaGlob extends Service {
4+
weDidIt = true;
5+
}

tests/test-helper.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import EmberApp from '@ember/application';
2-
import Resolver from 'ember-resolver';
1+
import EmberApp from '#src/index.ts';
2+
import Service from '@ember/service';
33
import EmberRouter from '@ember/routing/router';
44
import * as QUnit from 'qunit';
55
import { setApplication } from '@ember/test-helpers';
66
import { setup } from 'qunit-dom';
77
import { start as qunitStart, setupEmberOnerrorValidation } from 'ember-qunit';
88

9+
class Manual extends Service {
10+
weDidIt = true;
11+
}
12+
913
class Router extends EmberRouter {
1014
location = 'none';
1115
rootURL = '/';
1216
}
1317

1418
class TestApp extends EmberApp {
1519
modulePrefix = 'test-app';
16-
Resolver = Resolver.withModules({
17-
'test-app/router': { default: Router },
18-
// add any custom services here
19-
});
20+
modules = {
21+
'./router': { default: Router },
22+
'./services/manual': { default: Manual },
23+
...import.meta.glob('./services/*', { eager: true }),
24+
};
2025
}
2126

2227
Router.map(function () {});

0 commit comments

Comments
 (0)