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

@embroider/router Ember 4 CI job compatibility #1027

Merged
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
1 change: 0 additions & 1 deletion packages/router/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

root = true


[*]
end_of_line = lf
charset = utf-8
Expand Down
2 changes: 2 additions & 0 deletions packages/router/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# misc
/coverage/
!.*
.*/
.eslintcache

# ember-try
/.node_modules.ember-try/
Expand Down
45 changes: 31 additions & 14 deletions packages/router/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
'use strict';

module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: ['eslint:recommended', 'plugin:ember/recommended'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
Expand All @@ -15,28 +24,36 @@ module.exports = {
// node files
{
files: [
'.eslintrc.js',
'.template-lintrc.js',
'ember-cli-build.js',
'index.js',
'testem.js',
'blueprints/*/index.js',
'config/**/*.js',
'tests/dummy/config/**/*.js',
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
],
excludedFiles: [
'addon/**',
'addon-test-support/**',
'app/**',
'tests/dummy/app/**',
],
excludedFiles: ['addon/**', 'addon-test-support/**', 'app/**', 'tests/dummy/app/**'],
parserOptions: {
sourceType: 'script',
ecmaVersion: 2015,
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, {
// add your custom rules and overrides for node files here
}),
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
1 change: 1 addition & 0 deletions packages/router/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
Expand Down
5 changes: 5 additions & 0 deletions packages/router/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
/.editorconfig
/.ember-cli
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.prettierignore
/.prettierrc.js
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
Expand All @@ -22,6 +26,7 @@
/ember-cli-build.js
/testem.js
/tests/
/yarn-error.log
/yarn.lock
.gitkeep

Expand Down
21 changes: 21 additions & 0 deletions packages/router/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# unconventional js
/blueprints/*/files/
/vendor/

# compiled output
/dist/
/tmp/

# dependencies
/bower_components/
/node_modules/

# misc
/coverage/
!.*
.eslintcache

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
5 changes: 5 additions & 0 deletions packages/router/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
singleQuote: true,
};
2 changes: 1 addition & 1 deletion packages/router/.template-lintrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';

module.exports = {
extends: 'recommended'
extends: 'recommended',
};
36 changes: 16 additions & 20 deletions packages/router/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ language: node_js
node_js:
# we recommend testing addons with the same minimum supported node version as Ember CLI
# so that your addon works for all apps
- "8"
- '12'

sudo: false
dist: trusty
dist: xenial

addons:
chrome: stable
Expand All @@ -26,42 +25,39 @@ branches:
- /^v\d+\.\d+\.\d+/

jobs:
fail_fast: true
fast_finish: false
allow_failures:
- env: EMBER_TRY_SCENARIO=ember-canary

include:
# runs linting and tests with current locked deps

- stage: "Tests"
name: "Tests"
install:
- yarn install --non-interactive
- stage: 'Tests'
name: 'Tests'
script:
- yarn lint:hbs
- yarn lint:js
- yarn test
- yarn lint
- yarn test:ember

- name: "Floating Dependencies"
- stage: 'Additional Tests'
name: 'Floating Dependencies'
install:
- yarn install --no-lockfile --non-interactive
script:
- yarn test
- yarn test:ember

# we recommend new addons test the current and previous LTS
# as well as latest stable release (bonus points to beta/canary)
- stage: "Additional Tests"
env: EMBER_TRY_SCENARIO=ember-lts-2.18
- env: EMBER_TRY_SCENARIO=ember-lts-3.4
- env: EMBER_TRY_SCENARIO=ember-lts-3.16
- env: EMBER_TRY_SCENARIO=ember-lts-3.20
- env: EMBER_TRY_SCENARIO=ember-lts-3.24
- env: EMBER_TRY_SCENARIO=ember-release
- env: EMBER_TRY_SCENARIO=ember-beta
- env: EMBER_TRY_SCENARIO=ember-canary
- env: EMBER_TRY_SCENARIO=ember-default-with-jquery
- env: EMBER_TRY_SCENARIO=ember-classic

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH

install:
- yarn install --no-lockfile --non-interactive

script:
- node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO
23 changes: 11 additions & 12 deletions packages/router/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@

## Installation

* `git clone <repository-url>`
* `cd @embroider/router`
* `yarn install`
- `git clone <repository-url>`
- `cd @embroider/router`
- `yarn install`

## Linting

* `yarn lint:hbs`
* `yarn lint:js`
* `yarn lint:js --fix`
- `yarn lint`
- `yarn lint:fix`

## Running tests

* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
- `ember test` – Runs the test suite on the current Ember version
- `ember test --server` – Runs the test suite in "watch mode"
- `ember try:each` – Runs the test suite against multiple Ember versions

## Running the dummy application

* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
- `ember serve`
- Visit the dummy application at [http://localhost:4200](http://localhost:4200).

For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
4 changes: 4 additions & 0 deletions packages/router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ of lazy route bundles and loads them when needed.

## Compatibility

- Ember.js v3.16 or above
- Ember CLI v3.16 or above
- Node.js v12 or above

To get code-splitting, your app must build with Embroider. It's safe to use
this router in apps that aren't building with Embroider, but it won't do
anything.
Expand Down
31 changes: 19 additions & 12 deletions packages/router/addon/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable ember/no-private-routing-service */
/*
This code is adapted from ember-engines/addon/-private/router-ext.js.
*/
Expand All @@ -23,17 +24,21 @@ if (macroCondition(getGlobalConfig()['@embroider/core']?.active)) {
// mappings from routeName to the engines "original name" (which we know at build time).
let engine = engineInfoByRoute[routeName];
if (engine && window._embroiderEngineBundles_) {
return window._embroiderEngineBundles_.find(bundle => bundle.names.indexOf(engine.name) !== -1);
return window._embroiderEngineBundles_.find(
(bundle) => bundle.names.indexOf(engine.name) !== -1
);
}

if (window._embroiderRouteBundles_) {
return window._embroiderRouteBundles_.find(bundle => bundle.names.indexOf(routeName) !== -1);
return window._embroiderRouteBundles_.find(
(bundle) => bundle.names.indexOf(routeName) !== -1
);
}

return false;
};

Router = EmberRouter.extend({
class EmbroiderRouter extends EmberRouter {
// This is necessary in order to prevent the premature loading of lazy routes
// when we are merely trying to render a link-to that points at them.
// Unfortunately the stock query parameter behavior pulls on routes just to
Expand All @@ -43,20 +48,20 @@ if (macroCondition(getGlobalConfig()['@embroider/core']?.active)) {
if (bundle && !bundle.loaded) {
return undefined;
}
return this._super(...arguments);
},
return super._getQPMeta(...arguments);
}

// On older versions of Ember, this is a framework method that we're
// overriding to provide our own handlerResolver.
_getHandlerFunction() {
newSetup = false;
return this._handlerResolver();
},
}

// On newer versions of Ember, this is the framework method that we're
// overriding to provide our own handlerResolver.
setupRouter() {
let isSetup = this._super(...arguments);
let isSetup = super.setupRouter(...arguments);
if (newSetup) {
// Different versions of routerMicrolib use the names `getRoute` vs
// `getHandler`.
Expand All @@ -71,10 +76,10 @@ if (macroCondition(getGlobalConfig()['@embroider/core']?.active)) {
}
}
return isSetup;
},
}

_handlerResolver(original) {
return name => {
return (name) => {
let bundle = lazyBundle(name, this._engineInfoByRoute);
if (!bundle || bundle.loaded) {
return original(name);
Expand All @@ -88,14 +93,16 @@ if (macroCondition(getGlobalConfig()['@embroider/core']?.active)) {
bundle.loaded = true;
return original(name);
},
err => {
(err) => {
waiter.endAsync(token);
throw err;
}
);
};
},
});
}
}

Router = EmbroiderRouter;
} else {
Router = EmberRouter;
}
Expand Down
Loading