Skip to content

Commit

Permalink
feat(upgrade): Do not default to/from versions (#4379)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekradko authored Oct 22, 2024
1 parent 8d8c564 commit bdb2e8b
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .changeset/dirty-paws-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
23 changes: 16 additions & 7 deletions packages/upgrade/src/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MultiSelect, Select, TextInput } from '@inkjs/ui';
import { Newline, Text, useApp } from 'ink';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';

import { Header } from './components/Header.js';
import { Scan } from './components/Scan.js';
Expand Down Expand Up @@ -33,15 +33,12 @@ export default function App(props) {
const [sdkGuesses, setSdkGuesses] = useState([]);
const [sdkGuessConfirmed, setSdkGuessConfirmed] = useState(false);
const [sdkGuessAttempted, setSdkGuessAttempted] = useState(false);
// See comments below, can be enabled on next major

// eslint-disable-next-line no-unused-vars
const [fromVersion, setFromVersion] = useState(props.fromVersion);
const [fromVersionGuessAttempted, setFromVersionGuessAttempted] = useState(false);
// eslint-disable-next-line no-unused-vars

const [toVersion, setToVersion] = useState(props.toVersion);
const [dir, setDir] = useState(props.dir);
const [ignore, setIgnore] = useState(props.ignore);
const [ignore, setIgnore] = useState(props.ignore ?? []);
const [configComplete, setConfigComplete] = useState(false);
const [configVerified, setConfigVerified] = useState(false);
const [uuid, setUuid] = useState();
Expand All @@ -52,8 +49,20 @@ export default function App(props) {
setYolo(false);
}

useEffect(() => {
if (toVersion === 'core-2') {
setFromVersion('core-1');
}
}, [toVersion]);

useEffect(() => {
if (fromVersion === 'core-1') {
setToVersion('core-2');
}
}, [fromVersion]);

// Handle the individual SDK upgrade
if (sdks.length === 1) {
if (!fromVersion && !toVersion && sdks[0] === 'nextjs') {
return (
<SDKWorkflow
packageManager={props.packageManager}
Expand Down
5 changes: 3 additions & 2 deletions packages/upgrade/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ const cli = meow(
Examples
$ clerk-upgrade --sdk=nextjs --dir=src/**
$ clerk-upgrade --ignore=**/public/** --ignore=**/dist/**
$ clerk-upgrade --from=core-1 --to=core-2
`,
{
importMeta: import.meta,
flags: {
from: { type: 'string', default: 'core-1' },
to: { type: 'string', default: 'core-2' },
from: { type: 'string' },
to: { type: 'string' },
sdk: { type: 'string', choices: sdks.map(i => i.value) },
dir: { type: 'string' },
ignore: { type: 'string', isMultiple: true },
Expand Down
8 changes: 1 addition & 7 deletions packages/upgrade/src/codemods/transform-async-request.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,7 @@ module.exports = function transformAsyncRequest({ path, source }, { jscodeshift:
}
});

if (dirtyFlag) {
if (process.env.NODE_ENV !== 'test') {
console.log(`changed: ${path}`);
}
return root.toSource();
}
return undefined;
return dirtyFlag ? root.toSource() : undefined;
};

module.exports.parser = 'tsx';
41 changes: 23 additions & 18 deletions packages/upgrade/src/components/Scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import React, { useEffect, useState } from 'react';

import ExpandableList from '../util/expandable-list.js';

export function Scan({ fromVersion, toVersion, sdks, dir, ignore, noWarnings, uuid, disableTelemetry }) {
export function Scan(props) {
const { fromVersion, toVersion, sdks, dir, ignore, noWarnings, uuid, disableTelemetry } = props;
// NOTE: if the difference between fromVersion and toVersion is greater than 1
// we need to do a little extra work here and import two matchers,
// sequence them after each other, and clearly mark which version migration
Expand All @@ -29,7 +30,7 @@ export function Scan({ fromVersion, toVersion, sdks, dir, ignore, noWarnings, uu
// { sdkName: [{ title: 'x', matcher: /x/, slug: 'x', ... }] }
useEffect(() => {
setStatus(`Loading data for ${toVersion} migration`);
import(`./versions/${toVersion}/index.js`).then(version => {
import(`../versions/${toVersion}/index.js`).then(version => {
setMatchers(
sdks.reduce((m, sdk) => {
m[sdk] = version.default[sdk];
Expand All @@ -44,22 +45,26 @@ export function Scan({ fromVersion, toVersion, sdks, dir, ignore, noWarnings, uu
// result = `files` set to format: ['/filename', '/other/filename']
useEffect(() => {
setStatus('Collecting files to scan');
ignore.push(
'node_modules/**',
'**/node_modules/**',
'.git/**',
'package.json',
'**/package.json',
'package-lock.json',
'**/package-lock.json',
'yarn.lock',
'**/yarn.lock',
'pnpm-lock.yaml',
'**/pnpm-lock.yaml',
'**/*.(png|webp|svg|gif|jpg|jpeg)+', // common image files
'**/*.(mp4|mkv|wmv|m4v|mov|avi|flv|webm|flac|mka|m4a|aac|ogg)+', // common video files
);
globby(convertPathToPattern(path.resolve(dir)), { ignore: ignore.filter(Boolean) }).then(files => {
const pattern = convertPathToPattern(path.resolve(dir));

globby(pattern, {
ignore: [
'node_modules/**',
'**/node_modules/**',
'.git/**',
'package.json',
'**/package.json',
'package-lock.json',
'**/package-lock.json',
'yarn.lock',
'**/yarn.lock',
'pnpm-lock.yaml',
'**/pnpm-lock.yaml',
'**/*.(png|webp|svg|gif|jpg|jpeg)+',
'**/*.(mp4|mkv|wmv|m4v|mov|avi|flv|webm|flac|mka|m4a|aac|ogg)+',
...ignore,
].filter(Boolean),
}).then(files => {
setFiles(files);
});
}, [dir, ignore]);
Expand Down

0 comments on commit bdb2e8b

Please sign in to comment.