Skip to content

Commit de1a841

Browse files
committed
Create @shopify/polaris-migrator package
1 parent 0380b6d commit de1a841

30 files changed

+1374
-607
lines changed

.changeset/loud-camels-accept.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris-migrator': patch
3+
---
4+
5+
Initial release

.eslintrc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ module.exports = {
8787
'@shopify/jsx-no-hardcoded-content': 'off',
8888
},
8989
},
90+
{
91+
files: ['polaris-migrator/src/**/*.{ts,tsx}'],
92+
rules: {
93+
'import/no-default-export': 'off',
94+
},
95+
},
96+
{
97+
files: ['polaris-migrator/src/**/tests/*.{ts,tsx}'],
98+
rules: {
99+
'import/no-default-export': 'off',
100+
'import/no-extraneous-dependencies': 'off',
101+
'@shopify/jsx-no-hardcoded-content': 'off',
102+
'@typescript-eslint/ban-ts-comment': 'off',
103+
},
104+
},
90105
{
91106
files: ['polaris-react/src/**/*.{ts,tsx}'],
92107
extends: ['plugin:@shopify/typescript-type-checking'],

.stylelintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ module.exports = {
1616
'./stylelint-polaris/configs/internal',
1717
],
1818
},
19+
{
20+
files: ['polaris-migrator/**/tests/*.{css,scss}'],
21+
rules: {
22+
'declaration-property-value-disallowed-list': 'off',
23+
},
24+
},
1925
],
2026
ignoreFiles: [
2127
'**/.next/**/*.{css,scss}',

babel.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ module.exports = {
77
'.',
88
// Note: The following projects use rootMode: 'upward' to inherit
99
// and merge with this root level config.
10+
'./polaris-migrator',
1011
'./polaris-tokens',
1112
'./polaris-icons',
1213
'./polaris-react',

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"polaris-for-figma",
1212
"polaris-for-vscode",
1313
"polaris-icons",
14+
"polaris-migrator",
1415
"polaris-react",
1516
"stylelint-polaris",
1617
"polaris.shopify.com"
@@ -36,7 +37,7 @@
3637
"changeset": "changeset",
3738
"preversion-packages": "turbo run preversion",
3839
"version-packages": "yarn preversion-packages && changeset version",
39-
"release": "turbo run build --filter=polaris.shopify.com^... && changeset publish",
40+
"release": "turbo run build --filter='!polaris.shopify.com' && changeset publish",
4041
"preversion": "echo \"Error: use @changsets/cli to version packages\" && exit 1"
4142
},
4243
"devDependencies": {

polaris-migrator/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# [Polaris Migrator](https://polaris.shopify.com/docs/advanced-features)
2+
3+
[![npm version](https://img.shields.io/npm/v/@shopify/polaris-migrator.svg?style=flat)](https://www.npmjs.com/package/@shopify/polaris-migrator)
4+
5+
Codemod transformations to help upgrade your Polaris codebase.
6+
7+
## Usage
8+
9+
```sh
10+
npx @shopify/polaris-migrator <transform> <path>
11+
```
12+
13+
- `transform` - name of transform, see available transforms below.
14+
- `path` - files or directory to transform
15+
- `--dry` Do a dry-run, no code will be edited
16+
- `--print` Prints the changed output for comparison
17+
18+
## Documentation
19+
20+
Visit [polaris.shopify.com/docs/advanced-features/migrations](https://polaris.shopify.com/docs/advanced-features/migrations) to view available migrations.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env node
2+
3+
const {run} = require('./../dist');
4+
5+
run();

polaris-migrator/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
transform: {
3+
'\\.(js|tsx?)$': [
4+
'babel-jest',
5+
{targets: 'current node', envName: 'test', rootMode: 'upward'},
6+
],
7+
},
8+
};

polaris-migrator/package.json

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"name": "@shopify/polaris-migrator",
3+
"version": "0.0.0",
4+
"description": "Codemod transformations to help upgrade your Polaris codebase",
5+
"license": "SEE LICENSE IN LICENSE.md",
6+
"author": "Shopify <[email protected]>",
7+
"homepage": "https://polaris.shopify.com",
8+
"repository": "https://github.com/Shopify/polaris",
9+
"bugs": {
10+
"url": "https://github.com/Shopify/polaris/issues"
11+
},
12+
"publishConfig": {
13+
"access": "public",
14+
"@shopify:registry": "https://registry.npmjs.org"
15+
},
16+
"main": "dist/index.js",
17+
"bin": "bin/migrator-cli.js",
18+
"files": [
19+
"bin",
20+
"dist"
21+
],
22+
"scripts": {
23+
"build": "rollup -c",
24+
"dev": "rollup -c -w",
25+
"start": "./bin/migrator-cli.js",
26+
"lint": "TIMING=1 eslint --cache .",
27+
"test": "jest",
28+
"clean": "rm -rf .turbo node_modules dist *.tsbuildinfo"
29+
},
30+
"dependencies": {
31+
"chalk": "^4.1.0",
32+
"globby": "11.0.1",
33+
"is-git-clean": "^1.1.0",
34+
"jscodeshift": "^0.13.1",
35+
"meow": "^9.0.0",
36+
"postcss": "^8.4.14",
37+
"postcss-scss": "^4.0.4",
38+
"postcss-value-parser": "^4.2.0"
39+
},
40+
"devDependencies": {
41+
"@types/is-git-clean": "^1.1.0",
42+
"@types/jscodeshift": "^0.11.5",
43+
"prettier": "^2.7.1"
44+
}
45+
}

polaris-migrator/rollup.config.mjs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import * as fs from 'node:fs';
2+
import * as path from 'node:path';
3+
import * as url from 'node:url';
4+
5+
import {babel} from '@rollup/plugin-babel';
6+
import {nodeResolve} from '@rollup/plugin-node-resolve';
7+
import commonjs from '@rollup/plugin-commonjs';
8+
import json from '@rollup/plugin-json';
9+
import globby from 'globby';
10+
11+
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
12+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json')));
13+
14+
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
15+
16+
const migrationPaths = globby.sync('./src/migrations/*!(tests)/*.ts');
17+
18+
/** @type {import('rollup').RollupOptions} */
19+
export default {
20+
input: ['src/index.ts', ...migrationPaths],
21+
output: [
22+
{
23+
format: /** @type {const} */ ('cjs'),
24+
entryFileNames: '[name][assetExtname].js',
25+
dir: path.dirname(pkg.main),
26+
preserveModules: true,
27+
exports: 'auto',
28+
},
29+
],
30+
plugins: [
31+
// Allows node_modules resolution
32+
nodeResolve({extensions, preferBuiltins: true}),
33+
// Allow bundling cjs modules. Rollup doesn't understand cjs
34+
commonjs(),
35+
// Compile TypeScript/JavaScript files
36+
babel({
37+
extensions,
38+
rootMode: 'upward',
39+
include: ['src/**/*'],
40+
babelHelpers: 'bundled',
41+
envName: 'production',
42+
targets: 'node 14.13',
43+
}),
44+
json({compact: true}),
45+
],
46+
external: [
47+
...Object.keys(pkg.dependencies ?? {}),
48+
...Object.keys(pkg.peerDependencies ?? {}),
49+
'jscodeshift/src/Runner',
50+
],
51+
};

0 commit comments

Comments
 (0)