Conversation
🦋 Changeset detectedLatest commit: 38fcef1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@whydidoo is attempting to deploy a commit to the Callstack Team on Vercel. A member of the Team first needs to authorize it. |
| // Keep resources loaded by name from JavaScript. | ||
| const keepFile = Promise.all(tasks).then(async () => { | ||
| const keepPath = path.join(this.config.assetsDest, 'raw', 'keep.xml'); | ||
| const content = `<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="${resources.join(',')}" />\n`; |
There was a problem hiding this comment.
The keep file works, but the way it's added doesn't quite match how AssetsCopyProcessor is built. Everything else in the class is a job that enqueueChunk pushes onto queue, and execute() just runs the queue. Here execute() takes on Android-specific logic, and the keep-file write waits on Promise.all(tasks) even though it doesn't need the copied files. On top of that, isRemote exists only so the remote processors can opt out.
How about making it a normal queued job behind its own method, called only for the local processor?
const androidResourceRegExp = /^(drawable|raw|font)(?:-[^/]+)?\/([^/]+)\.[^/.]+$/;
// Resources resolved by name at runtime are invisible to the resource shrinker
// (mirrors Metro's createKeepFileAsync).
enqueueAndroidKeepFile() {
if (!this.androidResources.size) return;
const keepPath = path.join(this.config.assetsDest, 'raw', 'keep.xml');
const resources = [...this.androidResources].sort().join(',');
this.queue.push(async () => {
await this.filesystem.promises.mkdir(path.dirname(keepPath), { recursive: true });
await this.filesystem.promises.writeFile(
keepPath,
`<resources xmlns:tools="http://schemas.android.com/tools" tools:keep="${resources}" />\n`
);
});
}// OutputPlugin.ts, after the localChunks loop
localAssetsCopyProcessor?.enqueueAndroidKeepFile();With that, execute() stays as it is on main and isRemote can be removed. Separately, OutputPlugin creates a new processor on every compilation, so the androidResources.clear() and the "earlier execution" test aren't needed.
There was a problem hiding this comment.
Thanks, Danny! That’s a really good point. I’ve updated it as you suggested
Summary
Fixes #1472.
Skia loads bundled Android fonts from
res/raw, while Re.Pack previously emitted them only tores/font.res/rawcopy for TTF, OTF, and TTC fonts, preserving existingR.fontand XML font-family references.res/raw/keep.xmlso resource shrinking preserves assets loaded by name from JavaScript.Test plan
R.fontand XML font-family references in release builds.keep.xmlcaused those resources to be removed.