Skip to content

Commit cacf8c9

Browse files
authored
[Blueprints] Rename Blueprints v1 types, add Blueprint v2 types (#2648)
## Motivation for the change, related issues Renames Blueprint v1-related types an explicit "v1" in the name. Declares Blueprint v2-related types such as the schema from the [proposal](https://github.com/Automattic/WordPress-extension-proposals/blob/trunk/wep-1-blueprint-v2-schema/proposal.md). A part of #2586. ## Breaking changes This is a breaking change with respect to TypeScript types. The type named `Blueprint` now means `BlueprintV1 | BlueprintV2` which is a broader type than before. Therefore, let's do a major version bump after merging this PR. There are no breaking changes in runtime. cc @brandonpayton ## Testing Instructions (or ideally a Blueprint) CI
1 parent 0c00825 commit cacf8c9

File tree

17 files changed

+1941
-75
lines changed

17 files changed

+1941
-75
lines changed

packages/docs/site/src/components/BlueprintsAPI/model.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ const BlueprintsApi = getModule('@wp-playground/blueprints');
55
export const BlueprintSteps = BlueprintsApi.children
66
.filter((entry) => entry.name.match(/Step$/))
77
.filter(
8-
(entry) => !['CompiledStep', 'GenericStep', 'Step'].includes(entry.name)
8+
(entry) =>
9+
!['CompiledStep', 'CompiledV1Step', 'GenericStep', 'Step'].includes(
10+
entry.name
11+
)
912
)
1013
.filter((entry) => !entry?.flags?.isPrivate)
1114
.map((entry) => entry.name)

packages/playground/blueprints/src/index.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,29 @@
22
import '@php-wasm/node-polyfills';
33

44
export type {
5-
Blueprint,
6-
BlueprintBundle,
5+
BlueprintV1,
76
BlueprintV1Declaration,
8-
// For backwards compatibility:
9-
BlueprintV1Declaration as BlueprintDeclaration,
107
PHPConstants,
118
} from './lib/v1/types';
9+
export type {
10+
Blueprint,
11+
BlueprintBundle,
12+
BlueprintDeclaration,
13+
} from './lib/types';
1214
export {
13-
compileBlueprint,
1415
getBlueprintDeclaration,
1516
isBlueprintBundle,
16-
runBlueprintSteps,
17+
compileBlueprintV1,
18+
runBlueprintV1Steps,
19+
20+
// BC:
21+
compileBlueprintV1 as compileBlueprint,
22+
runBlueprintV1Steps as runBlueprintSteps,
1723
} from './lib/v1/compile';
1824
export type {
19-
CompileBlueprintOptions,
20-
CompiledBlueprint,
21-
CompiledStep,
25+
CompileBlueprintV1Options,
26+
CompiledBlueprintV1,
27+
CompiledV1Step,
2228
OnStepCompleted,
2329
} from './lib/v1/compile';
2430
export type {
@@ -43,8 +49,8 @@ export type {
4349
export * from './lib/steps';
4450
export * from './lib/steps/handlers';
4551
export type {
46-
BlueprintV2Declaration,
47-
ParsedBlueprintV2Declaration,
52+
RawBlueprintV2Data,
53+
ParsedBlueprintV2String,
4854
} from './lib/v2/blueprint-v2-declaration';
4955
export { getV2Runner } from './lib/v2/get-v2-runner';
5056
export { runBlueprintV2 } from './lib/v2/run-blueprint-v2';

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
OverlayFilesystem,
55
ZipFilesystem,
66
} from '@wp-playground/storage';
7-
import type { BlueprintBundle } from './v1/types';
7+
import type { BlueprintBundle } from './types';
88

99
/**
1010
* Resolves a remote blueprint from a URL.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Filesystem } from '@wp-playground/storage';
2+
import type { V2Schema } from './v2/wep-1-blueprint-v2-schema/appendix-A-blueprint-v2-schema';
3+
import type { BlueprintV1, BlueprintV1Declaration } from './v1/types';
4+
import type { RawBlueprintV2Data } from './v2/blueprint-v2-declaration';
5+
6+
/**
7+
* A filesystem structure containing a /blueprint.json file and any
8+
* resources referenced by that blueprint.
9+
*/
10+
export type BlueprintBundle = Filesystem;
11+
12+
export type BlueprintDeclaration = BlueprintV1Declaration | RawBlueprintV2Data;
13+
export type Blueprint = BlueprintV1 | V2Schema.BlueprintV2;

packages/playground/blueprints/src/lib/v1/compile.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PHP } from '@php-wasm/universal';
22
import {
3-
compileBlueprint,
4-
runBlueprintSteps,
3+
compileBlueprintV1,
4+
runBlueprintV1Steps,
55
validateBlueprint,
66
} from './compile';
77
import { defineWpConfigConsts } from '../steps/define-wp-config-consts';
@@ -26,8 +26,8 @@ describe('Blueprints', () => {
2626
});
2727

2828
it('should run a basic blueprint', async () => {
29-
await runBlueprintSteps(
30-
await compileBlueprint({
29+
await runBlueprintV1Steps(
30+
await compileBlueprintV1({
3131
steps: [
3232
{
3333
step: 'writeFile',
@@ -84,8 +84,8 @@ describe('Blueprints', () => {
8484
});
8585

8686
it('Should boot with WP-CLI support if the wpCli feature is enabled', async () => {
87-
await runBlueprintSteps(
88-
await compileBlueprint({
87+
await runBlueprintV1Steps(
88+
await compileBlueprintV1({
8989
extraLibraries: ['wp-cli'],
9090
}),
9191
php
@@ -101,9 +101,9 @@ describe('Blueprints', () => {
101101
);
102102
const zipData = fs.readFileSync(zipPath).buffer;
103103
const zipBundle = ZipFilesystem.fromArrayBuffer(zipData);
104-
const compiledBlueprint = await compileBlueprint(zipBundle);
104+
const compiledBlueprint = await compileBlueprintV1(zipBundle);
105105

106-
await runBlueprintSteps(compiledBlueprint, php);
106+
await runBlueprintV1Steps(compiledBlueprint, php);
107107

108108
expect(php.fileExists('/index.php')).toBe(true);
109109
expect(php.readFileAsText('/index.php')).toContain('<?php echo');
@@ -130,9 +130,9 @@ describe('Blueprints', () => {
130130
],
131131
}),
132132
});
133-
const compiledBlueprint = await compileBlueprint(fileTreeBundle);
133+
const compiledBlueprint = await compileBlueprintV1(fileTreeBundle);
134134

135-
await runBlueprintSteps(compiledBlueprint, php);
135+
await runBlueprintV1Steps(compiledBlueprint, php);
136136

137137
expect(php.fileExists('/text_file.txt')).toBe(true);
138138
expect(php.readFileAsText('/text_file.txt')).toContain(

packages/playground/blueprints/src/lib/v1/compile.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import type { Step, StepDefinition, WriteFileStep } from '../steps';
1111
import * as allStepHandlers from '../steps/handlers';
1212
import type {
1313
BlueprintV1Declaration,
14-
BlueprintBundle,
1514
ExtraLibrary,
1615
StreamBundledFile,
17-
Blueprint,
16+
BlueprintV1,
1817
} from './types';
18+
import type { BlueprintBundle } from '../types';
1919
import { logger } from '@php-wasm/logger';
2020

2121
// @TODO: Configure this in the `wp-cli` step, not here.
@@ -42,9 +42,9 @@ const keyedStepHandlers = {
4242
import blueprintValidator from '../../../public/blueprint-schema-validator';
4343
import { defaultWpCliPath, defaultWpCliResource } from '../steps/wp-cli';
4444

45-
export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
45+
export type CompiledV1Step = (php: UniversalPHP) => Promise<void> | void;
4646

47-
export interface CompiledBlueprint {
47+
export interface CompiledBlueprintV1 {
4848
/** The requested versions of PHP and WordPress for the blueprint */
4949
versions: {
5050
php: SupportedPHPVersion;
@@ -62,7 +62,7 @@ export interface CompiledBlueprint {
6262

6363
export type OnStepCompleted = (output: any, step: StepDefinition) => any;
6464

65-
export interface CompileBlueprintOptions {
65+
export interface CompileBlueprintV1Options {
6666
/** Optional progress tracker to monitor progress */
6767
progress?: ProgressTracker;
6868
/** Optional semaphore to control access to a shared resource */
@@ -87,11 +87,11 @@ export interface CompileBlueprintOptions {
8787
additionalSteps?: any[];
8888
}
8989

90-
export async function compileBlueprint(
90+
export async function compileBlueprintV1(
9191
input: BlueprintV1Declaration | BlueprintBundle,
92-
options: Omit<CompileBlueprintOptions, 'streamBundledFile'> = {}
93-
): Promise<CompiledBlueprint> {
94-
const finalOptions: CompileBlueprintOptions = {
92+
options: Omit<CompileBlueprintV1Options, 'streamBundledFile'> = {}
93+
): Promise<CompiledBlueprintV1> {
94+
const finalOptions: CompileBlueprintV1Options = {
9595
...options,
9696
};
9797

@@ -113,7 +113,7 @@ export function isBlueprintBundle(input: any): input is BlueprintBundle {
113113
}
114114

115115
export async function getBlueprintDeclaration(
116-
blueprint: Blueprint
116+
blueprint: BlueprintV1 | BlueprintBundle
117117
): Promise<BlueprintV1Declaration> {
118118
if (!isBlueprintBundle(blueprint)) {
119119
return blueprint;
@@ -140,8 +140,8 @@ function compileBlueprintJson(
140140
corsProxy,
141141
streamBundledFile,
142142
additionalSteps,
143-
}: CompileBlueprintOptions = {}
144-
): CompiledBlueprint {
143+
}: CompileBlueprintV1Options = {}
144+
): CompiledBlueprintV1 {
145145
blueprint = structuredClone(blueprint);
146146

147147
blueprint = {
@@ -502,7 +502,7 @@ interface CompileStepArgsOptions {
502502
/**
503503
* Proxy URL to use for cross-origin requests.
504504
*
505-
* @see CompileBlueprintOptions.corsProxy
505+
* @see CompileBlueprintV1Options.corsProxy
506506
*/
507507
corsProxy?: string;
508508
/**
@@ -528,7 +528,7 @@ function compileStep<S extends StepDefinition>(
528528
corsProxy,
529529
streamBundledFile,
530530
}: CompileStepArgsOptions
531-
): { run: CompiledStep; step: S; resources: Array<Resource<any>> } {
531+
): { run: CompiledV1Step; step: S; resources: Array<Resource<any>> } {
532532
const stepProgress = rootProgressTracker.stage(
533533
(step.progress?.weight || 1) / totalProgressWeight
534534
);
@@ -615,8 +615,8 @@ async function resolveArguments<T extends Record<string, unknown>>(args: T) {
615615
return resolved;
616616
}
617617

618-
export async function runBlueprintSteps(
619-
compiledBlueprint: CompiledBlueprint,
618+
export async function runBlueprintV1Steps(
619+
compiledBlueprint: CompiledBlueprintV1,
620620
playground: UniversalPHP
621621
) {
622622
await compiledBlueprint.run(playground);

packages/playground/blueprints/src/lib/v1/types.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { SupportedPHPVersion } from '@php-wasm/universal';
22
import type { StepDefinition } from '../steps';
33
import type { FileReference } from './resources';
44
import type { StreamedFile } from '@php-wasm/stream-compression';
5-
import type { Filesystem } from '@wp-playground/storage';
5+
import type { BlueprintBundle } from '../types';
66

77
export type ExtraLibrary =
88
// Install WP-CLI during boot.
@@ -12,13 +12,7 @@ export type PHPConstants = Record<string, string | boolean | number>;
1212

1313
export type StreamBundledFile = (relativePath: string) => Promise<StreamedFile>;
1414

15-
export type Blueprint = BlueprintBundle | BlueprintV1Declaration;
16-
17-
/**
18-
* A filesystem structure containing a /blueprint.json file and any
19-
* resources referenced by that blueprint.
20-
*/
21-
export type BlueprintBundle = Filesystem;
15+
export type BlueprintV1 = BlueprintV1Declaration | BlueprintBundle;
2216

2317
/**
2418
* The Blueprint declaration, typically stored in a blueprint.json file.

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import type { BlueprintV1Declaration } from '../v1/types';
22

3-
export type BlueprintV2Declaration =
4-
| string
5-
| BlueprintV1Declaration
6-
| undefined;
7-
export type ParsedBlueprintV2Declaration =
3+
export type RawBlueprintV2Data = string | BlueprintV1Declaration | undefined;
4+
export type ParsedBlueprintV2String =
85
| { type: 'inline-file'; contents: string }
96
| { type: 'file-reference'; reference: string };
107

118
export function parseBlueprintDeclaration(
12-
source: BlueprintV2Declaration | ParsedBlueprintV2Declaration
13-
): ParsedBlueprintV2Declaration {
9+
source: RawBlueprintV2Data | ParsedBlueprintV2String
10+
): ParsedBlueprintV2String {
1411
if (
1512
typeof source === 'object' &&
1613
'type' in source &&

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
import { phpVar } from '@php-wasm/util';
77
import { getV2Runner } from './get-v2-runner';
88
import {
9-
type BlueprintV2Declaration,
10-
type ParsedBlueprintV2Declaration,
9+
type RawBlueprintV2Data,
10+
type ParsedBlueprintV2String,
1111
parseBlueprintDeclaration,
1212
} from './blueprint-v2-declaration';
1313

@@ -32,7 +32,7 @@ export type BlueprintMessage =
3232
interface RunV2Options {
3333
php: UniversalPHP;
3434
cliArgs?: string[];
35-
blueprint: BlueprintV2Declaration | ParsedBlueprintV2Declaration;
35+
blueprint: RawBlueprintV2Data | ParsedBlueprintV2String;
3636
blueprintOverrides?: {
3737
wordpressVersion?: string;
3838
additionalSteps?: any[];

0 commit comments

Comments
 (0)