diff --git a/.circleci/config.yml b/.circleci/config.yml index 9b2358a72c4..bb5ab884002 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 + $nodeVersion = Get-Content .nvmrc + choco install nodejs --version $nodeVersion + npm install -g yarn + refreshenv - run: yarn --frozen-lockfile - run: yarn run build-dev - run: diff --git a/.github/workflows/pull-request-requirements.yml b/.github/workflows/pull-request-requirements.yml index 4fe02ef7156..e8d7911ce9d 100644 --- a/.github/workflows/pull-request-requirements.yml +++ b/.github/workflows/pull-request-requirements.yml @@ -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 diff --git a/.nvmrc b/.nvmrc index 8aeef54f8df..6d80269a4f0 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -14.21 +18.16.0 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3a8fa8d7fe..5ac04f7e733 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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 ``` @@ -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 diff --git a/build/node-loader.js b/build/node-loader.js index e68d0a214b7..ead997e23b3 100644 --- a/build/node-loader.js +++ b/build/node-loader.js @@ -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); } diff --git a/test/util/test.js b/test/util/test.js index fb384e65c2a..c6c0445bb89 100644 --- a/test/util/test.js +++ b/test/util/test.js @@ -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,