# Migrating to v2

> Upgrading a project from @eunomia/elements 1.x to 2.x with one command, and what it changes.

Source: https://eunomia-ds.com/guides/migrate-to-v2/

Version 2 of `@eunomia/elements` has two breaking changes for a 1.x project: the Sass sources moved to `@eunomia/core`, and `eun-button` and `eun-fab` dropped `popovertarget` for `command`/`commandfor`. Both are mechanical, so a script does them for you.

## Run the migration

From your project's root, on a clean git working tree:

```bash
npx -p @eunomia/elements@2 eunomia-migrate
```

It rewrites your files, updates `package.json`, installs with your package manager (npm, pnpm, Yarn or Bun, picked from your lockfile), then lists anything it couldn't rewrite on its own, with file and line. Review the diff, check those lines, and commit.

| Option | What it does |
| --- | --- |
| `--dry-run` | Lists what would change, writes nothing |
| `--no-install` | Updates `package.json` without running the package manager |
| `--force` | Runs even though the git working tree has uncommitted changes |
| `[dir]` | The project to migrate, when it isn't the current directory |

> **Running it twice is safe**
>
> A file already migrated is left alone, so you can run it again after fixing what it listed.

It skips `node_modules`, build output (`dist`, `build`, `.angular`, `.next`…) and minified files, and reads your styles, scripts, templates and JSON configuration (such as `angular.json`).

## What it changes

### Sass paths

`@eunomia/elements/styles/` no longer ships the `.scss` sources. The same files, at the same paths, are in `@eunomia/core/styles/`, so every reference moves there, whatever its prefix (`~`, `pkg:`, `node_modules/`) and including a `loadPaths`/`includePaths` entry:

```scss
// Before
@use "@eunomia/elements/styles/eunomia-themes.scss";
@use "pkg:@eunomia/elements/styles/breakpoints" as bp;

// After
@use "@eunomia/core/styles/eunomia-themes.scss";
@use "pkg:@eunomia/core/styles/breakpoints" as bp;
```

The compiled themes (`.css`) and their fonts stay in `@eunomia/elements/styles/`, so those paths are kept as they are.

### `popovertarget` on Button and Fab

On `eun-button` and `eun-fab`, `popovertarget` becomes `commandfor`, and `popovertargetaction` becomes `command`:

| 1.x | 2.x |
| --- | --- |
| `popovertarget="menu"` | `commandfor="menu"` |
| no `popovertargetaction`, or `"show"` | `command="show-popover"` |
| `popovertargetaction="hide"` | `command="hide-popover"` |
| `popovertargetaction="toggle"` | `command="toggle-popover"` |

```html
<!-- Before -->
<eun-button popovertarget="menu" popovertargetaction="toggle">Menu</eun-button>

<!-- After -->
<eun-button command="toggle-popover" commandfor="menu">Menu</eun-button>
```

It follows each framework's syntax: `[attr.popovertarget]` in Angular, `popoverTarget={id}` in JSX and `.popoverTarget=${id}` in Lit become `[attr.commandfor]`, `commandFor={id}` and `.commandFor=${id}`. A native `<button popovertarget>` is a browser feature, not Eunomia's: it's left as is. See [Invoker Commands API](https://eunomia-ds.com/guides/invoker-commands-api/) for everything `command`/`commandfor` can do beyond popovers.

### `package.json`

`@eunomia/elements` moves to the 2.x range, and `@eunomia/core` is added next to it: compiling the Sass themes now imports from it directly, which pnpm and Yarn's strict modes only allow for a declared dependency.

## What it leaves to you

The script only rewrites what it can read for sure. It lists, without touching them:

- a `popovertargetaction` bound to a variable (`[attr.popovertargetaction]="action"`): set `command` to the matching `show-popover`, `hide-popover` or `toggle-popover`, and rename `popovertarget` to `commandfor`;
- a `popovertarget` set from script (`setAttribute("popovertarget", …)`, `button.popoverTarget = …`) or through a spread or a wrapper component, in a file that uses Button or Fab: set `command` and `commandfor` instead.

## What doesn't need a change

The rest of 2.0 needs no edit in a 1.x project:

- `theme.js`, `breakpoints.js`, `setDefaultLocale` and the `@eunomia/elements/<component>.js` imports work as before;
- the charts moved to `@eunomia/charts`, but 1.x never shipped them;
- the CDN files keep their paths.

See the [changelog](https://eunomia-ds.com/changelog/) for the full list.

## See also

- [Get started](https://eunomia-ds.com/get-started/): installing and importing the components
- [Invoker Commands API](https://eunomia-ds.com/guides/invoker-commands-api/): `command` and `commandfor`, on Eunomia components and native buttons
- [Theming](https://eunomia-ds.com/theming/): the themes, compiled or from their Sass source
