Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Blueprints] Support Data Liberation importer in the importWxr step #2058

Merged
merged 38 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
27140e6
Blueprints: Use the Data Liberation plumbing in the importWxr step
adamziel Dec 5, 2024
bedde04
Fetch all requests via the CORS proxy, rebuild the http client to sup…
adamziel Dec 5, 2024
ae8328e
Rewrite attachments URLs even when they're served from another domain
adamziel Dec 5, 2024
d918af8
Don't assume any particular attachments domains mapping. Instead, exp…
adamziel Dec 5, 2024
22412ee
Detect attachments URLs based on the presence of a downloaded artifact.
adamziel Dec 5, 2024
05e0f6b
Phar building pipeline to use the data liberation plugin in the
adamziel Dec 7, 2024
043a225
Cleanup the build scripts
adamziel Dec 7, 2024
a2c517a
Move preloading the data-liberation-core.phar to the compile() function
adamziel Dec 7, 2024
e6896c6
Added development instructions to README.md
adamziel Dec 7, 2024
a44731d
Display WXR importing progress in the Playground loading bar
adamziel Dec 7, 2024
a5f77d1
Pass corsProxyUrl to TCPOverFetchWebsocket fro bootSiteClient
adamziel Dec 7, 2024
0d184e8
Conditionally enable the new importer based on the `"importer"` option
adamziel Dec 8, 2024
8b8defc
Remove a completed todo
adamziel Dec 8, 2024
e4e732b
Remove dev artifacts
adamziel Dec 8, 2024
b93a258
Lint PHP
adamziel Dec 8, 2024
82b6cd8
Update WP_Import_Session.php
adamziel Dec 8, 2024
6cca246
Resolve type problems
adamziel Dec 8, 2024
06a3a80
Revert unnecessary WP_Block_Markup_Url_Processor change
adamziel Dec 8, 2024
c45cd5b
Use the correct path comparison in is_child_url_of
adamziel Dec 8, 2024
3cff0a8
PHP 7.2 compat by forking and downgrading the dependencies
adamziel Dec 9, 2024
2313a2f
Add rector.php and downgrading README
adamziel Dec 9, 2024
f5cb3c6
Don't pass two copies of the access-Control headers to the requesting…
adamziel Dec 10, 2024
6f30925
Add an e2e test that checks against an exact string value to sutface …
adamziel Dec 10, 2024
7e03c88
Remove the forked WXR_Importer
adamziel Dec 10, 2024
5432fb6
Restore the previous e2e test
adamziel Dec 10, 2024
00ae242
Disable cors proxy in local e2e tests
adamziel Dec 10, 2024
187f4fe
Setup CORS proxy in CI
adamziel Dec 10, 2024
9013585
Merge branch 'trunk' into import-wxr-via-data-liberation
adamziel Dec 10, 2024
86faea4
Double the timeout for starting the CI dev server
adamziel Dec 10, 2024
8892672
Use preview-server instead of preview:server job name
adamziel Dec 10, 2024
feae37d
Propagate the CI config to the preview server
adamziel Dec 10, 2024
0f46d6a
Always run preview:server in ci mode
adamziel Dec 10, 2024
b0e5279
Try yet another way of starting the preview server
adamziel Dec 10, 2024
fc91300
Adjust the CORS request test
adamziel Dec 10, 2024
78e9a5d
Fetch a known fixed-length file to test the cors proxy
adamziel Dec 11, 2024
fe9ab1d
Adjust test value
adamziel Dec 11, 2024
ab8b2c2
Cors proxy: Prevent the HTTP/2 line from passing through to Safari to…
adamziel Dec 11, 2024
c2ec41d
Bump Playwright timeout from 30s to 45s – some checks can be slow in CI!
adamziel Dec 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Install Playwright Browsers
run: sudo npx playwright install --with-deps
- name: Prepare app deploy and offline mode
run: npx nx e2e:playwright:prepare-app-deploy-and-offline-mode playground-website
run: CORS_PROXY_URL=http://127.0.0.1:5263/cors-proxy.php? npx nx e2e:playwright:prepare-app-deploy-and-offline-mode playground-website
- name: Zip dist
run: zip -r dist.zip dist
- name: Upload dist
Expand Down
4 changes: 2 additions & 2 deletions packages/php-wasm/universal/src/lib/php-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ export class PHPWorker implements LimitedPHPApi {
}

