Skip to content

Conversation

@smallsaucepan
Copy link
Member

Changed multiple build and test processes to enable dev and testing (as maintainers) without having to build to ESM+CJS Javascript first.

In short:

  • heading in the direction of TS composite builds, which require capturing more explicit inter package dependencies so that eventually TS can work its magic with incremental builds and the like
  • each packages gets one or two new tsconfig files - one for building and one for type testing - and a tsup config file. There are a lot of them, though they are almost exclusively automatically generated (by monorepolint
  • thus able to remove the build pre-requisite from the test target - test TS directly, including dependent packages
  • updated some tsconfig options such as module and moduleResolution, though kept target at es2017 to be cautious between major versions

Vastly reduces the amount of uncessary JS we need to compile to test TS code. Developer workflow can be as quick as:

  • git clone ...
  • cd turf/
  • pnpm install
  • cd packages/turf-whatever/ - and edit a TS file to fix a bug
  • pnpm test - to run only that package's unit tests (and type tests if they exist)
  • cd ../.. && pnpm test - to run unit and type tests for all packages

Shouldn't result in the generation of a single line of Javascript!

To eventually generate JS for publishing there are new top level targets prerelease and release. Part of this PR review can be deciding what a ci target needs to do as well.

File by file checks on the contents of dist/ indicate no changes to generated ESM or CJS other than a handful of lines removed because we were able to remove an old node16 shim. Debugging map file symbols do change though that's somewhat expected.

Scaffolding changes committed first, and then the generated files separately to help with reviewing.

Please provide the following when creating a PR:

  • Meaningful title, including the name of the package being modified.
  • Summary of the changes.
  • Heads up if this is a breaking change.
  • Any issues this resolves.
  • Inclusion of your details in the contributors field of package.json - you've earned it! 👏
  • Confirmation you've read the steps for preparing a pull request.

…ete with esnext/bundler upgrade. Produces identical dist/ output (except for a few .cjs.map files) as the current build.
… tsup.config.ts files that include auto-generated project references where required. Several TS and JS specific template files added.

Had to stop prettier from checking those files though as the formats clashed.
Updated nx dependency to not require package build before test.
Added earcut DT types to turf-tesselate in order to retire local earcut.d.ts and keep tsconfig.json generation simple.
tsup now refers to per-package tsup.config.ts (and from there per-package tsconfig.build.json)
Full list of package paths listed in tsconfig.shared.json (manually maintained at the moment).
… new prerelease top level target.

Separated other top level targets to build only what we need for each npm lifecycle phase.
Replaced skipNodeModulesBundle with declaring all @turf/ libraries as external so tsup wouldn't bundle a package's dependencies in with it.
escheck moves from lint:* to it's own thing so we can lint during dev without needing JS build to escheck. It still gets run automatically before a release takes place.
Dropped a clumsy sweepline-intersections re-re-export shim that was tied to previous moduleResolution: node16
Added tsconfig.types.json for types.ts entry points to relevant projects.
"erasableSyntaxOnly": true,
"composite": true,
"allowImportingTsExtensions": true,
"outDir": "dist",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm kind of surprised this doesn't need to be "${configDir}/dist", but it seems to work 🤷

"escheck": "pnpm run /escheck:.*/",
"escheck:cjs": "es-check es8 packages/*/dist/cjs/index.cjs packages/turf/turf.min.js",
"escheck:esm": "es-check --module es8 packages/*/dist/esm/index.js",
"escheck:web": "es-check es5 packages/turf/turf.min.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

lmao we're still shipping es5 turf.min.js. That should definitely get bumped way forward.
#2989

"release": "pnpm run test:release && pnpm publish -r",
"rollup": "lerna run --scope @turf/turf rollup",
"test": "pnpx lerna run test",
"test:release": "pnpm run lint && pnpm run escheck && lerna run --scope @turf/turf last-checks"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be in favor of just keeping this all one test script, instead of breaking it out differently for releases.
We can probably entirely get rid of the escheck step once we swap TypeScript to targeting esnext.

} from "geojson";
import type { Intersection } from "sweepline-intersections";
import { sweeplineIntersections as findIntersections } from "./lib/sweepline-intersections-export.js";
import findIntersections from "sweepline-intersections";
Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't realize this shim stuff was still around. 🧹

splitting: true,
external: [
/^@turf\//, // Externalize all @turf workspace packages
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this required to basically reverse the paths changes when we're doing the tsup step?
They should be already excluded by default if I'm reading the docs right.

https://tsup.egoist.dev/#excluding-packages

"include": [
"index.ts",
"lib/**/*.ts"
],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can just be moved into tsconfig.shared.json like so:

"include": [
  "${configDir}/index.ts",
  "${configDir}/lib/**/*.ts"
]

Copy link
Member Author

Choose a reason for hiding this comment

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

Will give it a try.

{
"extends": "./tsconfig.json",
"compilerOptions": {
"composite": false
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little surprised you can't use the default tsconfig.json for the build step as well.
It might be a little extra work if you do the build step in every package as it will re-check any shared dependencies have already been built, but I think that a build of @turf/turf should just recursively build all packages for free if we're doing it in CI.

@smallsaucepan smallsaucepan marked this pull request as draft January 1, 2026 02:00
@smallsaucepan
Copy link
Member Author

Putting this on ice until we convert remaining JS in turf packages. Otherwise adding in complexity only to remove it again in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants