diff --git a/.circleci/config.yml b/.circleci/config.yml index 1c228e2a284..f3cda9fc147 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -156,7 +156,7 @@ workflows: defaults: &defaults docker: - - image: cimg/node:14.16-browsers + - image: cimg/node:18.12-browsers working_directory: ~/mapbox-gl-js jobs: 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); }