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 to Node v18 #12277

Merged
merged 18 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ workflows:

linux-defaults: &linux-defaults
docker:
- image: cimg/node:14.21-browsers
- image: cimg/node:18.16-browsers
working_directory: ~/mapbox-gl-js

mac-defaults: &mac-defaults
Expand Down Expand Up @@ -542,8 +542,14 @@ jobs:
<<: *windows-defaults
steps:
- checkout
- run: $NodeVersion = Get-Content -Path .\.nvmrc; nvm install $NodeVersion; nvm use $NodeVersion
- run: npm install --global yarn
- run:
name: Setup Node.js and Yarn
command: |
choco uninstall nvm.portable
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is an issue with backslashes in paths with the NPM package with the Node v18 version using NVM. The Chocolately version seems to be working fine.

$nodeVersion = Get-Content .nvmrc
choco install nodejs --version $nodeVersion
npm install -g yarn
refreshenv
- run: yarn --frozen-lockfile
- run: yarn run build-dev
- run:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pull-request-requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Use Node.js 14.x
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 14.x
node-version: 18.x
- name: Install dependencies
run: yarn install --cwd ./.github/actions
- name: Check if changelog entry exists
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.21
18.16.0
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ Install the Xcode Command Line Tools Package
xcode-select --install
```

Install [node.js](https://nodejs.org/) version 14
Install [node.js](https://nodejs.org/) version 18
```bash
brew install node@14
brew install node@18
```
Install [yarn](https://yarnpkg.com/en/)
```bash
Expand All @@ -30,10 +30,10 @@ yarn install

### Linux

Install [git](https://git-scm.com/), [node.js](https://nodejs.org/) version 14, [GNU Make](http://www.gnu.org/software/make/), and libglew-dev
Install [git](https://git-scm.com/), [node.js](https://nodejs.org/) version 18, [GNU Make](http://www.gnu.org/software/make/), and libglew-dev
```bash
sudo apt-get update
curl -sL https://deb.nodesource.com/setup_14.x | sudo bash -
curl -sL https://deb.nodesource.com/setup_18.x | sudo bash -
sudo apt-get install build-essential git nodejs libglew-dev libxi-dev
```

Expand All @@ -55,7 +55,7 @@ yarn install

### Windows

Install [git](https://git-scm.com/), [node.js](https://nodejs.org/) version 14, [yarn](https://yarnpkg.com/en/docs/install#windows-tab), [npm and node-gyp](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules).
Install [git](https://git-scm.com/), [node.js](https://nodejs.org/) version 18, [yarn](https://yarnpkg.com/en/docs/install#windows-tab), [npm and node-gyp](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules).

Clone the repository
```bash
Expand Down
47 changes: 28 additions & 19 deletions build/node-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,45 @@ import {dataToEsm} from '@rollup/pluginutils';
const glslRe = /\.glsl$/;
const jsonRe = /\.json$/;

export function resolve(specifier, context, defaultResolve) {
export async function resolve(specifier, context, nextResolve) {
if (glslRe.test(specifier)) {
const url = new URL(specifier, context.parentURL).href;
return {url};
return {url, shortCircuit: true};
}
return defaultResolve(specifier, context, defaultResolve);
}

export function getFormat(url, context, defaultGetFormat) {
if (glslRe.test(url) || jsonRe.test(url)) {
return {format: 'module'};
}
return defaultGetFormat(url, context, defaultGetFormat);
return nextResolve(specifier);
}

export function transformSource(source, context, defaultTransformSource) {
if (source.indexOf('@flow') >= 0) {
source = flowRemoveTypes(source.toString()).toString();
return {source};
export async function load(url, context, nextLoad) {
if (context.format === 'module') {
const {source: rawSource} = await nextLoad(url, context);
const source = rawSource.toString();
if (source.indexOf('@flow') >= 0) {
const transformedSource = flowRemoveTypes(source).toString();
return {format: 'module', source: transformedSource, shortCircuit: true};
}
}
if (glslRe.test(context.url)) {
return {source: `export default \`${source}\``};

if (glslRe.test(url)) {
const {source: rawSource} = await nextLoad(url, {...context, format: 'module'});
const source = `export default \`${rawSource.toString()}\``;
return {format: 'module', source, shortCircuit: true};
}
if (jsonRe.test(context.url)) {
source = dataToEsm(JSON.parse(source), {

if (jsonRe.test(url)) {
const {source: rawSource} = await nextLoad(url, {...context,
// Force import assertions as "assert { type: 'json' }"
importAssertions: {type: 'json'}
});

const source = dataToEsm(JSON.parse(rawSource.toString()), {
preferConst: true,
namedExports: true,
indent: ' '
});
return {source};

return {format: 'module', source, shortCircuit: true};
}
return defaultTransformSource(source, context, defaultTransformSource);

return nextLoad(url);
}
4 changes: 4 additions & 0 deletions test/util/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import tap from 'tap';
/*eslint-disable import/no-named-as-default-member */
import sinon from 'sinon';

// Disable MessageChannel in unit tests since
// it prevents a Node.js process from exiting.
delete global.MessageChannel;

type CreateTest = (typeof sinon) & {
(name: string, body: (test: CreateTest) => void): void,

Expand Down