Skip to content

Commit

Permalink
Rollback using @embroider/macros
Browse files Browse the repository at this point in the history
We can't bump `@embroider/macros` beyond 0.41.0 as it requires Node.js v12
and v2 of ember-cli-mirage depends on Node.js 10

using older version of `@embroider/macros` causes issues for users of this addon
hence this PR replaces back usage of `@embroider/macros` with
`require.has()` or `require.entries`
  • Loading branch information
SergeAstapov committed Apr 12, 2022
1 parent 977fc9b commit 1a99702
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 28 deletions.
4 changes: 1 addition & 3 deletions addon-test-support/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import setupMirage from './setup-mirage';
export { setupMirage };

import { dependencySatisfies } from '@embroider/macros';

if (dependencySatisfies('ember-qunit', '*')) {
if (typeof window.QUnit !== 'undefined') {
window.QUnit.config.urlConfig.push({
id: 'mirageLogging',
label: 'Mirage logging',
Expand Down
7 changes: 4 additions & 3 deletions addon/deprecate-reexports.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { deprecate } from '@ember/debug';
import { importSync, isTesting, dependencySatisfies } from '@embroider/macros';
import require from 'require';
import Ember from 'ember';
import * as mirage from 'miragejs';
import * as ecMirageExports from './index';

Expand All @@ -15,8 +16,8 @@ export function initDeprecatedReExports() {
// eslint-disable-next-line no-import-assign
Object.defineProperty(ecMirageExports, name, {
get() {
if (isTesting() && dependencySatisfies('ember-qunit', '*')) {
const { waitUntil, getContext } = importSync('@ember/test-helpers');
if (require.has('ember-qunit')) {
const { waitUntil, getContext } = require('@ember/test-helpers');

window.QUnit.begin(function () {
// Make sure deprecation message does not get "swallowed"
Expand Down
6 changes: 3 additions & 3 deletions addon/get-rfc232-test-context.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { importSync, dependencySatisfies, isTesting } from '@embroider/macros';
import require from 'require';

/**
Helper to get our rfc232/rfc268 test context object, or null if we're not in
Expand All @@ -10,8 +10,8 @@ export default function getRfc232TestContext() {
// Support older versions of `ember-qunit` that don't have
// `@ember/test-helpers` (and therefore cannot possibly be running an
// rfc232/rfc268 test).
if (dependencySatisfies('@ember/test-helpers', '*') && isTesting()) {
let { getContext } = importSync('@ember/test-helpers');
if (require.has('@ember/test-helpers')) {
let { getContext } = require('@ember/test-helpers');
return getContext();
}
}
13 changes: 11 additions & 2 deletions addon/utils/ember-data.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import { dependencySatisfies } from '@embroider/macros';
/* global requirejs */

function _hasEmberData() {
let matchRegex1 = /^ember-data/i;
let matchRegex2 = /^@ember-data/i;

return !!Object.keys(requirejs.entries).find(
(e) => !!e.match(matchRegex2) || !!e.match(matchRegex1)
);
}

/**
@hide
*/
export const hasEmberData = dependencySatisfies('ember-data', '*');
export const hasEmberData = _hasEmberData();

/**
@hide
Expand Down
18 changes: 1 addition & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"prepare": "./scripts/link.sh"
},
"dependencies": {
"@embroider/macros": "^0.41.0",
"broccoli-file-creator": "^2.1.1",
"broccoli-funnel": "^3.0.3",
"broccoli-merge-trees": "^4.2.0",
Expand All @@ -52,26 +51,11 @@
"lodash-es": "^4.17.11",
"miragejs": "^0.1.43"
},
"peerDependencies": {
"@ember/test-helpers": "*",
"ember-data": "*",
"ember-qunit": "*"
},
"peerDependenciesMeta": {
"@ember/test-helpers": {
"optional": true
},
"ember-data": {
"optional": true
},
"ember-qunit": {
"optional": true
}
},
"devDependencies": {
"@ember/jquery": "^2.0.0",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.6.0",
"@embroider/macros": "^0.41.0",
"@embroider/test-setup": "^0.41.0",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
Expand Down

0 comments on commit 1a99702

Please sign in to comment.