Skip to content

Commit

Permalink
Declare ember-data as an optional peer and add @embroider/addon-shim
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed May 2, 2023
1 parent c856ac9 commit 76fb057
Show file tree
Hide file tree
Showing 3 changed files with 375 additions and 26 deletions.
8 changes: 8 additions & 0 deletions addon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@
"start": "yarn build:js -w"
},
"peerDependencies": {
"ember-data": ">= 3.2",
"ember-source": "^4.0.0 || >= 5.0.0"
},
"peerDependenciesMeta": {
"ember-data": {
"optional": true
}
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"@ember/test-waiters": "^3.0.2",
"@embroider/addon-shim": "^1.8.4",
"@embroider/macros": "^1.10.0",
"@embroider/util": "^1.9.0"
},
Expand All @@ -63,6 +70,7 @@
"@typescript-eslint/parser": "^4.33.0",
"concurrently": "^7.6.0",
"documentation": "^14.0.1",
"ember-data": "^4.12.0",
"ember-source": "~4.9.2",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.6.0",
Expand Down
12 changes: 9 additions & 3 deletions addon/src/-internal/build-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ import ApplicationInstance from '@ember/application/instance';
import Application from '@ember/application';
import EmberObject from '@ember/object';

import require, { has } from 'require';
import Ember from 'ember';
import {
dependencySatisfies,
importSync,
macroCondition,
} from '@embroider/macros';

/**
* Adds methods that are normally only on registry to the container. This is largely to support the legacy APIs
Expand Down Expand Up @@ -116,13 +120,15 @@ export default function (resolver: Resolver) {

exposeRegistryMethodsWithoutDeprecations(container);

if (has('ember-data/setup-container')) {
if (macroCondition(dependencySatisfies('ember-data', '>= 2.3.0'))) {
// ember-data is a proper ember-cli addon since 2.3; if no 'import
// 'ember-data'' is present somewhere in the tests, there is also no `DS`
// available on the globalContext and hence ember-data wouldn't be setup
// correctly for the tests; that's why we import and call setupContainer
// here; also see https://github.com/emberjs/data/issues/4071 for context
let setupContainer = require('ember-data/setup-container')['default'];
let setupContainer = (importSync('ember-data/setup-container') as any)[
'default'
];
setupContainer(registry || container);
}

Expand Down
Loading

0 comments on commit 76fb057

Please sign in to comment.