Deprecate `td.function` in favor of `td.func`

Open
#214 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
30/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, rollup, webpack

Research direction

Start by tracing the current package exports and build setup, then compare how webpack, Rollup, and Browserify handle the proposed ES-module and CommonJS shapes. Done means preserving the intended top-level distribution API and tree shaking, documenting td.func(), and deciding when td.function should be removed in a major release.

Written by the indexing model from the issue text.

Description

Terrible luck to discover this after releasing 2.0.0, but subsequent improvements to the build have made me realize that the cute way we do this:

module.exports = { function: require('./function') /*...*/ }

Just won't fly in ES module-land, where something like this:

export { function }

Will blow up because it's a reserved word. (import {function} from 'testdouble' also blows up)

We can do:

export default {
  function: tdFunction
}

But then any module/bundler like webpack/rollup/browserify is going to have that default tacked onto it, which means that our distribution will be td.default.object or whatever.

I hope we can find some workaround to use ES exports exclusively and then solve this with build cleverness using one of the bundlers, but even if we do manage, having a top-level API that's a reserved word is probably not a great long-term play.

Goals:

  • hack up some short-term win with a bundler that'll let us still get tree shaking while using a CJS export at the top level or a way to modify the bundled content to td = td.default dynamically.
  • documentation change from td.function() to td.func()
  • figure out how soon we want to think about dropping td.function with another major bump.
Dominant language
JavaScript
Stars
1.4k
Forks
140
Avg merge
22h
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testdouble/testdouble.js

All issues in testdouble/testdouble.js

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.