Skip to content

Commit

Permalink
Migration to pnpm and improved exports strategy (#2555)
Browse files Browse the repository at this point in the history
* Moving to pnpm as package manager. Also taking the opportunity to tidy up our cjs / esm situation using tsup (instead of tsc and rollup). Can't get monorepolint to work with new setup so disabling for the time being.

* Changing all Turf imports to use named imports. Adding a few missing named exports. Updating github workflow actions to pnpm instead of yarn.

* Updating typescript module and moduleResolution mechanisms to "node16". Not tracking nodenext just yet. Changing tsup command to generate d.ts files that arethetypeswrong approves of.

* Tweaking github workflows to explicitely install pnpm.

* Looks like node needs the chosen cache binary installed first. Trying without cache as a first step.

* Seem to be hitting the tsx bug described here: privatenumber/tsx#421 Upgrading to latest tsx to remedy.

* Forgot to update lock file after updating tsx dep in package.json files.

* Sorting modules exported from @turf/turf alphabetically. Preparatory commit to add unexported modules.

* Converting index.mjs to typescript, and simplifying re-exported imports, and ordering alphabetically. Added in a couple of packages - convex, booleanValid and nearestNeighbourAnalysis. Rollup now only used in packages/turf so merging project root base config into there. Also now only using rollup in packages/turf to do final conversion to web module. JS and d.ts files generated the same as other modules, using tsup.

* Including tslib in @turf/turf build now that it's a TS module.

* Lot of per-package tsconfig items now on the tsup command line, so stripping back tsconfig.json to the bare minimum. Adding tsconfig.json to packages that while still only JS, are now processed by tsup.

* Same as last commit - simplifying tsconfig.json - except these are the subset of packages that had multiple entry points e.g. 3rd party code hosted locally in lib/

* Incorporating some suggestions from @favna on being more explicit with d.ts entries. #2307 (comment)  Specifying overall module type as commonjs explicitly.

* Reapplying cjsInterop / splitting workaround for CJS exports that we had on build target command line earlier in this PR in to tsup config file. Also disabling treeshaking as this was generating a warning for CJS files and causing the workaround above to not work.

* Upgrading rollup and related plugins. Updating to recommended modern browserslist config in babel.config.json e.g. previous chrome 67 and edge 17 are 5 years old, ie11 is just ... ugh

* Fluffed the browserslist config - need to cover es5 as well.

* Update .github/workflows/turf.yml to use actions/checkout v4.

Co-authored-by: Jeroen Claassens <[email protected]>

---------

Co-authored-by: Jeroen Claassens <[email protected]>
  • Loading branch information
smallsaucepan and favna authored Dec 18, 2023
1 parent d83e580 commit 4ea81e6
Show file tree
Hide file tree
Showing 398 changed files with 20,868 additions and 14,023 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/turf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ jobs:
node-version: [16.x, 18.x, 20.x]

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "yarn"

- run: yarn --frozen-lockfile
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
run_install: false

- run: pnpm install --frozen-lockfile
- run: git diff --exit-code
- run: yarn test
- run: pnpm test
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ packages/turf-*/test/in/**
packages/turf-*/test/out/**
packages/turf-*/test/true/**
packages/turf-*/test/false/**

pnpm-lock.yaml
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmClient": "yarn",
"npmClient": "pnpm",
"version": "7.0.0-alpha.2",
"command": {
"publish": {
Expand Down
24 changes: 10 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"funding": "https://opencollective.com/turf",
"scripts": {
"lint": "npm-run-all lint:*",
"lint:eslint": "eslint packages",
"lint:prettier": "prettier --check .",
"lint:mrl": "mrl check",
"lint:escheck-require": "es-check es8 packages/*/dist/js/index.js packages/turf/turf.min.js",
"lint:escheck-esm": "es-check --module es8 packages/*/dist/es/index.js",
"lint:escheck-es5": "es-check es5 packages/turf/turf.min.js",
"postlint": "documentation lint packages/turf-*/index.js",
"prepare": "lerna run build && node ./scripts/add-import-extensions.js",
"pretest": "npm run lint",
"test": "lerna run test",
"posttest": "lerna run --scope @turf/turf last-checks",
"lintDISABLED:mrl": "mrl check",
"lint:escheck-cjs": "es-check es8 packages/*/dist/cjs/index.cjs packages/turf/turf.min.js",
"lint:escheck-esm": "es-check --module es8 packages/*/dist/esm/index.mjs",
"lint:escheck-web": "es-check es5 packages/turf/turf.min.js",
"lint:docs": "documentation lint packages/turf-*/index.js packages/turf-*/index.mjs",
"preinstall": "npx only-allow pnpm",
"prepare": "lerna run build",
"test": "pnpm run lint && lerna run test && lerna run --scope @turf/turf last-checks",
"docs": "tsx ./scripts/generate-readmes.ts"
},
"husky": {
Expand Down Expand Up @@ -63,9 +59,9 @@
"npm-run-all": "^4.1.5",
"prettier": "^3.0.3",
"progress": "^2.0.3",
"rollup": "^2.79.1",
"ts-node": "^9.0.0",
"tsx": "^3.14.0",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.2.2",
"yamljs": "^0.3.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/turf-along/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Feature, LineString, Point } from "geojson";
import bearing from "@turf/bearing";
import destination from "@turf/destination";
import measureDistance from "@turf/distance";
import { bearing } from "@turf/bearing";
import { destination } from "@turf/destination";
import { distance as measureDistance } from "@turf/distance";
import { point, Units } from "@turf/helpers";
import { getGeom } from "@turf/invariant";

Expand Down
35 changes: 20 additions & 15 deletions packages/turf-along/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,30 @@
"turf",
"distance"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"type": "commonjs",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/js/index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
}
}
},
"types": "dist/js/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"bench": "tsx bench.ts",
"build": "npm-run-all --npm-path npm build:*",
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
"build:js": "tsc",
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
Expand All @@ -54,15 +58,16 @@
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.2.2"
},
"dependencies": {
"@turf/bearing": "^7.0.0-alpha.2",
"@turf/destination": "^7.0.0-alpha.2",
"@turf/distance": "^7.0.0-alpha.2",
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/invariant": "^7.0.0-alpha.2",
"@turf/bearing": "workspace:^",
"@turf/destination": "workspace:^",
"@turf/distance": "workspace:^",
"@turf/helpers": "workspace:^",
"@turf/invariant": "workspace:^",
"tslib": "^2.6.2"
}
}
6 changes: 1 addition & 5 deletions packages/turf-along/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"],
"extends": "../../tsconfig.shared.json"
}
4 changes: 2 additions & 2 deletions packages/turf-angle/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bearing from "@turf/bearing";
import { bearing } from "@turf/bearing";
import { bearingToAzimuth, Coord, isObject } from "@turf/helpers";
import rhumbBearing from "@turf/rhumb-bearing";
import { rhumbBearing } from "@turf/rhumb-bearing";

