Skip to content
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

Upgrade Node.js and npm to v18 and v9 #48950

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/create-block.yml
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['14']
node: ['16', '18']
os: [macos-latest, ubuntu-latest, windows-latest]

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/end2end-test.yml
Expand Up @@ -41,8 +41,8 @@ jobs:

- name: Running the tests
run: |
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
$( npm bin )/wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % ${{ matrix.totalParts }} == ${{ matrix.part }} - 1' < ~/.jest-e2e-tests )
npx wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --listTests > ~/.jest-e2e-tests
npx wp-scripts test-e2e --config=./packages/e2e-tests/jest.config.js --cacheDirectory="$HOME/.jest-cache" --runTestsByPath $( awk 'NR % ${{ matrix.totalParts }} == ${{ matrix.part }} - 1' < ~/.jest-e2e-tests )

- name: Archive debug artifacts (screenshots, HTML snapshots)
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/pull-request-automation.yml
Expand Up @@ -10,7 +10,7 @@ jobs:
if: ${{ github.repository == 'WordPress/gutenberg' }}
strategy:
matrix:
node: ['14']
node: ['18']

steps:
# Checkout defaults to using the branch which triggered the event, which
Expand All @@ -31,11 +31,9 @@ jobs:
path: ~/.npm
key: ${{ runner.os }}-node-${{ matrix.node }}-npm-pr-automation-cache-${{ hashFiles('**/package-lock.json') }}

# Changing into the action's directory and running `npm install` is much
# faster than a full project-wide `npm ci`.
# Only run `npm ci` in the package folder and ignore postinstall scripts.
- name: Install NPM dependencies
run: npm install
working-directory: packages/project-management-automation
run: npm ci -w @wordpress/project-management-automation --ignore-scripts
kevin940726 marked this conversation as resolved.
Show resolved Hide resolved

- uses: ./packages/project-management-automation
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node: ['14']
node: ['16', '18']

steps:
- uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
Expand Down
1 change: 1 addition & 0 deletions .npmrc
@@ -1,2 +1,3 @@
save-exact = true
engine-strict = true
legacy-peer-deps = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is supposed to be a temporary solution until we fix all the peer dependency issues.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kevin940726 I created a draft PR that solves the peer dependency issue related to React Native and removes this NPM configuration option. As far as I tested, the dependency installation works, although warnings are displayed. Let me know if you'd like to incorporate it into this PR, thanks 🙇 !

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I tried the same thing too, but I think it would be better to be a separate follow-up PR. Warnings can be intimidating for some, I would like to solve all warnings before we roll them out to all contributors.

