@@ -30,17 +30,12 @@ import type {
3030 BlueprintV1Declaration ,
3131 OnStepCompleted ,
3232} from '@wp-playground/blueprints' ;
33- import {
34- compileBlueprintV1 ,
35- runBlueprintV1Steps ,
36- } from '@wp-playground/blueprints' ;
37- import { consumeAPI } from '@php-wasm/web' ;
3833import { ProgressTracker } from '@php-wasm/progress' ;
3934import type { MountDescriptor , PlaygroundClient } from '@wp-playground/remote' ;
40- import { collectPhpLogs , logger } from '@php-wasm/logger' ;
4135import { additionalRemoteOrigins } from './additional-remote-origins' ;
4236// eslint-disable-next-line @nx/enforce-module-boundaries
4337import { remoteDevServerHost , remoteDevServerPort } from '../../build-config' ;
38+ import { BlueprintsV1Handler } from './blueprints-v1-handler' ;
4439
4540export interface StartPlaygroundOptions {
4641 iframe : HTMLIFrameElement ;
@@ -99,22 +94,15 @@ export interface StartPlaygroundOptions {
9994 * @param options Options for loading the playground.
10095 * @returns A PlaygroundClient instance.
10196 */
102- export async function startPlaygroundWeb ( {
103- iframe,
104- blueprint,
105- remoteUrl,
106- progressTracker = new ProgressTracker ( ) ,
107- disableProgressBar,
108- onBlueprintStepCompleted,
109- onBlueprintValidated,
110- onClientConnected = ( ) => { } ,
111- sapiName,
112- mounts,
113- scope,
114- corsProxy,
115- shouldInstallWordPress,
116- sqliteDriverVersion,
117- } : StartPlaygroundOptions ) : Promise < PlaygroundClient > {
97+ export async function startPlaygroundWeb (
98+ options : StartPlaygroundOptions
99+ ) : Promise < PlaygroundClient > {
100+ const {
101+ iframe,
102+ progressTracker = new ProgressTracker ( ) ,
103+ disableProgressBar,
104+ } = options ;
105+ let { remoteUrl } = options ;
118106 assertLikelyCompatibleRemoteOrigin ( remoteUrl ) ;
119107 allowStorageAccessByUserActivation ( iframe ) ;
120108
@@ -123,60 +111,14 @@ export async function startPlaygroundWeb({
123111 } ) ;
124112 progressTracker . setCaption ( 'Preparing WordPress' ) ;
125113
126- // Set a default blueprint if none is provided.
127- if ( ! blueprint ) {
128- blueprint = { } ;
129- }
130-
131- const compiled = await compileBlueprintV1 ( blueprint , {
132- progress : progressTracker . stage ( 0.5 ) ,
133- onStepCompleted : onBlueprintStepCompleted ,
134- onBlueprintValidated,
135- corsProxy,
136- } ) ;
137-
138114 await new Promise ( ( resolve ) => {
139115 iframe . src = remoteUrl ;
140116 iframe . addEventListener ( 'load' , resolve , false ) ;
141117 } ) ;
142118
143- // Connect the Comlink API client to the remote worker,
144- // boot the playground, and run the blueprint steps.
145- const playground = consumeAPI < PlaygroundClient > (
146- iframe . contentWindow ! ,
147- iframe . ownerDocument ! . defaultView !
148- ) as PlaygroundClient ;
149- await playground . isConnected ( ) ;
150- progressTracker . pipe ( playground ) ;
151- const downloadPHPandWP = progressTracker . stage ( ) ;
152- await playground . onDownloadProgress ( downloadPHPandWP . loadingListener ) ;
153- await playground . boot ( {
154- mounts,
155- sapiName,
156- scope : scope ?? Math . random ( ) . toFixed ( 16 ) ,
157- shouldInstallWordPress,
158- phpVersion : compiled . versions . php ,
159- wpVersion : compiled . versions . wp ,
160- withICU : compiled . features . intl ,
161- withNetworking : compiled . features . networking ,
162- corsProxyUrl : corsProxy ,
163- sqliteDriverVersion,
164- } ) ;
165- await playground . isReady ( ) ;
166- downloadPHPandWP . finish ( ) ;
119+ const handler = new BlueprintsV1Handler ( options ) ;
120+ const playground = await handler . bootPlayground ( iframe , progressTracker ) ;
167121
168- collectPhpLogs ( logger , playground ) ;
169- onClientConnected ( playground ) ;
170-
171- await runBlueprintV1Steps ( compiled , playground ) ;
172- /**
173- * Pre-fetch WordPress update checks to speed up the initial wp-admin load.
174- *
175- * @see https://github.com/WordPress/wordpress-playground/pull/2295
176- */
177- if ( compiled . features . networking ) {
178- await playground . prefetchUpdateChecks ( ) ;
179- }
180122 progressTracker . finish ( ) ;
181123
182124 return playground ;
0 commit comments