fix(subsUnion): resolve turf deps by absolute path, not bare specifier
All checks were successful
build-image / build (push) Successful in 12m9s

The previous side-effect-import fix didn't work: the app's own npm deps
(installed by `meteor build`) live in programs/server/npm/node_modules,
a SIBLING of programs/server/assets, not an ancestor of it. Node's
require() only walks up parent directories looking for node_modules,
so require('@turf/circle') from the worker asset script could never
find it regardless of what gets imported elsewhere in the app — it
kept failing with "Cannot find module '@turf/circle'" even after that
fix was deployed.

calcUnionAsync.js (Meteor-compiled code, which already knows how to
locate the app's npm deps) now resolves the three turf package paths
itself and hands them to the worker via workerData; the worker
requires them by absolute path instead of bare specifier.
This commit is contained in:
vjrj 2026-07-30 08:48:50 +02:00
parent 50ca9cc6cf
commit 324936242b
2 changed files with 30 additions and 14 deletions

View file

@ -15,10 +15,20 @@
// subs gets merged into (the incremental-add fast path) instead of starting
// from scratch — for a single new subscription this is one tunion() call
// instead of redoing the whole chain over every subscription again.
// workerData.turfPaths gives absolute paths to @turf/circle, @turf/union and
// @turf/truncate — this file lives under programs/server/assets/, while the
// app's own npm deps live in the sibling programs/server/npm/node_modules,
// which plain require('@turf/circle') can never find by walking up parent
// directories. The caller resolves the paths (it's Meteor-compiled code that
// knows how to find them) and hands them over instead.
const { parentPort, workerData } = require('worker_threads');
const tcircle = require('@turf/circle').default;
const tunion = require('@turf/union').default;
const ttrunc = require('@turf/truncate').default;
// eslint-disable-next-line import/no-dynamic-require
const tcircle = require(workerData.turfPaths.circle).default;
// eslint-disable-next-line import/no-dynamic-require
const tunion = require(workerData.turfPaths.union).default;
// eslint-disable-next-line import/no-dynamic-require
const ttrunc = require(workerData.turfPaths.truncate).default;
const truncOptions = { precision: 6, coordinates: 2 };