microsoft / microsoft/TypeScript

Standard package.json key for .ts files

Open
#12,561 9 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Community Tooling Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

A common TypeScript module structure looks like this:

src/index.ts
dist/index.js
dist/index.d.ts

and a package.json that looks like this:

  "main": "dist/index.js",
  "types": "dist/index.d.ts",

There's a convention to use the package.json key jsnext:main to point to a variant of main that uses ES2015 module syntax. Can we develop a similar convention to point at .ts files, e.g. typescript:main?

Consider a TypeScript project that is sharded across many microlibraries (e.g. my-project-core, my-project-thing-plugin, my-project-other-thing-plugin). I'd like to be able to configure my bundler to import from src/*.ts files for any module whose name starts with my-project. Otherwise, it will be looking in dist/*.js and I'll have to rebuild the plugins any time I make changes in them.

Of course, I could use jsnext:main for this purpose now, but any consumers who aren't using TypeScript would get syntax errors for any files that contained TS-specific syntax like types. Similarly, I could make up my own package.json key and configure my bundler to look there first, but it behooves the community to have a convention here. That will allow bundlers like Webpack, Browserify, Rollup, and Pundle to look in the right place by default.

Contributor guide

Open the contributing guide

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.

Research direction

Review the package.json entries shown in the issue, especially main, types, and jsnext:main, then compare how Webpack and Rollup resolve package entry points. Research whether a TypeScript-specific convention has community or bundler support; done means the convention's design and adoption path are clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
rollup, typescript, webpack
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.