Skip to content

Commit

Permalink
Remove require usage in favor of @embroider/macros
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Aug 19, 2024
1 parent 5aad468 commit 77a8821
Showing 1 changed file with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import type { Resolver } from '@ember/owner';
import ApplicationInstance from '@ember/application/instance';
import Application from '@ember/application';
import EmberObject from '@ember/object';
import {
macroCondition,
importSync,
dependencySatisfies,
} from '@embroider/macros';

import require, { has } from 'require';
import Ember from 'ember';
Expand Down Expand Up @@ -147,14 +152,21 @@ export default function buildRegistry(resolver: Resolver) {

exposeRegistryMethodsWithoutDeprecations(container);

if (has('ember-data/setup-container')) {
// 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'];
setupContainer(owner);
// 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
if (macroCondition(dependencySatisfies('ember-data', '>= 2.3'))) {
// Additionally, this file is deprecated with no replacement for
// removal in ember-data v6.0
// See: ember-data/dist/setup-container
if (macroCondition(dependencySatisfies('ember-data', '< 6.0'))) {
let { default: setupContainer } = importSync(
'ember-data/setup-container'
) as any;
setupContainer(owner);
}
}

return {
Expand Down

0 comments on commit 77a8821

Please sign in to comment.