Skip to content

Commit a2c517a

Browse files
committed
Move preloading the data-liberation-core.phar to the compile() function
1 parent 043a225 commit a2c517a

File tree

2 files changed

+16
-21
lines changed

2 files changed

+16
-21
lines changed

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { Step, StepDefinition, WriteFileStep } from './steps';
1111
import * as allStepHandlers from './steps/handlers';
1212
import { Blueprint, ExtraLibrary } from './blueprint';
1313
import { logger } from '@php-wasm/logger';
14+
/* @ts-ignore */
15+
// eslint-disable-next-line
16+
import dataLiberationCoreUrl from '../../../data-liberation/dist/data-liberation-core.phar.gz?url';
1417

1518
// @TODO: Configure this in the `wp-cli` step, not here.
1619
const { wpCLI, ...otherStepHandlers } = allStepHandlers;
@@ -229,11 +232,12 @@ export function compileBlueprint(
229232
);
230233
if (importWxrStepIndex !== undefined && importWxrStepIndex > -1) {
231234
blueprint.steps?.splice(importWxrStepIndex, 0, {
232-
step: 'installPlugin',
233-
pluginData: {
235+
step: 'writeFile',
236+
path: '/internal/shared/data-liberation-core.phar',
237+
data: {
234238
resource: 'url',
235-
url: 'https://playground.wordpress.net/wordpress-importer.zip',
236-
caption: 'Downloading the WordPress Importer plugin',
239+
url: dataLiberationCoreUrl,
240+
caption: 'Downloading the Data Liberation WXR importer',
237241
},
238242
});
239243
}

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

+8-17
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,10 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = async (
3737
progress?
3838
) => {
3939
progress?.tracker?.setCaption('Importing content');
40-
try {
41-
const dataLiberationPlugin = await fetch(dataLiberationPluginUrl);
42-
await playground.writeFile(
43-
'/internal/shared/data-liberation.phar',
44-
new Uint8Array(await dataLiberationPlugin.arrayBuffer())
45-
);
46-
await writeFile(playground, {
47-
path: '/tmp/import.wxr',
48-
data: file,
49-
});
50-
} catch (e) {
51-
console.log('oops');
52-
console.log(e);
53-
console.error(e);
54-
throw e;
55-
}
40+
await writeFile(playground, {
41+
path: '/tmp/import.wxr',
42+
data: file,
43+
});
5644
const docroot = await playground.documentRoot;
5745
playground.onMessage((messageString) => {
5846
const message = JSON.parse(messageString) as any;
@@ -68,6 +56,8 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = async (
6856
require ${phpVar(docroot)} . '/wp-load.php';
6957
require ${phpVar(docroot)} . '/wp-admin/includes/admin.php';
7058
59+
// Defines the constants expected by the Box .phar stub when "cli" is used
60+
// as the SAPI name.
7161
// @TODO: Don't use the "cli" SAPI string and don't allow composer to run platform checks.
7262
if(!defined('STDERR')) {
7363
define('STDERR', fopen('php://stderr', 'w'));
@@ -78,7 +68,8 @@ export const importWxr: StepHandler<ImportWxrStep<File>> = async (
7868
if(!defined('STDOUT')) {
7969
define('STDOUT', fopen('php://stdout', 'w'));
8070
}
81-
require '/internal/shared/data-liberation.phar';
71+
// Preloaded by the Blueprint compile() function
72+
require '/internal/shared/data-liberation-core.phar';
8273
8374
$admin_id = get_users(array('role' => 'Administrator') )[0]->ID;
8475
wp_set_current_user( $admin_id );

0 commit comments

Comments
 (0)