Skip to content

Commit a78f0b0

Browse files
committed
Merge branch 'trunk' into replace-nightly-with-trunk
2 parents edfd8d6 + 4d8ddd9 commit a78f0b0

File tree

69 files changed

+1766
-617
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1766
-617
lines changed

packages/playground/blueprints/public/blueprint-schema-validator.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10340,7 +10340,7 @@ function validate14(
1034010340
? validate12.errors
1034110341
: vErrors.concat(
1034210342
validate12.errors
10343-
);
10343+
);
1034410344
errors = vErrors.length;
1034510345
}
1034610346
var valid21 =
@@ -11019,7 +11019,7 @@ function validate14(
1101911019
? validate12.errors
1102011020
: vErrors.concat(
1102111021
validate12.errors
11022-
);
11022+
);
1102311023
errors = vErrors.length;
1102411024
}
1102511025
var valid27 =
@@ -11435,7 +11435,7 @@ function validate14(
1143511435
? validate12.errors
1143611436
: vErrors.concat(
1143711437
validate12.errors
11438-
);
11438+
);
1143911439
errors =
1144011440
vErrors.length;
1144111441
}
@@ -11467,7 +11467,7 @@ function validate14(
1146711467
? validate18.errors
1146811468
: vErrors.concat(
1146911469
validate18.errors
11470-
);
11470+
);
1147111471
errors =
1147211472
vErrors.length;
1147311473
}
@@ -11553,7 +11553,7 @@ function validate14(
1155311553
? validate12.errors
1155411554
: vErrors.concat(
1155511555
validate12.errors
11556-
);
11556+
);
1155711557
errors =
1155811558
vErrors.length;
1155911559
}
@@ -12101,7 +12101,7 @@ function validate14(
1210112101
? validate12.errors
1210212102
: vErrors.concat(
1210312103
validate12.errors
12104-
);
12104+
);
1210512105
errors =
1210612106
vErrors.length;
1210712107
}
@@ -12133,7 +12133,7 @@ function validate14(
1213312133
? validate18.errors
1213412134
: vErrors.concat(
1213512135
validate18.errors
12136-
);
12136+
);
1213712137
errors =
1213812138
vErrors.length;
1213912139
}
@@ -12219,7 +12219,7 @@ function validate14(
1221912219
? validate12.errors
1222012220
: vErrors.concat(
1222112221
validate12.errors
12222-
);
12222+
);
1222312223
errors =
1222412224
vErrors.length;
1222512225
}
@@ -13969,7 +13969,7 @@ function validate14(
1396913969
? validate30.errors
1397013970
: vErrors.concat(
1397113971
validate30.errors
13972-
);
13972+
);
1397313973
errors = vErrors.length;
1397413974
}
1397513975
var valid54 =
@@ -15456,7 +15456,7 @@ function validate14(
1545615456
? validate32.errors
1545715457
: vErrors.concat(
1545815458
validate32.errors
15459-
);
15459+
);
1546015460
errors = vErrors.length;
1546115461
}
1546215462
var valid68 =
@@ -16180,7 +16180,7 @@ function validate14(
1618016180
? validate12.errors
1618116181
: vErrors.concat(
1618216182
validate12.errors
16183-
);
16183+
);
1618416184
errors = vErrors.length;
1618516185
}
1618616186
var valid76 =
@@ -16810,7 +16810,7 @@ function validate14(
1681016810
? validate12.errors
1681116811
: vErrors.concat(
1681216812
validate12.errors
16813-
);
16813+
);
1681416814
errors = vErrors.length;
1681516815
}
1681616816
var valid83 =
@@ -17589,7 +17589,7 @@ function validate14(
1758917589
? validate12.errors
1759017590
: vErrors.concat(
1759117591
validate12.errors
17592-
);
17592+
);
1759317593
errors =
1759417594
vErrors.length;
1759517595
}
@@ -18636,7 +18636,7 @@ function validate14(
1863618636
? validate18.errors
1863718637
: vErrors.concat(
1863818638
validate18.errors
18639-
);
18639+
);
1864018640
errors =
1864118641
vErrors.length;
1864218642
}
@@ -20513,7 +20513,7 @@ function validate11(
2051320513
? validate12.errors
2051420514
: vErrors.concat(
2051520515
validate12.errors
20516-
);
20516+
);
2051720517
errors =
2051820518
vErrors.length;
2051920519
}
@@ -21127,7 +21127,7 @@ function validate11(
2112721127
? validate14.errors
2112821128
: vErrors.concat(
2112921129
validate14.errors
21130-
);
21130+
);
2113121131
errors =
2113221132
vErrors.length;
2113321133
}

