Skip to content

Commit 60dce69

Browse files
committed
chore: fix rit and e2e
1 parent 2b589d7 commit 60dce69

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

tools/react-integration-tester/src/__tests__/cli.e2e.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ describe('rit CLI e2e', () => {
105105
expect(runCmd.cwd).toEqual(expect.stringContaining(join(fs.tempDir, 'tmp/rit/react-18/proj-react-18')));
106106

107107
// no project folder exists as it was cleanuped
108-
expect(readdirSync(join(fs.tempDir, 'tmp/rit/react-18/'))).toEqual(['package.json']);
108+
expect(readdirSync(join(fs.tempDir, 'tmp/rit/react-18/')).sort()).toEqual([
109+
'.yarnrc.yml',
110+
'package.json',
111+
'yarn.lock',
112+
]);
109113
});
110114

111115
test('--install-deps installs into react root (no project scaffolding)', () => {

tools/react-integration-tester/src/setup.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ function renderTemplateToFile(templateFilePath: string, data: Record<string, unk
125125
* Writes only when the file does not exist or dependencies actually change (to avoid race issues on CI).
126126
* Returned value indicates whether a write occurred.
127127
*/
128+
function ensureWorkspaceIsolation(reactRootPath: string) {
129+
// Create an empty yarn.lock so Yarn 4 treats this directory as a standalone
130+
// project root instead of traversing up into the parent monorepo workspace.
131+
const yarnLockPath = join(reactRootPath, 'yarn.lock');
132+
if (!existsSync(yarnLockPath)) {
133+
writeFileSync(yarnLockPath, '');
134+
}
135+
136+
// Create a minimal .yarnrc.yml so that Yarn uses node-modules linker and
137+
// does not inherit the parent workspace's yarnPath (which is a relative path
138+
// that would not resolve correctly from the tmp directory).
139+
const yarnrcPath = join(reactRootPath, '.yarnrc.yml');
140+
if (!existsSync(yarnrcPath)) {
141+
writeFileSync(yarnrcPath, 'nodeLinker: node-modules\n');
142+
}
143+
}
144+
128145
function upsertReactRootPackageJson(params: {
129146
reactRootPath: string;
130147
react: ReactVersion;
@@ -133,6 +150,7 @@ function upsertReactRootPackageJson(params: {
133150
}): { wrote: boolean; pkgPath: string } {
134151
const { reactRootPath, react, dependencies, logger } = params;
135152
mkdirSync(reactRootPath, { recursive: true });
153+
ensureWorkspaceIsolation(reactRootPath);
136154
const reactRootPkgPath = join(reactRootPath, 'package.json');
137155

138156
const basePkg: PackageJson = {

0 commit comments

Comments
 (0)