work around canvas/sharp order requirments

This commit is contained in:
acalcutt 2023-04-02 21:56:52 -04:00 committed by Andrew Calcutt
parent 44fa77a79d
commit a3e68c7698
3 changed files with 18 additions and 2 deletions

View file

@ -0,0 +1,7 @@
'use strict';
// sharp has to be required before node-canvas on linux. see https://github.com/lovell/sharp/issues/371
import sharp from 'sharp';
import { createCanvas, Image } from 'canvas';
export {sharp, createCanvas, Image};

View file

@ -0,0 +1,7 @@
'use strict';
// sharp has to be required after node-canvas on windows. see https://github.com/Automattic/node-canvas/issues/2155#issuecomment-1487190125
import { createCanvas, Image } from 'canvas';
import sharp from 'sharp';
export {sharp, createCanvas, Image};

View file

@ -6,8 +6,6 @@ import path from 'path';
import url from 'url';
import util from 'util';
import zlib from 'zlib';
import sharp from 'sharp'; // sharp has to be required before node-canvas. see https://github.com/lovell/sharp/issues/371
import { createCanvas, Image } from 'canvas';
import clone from 'clone';
import Color from 'color';
import express from 'express';
@ -20,6 +18,10 @@ import proj4 from 'proj4';
import request from 'request';
import { getFontsPbf, getTileUrls, fixTileJSONCenter } from './utils.js';
import Os from 'os'
var ostype = (Os.platform() == 'win32') ? "windows":"unix";
const { sharp, createCanvas, Image } = await import(`./render_import_${ostype}.js`);
const FLOAT_PATTERN = '[+-]?(?:\\d+|\\d+.?\\d+)';
const PATH_PATTERN =
/^((fill|stroke|width)\:[^\|]+\|)*((enc:.+)|((-?\d+\.?\d*,-?\d+\.?\d*\|)+(-?\d+\.?\d*,-?\d+\.?\d*)))/;