Title: Only look up package.json type if module is node16/nodenext or file is in node_modules by andrewbranch · Pull Request #58825 · microsoft/TypeScript · GitHub
Open Graph Title: Only look up package.json type if module is node16/nodenext or file is in node_modules by andrewbranch · Pull Request #58825 · microsoft/TypeScript
X Title: Only look up package.json type if module is node16/nodenext or file is in node_modules by andrewbranch · Pull Request #58825 · microsoft/TypeScript
Description: This walks back the heuristics added to non-Node.js module modes in #57896 a bit, based mostly on feedback in #58663. In 5.5-beta, an explicit package.json "type" or module-format-specific file extension started overriding "module": "commonjs" or "module": "esnext" in tsconfig.json. This impacted both type checking (relevant primarily for imports of node_modules dependencies, but with some effects on local files, e.g. with verbatimModuleSyntax) and emit (relevant for local project source files, if emit was enabled). The feedback in #58663 was that the effects on local files were unwelcome because the emitted files (whether from tsc or another tool) were going to be placed in some other context tsc didn’t know about, so the package.json tsc was finding during compilation shouldn’t be considered during the build. With this PR, we only look up package.json "type" if --module is node16/nodenext (as we’ve always done) or if the file is inside node_modules. Some testing and experimentation is still needed to ensure this doesn’t create inconsistencies with symlinked monorepos. This doesn’t seem to cause inconsistencies with workspaces-style monorepos, because module resolution takes the realpath of files in node_modules before we see if we need to look up a package.json "type". So in a project references example like . └── packages/ ├── app/ │ ├── node_modules/shared ↪︎ │ ├── tsconfig.json │ ├── package.json │ └── index.ts └── shared/ ├── dist/index.d.ts ├── src/index.ts ├── tsconfig.json └── package.json When we build shared/tsconfig.json, we decide that shared/src/index.ts is not inside node_modules. Then, when we build app/tsconfig.json, even though we resolve app/node_modules/shared/dist/index.d.ts, we realpath it to shared/dist/index.d.ts and count it as not inside node_modules. Having this consistency between input and output files regardless of how they’re resolved is what matters most. The caveat is that the realpath and project references logic can cause the type checking of app/tsconfig.json during development to behave differently than it would after publishing/deploying into a situation where app/node_modules/shared is no longer a symlink, but a real node_modules package. Fixes #54752 Fixes #50647
Open Graph Description: This walks back the heuristics added to non-Node.js module modes in #57896 a bit, based mostly on feedback in #58663. In 5.5-beta, an explicit package.json "type" or module-format-specifi...
X Description: This walks back the heuristics added to non-Node.js module modes in #57896 a bit, based mostly on feedback in #58663. In 5.5-beta, an explicit package.json "type" or module-format...
Opengraph URL: https://github.com/microsoft/TypeScript/pull/58825
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:60f459f7-c799-aa91-3617-a8a8b1778a4a |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E7CC:253796:3958A5E:4E1B1F1:6A5DECF6 |
| html-safe-nonce | 6baefd9746e238f801e7f00734dde6dbe76f2d37c8d7ea080a158dd2526e8a25 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0NDOjI1Mzc5NjozOTU4QTVFOjRFMUIxRjE6NkE1REVDRjYiLCJ2aXNpdG9yX2lkIjoiNzUwODY3ODY4NTg0NTQ4Mjc0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c71c5cd484f5a0a4bd88ab0f9188a6a57f06367845a01870f72f2847447a29cb |
| hovercard-subject-tag | pull_request:1913239815 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/microsoft/TypeScript/pull/58825/files |
| twitter:image | https://avatars.githubusercontent.com/u/3277153?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/3277153?s=400&v=4 |
| og:image:alt | This walks back the heuristics added to non-Node.js module modes in #57896 a bit, based mostly on feedback in #58663. In 5.5-beta, an explicit package.json "type" or module-format-specifi... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8e8f322dc74b1a8d5bafb296008dbb96bb4a0bc6ee2d6f30844ab111697c520d |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7ae00b343090b49d0d18b8184187f51a39ed917c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width