Skip to content

Commit 7f5ffbf

Browse files
committed
fix(testing): seed typescript before plugins in e2e workspaces to avoid TS7 stub
npm hoists and pnpm freezes the plugins' unbounded typescript peers (@phenomnomnominal/tsquery, @rollup/plugin-typescript) onto the API-less TypeScript 7 native stub during graph inference. Installing typescript before the plugins lets those peers dedup to it. Seeding before (not after) the plugin install is required for pnpm, which won't re-dedup a peer added afterward.
1 parent eba643f commit 7f5ffbf

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

e2e/utils/create-project-utils.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020

2121
import { output, readJsonFile } from '@nx/devkit';
2222
import { angularCliVersion as defaultAngularCliVersion } from '@nx/workspace/src/utils/versions';
23+
import { typescriptVersion as defaultTypescriptVersion } from '@nx/js/src/utils/versions';
2324
import { dump } from '@zkochan/js-yaml';
2425
import { execSync, ExecSyncOptions } from 'node:child_process';
2526
import { readFileSync } from 'node:fs';
@@ -91,11 +92,13 @@ export function newProject({
9192
packageManager = getSelectedPackageManager(),
9293
packages,
9394
preset = 'apps',
95+
typescriptVersion = defaultTypescriptVersion,
9496
}: {
9597
name?: string;
9698
packageManager?: 'npm' | 'yarn' | 'pnpm' | 'bun';
9799
readonly packages?: Array<NxPackage>;
98100
preset?: string;
101+
typescriptVersion?: string;
99102
} = {}): string {
100103
const newProjectStart = performance.mark('new-project:start');
101104
try {
@@ -140,6 +143,13 @@ export function newProject({
140143

141144
if (packagesToInstall.length) {
142145
const packageInstallStart = performance.mark('packageInstall:start');
146+
// Seed typescript before the plugins so their unbounded typescript peers
147+
// (tsquery >3.0.0, @rollup/plugin-typescript >=3.7.0) dedup to it, not the
148+
// API-less TypeScript 7 native stub. Must run before the plugin install —
149+
// pnpm freezes peers per-dependent and won't re-dedup a peer added after.
150+
if (packageManager === 'npm' || packageManager === 'pnpm') {
151+
packageInstall('typescript', projScope, typescriptVersion);
152+
}
143153
packageInstall(packagesToInstall.join(` `), projScope);
144154
const packageInstallEnd = performance.mark('packageInstall:end');
145155
packageInstallMeasure = performance.measure(

0 commit comments

Comments
 (0)