Skip to content

Commit

Permalink
Update Node version to 16 and fix other config / API usage for newly-…
Browse files Browse the repository at this point in the history
…broken deps (#6775)

* Update Node version to 16
* Explicitly drop the `node:process` module in the Playground's webpack config
* Fix pixi webpack config
* Correctly set htmlparser2 in Cheerio
  • Loading branch information
danielrozenberg authored Feb 29, 2024
1 parent e2cbd5b commit c3f2277
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-js.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint-yaml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release-static-production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand All @@ -53,7 +53,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-playground.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setting up Node.js
uses: actions/setup-node@v4
with:
node-version: 14
node-version: 16
cache: npm

- name: Installing Node.js packages
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.development
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN \
rm -rf /var/lib/apt/lists/*

RUN \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
curl -sL https://deb.nodesource.com/setup_16.x | bash - && \
apt-get install -y nodejs && \
npm i -g npm && \
npm install -g gulp
Expand Down
3 changes: 2 additions & 1 deletion gulpfile.js/staticify.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const {
FORMAT_WEBSITES,
SUPPORTED_FORMATS,
} = require('@lib/amp/formatHelper.js');
const {cheerioOptions} = require('../platform/lib/common/cheerioOptions');
const coursesPath = '/documentation/courses';
const coursesRegex = new RegExp(`^(.+)(?:${coursesPath})(.*)$`);

Expand Down Expand Up @@ -208,7 +209,7 @@ async function staticify(done) {
through.obj(function (file, enc, callback) {
let renderedPage = file.contents.toString();

const $ = Cheerio.load(renderedPage);
const $ = Cheerio.load(renderedPage, cheerioOptions);
const $links = $('.nav-link');
const $levelToggle = $('.toggle-button input');

Expand Down
4 changes: 3 additions & 1 deletion pixi/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ module.exports = (env, argv) => {
},

devServer: {
writeToDisk: true,
devMiddleware: {
writeToDisk: true,
},
},
};
};
14 changes: 14 additions & 0 deletions platform/lib/common/cheerioOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
/** @type {import('cheerio').CheerioOptions} */
cheerioOptions: {
// Simply setting an `xml` key here forces Cheerio to use htmlparser2 instead of the more strict parse5.
// https://cheerio.js.org/docs/advanced/configuring-cheerio#parsing-xml-with-htmlparser2
xml: {
// Our tests were written with this setting in mind.
decodeEntities: false,
// This indicates that we expect to parse HTML, not XML.
// https://cheerio.js.org/docs/advanced/configuring-cheerio#using-htmlparser2-for-html
xmlMode: false,
},
},
};
3 changes: 2 additions & 1 deletion platform/lib/format-transform/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const amphtmlValidator = require('amphtml-validator');
const {htmlContent} = require('@lib/utils/cheerioHelper');
const config = require('@lib/config.js');
const formats = require('./formats');
const {cheerioOptions} = require('../common/cheerioOptions');

const host = config.hosts.platform;
const FORMATS_REGEXP = /@formats\(([^)]+)\)/;
Expand Down Expand Up @@ -49,7 +50,7 @@ class FormatTransform {
throw new Error(`Unsupported transform format: ${target}`);
}
const {transforms, validatorRuntime} = this.formats[target];
const $ = cheerio.load(input, {decodeEntities: false});
const $ = cheerio.load(input, cheerioOptions);
this.applyCommentFormatFilters_($, target);
for (const selector of Object.keys(transforms)) {
const elements = $(selector);
Expand Down
2 changes: 1 addition & 1 deletion platform/lib/utils/cheerioHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @return {String}
*/
function htmlContent(dom) {
let html = dom.html({_useHtmlParser2: true});
let html = dom.html();
html = html.replace(
'xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink"',
'xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"'
Expand Down
1 change: 1 addition & 0 deletions playground/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = (env, argv) => {
fallback: {
util: require.resolve('util/util.js'),
stream: require.resolve('stream-browserify'),
process: false,
},
},
optimization: {
Expand Down

0 comments on commit c3f2277

Please sign in to comment.