/** @inheritDoc @php-wasm/universal!/PHP.onMessage */
onMessage(listener: MessageListener): void {
_private.get(this)!.php!.onMessage(listener);
onMessage(listener: MessageListener) {
return _private.get(this)!.php!.onMessage(listener);
}

/** @inheritDoc @php-wasm/universal!/PHP.defineConstant */
Expand Down
5 changes: 5 additions & 0 deletions packages/php-wasm/universal/src/lib/php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ export class PHP implements Disposable {
*/
onMessage(listener: MessageListener) {
this.#messageListeners.push(listener);
return async () => {
this.#messageListeners = this.#messageListeners.filter(
(l) => l !== listener
);
};
}

async setSpawnHandler(handler: SpawnHandler | string) {
Expand Down
56 changes: 46 additions & 10 deletions packages/php-wasm/web/src/lib/tcp-over-fetch-websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { ContentTypes } from './tls/1_2/types';

export type TCPOverFetchOptions = {
CAroot: GeneratedCertificate;
corsProxyUrl?: string;
};

/**
Expand All @@ -67,6 +68,7 @@ export const tcpOverFetchWebsocket = (tcpOptions: TCPOverFetchOptions) => {
constructor(url: string, wsOptions: string[]) {
super(url, wsOptions, {
CAroot: tcpOptions.CAroot,
corsProxyUrl: tcpOptions.corsProxyUrl,
});
}
};
Expand All @@ -85,6 +87,7 @@ export interface TCPOverFetchWebsocketOptions {
* clientDownstream stream and tracking the closure of that stream.
*/
outputType?: 'messages' | 'stream';
corsProxyUrl?: string;
}

export class TCPOverFetchWebsocket {
Expand All @@ -101,6 +104,7 @@ export class TCPOverFetchWebsocket {
port = 0;
listeners = new Map<string, any>();
CAroot?: GeneratedCertificate;
corsProxyUrl?: string;

clientUpstream = new TransformStream();
clientUpstreamWriter = this.clientUpstream.writable.getWriter();
Expand All @@ -111,13 +115,18 @@ export class TCPOverFetchWebsocket {
constructor(
public url: string,
public options: string[],
{ CAroot, outputType = 'messages' }: TCPOverFetchWebsocketOptions = {}
{
CAroot,
corsProxyUrl,
outputType = 'messages',
}: TCPOverFetchWebsocketOptions = {}
) {
const wsUrl = new URL(url);
this.host = wsUrl.searchParams.get('host')!;
this.port = parseInt(wsUrl.searchParams.get('port')!, 10);
this.binaryType = 'arraybuffer';

this.corsProxyUrl = corsProxyUrl;
this.CAroot = CAroot;
if (outputType === 'messages') {
this.clientDownstream.readable
Expand Down Expand Up @@ -307,9 +316,10 @@ export class TCPOverFetchWebsocket {
'https'
);
try {
await RawBytesFetch.fetchRawResponseBytes(request).pipeTo(
tlsConnection.serverEnd.downstream.writable
);
await RawBytesFetch.fetchRawResponseBytes(
request,
this.corsProxyUrl
).pipeTo(tlsConnection.serverEnd.downstream.writable);
} catch (e) {
// Ignore errors from fetch()
// They are handled in the constructor
Expand All @@ -327,9 +337,10 @@ export class TCPOverFetchWebsocket {
'http'
);
try {
await RawBytesFetch.fetchRawResponseBytes(request).pipeTo(
this.clientDownstream.writable
);
await RawBytesFetch.fetchRawResponseBytes(
request,
this.corsProxyUrl
).pipeTo(this.clientDownstream.writable);
} catch (e) {
// Ignore errors from fetch()
// They are handled in the constructor
Expand Down Expand Up @@ -409,7 +420,11 @@ class RawBytesFetch {
/**
* Streams a HTTP response including the status line and headers.
*/
static fetchRawResponseBytes(request: Request) {
static fetchRawResponseBytes(request: Request, corsProxyUrl?: string) {
const targetRequest = corsProxyUrl
? new Request(`${corsProxyUrl}${request.url}`, request)
: request;

// This initially used a TransformStream and piped the response
// body to the writable side of the TransformStream.
//
Expand All @@ -419,13 +434,34 @@ class RawBytesFetch {
async start(controller) {
let response: Response;
try {
response = await fetch(request);
controller.enqueue(RawBytesFetch.headersAsBytes(response));
response = await fetch(targetRequest);
} catch (error) {
/**
* Pretend we've got a 400 Bad Request response whenever
* the fetch() call fails.
*
* Just propagating an error and closing a WebSocket does
* not make PHP aware the socket closed abruptly. This means
* the AsyncHttp\Client will keep polling the socket indefinitely
* until the request times out. This isn't perfect, as we want
* to close the socket as soon as possible to avoid, e.g., 10 seconds
* of unnecessary waitin for the timeout
*
* The root cause is unknown and likely related to the low-level
* implementation of polling file descriptors. The following
* workaround is far from ideal, but it must suffice until we
* have a platform-level resolution.
*/
controller.enqueue(
new TextEncoder().encode(
'HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\n\r\n'
)
);
controller.error(error);
return;
}

controller.enqueue(RawBytesFetch.headersAsBytes(response));
const reader = response.body?.getReader();
if (!reader) {
controller.close();
Expand Down
Loading
Loading