From f752b5eea1a5b6eecd43f959edf74c47bb9e0a82 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Sat, 3 Oct 2026 18:47:31 -0700 Subject: [PATCH] fix: resolve bundled data URLs when used, not at import The submarine cable source and the infrastructure data URLs built their asset URLs from import.meta.url while the module loaded. Importing the tool services therefore failed in runtimes without a usable module URL, even for tools that never read those files. Build the URLs when they are read; Vite still rewrites them in browser builds. --- src/data/infrastructure.js | 5 ++--- src/layers/submarineCables/bundledSource.js | 25 ++++++++++++--------- src/sources/infrastructureData.js | 21 +++++++++-------- 3 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/data/infrastructure.js b/src/data/infrastructure.js index ea78494c8..348d4bfb4 100644 --- a/src/data/infrastructure.js +++ b/src/data/infrastructure.js @@ -1,15 +1,14 @@ import { createLocalGeoJsonLayer } from './localGeojsonCore.js'; import { INFRASTRUCTURE_DATA_URLS } from '../sources/infrastructureData.js'; -const datacentersUrl = INFRASTRUCTURE_DATA_URLS['local-datacenters']; -const damsUrl = INFRASTRUCTURE_DATA_URLS['local-dams']; - /** * Create fresh datacenter and dam layers without starting or loading them. * @param {object} services Caller-owned context, overlay and render operations. * @returns {object[]} Datacenters then dams, with stable standalone identities. */ export function createInfrastructureLayers(services) { + const datacentersUrl = INFRASTRUCTURE_DATA_URLS['local-datacenters']; + const damsUrl = INFRASTRUCTURE_DATA_URLS['local-dams']; const datacenters = createLocalGeoJsonLayer( { id: 'local-datacenters', diff --git a/src/layers/submarineCables/bundledSource.js b/src/layers/submarineCables/bundledSource.js index 6aa0b70bb..881522ee9 100644 --- a/src/layers/submarineCables/bundledSource.js +++ b/src/layers/submarineCables/bundledSource.js @@ -1,14 +1,19 @@ // This dataset is CC BY-NC-SA 3.0, not the project's MIT license. // Commercial users must remove it or obtain a TeleGeography license. // See DATA_SOURCES.md and the bundled dataset's source.json. -const cableUrl = new URL( - '../../data/local_data/telegeography_submarine_cables/cable-geo.json', - import.meta.url, -).href; -const landingPointUrl = new URL( - '../../data/local_data/telegeography_submarine_cables/landing-point-geo.json', - import.meta.url, -).href; +// Resolved when read, so importing this module never needs a module URL. +function cableUrl() { + return new URL( + '../../data/local_data/telegeography_submarine_cables/cable-geo.json', + import.meta.url, + ).href; +} +function landingPointUrl() { + return new URL( + '../../data/local_data/telegeography_submarine_cables/landing-point-geo.json', + import.meta.url, + ).href; +} /** Supply GeoJSON collections without coupling the renderer to asset URLs. */ export function createBundledCableSource({ @@ -33,8 +38,8 @@ export function createBundledCableSource({ label: 'TeleGeography', async fetch(signal) { const [cables, landingPoints] = await Promise.all([ - read(cableUrl, signal), - read(landingPointUrl, signal), + read(cableUrl(), signal), + read(landingPointUrl(), signal), ]); return { cables, landingPoints }; }, diff --git a/src/sources/infrastructureData.js b/src/sources/infrastructureData.js index 6936b9aa5..33206ab44 100644 --- a/src/sources/infrastructureData.js +++ b/src/sources/infrastructureData.js @@ -3,16 +3,19 @@ * data files, line-delimited GeoJSON parsing and analyst records. */ -// Resolved by Vite in builds and relative to this module in other consumers. +// Resolved by Vite in builds and relative to this module in other consumers, +// when read, so importing this module never needs a module URL. export const INFRASTRUCTURE_DATA_URLS = Object.freeze({ - 'local-datacenters': new URL( - '../data/local_data/datacenters/datacenters.geojsonl', - import.meta.url, - ).href, - 'local-dams': new URL( - '../data/local_data/dams/dams.geojsonl', - import.meta.url, - ).href, + get 'local-datacenters'() { + return new URL( + '../data/local_data/datacenters/datacenters.geojsonl', + import.meta.url, + ).href; + }, + get 'local-dams'() { + return new URL('../data/local_data/dams/dams.geojsonl', import.meta.url) + .href; + }, }); /** Parse GeoJSON Lines: one Feature per non-empty line. */