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
build!: generate cjs and type declarations #1572
Conversation
22dab1b
to
45f2ba5
Compare
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react", | ||
"lib": ["es5", "es6", "dom"], | ||
"moduleResolution": "node", | ||
"noUnusedLocals": true, | ||
"outDir": "lib", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer using tsc
to build
tsconfig.json
Outdated
@@ -4,13 +4,13 @@ | |||
"allowJs": false, | |||
"allowSyntheticDefaultImports": true, | |||
"declaration": true, | |||
"declarationDir": "lib/types", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
builds the declaration files to this folder
rollup.config.mjs
Outdated
*/ | ||
declaration: false, | ||
declarationDir: undefined, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already an issue raised in the plugin repo rollup/plugins#1230 (comment)
format: 'cjs', | ||
preserveModules: true, | ||
preserveModulesRoot: 'src', | ||
sourcemap: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can turn sourcemaps off, not sure if anyone will take a look but also wouldn't hurt to have
@@ -90,8 +93,6 @@ | |||
"react-popper": "^2.3.0", | |||
"react-portal": "^4.2.2" | |||
}, | |||
"entry": "lib/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what this line did?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea. Probs something in the BM template that doesn't do anything.
Codecov Report
@@ Coverage Diff @@
## ah-ssr-build #1572 +/- ##
=============================================
Coverage 91.63% 91.63%
=============================================
Files 279 279
Lines 4269 4269
Branches 775 775
=============================================
Hits 3912 3912
Misses 331 331
Partials 26 26
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
package.json
Outdated
"main": "lib/cjs/index.js", | ||
"module": "lib/es/index.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These will certainly work 👍
Although in the future we may want to switch over to conditional exports.
Per https://nodejs.org/api/packages.html#dual-commonjses-module-packages (and other places in the docs), I think exports
is preferred now (although main/module is still common).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 🤘
"./tailwind.config.mjs": { | ||
"import": "./tailwind.config.mjs" | ||
} | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahuth Not sure if I'm using conditional exports right but seems that we have to explicitly state which files are allowed to be exported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's true. I kind of forgot that there was more than just the index.js files (such as fonts, css, tailwind, etc).
Does this seem like it's too cumbersome, or is it okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine unless consumers want to use some of the internal components or the utils, which we haven't come across yet
preserveModules: true, | ||
preserveModulesRoot: 'src', | ||
sourcemap: true, | ||
entryFileNames: '[name].cjs', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either way seems reasonable, so let's go with your preference.
tailwind.config.mjs
Outdated
@@ -64,4 +66,4 @@ export default { | |||
xxl: '1400px', | |||
}, | |||
}, | |||
} satisfies Config; | |||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahuth I converted this into an mjs
file so that it can be used without processing in pilots, still getting typing with the jsdoc @type
tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to keep this TS, so that it's easier for the pilots to write their tailwind files in TS.
Meaning, the pilot swill have to process their tailwind.config.ts anyway, so it's fine for that TS file to import another TS file (the EDS tailwind config).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me, reverted to TS
"./index.css": { | ||
"import": "./lib/index.css", | ||
"require": "./lib/index.css" | ||
}, | ||
"./fonts.css": { | ||
"import": "./lib/tokens/fonts.css", | ||
"require": "./lib/tokens/fonts.css" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I short handed some of these styles exports so it's less unwieldy (i.e. import '@chanzuckerberg/eds/fonts.css
and not import @chanzuckerberg/eds/lib/tokens/fonts.css
) ... it IS breaking but the whole build feature will be breaking so might as well include it... lmk if we shouldn't break this since cost is pretty low
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"suppressImplicitAnyIndexErrors": true, | ||
"target": "es6" | ||
"target": "es2018" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Target is being bumped to remove tslib
usage in running rollup build with @rollup/plugin-typescript
. tslib was used for __rest
utility which is the spread object functionality that comes with es2018
. tslib
is being grepped for as a build test
then | ||
echo "tslib found in lib" | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested failing with es2017
https://github.com/chanzuckerberg/edu-design-system/actions/runs/4600946862/jobs/8128192461
* build: use rollup to build JS and styles - To better support server-side rendering - By producing a single .css file - Instead of delegating css module processing to consuming apps * refactor(rollup): remove spritemap and commonjs from config * build: remove styles build from main build command * refactor: import css variables into index * build(rollup): mark dependencies as external (#1558) * build(rollup): mark dependencies as external * build(rollup): use node resolve plugin * docs(build): explain rollup external option * build!: generate cjs and type declarations (#1572) * build: generate cjs and esm, separate types build * build: add sourcemaps and add declaration back to tsconfig * build: cjs and js in the same output * build: add conditional exports * build: remove build types script * refactor: revert tw config to ts * build: bump target to es2018 and grep for tslib * chore(release): 12.0.0-alpha.0 * refactor: dry css exports * build!: remove some tokens from build (#1581) * refactor: remove references to unexported files * build!: no longer include some tokens in build * refactor: remove unused commonjs plugin (#1582) * chore(release): 12.0.0-alpha.1 * refactor: use named import for clsx * chore: remove rollup plugin commonjs * Revert "refactor: use named import for clsx" This reverts commit d58182b. * docs: explicate tslib grep * fix: no need for ts expect error --------- Co-authored-by: Andrew Huth <ahuth@chanzuckerberg.com>
## [12.0.0](v11.1.1...v12.0.0) (2023-04-17) ### ⚠ BREAKING CHANGES * use rollup (#1555) ### Features * export some subcomponents ([#1579](#1579)) ([2857ae4](2857ae4)) * **TextareaField:** add character length counter ([#1580](#1580)) ([ff6226f](ff6226f)) ### Bug Fixes * restore check for undefined any types ([#1585](#1585)) ([c7fae07](c7fae07)) * **Skeleton:** mark .Rect as deprecated ([#1586](#1586)) ([405f81b](405f81b)) * sync typography presets to documentation ([#1592](#1592)) ([b56eadb](b56eadb)) * **typography:** add missing eds-font-size-20 ([#1591](#1591)) ([de5dd03](de5dd03)) ### build * use rollup ([#1555](#1555)) ([d794696](d794696)), closes [#1558](#1558) [#1572](#1572) [#1581](#1581) [#1582](#1582)
EDS-886
Summary:
*.cjs
files to/lib
*.js
files tolib
lib/types
Test Plan:
node_modules/@chanzuckerberg/eds
debugger
line to one of the used components in thees
folder to make sure the esm build was being used:debugger
into a component not being used did not trigger the browser debugger, suggesting tree shaking is workingnpm test
in edu-stack passes even withtransformIgnorePatterns: ['/node_modules/(?!(@chanzuckerberg/eds))']
removedtslib
since that was a peerdep of@rollup/plugin-typescript