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(Package): convert to strict ESM #1215

Draft
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

pladaria
Copy link
Member

@pladaria pladaria commented Aug 27, 2024

BREAKING CHANGE:

  • This library is now a strict ESM package
  • import icons from '@telefonica/mistica/icons'

Tasks in this PR

  • New package.json exports configuration
  • simplified dist folder
    • exported css files are now located in dist/css (physical location)
    • no temporary dist-ts folder for type definitions generation
  • commonjs scripts now use the .cjs extension
  • Icons export using export * from

@pladaria pladaria marked this pull request as draft August 27, 2024 09:19
Copy link

github-actions bot commented Aug 27, 2024

Size stats

master this branch diff
Total JS 12.1 MB 12.2 MB +81.4 kB
JS without icons 2.03 MB 2.24 MB +213 kB
Lib overhead 77.1 kB 76.7 kB -352 B
Lib overhead (gzip) 18.9 kB 18.4 kB -451 B

Copy link

github-actions bot commented Aug 29, 2024

Accessibility report
✔️ No issues found

ℹ️ You can run this locally by executing yarn audit-accessibility.

Copy link

github-actions bot commented Aug 29, 2024

Deploy preview for mistica-web ready!

✅ Preview
https://mistica-92wamniz8-flows-projects-65bb050e.vercel.app

Built with commit 3930366.
This pull request is being automatically deployed with vercel-action

Comment on lines +35 to +36
"test-acceptance": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs test-acceptance --config jest.acceptance.config.cjs",
"test-ssr": "JEST_PUPPETEER_CONFIG=jest-puppeteer.config.cjs test-acceptance --config jest.ssr.config.cjs",
Copy link
Member Author

Choose a reason for hiding this comment

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

The JEST_PUPPETEER_CONFIG env var tells jest-environment-puppeteer where to find the puppeteer config.
This is needed because we're using an old version of the jest-environment-puppeteer library (v6) and it is unaware of .cjs files. Newer versions don't have this issue but we cannot upgrade because this requires a puppeteer upgrade.

Comment on lines +1 to +5
{
"env": {
"es6": true
}
}
Copy link
Member Author

@pladaria pladaria Aug 29, 2024

Choose a reason for hiding this comment

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

We should update our jest configuration to understand .cjs files.
https://jira.tid.es/browse/WEB-2005

Comment on lines +44 to +55
// otherwise, all dependencies are included in a "node_modules" folder inside "./dist"
external: [
...Object.keys(packageJson.dependencies),
...Object.keys(packageJson.peerDependencies),
'react/jsx-runtime',
'moment/locale/de.js',
'moment/locale/es.js',
'moment/locale/en-gb.js',
'moment/locale/pt-br.js',
'moment/moment.js',
'@vanilla-extract/sprinkles/createRuntimeSprinkles',
],
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, without this, a node_modules folder is created inside dist containing copies of all external packages, including react and react-dom. That produces a broken build because using mistica introduces two copies of react.

Comment on lines -219 to -233
/*
* Temporary solution to export Community components until Mistica gets migrated to ESModules
* the community.js export has issues because it exports an ES module and next12 interterprets it as a CommonJS module
* importing from /dist/ is not an option because those modules don't get the context from the theme provider
*/
export {default as CommunityExampleComponent} from './community/example-component';
export {default as CommunityAdvancedDataCard} from './community/advanced-data-card';
export {
RowBlock as CommunityRowBlock,
SimpleBlock as CommunitySimpleBlock,
InformationBlock as CommunityInformationBlock,
HighlightedValueBlock as CommunityHighlightedValueBlock,
ValueBlock as CommunityValueBlock,
ProgressBlock as CommunityProgressBlock,
} from './community/blocks';
Copy link
Member Author

Choose a reason for hiding this comment

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

see package.json. There is now a dedicated export in /community for these components

Copy link

github-actions bot commented Aug 29, 2024

Screenshot tests report

✔️ All passing

} from './community/blocks';
export {default as iconKeywords} from './generated/mistica-icons/icons-keywords';

// Exported this way to facilitate tree-shaking
Copy link
Member Author

Choose a reason for hiding this comment

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

no more copy paste needed. The icons are exported as export * from './generated/mistica-icons'; (see the end of this file)

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

Successfully merging this pull request may close these issues.

1 participant