2 changes: 1 addition & 1 deletion .nvmrc
@@ -1 +1 @@
14
18
12 changes: 3 additions & 9 deletions bin/api-docs/update-api-docs.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
const { join, relative, resolve, sep, dirname } = require( 'path' );
const { relative, resolve, sep, dirname } = require( 'path' );
const glob = require( 'fast-glob' );
const execa = require( 'execa' );
const { Transform } = require( 'stream' );
Expand Down Expand Up @@ -217,15 +217,9 @@ glob.stream( [
path = findDefaultSourcePath( dirname( file ) ),
] of tokens ) {
await execa(
`"${ join(
__dirname,
'..',
'..',
'node_modules',
'.bin',
'docgen'
) }"`,
'npx',
[
'docgen',
relative( ROOT_DIR, resolve( dirname( file ), path ) ),
`--output ${ output }`,
'--to-token',
Expand Down
3 changes: 1 addition & 2 deletions bin/packages/lint-staged-typecheck.js
Expand Up @@ -12,7 +12,6 @@ const execa = require( 'execa' );
require( './validate-typescript-version' );

const repoRoot = path.join( __dirname, '..', '..' );
const tscPath = path.join( repoRoot, 'node_modules', '.bin', 'tsc' );

// lint-staged passes full paths to staged changes
const changedFiles = process.argv.slice( 2 );
Expand All @@ -28,7 +27,7 @@ const changedPackages = _.uniq(
);

try {
execa.sync( tscPath, [ '--build', ...changedPackages ] );
execa.sync( 'npx', [ 'tsc', '--build', ...changedPackages ] );
} catch ( err ) {
console.error( err.stdout );
process.exitCode = 1;
Expand Down
10 changes: 5 additions & 5 deletions bin/test-create-block.sh
Expand Up @@ -63,10 +63,10 @@ if [ "$expected" -ne "$actual" ]; then
fi

status "Formatting files..."
../node_modules/.bin/wp-scripts format
npx wp-scripts format

status "Building block..."
../node_modules/.bin/wp-scripts build
npx wp-scripts build

status "Verifying build..."
expected=5
Expand All @@ -77,10 +77,10 @@ if [ "$expected" -ne "$actual" ]; then
fi

status "Linting CSS files..."
../node_modules/.bin/wp-scripts lint-style
npx wp-scripts lint-style

status "Linting JavaScript files..."
../node_modules/.bin/wp-scripts lint-js
npx wp-scripts lint-js

status "Creating a plugin zip file..."
../node_modules/.bin/wp-scripts plugin-zip
npx wp-scripts plugin-zip
6 changes: 3 additions & 3 deletions bin/validate-package-lock.js
Expand Up @@ -20,8 +20,8 @@ const { red, yellow } = require( 'chalk' );
// @ts-ignore
const packageLock = require( '../package-lock' );

const dependencies = Object.entries( packageLock.dependencies );
for ( const [ name, dependency ] of dependencies ) {
const packages = Object.entries( packageLock.packages );
for ( const [ name, dependency ] of packages ) {
if ( dependency.resolved === false ) {
console.log(
`Invalid resolved dependency in package-lock.json.
Expand All @@ -38,6 +38,6 @@ To fix, try removing the node_modules directory and reverting package-lock.json,
}

if ( dependency.dependencies ) {
dependencies.push( ...Object.entries( dependency.dependencies ) );
packages.push( ...Object.entries( dependency.dependencies ) );
}
}
Expand Up @@ -5,7 +5,7 @@ The following guide is for setting up your local environment to contribute to th
## Prerequisites

- Node.js
Gutenberg is a JavaScript project and requires [Node.js](https://nodejs.org/). The project is built using Node.js v14, and npm v6. See the [LTS release schedule](https://github.com/nodejs/Release#release-schedule) for details.
Gutenberg is a JavaScript project and requires [Node.js](https://nodejs.org/). The project is built using Node.js v18, and npm v9. See the [LTS release schedule](https://github.com/nodejs/Release#release-schedule) for details.

We recommend using the [Node Version Manager](https://github.com/nvm-sh/nvm) (nvm) since it is the easiest way to install and manage node for macOS, Linux, and Windows 10 using WSL2. See [our Development Tools guide](/docs/getting-started/devenv/README.md#development-tools) or the Nodejs site for additional installation instructions.

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/create-block/README.md
Expand Up @@ -18,7 +18,7 @@ From your plugins directory, to create your block run:
npx @wordpress/create-block gutenpride --template @wordpress/create-block-tutorial-template
```

> Remember that you should use Node.js v14. Other versions may result in an error in the terminal. See [Node Development Tools](https://developer.wordpress.org/block-editor/getting-started/devenv/#node-development-tools) for more info.
> Remember that you should use Node.js >=v14. Older versions may result in an error in the terminal. See [Node Development Tools](https://developer.wordpress.org/block-editor/getting-started/devenv/#node-development-tools) for more info.

The [npx command](https://docs.npmjs.com/cli/v8/commands/npx) runs a command from a remote package, in this case our create-block package that will create a new directory called `gutenpride`, installs the necessary files, and builds the block plugin. If you want an interactive mode that prompts you for details, run the command without the `gutenpride` name.

Expand Down
20 changes: 10 additions & 10 deletions docs/getting-started/devenv/README.md
Expand Up @@ -21,10 +21,10 @@ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
```

Quit and restart terminal
Install Node.js v14.
Install Node.js v18.

```
nvm install 14
nvm install 18
```

**2. WordPress Development Site**
Expand Down Expand Up @@ -57,7 +57,7 @@ The tools are used to convert the JavaScript we are going to write into a format

For Mac and Linux, it is recommended to use the [Node Version Manager](https://github.com/nvm-sh/nvm) (nvm). Using `nvm` to install node allows installing specific versions, plus installs locally in your home directory and avoids any global permission issues.

For Windows, or alternative installs, you can [download a Nodejs installer](https://nodejs.org/en/download/) directly from the main Node.js website, v14 is recommended. Installers are available for Windows and Mac, and binaries available for Linux. See Node.js site for additional installation methods.
For Windows, or alternative installs, you can [download a Nodejs installer](https://nodejs.org/en/download/) directly from the main Node.js website, v18 is recommended. Installers are available for Windows and Mac, and binaries available for Linux. See Node.js site for additional installation methods.

Here are the quick instructions to install using nvm, see the [full installation instructions](https://github.com/nvm-sh/nvm#installing-and-updating) for additional details.

Expand All @@ -71,16 +71,16 @@ Note: On macOS, the required developer tools are not installed by default, if no

<img src="https://developer.wordpress.org/files/2020/07/git-install-prompt.png" alt="Mac git command requires command line developer tools" width="400" height="195"/>

After installing nvm, you need to use it to install Node.js, to install v14, run:
After installing nvm, you need to use it to install Node.js, to install v18, run:

```sh
nvm install 14
nvm install 18
```

If there is an error running the above command, for example a common error that occurs is:

```sh
$ nvm install 14
$ nvm install 18
zsh: command not found: nvm
```

Expand All @@ -93,20 +93,20 @@ On macOS Catalina, the default shell is zsh, to create the profile file type `to
After creating the profile file, re-run the install command:

```sh
nvm install 14
nvm install 18
```

The important part after installing is being able to use them in your terminal. Open a terminal command-line and type `node -v` and `npm -v` to confirm they are installed.

```sh
> node -v
v14.19.0
v18.14.2

> npm -v
6.14.16
9.6.0
```

Your versions may not match exactly, that is fine. The minimum version for Node.js is >= 12 and for npm >= 6.9, using v14 will be supported until upgrade is required.
Your versions may not match exactly, that is fine. The minimum version for Node.js is >= 18 and for npm >= 9, using v18 will be supported until upgrade is required.

## WordPress Development Site

Expand Down
2 changes: 2 additions & 0 deletions lerna.json
@@ -1,4 +1,6 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useWorkspaces": true,
"command": {
"publish": {
"message": "chore(release): publish"
Expand Down