You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes referred to as "codemods", migrations are JavaScript functions which modify some code from one form to another (eg; to move between breaking versions of `@shopify/polaris`). ASTs (Abstract Syntax Trees) are used to "walk" through the code in discreet, strongly typed steps, called "nodes". All changes made to nodes (and thus the AST) are then written out as the new/"migrated" version of the code.
241
241
242
-
Run `yarn new-migration` to generate a new migration from a template.
242
+
`polaris-migrator` supports two types of migrations:
243
+
244
+
- SASS Migrations
245
+
- Typescript Migrations
246
+
247
+
### Creating a SASS migration
248
+
249
+
Run `yarn new-migration` to generate a new migration from the `sass-migration` template:
243
250
244
251
```sh
245
252
❯ yarn new-migration
@@ -250,7 +257,7 @@ $ plop
250
257
typescript-migration
251
258
```
252
259
253
-
We will use the `sass-migration` and call our migration`replace-sass-function` for this example. Provide the name of your migration:
260
+
Next, provide the name of your migration. For example; `replace-sass-function`:
254
261
255
262
```sh
256
263
? [PLOP] Please choose a generator. sass-migration
@@ -269,45 +276,46 @@ migrations
269
276
└── replace-sass-function.test.ts
270
277
```
271
278
272
-
###Writing migration function
279
+
#### The SASS migration function
273
280
274
-
A migration is simply a javascript function which serves as the entry-point for your codemod. The `replace-sass-function.ts` file defines a "migration" function. This function is named the same as the provided migration name, `replace-sass-function`, and is the default export of the file.
281
+
Each migrator has a default export adhering to the [PostCSS Plugin API](https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md) with one main difference: events are only executed once.
275
282
276
-
Some example code has been provided for each template. You can make any migration code adjustments in the migration function. For Sass migrations, a [PostCSS plugin](https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md)is used to parse and transform the source code provided by the [jscodeshift](https://github.com/facebook/jscodeshift).
283
+
Continuing the example, here is what the migration may look like if our goal is to replace the Sass function `hello()` with `world()`.
This example migration will replace the Sass function `hello()` with `world()`.
316
+
A more complete example can be seen in [`replace-spacing-lengths.ts`](https://github.com/Shopify/polaris/blob/main/polaris-migrator/src/migrations/replace-spacing-lengths/replace-spacing-lengths.ts).
309
317
310
-
### Testing
318
+
####Testing
311
319
312
320
The template will also generate starting test files you can use to test your migration. In your migrations `tests` folder, you can see 3 files:
313
321
@@ -317,6 +325,8 @@ The template will also generate starting test files you can use to test your mig
317
325
318
326
The main test file will load the input/output fixtures to test your migration against. You can configure additional fixtures and test migration options (see the `replace-sass-spacing.test.ts` as an example).
319
327
328
+
## Running Migrations
329
+
320
330
Run tests locally from workspace root by filtering to the migrations package:
0 commit comments