/**
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)
Expand Down
39 changes: 22 additions & 17 deletions packages/turf-angle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,55 @@
"turf",
"angle"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"type": "commonjs",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/js/index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
}
}
},
"types": "dist/js/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"bench": "tsx bench.ts",
"build": "npm-run-all --npm-path npm build:*",
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
"build:js": "tsc",
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
},
"devDependencies": {
"@turf/distance": "^7.0.0-alpha.2",
"@turf/sector": "^7.0.0-alpha.2",
"@turf/truncate": "^7.0.0-alpha.2",
"@turf/distance": "workspace:^",
"@turf/sector": "workspace:^",
"@turf/truncate": "workspace:^",
"@types/benchmark": "^2.1.5",
"@types/tape": "^4.2.32",
"benchmark": "^2.1.4",
"glob": "^10.3.10",
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.2.2",
"write-json-file": "^5.0.0"
},
"dependencies": {
"@turf/bearing": "^7.0.0-alpha.2",
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/invariant": "^7.0.0-alpha.2",
"@turf/rhumb-bearing": "^7.0.0-alpha.2",
"@turf/bearing": "workspace:^",
"@turf/helpers": "workspace:^",
"@turf/invariant": "workspace:^",
"@turf/rhumb-bearing": "workspace:^",
"tslib": "^2.6.2"
}
}
2 changes: 1 addition & 1 deletion packages/turf-angle/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import path from "path";
import { glob } from "glob";
import { loadJsonFileSync } from "load-json-file";
import { writeJsonFileSync } from "write-json-file";
import sector from "@turf/sector";
import { sector } from "@turf/sector";
import { bearing } from "@turf/bearing";
import { truncate } from "@turf/truncate";
import { distance } from "@turf/distance";
Expand Down
6 changes: 1 addition & 5 deletions packages/turf-angle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"]
"extends": "../../tsconfig.shared.json"
}
29 changes: 17 additions & 12 deletions packages/turf-area/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@
"polygon",
"multipolygon"
],
"main": "dist/js/index.js",
"module": "dist/es/index.js",
"type": "commonjs",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
"types": "dist/cjs/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/js/index.d.ts",
"import": "./dist/es/index.js",
"require": "./dist/js/index.js"
"import": {
"types": "./dist/esm/index.d.mts",
"default": "./dist/esm/index.mjs"
},
"require": {
"types": "./dist/cjs/index.d.ts",
"default": "./dist/cjs/index.cjs"
}
}
},
"types": "dist/js/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"bench": "tsx bench.ts",
"build": "npm-run-all --npm-path npm build:*",
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
"build:js": "tsc",
"build": "tsup --config ../../tsup.config.ts",
"docs": "tsx ../../scripts/generate-readmes.ts",
"test": "npm-run-all --npm-path npm test:*",
"test:tape": "tsx test.ts"
Expand All @@ -53,13 +57,14 @@
"load-json-file": "^7.0.1",
"npm-run-all": "^4.1.5",
"tape": "^5.7.2",
"tsx": "^3.14.0",
"tsup": "^8.0.1",
"tsx": "^4.6.2",
"typescript": "^5.2.2",
"write-json-file": "^5.0.0"
},
"dependencies": {
"@turf/helpers": "^7.0.0-alpha.2",
"@turf/meta": "^7.0.0-alpha.2",
"@turf/helpers": "workspace:^",
"@turf/meta": "workspace:^",
"tslib": "^2.6.2"
}
}
6 changes: 1 addition & 5 deletions packages/turf-area/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"extends": "../../tsconfig.shared.json",
"compilerOptions": {
"outDir": "dist/js"
},
"files": ["index.ts"]
"extends": "../../tsconfig.shared.json"
}
12 changes: 6 additions & 6 deletions packages/turf-bbox-clip/lib/lineclip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ function intersect(
return edge & 8
? [a[0] + ((b[0] - a[0]) * (bbox[3] - a[1])) / (b[1] - a[1]), bbox[3]] // top
: edge & 4
? [a[0] + ((b[0] - a[0]) * (bbox[1] - a[1])) / (b[1] - a[1]), bbox[1]] // bottom
: edge & 2
? [bbox[2], a[1] + ((b[1] - a[1]) * (bbox[2] - a[0])) / (b[0] - a[0])] // right
: edge & 1
? [bbox[0], a[1] + ((b[1] - a[1]) * (bbox[0] - a[0])) / (b[0] - a[0])] // left
: null;
? [a[0] + ((b[0] - a[0]) * (bbox[1] - a[1])) / (b[1] - a[1]), bbox[1]] // bottom
: edge & 2
? [bbox[2], a[1] + ((b[1] - a[1]) * (bbox[2] - a[0])) / (b[0] - a[0])] // right
: edge & 1
? [bbox[0], a[1] + ((b[1] - a[1]) * (bbox[0] - a[0])) / (b[0] - a[0])] // left
: null;
}

// bit code reflects the point position relative to the bbox:
Expand Down
Loading

0 comments on commit 4ea81e6

Please sign in to comment.