Skip to content

Commit 4ea81e6

Browse files
smallsaucepanfavna
andauthored
Migration to pnpm and improved exports strategy (#2555)
* 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 <jeroen.claassens@live.nl> --------- Co-authored-by: Jeroen Claassens <jeroen.claassens@live.nl>
1 parent d83e580 commit 4ea81e6

File tree

398 files changed

+20868
-14023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+20868
-14023
lines changed

.github/workflows/turf.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,20 @@ jobs:
1818
node-version: [16.x, 18.x, 20.x]
1919

2020
steps:
21-
- uses: actions/checkout@v3
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
2224
- name: Use Node.js ${{ matrix.node-version }}
2325
uses: actions/setup-node@v3
2426
with:
2527
node-version: ${{ matrix.node-version }}
26-
cache: "yarn"
2728

28-
- run: yarn --frozen-lockfile
29+
- name: Install pnpm
30+
uses: pnpm/action-setup@v2
31+
with:
32+
version: 8
33+
run_install: false
34+
35+
- run: pnpm install --frozen-lockfile
2936
- run: git diff --exit-code
30-
- run: yarn test
37+
- run: pnpm test

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ packages/turf-*/test/in/**
1717
packages/turf-*/test/out/**
1818
packages/turf-*/test/true/**
1919
packages/turf-*/test/false/**
20+
21+
pnpm-lock.yaml

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"npmClient": "yarn",
2+
"npmClient": "pnpm",
33
"version": "7.0.0-alpha.2",
44
"command": {
55
"publish": {

package.json

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
{
22
"private": true,
3-
"workspaces": [
4-
"packages/*"
5-
],
63
"funding": "https://opencollective.com/turf",
74
"scripts": {
85
"lint": "npm-run-all lint:*",
96
"lint:eslint": "eslint packages",
107
"lint:prettier": "prettier --check .",
11-
"lint:mrl": "mrl check",
12-
"lint:escheck-require": "es-check es8 packages/*/dist/js/index.js packages/turf/turf.min.js",
13-
"lint:escheck-esm": "es-check --module es8 packages/*/dist/es/index.js",
14-
"lint:escheck-es5": "es-check es5 packages/turf/turf.min.js",
15-
"postlint": "documentation lint packages/turf-*/index.js",
16-
"prepare": "lerna run build && node ./scripts/add-import-extensions.js",
17-
"pretest": "npm run lint",
18-
"test": "lerna run test",
19-
"posttest": "lerna run --scope @turf/turf last-checks",
8+
"lintDISABLED:mrl": "mrl check",
9+
"lint:escheck-cjs": "es-check es8 packages/*/dist/cjs/index.cjs packages/turf/turf.min.js",
10+
"lint:escheck-esm": "es-check --module es8 packages/*/dist/esm/index.mjs",
11+
"lint:escheck-web": "es-check es5 packages/turf/turf.min.js",
12+
"lint:docs": "documentation lint packages/turf-*/index.js packages/turf-*/index.mjs",
13+
"preinstall": "npx only-allow pnpm",
14+
"prepare": "lerna run build",
15+
"test": "pnpm run lint && lerna run test && lerna run --scope @turf/turf last-checks",
2016
"docs": "tsx ./scripts/generate-readmes.ts"
2117
},
2218
"husky": {
@@ -63,9 +59,9 @@
6359
"npm-run-all": "^4.1.5",
6460
"prettier": "^3.0.3",
6561
"progress": "^2.0.3",
66-
"rollup": "^2.79.1",
6762
"ts-node": "^9.0.0",
68-
"tsx": "^3.14.0",
63+
"tsup": "^8.0.1",
64+
"tsx": "^4.6.2",
6965
"typescript": "^5.2.2",
7066
"yamljs": "^0.3.0"
7167
}

packages/turf-along/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Feature, LineString, Point } from "geojson";
2-
import bearing from "@turf/bearing";
3-
import destination from "@turf/destination";
4-
import measureDistance from "@turf/distance";
2+
import { bearing } from "@turf/bearing";
3+
import { destination } from "@turf/destination";
4+
import { distance as measureDistance } from "@turf/distance";
55
import { point, Units } from "@turf/helpers";
66
import { getGeom } from "@turf/invariant";
77

