Skip to content

Migration Codemods

Pinia Colada ships ast-grep codemods to automate breaking-change migrations. Always commit your changes before running a codemod so you can review the diff.

Running codemods

With pnpm dlx (no global install):

sh
pnpm --package=@ast-grep/cli dlx ast-grep scan -r node_modules/@pinia/colada/codemods/rules/<rule-file>.yaml -i src

Or install ast-grep globally and run:

sh
ast-grep scan -r node_modules/@pinia/colada/codemods/rules/<rule-file>.yaml -i src

Replace src with the directory that contains your source files and <rule-file> with the migration file name listed below.

0.13 → 0.14

File: migration-0-13-to-0-14.yaml

Global query options passed to the PiniaColada plugin have been moved under a queryOptions key. Calls without any options now require an empty object.

Before:

ts
app.use(PiniaColada, { 
  staleTime: 10_000, 
  refetchOnWindowFocus: true, 
  plugins: [/* ... */], 
})

app.use(PiniaColada)

After:

ts
app.use(PiniaColada, { 
  queryOptions: { 
    staleTime: 10_000, 
    refetchOnWindowFocus: true, 
  }, 
  plugins: [/* ... */], 
})

app.use(PiniaColada, {})

Run the codemod:

sh
ast-grep scan -r node_modules/@pinia/colada/codemods/rules/migration-0-13-to-0-14.yaml -i src

0.21 → 1.0

File: migration-0-21-to-1-0.yaml

The two-parameter form of useQuery and useQueryState is deprecated in favor of a single function parameter.

Before:

ts
useQuery(useContactList, () => ({ search: search.value }))
useQueryState(useContactList, () => ({ search: search.value }))

After:

ts
useQuery(() => useContactList({ search: search.value }))
useQueryState(() => useContactList({ search: search.value }).key)

Run the codemod:

sh
ast-grep scan -r node_modules/@pinia/colada/codemods/rules/migration-0-21-to-1-0.yaml -i src

Released under the MIT License.