Skip to content

Commit ed3375e

Browse files
authored
Merge pull request #141 from livesession/fix/dev-in-repo
fix(dev-in-repo): fix tests and dev mode in repo to make it running well
2 parents 138fa56 + 53bcb99 commit ed3375e

5 files changed

Lines changed: 58 additions & 54 deletions

File tree

__tests__/e2e/7.themes/1.dynamic-theme-resolution/dynamic-theme-resolution.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { test, expect } from '@playwright/test';
33
import { createXydBuildServer, XydServer } from '../../utils/xyd-server';
44

55
test.describe('Dynamic Theme Resolution', () => {
6+
// Run tests serially so they share a single beforeAll/server. With
7+
// fullyParallel: true, each test would spawn its own xyd build, and they'd
8+
// race on the shared <monorepo>/.xyd/host directory (rmSync of host fails
9+
// with ENOTEMPTY when another worker is mid-copy).
10+
test.describe.configure({ mode: 'serial' });
11+
612
let server: XydServer;
713

814
test.beforeAll(async () => {

__tests__/e2e/7.themes/2.custom-npm-theme/custom-npm-theme.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { createXydBuildServer, XydServer } from '../../utils/xyd-server';
88
const REGISTRY = process.env.XYD_E2E_VERDACCIO_URL || process.env.npm_config_registry || 'http://localhost:4873';
99

1010
test.describe('Custom npm Theme', () => {
11+
// Run tests serially so they share a single beforeAll/server. With
12+
// fullyParallel: true, each test would spawn its own xyd build, and they'd
13+
// race on the shared <monorepo>/.xyd/host directory.
14+
test.describe.configure({ mode: 'serial' });
15+
1116
let server: XydServer;
1217

1318
test.beforeAll(async () => {

__tests__/e2e/7.themes/3.custom-npm-theme-advanced/custom-npm-theme-advanced.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import { createXydBuildServer, XydServer } from '../../utils/xyd-server';
77
const REGISTRY = process.env.XYD_E2E_VERDACCIO_URL || process.env.npm_config_registry || 'http://localhost:4873';
88

99
test.describe('Custom npm Theme (Advanced)', () => {
10+
// Run tests serially so they share a single beforeAll/server. With
11+
// fullyParallel: true, each test would spawn its own xyd build, and they'd
12+
// race on the shared <monorepo>/.xyd/host directory.
13+
test.describe.configure({ mode: 'serial' });
14+
1015
let server: XydServer;
1116

1217
test.beforeAll(async () => {

packages/xyd-documan/src/build.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,38 @@ function setupInstallableEnvironmentV2() {
188188
}
189189
fs.symlinkSync(hostNodeModules, symbolicXydNodeModules, 'dir');
190190

191+
// In XYD_DEV_MODE the host (.xyd/host) lives in the monorepo, but
192+
// <cwd>/.xyd/build/server/index.js — the file react-router's prerender
193+
// plugin dynamically imports — sits in the user's CWD. Node's module
194+
// resolution walks up from that file and reaches .xyd/node_modules
195+
// (symlinked above to the host's node_modules, which only carries the
196+
// host's *direct* deps as pnpm symlinks). It never sees the monorepo's
197+
// root node_modules where shamefully-hoist makes every transitive dep
198+
// (radix-ui, vfile, lucide-react, …) resolvable. Without this fallback,
199+
// the prerender's `import()` blows up with "Cannot find package …" and
200+
// the build silently emits no HTML — surfacing only as
201+
// "✗ Build failed in N.NNs". A real install path (CI, published xyd-js)
202+
// doesn't need this because pnpm install in .xyd/host produces a
203+
// fully-populated node_modules.
204+
if (process.env.XYD_DEV_MODE) {
205+
// <documan>/dist/index.js → packages/xyd-documan → packages → monorepo
206+
const monorepoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../..")
207+
const monorepoNodeModules = path.join(monorepoRoot, "node_modules")
208+
const cwdNodeModules = path.join(process.cwd(), "node_modules")
209+
const insideMonorepo = process.cwd() === monorepoRoot ||
210+
process.cwd().startsWith(monorepoRoot + path.sep)
211+
212+
if (!insideMonorepo && fs.existsSync(monorepoNodeModules)) {
213+
if (fs.existsSync(cwdNodeModules) && fs.lstatSync(cwdNodeModules).isSymbolicLink()) {
214+
fs.unlinkSync(cwdNodeModules)
215+
}
216+
// Don't clobber a real node_modules the user already manages.
217+
if (!fs.existsSync(cwdNodeModules)) {
218+
fs.symlinkSync(monorepoNodeModules, cwdNodeModules, 'dir')
219+
}
220+
}
221+
}
222+
191223
// const buildDir = getBuildPath();
192224
// const packageJsonPath = path.join(buildDir, 'package.json');
193225

pnpm-lock.yaml

Lines changed: 10 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)