Title: Establish a package.json convention for Typescript source in monorepos and npm packages · Issue #51750 · microsoft/TypeScript · GitHub
Open Graph Title: Establish a package.json convention for Typescript source in monorepos and npm packages · Issue #51750 · microsoft/TypeScript
X Title: Establish a package.json convention for Typescript source in monorepos and npm packages · Issue #51750 · microsoft/TypeScript
Description: Suggestion Establish a convention for a field in package.json that will to point to Typescript source code, respected as an override by tsc, for IDE and downstream build tooling. 🔍 Search Terms List of keywords you searched for before cr...
Open Graph Description: Suggestion Establish a convention for a field in package.json that will to point to Typescript source code, respected as an override by tsc, for IDE and downstream build tooling. 🔍 Search Terms Lis...
X Description: Suggestion Establish a convention for a field in package.json that will to point to Typescript source code, respected as an override by tsc, for IDE and downstream build tooling. 🔍 Search Terms Lis...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/51750
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Establish a package.json convention for Typescript source in monorepos and npm packages","articleBody":"# Suggestion\r\n\r\nEstablish a convention for a field in package.json that will to point to Typescript source code, respected as an override by tsc, for IDE and downstream build tooling.\r\n\r\n## 🔍 Search Terms\r\n\r\nList of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.\r\n\r\nexports typescript index.ts main source package.json\r\n\r\n## ✅ Viability Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [X] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [X] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [X] This could be implemented without emitting different JS based on the types of the expressions\r\n* [X] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)\r\n* [X] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n\r\n## ⭐ Suggestion\r\n\r\nThe tsc tool, through implementing and documenting a specific source import behaviour from package.json fields, could ensure that monorepo authors importing local packages and third-party bundlers importing upstream packages can resolve directly to Typescript source, while allowing package.json metadata to support publishing into the javascript ecosystem through \"main\", \"module\", \"exports\" independently (since they would always use distinct fields from the fields pointing to Typescript source).\r\n \r\nProposals for this new field could be...\r\n\r\n* Introduce a convention for a field in `exports[*][\"import\"]` and `exports[*][\"require\"]` alongside `\"node\"`, `\"browser\"`, `\"default\"` e.g. a `\"typescript\"` or `\"source\"` field.\r\n* Introduce a convention for a field in `exports[*]` alongside `\"import\"` and `\"require\"` - e.g. an `\"import:tsc\"` or `\"compile\"` field.\r\n* Document and support that the top-level `\"types\"` field can be `.ts` and not just `.d.ts`, meaning it can serve both declarations and source\r\n* Document and support that the top-level `\"source\"` field can point to `.ts` and that tsc see will see it as an override of `\"main\"`, `\"module\"`, entries in `\"exports\"` \r\n\r\n## 📃 Motivating Example\r\n\r\nIn a monorepo, using a \"main\" field that resolves directly to a `.ts` path already allows direct resolution of source code. However, this interferes with the primary use case of the \"main\" field - to resolve Javascript. This then demands fragile prepublish and postpublish steps if \"./src/index.ts\" is to be rewritten to \"./dist/index.js\" and back again to fulfil the needs of a publish script. This suggests a distinct field needs to live alongside the Javascript resolution fields, allowing all elements to coexist and be individually addressable within the structure of a package.\r\n\r\n## 💻 Use Cases\r\n\r\n* Within a monorepo having multiple workspaces, they can have \"main\" or \"exports\" fields which point directly to Typescript files, allowing easy hot-reloading and eliminating the need for complex and fragile watches to fulfil e.g. transpiling to the CommonJS artefact pointed to by \"main\", or prepublish/postpublish scripts to rewrite \"main\".\r\n\r\n* Within a downstream project that consumed an npm package following this convention (and including Typescript source) the downstream bundling process could consume source before it had been through any prior bundling process, minimising cruft and increasing the chances of adequate sourcemapping.","author":{"url":"https://github.com/cefn","@type":"Person","name":"cefn"},"datePublished":"2022-12-04T23:51:38Z","url":"https://github.com/microsoft/TypeScript/issues/51750"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a1b244ae-a873-3911-d50b-0742d98f251a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80E8:269AD9:27CD688:35281A3:6B01B0ED |
| html-safe-nonce | 80fe56419ab99ddb08ee8d1aab2266c82b4e3b85130ff107898068fdf4550be4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEU4OjI2OUFEOToyN0NENjg4OjM1MjgxQTM6NkIwMUIwRUQiLCJ2aXNpdG9yX2lkIjoiNDk1OTU4ODExOTc1MjAxMDA1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b9a8b3621903c2b137e46ef99e72a3d8721c0c3f89d72e38119fa528a25d7ae2 |
| hovercard-subject-tag | issue:1475314796 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/51750/issue_layout |
| twitter:image | https://opengraph.githubassets.com/e8bfb78e7c5613bbcdfd6724cafc5a9a5329926e991038e96c4cc846b8c9a754/microsoft/TypeScript/issues/51750 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/e8bfb78e7c5613bbcdfd6724cafc5a9a5329926e991038e96c4cc846b8c9a754/microsoft/TypeScript/issues/51750 |
| og:image:alt | Suggestion Establish a convention for a field in package.json that will to point to Typescript source code, respected as an override by tsc, for IDE and downstream build tooling. 🔍 Search Terms Lis... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | cefn |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width