Skip to content

Commit

Permalink
Reduce bundle size of apps that import @turf/helpers (#2623)
Browse files Browse the repository at this point in the history
* Remove GeojsonEquality library from turf-helpers/lib/ in favour of the third party geojson-equality-ts (which is essentially a copy of the code we're removing from turf-helpers/lib/). This allows us to remove the dependency on deep-equal which was causing an unintended increase in bundle size for users of turf-helpers. Updated boolean-equal and boolean-overlap to use geojson-equality-ts directly.

* Removing keepNames from tsup config.

---------

Co-authored-by: Tim Welch <[email protected]>
  • Loading branch information
smallsaucepan and twelch authored Jun 25, 2024
1 parent 3616782 commit 0ce6ecc
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 1,326 deletions.
7 changes: 4 additions & 3 deletions packages/turf-boolean-equal/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Feature, Geometry } from "geojson";
import { GeojsonEquality } from "@turf/helpers";
import { geojsonEquality } from "geojson-equality-ts";
import { cleanCoords } from "@turf/clean-coords";
import { getGeom } from "@turf/invariant";

Expand Down Expand Up @@ -45,8 +45,9 @@ function booleanEqual(
const type2 = getGeom(feature2).type;
if (type1 !== type2) return false;

const equality = new GeojsonEquality({ precision: precision });
return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
return geojsonEquality(cleanCoords(feature1), cleanCoords(feature2), {
precision,
});
}

export { booleanEqual };
Expand Down
1 change: 1 addition & 0 deletions packages/turf-boolean-equal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@turf/clean-coords": "workspace:^",
"@turf/helpers": "workspace:^",
"@turf/invariant": "workspace:^",
"geojson-equality-ts": "^1.0.2",
"tslib": "^2.6.2"
}
}
6 changes: 3 additions & 3 deletions packages/turf-boolean-overlap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { segmentEach } from "@turf/meta";
import { getGeom } from "@turf/invariant";
import { lineOverlap } from "@turf/line-overlap";
import { lineIntersect } from "@turf/line-intersect";
import { GeojsonEquality } from "@turf/helpers";
import { geojsonEquality } from "geojson-equality-ts";

/**
* Compares two geometries of the same dimension and returns true if their intersection set results in a geometry
Expand Down Expand Up @@ -49,8 +49,8 @@ function booleanOverlap(
if (type1 === "Point") throw new Error("Point geometry not supported");

// features must be not equal
const equality = new GeojsonEquality({ precision: 6 });
if (equality.compare(feature1 as any, feature2 as any)) return false;
if (geojsonEquality(feature1 as any, feature2 as any, { precision: 6 }))
return false;

let overlap = 0;

Expand Down
1 change: 1 addition & 0 deletions packages/turf-boolean-overlap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"@turf/line-intersect": "workspace:^",
"@turf/line-overlap": "workspace:^",
"@turf/meta": "workspace:^",
"geojson-equality-ts": "^1.0.2",
"tslib": "^2.6.2"
}
}
1 change: 0 additions & 1 deletion packages/turf-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {

import { Id } from "./lib/geojson.js";
export * from "./lib/geojson.js";
export * from "./lib/geojson-equality.js";

// TurfJS Combined Types
export type Coord = Feature<Point> | Point | Position;
Expand Down
198 changes: 0 additions & 198 deletions packages/turf-helpers/lib/geojson-equality.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/turf-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
},
"devDependencies": {
"@types/benchmark": "^2.1.5",
"@types/deep-equal": "^1.0.4",
"@types/tape": "^4.2.32",
"benchmark": "^2.1.4",
"npm-run-all": "^4.1.5",
Expand All @@ -69,7 +68,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"deep-equal": "^2.2.3",
"tslib": "^2.6.2"
}
}
Loading

0 comments on commit 0ce6ecc

Please sign in to comment.