packages/playground/blueprints/src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export {
1919
isBlueprintBundle,
2020
compileBlueprintV1,
2121
runBlueprintV1Steps,
22+
InvalidBlueprintError,
23+
BlueprintStepExecutionError,
2224

2325
// BC:
2426
compileBlueprintV1 as compileBlueprint,
@@ -49,6 +51,7 @@ export type {
4951
VFSReference,
5052
VFSResource,
5153
} from './lib/v1/resources';
54+
export { BlueprintFilesystemRequiredError } from './lib/v1/resources';
5255
export * from './lib/steps';
5356
export * from './lib/steps/handlers';
5457
export type {
@@ -61,7 +64,10 @@ export { getV2Runner } from './lib/v2/get-v2-runner';
6164
export { runBlueprintV2 } from './lib/v2/run-blueprint-v2';
6265
export type { BlueprintMessage } from './lib/v2/run-blueprint-v2';
6366

64-
export { resolveRemoteBlueprint } from './lib/resolve-remote-blueprint';
67+
export {
68+
resolveRemoteBlueprint,
69+
BlueprintFetchError,
70+
} from './lib/resolve-remote-blueprint';
6571
export { wpContentFilesExcludedFromExport } from './lib/utils/wp-content-files-excluded-from-exports';
6672
export { resolveRuntimeConfiguration } from './lib/resolve-runtime-configuration';
6773

packages/playground/blueprints/src/lib/resolve-remote-blueprint.ts

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import {
66
} from '@wp-playground/storage';
77
import type { BlueprintBundle } from './types';
88

9+
export class BlueprintFetchError extends Error {
10+
constructor(
11+
message: string,
12+
public readonly url: string,
13+
options?: ErrorOptions
14+
) {
15+
super(message, options);
16+
this.name = 'BlueprintFetchError';
17+
}
18+
}
19+
920
/**
1021
* Resolves a remote blueprint from a URL.
1122
*
@@ -15,34 +26,42 @@ import type { BlueprintBundle } from './types';
1526
export async function resolveRemoteBlueprint(
1627
url: string
1728
): Promise<BlueprintBundle> {
18-
const response = await fetch(url, {
19-
credentials: 'omit',
20-
});
21-
if (!response.ok) {
22-
throw new Error(`Failed to fetch blueprint from ${url}`);
23-
}
24-
const blueprintBytes = await response.arrayBuffer();
2529
try {
26-
const blueprintText = new TextDecoder().decode(blueprintBytes);
27-
JSON.parse(blueprintText);
30+
const response = await fetch(url, {
31+
credentials: 'omit',
32+
});
33+
if (!response.ok) {
34+
throw new Error(`Failed to fetch blueprint from ${url}`);
35+
}
36+
const blueprintBytes = await response.arrayBuffer();
37+
try {
38+
const blueprintText = new TextDecoder().decode(blueprintBytes);
39+
JSON.parse(blueprintText);
2840

29-
// No exceptions, good! We're dealing with a JSON file. Let's
30-
// resolve the "bundled" resources from the same remote URL.
31-
return new OverlayFilesystem([
32-
new InMemoryFilesystem({
33-
'blueprint.json': blueprintText,
34-
}),
35-
new FetchFilesystem({
36-
baseUrl: url,
37-
}),
38-
]);
39-
} catch {
40-
// If the blueprint is not a JSON file, check if it's a ZIP file.
41-
if (await looksLikeZipFile(blueprintBytes)) {
42-
return ZipFilesystem.fromArrayBuffer(blueprintBytes);
41+
// No exceptions, good! We're dealing with a JSON file. Let's
42+
// resolve the "bundled" resources from the same remote URL.
43+
return new OverlayFilesystem([
44+
new InMemoryFilesystem({
45+
'blueprint.json': blueprintText,
46+
}),
47+
new FetchFilesystem({
48+
baseUrl: url,
49+
}),
50+
]);
51+
} catch {
52+
// If the blueprint is not a JSON file, check if it's a ZIP file.
53+
if (await looksLikeZipFile(blueprintBytes)) {
54+
return ZipFilesystem.fromArrayBuffer(blueprintBytes);
55+
}
56+
throw new Error(
57+
`Blueprint file at ${url} is neither a valid JSON nor a ZIP file.`
58+
);
4359
}
44-
throw new Error(
45-
`Blueprint file at ${url} is neither a valid JSON nor a ZIP file.`
60+
} catch (error) {
61+
throw new BlueprintFetchError(
62+
`Blueprint file at ${url} is neither a valid JSON nor a ZIP file.`,
63+
url,
64+
{ cause: error }
4665
);
4766
}
4867
}

packages/playground/blueprints/src/lib/steps/activate-plugin.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('Blueprint step activatePlugin()', () => {
2525
php = await handler.getPrimaryPhp();
2626
}, 30_000);
2727

28+
afterEach(async () => {
29+
php.exit();
30+
await handler[Symbol.asyncDispose]();
31+
});
32+
2833
it('should activate a plugin file located in the plugins directory', async () => {
2934
const docroot = handler.documentRoot;
3035
php.writeFile(

packages/playground/blueprints/src/lib/steps/activate-plugin.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export const activatePlugin: StepHandler<ActivatePluginStep> = async (
9898
/**
9999
* Instead of trusting the activation response, check the active plugins list.
100100
*
101-
* We try to discard any extra output via output buffering. The output of the script below
101+
* We try to discard any extra output via output buffering. The output of the script below
102102
* end with `{"success": true}` or `{"success": false}`. Only `{"success": true}` is
103103
* treated as a successful plugin activation.
104104
*/
@@ -152,9 +152,11 @@ export const activatePlugin: StepHandler<ActivatePluginStep> = async (
152152
}
153153

154154
throw new Error(
155-
`Plugin ${pluginPath} could not be activated – WordPress exited with no error. ` +
156-
`Sometimes, when $_SERVER or site options are not configured correctly, ` +
157-
`WordPress exits early with a 301 redirect. ` +
158-
`Inspect the "debug" logs in the console for more details.`
155+
`Plugin ${pluginPath} could not be activated - WordPress exited with exit code ${activatePluginResult.exitCode}. ` +
156+
`Inspect the "debug" logs in the console for more details. Output headers: ${JSON.stringify(
157+
activatePluginResult.headers,
158+
null,
159+
2
160+
)}`
159161
);
160162
};

packages/playground/blueprints/src/lib/steps/activate-theme.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ describe('Blueprint step activateTheme()', () => {
2525
php = await handler.getPrimaryPhp();
2626
});
2727

28+
afterEach(async () => {
29+
php.exit();
30+
await handler[Symbol.asyncDispose]();
31+
});
32+
2833
it('should activate the theme', async () => {
2934
const docroot = php.documentRoot;
3035
php.mkdir(`${docroot}/wp-content/themes/test-theme`);

packages/playground/blueprints/src/lib/steps/activate-theme.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ export const activateTheme: StepHandler<ActivateThemeStep> = async (
6767
if (result.text !== 'Theme activated successfully') {
6868
logger.debug(result);
6969
throw new Error(
70-
`Theme ${themeFolderName} could not be activated – WordPress exited with no error. ` +
71-
`Sometimes, when $_SERVER or site options are not configured correctly, ` +
72-
`WordPress exits early with a 301 redirect. ` +
73-
`Inspect the "debug" logs in the console for more details`
70+
`Theme ${themeFolderName} could not be activated - WordPress exited with exit code ${result.exitCode}. ` +
71+
`Inspect the "debug" logs in the console for more details. Output headers: ${JSON.stringify(
72+
result.headers,
73+
null,
74+
2
75+
)}`
7476
);
7577
}
7678
};

packages/playground/blueprints/src/lib/steps/define-wp-config-consts.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ describe('defineBeforeRun', () => {
1010
php = new PHP(await loadNodeRuntime(RecommendedPHPVersion));
1111
});
1212

13+
afterEach(() => {
14+
php.exit();
15+
});
16+
1317
it('should define the constants before running the requested script', async () => {
1418
const constants = {
1519
SITE_URL: 'http://test.url',

packages/playground/blueprints/src/lib/steps/import-theme-starter-content.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ describe('Blueprint step importThemeStarterContent', () => {
2424
php = await handler.getPrimaryPhp();
2525
});
2626

27+
afterEach(async () => {
28+
php.exit();
29+
await handler[Symbol.asyncDispose]();
30+
});
31+
2732
it('Should import theme starter content', async () => {
2833
const docroot = php.documentRoot;
2934
// Create a test theme with starter content, Must have at a minimum

packages/playground/blueprints/src/lib/steps/import-wxr.spec.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ describe('Blueprint step importWxr', () => {
9191
});
9292
}, 30_000);
9393

94+
afterEach(async () => {
95+
php.exit();
96+
await handler[Symbol.asyncDispose]();
97+
});
98+
9499
it(
95100
'Should import a WXR file with JSON-encoded UTF-8 characters',
96101
async () => {
@@ -270,7 +275,7 @@ describe('Blueprint step importWxr', () => {
270275
const result = await php.run({
271276
code: `<?php
272277
require getenv('DOCROOT') . '/wp-load.php';
273-
278+
274279
// Get all imported posts
275280
$posts = get_posts([
276281
'post_type' => ['post', 'page'],
@@ -279,10 +284,10 @@ describe('Blueprint step importWxr', () => {
279284
'orderby' => 'ID',
280285
'order' => 'ASC'
281286
]);
282-
287+
283288
// Get admin user info
284289
$admin_user = get_user_by('login', 'admin');
285-
290+
286291
$post_authors = [];
287292
foreach ($posts as $post) {
288293
$author = get_user_by('ID', $post->post_author);
@@ -295,7 +300,7 @@ describe('Blueprint step importWxr', () => {
295300
'author_display_name' => $author ? $author->display_name : null,
296301
];
297302
}
298-
303+
299304
echo json_encode([
300305
'admin_user_id' => $admin_user ? $admin_user->ID : null,
301306
'admin_user_login' => $admin_user ? $admin_user->user_login : null,

0 commit comments

Comments
 (0)