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

feat: add guard for unsupported versions #86

Merged
merged 6 commits into from
Nov 15, 2023
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x
cache: yarn

- name: Install Dependencies
Expand All @@ -48,7 +48,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x
cache: yarn

- name: Install Dependencies
Expand Down Expand Up @@ -86,12 +86,12 @@ jobs:
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x
cache: yarn

- name: Install Dependencies
run: until yarn install --frozen-lockfile; do echo "Retrying yarn"; done

- name: Run Tests
run: ./node_modules/.bin/ember try:one ${{ matrix.try-scenario }}
working-directory: test-app
working-directory: test-app
11 changes: 6 additions & 5 deletions ember-engines-router-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"start": "rollup --config --watch"
},
"dependencies": {
"@embroider/addon-shim": "^1.8.4"
"@embroider/addon-shim": "^1.8.4",
"@embroider/macros": "^1.13.2"
},
"devDependencies": {
"@babel/core": "^7.20.7",
Expand All @@ -55,8 +56,11 @@
"prettier": "^2.8.1",
"rollup": "^3.8.1"
},
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0"
},
"engines": {
"node": "14.* || 16.* || >= 18"
"node": "16.* || 18.* || >= 20"
},
"publishConfig": {
"registry": "https://registry.npmjs.org"
Expand Down Expand Up @@ -85,8 +89,5 @@
"./initializers/ember-engines-router-service.js": "./dist/_app_/initializers/ember-engines-router-service.js",
"./services/engine-router-service.js": "./dist/_app_/services/engine-router-service.js"
}
},
"volta": {
"extends": "../package.json"
}
}
34 changes: 23 additions & 11 deletions ember-engines-router-service/src/services/engine-router-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { action, computed } from '@ember/object';
import { reads } from '@ember/object/computed';
import { getOwner } from '@ember/application';
import Evented from '@ember/object/evented';
import { macroCondition, dependencySatisfies } from '@embroider/macros';
import { namespaceEngineRouteName } from '../utils/namespace-engine-route-name';
import { getRootOwner } from '../utils/root-owner';
import { resemblesURL } from '../utils/resembles-url';

const warningMessage =
'Refresh method is not available in ember-source below v4.1';

export default class EngineRouterService extends Service.extend(Evented) {
constructor(...args) {
super(...args);
Expand Down Expand Up @@ -66,21 +70,29 @@ export default class EngineRouterService extends Service.extend(Evented) {
}

refresh(routeName = this.currentRouteName, ...args) {
if (resemblesURL(routeName)) {
return this.externalRouter.refresh(routeName);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
if (resemblesURL(routeName)) {
return this.externalRouter.refresh(routeName);
}

return this.externalRouter.refresh(
namespaceEngineRouteName(this._mountPoint, routeName),
...args
);
} else {
assert(warningMessage);
}

return this.externalRouter.refresh(
namespaceEngineRouteName(this._mountPoint, routeName),
...args
);
}

refreshExternal(routeName, ...args) {
return this.externalRouter.refresh(
this.getExternalRouteName(routeName),
...args
);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
return this.externalRouter.refresh(
this.getExternalRouteName(routeName),
...args
);
} else {
assert(warningMessage);
}
}

transitionTo(routeName, ...args) {
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,5 @@
},
"npm": false
},
"volta": {
"node": "14.21.2",
"yarn": "1.22.19"
}
"packageManager": "[email protected]"
}
7 changes: 3 additions & 4 deletions test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
"@babel/eslint-parser": "^7.19.1",
"@ember/legacy-built-in-components": "0.4.1",
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.1.1",
"@ember/test-helpers": "^2.9.3",
"@embroider/macros": "^1.13.2",
"@embroider/test-setup": "^2.0.2",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
Expand Down Expand Up @@ -75,12 +77,9 @@
"webpack": "^5.75.0"
},
"engines": {
"node": "14.* || 16.* || >= 18"
"node": "16.* || 18.* || >= 20"
},
"ember": {
"edition": "octane"
},
"volta": {
"extends": "../package.json"
}
}
67 changes: 37 additions & 30 deletions test-app/tests/acceptance/routeable-engine-demo-refresh-test.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,50 @@
import { module, test } from 'qunit';
import { setupApplicationTest } from 'ember-qunit';
import { visit, find, click } from '@ember/test-helpers';
import { macroCondition, dependencySatisfies } from '@embroider/macros';

module('Acceptance | Engine Router Service | Refresh Method', function (hooks) {
setupApplicationTest(hooks);
if (macroCondition(dependencySatisfies('ember-source', '>= 4.1.0'))) {
module(
'Acceptance | Engine Router Service | Refresh Method',
function (hooks) {
setupApplicationTest(hooks);

test('refresh without params triggers refresh with current route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');
test('refresh without params triggers refresh with current route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh');
let counter = await find('.route-refresh-counter').textContent;

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
});
await click('.refresh');

test('refresh with params triggers refresh on provided route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');
counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
});

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-route');
test('refresh with params triggers refresh on provided route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
});
let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-route');

test('refresh external route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');
counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.route-refresh-counter').hasText(counter);
});

let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-external');
test('refresh external route', async function (assert) {
await visit('/routable-engine-demo/ember-blog/new');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.global-refresh-counter').hasText(counter);
});
});
let counter = await find('.route-refresh-counter').textContent;
await click('.refresh-external');

counter = parseInt(counter, 10);
counter = ++counter;
counter = counter.toString();
assert.dom('.global-refresh-counter').hasText(counter);
});
}
);
}
Loading