Skip to content

Commit

Permalink
Feature/issue 957 node 18 upgrade (#1014)
Browse files Browse the repository at this point in the history
* upgrade node 18

* update node version documentation

* adopt native fetch

* upgrade Ubuntu version for Linux GitHub Actions
  • Loading branch information
thescientist13 authored Dec 10, 2022
1 parent d6d5230 commit a3f667f
Show file tree
Hide file tree
Showing 23 changed files with 19 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-exp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [pull_request]
jobs:

build:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

strategy:
matrix:
node: [16]
node: [18]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-win-exp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node: [16]
node: [18]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:

strategy:
matrix:
node: [14, 16]
node: [18]

steps:
- uses: actions/checkout@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ on: [pull_request]
jobs:

build:
runs-on: ubuntu-18.04
runs-on: ubuntu-20.04

strategy:
matrix:
node: [14, 16]
node: [18]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node: [14]
node: [18]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [14]
node-version: [18]

steps:
- uses: actions/checkout@v1
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.17.0
18.12.1
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
skip_processing = true

[build.environment]
NODE_VERSION = "14.16.0"
NODE_VERSION = "18.12.1"

[[redirects]]
from = "/docs/tech-stack/"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "cross-env __GWD_ROLLUP_MODE__=strict node . build",
"serve": "node . serve",
"develop": "node . develop",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" \"./packages/**/**/*.spec.js\"",
"test": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 c8 mocha --exclude \"./packages/**/test/cases/exp-*/**\" \"./packages/**/**/*.spec.js\"",
"test:exp": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader $(pwd)/test/test-loader.js ./node_modules/mocha/bin/mocha \"./packages/**/**/*.spec.js\"",
"test:exp:win": "cross-env BROWSERSLIST_IGNORE_OLD_DATA=true __GWD_ROLLUP_MODE__=strict NODE_NO_WARNINGS=1 node --experimental-loader file:\\\\%cd%\\test\\test-loader.js ./node_modules/mocha/bin/mocha --exclude \"./packages/init/test/cases/**\" \"./packages/**/**/*.spec.js\"",
"test:tdd": "yarn test --watch",
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"Web Components"
],
"engines": {
"node": ">=14"
"node": ">=18.12.1"
},
"bin": {
"greenwood": "./src/index.js"
Expand All @@ -36,7 +36,6 @@
"koa": "^2.13.0",
"livereload": "^0.9.1",
"markdown-toc": "^1.2.0",
"node-fetch": "^2.6.1",
"node-html-parser": "^1.2.21",
"rehype-raw": "^5.0.0",
"rehype-stringify": "^8.0.0",
Expand Down
6 changes: 2 additions & 4 deletions packages/cli/src/loader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Node ^16.17.0
import path from 'path';
import { readAndMergeConfig as initConfig } from './lifecycles/config.js';
import { URL, fileURLToPath } from 'url';
Expand All @@ -10,12 +9,11 @@ const plugins = config.plugins.filter(plugin => plugin.type === 'resource' && !p
}
}));

// TODO need to polyfill original URL header instead of extensions?
function getCustomLoaderPlugins(url, body, headers) {
return plugins.filter(plugin => plugin.extensions.includes(path.extname(url)) && (plugin.shouldServe(url, body, headers) || plugin.shouldIntercept(url, body, headers)));
}

// https://nodejs.org/docs/latest-v16.x/api/esm.html#resolvespecifier-context-nextresolve
// https://nodejs.org/docs/latest-v18.x/api/esm.html#resolvespecifier-context-nextresolve
export function resolve(specifier, context, defaultResolve) {
const { baseURL } = context;

Expand All @@ -29,7 +27,7 @@ export function resolve(specifier, context, defaultResolve) {
return defaultResolve(specifier, context, defaultResolve);
}

// https://nodejs.org/docs/latest-v16.x/api/esm.html#loadurl-context-nextload
// https://nodejs.org/docs/latest-v18.x/api/esm.html#loadurl-context-nextload
export async function load(source, context, defaultLoad) {
const resourcePlugins = getCustomLoaderPlugins(source);
const extension = path.extname(source).replace('.', '');
Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/plugins/resource/plugin-dev-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Manages routing devServer.proxy entries to their destination.
*
*/
import fetch from 'node-fetch';
import { ResourceInterface } from '../../lib/resource-interface.js';

class DevProxyResource extends ResourceInterface {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import fetch from 'node-fetch';
import '../components/card.js';

export default class UsersPage extends HTMLElement {
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/test/cases/develop.ssr/src/pages/artists.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import fetch from 'node-fetch';

async function getTemplate(compilation, route) {
return `
<html>
Expand Down
1 change: 0 additions & 1 deletion packages/init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"chalk": "^4.1.2",
"commander": "^8.2.0",
"inquirer": "^8.2.0",
"node-fetch": "^2.6.7",
"simple-git": "^2.48.0"
}
}
1 change: 0 additions & 1 deletion packages/init/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import chalk from 'chalk';
import simpleGit from 'simple-git';
import commander from 'commander';
import { copyFolder } from './copy-folder.js';
import fetch from 'node-fetch';
import fs from 'fs';
import inquirer from 'inquirer';
import os from 'os';
Expand Down
3 changes: 1 addition & 2 deletions packages/plugin-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"@rollup/plugin-alias": "^3.1.2",
"apollo-server": "^2.21.0",
"graphql": "^15.5.0",
"graphql-tag": "^2.10.1",
"node-fetch": "^2.6.1"
"graphql-tag": "^2.10.1"
},
"devDependencies": {
"@greenwood/cli": "^0.27.2"
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-graphql/src/core/cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import ApolloCore from '@apollo/client/core/core.cjs.js';
import fetch from 'node-fetch';
import fs from 'fs';
import { gql } from 'apollo-server';
import { getQueryHash } from './common.js';
Expand Down
3 changes: 1 addition & 2 deletions www/pages/docs/server-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export {
When using `export default`, Greenwood supports providing a custom element as the export for your page content. It uses [**WCC**](https://github.com/ProjectEvergreen/wcc) by default which also includes support for rendering [Declarative Shadow DOM](https://web.dev/declarative-shadow-dom/).

```js
import fetch from 'node-fetch';
import '../components/card/card.js'; // <wc-card></wc-card>

export default class UsersPage extends HTMLElement {
Expand Down Expand Up @@ -218,7 +217,7 @@ console.log(json); // { status: 200, message: 'some data' }
```

**Steps**
1. Make sure you are using Node `v16.17.0`
1. Make sure you are using Node `v18.12.1`
1. Run the Greenwood CLI using the `--experimental-loaders` flag and pass Greenwood's custom loader
```shell
$ node --experimental-loader ./node_modules/@greenwood/cli/src/loader.js ./node_modules/.bin/greenwood <command>
Expand Down
4 changes: 2 additions & 2 deletions www/pages/getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ $ npm -v

# for example
$ node -v
v14.16.0
v18.12.1

$ npm -v
6.4.1
8.19.2
```

Along with this, familiarity of the command line / terminal is also assumed as Greenwood is a command line tool, and so all examples will assume a bash / shell like environment. Example commands used in this guide are:
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8254,7 +8254,7 @@ node-fetch-npm@^2.0.2:
json-parse-better-errors "^1.0.0"
safe-buffer "^5.1.1"

[email protected], node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1, node-fetch@^2.6.7:
[email protected], node-fetch@^2.5.0, node-fetch@^2.6.0, node-fetch@^2.6.1:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down

0 comments on commit a3f667f

Please sign in to comment.