Skip to content

Commit

Permalink
Upgrade Ember.js from v3.28.3 to v4.10.0 (#103)
Browse files Browse the repository at this point in the history
* build: upgrade Ember.js from v3.28.3 to v4.10.0

* refactor: use buil-in tests setup wrappers

* refactor: standardise helper & fix types checks

- Standardise helper's function signature and body
  To match what is generated by default when creating a new helper.

- Fix types errors provided by implicit TypeScript checks
  This will help whenever the project is migrated to TS

* test: fix test, add required Webpack polyfills

What was done and why:

- After the `stream` module, the modules `util` and `process` had to be
  added to the dependencies as well in order to satisfy Webpack v5 which
  does not include polyfills anymore, otherwise tests were failing.
  - https://webpack.js.org/migrate/5/
  - https://webpack.js.org/configuration/resolve/#resolvefallback
  - https://github.com/ef4/ember-auto-import/blob/v2.6.0/docs/upgrade-guide-2.0.md
  - https://gist.github.com/ef4/d2cf5672a93cf241fd47c020b9b3066a

  For the `process` module, adding it to the `fallback` key was not
  working, it had to be included in the `plugins` key:
  - https://stackoverflow.com/questions/65018431/webpack-5-uncaught-referenceerror-process-is-not-defined/65018686#65018686
  - https://discord.com/channels/480462759797063690/898671957007011841/898682272847384596
    Overall, these messages on Discord give the entire final solution in
    this commit.

- `wepack` moved to the dependencies because otherwise `eslint-plugin-n`
  was returning the error:

  ```
  "webpack" is not published.eslintn/no-unpublished-require
  ```

  See:
  - https://github.com/eslint-community/eslint-plugin-n/blob/15.6.1/docs/rules/no-unpublished-require.md
  - mysticatea/eslint-plugin-node#47
  • Loading branch information
MrChocolatine authored Apr 28, 2023
1 parent ab9f7d8 commit d78b6d4
Show file tree
Hide file tree
Showing 24 changed files with 1,746 additions and 2,740 deletions.
8 changes: 7 additions & 1 deletion .ember-cli
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@

Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
"disableAnalytics": true,

/**
Setting `isTypeScriptProject` to true will force the blueprint generators to generate TypeScript
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
*/
"isTypeScriptProject": false
}
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
3 changes: 1 addition & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ module.exports = {
browser: false,
node: true,
},
plugins: ['n'],
extends: ['plugin:n/recommended'],
},
{
// Test files:
// test files
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
node-version: 14
package-manager: yarn
ember-try-scenarios: "[
'ember-lts-3.20',
'ember-lts-3.24',
'ember-lts-3.28',
'ember-lts-4.4',
'ember-release',
'ember-beta',
'ember-canary',
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try

# broccoli-debug
/DEBUG/
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
/coverage/
!.*
.eslintcache
.lint-todo/

# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/npm-shrinkwrap.json.ember-try
/package.json.ember-try
/package-lock.json.ember-try
/yarn.lock.ember-try
9 changes: 8 additions & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
'use strict';

module.exports = {
singleQuote: true,
overrides: [
{
files: '*.{js,ts}',
options: {
singleQuote: true,
},
},
],
};
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
* `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://cli.emberjs.com/release/](https://cli.emberjs.com/release/).
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ Medium-like reading time estimation for EmberJS.

Based on [reading-time](https://github.com/ngryman/reading-time) and [humanized-duration](https://github.com/EvanHahn/HumanizeDuration.js/) libraries.


## Compatibility

* Ember.js v3.20 or above
* Ember CLI v3.20 or above

* Ember.js v3.28 or above
* Ember CLI v3.28 or above
* Node.js v14 or above


## Installation

```
ember install ember-reading-time
```


## Usage

By default, `reading-time` helper will humanize down to the minute and use english as language.
Expand All @@ -28,14 +32,17 @@ By default, `reading-time` helper will humanize down to the minute and use engli
{{reading-time 'My text here' (hash language='ja')}}
```


### Options

All options from `humanize-duration` are available: https://github.com/EvanHahn/HumanizeDuration.js#options


## Contributing

See the [Contributing](CONTRIBUTING.md) guide for details.


## Contributors

<!-- readme: contributors,ember-tomster/- -start -->
Expand Down Expand Up @@ -79,6 +86,7 @@ See the [Contributing](CONTRIBUTING.md) guide for details.
</table>
<!-- readme: contributors,ember-tomster/- -end -->


## License

This project is licensed under the [MIT License](LICENSE.md).
23 changes: 12 additions & 11 deletions addon/helpers/reading-time.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import { helper } from '@ember/component/helper';
import readingTime from 'reading-time';
import humanizeDuration from 'humanize-duration';

export default helper((params /*, hash*/) => {
let stats = readingTime(params[0] ?? '');
let options = params[1];
export default helper(function helperReadingTime(positional /*, named*/) {
const stats = readingTime(String(positional[0]));
const userOptions = positional[1];

const defaultOptions = {
round: true,
/** @type {['m']} */
units: ['m'],
language: 'en',
};

return humanizeDuration(
stats.time < 60000 ? 60000 : stats.time,
Object.assign(
{
round: true,
units: ['m'],
language: 'en',
},
options
)
Object.assign({}, defaultOptions, userOptions)
);
});
5 changes: 0 additions & 5 deletions config/environment.js

This file was deleted.

11 changes: 9 additions & 2 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const { maybeEmbroider } = require('@embroider/test-setup');
const { ProvidePlugin } = require('webpack');

/**
* `EMBROIDER_TEST_SETUP_OPTIONS` is set by the Embroider scenarios for `ember-try`:
Expand All @@ -10,7 +11,7 @@ const { maybeEmbroider } = require('@embroider/test-setup');
const IS_EMBROIDER_ENABLED = Boolean(process.env.EMBROIDER_TEST_SETUP_OPTIONS);

module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
const app = new EmberAddon(defaults, {
// Add options here
});

Expand All @@ -34,10 +35,16 @@ module.exports = function (defaults) {
node: {
global: true,
},
plugins: [
new ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
fallback: {
// `stream-browserify` is added for the Embroider tests, see `config/ember-try.js`.
stream: require.resolve('stream-browserify') // eslint-disable-line
stream: require.resolve('stream-browserify'),
util: require.resolve('util/')
},
},
},
Expand Down
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const { ProvidePlugin } = require('webpack');

module.exports = {
name: require('./package').name,
options: {
Expand All @@ -8,9 +10,15 @@ module.exports = {
node: {
global: true,
},
plugins: [
new ProvidePlugin({
process: 'process/browser',
}),
],
resolve: {
fallback: {
stream: require.resolve('stream-browserify'),
util: require.resolve('util/'),
},
},
},
Expand Down
65 changes: 34 additions & 31 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,65 +30,68 @@
],
"scripts": {
"build": "ember build --environment=production",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"lint": "concurrently \"npm:lint:*(!fix)\" --names \"lint:\"",
"lint:fix": "concurrently \"npm:lint:*:fix\" --names \"fix:\"",
"lint:hbs": "ember-template-lint .",
"lint:hbs:fix": "ember-template-lint . --fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "npm-run-all lint test:*",
"test": "concurrently \"npm:lint\" \"npm:test:*\" --names \"lint,test:\"",
"test:ember": "ember test",
"test:ember-compatibility": "ember try:each"
},
"dependencies": {
"ember-auto-import": "^2.4.2",
"ember-cli-babel": "^7.26.6",
"ember-cli-htmlbars": "^6.0.1",
"ember-auto-import": "^2.5.0",
"ember-cli-babel": "^7.26.11",
"ember-cli-htmlbars": "^6.2.0",
"humanize-duration": "^3.27.0",
"process": "^0.11.10",
"reading-time": "^1.5.0",
"stream-browserify": "^3.0.0"
"stream-browserify": "^3.0.0",
"util": "^0.12.5",
"webpack": "^5.75.0"
},
"devDependencies": {
"@babel/core": "^7.18.2",
"@babel/eslint-parser": "^7.18.2",
"@ember/optional-features": "^2.0.0",
"@ember/test-helpers": "^2.4.2",
"@embroider/test-setup": "^1.8.3",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"@ember/string": "^3.0.1",
"@ember/test-helpers": "^2.9.3",
"@embroider/test-setup": "^2.0.2",
"@glimmer/component": "^1.1.2",
"@glimmer/tracking": "^1.1.2",
"broccoli-asset-rev": "^3.0.0",
"ember-cli": "~3.28.3",
"ember-cli-dependency-checker": "^3.2.0",
"concurrently": "^7.6.0",
"ember-cli": "~4.10.0",
"ember-cli-dependency-checker": "^3.3.1",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.2",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-export-application-global": "^2.0.1",
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.4",
"ember-resolver": "^8.0.2",
"ember-source": "~3.28.4",
"ember-qunit": "^6.1.1",
"ember-resolver": "^10.0.0",
"ember-source": "~4.10.0",
"ember-source-channel-url": "^3.0.0",
"ember-template-lint": "^3.6.0",
"ember-template-lint": "^5.3.1",
"ember-try": "^2.0.0",
"eslint": "^8.16.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^11.0.6",
"eslint-plugin-n": "^15.2.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-qunit": "^7.0.0",
"eslint-config-prettier": "^8.6.0",
"eslint-plugin-ember": "^11.4.3",
"eslint-plugin-n": "^15.6.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-qunit": "^7.3.4",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"qunit": "^2.16.0",
"qunit-dom": "^2.0.0",
"webpack": "5"
"prettier": "^2.8.3",
"qunit": "^2.19.3",
"qunit-dom": "^2.0.0"
},
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0"
},
"engines": {
"node": "14.* || >= 16"
"node": "14.* || 16.* || >= 18"
},
"ember": {
"edition": "octane"
Expand Down
1 change: 0 additions & 1 deletion tests/dummy/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand Down
2 changes: 1 addition & 1 deletion tests/dummy/config/ember-cli-update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages": [
{
"name": "ember-cli",
"version": "3.28.3",
"version": "4.10.0",
"blueprints": [
{
"name": "addon",
Expand Down
21 changes: 4 additions & 17 deletions config/ember-try.js → tests/dummy/config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ module.exports = async function () {
useYarn: true,
scenarios: [
{
name: 'ember-lts-3.20',
name: 'ember-lts-3.28',
npm: {
devDependencies: {
'ember-source': '~3.20.5',
'ember-source': '~3.28.0',
},
},
},
{
name: 'ember-lts-3.24',
name: 'ember-lts-4.4',
npm: {
devDependencies: {
'ember-source': '~3.24.3',
'ember-source': '~4.4.0',
},
},
},
Expand Down Expand Up @@ -47,19 +47,6 @@ module.exports = async function () {
},
},
},
{
name: 'ember-default-with-jquery',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true,
}),
},
npm: {
devDependencies: {
'@ember/jquery': '^1.1.0',
},
},
},
{
name: 'ember-classic',
env: {
Expand Down
Loading

0 comments on commit d78b6d4

Please sign in to comment.