Skip to content

Commit

Permalink
Removing hacky cjs/esm export/import wrappers in favour of defaultImp…
Browse files Browse the repository at this point in the history
…ort library which takes care of finding the correct default to import from CJS packages.
  • Loading branch information
smallsaucepan committed Mar 11, 2024
1 parent 519aca9 commit f8184c3
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 33 deletions.
6 changes: 5 additions & 1 deletion packages/turf-clusters-dbscan/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { GeoJsonProperties, FeatureCollection, Point } from "geojson";
import { clone } from "@turf/clone";
import { distance } from "@turf/distance";
import { degreesToRadians, lengthToDegrees, Units } from "@turf/helpers";
import { rbush as RBush } from "./lib/rbush-export.js";
import { defaultImport } from "default-import";
import rbush from "rbush";

// Use defaultImport to get correct default from CJS module.
const RBush = defaultImport(rbush);

type Dbscan = "core" | "edge" | "noise";
type DbscanProps = GeoJsonProperties & {
Expand Down
7 changes: 0 additions & 7 deletions packages/turf-clusters-dbscan/lib/rbush-export.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/turf-clusters-dbscan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"@turf/distance": "workspace:^",
"@turf/helpers": "workspace:^",
"@turf/meta": "workspace:^",
"default-import": "^1.1.5",
"rbush": "^3.0.1",
"tslib": "^2.6.2"
}
Expand Down
8 changes: 6 additions & 2 deletions packages/turf-collect/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { FeatureCollection, Polygon, Point } from "geojson";
import { bbox as turfbbox } from "@turf/bbox";
import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
import { rbush } from "./lib/rbush-export.js";
import { defaultImport } from "default-import";
import rbush from "rbush";

// Use defaultImport to get correct default from CJS module.
const RBush = defaultImport(rbush);

interface Entry {
minX: number;
Expand Down Expand Up @@ -47,7 +51,7 @@ function collect(
inProperty: string,
outProperty: string
): FeatureCollection<Polygon> {
var rtree = new rbush<Entry>(6);
var rtree = new RBush<Entry>(6);

var treeItems = points.features.map(function (item) {
return {
Expand Down
7 changes: 0 additions & 7 deletions packages/turf-collect/lib/rbush-export.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/turf-collect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"@turf/bbox": "workspace:^",
"@turf/boolean-point-in-polygon": "workspace:^",
"@turf/helpers": "workspace:^",
"default-import": "^1.1.5",
"rbush": "^3.0.1",
"tslib": "^2.6.2"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/turf-kinks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
Polygon,
} from "geojson";
import { point } from "@turf/helpers";
import { sweeplineIntersections as findIntersections } from "./lib/sweepline-intersections-export.js";
import { defaultImport } from "default-import";
import sweeplineIntersections from "sweepline-intersections";

// Use defaultImport to get correct default from CJS module.
const findIntersections = defaultImport(sweeplineIntersections);

/**
* Takes a {@link LineString|linestring}, {@link MultiLineString|multi-linestring},
Expand Down
7 changes: 0 additions & 7 deletions packages/turf-kinks/lib/sweepline-intersections-export.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/turf-kinks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
},
"dependencies": {
"@turf/helpers": "workspace:^",
"default-import": "^1.1.5",
"sweepline-intersections": "^1.5.0",
"tslib": "^2.6.2"
}
Expand Down
6 changes: 5 additions & 1 deletion packages/turf-line-intersect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import {
Point,
Polygon,
} from "geojson";
import { defaultImport } from "default-import";
import type { Intersection } from "sweepline-intersections";
import { sweeplineIntersections as findIntersections } from "./lib/sweepline-intersections-export.js";
import sweeplineIntersections from "sweepline-intersections";

// Use defaultImport to get correct default from CJS module.
const findIntersections = defaultImport(sweeplineIntersections);

/**
* Takes any LineString or Polygon GeoJSON and returns the intersecting point(s).
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions packages/turf-line-intersect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},
"dependencies": {
"@turf/helpers": "workspace:^",
"default-import": "^1.1.5",
"sweepline-intersections": "^1.5.0",
"tslib": "^2.6.2"
}
Expand Down
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8184c3

Please sign in to comment.