@mapwhit/glyph-server 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,9 +1,17 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('dotenv').config({ path: '/etc/default/map-glyph-server' });
3
+ import process from 'node:process';
4
+ import connect from '@pirxpilot/connect';
5
+ import Debug from 'debug';
6
+ import router from './lib/map-glyph-server.js';
4
7
 
5
- const connect = require('@pirxpilot/connect');
6
- const router = require('./lib/map-glyph-server');
8
+ const debug = Debug('map-glyph-server:app');
9
+
10
+ try {
11
+ process.loadEnvFile('/etc/default/map-glyph-server');
12
+ } catch {
13
+ debug('Environment file cannot be loaded.');
14
+ }
7
15
 
8
16
  const PORT = process.env.MAP_GLYPH_SERVER_PORT || 3060;
9
17
  const FONT_PATH = process.env.MAP_GLYPH_SERVER_FONT_PATH;
@@ -13,13 +21,11 @@ if (!FONT_PATH) {
13
21
  process.exit(1);
14
22
  }
15
23
 
16
- const app = connect();
24
+ export const app = connect();
17
25
 
18
26
  app.use('/fonts', router(FONT_PATH));
19
27
 
20
- module.exports = app;
21
-
22
- if (!module.parent) {
28
+ if (import.meta.main) {
23
29
  app.listen(PORT);
24
30
  console.log('Listening on port', PORT);
25
31
  }
package/lib/find-fonts.js CHANGED
@@ -1,13 +1,12 @@
1
- const { readdir, stat } = require('node:fs/promises');
2
- const { join } = require('node:path');
1
+ import { readdir, stat } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import Debug from 'debug';
3
4
 
4
- const debug = require('debug')('map-glyph-server');
5
-
6
- module.exports = findFonts;
5
+ const debug = Debug('map-glyph-server');
7
6
 
8
7
  const memo = Object.create(null);
9
8
 
10
- function findFonts(fontPath) {
9
+ export default function findFonts(fontPath) {
11
10
  let p = memo[fontPath];
12
11
  if (!p) {
13
12
  memo[fontPath] = p = findFontsImplementation(fontPath);
@@ -19,9 +18,7 @@ async function findFontsImplementation(fontPath) {
19
18
  debug('Looking for fonts in:', fontPath);
20
19
  const dirs = await readdir(fontPath, { withFileTypes: true });
21
20
  const fonts = {};
22
- await Promise.all(
23
- dirs.filter(d => d.isDirectory() || d.isSymbolicLink()).map(checkDir)
24
- );
21
+ await Promise.all(dirs.filter(d => d.isDirectory() || d.isSymbolicLink()).map(checkDir));
25
22
  return fonts;
26
23
 
27
24
  async function checkDir({ name, parentPath }) {
@@ -1,11 +1,9 @@
1
- const { join } = require('node:path');
2
- const { readFile } = require('node:fs/promises');
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { combine } from '@furkot/glyph-pbf-composite';
4
+ import Debug from 'debug';
3
5
 
4
- const { combine } = require('@furkot/glyph-pbf-composite');
5
-
6
- const debug = require('debug')('map-glyph-server');
7
-
8
- module.exports = getFontsPbf;
6
+ const debug = Debug('map-glyph-server');
9
7
 
10
8
  async function getFontPbf(fontPath, choices, range) {
11
9
  debug('Looking for', choices[0], range);
@@ -35,15 +33,12 @@ async function getFontPbf(fontPath, choices, range) {
35
33
  }
36
34
  }
37
35
 
38
- async function getFontsPbf(fontPath, fonts, range, fallbacks) {
39
- let pbfs = await Promise.all(
40
- fonts.map(font => getFontPbf(fontPath, [font, ...fallbacks], range))
41
- );
36
+ export default async function getFontsPbf(fontPath, fonts, range, fallbacks) {
37
+ let pbfs = await Promise.all(fonts.map(font => getFontPbf(fontPath, [font, ...fallbacks], range)));
42
38
  // only non-empty fonts are OK
43
39
  pbfs = pbfs.filter(p => p?.length);
44
40
  debug(pbfs);
45
41
  if (pbfs.length < fonts.length) {
46
- console.log('here');
47
42
  throw 404;
48
43
  }
49
44
  const result = pbfs.length > 1 ? combine(pbfs) : pbfs[0];
@@ -1,13 +1,12 @@
1
- const Router = require('@pirxpilot/router');
2
-
3
- const findFonts = require('./find-fonts');
4
- const getFontsPbf = require('./get-fonts-pbf');
5
- const entityTag = require('etag');
6
- const fresh = require('fresh');
1
+ import Router from '@pirxpilot/router';
2
+ import entityTag from 'etag';
3
+ import fresh from 'fresh';
4
+ import findFonts from './find-fonts.js';
5
+ import getFontsPbf from './get-fonts-pbf.js';
7
6
 
8
7
  const CACHE_MAX_AGE = process.env.MAP_GLYPH_SERVER_CACHE_MAX_AGE;
9
8
 
10
- async function find(req, res, next) {
9
+ async function find(req, _res, next) {
11
10
  const fonts = await findFonts(req.fontPath);
12
11
  req.fonts = fonts;
13
12
  req.fontList = Object.keys(fonts);
@@ -45,22 +44,18 @@ async function sendFontsPbf(req, res) {
45
44
  res.end(pbf);
46
45
  }
47
46
 
48
- module.exports = function (fontPath) {
47
+ export default function (fontPath) {
49
48
  const router = new Router({
50
49
  strict: true,
51
50
  caseSensitive: true
52
51
  });
53
52
 
54
- router.use(function (req, res, next) {
53
+ router.use((req, _res, next) => {
55
54
  req.fontPath = fontPath;
56
55
  next();
57
56
  });
58
57
 
59
- router.get(
60
- /^\/(?<fontstack>[^/]+)\/(?<range>\d+-\d+)\.pbf$/,
61
- find,
62
- sendFontsPbf
63
- );
58
+ router.get(/^\/(?<fontstack>[^/]+)\/(?<range>\d+-\d+)\.pbf$/, find, sendFontsPbf);
64
59
  router.get('/.json', find, sendFontsList);
65
60
  return router;
66
- };
61
+ }
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@mapwhit/glyph-server",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Server for glyph/font files compatible with mapbox-gl-js",
5
+ "type": "module",
5
6
  "author": {
6
7
  "name": "Damian Krzeminski",
7
8
  "email": "pirxpilot@furkot.com",
@@ -27,12 +28,11 @@
27
28
  "@pirxpilot/connect": "~4",
28
29
  "@pirxpilot/router": "~1",
29
30
  "debug": "~4",
30
- "dotenv": "~16",
31
31
  "etag": "~1",
32
32
  "fresh": "~2"
33
33
  },
34
34
  "devDependencies": {
35
- "@biomejs/biome": "^1.9.4",
35
+ "@biomejs/biome": "2.2.4",
36
36
  "supertest-fetch": "~2"
37
37
  },
38
38
  "scripts": {