Skip to content

Commit ed61fe4

Browse files
authored
Declare the correct Blueprints v2 types (#2655)
## Motivation for the change, related issues Uses the actual Blueprint v2 type declarations from https://github.com/Automattic/WordPress-extension-proposals/blob/trunk/wep-1-blueprint-v2-schema/proposal.md instead of saying V2 schema is the same as V1 schema. A part of #2586. ## Testing Instructions (or ideally a Blueprint) CI.
1 parent 493a370 commit ed61fe4

File tree

6 files changed

+45
-14
lines changed

6 files changed

+45
-14
lines changed

packages/playground/blueprints/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ export type {
4949
export * from './lib/steps';
5050
export * from './lib/steps/handlers';
5151
export type {
52+
BlueprintV2,
53+
BlueprintV2Declaration,
5254
RawBlueprintV2Data,
53-
ParsedBlueprintV2String,
55+
ParsedBlueprintV1orV2String as ParsedBlueprintV2String,
5456
} from './lib/v2/blueprint-v2-declaration';
5557
export { getV2Runner } from './lib/v2/get-v2-runner';
5658
export { runBlueprintV2 } from './lib/v2/run-blueprint-v2';
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import type { Filesystem } from '@wp-playground/storage';
2-
import type { V2Schema } from './v2/wep-1-blueprint-v2-schema/appendix-A-blueprint-v2-schema';
32
import type { BlueprintV1, BlueprintV1Declaration } from './v1/types';
4-
import type { RawBlueprintV2Data } from './v2/blueprint-v2-declaration';
3+
import type {
4+
BlueprintV2,
5+
BlueprintV2Declaration,
6+
} from './v2/blueprint-v2-declaration';
57

68
/**
79
* A filesystem structure containing a /blueprint.json file and any
810
* resources referenced by that blueprint.
911
*/
1012
export type BlueprintBundle = Filesystem;
1113

12-
export type BlueprintDeclaration = BlueprintV1Declaration | RawBlueprintV2Data;
13-
export type Blueprint = BlueprintV1 | V2Schema.BlueprintV2;
14+
export type BlueprintDeclaration =
15+
| BlueprintV1Declaration
16+
| BlueprintV2Declaration;
17+
export type Blueprint = BlueprintV1 | BlueprintV2;

packages/playground/blueprints/src/lib/v2/blueprint-v2-declaration.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1+
import type { BlueprintBundle } from '../types';
12
import type { BlueprintV1Declaration } from '../v1/types';
3+
import type { V2Schema } from './wep-1-blueprint-v2-schema/appendix-A-blueprint-v2-schema';
24

3-
export type RawBlueprintV2Data = string | BlueprintV1Declaration | undefined;
4-
export type ParsedBlueprintV2String =
5+
type BlueprintV2Declaration = V2Schema.BlueprintV2;
6+
export type BlueprintV2 = BlueprintV2Declaration | BlueprintBundle;
7+
8+
export type { BlueprintV2Declaration };
9+
export type RawBlueprintV2Data = string | BlueprintV2Declaration | undefined;
10+
11+
export type ParsedBlueprintV1orV2String =
512
| { type: 'inline-file'; contents: string }
613
| { type: 'file-reference'; reference: string };
714

815
export function parseBlueprintDeclaration(
9-
source: RawBlueprintV2Data | ParsedBlueprintV2String
10-
): ParsedBlueprintV2String {
16+
source:
17+
| RawBlueprintV2Data
18+
| ParsedBlueprintV1orV2String
19+
| BlueprintV1Declaration
20+
): ParsedBlueprintV1orV2String {
1121
if (
1222
typeof source === 'object' &&
1323
'type' in source &&

packages/playground/blueprints/src/lib/v2/run-blueprint-v2.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { phpVar } from '@php-wasm/util';
77
import { getV2Runner } from './get-v2-runner';
88
import {
99
type RawBlueprintV2Data,
10-
type ParsedBlueprintV2String,
10+
type ParsedBlueprintV1orV2String,
1111
parseBlueprintDeclaration,
1212
} from './blueprint-v2-declaration';
13+
import type { BlueprintV1Declaration } from '../v1/types';
1314

1415
export type PHPExceptionDetails = {
1516
exception: string;
@@ -32,7 +33,10 @@ export type BlueprintMessage =
3233
interface RunV2Options {
3334
php: UniversalPHP;
3435
cliArgs?: string[];
35-
blueprint: RawBlueprintV2Data | ParsedBlueprintV2String;
36+
blueprint:
37+
| RawBlueprintV2Data
38+
| ParsedBlueprintV1orV2String
39+
| BlueprintV1Declaration;
3640
blueprintOverrides?: {
3741
wordpressVersion?: string;
3842
additionalSteps?: any[];

packages/playground/cli/src/blueprints-v2/worker-thread-v2.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { sprintf } from '@php-wasm/util';
2121
import {
2222
type BlueprintMessage,
2323
runBlueprintV2,
24+
type BlueprintV1Declaration,
2425
} from '@wp-playground/blueprints';
2526
import {
2627
type ParsedBlueprintV2String,
@@ -122,13 +123,19 @@ export type PrimaryWorkerBootArgs = RunCLIArgs & {
122123
firstProcessId: number;
123124
processIdSpaceLength: number;
124125
trace: boolean;
125-
blueprint: RawBlueprintV2Data | ParsedBlueprintV2String;
126+
blueprint:
127+
| RawBlueprintV2Data
128+
| ParsedBlueprintV2String
129+
| BlueprintV1Declaration;
126130
nativeInternalDirPath: string;
127131
};
128132

129133
type WorkerRunBlueprintArgs = RunCLIArgs & {
130134
siteUrl: string;
131-
blueprint: RawBlueprintV2Data | ParsedBlueprintV2String;
135+
blueprint:
136+
| RawBlueprintV2Data
137+
| ParsedBlueprintV2String
138+
| BlueprintV1Declaration;
132139
};
133140

134141
export type SecondaryWorkerBootArgs = {

packages/playground/cli/src/run-cli.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import type {
1414
BlueprintBundle,
1515
BlueprintV1Declaration,
16+
BlueprintV2Declaration,
1617
} from '@wp-playground/blueprints';
1718
import { runBlueprintV1Steps } from '@wp-playground/blueprints';
1819
import { RecommendedPHPVersion } from '@wp-playground/common';
@@ -394,7 +395,10 @@ export async function parseOptionsAndRunCLI() {
394395
}
395396

396397
export interface RunCLIArgs {
397-
blueprint?: BlueprintV1Declaration | BlueprintBundle;
398+
blueprint?:
399+
| BlueprintV1Declaration
400+
| BlueprintV2Declaration
401+
| BlueprintBundle;
398402
command: 'server' | 'run-blueprint' | 'build-snapshot';
399403
debug?: boolean;
400404
login?: boolean;

0 commit comments

Comments
 (0)