Skip to content

Commit ac2ed4e

Browse files
committed
Create @shopify/polaris-migrator package
1 parent 06c6744 commit ac2ed4e

30 files changed

+1407
-581
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"
@@ -37,7 +38,7 @@
3738
"gen-assets": "turbo run gen-assets --filter=polaris.shopify.com",
3839
"preversion-packages": "turbo run preversion",
3940
"version-packages": "yarn preversion-packages && changeset version",
40-
"release": "turbo run build --filter=polaris.shopify.com^... && changeset publish",
41+
"release": "turbo run build --filter='!polaris.shopify.com' && changeset publish",
4142
"preversion": "echo \"Error: use @changsets/cli to version packages\" && exit 1"
4243
},
4344
"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 <migration> <path>
11+
```
12+
13+
- `migration` - name of migration, see available migrations on the docs site below.
14+
- `path` - files or directory to perform migration
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/cjs');
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: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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/cjs/index.js",
17+
"module": "dist/esm/index.mjs",
18+
"types": "dist/types/index.d.ts",
19+
"bin": "bin/migrator-cli.js",
20+
"files": [
21+
"bin",
22+
"dist"
23+
],
24+
"scripts": {
25+
"build": "run-s build:*",
26+
"build:js": "rollup -c",
27+
"build:types": "tsc -b",
28+
"dev": "rollup -c -w",
29+
"start": "./bin/migrator-cli.js",
30+
"lint": "TIMING=1 eslint --cache .",
31+
"test": "jest",
32+
"clean": "rm -rf .turbo node_modules dist *.tsbuildinfo"
33+
},
34+
"dependencies": {
35+
"chalk": "^4.1.0",
36+
"globby": "11.0.1",
37+
"is-git-clean": "^1.1.0",
38+
"jscodeshift": "^0.13.1",
39+
"meow": "^9.0.0",
40+
"postcss": "^8.4.14",
41+
"postcss-scss": "^4.0.4",
42+
"postcss-value-parser": "^4.2.0"
43+
},
44+
"devDependencies": {
45+
"@types/is-git-clean": "^1.1.0",
46+
"@types/jscodeshift": "^0.11.5",
47+
"@rollup/plugin-babel": "^5.3.1",
48+
"@rollup/plugin-commonjs": "^22.0.2",
49+
"@rollup/plugin-json": "^4.1.0",
50+
"@rollup/plugin-node-resolve": "^13.3.0",
51+
"@shopify/polaris": "^10.0.0",
52+
"prettier": "^2.7.1"
53+
}
54+
}

polaris-migrator/rollup.config.mjs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
format: /** @type {const} */ ('esm'),
31+
entryFileNames: '[name][assetExtname].mjs',
32+
dir: path.dirname(pkg.module),
33+
preserveModules: true,
34+
},
35+
],
36+
plugins: [
37+
// Allows node_modules resolution
38+
nodeResolve({extensions, preferBuiltins: true}),
39+
// Allow bundling cjs modules. Rollup doesn't understand cjs
40+
commonjs(),
41+
// Compile TypeScript/JavaScript files
42+
babel({
43+
extensions,
44+
rootMode: 'upward',
45+
include: ['src/**/*'],
46+
babelHelpers: 'bundled',
47+
envName: 'production',
48+
targets: 'node 14.13',
49+
}),
50+
json({compact: true}),
51+
],
52+
external: [
53+
...Object.keys(pkg.dependencies ?? {}),
54+
...Object.keys(pkg.peerDependencies ?? {}),
55+
'jscodeshift/src/Runner',
56+
],
57+
};

0 commit comments

Comments
 (0)