@wp-playground/blueprints 0.1.30 → 0.1.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wp-playground/blueprints",
3
- "version": "0.1.30",
3
+ "version": "0.1.33",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./index.js",
@@ -20,5 +20,5 @@
20
20
  "publishConfig": {
21
21
  "access": "public"
22
22
  },
23
- "gitHead": "df3e9bff1de33d53d026c35a6ba5534aeff21a78"
23
+ "gitHead": "5bcbe7698d538b407ecb3f6c68b111eda03e0543"
24
24
  }
@@ -82,9 +82,12 @@ export function compileBlueprint(
82
82
  run: async (playground: UniversalPHP) => {
83
83
  try {
84
84
  // Start resolving resources early
85
- for (const { asyncResources } of compiled) {
86
- for (const resource of asyncResources) {
87
- resource.resolve();
85
+ for (const { resources } of compiled) {
86
+ for (const resource of resources) {
87
+ resource.setPlayground(playground);
88
+ if (resource.isAsync) {
89
+ resource.resolve();
90
+ }
88
91
  }
89
92
  }
90
93
 
@@ -92,10 +95,17 @@ export function compileBlueprint(
92
95
  const result = await run(playground);
93
96
  onStepCompleted(result, step);
94
97
  }
95
- if ('goTo' in playground) {
98
+ try {
96
99
  await (playground as any).goTo(
97
100
  blueprint.landingPage || '/'
98
101
  );
102
+ } catch (e) {
103
+ /*
104
+ * NodePHP exposes no goTo method.
105
+ * We can't use `goto` in playground here,
106
+ * because it may be a Comlink proxy object
107
+ * with no such method.
108
+ */
99
109
  }
100
110
  } finally {
101
111
  progress.finish();
@@ -159,7 +169,7 @@ function compileStep<S extends StepDefinition>(
159
169
  rootProgressTracker,
160
170
  totalProgressWeight,
161
171
  }: CompileStepArgsOptions
162
- ): { run: CompiledStep; step: S; asyncResources: Array<Resource> } {
172
+ ): { run: CompiledStep; step: S; resources: Array<Resource> } {
163
173
  const stepProgress = rootProgressTracker.stage(
164
174
  (step.progress?.weight || 1) / totalProgressWeight
165
175
  );
@@ -195,6 +205,7 @@ function compileStep<S extends StepDefinition>(
195
205
  * The weight of each async resource is the same, and is the same as the
196
206
  * weight of the step itself.
197
207
  */
208
+ const resources = getResources(args);
198
209
  const asyncResources = getResources(args).filter(
199
210
  (resource) => resource.isAsync
200
211
  );
@@ -204,7 +215,7 @@ function compileStep<S extends StepDefinition>(
204
215
  resource.progress = stepProgress.stage(evenWeight);
205
216
  }
206
217
 
207
- return { run, step, asyncResources };
218
+ return { run, step, resources };
208
219
  }
209
220
 
210
221
  /**
@@ -344,6 +344,11 @@ export class DecoratedResource<T extends Resource> extends Resource {
344
344
  return this.resource.resolve();
345
345
  }
346
346
 
347
+ /** @inheritDoc */
348
+ override async setPlayground(playground: UniversalPHP) {
349
+ return this.resource.setPlayground(playground);
350
+ }
351
+
347
352
  /** @inheritDoc */
348
353
  get progress() {
349
354
  return this.resource.progress;
@@ -9,19 +9,21 @@ export type SetSiteOptionsStep = {
9
9
 
10
10
  export const setSiteOptions: StepHandler<SetSiteOptionsStep> = async (
11
11
  client,
12
- options
12
+ { options }
13
13
  ) => {
14
- const result = await client.run({
15
- code: `<?php
14
+ const code = `<?php
16
15
  include 'wordpress/wp-load.php';
17
16
  $site_options = ${phpVar(options)};
18
17
  foreach($site_options as $name => $value) {
19
18
  update_option($name, $value);
20
19
  }
21
20
  echo "Success";
22
- `,
21
+ `;
22
+ const result = await client.run({
23
+ code,
23
24
  });
24
25
  assertSuccess(result);
26
+ return { code, result };
25
27
  };
26
28
 
27
29
  export interface UpdateUserMetaStep {
@@ -33,17 +35,19 @@ export const updateUserMeta: StepHandler<UpdateUserMetaStep> = async (
33
35
  client,
34
36
  { meta, userId }
35
37
  ) => {
36
- const result = await client.run({
37
- code: `<?php
38
+ const code = `<?php
38
39
  include 'wordpress/wp-load.php';
39
40
  $meta = ${phpVar(meta)};
40
41
  foreach($meta as $name => $value) {
41
42
  update_user_meta(${phpVar(userId)}, $name, $value);
42
43
  }
43
44
  echo "Success";
44
- `,
45
+ `;
46
+ const result = await client.run({
47
+ code,
45
48
  });
46
49
  assertSuccess(result);
50
+ return { code, result };
47
51
  };
48
52
 
49
53
  async function assertSuccess(result: PHPResponse) {