Handle optional compat patch failures for TypeScript 7 - #7190
Conversation
|
Thanks for this. Bounding the patch to The TypeScript 7.0 RC announcement recommends a side-by-side install that aliases {
"devDependencies": {
"typescript": "npm:@typescript/typescript6@^6.0.0",
"typescript-7": "npm:typescript@rc"
}
}
Repro on # .yarnrc.yml
nodeLinker: node-modules{ "devDependencies": { "typescript": "npm:@typescript/typescript6@^6.0.0" } }
Two more robust options, either of which also covers the alias case:
(1) is the precise fix; (2) is good defense-in-depth and matches what the docs say Happy to help if you want it! |
|
I think the optional qualifier being ignored is a proper bug to fix, yeah - also something curious in the current PR, it seems to be breaking a test 🤔 |
|
Thanks @maik-bol and @arcanis , that makes sense. I updated the PR to address this in two layers:
I also added coverage for the alias case from the TS 7 recommendation: {
"typescript": "npm:@typescript/typescript6@^6.0.0"
}So this should cover both direct On the CI failure: |
Co-authored-by: Cursor <cursoragent@cursor.com>
1c09061 to
ce3dafd
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
Amazing work, thanks for the effort! |
|
Really hope this gets merged sooner rather than later – would be absurd if Typescript 7.0 drops this week and Yarn users can't use it, not because it can't be fixed, but because it just hasn't been prioritised.
|
|
@arcanis would you please take a look? any issues with the PR? |
|
@arcanis any plan to release this? |
|
Just released in 4.17.1, thanks for your patience 🙏 |
|
Seems like there is still an issue with the recommended side by side install. |
## Summary - Bound the generated TypeScript compatibility patch to TypeScript versions before 7.0.0, and committed the matching generated patch artifact so the compat patch generator stays reproducible. - Fixed optional patch handling so `optional!` patches fall back when a package no longer ships a target file (for example `lib/_tsc.js` in TypeScript 7 / TypeScript compatibility shims), instead of failing the install with `ENOENT`. - Added regression coverage for both direct `typescript@7.0.1-rc` installs and the TypeScript 7 side-by-side recommendation where the `typescript` ident aliases to `npm:@typescript/typescript6@^6.0.0`. - Stabilized the scoped `plugin-typescript` acceptance test by moving it from `@babel/traverse` (now reported by npm search metadata as having included types) to a fixture package that still exercises DefinitelyTyped scoped package insertion. - Added deferred version metadata for the changed workspaces. ## Test plan - `yarn workspace @yarnpkg/plugin-compat test:plugin-compat` - `yarn test:unit packages/plugin-patch` - `node ./scripts/run-yarn.js test:integration packages/acceptance-tests/pkg-tests-specs/sources/plugins/plugin-typescript.test.ts` - `yarn version check` ## Notes TypeScript 7 ships a native compiler package layout and no longer has the legacy JS compiler files patched by the existing PnP compatibility diff, such as `lib/_tsc.js`. Bounding the TypeScript compat patch makes this intent explicit, while the optional patch fallback fixes the broader bug that `optional!` patch failures caused by missing target files were still fatal. TypeScript 7 support should ship with microsoft/typescript-go#1966. Made with Cursor --------- Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: John Doe <you@example.com> Co-authored-by: Maël Nison <mael.nison@mistral.ai>
the upgrade to yarn 4.17.1 is necessary as a bug with installing typescript v7 has been fixed: yarnpkg/berry#7190 the double-installation is necessary, as typescript v7 does not have an API yet, thus typescript-eslint otherwise could not use it: typescript-eslint/typescript-eslint#10940 & https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/#running-side-by-side-with-typescript-6.0
## Description of the change TypeScript 7 is [officially out today](https://devblogs.microsoft.com/typescript/announcing-typescript-7-0/) and this PR gets us on board with its super-speedy goodness. TS7 introduces a new `tsc` implementation written in go, which on my machine reduces `nx typecheck staff`'s runtime from over a minute to 15-20 seconds. Here are the changes that were required: * This PR is stacked on Recidiviz/recidiviz-dashboards#14630 to get us nx 22, which fixed a path resolution bug: ts7 removed baseUrl as a tsconfig option in favor of anchoring all path aliases directly. * Upgraded yarn to let it install ts7 cleanly (yarnpkg/berry#7190) * Exempted typescript 7.0.2 from the yarn age gate because this is a known, high-profile release with big upside * Replaced nxViteTsPaths() with vite-tsconfig-paths: the former is deprecated in nx 22 and shares the aforementioned baseUrl issue. The new package also doesn't need the big list of asset extensions we had to add in the nx 22 upgrade pr. * Changed moduleResolution from node to bundler: ts7 doesn't support the former, and the latter better matches what we're actually doing at runtime anyway. * Stopped emitting declarations from some libraries. Ts7 was erroring on these, but we're not actually using them anywhere * Fixed/tightened up various minor latent typing issues * By default, tsc launches four parallel typecheckers in each process. I found that when checking staff this ate up all my memory and started choking on swap. Reducing it to two (just for that project) seemed to give the best results. I've got an M2 Pro with 16GB of RAM. I'd be interested to see others' results here. ## Type of change > All pull requests must have at least one of the following labels applied (otherwise the PR will fail): | Label | Description | | --------------------------- | --------------------------------------------------------------------------------------------------------- | | Type: Bug | non-breaking change that fixes an issue | | Type: Feature | non-breaking change that adds functionality | | Type: Breaking Change | fix or feature that would cause existing functionality to not work as expected | | Type: Non-breaking refactor | change addresses some tech debt item or prepares for a later change, but does not change functionality | | Type: Configuration Change | adjusts configuration to achieve some end related to functionality, development, performance, or security | | Type: Dependency Upgrade | upgrades a project dependency - these changes are not included in release notes | ## Related issues Closes #XXXX Resolve Sentry issue: Fixes RECIDIVIZ-PULSE-DASHBOARD-[XXX] ## Checklists ### Development These boxes should be checked by the submitter prior to merging: - [ ] Manual testing against realistic data has been performed locally - [ ] E2E have been run for Lantern changes ([Steps in the Readme](https://github.com/Recidiviz/recidiviz-dashboards#running-e2e-tests)) ### Code review These boxes should be checked by reviewers prior to merging: - [x] This pull request has a descriptive title and information useful to a reviewer - [x] Potential security implications or infrastructural changes have been considered, if relevant --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> GitOrigin-RevId: 856d93ab41f0414ac72bcf5a7e182e6792af5cf0
Dependabot's daily typescript bump attempt (6.0.3 -> 7.0.2) was failing with: YN0001: typescript@patch:...builtin<compat/typescript>: ENOENT: no such file or directory, lstat '/node_modules/typescript/lib/_tsc.js' Yarn's builtin compat/typescript patch assumes the legacy JS compiler file layout, which TypeScript 7's native compiler package no longer has. This was fixed upstream in yarnpkg/berry#7190 (released in Yarn 4.17.1) by bounding the patch to TypeScript <7 and making optional patch failures non-fatal. 4.18.0 additionally picks up #7216, a related bin-precedence fix for the recommended TS 6/7 side-by-side setup. Verified by reproducing Dependabot's exact command (`yarn install --mode=update-lockfile` with typescript bumped to 7.0.2) against the new Yarn version, which now succeeds. Also keeps enableScripts on Yarn's actual default (false, since 4.14) rather than the blanket `true` its version-migration step would otherwise have pinned, and allowlists only the three packages that ship native binaries this project's tooling actually needs (esbuild, @swc/core, workerd) via dependenciesMeta.built. core-js's postinstall is a no-op sponsorship banner and doesn't need it. approvedGitRepositories is left empty since this repo has no git dependencies.
Dependabot's daily typescript bump attempt (6.0.3 -> 7.0.2) was failing with: YN0001: typescript@patch:...builtin<compat/typescript>: ENOENT: no such file or directory, lstat '/node_modules/typescript/lib/_tsc.js' Yarn's builtin compat/typescript patch assumes the legacy JS compiler file layout, which TypeScript 7's native compiler package no longer has. This was fixed upstream in yarnpkg/berry#7190 (released in Yarn 4.17.1) by bounding the patch to TypeScript <7 and making optional patch failures non-fatal. 4.18.0 additionally picks up #7216, a related bin-precedence fix for the recommended TS 6/7 side-by-side setup. Verified by reproducing Dependabot's exact command (`yarn install --mode=update-lockfile` with typescript bumped to 7.0.2) against the new Yarn version, which now succeeds. Also keeps enableScripts on Yarn's actual default (false, since 4.14) rather than the blanket `true` its version-migration step would otherwise have pinned, and allowlists only the three packages that ship native binaries this project's tooling actually needs (esbuild, @swc/core, workerd) via dependenciesMeta.built. core-js's postinstall is a no-op sponsorship banner and doesn't need it. approvedGitRepositories is left empty since this repo has no git dependencies.
Summary
optional!patches fall back when a package no longer ships a target file (for examplelib/_tsc.jsin TypeScript 7 / TypeScript compatibility shims), instead of failing the install withENOENT.typescript@7.0.1-rcinstalls and the TypeScript 7 side-by-side recommendation where thetypescriptident aliases tonpm:@typescript/typescript6@^6.0.0.plugin-typescriptacceptance test by moving it from@babel/traverse(now reported by npm search metadata as having included types) to a fixture package that still exercises DefinitelyTyped scoped package insertion.Test plan
yarn workspace @yarnpkg/plugin-compat test:plugin-compatyarn test:unit packages/plugin-patchnode ./scripts/run-yarn.js test:integration packages/acceptance-tests/pkg-tests-specs/sources/plugins/plugin-typescript.test.tsyarn version checkNotes
TypeScript 7 ships a native compiler package layout and no longer has the legacy JS compiler files patched by the existing PnP compatibility diff, such as
lib/_tsc.js. Bounding the TypeScript compat patch makes this intent explicit, while the optional patch fallback fixes the broader bug thatoptional!patch failures caused by missing target files were still fatal.TypeScript 7 support should ship with microsoft/typescript-go#1966.
Made with Cursor