-
Notifications
You must be signed in to change notification settings - Fork 224
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
Refactor gulpfile from CommonJS to ECMAScript modules (ESM) #3181
Refactor gulpfile from CommonJS to ECMAScript modules (ESM) #3181
Conversation
@MikeMcC399 Thank you very much for providing this PR. We will review it ASAP. |
Successfully tested on Windows 11 and Ubuntu 20.04 with |
|
Investigation needed, so setting to Draft status. Updating yargs from the current |
An upgrade to yargs >= v16 could be looked at separately, however it is not necessary at this time. |
The answer to the By changing the import of import npmYargs from 'yargs';
import { hideBin } from 'yargs/helpers';
const yargs = npmYargs(hideBin(process.argv));
|
Please let me know if I should test this PR on a M1 mac. |
Thank you for your offer! You are welcome to test it in your environment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on a M1 MacBook Air. After I restarted my machine, it worked. So nothing is blocking this PR from being merged IMO.
I much appreciate your testing on M1. I already tested on Ubuntu and Windows 11, so I also think this PR is fine. |
This PR refactors gulpfile.js, which builds the website, so that it uses an ECMAScript modules (ESM) structure. This is compatible with newer ESM packages and with older CommonJS packages.
It address issue #3176 "Update gulpfile to use ESM".
Changes
The gulpfile.js is renamed to
gulpfile.mjs
(see https://nodejs.org/docs/latest-v16.x/api/esm.html#enabling) so that ESM is automatically used.The CommonJS
require
lines in the file which called in the necessary npm packages are converted to ESMimport
syntax (see https://nodejs.org/docs/latest-v16.x/api/esm.html#no-require-exports-or-moduleexports). In addition the order of the import lines has been sorted for better readability:The use of the gulp-load-plugins module is removed and replaced by individual imports of gulp modules. This is because gulp-load-plugins produces the error
TypeError: Cannot read properties of undefined (reading 'filename')
in an ESM environment.https://github.com/jackfranklin/gulp-load-plugins/releases/tag/v2.0.8 provides a workaround, however this does not seem reliable for the multiple environments which this web may be built under.
The associated
$.
constructs are also replaced accordingly (gulp-if
,gulp-imagemin
,gulp-postcss
,gulp-sitemap
andgulp-sourcemaps
). Several gulp modules were already separatelyrequired
so the use of gulp-load-plugins was already inconsistently applied.mozjpeg
called fromgulp-imagemin
needs special migration treatment. See https://github.com/sindresorhus/gulp-imagemin#custom-plugin-options for new syntax necessary forgulp-imagemin
8.0.0 (otherwise "TypeError: imagemin.mozjpeg is not a function" is output).The tag
assert {type: 'json'}
is added to json imports. This produces a warning in node 16: "ExperimentalWarning: Importing JSON modules is an experimental feature. This feature could change at any time".Verification
Ensure that the web can be built using
npm run build
.Execute
npm install gulp-imagemin@latest
to install version 8.0.0 and check again for a successful web build.Restore the
gulp-imagemin
to version 7.1.0 withgit restore .
npm ci
Check at any time which version of gulp-imagemin is installed using
npm ls gulp-imagemin
.Ensure that
npm test
successfully runs the Cypress test suite.Internal Tracking ID: EXPOSUREAPP-14248