packages/turf-along/package.json

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,30 @@
2323
"turf",
2424
"distance"
2525
],
26-
"main": "dist/js/index.js",
27-
"module": "dist/es/index.js",
26+
"type": "commonjs",
27+
"main": "dist/cjs/index.cjs",
28+
"module": "dist/esm/index.mjs",
29+
"types": "dist/cjs/index.d.ts",
2830
"exports": {
2931
"./package.json": "./package.json",
3032
".": {
31-
"types": "./dist/js/index.d.ts",
32-
"import": "./dist/es/index.js",
33-
"require": "./dist/js/index.js"
33+
"import": {
34+
"types": "./dist/esm/index.d.mts",
35+
"default": "./dist/esm/index.mjs"
36+
},
37+
"require": {
38+
"types": "./dist/cjs/index.d.ts",
39+
"default": "./dist/cjs/index.cjs"
40+
}
3441
}
3542
},
36-
"types": "dist/js/index.d.ts",
3743
"sideEffects": false,
3844
"files": [
3945
"dist"
4046
],
4147
"scripts": {
4248
"bench": "tsx bench.ts",
43-
"build": "npm-run-all --npm-path npm build:*",
44-
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
45-
"build:js": "tsc",
49+
"build": "tsup --config ../../tsup.config.ts",
4650
"docs": "tsx ../../scripts/generate-readmes.ts",
4751
"test": "npm-run-all --npm-path npm test:*",
4852
"test:tape": "tsx test.ts"
@@ -54,15 +58,16 @@
5458
"load-json-file": "^7.0.1",
5559
"npm-run-all": "^4.1.5",
5660
"tape": "^5.7.2",
57-
"tsx": "^3.14.0",
61+
"tsup": "^8.0.1",
62+
"tsx": "^4.6.2",
5863
"typescript": "^5.2.2"
5964
},
6065
"dependencies": {
61-
"@turf/bearing": "^7.0.0-alpha.2",
62-
"@turf/destination": "^7.0.0-alpha.2",
63-
"@turf/distance": "^7.0.0-alpha.2",
64-
"@turf/helpers": "^7.0.0-alpha.2",
65-
"@turf/invariant": "^7.0.0-alpha.2",
66+
"@turf/bearing": "workspace:^",
67+
"@turf/destination": "workspace:^",
68+
"@turf/distance": "workspace:^",
69+
"@turf/helpers": "workspace:^",
70+
"@turf/invariant": "workspace:^",
6671
"tslib": "^2.6.2"
6772
}
6873
}

packages/turf-along/tsconfig.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"extends": "../../tsconfig.shared.json",
3-
"compilerOptions": {
4-
"outDir": "dist/js"
5-
},
6-
"files": ["index.ts"],
2+
"extends": "../../tsconfig.shared.json"
73
}

packages/turf-angle/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import bearing from "@turf/bearing";
1+
import { bearing } from "@turf/bearing";
22
import { bearingToAzimuth, Coord, isObject } from "@turf/helpers";
3-
import rhumbBearing from "@turf/rhumb-bearing";
3+
import { rhumbBearing } from "@turf/rhumb-bearing";
44

55
/**
66
* Finds the angle formed by two adjacent segments defined by 3 points. The result will be the (positive clockwise)

packages/turf-angle/package.json

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,50 +23,55 @@
2323
"turf",
2424
"angle"
2525
],
26-
"main": "dist/js/index.js",
27-
"module": "dist/es/index.js",
26+
"type": "commonjs",
27+
"main": "dist/cjs/index.cjs",
28+
"module": "dist/esm/index.mjs",
29+
"types": "dist/cjs/index.d.ts",
2830
"exports": {
2931
"./package.json": "./package.json",
3032
".": {
31-
"types": "./dist/js/index.d.ts",
32-
"import": "./dist/es/index.js",
33-
"require": "./dist/js/index.js"
33+
"import": {
34+
"types": "./dist/esm/index.d.mts",
35+
"default": "./dist/esm/index.mjs"
36+
},
37+
"require": {
38+
"types": "./dist/cjs/index.d.ts",
39+
"default": "./dist/cjs/index.cjs"
40+
}
3441
}
3542
},
36-
"types": "dist/js/index.d.ts",
3743
"sideEffects": false,
3844
"files": [
3945
"dist"
4046
],
4147
"scripts": {
4248
"bench": "tsx bench.ts",
43-
"build": "npm-run-all --npm-path npm build:*",
44-
"build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
45-
"build:js": "tsc",
49+
"build": "tsup --config ../../tsup.config.ts",
4650
"docs": "tsx ../../scripts/generate-readmes.ts",
4751
"test": "npm-run-all --npm-path npm test:*",
4852
"test:tape": "tsx test.ts"
4953
},
5054
"devDependencies": {
51-
"@turf/distance": "^7.0.0-alpha.2",
52-
"@turf/sector": "^7.0.0-alpha.2",
53-
"@turf/truncate": "^7.0.0-alpha.2",
55+
"@turf/distance": "workspace:^",
56+
"@turf/sector": "workspace:^",
57+
"@turf/truncate": "workspace:^",
5458
"@types/benchmark": "^2.1.5",
5559
"@types/tape": "^4.2.32",
5660
"benchmark": "^2.1.4",
5761
"glob": "^10.3.10",
5862
"load-json-file": "^7.0.1",
5963
"npm-run-all": "^4.1.5",
6064
"tape": "^5.7.2",
61-
"tsx": "^3.14.0",
65+
"tsup": "^8.0.1",
66+
"tsx": "^4.6.2",
6267
"typescript": "^5.2.2",
6368
"write-json-file": "^5.0.0"
6469
},
6570
"dependencies": {
66-
"@turf/bearing": "^7.0.0-alpha.2",
67-
"@turf/helpers": "^7.0.0-alpha.2",
68-
"@turf/invariant": "^7.0.0-alpha.2",
69-
"@turf/rhumb-bearing": "^7.0.0-alpha.2",
71+
"@turf/bearing": "workspace:^",
72+
"@turf/helpers": "workspace:^",
73+
"@turf/invariant": "workspace:^",
74+
"@turf/rhumb-bearing": "workspace:^",
7075
"tslib": "^2.6.2"
7176
}
7277
}

packages/turf-angle/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from "path";
33
import { glob } from "glob";
44
import { loadJsonFileSync } from "load-json-file";
55
import { writeJsonFileSync } from "write-json-file";
6-
import sector from "@turf/sector";
6+
import { sector } from "@turf/sector";
77
import { bearing } from "@turf/bearing";
88
import { truncate } from "@turf/truncate";
99
import { distance } from "@turf/distance";

0 commit comments

Comments
 (0)