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

feat(packages/sui-studio): Add new param to use explicit import #1460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

stivaliserna
Copy link
Member

Description

This PR adds a new option --explicit to generate a component in a file with its same name and an index re-export, this makes searching easier while keeping cleaner imports.

Component
  src
    |--Component.js
    |--index.js

Beta: @s-ui/[email protected]

Feedback is much appreciated 🙂

@@ -52,6 +53,7 @@ const componentInPascal = toPascalCase(
const COMPONENT_DIR = `/components/${category}/${component}/`
const COMPONENT_PATH = `${BASE_DIR}${COMPONENT_DIR}`
const COMPONENT_ENTRY_JS_POINT_FILE = `${COMPONENT_PATH}src/index.js`
const COMPONENT_JS_POINT_FILE = `${COMPONENT_PATH}src/${componentInPascal}.js`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe a more descriptive name would help, something like EXPLICIT_COMPONENT_JS_POINT_FILE

Copy link
Member Author

Choose a reason for hiding this comment

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

Agree! 👌 Thanks Javi!

Comment on lines +158 to +161
const explicitImportTemplate = `import ${componentInPascal} from './${componentInPascal}.js'

export default ${componentInPascal}
`
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we can go with the shorter version that mixes the rexport of default and named exports.

Suggested change
const explicitImportTemplate = `import ${componentInPascal} from './${componentInPascal}.js'
export default ${componentInPascal}
`
const explicitImportTemplate = `export {default} from './${componentInPascal}.js'
`

Then if we want to export some named (for example: foo and bar) things inside the component would be much shorter:

const explicitImportTemplate = export {default, foo, bar} from './${componentInPascal}.js'`

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a proposal in stage 1, I checked and we use @babel/plugin-proposal-export-default-from to support it. If we're sure our infra will keep it, I'm ok with the change, but just want to double check 🙂

@arnau-rius
Copy link
Contributor

If this is the new way of generating component, maybe we should create a script to modify also the already created components, so we just have one standard way of creating components. What do you think?

@stivaliserna
Copy link
Member Author

If this is the new way of generating component, maybe we should create a script to modify also the already created components, so we just have one standard way of creating components. What do you think?

Yeah, makes sense! And we'll need to migrate the rest of components to actually solve our pain. Will work on it 👌

Thanks @arnau-rius!

@arnau-rius
Copy link
Contributor

If this is the new way of generating component, maybe we should create a script to modify also the already created components, so we just have one standard way of creating components. What do you think?

Yeah, makes sense! And we'll need to migrate the rest of components to actually solve our pain. Will work on it 👌

Thanks @arnau-rius!

In case it gives you some guidance, here you can find two migrations that previously had been applied to the sui-studio, for cases similar to this one.

https://github.com/SUI-Components/sui/tree/master/packages/sui-studio/bin/migrations

  • demo-folders
  • test-folders

Maybe would be interesting to check that all marketplaces are OK with this new structure before coding/planning a migration.

👍🏽

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants