Skip to content

Commit 7395b1b

Browse files
committed
fix: inline iD tagging-schema JSON into api bundle so runtime require doesn't fail
1 parent 51f68af commit 7395b1b

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

integrations/geocoding/osm-label.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
* Resolves OSM class/type pairs to human-readable English labels using the
33
* iD editor's tagging schema (@openstreetmap/id-tagging-schema). The full
44
* JSON is loaded once at startup — server-side only, never sent to the client.
5+
*
6+
* Uses static JSON imports so esbuild inlines the data into the api bundle
7+
* at build time. A runtime `require()` would fail in the containerized api
8+
* image because `@openstreetmap/id-tagging-schema` is a sub-dep of the
9+
* geocoding integration, not a root-hoisted package that `createRequire`
10+
* can find from `apps/api/dist/server.js`.
511
*/
612

7-
import { createRequire } from "node:module";
8-
9-
const require = createRequire(import.meta.url);
13+
import presets from "@openstreetmap/id-tagging-schema/dist/presets.json" with { type: "json" };
14+
import enTranslations from "@openstreetmap/id-tagging-schema/dist/translations/en.json" with {
15+
type: "json",
16+
};
1017

1118
type PresetEntry = { name?: string };
1219
type TranslationEntry = { name?: string };
1320
type EnTranslations = { en?: { presets?: { presets?: Record<string, TranslationEntry> } } };
1421

15-
const schema = require("@openstreetmap/id-tagging-schema/dist/presets.json") as Record<
16-
string,
17-
PresetEntry
18-
>;
19-
20-
const translations =
21-
(require("@openstreetmap/id-tagging-schema/dist/translations/en.json") as EnTranslations).en
22-
?.presets?.presets ?? {};
22+
const schema = presets as Record<string, PresetEntry>;
23+
const translations = (enTranslations as EnTranslations).en?.presets?.presets ?? {};
2324

2425
// iD names include editing-context qualifiers that are verbose in a display context.
2526
// Strip them wherever they appear as a trailing suffix.

0 commit comments

Comments
 (0)