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: update to rollup 4 #1370

Merged
merged 21 commits into from Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/x-archetype-utils/package.json
Expand Up @@ -37,17 +37,17 @@
},
"dependencies": {
"@empathyco/x-deep-merge": "^2.0.3-alpha.0",
"@empathyco/x-utils": "workspace:^1.0.3-alpha.0",
"tslib": "~2.6.0",
"vue-i18n": "~8.28.2"
},
"devDependencies": {
"@empathyco/x-utils": "^1.0.3-alpha.0",
"@types/jest": "~27.5.0",
"@types/node": "~18.18.0",
"@vue/test-utils": "~1.0.3",
"jest": "~27.5.0",
"rimraf": "~3.0.2",
"rollup": "~2.79.1",
"rollup": "~4.9.1",
"rollup-plugin-copy": "~3.5.0",
"rollup-plugin-delete": "~2.0.0",
"rollup-plugin-typescript2": "~0.36.0",
Expand Down
diegopf marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -4,17 +4,19 @@ import typescript from 'rollup-plugin-typescript2';

export default {
input: 'src/index.ts',
preserveModules: true,
output: [
{
format: 'cjs',
dir: 'dist/cjs'
dir: 'dist/cjs',
preserveModules: true
},
{
format: 'esm',
dir: 'dist/esm'
dir: 'dist/esm',
preserveModules: true
}
],
external: ['@empathyco/x-deep-merge', '@empathyco/x-utils', 'vue-i18n'],
plugins: [
del({ targets: 'dist' }),
copy({
Expand Down
2 changes: 1 addition & 1 deletion packages/x-components/build/build.ts
Expand Up @@ -31,5 +31,5 @@ async function build(): Promise<any> {
* Function for deleting useless folders.
*/
function removeTempFiles(): void {
fs.rmdirSync(path.join(rootDir, 'temp'), { recursive: true });
fs.rmSync(path.join(rootDir, 'temp'), { recursive: true });
}
Expand Up @@ -56,7 +56,7 @@ export function importTokens(): Plugin {
* This function returns a {@link Plugin | RollupJS Plugin} to omit the `.js` files from the
* output generation. This is necessary because the `rollup-plugin-styles` plugin outputs `.js`
* files together with the `.css`, to import them as module. It has a mode to only "emit" CSS,
* but it needs another plugin (lintcss) and is failing right now.
* but it needs another plugin (litcss) and is failing right now.
*
* @returns The plugin object to use in the Rollup config.
* @internal
Expand Down
10 changes: 5 additions & 5 deletions packages/x-components/build/rollup.config.ts
Expand Up @@ -36,7 +36,7 @@ export const rollupConfig = createRollupOptions({
* Because of that, when rollup detects a circular dependency (it emits a warning), we stop
* the build with an error */
if (warning.code === 'CIRCULAR_DEPENDENCY') {
throw Error(`Circular dependency found: ${warning.cycle?.join(' ') as string}`);
throw Error(`Circular dependency found: ${warning.ids?.join(' ') as string}`);
}
},
external(id) {
Expand Down Expand Up @@ -119,7 +119,7 @@ export const rollupConfig = createRollupOptions({
copy({
targets: [
{
src: ['build-helpers', 'CHANGELOG.md', 'package.json', 'README.md', 'docs'],
src: ['CHANGELOG.md', 'package.json', 'README.md', 'docs'],
dest: buildPath
}
],
Expand All @@ -136,9 +136,9 @@ export const rollupConfig = createRollupOptions({
const commonCssOptions = createRollupOptions({
output: {
dir: cssOutputDirectory,
assetFileNames: '[name][extname]'
},
preserveModules: true
assetFileNames: '[name][extname]',
preserveModules: true
}
});

/**
Expand Down
8 changes: 3 additions & 5 deletions packages/x-components/package.json
Expand Up @@ -30,7 +30,7 @@
"./tests/**/*",
"**/*.scss",
"**/*.scss.js",
"**/*vue_styles.*.vue.js",
"**/*vue[0-9].js",
Copy link
Contributor Author

@diegopf diegopf Dec 19, 2023

Choose a reason for hiding this comment

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

Due to how rollup generates now the output filenames when preserving modules, we need to adjust the sideEffect field in the package.json so bundlers do not tree shake styles of vue components.

The rollup-plugin-vue splits every vue sfc into two virtual files. Taking for example the redirection.vue component:

redirection.vue?rollup-plugin-vue=script.ts
redirection.vue?rollup-plugin-vue=styles.0.css

Prior to v3 rollup generates three files:
redirection.vue.js
redirection.vue_rollup_plugin-vue_script.vue.js
redirection.vue_rollup_plugin-vue_styles.0.js.

However, now rollup will name those files:
redirection.vue.js
redirection.vue.2.js
redirection.vue.3.js

You can see a simple example using the rollup repl

Rollup 2.79.1 filenames

Rollup 4.9.1 filenames

"**/*.css",
"**/*.vue"
],
Expand Down Expand Up @@ -97,7 +97,7 @@
"@empathyco/x-tailwindcss": "^1.1.2-alpha.0",
"@microsoft/api-documenter": "~7.23.0",
"@microsoft/api-extractor": "~7.38.0",
"@rollup/plugin-commonjs": "~25.0.0",
"@rollup/plugin-commonjs": "~25.0.7",
"@testing-library/jest-dom": "~5.17.0",
"@types/autoprefixer": "~10.2.0",
"@types/glob": "^8.0.1",
Expand All @@ -118,11 +118,9 @@
"postcss-dir-pseudo-class": "~7.0.0",
"postcss-logical": "~4.0.2",
"rimraf": "~3.0.2",
"rollup": "~2.79.1",
"rollup": "~4.9.1",
"rollup-plugin-copy": "~3.5.0",
"rollup-plugin-delete": "~2.0.0",
"rollup-plugin-rename": "~1.0.1",
"rollup-plugin-sourcemaps": "~0.6.3",
"rollup-plugin-styles": "~4.0.0",
"rollup-plugin-typescript2": "~0.36.0",
"rollup-plugin-vue": "~5.1.9",
Expand Down
diegopf marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

iep! We forgot this one!
output: [{ format: 'esm', dir: resolve(__dirname, '../showcase'), preserveModules: true }],

Expand Up @@ -2,6 +2,8 @@ import { resolve } from 'path';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import vue from 'rollup-plugin-vue';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export default {
input: resolve(__dirname, 'src/index.ts'),
Expand Down
6 changes: 3 additions & 3 deletions packages/x-tailwindcss/package.json
Expand Up @@ -30,7 +30,7 @@
"dev": "vite serve demo",
"dev:build": "vite build demo",
"prebuild": "rimraf ./dist ./showcase ./*.tgz",
"build": "rollup -c && rollup -c demo/rollup.config.js",
"build": "rollup -c && rollup -c demo/rollup.config.mjs",
"postbuild": "pnpm pack",
"lint": "eslint . --ext .ts,.vue",
"prepublishOnly": "pnpm run build"
Expand All @@ -57,12 +57,12 @@
}
},
"devDependencies": {
"@rollup/plugin-commonjs": "~25.0.0",
"@rollup/plugin-commonjs": "~25.0.7",
"autoprefixer": "~10.4.4",
"postcss": "~8.4.12",
"postcss-import": "~15.1.0",
"rimraf": "~3.0.2",
"rollup": "~2.79.1",
"rollup": "~4.9.1",
"rollup-plugin-typescript2": "~0.36.0",
"rollup-plugin-vue": "~5.1.9",
"tailwindcss": "~3.3.0",
Expand Down
diegopf marked this conversation as resolved.
Show resolved Hide resolved
@@ -1,14 +1,15 @@
import { resolve } from 'path';
import typescript from 'rollup-plugin-typescript2';
import commonjs from '@rollup/plugin-commonjs';
import * as url from 'url';
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export default {
input: resolve(__dirname, 'src/index.ts'),
output: [
{ format: 'esm', dir: resolve(__dirname, 'dist/esm') },
{ format: 'cjs', dir: resolve(__dirname, 'dist/cjs'), exports: 'auto' }
{ format: 'esm', dir: resolve(__dirname, 'dist/esm'), preserveModules: true },
{ format: 'cjs', dir: resolve(__dirname, 'dist/cjs'), preserveModules: true, exports: 'auto' }
],
preserveModules: true,
external: ['tailwindcss', 'tailwindcss/plugin', '@empathyco/x-deep-merge', '@empathyco/x-utils'],
plugins: [
commonjs(),
Expand Down
2 changes: 1 addition & 1 deletion packages/x-types/package.json
Expand Up @@ -47,7 +47,7 @@
"@microsoft/api-extractor": "~7.38.0",
"@types/jest": "~27.5.0",
"jest": "~27.5.0",
"rollup": "~2.79.1",
"rollup": "~4.9.1",
"rollup-plugin-delete": "~2.0.0",
"rollup-plugin-typescript2": "~0.36.0",
"typescript": "~4.9.4"
Expand Down
diegopf marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -4,15 +4,16 @@ import typescript from 'rollup-plugin-typescript2';
/* Models - CJS & ESM build */
const models = {
input: 'src/index.ts',
preserveModules: true,
output: [
{
format: 'cjs',
dir: 'dist/cjs'
dir: 'dist/cjs',
preserveModules: true
},
{
format: 'esm',
dir: 'dist/esm'
dir: 'dist/esm',
preserveModules: true
}
],
plugins: [
Expand Down