From 2821bdb8569429d1bd34fe7d14dabbcafc71d50a Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Sat, 30 Oct 2021 02:05:50 +0300 Subject: [PATCH 1/9] fix standalone transform runs - resolve path of transform MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit in the issue you linked [1] from jscodeshift, i think you forgot the `path.resolve` for non-http(s) imports (not even sure how they'd work tbh). i tried running a local transform and it didn't work, but with this fix it did regardless of where i called the `packages/cli/bin/codeshift-cli.js` from. i think you might've been using the packages and not the --transforms flag so i understand why you could've missed it 😅 tbh there are more improvements to make w/ the local transforms (see [2]) but this is the first step :D [1] https://github.com/facebook/jscodeshift/issues/398 [2] https://github.com/CodeshiftCommunity/CodeshiftCommunity/issues/48#issuecomment-955049880 --- packages/cli/src/main.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index 5ae27236b..73352daa5 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -1,3 +1,4 @@ +import path from 'path'; import semver from 'semver'; import chalk from 'chalk'; import { PluginManager } from 'live-plugin-manager'; @@ -126,9 +127,10 @@ export default async function main(paths: string[], flags: Flags) { ); for (const transform of transforms) { - console.log(chalk.green('Running transform:'), transform); + const resolvedTransformPath = path.resolve(transform); + console.log(chalk.green('Running transform:'), resolvedTransformPath); - await jscodeshift.run(transform, paths, { + await jscodeshift.run(resolvedTransformPath, paths, { verbose: 0, dry: flags.dry, print: true, From b8d9e78c0ec5f6813f4e98ddfb8807ab138285b6 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Fri, 29 Oct 2021 16:46:10 +0300 Subject: [PATCH 2/9] cui: Initial setup: @pipedrive/convention-ui-react Signed-off-by: Kipras Melnikovas --- .eslintignore | 2 ++ .../.gitignore | 1 + .../.npmignore | 5 ++++ .../.prettierrc.js | 7 ++++++ .../jest.config.js | 21 ++++++++++++++++ .../package.json | 24 +++++++++++++++++++ .../src/5.0.0/transform.spec.ts | 20 ++++++++++++++++ .../src/5.0.0/transform.ts | 7 ++++++ .../src/codeshift.config.js | 9 +++++++ .../tsconfig.json | 14 +++++++++++ package.json | 4 ++-- yarn.lock | 8 +++---- 12 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 .eslintignore create mode 100644 community/@pipedrive__convention-ui-react/.gitignore create mode 100644 community/@pipedrive__convention-ui-react/.npmignore create mode 100644 community/@pipedrive__convention-ui-react/.prettierrc.js create mode 100644 community/@pipedrive__convention-ui-react/jest.config.js create mode 100644 community/@pipedrive__convention-ui-react/package.json create mode 100644 community/@pipedrive__convention-ui-react/src/5.0.0/transform.spec.ts create mode 100644 community/@pipedrive__convention-ui-react/src/5.0.0/transform.ts create mode 100644 community/@pipedrive__convention-ui-react/src/codeshift.config.js create mode 100644 community/@pipedrive__convention-ui-react/tsconfig.json diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..f06235c46 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/community/@pipedrive__convention-ui-react/.gitignore b/community/@pipedrive__convention-ui-react/.gitignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/.gitignore @@ -0,0 +1 @@ +node_modules diff --git a/community/@pipedrive__convention-ui-react/.npmignore b/community/@pipedrive__convention-ui-react/.npmignore new file mode 100644 index 000000000..3ffc71d94 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/.npmignore @@ -0,0 +1,5 @@ +src/ +**/__test__ +**/*.spec.(ts|js) +.vscode +jest.config.js diff --git a/community/@pipedrive__convention-ui-react/.prettierrc.js b/community/@pipedrive__convention-ui-react/.prettierrc.js new file mode 100644 index 000000000..edeb32b59 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + semi: true, + trailingComma: "all", + singleQuote: false, + printWidth: 120, + tabWidth: 4, +}; diff --git a/community/@pipedrive__convention-ui-react/jest.config.js b/community/@pipedrive__convention-ui-react/jest.config.js new file mode 100644 index 000000000..c10b374d3 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/jest.config.js @@ -0,0 +1,21 @@ +module.exports = { + transform: { + "^.+\\.ts$": "ts-jest", // + }, + moduleFileExtensions: [ + "ts", // + "tsx", + "js", + ], + testRegex: "^.+\\.spec\\.(tsx|ts|js)$", + globals: { + // + "ts-jest": { + tsconfig: "tsconfig.json", + }, + }, + testPathIgnorePatterns: [ + "/node_modules/", // + "dist/", + ], +}; diff --git a/community/@pipedrive__convention-ui-react/package.json b/community/@pipedrive__convention-ui-react/package.json new file mode 100644 index 000000000..0e364c979 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/package.json @@ -0,0 +1,24 @@ +{ + "private": true, + "name": "@pipedrive/convention-ui-react", + "version": "0.0.0", + "license": "MIT", + "main": "dist/codeshift.config.js", + "scripts": { + "build": "tsc --build", + "test": "jest" + }, + "dependencies": {}, + "devDependencies": { + "@codeshift/test-utils": "*", + "@codeshift/utils": "*", + "@types/jest": "^26.0.15", + "@types/node": "^16.11.0", + "jest": "^26.6.0", + "jscodeshift": "^0.12.0", + "prettier": "^1.16.4", + "ts-jest": "^26.4.4", + "typescript": "^4.3.5" + }, + "repository": "https://github.com/CodeshiftCommunity/CodeshiftCommunity/tree/master/community/@pipedrive__convention-ui-react" +} diff --git a/community/@pipedrive__convention-ui-react/src/5.0.0/transform.spec.ts b/community/@pipedrive__convention-ui-react/src/5.0.0/transform.spec.ts new file mode 100644 index 000000000..5f9b24d3b --- /dev/null +++ b/community/@pipedrive__convention-ui-react/src/5.0.0/transform.spec.ts @@ -0,0 +1,20 @@ +// import { applyTransform } from "@codeshift/test-utils"; +// import * as transformer from "./transform"; + +// describe("@pipedrive/convention-ui-react@5.0.0 transform", () => { +// it("should transform correctly", () => { +// const result = applyTransform( +// transformer, +// ` +// import foo from '<% packageName %>'; +// console.log(foo); +// `, +// { parser: "tsx" }, +// ); + +// expect(result).toMatchInlineSnapshot(` +// "import foo from '<% packageName %>'; +// console.log(foo);" +// `); +// }); +// }); diff --git a/community/@pipedrive__convention-ui-react/src/5.0.0/transform.ts b/community/@pipedrive__convention-ui-react/src/5.0.0/transform.ts new file mode 100644 index 000000000..982997186 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/src/5.0.0/transform.ts @@ -0,0 +1,7 @@ +import { API, FileInfo, Options } from "jscodeshift"; + +export default function transformer(file: FileInfo, { jscodeshift: j }: API, options: Options) { + const source = j(file.source); + + return source.toSource(options.printOptions); +} diff --git a/community/@pipedrive__convention-ui-react/src/codeshift.config.js b/community/@pipedrive__convention-ui-react/src/codeshift.config.js new file mode 100644 index 000000000..350960681 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/src/codeshift.config.js @@ -0,0 +1,9 @@ +module.exports = { + maintainers: ["kiprasmel"], + target: [], + description: "Codemods for @pipedrive/convention-ui-react", + transforms: { + "5.0.0": require.resolve("./5.0.0/transform"), // + }, + presets: {}, +}; diff --git a/community/@pipedrive__convention-ui-react/tsconfig.json b/community/@pipedrive__convention-ui-react/tsconfig.json new file mode 100644 index 000000000..c12d4e6d6 --- /dev/null +++ b/community/@pipedrive__convention-ui-react/tsconfig.json @@ -0,0 +1,14 @@ +{ + "include": [ + "src/**/*" // + ], + "compilerOptions": { + "outDir": "dist", // + "esModuleInterop": true, + "allowJs": true, + "types": [ + "jest", // + "node" + ] + } +} diff --git a/package.json b/package.json index ec3817f28..ab788aa5e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "test:watch": "jest --watch", "test:coverage": "jest --coverage", "validate": "yarn build && yarn lint && yarn monorepo:check && preconstruct validate", - "lint": "eslint --config .eslintrc.js --ext tsx,ts ./packages/**/src ./community/**/*", + "lint": "yarn eslint --config .eslintrc.js --ext tsx,ts ./packages/**/src ./community/**/*", "lint:fix": "yarn lint -- --fix", "lint:file-structure": "npx @ls-lint/ls-lint", "types:check": "tsc --noEmit --skipLibCheck", @@ -61,7 +61,7 @@ "ts-loader": "^6.2.1", "ts-node": "^9.1.1", "tslib": "^2.2.0", - "typescript": "^4.1.3" + "typescript": "^4.3.5" }, "workspaces": [ "packages/*", diff --git a/yarn.lock b/yarn.lock index 0ccb6c00f..fcb036645 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7050,10 +7050,10 @@ typedarray@^0.0.6: resolved "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.1.3: - version "4.4.2" - resolved "https://registry.npmjs.org/typescript/-/typescript-4.4.2.tgz#6d618640d430e3569a1dfb44f7d7e600ced3ee86" - integrity sha512-gzP+t5W4hdy4c+68bfcv0t400HVJMMd2+H9B7gae1nQlBzCqvrXX+6GL/b3GAgyTH966pzrZ70/fRjwAtZksSQ== +typescript@^4.3.5: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" From 0f47286c888fb937af8456744d01f9952381793e Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Fri, 29 Oct 2021 16:41:06 +0300 Subject: [PATCH 3/9] cui: better ts support Signed-off-by: Kipras Melnikovas --- .../tsconfig.json | 42 ++++++++++++++----- yarn.lock | 10 +++++ 2 files changed, 42 insertions(+), 10 deletions(-) diff --git a/community/@pipedrive__convention-ui-react/tsconfig.json b/community/@pipedrive__convention-ui-react/tsconfig.json index c12d4e6d6..d76f1bfb9 100644 --- a/community/@pipedrive__convention-ui-react/tsconfig.json +++ b/community/@pipedrive__convention-ui-react/tsconfig.json @@ -1,14 +1,36 @@ { - "include": [ - "src/**/*" // - ], "compilerOptions": { - "outDir": "dist", // - "esModuleInterop": true, "allowJs": true, - "types": [ - "jest", // - "node" - ] - } + "target": "es5", // + "module": "commonjs", + "lib": [ + "es2017" // + ], + "skipLibCheck": true, + "sourceMap": true, + "outDir": "./dist", + "moduleResolution": "node", + "removeComments": true, + "noImplicitAny": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "resolveJsonModule": true, + "baseUrl": "." + }, + "exclude": [ + "node_modules" // + ], + "include": [ + "./src/**/*.ts", // + "./src/**/*.js" + ] } diff --git a/yarn.lock b/yarn.lock index fcb036645..a9e2bc155 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1762,6 +1762,11 @@ resolved "https://registry.npmjs.org/@types/node/-/node-12.20.21.tgz#575e91f59c2e79318c2d39a48286c6954e484fd5" integrity sha512-Qk7rOvV2A4vNgXNS88vEvbJE1NDFPCQ8AU+pNElrU2bA4yrRDef3fg3SUe+xkwyin3Bpg/Xh5JkNWTlsOcS2tA== +"@types/node@^16.11.0": + version "16.11.4" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.4.tgz#90771124822d6663814f7c1c9b45a6654d8fd964" + integrity sha512-TMgXmy0v2xWyuCSCJM6NCna2snndD8yvQF67J29ipdzMcsPa9u+o0tjF5+EQNdhcuZplYuouYqpc4zcd5I6amQ== + "@types/normalize-package-data@^2.4.0": version "2.4.1" resolved "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301" @@ -7055,6 +7060,11 @@ typescript@^4.3.5: resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== +typescript@^4.3.5: + version "4.4.4" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" + integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== + unicode-canonical-property-names-ecmascript@^1.0.4: version "1.0.4" resolved "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818" From f247d0d6d1664ab08157d755a0455e480ff307c8 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Mon, 1 Nov 2021 15:35:04 +0200 Subject: [PATCH 4/9] feat: temp `run.js` script to quickly run local codemods Signed-off-by: Kipras Melnikovas --- run.js | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ shorthands.json | 3 ++ 2 files changed, 130 insertions(+) create mode 100755 run.js create mode 100644 shorthands.json diff --git a/run.js b/run.js new file mode 100755 index 000000000..4fe483a58 --- /dev/null +++ b/run.js @@ -0,0 +1,127 @@ +#!/usr/bin/env node + +/** + * a temporary utility to run local codemods quickly + * before we improve stuff upstream. + */ + +const helpMsg = ` +run.js parser=flow codemodsToRun filesOrDirectoriesToModify extensions="js,jsx,ts,tsx" + +codemodsToRun - paths to codemods which have a codeshift.config.js file. + separated by spaces. + can also just provide keys from the "shorthands.json" file + +examples: + +./run.js flow ./community/@pipedrive__convention-ui-react/src/5.0.0/transform.ts ~/projects/some-project-which-uses-cui4/src/ +./run.js flow cui5 ~/projects/some-project-which-uses-cui4/src/ # cui5 is from shorthands.json + +`; + +const path = require('path'); +const cp = require('child_process'); + +const peekNextArg = () => process.argv[0]; +const eatNextArg = () => process.argv.shift(); + +const shouldPrintHelp = () => ( + (should = + !process.argv.length || + ['-h', '--help', '-help', 'help'].includes(peekNextArg())), + should && console.log(helpMsg), + should +); + +const parseArgv = () => ( + process.argv.splice(0, 2), + shouldPrintHelp() && process.exit(1), + { + parser: eatNextArg() || 'flow', + transformsToRun: eatNextArg() || '', + filesOrDirectoriesToModify: eatNextArg() || '', + extensions: eatNextArg() || 'js,jsx,ts,tsx', + } +); + +run(); + +function run() { + let { + parser, // + transformsToRun, + filesOrDirectoriesToModify, + extensions, + } = parseArgv(); + + const shorthands = require(path.join(__dirname, './shorthands.json')); + console.log({ shorthands }); + + transformsToRun = parseArrayFromCsv(transformsToRun) + .map(t => { + if (t in shorthands) { + return resolveTransformsFromShorthand(shorthands[t]); + } else { + const dir = path.dirname(t); + const cmd = `yarn --cwd ${dir} build`; + console.log('transform to run, build cmd', { cmd }); + cp.execSync(cmd); + return t; + } + }) + .flat(); + + filesOrDirectoriesToModify = parseArrayFromCsv(filesOrDirectoriesToModify); + + const cliPath = path.join(__dirname, './packages/cli/bin/codeshift-cli.js'); + + const cmdToExec = `${cliPath} --parser ${parser} -e ${extensions} -t ${transformsToRun} ${filesOrDirectoriesToModify}`; + console.log({ cmdToExec }); + + cp.exec(cmdToExec, (err, stdout, stderr) => { + if (err) { + console.error(stderr); + return process.exit(1); + } + + console.log(stdout); + + console.log('succ'); + process.exit(0); + }); +} + +function parseArrayFromCsv(csv = '') { + return csv + .split(',') + .filter(c => !!c) + .map(c => c.trim()) + .filter(c => !!c); +} + +function resolveTransformsFromShorthand([pathToCodemodPkg, transformVersion]) { + cp.execSync(`yarn --cwd ${pathToCodemodPkg} build`); + console.log('built'); + + const pathToCodemodConfig = path.join( + pathToCodemodPkg, + 'dist', + 'codeshift.config.js', + ); + console.log({ pathToCodemodConfig }); + + const codemodCfg = require(path.join(__dirname, pathToCodemodConfig)); + + const { transforms } = codemodCfg; + + const transformsApplicable = Object.entries(transforms) + .map(([version, relPathToTransform]) => { + if (version === transformVersion) { + return relPathToTransform; + // return path.join(pathToCodemodPkg, 'dist', relPathToTransform); // TODO must ensure it's compiled / run with ts-node / require from 'dist' + } + }) + .filter(x => !!x); + + return transformsApplicable; +} diff --git a/shorthands.json b/shorthands.json new file mode 100644 index 000000000..fffb4a391 --- /dev/null +++ b/shorthands.json @@ -0,0 +1,3 @@ +{ + "cui5": ["./community/@pipedrive__convention-ui-react", "5.0.0"] +} From 61cc9496a6c59bac1c8969cb20e7702c8e99e3ca Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Mon, 1 Nov 2021 18:04:16 +0200 Subject: [PATCH 5/9] fix: we only support a single path for applying codemods (will fix later in main cli) Signed-off-by: Kipras Melnikovas --- run.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/run.js b/run.js index 4fe483a58..288bee00d 100755 --- a/run.js +++ b/run.js @@ -6,7 +6,7 @@ */ const helpMsg = ` -run.js parser=flow codemodsToRun filesOrDirectoriesToModify extensions="js,jsx,ts,tsx" +run.js parser=flow codemodsToRun fileOrDirectoryToModify extensions="js,jsx,ts,tsx" codemodsToRun - paths to codemods which have a codeshift.config.js file. separated by spaces. @@ -38,8 +38,8 @@ const parseArgv = () => ( shouldPrintHelp() && process.exit(1), { parser: eatNextArg() || 'flow', - transformsToRun: eatNextArg() || '', - filesOrDirectoriesToModify: eatNextArg() || '', + transformsToRun: parseArrayFromCsv(eatNextArg() || ''), + fileOrDirectoryToModify: eatNextArg() || '', extensions: eatNextArg() || 'js,jsx,ts,tsx', } ); @@ -50,14 +50,14 @@ function run() { let { parser, // transformsToRun, - filesOrDirectoriesToModify, + fileOrDirectoryToModify, extensions, } = parseArgv(); const shorthands = require(path.join(__dirname, './shorthands.json')); console.log({ shorthands }); - transformsToRun = parseArrayFromCsv(transformsToRun) + transformsToRun = transformsToRun .map(t => { if (t in shorthands) { return resolveTransformsFromShorthand(shorthands[t]); @@ -71,11 +71,9 @@ function run() { }) .flat(); - filesOrDirectoriesToModify = parseArrayFromCsv(filesOrDirectoriesToModify); - const cliPath = path.join(__dirname, './packages/cli/bin/codeshift-cli.js'); - const cmdToExec = `${cliPath} --parser ${parser} -e ${extensions} -t ${transformsToRun} ${filesOrDirectoriesToModify}`; + const cmdToExec = `${cliPath} --parser ${parser} -e ${extensions} -t ${transformsToRun} ${fileOrDirectoryToModify}`; console.log({ cmdToExec }); cp.exec(cmdToExec, (err, stdout, stderr) => { From e946a1fad8b83d1a88b37d6ad1784c0b0cc1b458 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Wed, 3 Nov 2021 18:20:40 +0200 Subject: [PATCH 6/9] feat: allow specifying multiple transforms maybe would be nicer if the interface would be `-t t1 -t t2 -t t3` instead of current `-t t1,t2,t3` (you could separate into multiple lines and keep it cleaner), but don't know how to do that so this works just fine. Signed-off-by: Kipras Melnikovas --- packages/cli/src/index.ts | 2 +- packages/cli/src/main.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index b5ee325f2..08fc7ea69 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -16,7 +16,7 @@ program .usage('[global options] ...') .option( '-t, --transform ', - 'The transform to run, will prompt for a transform if not provided and no module is passed', + 'The transform(s) to run, will prompt for a transform if not provided and no module is passed\nTo provide multiple transforms, separate them with commas (e.g. "-t t1,t2,t3")', ) .option( '--packages ', diff --git a/packages/cli/src/main.ts b/packages/cli/src/main.ts index 5ae27236b..4b17992b1 100644 --- a/packages/cli/src/main.ts +++ b/packages/cli/src/main.ts @@ -23,7 +23,11 @@ export default async function main(paths: string[], flags: Flags) { } if (flags.transform) { - transforms.push(flags.transform); + if (flags.transform.includes(',')) { + flags.transform.split(',').forEach(t => transforms.push(t.trim())); + } else { + transforms.push(flags.transform); + } } const packageManager = new PluginManager(); From f4b83ef2302f40a9f730a8c9d7df9c46367d4816 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Wed, 3 Nov 2021 19:08:39 +0200 Subject: [PATCH 7/9] fix: join transforms with ',' depends on: https://github.com/pipedrive/CodeshiftCommunity/pull/5 Signed-off-by: Kipras Melnikovas --- run.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/run.js b/run.js index 288bee00d..24767cc4c 100755 --- a/run.js +++ b/run.js @@ -69,7 +69,8 @@ function run() { return t; } }) - .flat(); + .flat() + .join(','); const cliPath = path.join(__dirname, './packages/cli/bin/codeshift-cli.js'); From a5aeb9435a4bfd153cd874f2f774615170b5762d Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Wed, 3 Nov 2021 20:46:05 +0200 Subject: [PATCH 8/9] feat: pipe stdio! Signed-off-by: Kipras Melnikovas (cherry picked from commit d53171e599b8ea286b9a0f349fb0063d9e0cc502) --- run.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/run.js b/run.js index 24767cc4c..927ed5a67 100755 --- a/run.js +++ b/run.js @@ -44,6 +44,21 @@ const parseArgv = () => ( } ); +/** + * will pipe stdio as if we were running the command ourselves! + * + * see https://stackoverflow.com/a/47338488/9285308 + * + * usage: + * + * ```js + * const command = "ls -la"; + * require("child_process").execSync(command, { ...pipeStdioOpts() }); + * ``` + * + */ +const pipeStdioOpts = (cwd = process.cwd()) => ({ cwd, stdio: 'inherit' }); + run(); function run() { @@ -65,7 +80,7 @@ function run() { const dir = path.dirname(t); const cmd = `yarn --cwd ${dir} build`; console.log('transform to run, build cmd', { cmd }); - cp.execSync(cmd); + cp.execSync(cmd, { ...pipeStdioOpts() }); return t; } }) @@ -77,17 +92,7 @@ function run() { const cmdToExec = `${cliPath} --parser ${parser} -e ${extensions} -t ${transformsToRun} ${fileOrDirectoryToModify}`; console.log({ cmdToExec }); - cp.exec(cmdToExec, (err, stdout, stderr) => { - if (err) { - console.error(stderr); - return process.exit(1); - } - - console.log(stdout); - - console.log('succ'); - process.exit(0); - }); + cp.execSync(cmdToExec, { ...pipeStdioOpts() }); } function parseArrayFromCsv(csv = '') { @@ -99,7 +104,7 @@ function parseArrayFromCsv(csv = '') { } function resolveTransformsFromShorthand([pathToCodemodPkg, transformVersion]) { - cp.execSync(`yarn --cwd ${pathToCodemodPkg} build`); + cp.execSync(`yarn --cwd ${pathToCodemodPkg} build`, { ...pipeStdioOpts() }); console.log('built'); const pathToCodemodConfig = path.join( From 3f7e7bac4d63566a6b6ecc8f9301dd271f350312 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Thu, 25 Nov 2021 10:08:36 +0200 Subject: [PATCH 9/9] feat: add a temp script for running & seeing diff quickly Signed-off-by: Kipras Melnikovas --- x | 222 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100755 x diff --git a/x b/x new file mode 100755 index 000000000..3b5937d83 --- /dev/null +++ b/x @@ -0,0 +1,222 @@ +#!/usr/bin/env bash + +set -e + +mkdir -p .tmp/ + +for i in {1..1}; do cat > ./.tmp/$i.js < + lol haha + +); + +const a2 = + + nice badge bro + + +const a3 = + + this one too damn + + +const a4 =