Skip to content

Commit

Permalink
Prior commit failed post-commit CI. Identified a problem with the fin…
Browse files Browse the repository at this point in the history
…al packages/turf/ conversion from mjs to rolled up js. "In strict mode code, functions can only be declared at top level or inside a block."
  • Loading branch information
smallsaucepan committed Sep 12, 2023
1 parent 3f3f203 commit e6dfbd8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
14 changes: 9 additions & 5 deletions packages/turf-distance/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Point } from "geojson";
import { getCoord } from "@turf/invariant";
import type { Coord, Datum, Units } from "@turf/helpers";
import {
datums,
radiansToLength,
degreesToRadians,
datums,
Coord,
Datum,
Units,
convertLength,
} from "@turf/helpers";
// Unable to find an equivalent import statement that works. Fails when building
// index.mjs → turf.min.js in packages/turf/
// import { LatLonEllipsoidal as LatLon } from "geodesy";
const LatLon = require("geodesy").LatLonEllipsoidal;

//http://en.wikipedia.org/wiki/Haversine_formula
Expand Down Expand Up @@ -142,7 +143,10 @@ function geodesic_ellipsoid_distance(
fromLatLon.datum = datums.WGS84;
}

const meters = fromLatLon.distanceTo(toLatLon);
// LatLonEllipsoidal types don't properly list all base LatLon functions
// e.g. distanceTo. Should be able to remove when we can move to a newer
// version of geodesy.
const meters = (fromLatLon as any).distanceTo(toLatLon);
// geodesy lib result is in meters
return convertLength(meters, "meters", options.units);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-distance/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require("path");
const test = require("tape");
const load = require("load-json-file");
const write = require("write-json-file");
import { datums, point } from "@turf/helpers";
const { datums, point } = require("@turf/helpers");
const distance = require("./index").default;

const directories = {
Expand Down
11 changes: 8 additions & 3 deletions packages/turf-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import {
Position,
GeoJsonProperties,
} from "geojson";
import { Datums, LatLonEllipsoidal } from "geodesy";
import type { Datum } from "geodesy";
// Unable to find an equivalent import statement that works. Fails when building
// index.mjs → turf.min.js in packages/turf/
// import { LatLonEllipsoidal as LatLon } from "geodesy";
const LatLon = require("geodesy").LatLonEllipsoidal;

import { Id } from "./lib/geojson";
export * from "./lib/geojson";
Expand Down Expand Up @@ -122,11 +126,12 @@ export const areaFactors: Record<AreaUnits, number> = {
* @memberof helpers
* @type {Object}
*/
export const datums: Datums = LatLonEllipsoidal.datum;
const datums = LatLon.datum;
export { datums };

// Re-export type from geodesy so clients don't need to refer directly to
// geodesy types.
export type { Datum } from "geodesy";
export type { Datum };

/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
Expand Down
2 changes: 1 addition & 1 deletion packages/turf-length/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Feature, FeatureCollection, GeometryCollection } from "geojson";
import distance from "@turf/distance";
import { Datum, Units } from "@turf/helpers";
import type { Datum, Units } from "@turf/helpers";
import { segmentReduce } from "@turf/meta";

/**
Expand Down

0 comments on commit e6dfbd8

Please sign in to comment.