Skip to content

Commit

Permalink
Upgrade to Node v18
Browse files Browse the repository at this point in the history
Use Node v18 API in `node-loader`
  • Loading branch information
stepankuzmin committed Dec 22, 2022
1 parent 7bbf2e9 commit 7a9478e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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);
}

0 comments on commit 7a9478e

Please sign in to comment.