Skip to content

Commit

Permalink
Preserve SVG assets in wp.data bundle
Browse files Browse the repository at this point in the history
Restores a few SVG files that were previously stripped from the data
bundle and restored as empty files via addMissingSvgs() function.

This allows us to apply one WordPress patch less (`addMissingSvgs()`).
  • Loading branch information
adamziel committed Oct 16, 2023
1 parent 3000aef commit d744c4c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 17 deletions.
5 changes: 4 additions & 1 deletion packages/playground/compile-wordpress/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ RUN cd wordpress && \
-o -name '*.scss' -o -name '*.stylelintignore' -o -name '*.svg' \
-o -name '*.ttf' -o -name '*.txt' -o -name '*.woff' \
-o -name '*.woff2' -o -name '*.jpeg' -o -name '*.jpg' \
\) -delete
\) \
# Preserve the wp-admin SVG files that are read by PHP
-not -path '*/wp-admin/images/*.svg' \
-delete

# Keep only the CSS files that are read by PHP
RUN cd wordpress && \
Expand Down
16 changes: 0 additions & 16 deletions packages/playground/remote/src/lib/web-wordpress-patches/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export function applyWebWordPressPatches(php: UniversalPHP) {
const patch = new WordPressPatcher(php, DOCROOT);

patch.replaceRequestsTransports();
patch.addMissingSvgs();
}

class WordPressPatcher {
Expand Down Expand Up @@ -87,21 +86,6 @@ class WordPressPatcher {
linksTargetingTopFrameShouldTargetPlaygroundIframe
);
}

async addMissingSvgs() {
// @TODO: use only on the web version, or not even there – just include these
// in WordPress build:
this.php.mkdirTree(`${this.wordpressPath}/wp-admin/images`);
const missingSvgs = [
`${this.wordpressPath}/wp-admin/images/about-header-about.svg`,
`${this.wordpressPath}/wp-admin/images/dashboard-background.svg`,
];
for (const missingSvg of missingSvgs) {
if (!(await this.php.fileExists(missingSvg))) {
await this.php.writeFile(missingSvg, '');
}
}
}
}

type PatchFileCallback = (contents: string) => string | Uint8Array;
Expand Down

0 comments on commit d744c4c

Please sign in to comment.