Skip to content

Commit 95576c6

Browse files
committed
CI failures
1 parent cb5a9f7 commit 95576c6

File tree

3 files changed

+84
-8
lines changed

3 files changed

+84
-8
lines changed

packages/docs/site/playwright.config.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,35 @@
11
import { defineConfig } from '@playwright/test';
2+
import fs from 'fs';
3+
import path from 'path';
24

35
const port = process.env.DOCS_E2E_PORT ?? '4173';
46
const host = process.env.DOCS_E2E_HOST ?? '127.0.0.1';
57
const baseUrl = process.env.DOCS_E2E_BASE_URL ?? `http://${host}:${port}`;
8+
const rawBasePath = process.env.DOCS_E2E_BASE_PATH ?? '/wordpress-playground';
9+
const normalizedBasePath =
10+
rawBasePath === '/' ? '/' : `/${rawBasePath.replace(/^\/|\/$/g, '')}`;
11+
const healthPath =
12+
process.env.DOCS_E2E_HEALTH_PATH ?? `${normalizedBasePath}/index.html`;
13+
const repoRoot =
14+
process.env.DOCS_E2E_REPO_ROOT ?? path.resolve(__dirname, '../../..');
15+
const buildDir =
16+
process.env.DOCS_E2E_BUILD_DIR ?? path.join(repoRoot, 'dist/docs/build');
17+
18+
const mountDir =
19+
normalizedBasePath === '/'
20+
? null
21+
: path.join(buildDir, normalizedBasePath.replace(/^\//, ''));
22+
23+
if (mountDir && fs.existsSync(buildDir) && !fs.existsSync(mountDir)) {
24+
try {
25+
fs.symlinkSync(buildDir, mountDir, 'junction');
26+
} catch (error) {
27+
console.warn(
28+
`docs-site e2e: failed to create symlink for base path ${normalizedBasePath}`,
29+
error
30+
);
31+
}
32+
}
633

734
export default defineConfig({
835
testDir: './tests',
@@ -17,8 +44,8 @@ export default defineConfig({
1744
video: 'retain-on-failure',
1845
},
1946
webServer: {
20-
command: `npx http-server dist/docs/build -p ${port} -c-1`,
21-
url: `${baseUrl}/wordpress-playground/`,
47+
command: `npx http-server "${buildDir}" -p ${port} -a ${host} -c-1`,
48+
url: `${baseUrl}${healthPath}`,
2249
reuseExistingServer: !process.env.CI,
2350
timeout: 120_000,
2451
},

packages/docs/site/plugins/docusaurus-dedupe-aliases.js

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs');
2+
const path = require('path');
23
const moduleRequire = require('module').createRequire(__dirname);
34

45
const PACKAGES_TO_DEDUPE = [
@@ -41,19 +42,45 @@ function normalizeSubpath(pkgName, subpath) {
4142
return `${pkgName}/${subpath.replace(/^\.\//, '')}`;
4243
}
4344

44-
function buildAliasesForPackage(pkgName) {
45-
let pkgJsonPath;
45+
function resolvePackageMetadata(pkgName) {
46+
let entryPoint;
4647
try {
47-
pkgJsonPath = moduleRequire.resolve(`${pkgName}/package.json`);
48+
entryPoint = moduleRequire.resolve(pkgName);
4849
} catch (error) {
4950
console.warn(
50-
`docusaurus-dedupe-aliases: unable to resolve ${pkgName}`,
51+
`docusaurus-dedupe-aliases: unable to resolve entry for ${pkgName}`,
5152
error
5253
);
54+
return null;
55+
}
56+
57+
let currentDir = path.dirname(entryPoint);
58+
const fsRoot = path.parse(currentDir).root;
59+
60+
while (currentDir && currentDir !== fsRoot) {
61+
const candidate = path.join(currentDir, 'package.json');
62+
if (fs.existsSync(candidate)) {
63+
const pkgJson = JSON.parse(fs.readFileSync(candidate, 'utf8'));
64+
if (pkgJson?.name === pkgName) {
65+
return { pkgJson, pkgRoot: currentDir };
66+
}
67+
}
68+
currentDir = path.dirname(currentDir);
69+
}
70+
71+
console.warn(
72+
`docusaurus-dedupe-aliases: could not locate package.json for ${pkgName}`
73+
);
74+
return null;
75+
}
76+
77+
function buildAliasesForPackage(pkgName) {
78+
const metadata = resolvePackageMetadata(pkgName);
79+
if (!metadata) {
5380
return [];
5481
}
5582

56-
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
83+
const { pkgJson, pkgRoot } = metadata;
5784
const exportKeys = getExportKeys(pkgJson.exports);
5885

5986
return exportKeys.flatMap((subpath) => {
@@ -64,6 +91,21 @@ function buildAliasesForPackage(pkgName) {
6491
subpath === '.' ? `${pkgName}$` : specifier.replace(/\\/g, '/');
6592
return [[aliasKey, target]];
6693
} catch (error) {
94+
const aliasKey =
95+
subpath === '.' ? `${pkgName}$` : specifier.replace(/\\/g, '/');
96+
const fallbackTarget =
97+
subpath === '.'
98+
? path.join(pkgRoot, pkgJson.main ?? 'index.js')
99+
: path.join(pkgRoot, subpath.replace(/^\.\//, ''));
100+
101+
if (fs.existsSync(fallbackTarget)) {
102+
console.warn(
103+
`docusaurus-dedupe-aliases: resolved ${specifier} via fallback path ${fallbackTarget} due to`,
104+
error.message
105+
);
106+
return [[aliasKey, fallbackTarget]];
107+
}
108+
67109
console.warn(
68110
`docusaurus-dedupe-aliases: unable to resolve specifier ${specifier}`,
69111
error

packages/docs/site/tests/api-reference.spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { test, expect } from '@playwright/test';
22

3+
const rawBasePath = process.env.DOCS_E2E_BASE_PATH ?? '/wordpress-playground';
4+
const normalizedBasePath =
5+
rawBasePath === '/' ? '/' : `/${rawBasePath.replace(/^\/|\/$/g, '')}`;
6+
const apiPath =
7+
process.env.DOCS_E2E_API_PATH ??
8+
`${normalizedBasePath === '/' ? '' : normalizedBasePath}/api`;
9+
310
test.describe('Docs API reference', () => {
411
test('loads without runtime errors', async ({ page }) => {
512
const pageErrors: Error[] = [];
@@ -20,7 +27,7 @@ test.describe('Docs API reference', () => {
2027
}
2128
});
2229

23-
await page.goto('/wordpress-playground/api', {
30+
await page.goto(apiPath, {
2431
waitUntil: 'networkidle',
2532
});
2633
await expect(page.locator('.apiPage')).toBeVisible();

0 commit comments

Comments
 (0)