Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to pnpm and improved exports strategy #2555

Merged
merged 17 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
4bbd264
Moving to pnpm as package manager. Also taking the opportunity to tid…
smallsaucepan Dec 10, 2023
deb837b
Changing all Turf imports to use named imports. Adding a few missing …
smallsaucepan Dec 11, 2023
cbefae6
Updating typescript module and moduleResolution mechanisms to "node16…
smallsaucepan Dec 11, 2023
026d32f
Tweaking github workflows to explicitely install pnpm.
smallsaucepan Dec 11, 2023
4cd5560
Looks like node needs the chosen cache binary installed first. Trying…
smallsaucepan Dec 11, 2023
3689752
Seem to be hitting the tsx bug described here: https://github.com/pri…
smallsaucepan Dec 11, 2023
c94040b
Forgot to update lock file after updating tsx dep in package.json files.
smallsaucepan Dec 11, 2023
0fc5e2d
Sorting modules exported from @turf/turf alphabetically. Preparatory …
smallsaucepan Dec 11, 2023
89cc0c5
Converting index.mjs to typescript, and simplifying re-exported impor…
smallsaucepan Dec 13, 2023
477dc61
Including tslib in @turf/turf build now that it's a TS module.
smallsaucepan Dec 13, 2023
afa6b2d
Lot of per-package tsconfig items now on the tsup command line, so st…
smallsaucepan Dec 13, 2023
effc083
Same as last commit - simplifying tsconfig.json - except these are th…
smallsaucepan Dec 13, 2023
faa15c8
Incorporating some suggestions from @favna on being more explicit wit…
smallsaucepan Dec 16, 2023
7234245
Reapplying cjsInterop / splitting workaround for CJS exports that we …
smallsaucepan Dec 16, 2023
1a9e240
Upgrading rollup and related plugins. Updating to recommended modern …
smallsaucepan Dec 17, 2023
d174ad3
Fluffed the browserslist config - need to cover es5 as well.
smallsaucepan Dec 17, 2023
f1c6358
Update .github/workflows/turf.yml to use actions/checkout v4.
smallsaucepan Dec 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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@v3
smallsaucepan marked this conversation as resolved.
Show resolved Hide resolved

- 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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with .ts modules?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean "documentation lint"? Good question. I'll check and we can include turf-*/index.ts as a seperate change.

"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