Skip to content

Commit

Permalink
test: fix test, add required Webpack polyfills
Browse files Browse the repository at this point in the history
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 committed Feb 12, 2023
1 parent a9d7543 commit 53338ed
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
9 changes: 8 additions & 1 deletion 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 Down Expand Up @@ -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
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@
"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",
Expand Down Expand Up @@ -81,8 +84,7 @@
"loader.js": "^4.7.0",
"prettier": "^2.8.3",
"qunit": "^2.19.3",
"qunit-dom": "^2.0.0",
"webpack": "^5.75.0"
"qunit-dom": "^2.0.0"
},
"peerDependencies": {
"ember-source": "^3.28.0 || ^4.0.0"
Expand Down
29 changes: 26 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5810,7 +5810,7 @@ is-accessor-descriptor@^1.0.0:
dependencies:
kind-of "^6.0.0"

is-arguments@^1.1.1:
is-arguments@^1.0.4, is-arguments@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/is-arguments/-/is-arguments-1.1.1.tgz#15b3f88fda01f2a97fec84ca761a560f123efa9b"
integrity sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==
Expand Down Expand Up @@ -5930,6 +5930,13 @@ is-fullwidth-code-point@^3.0.0:
resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d"
integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==

is-generator-function@^1.0.7:
version "1.0.10"
resolved "https://registry.yarnpkg.com/is-generator-function/-/is-generator-function-1.0.10.tgz#f1558baf1ac17e0deea7c0415c438351ff2b3c72"
integrity sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==
dependencies:
has-tostringtag "^1.0.0"

is-git-url@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-git-url/-/is-git-url-1.0.0.tgz#53f684cd143285b52c3244b4e6f28253527af66b"
Expand Down Expand Up @@ -6056,7 +6063,7 @@ [email protected]:
dependencies:
core-util-is "~1.0.0"

is-typed-array@^1.1.10, is-typed-array@^1.1.9:
is-typed-array@^1.1.10, is-typed-array@^1.1.3, is-typed-array@^1.1.9:
version "1.1.10"
resolved "https://registry.yarnpkg.com/is-typed-array/-/is-typed-array-1.1.10.tgz#36a5b5cb4189b575d1a3e4b08536bfb485801e3f"
integrity sha512-PJqgEHiWZvMpaFZ3uTc8kHPM4+4ADTlDniuQL7cU/UDA0Ql7F70yGfHph3cLNe+c9toaigv+DFzTJKhc2CtO6A==
Expand Down Expand Up @@ -7674,6 +7681,11 @@ process-relative-require@^1.0.0:
dependencies:
node-modules-path "^1.0.0"

process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==

promise-map-series@^0.2.1:
version "0.2.3"
resolved "https://registry.yarnpkg.com/promise-map-series/-/promise-map-series-0.2.3.tgz#c2d377afc93253f6bd03dbb77755eb88ab20a847"
Expand Down Expand Up @@ -9257,6 +9269,17 @@ util-deprecate@^1.0.1, util-deprecate@^1.0.2:
resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==

util@^0.12.5:
version "0.12.5"
resolved "https://registry.yarnpkg.com/util/-/util-0.12.5.tgz#5f17a6059b73db61a875668781a1c2b136bd6fbc"
integrity sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==
dependencies:
inherits "^2.0.3"
is-arguments "^1.0.4"
is-generator-function "^1.0.7"
is-typed-array "^1.1.3"
which-typed-array "^1.1.2"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
Expand Down Expand Up @@ -9459,7 +9482,7 @@ which-collection@^1.0.1:
is-weakmap "^2.0.1"
is-weakset "^2.0.1"

which-typed-array@^1.1.9:
which-typed-array@^1.1.2, which-typed-array@^1.1.9:
version "1.1.9"
resolved "https://registry.yarnpkg.com/which-typed-array/-/which-typed-array-1.1.9.tgz#307cf898025848cf995e795e8423c7f337efbde6"
integrity sha512-w9c4xkx6mPidwp7180ckYWfMmvxpjlZuIudNtDf4N/tTAUB8VJbX25qZoAsrtGuYNnGw3pa0AXgbGKRB8/EceA==
Expand Down

0 comments on commit 53338ed

Please sign in to comment.