diff --git a/.gitignore b/.gitignore index 43fcc33e38..1d2bd429e4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ **/tests/e2e/videos/ **/tests/e2e/screenshots/ +**/tests/e2e/downloads/ # local env files .env.local diff --git a/packages/_vue3-migration-test/CHANGELOG.md b/packages/_vue3-migration-test/CHANGELOG.md index 521e723310..8003a068f7 100644 --- a/packages/_vue3-migration-test/CHANGELOG.md +++ b/packages/_vue3-migration-test/CHANGELOG.md @@ -3,6 +3,23 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [1.0.0-alpha.51](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.50...vue3-migration-test@1.0.0-alpha.51) (2024-09-05) + + +### Bug Fixes + +* **list-components:** fix list components, migrate infinite-scroll directive and deprecated layouts (#1576) ([4b57f19](https://github.com/empathyco/x/commit/4b57f19be601220a4dc6874dc1d5efa8fdbcf991)) + + +### Code Refactoring + +* **animation-factory:** fix Vue3 breaking changes (#1579) ([f915731](https://github.com/empathyco/x/commit/f915731cc8ea662a2066fee054f47885ee2154a9)) +* **base-switch:** decommission of value prop (#1589) ([35968eb](https://github.com/empathyco/x/commit/35968ebb69634984e867b03221d373efe4af96c8)) +* **base-switch:** migrate component to vue3 (#1588) ([875a6e2](https://github.com/empathyco/x/commit/875a6e2638885498396db362753550857ec8d7e2)) +* **staggered-fade-and-slide:** use Vue native staggered transition (#1578) ([79e136f](https://github.com/empathyco/x/commit/79e136f04b0b75ddea77c464b8f5ea0ed6602eb1)) + + + ## [1.0.0-alpha.50](https://github.com/empathyco/x/compare/vue3-migration-test@1.0.0-alpha.49...vue3-migration-test@1.0.0-alpha.50) (2024-07-23) diff --git a/packages/_vue3-migration-test/package.json b/packages/_vue3-migration-test/package.json index 382a7b12e4..620805f50e 100644 --- a/packages/_vue3-migration-test/package.json +++ b/packages/_vue3-migration-test/package.json @@ -1,7 +1,7 @@ { "name": "vue3-migration-test", "private": "true", - "version": "1.0.0-alpha.50", + "version": "1.0.0-alpha.51", "scripts": { "dev": "vite", "preview": "vite preview", diff --git a/packages/_vue3-migration-test/src/components/animations/index.ts b/packages/_vue3-migration-test/src/components/animations/index.ts index b951da74a4..ca0d8338a1 100644 --- a/packages/_vue3-migration-test/src/components/animations/index.ts +++ b/packages/_vue3-migration-test/src/components/animations/index.ts @@ -5,3 +5,4 @@ export { default as TestCrossFade } from './test-cross-fade.vue'; export { default as TestFade } from './test-fade.vue'; export { default as TestFadeAndSlide } from './test-fade-and-slide.vue'; export { default as TestAnimationFactory } from './test-animation-factory.vue'; +export { default as TestStaggeredFadeAndSlide } from './test-staggered-fade-and-slide.vue'; diff --git a/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue b/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue index 3aa3de66cf..e27e830812 100644 --- a/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue +++ b/packages/_vue3-migration-test/src/components/animations/test-animation-factory.vue @@ -1,35 +1,5 @@ diff --git a/packages/_vue3-migration-test/src/components/animations/test-staggered-fade-and-slide.vue b/packages/_vue3-migration-test/src/components/animations/test-staggered-fade-and-slide.vue new file mode 100644 index 0000000000..dadcd355f5 --- /dev/null +++ b/packages/_vue3-migration-test/src/components/animations/test-staggered-fade-and-slide.vue @@ -0,0 +1,68 @@ + + + diff --git a/packages/_vue3-migration-test/src/components/index.ts b/packages/_vue3-migration-test/src/components/index.ts index 77985e8f78..d9005ffb9a 100644 --- a/packages/_vue3-migration-test/src/components/index.ts +++ b/packages/_vue3-migration-test/src/components/index.ts @@ -6,7 +6,6 @@ export { default as TestBaseDropdown } from './test-base-dropdown.vue'; export { default as TestBaseEventButton } from './test-base-event-button.vue'; export { default as TestBaseVariableColumnGrid } from './test-base-variable-column-grid.vue'; export { default as TestSlidingPanel } from './test-sliding-panel.vue'; -export { default as TestUseLayouts } from './test-use-layouts.vue'; export { default as TestBaseSuggestions } from './suggestions/test-base-suggestions.vue'; export { default as TestHighlight } from './test-highlight.vue'; export { default as TestBaseResultImages } from './result/test-base-result-images.vue'; @@ -20,3 +19,4 @@ export { default as TestTagging } from './tagging/test-tagging.vue'; export { default as TestRenderlessExtraParam } from './extra-params/test-renderless-extra-param.vue'; export { default as TestIcons } from './icons/test-icons.vue'; export { default as TestDisplayEmitter } from './test-display-emitter.vue'; +export { default as TestBaseSwitch } from './test-base-switch.vue'; diff --git a/packages/_vue3-migration-test/src/components/test-base-switch.vue b/packages/_vue3-migration-test/src/components/test-base-switch.vue new file mode 100644 index 0000000000..5ecb913878 --- /dev/null +++ b/packages/_vue3-migration-test/src/components/test-base-switch.vue @@ -0,0 +1,18 @@ + + + diff --git a/packages/_vue3-migration-test/src/components/test-use-layouts.vue b/packages/_vue3-migration-test/src/components/test-use-layouts.vue deleted file mode 100644 index c925c8c5eb..0000000000 --- a/packages/_vue3-migration-test/src/components/test-use-layouts.vue +++ /dev/null @@ -1,36 +0,0 @@ - - - - - diff --git a/packages/_vue3-migration-test/src/router.ts b/packages/_vue3-migration-test/src/router.ts index c040f9f98c..9dd876ef80 100644 --- a/packages/_vue3-migration-test/src/router.ts +++ b/packages/_vue3-migration-test/src/router.ts @@ -22,7 +22,6 @@ import { TestSearchBox, TestBaseVariableColumnGrid, TestEmpathize, - TestUseLayouts, TestSlidingPanel, TestBaseSuggestions, TestHighlight, @@ -50,7 +49,9 @@ import { TestRenderlessExtraParam, TestAnimationFactory, TestIcons, - TestDisplayEmitter + TestDisplayEmitter, + TestBaseSwitch, + TestStaggeredFadeAndSlide } from './'; const routes = [ @@ -174,11 +175,6 @@ const routes = [ name: 'BaseVariableColumnGrid', component: TestBaseVariableColumnGrid }, - { - path: '/test-use-layouts', - name: 'UseLayouts', - component: TestUseLayouts - }, { path: '/base-suggestions', name: 'BaseSuggestions', @@ -308,6 +304,16 @@ const routes = [ path: '/display-emitter', name: 'DisplayEmitter', component: TestDisplayEmitter + }, + { + path: '/base-switch', + name: 'BaseSwitch', + component: TestBaseSwitch + }, + { + path: '/staggered-fade-and-slide', + name: 'StaggeredFadeAndSlide', + component: TestStaggeredFadeAndSlide } ]; diff --git a/packages/x-archetype-utils/CHANGELOG.md b/packages/x-archetype-utils/CHANGELOG.md index e326fed8eb..d3884d2e86 100644 --- a/packages/x-archetype-utils/CHANGELOG.md +++ b/packages/x-archetype-utils/CHANGELOG.md @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [2.0.0-alpha.1](https://github.com/empathyco/x/compare/@empathyco/x-archetype-utils@1.1.0-alpha.2...@empathyco/x-archetype-utils@2.0.0-alpha.1) (2024-09-05) + + +### ⚠ BREAKING CHANGES + +* @empathyco/x-components v6 and @empathyco/x-archetype-utils v2 are only compatible with Vue 3 and if you are looking for the Vue 2 versions, take look at the main brach. +* @empathyco/x-archetype-utils is only compatible with vue 3 + +### Features + +* bump packages versions (#1611) ([eb7d377](https://github.com/empathyco/x/commit/eb7d377f0da3d09b78bc964de90529326889eb62)) +* bump vue18n version (#1604) ([9320c57](https://github.com/empathyco/x/commit/9320c57bd1aa2ff01fea8133238dc8fb809484c0)) +* **rollup:** update replace config to align CSS injector with Vue 3 (#1607) ([b98a31e](https://github.com/empathyco/x/commit/b98a31e488b788bab0a2fede87739e4cc9d1df57)) + + + ## [1.1.0-alpha.2](https://github.com/empathyco/x/compare/@empathyco/x-archetype-utils@1.1.0-alpha.1...@empathyco/x-archetype-utils@1.1.0-alpha.2) (2024-02-08) diff --git a/packages/x-archetype-utils/package.json b/packages/x-archetype-utils/package.json index 8cf14fe964..9e5403bd01 100644 --- a/packages/x-archetype-utils/package.json +++ b/packages/x-archetype-utils/package.json @@ -1,6 +1,6 @@ { "name": "@empathyco/x-archetype-utils", - "version": "1.1.0-alpha.2", + "version": "2.0.0-alpha.1", "description": "Utilities for x-archetype", "author": "Empathy Systems Corporation S.L.", "license": "Apache-2.0", @@ -39,12 +39,12 @@ "@empathyco/x-deep-merge": "^2.0.3-alpha.1", "@empathyco/x-utils": "workspace:^1.0.3-alpha.1", "tslib": "~2.6.0", - "vue-i18n": "~8.28.2" + "vue-i18n": "~9.14.0" }, "devDependencies": { "@types/jest": "~27.5.0", "@types/node": "~18.19.0", - "@vue/test-utils": "~1.0.3", + "@vue/test-utils": "~2.4.6", "jest": "~27.5.0", "rimraf": "~3.0.2", "rollup": "~4.9.1", @@ -53,11 +53,11 @@ "rollup-plugin-typescript2": "~0.36.0", "ts-jest": "~27.1.0", "typescript": "~4.9.4", - "vue": "~2.7.14" + "vue": "~3.4.31" }, "peerDependencies": { - "vue": "^2.7.0", - "vue-i18n": "^8.0.0" + "vue": "^3.4.31", + "vue-i18n": "^9.14.0" }, "publishConfig": { "access": "public" diff --git a/packages/x-archetype-utils/rollup.config.mjs b/packages/x-archetype-utils/rollup.config.mjs index 3173eb269e..d5b739bc33 100644 --- a/packages/x-archetype-utils/rollup.config.mjs +++ b/packages/x-archetype-utils/rollup.config.mjs @@ -24,7 +24,13 @@ export default { }), typescript({ clean: true, - useTsconfigDeclarationDir: true + useTsconfigDeclarationDir: true, + tsconfigOverride: { + exclude: [ + 'node_modules', + '**/__tests__/**', + ] + } }) ] }; diff --git a/packages/x-archetype-utils/src/__tests__/i18n.plugin.spec.ts b/packages/x-archetype-utils/src/__tests__/i18n.plugin.spec.ts index 82becaa99f..a050a695a0 100644 --- a/packages/x-archetype-utils/src/__tests__/i18n.plugin.spec.ts +++ b/packages/x-archetype-utils/src/__tests__/i18n.plugin.spec.ts @@ -1,6 +1,5 @@ import { DeepPartial } from '@empathyco/x-utils'; -import Vue from 'vue'; -import { mount, createLocalVue, Wrapper } from '@vue/test-utils'; +import { mount, VueWrapper } from '@vue/test-utils'; import { I18n } from '../i18n/i18n.plugin'; import { Device, I18nOptions, Locale } from '../i18n/i18n.types'; @@ -24,10 +23,6 @@ describe('Test custom i18n plugin for several use cases', () => { i18nOptions: Partial>> = {}, key = 'testComponent.title' ): Promise { - const TestComponent = Vue.component('testComponent', { - template: `
{{ $t("${key}") }}
` - }); - const localVue = createLocalVue(); const i18n = await I18n.create({ locale: 'en', messages: { @@ -43,11 +38,19 @@ describe('Test custom i18n plugin for several use cases', () => { fallbackLocale: 'en', ...i18nOptions }); - localVue.use(i18n); const setLocale = i18n.setLocale.bind(i18n); const setLocaleDevice = i18n.setDevice.bind(i18n); - const wrapper = mount(TestComponent, { localVue, i18n: i18n.vueI18n }); + const wrapper = mount( + { + template: `
{{ $t("${key}") }}
` + }, + { + global: { + plugins: [i18n] + } + } + ); return { wrapper, setLocale, setLocaleDevice }; } @@ -158,7 +161,7 @@ describe('Test custom i18n plugin for several use cases', () => { }); interface RenderComponentAPI { - wrapper: Wrapper; + wrapper: VueWrapper; setLocale: (newLocale: Locale) => Promise; setLocaleDevice: (newDevice: Device) => Promise; } diff --git a/packages/x-archetype-utils/src/build/rollup/rollup.config.ts b/packages/x-archetype-utils/src/build/rollup/rollup.config.ts index cfc387a831..21218c4227 100644 --- a/packages/x-archetype-utils/src/build/rollup/rollup.config.ts +++ b/packages/x-archetype-utils/src/build/rollup/rollup.config.ts @@ -1,7 +1,8 @@ export const rollupCssInjectorConfig = { replace: { // Replace X CSS injector by our custom one. - 'addStyle(id, style);': 'window.xCSSInjector.addStyle(style);', + 'export default injectCss;': + 'export default (css) => window.xCSSInjector.addStyle({ source: css });', delimiters: ['', ''] }, styles: { diff --git a/packages/x-archetype-utils/src/i18n/i18n.plugin.ts b/packages/x-archetype-utils/src/i18n/i18n.plugin.ts index ec3b18440c..853b26f94d 100644 --- a/packages/x-archetype-utils/src/i18n/i18n.plugin.ts +++ b/packages/x-archetype-utils/src/i18n/i18n.plugin.ts @@ -1,6 +1,6 @@ import { isObject } from '@empathyco/x-utils'; -import { VueConstructor } from 'vue'; -import VueI18n, { LocaleMessageObject, LocaleMessage } from 'vue-i18n'; +import { App } from 'vue'; +import { createI18n, LocaleMessageObject, I18n as VueI18n } from 'vue-i18n'; import { deepMerge } from '@empathyco/x-deep-merge'; import { AnyMessages, Device, I18nOptions, LoadLazyMessagesByDevice, Locale } from './i18n.types'; @@ -49,19 +49,20 @@ export class I18n { * * @param vue - The Vue instance. */ - install(vue: VueConstructor): void { - vue.use(VueI18n); - this.vueI18n = new VueI18n({ + install(vue: App): void { + this.vueI18n = createI18n({ locale: this.locale, - messages: this.currentMessages ? { [this.locale]: this.currentMessages } : {}, silentFallbackWarn: true, - missing: (locale, key) => { + messages: this.currentMessages ? ({ [this.locale]: this.currentMessages } as any) : {}, + missing: (_, key: string) => { return ( this.getMessageWithDotsInKey(key) ?? - `[i18n] Key '${key}' is missing for locale: '${locale}'` + `[i18n] Key '${key}' is missing for locale: '${this.locale}'` ); } }); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + vue.use(this.vueI18n); } /** @@ -76,7 +77,7 @@ export class I18n { // TO-DO Support function or array messages const message = path .split('.') - .reduce( + .reduce( (messages, key, index, pathParts) => isObject(messages) ? messages[key] ?? messages[pathParts.slice(index).join('.')] @@ -98,7 +99,7 @@ export class I18n { this.locale = newLocale; await this.changeMessages(); - this.vueI18n.locale = this.locale; + this.vueI18n.global.locale = this.locale; } } @@ -123,7 +124,8 @@ export class I18n { protected async changeMessages(): Promise { this.currentMessages = await this.getCurrentMessages(); - this.vueI18n.setLocaleMessage(this.locale, this.currentMessages); + // eslint-disable-next-line @typescript-eslint/no-unsafe-call + this.vueI18n.global.setLocaleMessage(this.locale, this.currentMessages); } /** diff --git a/packages/x-archetype-utils/src/i18n/i18n.types.ts b/packages/x-archetype-utils/src/i18n/i18n.types.ts index 0b37a1974d..aa85223e4c 100644 --- a/packages/x-archetype-utils/src/i18n/i18n.types.ts +++ b/packages/x-archetype-utils/src/i18n/i18n.types.ts @@ -1,5 +1,5 @@ -import VueI18n from 'vue-i18n'; import { DeepPartial } from '@empathyco/x-utils'; +import { I18n as VueI18n } from 'vue-i18n'; /** Supported locales. */ export type Locale = string; diff --git a/packages/x-components/.eslintrc.js b/packages/x-components/.eslintrc.js index 75aafd665d..91454f1566 100644 --- a/packages/x-components/.eslintrc.js +++ b/packages/x-components/.eslintrc.js @@ -8,8 +8,10 @@ module.exports = { rules: { 'no-dupe-class-members': 'off', '@typescript-eslint/no-unused-vars-experimental': 'off', + '@typescript-eslint/explicit-function-return-type': 'off', 'vue/require-default-prop': 'off', - '@typescript-eslint/explicit-function-return-type': 'off' + 'vue/multi-word-component-names': 'off', + 'vue/no-v-for-template-key': 'off' }, overrides: [ { @@ -34,7 +36,9 @@ module.exports = { { files: ['*.spec.ts'], rules: { - 'max-len': 'off' + 'max-len': 'off', + '@typescript-eslint/no-unsafe-argument': 'off', + 'vue/one-component-per-file': 'off' } } ] diff --git a/packages/x-components/.gitignore b/packages/x-components/.gitignore index e4ef8b47ee..a11c342ad7 100644 --- a/packages/x-components/.gitignore +++ b/packages/x-components/.gitignore @@ -8,6 +8,7 @@ /tests/e2e/videos/ /tests/e2e/screenshots/ +/tests/e2e/downloads/ # local env files .env.local diff --git a/packages/x-components/CHANGELOG.md b/packages/x-components/CHANGELOG.md index f00aa03642..d0595b75ff 100644 --- a/packages/x-components/CHANGELOG.md +++ b/packages/x-components/CHANGELOG.md @@ -3,6 +3,90 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +## [6.0.0-alpha.3](https://github.com/empathyco/x/compare/@empathyco/x-components@6.0.0-alpha.2...@empathyco/x-components@6.0.0-alpha.3) (2024-10-04) + + +### Bug Fixes + +* **scroll:** scroll direction inconsistency (#1629) ([ad970ae](https://github.com/empathyco/x/commit/ad970ae8cd7898f23baa11d3a128d3251cd57cdb)) + + + +## [6.0.0-alpha.2](https://github.com/empathyco/x/compare/@empathyco/x-components@6.0.0-alpha.1...@empathyco/x-components@6.0.0-alpha.2) (2024-09-25) + + +### ⚠ BREAKING CHANGES + +* **history-queries-switch:** remove `change` event emission in favour of `update:modelValue` in `BaseSwitch` component. + +### Bug Fixes + +* **history-queries-switch:** migrate value to modelValue (#1618) ([82a6e27](https://github.com/empathyco/x/commit/82a6e27b9a78388b6c0b42c57ce7ff6e63293686)) + + +### Testing + +* active and fix linter for tests (#1616) ([0f35e7c](https://github.com/empathyco/x/commit/0f35e7caf529e7a06252abe0ea64b119c1206566)) +* adjust test to vue3 (#1608) ([0f4bb97](https://github.com/empathyco/x/commit/0f4bb97dcba50b21c98575d51bda944bfe532b1f)) +* **e2e-components:** rewrite all e2e sheet components to accomplish vue3 (#1619) ([5a419b2](https://github.com/empathyco/x/commit/5a419b2d882c151f81d9921d591140e5471f5b05)) +* **e2e:** fix e2e tests (#1617) ([f81add6](https://github.com/empathyco/x/commit/f81add665e5b2f36ecedf25d14eb5f6573f0e0fb)) + + + +## [6.0.0-alpha.1](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.81...@empathyco/x-components@6.0.0-alpha.1) (2024-09-05) + + +### ⚠ BREAKING CHANGES + +* @empathyco/x-components v6 and @empathyco/x-archetype-utils v2 are only compatible with Vue 3 and if you are looking for the Vue 2 versions, take look at the main brach. +* refactors the GlobalXBus to use a prop to receive the listeners instead of relying on attributes. + +### Features + +* bump packages versions (#1611) ([eb7d377](https://github.com/empathyco/x/commit/eb7d377f0da3d09b78bc964de90529326889eb62)) +* make internal demo app functional (#1574) ([a485dea](https://github.com/empathyco/x/commit/a485dea768918280e2fec46cae0d5a3f4932002f)) +* **x-installer:** update to vue3 and adapt x-installer (#1572) ([c6b28e5](https://github.com/empathyco/x/commit/c6b28e5e9a07832e992f27a40d7513dbec90d2f2)) + + +### Bug Fixes + +* adjust to new vue render function API (#1596) ([7ec2b97](https://github.com/empathyco/x/commit/7ec2b9719f18275e7843544f26f94c393fef7090)) +* **infinite-scroll:** getting xBus from XPlugin instead useXBus ([b936ae5](https://github.com/empathyco/x/commit/b936ae585b4ef5ae390515cfc2c3a0dfc782ad39)) +* **layout:** avoid shared CSS classes between layouts with scoped (#1605) ([b3cc3f5](https://github.com/empathyco/x/commit/b3cc3f528f71b0877a406c65cadfbecda7aca756)) +* **list-components:** fix list components, migrate infinite-scroll directive and deprecated layouts (#1576) ([4b57f19](https://github.com/empathyco/x/commit/4b57f19be601220a4dc6874dc1d5efa8fdbcf991)) +* **search:** replace results state to append new results instead of pushing them (#1597) ([e64e3cb](https://github.com/empathyco/x/commit/e64e3cb9f3c046d1c30249fb56b0b3ad32f97925)) + + +### Testing + +* **auto-progress-bar:** fix test after Vue3 update (#1582) ([335c370](https://github.com/empathyco/x/commit/335c37021f9a0f6fefaec01714cc31fb6bf66391)) +* **components:** fix tests after Vue3 update BATCH 1 ([5d4dec8](https://github.com/empathyco/x/commit/5d4dec81b5b9ee99f1cbfc1d88bbf58cd5188602)) +* **vue-jest:** update vue-jest dependency (#1581) ([46ff08b](https://github.com/empathyco/x/commit/46ff08bb5834d790b0c6414fc549141b9a64f1d1)) + + +### Code Refactoring + +* **animation-factory:** fix Vue3 breaking changes (#1579) ([f915731](https://github.com/empathyco/x/commit/f915731cc8ea662a2066fee054f47885ee2154a9)) +* **base-switch:** decommission of value prop (#1589) ([35968eb](https://github.com/empathyco/x/commit/35968ebb69634984e867b03221d373efe4af96c8)) +* **base-switch:** migrate component to vue3 (#1588) ([875a6e2](https://github.com/empathyco/x/commit/875a6e2638885498396db362753550857ec8d7e2)) +* **components:** remove warnings first batch (#1575) ([1877da6](https://github.com/empathyco/x/commit/1877da61c2eb5aff5742387dc2285b3db86afda5)) +* get rid of NoElement component and useNoElementRender composable (#1583) ([059eecc](https://github.com/empathyco/x/commit/059eecc0fd5aa1612c1fc7b4d5ec08cfe5fc5b84)) +* **render-function:** clear void calls (#1580) ([7875ff5](https://github.com/empathyco/x/commit/7875ff5b8420ea1ed03edd3fee28a822582b4641)) +* **staggered-fade-and-slide:** use Vue native staggered transition (#1578) ([79e136f](https://github.com/empathyco/x/commit/79e136f04b0b75ddea77c464b8f5ea0ed6602eb1)) +* **v-deep:** replace by :deep() (#1577) ([71c08db](https://github.com/empathyco/x/commit/71c08dbc175093bbfc56160e3b07b8774fcbc683)) + + +### Build System + +* adjust rollup production build for Vue3 (#1603) ([ed587b1](https://github.com/empathyco/x/commit/ed587b16a56b32734e9cf3ff05311954627f3820)) + + +### Continuous Integration + +* **linter:** fix linter issues to pass the CI (#1606) ([aff3151](https://github.com/empathyco/x/commit/aff3151818c64885d7c28e69f511d33ae41b38f5)) + + + ## [5.0.0-alpha.81](https://github.com/empathyco/x/compare/@empathyco/x-components@5.0.0-alpha.80...@empathyco/x-components@5.0.0-alpha.81) (2024-08-20) diff --git a/packages/x-components/build/build.ts b/packages/x-components/build/build.ts index 42b28542fe..5bf2451666 100644 --- a/packages/x-components/build/build.ts +++ b/packages/x-components/build/build.ts @@ -1,35 +1,16 @@ -import * as path from 'path'; -import fs from 'fs'; -import { rollup } from 'rollup'; -import { cssDeprecatedComponentsRollupConfig, rollupConfig } from './rollup.config'; - -const rootDir = path.resolve(__dirname, '../'); - -// eslint-disable-next-line no-console -build().catch(console.error); +import { OutputOptions, rollup } from 'rollup'; +import { cssDeprecatedRollupConfig, rollupConfig } from './rollup.config'; /** * Entry point for building the project. */ -async function build(): Promise { - try { - const bundle = await rollup(rollupConfig); - await bundle.write(rollupConfig.output); - - const bundleCssDeprecatedComponents = await rollup(cssDeprecatedComponentsRollupConfig); - await bundleCssDeprecatedComponents.write(cssDeprecatedComponentsRollupConfig.output); +async function build() { + const bundle = await rollup(rollupConfig); + await bundle.write(rollupConfig.output as OutputOptions); - return removeTempFiles(); - } catch (error) { - // eslint-disable-next-line no-console - console.error('Build failed: ', (error as Error).message); - process.exit(1); - } + const bundleCssDeprecatedComponents = await rollup(cssDeprecatedRollupConfig); + await bundleCssDeprecatedComponents.write(cssDeprecatedRollupConfig.output as OutputOptions); } -/** - * Function for deleting useless folders. - */ -function removeTempFiles(): void { - fs.rmSync(path.join(rootDir, 'temp'), { recursive: true }); -} +// eslint-disable-next-line no-console +build().catch(console.error); diff --git a/packages/x-components/build/build.utils.ts b/packages/x-components/build/build.utils.ts index 398eba5fb4..9cd88ad004 100644 --- a/packages/x-components/build/build.utils.ts +++ b/packages/x-components/build/build.utils.ts @@ -2,24 +2,24 @@ import fs from 'fs'; import path from 'path'; /** - * Asserts a file path directory exists recursively, creating it if it does not. + * Asserts a directory exist recursively, creating it if it does not. * - * @param filePath - The full path to the file, that may or may not exist. + * @param directoryPath - The full directory path, that may or may not exist. */ -export function ensureFilePathExists(filePath: string): void { - const dirName = path.dirname(filePath); - ensureDirectoryPathExists(dirName); +export function ensureDirectoryPathExists(directoryPath: string) { + if (!fs.existsSync(directoryPath)) { + fs.mkdirSync(directoryPath, { recursive: true }); + } } /** - * Asserts a directory exist recursively, creating it if it does not. + * Asserts a file path directory exists recursively, creating it if it does not. * - * @param directoryPath - The full directory path, that may or may not exists. + * @param filePath - The full path to the file, that may or may not exist. */ -export function ensureDirectoryPathExists(directoryPath: string): void { - if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath, { recursive: true }); - } +export function ensureFilePathExists(filePath: string) { + const dirName = path.dirname(filePath); + ensureDirectoryPathExists(dirName); } /** @@ -28,7 +28,7 @@ export function ensureDirectoryPathExists(directoryPath: string): void { * @param sourceFolder - Source folder to be copied. * @param targetFolder - Target folder. */ -export function copyFolderSync(sourceFolder: string, targetFolder: string): void { +export function copyFolderSync(sourceFolder: string, targetFolder: string) { if (!fs.existsSync(targetFolder)) { fs.mkdirSync(targetFolder); } @@ -49,6 +49,6 @@ export function copyFolderSync(sourceFolder: string, targetFolder: string): void * @param path - The path to normalize. * @returns A normalized path. */ -export function normalizePath(path: string): string { +export function normalizePath(path: string) { return path.replace(/\\/g, '/'); } diff --git a/packages/x-components/build/postcss-dir-pseudo-class.d.ts b/packages/x-components/build/postcss-dir-pseudo-class.d.ts deleted file mode 100644 index 97c67b6cbc..0000000000 --- a/packages/x-components/build/postcss-dir-pseudo-class.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module 'postcss-dir-pseudo-class' { - import { Options } from './postcss-types/options'; - - function postcssDirPseudoClass(options?: Options = {}): Plugin; - export = postcssDirPseudoClass; -} diff --git a/packages/x-components/build/postcss-logical.d.ts b/packages/x-components/build/postcss-logical.d.ts deleted file mode 100644 index 3e9b159118..0000000000 --- a/packages/x-components/build/postcss-logical.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -declare module 'postcss-logical' { - import { Options } from './postcss-types/options'; - - function postcssLogical(options?: Options = {}): Plugin; - export = postcssLogical; -} diff --git a/packages/x-components/build/postcss-types/options.ts b/packages/x-components/build/postcss-types/options.ts deleted file mode 100644 index 39996ec735..0000000000 --- a/packages/x-components/build/postcss-types/options.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface Options { - dir?: 'rtl' | 'ltr'; - preserve?: boolean; -} diff --git a/packages/x-components/build/rollup-plugins/design-system.rollup-plugin.ts b/packages/x-components/build/rollup-plugins/design-system.rollup-plugin.ts index 19295040b1..18a73605dc 100644 --- a/packages/x-components/build/rollup-plugins/design-system.rollup-plugin.ts +++ b/packages/x-components/build/rollup-plugins/design-system.rollup-plugin.ts @@ -1,5 +1,4 @@ import fs from 'fs'; -import path from 'path'; import { Plugin } from 'rollup'; import { normalizePath } from '../build.utils'; @@ -12,28 +11,13 @@ import { normalizePath } from '../build.utils'; * returns `src/design-system/button/default.tokens.scss` if exists. * @internal */ -function getTokensFilePath(file: string): string | null { +function getTokensFilePath(file: string) { const fileParts = file.split('.'); const fileExtension = fileParts.pop() ?? ''; const tokensFile = `${fileParts.join('.')}.tokens.${fileExtension}`; return fs.existsSync(tokensFile) ? normalizePath(tokensFile) : null; } -/** - * This function returns the name for the CSS file using the component name and the variant. - * The component name is extracted from the folder name, and the variant name is extracted from - * the file name. - * - * @param file - The path of the file processed. - * @returns The name for the CSS file with the component and the variant. - * @example For `src/style/components/button/pill.scss` file this function returns `button-pill`. - * @internal - */ -export function renameComponentCssFile(file: string): string { - const parentFolder = path.dirname(file).split(path.sep)?.pop() ?? ''; - return `${parentFolder}-${path.basename(file).replace('.scss', '')}`; -} - /** * This function returns a {@link Plugin | RollupJS Plugin} to import the tokens files into the * components .scss files. For each `xxx.scss` processed, it looks for the `xxx.tokens.scss` tokens diff --git a/packages/x-components/build/rollup-plugins/x-components.rollup-plugin.ts b/packages/x-components/build/rollup-plugins/x-components.rollup-plugin.ts index 30719690bc..8de6bd9f38 100644 --- a/packages/x-components/build/rollup-plugins/x-components.rollup-plugin.ts +++ b/packages/x-components/build/rollup-plugins/x-components.rollup-plugin.ts @@ -17,9 +17,9 @@ export interface GenerateEntryFilesOptions { /** The path where the build will go. */ buildPath: string; /** The path to the directory where generated js files are stored. */ - jsOutputDirectory: string; + jsOutputDir: string; /** The path to the directory where generated .d.ts files are stored. */ - typesOutputDirectory: string; + typesOutputDir: string; } /** @@ -44,9 +44,9 @@ export function generateEntryFiles(options: GenerateEntryFilesOptions): Plugin { * - 1 Typings file per entry point. */ writeBundle() { - generateEntryPoints(options.buildPath, options.jsOutputDirectory, 'js'); - generateEntryPoints(options.buildPath, options.typesOutputDirectory, 'd.ts'); - copyIndexSourcemap(options.buildPath, options.jsOutputDirectory); + generateEntryPoints(options.buildPath, options.jsOutputDir, 'js'); + generateEntryPoints(options.buildPath, options.typesOutputDir, 'd.ts'); + copyIndexSourcemap(options.buildPath, options.jsOutputDir); } }; } diff --git a/packages/x-components/build/rollup.config.ts b/packages/x-components/build/rollup.config.ts index 7b3e71215e..bd23383a29 100644 --- a/packages/x-components/build/rollup.config.ts +++ b/packages/x-components/build/rollup.config.ts @@ -1,14 +1,12 @@ import path from 'path'; -import commonjs from '@rollup/plugin-commonjs'; import { sync as glob } from 'glob'; -import { RollupOptions } from 'rollup'; +import { RollupOptions, Plugin } from 'rollup'; import copy from 'rollup-plugin-copy'; import del from 'rollup-plugin-delete'; import styles from 'rollup-plugin-styles'; import typescript from 'rollup-plugin-typescript2'; -import vue, { VuePluginOptions } from 'rollup-plugin-vue'; -import packageJSON from '../package.json'; -import { normalizePath } from './build.utils'; +import vue3 from '@vitejs/plugin-vue'; +import { dependencies as pkgDeps, peerDependencies as pkgPeerDeps } from '../package.json'; import { apiDocumentation } from './docgen/documentation.rollup-plugin'; import { importTokens, omitJsFiles } from './rollup-plugins/design-system.rollup-plugin'; import { generateEntryFiles } from './rollup-plugins/x-components.rollup-plugin'; @@ -16,17 +14,21 @@ import { generateEntryFiles } from './rollup-plugins/x-components.rollup-plugin' const rootDir = path.resolve(__dirname, '../'); const buildPath = path.join(rootDir, 'dist'); -const dependencies = new Set( - Object.keys(packageJSON.dependencies).concat(Object.keys(packageJSON.peerDependencies)) -); -const jsOutputDirectory = path.join(buildPath, 'js'); -const typesOutputDirectory = path.join(buildPath, 'types'); -const cssOutputDirectory = path.join(buildPath, 'design-system'); +const jsOutputDir = path.join(buildPath, 'js'); +const typesOutputDir = path.join(buildPath, 'types'); -export const rollupConfig = createRollupOptions({ +const dependencies = new Set(Object.keys(pkgDeps).concat(Object.keys(pkgPeerDeps))); + +const vueDocs = { + name: 'vue-docs', + transform: (_code: unknown, id: string) => + !/vue&type=docs/.test(id) ? undefined : `export default ''` +}; + +export const rollupConfig: RollupOptions = { input: path.join(rootDir, 'src/index.ts'), output: { - dir: jsOutputDirectory, + dir: jsOutputDir, format: 'esm', sourcemap: true, preserveModules: true @@ -36,7 +38,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.ids?.join(' ') as string}`); + throw Error(`Circular dependency found: ${warning.ids?.join(' ') ?? ''}`); } }, external(id) { @@ -44,26 +46,28 @@ export const rollupConfig = createRollupOptions({ Rollup treats by default all node_modules dependencies as external, but will launch a warning if you don't manually specify them. In our case apart from the package.json ones, we also need to add any dependency that starts with rxjs (due to rxjs having multiple - entry points), and the vue-runtime-helpers, which is a dependency added by the SFC compiler + entry points) */ return ( dependencies.has(id) || // Package.json dependencies /* As rxjs has multiple entry points, it needs to be declared this way */ - id.startsWith('rxjs') || - /* Vue SFC dependency. Needs to be here because rollup generates a relative import to the - node_modules folder */ - id.includes('vue-runtime-helpers') + id.startsWith('rxjs') ); }, plugins: [ - del({ targets: [`${buildPath}/*`, `${path.join(rootDir, 'docs')}/*`] }), - commonjs(), + del({ + targets: [ + `${buildPath}/*`, + `${path.join(rootDir, 'docs')}/*`, + `${path.join(rootDir, 'temp')}/*` + ] + }), typescript({ useTsconfigDeclarationDir: true, tsconfig: path.resolve(rootDir, 'tsconfig.json'), tsconfigOverride: { compilerOptions: { - declarationDir: typesOutputDirectory, + declarationDir: typesOutputDir, target: 'es2020' }, exclude: [ @@ -75,91 +79,50 @@ export const rollupConfig = createRollupOptions({ ] } }), - vue({ - css: false, - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore Undocumented option to disable vue sourcemap generation because it breaks if - // lang is set to ts: - // https://github.com/vuejs/rollup-plugin-vue/issues/272#issuecomment-491721842 - needMap: false, + vue3({ template: { compilerOptions: { whitespace: 'condense' } - } as VuePluginOptions['template'], - style: { - postcssCleanOptions: { disabled: true } } - }), + }) as Plugin, styles({ + minimize: true, mode: [ 'inject', - (varname: string, id: string) => - `import { createInjector, createInjectorSSR } from 'vue-runtime-helpers'; - const isBrowser = /*#__PURE__*/ (function () { - return ( - Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) !== - '[object process]' - ); - })(); - const useBrowserInjector = - (typeof STRIP_SSR_INJECTOR !== 'undefined' && STRIP_SSR_INJECTOR) || isBrowser; - const injector = useBrowserInjector ? createInjector({}) : createInjectorSSR({}); - injector('${normalizePath(id)}',{source:${varname}});` + varname => { + const pathInjector = path.resolve('./tools/inject-css.js'); + return `import injectCss from '${pathInjector}';injectCss(${varname});`; + } ] }), - generateEntryFiles({ - buildPath, - jsOutputDirectory, - typesOutputDirectory - }), - apiDocumentation({ - buildPath - }), + vueDocs, + generateEntryFiles({ buildPath, jsOutputDir, typesOutputDir }), + apiDocumentation({ buildPath }), copy({ targets: [ - { - src: ['CHANGELOG.md', 'package.json', 'README.md', 'docs'], - dest: buildPath - } + { src: ['build/tools'], dest: buildPath }, + { src: ['CHANGELOG.md', 'package.json', 'README.md', 'docs'], dest: buildPath } ], hook: 'writeBundle' }) ] -}); +}; // Design System CSS generation +const cssOutputDir = path.join(buildPath, 'design-system'); -/** - * Common options for all CSS Rollup configs. - */ -const commonCssOptions = createRollupOptions({ +/** The config to generate one `.css` file with all the deprecated styles. */ +export const cssDeprecatedRollupConfig: RollupOptions = { + input: glob('src/design-system-deprecated/**/*.scss'), output: { - dir: cssOutputDirectory, + dir: cssOutputDir, assetFileNames: '[name][extname]', preserveModules: true - } -}); - -/** - * The config to generate one `.css` file with all the deprecated styles. - */ -export const cssDeprecatedComponentsRollupConfig = createRollupOptions({ - ...commonCssOptions, - input: glob('src/design-system-deprecated/**/*.scss'), + }, plugins: [ importTokens(), styles({ mode: ['extract', 'deprecated-full-theme.css'] }), omitJsFiles() ] -}); - -/** - * Util function to create type-safe Rollup options. - * - * @param options - The Rollup options to create. - * @returns Type-safe Rollup options. - */ -export function createRollupOptions(options: T): T { - return options; -} +}; diff --git a/packages/x-components/build/tools/inject-css.js b/packages/x-components/build/tools/inject-css.js new file mode 100644 index 0000000000..5de49db0ce --- /dev/null +++ b/packages/x-components/build/tools/inject-css.js @@ -0,0 +1,13 @@ +/** + * Simple CSS injector to append styles to the head. + * This injector can be overwritten at build time. + * + * @params css - CSS code. + */ +function injectCss(css) { + const el = document.createElement('style'); + el.textContent = css; + document.head.appendChild(el); +} + +export default injectCss; diff --git a/packages/x-components/cypress.config.ts b/packages/x-components/cypress.config.ts index 03daafc26b..afb2975fd1 100644 --- a/packages/x-components/cypress.config.ts +++ b/packages/x-components/cypress.config.ts @@ -1,6 +1,7 @@ +import { defineConfig } from 'cypress'; +import createBundler from '@bahmutov/cypress-esbuild-preprocessor'; import { addCucumberPreprocessorPlugin } from '@badeball/cypress-cucumber-preprocessor'; import { createEsbuildPlugin } from '@badeball/cypress-cucumber-preprocessor/esbuild'; -import { defineConfig } from 'cypress'; export default defineConfig({ e2e: { @@ -9,34 +10,37 @@ export default defineConfig({ requestTimeout: 7000, viewportHeight: 1080, viewportWidth: 1920, - screenshotOnRunFailure: false, - video: false, + specPattern: 'tests/e2e/**/*.feature', supportFile: 'tests/support/index.ts', fixturesFolder: 'tests/e2e/fixtures', screenshotsFolder: 'tests/e2e/screenshots', + downloadsFolder: 'tests/e2e/downloads', + experimentalRunAllSpecs: true, + screenshotOnRunFailure: false, + video: false, retries: { openMode: 0, runMode: 1 }, + // https://github.com/badeball/cypress-cucumber-preprocessor/blob/master/docs/quick-start.md async setupNodeEvents(on, config) { + // This is required for the preprocessor to be able to generate JSON reports after each run, and more. await addCucumberPreprocessorPlugin(on, config); - on( - 'file:preprocessor', - require('@bahmutov/cypress-esbuild-preprocessor')({ - plugins: [createEsbuildPlugin(config)] - }) - ); + + on('file:preprocessor', createBundler({ plugins: [createEsbuildPlugin(config)] })); + + // Make sure to return the config object as it might have been modified by the plugin. return config; - }, - specPattern: 'tests/e2e/**/*.feature', - experimentalRunAllSpecs: true + } }, component: { defaultCommandTimeout: 7000, - experimentalSingleTabRunMode: true, + viewportHeight: 1080, + viewportWidth: 1920, specPattern: 'tests/unit/**/*.spec.ts', supportFile: 'tests/support/index.ts', indexHtmlFile: 'tests/support/component-index.html', + experimentalSingleTabRunMode: true, screenshotOnRunFailure: false, video: false, retries: { diff --git a/packages/x-components/jest.config.js b/packages/x-components/jest.config.js index ceb4f32f37..fecc057095 100644 --- a/packages/x-components/jest.config.js +++ b/packages/x-components/jest.config.js @@ -1,9 +1,12 @@ module.exports = { preset: 'ts-jest', transform: { - '^.+\\.vue$': '@vue/vue2-jest', + '^.+\\.vue$': '@vue/vue3-jest', '^.+\\.scss$': 'jest-scss-transform' }, + moduleNameMapper: { + 'vue-global-events': '/node_modules/vue-global-events/dist/index.cjs' + }, testMatch: ['/src/**/*.spec.ts'], setupFilesAfterEnv: ['./jest.setup.ts'], // jest 27 changes the default environment to node instead of jsdom diff --git a/packages/x-components/package.json b/packages/x-components/package.json index 576e8d6759..c7c967bbff 100644 --- a/packages/x-components/package.json +++ b/packages/x-components/package.json @@ -1,6 +1,6 @@ { "name": "@empathyco/x-components", - "version": "5.0.0-alpha.81", + "version": "6.0.0-alpha.3", "description": "Empathy X Components", "author": "Empathy Systems Corporation S.L.", "license": "Apache-2.0", @@ -30,8 +30,8 @@ "./tests/**/*", "**/*.scss", "**/*.scss.js", - "**/*vue[0-9].js", "**/*.css", + "**/*vue[0-9].js", "**/*.vue" ], "repository": { @@ -54,9 +54,9 @@ "lint": "eslint . --ext .ts,.vue", "test:unit": "jest --silent", "test:unit-jest": "jest", - "test:unit-cypress": "cypress run --component --browser chrome", "test:unit-coverage": "jest --coverage", "test:unit-watch": "jest --watch", + "test:unit-cypress": "cypress run --component --browser chrome", "test:e2e": "start-server-and-test preview http://localhost:8080 cypress:open", "test:e2e:firefox": "start-server-and-test serve http://localhost:8080 cypress:open:firefox", "test:e2e:ci": "start-server-and-test serve http://localhost:8080 cypress:run:ci", @@ -79,35 +79,30 @@ "@empathyco/x-utils": "^1.0.3-alpha.1", "@vue/devtools-api": "~6.5.0", "@vueuse/core": "~10.7.1", - "js-md5": "^0.8.3", + "js-md5": "~0.8.3", "rxjs": "~7.8.0", "tslib": "~2.6.0", - "vue-class-component": "~7.2.6", - "vue-global-events": "~1.2.1", - "vue-property-decorator": "~8.5.0", - "vue-runtime-helpers": "~1.1.2" + "vue-global-events": "~3.0.1" }, "peerDependencies": { - "vue": "~2.7.0", - "vuex": "^3.0.0" + "vue": "~3.4.31", + "vuex": "4.0.2" }, "devDependencies": { "@badeball/cypress-cucumber-preprocessor": "~20.0.0", "@bahmutov/cypress-esbuild-preprocessor": "~2.2.0", - "@cypress/vue2": "~2.0.1", - "@empathyco/x-tailwindcss": "^1.2.0-alpha.5", + "@empathyco/x-tailwindcss": "^1.2.0-alpha.6", "@microsoft/api-documenter": "~7.23.0", "@microsoft/api-extractor": "~7.39.0", - "@rollup/plugin-commonjs": "~25.0.7", "@testing-library/jest-dom": "~5.17.0", "@types/autoprefixer": "~10.2.0", - "@types/glob": "^8.0.1", + "@types/glob": "~8.0.1", "@types/jest": "~27.5.0", "@types/node": "~18.19.0", "@types/testing-library__jest-dom": "~5.14.5", - "@vitejs/plugin-vue2": "^2.2.0", - "@vue/test-utils": "~1.0.3", - "@vue/vue2-jest": "~27.0.0-alpha.3", + "@vitejs/plugin-vue": "~5.1.2", + "@vue/test-utils": "~2.4.6", + "@vue/vue3-jest": "~27.0.0", "autoprefixer": "~10.4.4", "convert-source-map": "~2.0.0", "cypress": "~13.6.0", @@ -124,20 +119,19 @@ "rollup-plugin-delete": "~2.0.0", "rollup-plugin-styles": "~4.0.0", "rollup-plugin-typescript2": "~0.36.0", - "rollup-plugin-vue": "~5.1.9", + "rollup-plugin-vue": "~6.0.0", "sass": "~1.70.0", "start-server-and-test": "~2.0.0", "tailwindcss": "~3.4.0", "ts-jest": "~27.1.0", - "ts-node": "~10.9.1", + "ts-node": "~10.9.2", "typescript": "~4.9.4", - "vite": "^4.5.0", - "vite-plugin-vue-inspector": "^4.0.0", - "vue": "~2.7.14", - "vue-docgen-cli": "~4.67.0", - "vue-router": "~3.6.5", - "vue-template-compiler": "~2.7.14", - "vuex": "~3.6.2" + "vite": "~4.5.0", + "vite-plugin-vue-inspector": "~5.1.2", + "vue": "~3.4.31", + "vue-docgen-cli": "~4.79.0", + "vue-router": "~4.4.0", + "vuex": "4.0.2" }, "publishConfig": { "access": "public", diff --git a/packages/x-components/src/App.vue b/packages/x-components/src/App.vue index ac2acc6692..38a0ad4873 100644 --- a/packages/x-components/src/App.vue +++ b/packages/x-components/src/App.vue @@ -10,11 +10,7 @@ - - - - diff --git a/packages/x-components/src/components/animations/collapse-height.vue b/packages/x-components/src/components/animations/collapse-height.vue index 7c512b4871..3bb53e95ce 100644 --- a/packages/x-components/src/components/animations/collapse-height.vue +++ b/packages/x-components/src/components/animations/collapse-height.vue @@ -1,8 +1,5 @@