-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor saveAssets code to allow out of tree overrides (#2591)
- Loading branch information
1 parent
642f233
commit 2edf436
Showing
11 changed files
with
181 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@rnx-kit/metro-service": minor | ||
--- | ||
|
||
Refactor saveAssets code to allow out of tree overrides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import path from "path"; | ||
import type { PackagerAsset, SaveAssetsPlugin } from "./types"; | ||
|
||
export function getAssetDestPath(asset: PackagerAsset, scale: number): string { | ||
const suffix = scale === 1 ? "" : `@${scale}x`; | ||
const fileName = `${asset.name + suffix}.${asset.type}`; | ||
return path.join( | ||
// Assets can have relative paths outside of the project root. | ||
// Replace `../` with `_` to make sure they don't end up outside of | ||
// the expected assets directory. | ||
asset.httpServerLocation.substr(1).replace(/\.\.\//g, "_"), | ||
fileName | ||
); | ||
} | ||
|
||
export const saveAssetsDefault: SaveAssetsPlugin = ( | ||
assets, | ||
_platform, | ||
_assetsDest, | ||
_assetCatalogDest, | ||
addAssetToCopy | ||
) => { | ||
assets.forEach((asset) => addAssetToCopy(asset, undefined, getAssetDestPath)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
import type { AssetData } from "metro"; | ||
|
||
export type PackagerAsset = { | ||
httpServerLocation: string; | ||
name: string; | ||
type: string; | ||
}; | ||
|
||
export type SaveAssetsPlugin = ( | ||
assets: ReadonlyArray<AssetData>, | ||
platform: string, | ||
assetsDest: string | undefined, | ||
assetCatalogDest: string | undefined, | ||
addAssetToCopy: ( | ||
asset: AssetData, | ||
allowedScales: number[] | undefined, | ||
getAssetDestPath: (asset: AssetData, scale: number) => string | ||
) => void | ||
) => void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.