Skip to content

Infra/assets internal new structure #3635

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

Merged
merged 39 commits into from
Mar 20, 2025

Conversation

adids1221
Copy link
Contributor

@adids1221 adids1221 commented Mar 18, 2025

Description

Based on #3618 changes, implemented new structure for local assets on web.
Assets in .web files now represent in object of: {uri, width, height}, this object is valid source for RN Image.
In the uri we will set require(...).default as value to support webDemo and docuilib.
webDemo set eslint in imageLoader to true (true by default link)

⚠️ Removed ReactLiveScope configurations file since it's not necessary anymore, it was a fix for images with .default - all the assets files are with .default (related PR).

Snapshot version for testing: 7.39.0 - 6582

Changelog

Local Assets new structure, support web and mobile devices.

Additional info

MADS-4531

@adids1221 adids1221 changed the base branch from master to infra/Assets_internal March 18, 2025 13:57
@adids1221 adids1221 added docs docs related issue Do Not Merge! labels Mar 18, 2025
@@ -1,38 +1,38 @@
export const icons = {
get check() {
return require('./check.png');
return {uri: require('./check.png'), width: 21, height: 15};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it working?
A local assets is usually passed as a source, while external uses uri
Is that what we do in private also?

@@ -2,6 +2,23 @@ import get from 'lodash/get';
import Assets from '../assets';
import type {ImageSourceType} from '../components/image';

export function extractImageSource(source?: ImageSourceType) {
const sourceUri = get(source, 'uri');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid using get so you'll get proper typings you can change to source?.uri


if (sourceUri) {
// Case when uri is a number (Local Assets)
if (typeof sourceUri === 'number') {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't like this solution, it changes the behavior of a local asset. You are changing the way local assets are passed which is not a good idea (for instance, you can see that ColorSwatch is broken now because it's not using our Icon component)

package.json Outdated
@@ -39,7 +39,8 @@
"releaseDemo": "./scripts/release/releaseDemo.sh",
"releaseDocs": "./scripts/release/releaseDocs.sh",
"releaseEslint": "./scripts/release/releaseEslint.sh",
"releaseNative": "./scripts/release/releaseNative.sh"
"releaseNative": "./scripts/release/releaseNative.sh",
"update-web-assets": "node scripts/assets/extract-dimensions.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateWebAssets - let's follow the other scripts' naming convention

height: dimensions.height
};
} catch (sizeError) {
console.log(`Error getting dimensions for ${imagePath}:`, sizeError);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this as error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, added // eslint-disable-next-line no-restricted-syntax since we have eslint over this.
Also for the other console .

return {width: 24, height: 24};
}
} catch (error) {
console.log(`Error getting dimensions for ${imagePath}:`, error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be error


// Function to create index files with dimensions
function createIndexFile(sourcePath, targetPath, fileType) {
const files = fs.readdirSync(sourcePath).filter(file => !file.includes('@') && !file.startsWith('.'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the !file.startsWith('.') is about?

Copy link
Contributor Author

@adids1221 adids1221 Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is Devin script.
Iv'e check it's unnecessary removed.
for now we don't want to include the "sized" files @1.5x...

@@ -0,0 +1,86 @@
const fs = require('fs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the file to extractDimensions.js

Base automatically changed from infra/Assets_internal to master March 20, 2025 10:29
@adids1221 adids1221 requested a review from M-i-k-e-l March 20, 2025 10:41
@adids1221 adids1221 assigned Inbal-Tish and M-i-k-e-l and unassigned adids1221 Mar 20, 2025
@M-i-k-e-l M-i-k-e-l merged commit 24a81f3 into master Mar 20, 2025
1 check passed
@M-i-k-e-l M-i-k-e-l deleted the infra/Assets_internal_new_strucure branch March 20, 2025 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs docs related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants