Skip to content

Commit d652b52

Browse files
committed
Initial renaming of migrations to new convention
1 parent d7dc443 commit d652b52

File tree

64 files changed

+120
-120
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+120
-120
lines changed

polaris-migrator/README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ npx @shopify/polaris-migrator replace-spacing-lengths <path>
7373
For projects that use the [`@use` rule](https://sass-lang.com/documentation/at-rules/use), all Sass related migrations (ex: `replace-sass-spacing`) accept a `namespace` flag to target a specific `<namespace>.<variable|function|mixin>`.
7474

7575
```sh
76-
npx @shopify/polaris-migrator <sass-migration> <path> --namespace="legacy-polaris-v8"
76+
npx @shopify/polaris-migrator <scss-migration> <path> --namespace="legacy-polaris-v8"
7777
```
7878

79-
### `replace-sass-color`
79+
### `scss-replace-color`
8080

8181
Replace the legacy Sass `color()` function with the supported CSS custom property token equivalent (ex: `var(--p-surface)`). This will only replace a limited subset of mapped values. See the [color-maps.ts](https://github.com/Shopify/polaris/blob/main/polaris-migrator/src/migrations/replace-sass-color/color-maps.ts) for a full list of color mappings based on the CSS property.
8282

@@ -88,10 +88,10 @@ Replace the legacy Sass `color()` function with the supported CSS custom propert
8888
```
8989

9090
```sh
91-
npx @shopify/polaris-migrator replace-sass-color <path>
91+
npx @shopify/polaris-migrator scss-replace-color <path>
9292
```
9393

94-
### `replace-sass-spacing`
94+
### `scss-replace-spacing`
9595

9696
Replace the legacy Sass `spacing()` function with the supported CSS custom property token equivalent (ex: `var(--p-space-4)`).
9797

@@ -103,10 +103,10 @@ Replace the legacy Sass `spacing()` function with the supported CSS custom prope
103103
```
104104

105105
```sh
106-
npx @shopify/polaris-migrator replace-sass-spacing <path>
106+
npx @shopify/polaris-migrator scss-replace-spacing <path>
107107
```
108108

109-
### `replace-static-breakpoint-mixins`
109+
### `scss-replace-breakpoints`
110110

111111
Replace legacy static breakpoint mixins with the new Polaris [media query variables](https://github.com/Shopify/polaris/blob/main/documentation/guides/migrating-from-v9-to-v10.md#media-query-variables).
112112

@@ -116,10 +116,10 @@ Replace legacy static breakpoint mixins with the new Polaris [media query variab
116116
```
117117

118118
```sh
119-
npx @shopify/polaris-migrator replace-static-breakpoint-mixins <path>
119+
npx @shopify/polaris-migrator scss-replace-breakpoints <path>
120120
```
121121

122-
### `replace-static-mixins-with-declarations`
122+
### `scss-replace-text-emphasis`
123123

124124
Replace legacy static mixins with their corresponding declarations and CSS custom properties.
125125

@@ -130,10 +130,10 @@ Replace legacy static mixins with their corresponding declarations and CSS custo
130130
```
131131

132132
```sh
133-
npx @shopify/polaris-migrator replace-static-mixins-with-declarations <path>
133+
npx @shopify/polaris-migrator scss-replace-text-emphasis <path>
134134
```
135135

136-
### `replace-typography-declarations`
136+
### `styles-tokenize-fonts`
137137

138138
Replace legacy Typography functions and hardcoded lengths with Polaris custom properties for `font-family`, `font-size`, `font-weight`, and `line-height` declarations.
139139

@@ -152,10 +152,10 @@ Replace legacy Typography functions and hardcoded lengths with Polaris custom pr
152152
```
153153

154154
```sh
155-
npx @shopify/polaris-migrator replace-typography-declarations <path>
155+
npx @shopify/polaris-migrator styles-tokenize-fonts <path>
156156
```
157157

158-
### `replace-border-declarations`
158+
### `styles-tokenize-fonts`
159159

160160
Replace lengths (`px`, `rem`) and legacy Sass functions (`rem()`,`border()`, `border-width()`, `border-radius()`) in border declarations (`border`, `border-width`, and `border-radius`) with the corresponding Polaris [shape](https://polaris.shopify.com/tokens/shape) token.
161161

@@ -180,10 +180,10 @@ Replace lengths (`px`, `rem`) and legacy Sass functions (`rem()`,`border()`, `bo
180180
```
181181

182182
```sh
183-
npx @shopify/polaris-migrator replace-border-declarations <path>
183+
npx @shopify/polaris-migrator styles-tokenize-fonts <path>
184184
```
185185

186-
### `replace-sass-z-index`
186+
### `scss-replace-z-index`
187187

188188
Replace the legacy Sass `z-index()` function with the supported CSS custom property token equivalent (ex: `var(--p-z-1)`).
189189

@@ -232,7 +232,7 @@ In these cases you may also want to run `npx sass-migrator module <path> --migra
232232
Be aware that this may also create additional code changes in your codebase, we recommend running this only if there are large number of instances of migrations from `z-index` to `map.get`. Otherwise it may be easier to add `use 'sass:map'` to the top of your `.scss` file manually.
233233

234234
```sh
235-
npx @shopify/polaris-migrator replace-sass-spacing <path>
235+
npx @shopify/polaris-migrator scss-replace-z-index <path>
236236
```
237237

238238
## Creating Migrations
@@ -241,56 +241,56 @@ Sometimes referred to as "codemods", migrations are JavaScript functions which m
241241

242242
`polaris-migrator` supports two types of migrations:
243243

244-
- SASS Migrations
244+
- SCSS Migrations
245245
- Typescript Migrations
246246

247-
### Creating a SASS migration
247+
### Creating a SCSS migration
248248

249-
Run `yarn new-migration` to generate a new migration from the `sass-migration` template:
249+
Run `yarn new-migration` to generate a new migration from the `scss-migration` template:
250250

251251
```sh
252252
❯ yarn new-migration
253253
$ yarn workspace @shopify/polaris-migrator generate
254254
$ plop
255255
? [PLOP] Please choose a generator. (Use arrow keys)
256-
sass-migration
256+
scss-migration
257257
typescript-migration
258258
```
259259

260-
Next, provide the name of your migration. For example; `replace-sass-function`:
260+
Next, provide the name of your migration. For example; `scss-replace-function`:
261261

262262
```sh
263263
? [PLOP] Please choose a generator. sass-migration
264-
? Name of the migration (e.g. replace-sass-layout) replace-sass-function
264+
? Name of the migration (e.g. scss-replace-function) scss-replace-function
265265
```
266266

267267
The generator will create the following files in the `migrations` folder:
268268

269269
```
270270
migrations
271-
└── replace-sass-function
272-
├── replace-sass-function.ts
271+
└── scss-replace-function
272+
├── scss-replace-function.ts
273273
└── tests
274-
├── replace-sass-function.input.scss
275-
├── replace-sass-function.output.scss
276-
└── replace-sass-function.test.ts
274+
├── scss-replace-function.input.scss
275+
├── scss-replace-function.output.scss
276+
└── scss-replace-function.test.ts
277277
```
278278

279-
#### The SASS migration function
279+
#### The SCSS migration function
280280

281281
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.
282282

283283
Continuing the example, here is what the migration may look like if our goal is to replace the Sass function `hello()` with `world()`.
284284

285285
```ts
286-
// polaris-migrator/src/migrations/replace-sass-function/replace-sass-function.ts
286+
// polaris-migrator/src/migrations/scss-replace-function/scss-replace-function.ts
287287

288288
import type {FileInfo} from 'jscodeshift';
289289
import postcss, {Plugin} from 'postcss';
290290
import valueParser from 'postcss-value-parser';
291291

292292
const plugin = (): Plugin => ({
293-
postcssPlugin: 'replace-sass-function',
293+
postcssPlugin: 'scss-replace-function',
294294
Declaration(decl) {
295295
// const prop = decl.prop;
296296
const parsedValue = valueParser(decl.value);
@@ -305,22 +305,22 @@ const plugin = (): Plugin => ({
305305
},
306306
});
307307

308-
export default function replaceSassFunction(fileInfo: FileInfo) {
308+
export default function scssReplaceFunction(fileInfo: FileInfo) {
309309
return postcss(plugin()).process(fileInfo.source, {
310310
syntax: require('postcss-scss'),
311311
}).css;
312312
}
313313
```
314314

315-
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).
315+
A more complete example can be seen in [`styles-tokenize-space.ts`](https://github.com/Shopify/polaris/blob/main/polaris-migrator/src/migrations/styles-tokenize-space/styles-tokenize-space.ts).
316316

317317
#### Testing
318318

319319
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:
320320

321-
- `replace-sass-function.test.ts` – Runs the fixtures and sets up additional migration options
322-
- `replace-sass-function.input.scss` – The starting source input
323-
- `replace-sass-function.output.scss` – The expected output after migration
321+
- `scss-replace-function.test.ts` – Runs the fixtures and sets up additional migration options
322+
- `scss-replace-function.input.scss` – The starting source input
323+
- `scss-replace-function.output.scss` – The expected output after migration
324324

325325
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).
326326

@@ -329,7 +329,7 @@ The main test file will load the input/output fixtures to test your migration ag
329329
Run tests locally from workspace root by filtering to the migrations package:
330330

331331
```sh
332-
npx turbo run test --filter=polaris-migrator -- replace-sass-function
332+
npx turbo run test --filter=polaris-migrator -- scss-replace-function
333333
```
334334

335335
### Testing in another codebase
@@ -340,7 +340,7 @@ In your PR, you can add a comment with the text `/snapit` to create a new [snaps
340340

341341
```sh
342342
# example snapshot release
343-
npx @shopify/polaris-migrator@0.0.0-snapshot-release-20220919213536 replace-sass-function "./app/**/*.scss"
343+
npx @shopify/polaris-migrator@0.0.0-snapshot-release-20220919213536 scss-replace-function "./app/**/*.scss"
344344
```
345345

346346
### Linting and formatting migrations

polaris-migrator/plopfile.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
1010
// eslint-disable-next-line import/no-default-export
1111
export default async function run(plop) {
1212
plop.setGenerator(
13-
'sass-migration',
13+
'scss-migration',
1414
await plopDir({
1515
plop,
16-
templateDir: path.join(__dirname, './templates/sass-migration'),
16+
templateDir: path.join(__dirname, './templates/scss-migration'),
1717
outputDir: path.join(__dirname, './src/migrations'),
1818
prompts: [
1919
{
2020
name: 'migrationName',
2121
message: 'Name of the migration',
22-
suffix: ' (e.g. replace-sass-layout)',
22+
suffix: ' (e.g. scss-replace-function)',
2323
validate: (input) => validateMigrationName(plop, input),
2424
},
2525
],
@@ -36,7 +36,7 @@ export default async function run(plop) {
3636
{
3737
name: 'migrationName',
3838
message: 'Name of the migration',
39-
suffix: ' (e.g. replace-component-layout)',
39+
suffix: ' (e.g. component-replace-prop)',
4040
validate: (input) => validateMigrationName(plop, input),
4141
},
4242
],

polaris-migrator/src/migrations/rename-component-prop/rename-component-prop.ts renamed to polaris-migrator/src/migrations/component-rename-prop/component-rename-prop.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type {API, FileInfo, Options} from 'jscodeshift';
22

33
import {renameProps} from '../../utilities/jsx';
44

5-
export default function renameComponentProp(
5+
export default function componentRenameProp(
66
file: FileInfo,
77
{jscodeshift: j}: API,
88
options: Options,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {check} from '../../../utilities/testUtils';
22

3-
const migration = 'rename-component-prop';
4-
const fixtures = ['rename-component-prop'];
3+
const migration = 'component-rename-prop';
4+
const fixtures = ['component-rename-prop'];
55

66
for (const fixture of fixtures) {
77
check(__dirname, {

polaris-migrator/src/migrations/replace-static-breakpoint-mixins/tests/replace-static-breakpoint-mixins.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

polaris-migrator/src/migrations/replace-static-mixins-with-declarations/tests/replace-static-mixins-with-declarations.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

polaris-migrator/src/migrations/replace-typography-declarations/tests/replace-typography-declarations.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const plugin = (options: PluginOptions = {}): Plugin => {
3333
);
3434

3535
return {
36-
postcssPlugin: 'ReplaceStaticBreakpointMixins',
36+
postcssPlugin: 'scss-replace-breakpoints',
3737
AtRule(atRule) {
3838
if (atRule.name !== 'include') return;
3939

@@ -50,7 +50,7 @@ const plugin = (options: PluginOptions = {}): Plugin => {
5050
};
5151
};
5252

53-
export default function replaceStaticMixinsWithDeclarations(
53+
export default function sassReplaceBreakpoints(
5454
fileInfo: FileInfo,
5555
_: API,
5656
options: Options,

0 commit comments

Comments
 (0)