@backstage/codemods 0.1.37 → 0.1.38-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @backstage/codemods
2
2
 
3
+ ## 0.1.38-next.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 344ea56acc: Bump `commander` to version 9.1.0
8
+
3
9
  ## 0.1.37
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var program = require('commander');
3
+ var commander = require('commander');
4
4
  var chalk = require('chalk');
5
5
  var path = require('path');
6
6
  var child_process = require('child_process');
@@ -9,7 +9,6 @@ var os = require('os');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
- var program__default = /*#__PURE__*/_interopDefaultLegacy(program);
13
12
  var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
14
13
 
15
14
  const codemods = [
@@ -30,10 +29,13 @@ class CustomError extends Error {
30
29
  }
31
30
  class ExitCodeError extends CustomError {
32
31
  constructor(code, command) {
32
+ var __super = (...args) => {
33
+ super(...args);
34
+ };
33
35
  if (command) {
34
- super(`Command '${command}' exited with code ${code}`);
36
+ __super(`Command '${command}' exited with code ${code}`);
35
37
  } else {
36
- super(`Child exited with code ${code}`);
38
+ __super(`Child exited with code ${code}`);
37
39
  }
38
40
  this.code = code;
39
41
  }
@@ -56,7 +58,7 @@ ${chalk__default["default"].red(`${error}`)}
56
58
 
57
59
  const paths = cliCommon.findPaths(__dirname);
58
60
  function createCodemodAction(name) {
59
- return async (_, cmd) => {
61
+ return async (dirs, opts) => {
60
62
  const transformPath = path.relative(process.cwd(), paths.resolveOwn("transforms", `${name}.js`));
61
63
  const args = [
62
64
  "--parser=tsx",
@@ -65,11 +67,11 @@ function createCodemodAction(name) {
65
67
  transformPath,
66
68
  "--ignore-pattern=**/node_modules/**"
67
69
  ];
68
- if (cmd.dry) {
70
+ if (opts.dry) {
69
71
  args.push("--dry");
70
72
  }
71
- if (cmd.args.length) {
72
- args.push(...cmd.args);
73
+ if (dirs.length) {
74
+ args.push(...dirs);
73
75
  } else {
74
76
  args.push(".");
75
77
  }
@@ -108,29 +110,29 @@ function createCodemodAction(name) {
108
110
  };
109
111
  }
110
112
 
111
- var version = "0.1.37";
113
+ var version = "0.1.38-next.0";
112
114
 
113
115
  async function main(argv) {
114
- program__default["default"].name("backstage-codemods").version(version);
115
- const applyCommand = program__default["default"].command("apply <codemod> [<target-dirs...>]").description("Apply a codemod to target directories, defaulting to the current directory");
116
+ commander.program.name("backstage-codemods").version(version);
117
+ const applyCommand = commander.program.command("apply <codemod> [target-dirs...]").description("Apply a codemod to target directories, defaulting to the current directory");
116
118
  for (const codemod of codemods) {
117
- applyCommand.command(`${codemod.name} [<target-dirs...>]`).description(codemod.description).option("-d, --dry", "Dry run, no changes written to files").action(createCodemodAction(codemod.name));
119
+ applyCommand.command(`${codemod.name} [target-dirs...]`).description(codemod.description).option("-d, --dry", "Dry run, no changes written to files").action(createCodemodAction(codemod.name));
118
120
  }
119
- program__default["default"].command("list").description("List available codemods").action(() => {
121
+ commander.program.command("list").description("List available codemods").action(() => {
120
122
  const maxNameLength = Math.max(...codemods.map((m) => m.name.length));
121
123
  for (const codemod of codemods) {
122
124
  const paddedName = codemod.name.padEnd(maxNameLength, " ");
123
125
  console.log(`${paddedName} - ${codemod.description}`);
124
126
  }
125
127
  });
126
- program__default["default"].on("command:*", () => {
128
+ commander.program.on("command:*", () => {
127
129
  console.log();
128
- console.log(chalk__default["default"].red(`Invalid command: ${program__default["default"].args.join(" ")}`));
130
+ console.log(chalk__default["default"].red(`Invalid command: ${commander.program.args.join(" ")}`));
129
131
  console.log();
130
- program__default["default"].outputHelp();
132
+ commander.program.outputHelp();
131
133
  process.exit(1);
132
134
  });
133
- program__default["default"].parse(argv);
135
+ commander.program.parse(argv);
134
136
  }
135
137
  process.on("unhandledRejection", (rejection) => {
136
138
  if (rejection instanceof Error) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/codemods.ts","../src/errors.ts","../src/action.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface Codemod {\n name: string;\n description: string;\n}\n\nexport const codemods: Codemod[] = [\n {\n name: 'core-imports',\n description:\n 'Updates @backstage/core imports to use @backstage/core-* imports instead.',\n },\n {\n name: 'extension-names',\n description:\n 'Adds a \"name\" property to all core extensions provided by plugins.',\n },\n];\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport chalk from 'chalk';\n\nexport class CustomError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n}\n\nexport class ExitCodeError extends CustomError {\n readonly code: number;\n\n constructor(code: number, command?: string) {\n if (command) {\n super(`Command '${command}' exited with code ${code}`);\n } else {\n super(`Child exited with code ${code}`);\n }\n this.code = code;\n }\n}\n\nexport function exitWithError(error: Error): never {\n if (error instanceof ExitCodeError) {\n process.stderr.write(`\\n${chalk.red(error.message)}\\n\\n`);\n process.exit(error.code);\n } else {\n process.stderr.write(`\\n${chalk.red(`${error}`)}\\n\\n`);\n process.exit(1);\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { relative as relativePath } from 'path';\nimport { spawn } from 'child_process';\nimport { Command } from 'commander';\nimport { findPaths } from '@backstage/cli-common';\nimport { platform } from 'os';\nimport { ExitCodeError } from './errors';\n\n// eslint-disable-next-line no-restricted-syntax\nconst paths = findPaths(__dirname);\n\nexport function createCodemodAction(name: string) {\n return async (_: unknown, cmd: Command) => {\n const transformPath = relativePath(\n process.cwd(),\n paths.resolveOwn('transforms', `${name}.js`),\n );\n\n const args = [\n '--parser=tsx',\n '--extensions=tsx,js,ts,tsx',\n '--transform',\n transformPath,\n '--ignore-pattern=**/node_modules/**',\n ];\n\n if (cmd.dry) {\n args.push('--dry');\n }\n\n if (cmd.args.length) {\n args.push(...cmd.args);\n } else {\n args.push('.');\n }\n\n console.log(`Running jscodeshift with these arguments: ${args.join(' ')}`);\n\n let command;\n if (platform() === 'win32') {\n command = 'jscodeshift';\n } else {\n // jscodeshift ships a slightly broken bin script with windows\n // line endings so we need to execute it using node rather than\n // letting the `#!/usr/bin/env node` take care of it\n command = process.argv0;\n args.unshift(require.resolve('.bin/jscodeshift'));\n }\n\n const child = spawn(command, args, {\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n FORCE_COLOR: 'true',\n },\n });\n\n if (typeof child.exitCode === 'number') {\n if (child.exitCode) {\n throw new ExitCodeError(child.exitCode, name);\n }\n return;\n }\n\n await new Promise<void>((resolve, reject) => {\n child.once('error', error => reject(error));\n child.once('exit', code => {\n if (code) {\n reject(new ExitCodeError(code, name));\n } else {\n resolve();\n }\n });\n });\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A collection of codemods for Backstage projects\n *\n * @packageDocumentation\n */\n\nimport program from 'commander';\nimport chalk from 'chalk';\nimport { codemods } from './codemods';\nimport { exitWithError } from './errors';\nimport { createCodemodAction } from './action';\nimport { version } from '../package.json';\n\nasync function main(argv: string[]) {\n program.name('backstage-codemods').version(version);\n\n const applyCommand = program\n .command('apply <codemod> [<target-dirs...>]')\n .description(\n 'Apply a codemod to target directories, defaulting to the current directory',\n );\n\n for (const codemod of codemods) {\n applyCommand\n .command(`${codemod.name} [<target-dirs...>]`)\n .description(codemod.description)\n .option('-d, --dry', 'Dry run, no changes written to files')\n .action(createCodemodAction(codemod.name));\n }\n\n program\n .command('list')\n .description('List available codemods')\n .action(() => {\n const maxNameLength = Math.max(...codemods.map(m => m.name.length));\n for (const codemod of codemods) {\n const paddedName = codemod.name.padEnd(maxNameLength, ' ');\n console.log(`${paddedName} - ${codemod.description}`);\n }\n });\n\n program.on('command:*', () => {\n console.log();\n console.log(chalk.red(`Invalid command: ${program.args.join(' ')}`));\n console.log();\n program.outputHelp();\n process.exit(1);\n });\n\n program.parse(argv);\n}\n\nprocess.on('unhandledRejection', (rejection: unknown) => {\n if (rejection instanceof Error) {\n exitWithError(rejection);\n } else {\n exitWithError(new Error(`Unknown rejection: '${rejection}'`));\n }\n});\n\nmain(process.argv).catch(exitWithError);\n"],"names":["chalk","findPaths","relativePath","plat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,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,GAAG,CAAC,CAAC;AACL,EAAEA,2BAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AACD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,SAAS,KAAK;AAChD,EAAE,IAAI,SAAS,YAAY,KAAK,EAAE;AAClC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7B,GAAG,MAAM;AACT,IAAI,aAAa,CAAC,IAAI,KAAK,CAAC,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,GAAG;AACH,CAAC,CAAC,CAAC;AACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/codemods.ts","../src/errors.ts","../src/action.ts","../src/index.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport interface Codemod {\n name: string;\n description: string;\n}\n\nexport const codemods: Codemod[] = [\n {\n name: 'core-imports',\n description:\n 'Updates @backstage/core imports to use @backstage/core-* imports instead.',\n },\n {\n name: 'extension-names',\n description:\n 'Adds a \"name\" property to all core extensions provided by plugins.',\n },\n];\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport chalk from 'chalk';\n\nexport class CustomError extends Error {\n get name(): string {\n return this.constructor.name;\n }\n}\n\nexport class ExitCodeError extends CustomError {\n readonly code: number;\n\n constructor(code: number, command?: string) {\n if (command) {\n super(`Command '${command}' exited with code ${code}`);\n } else {\n super(`Child exited with code ${code}`);\n }\n this.code = code;\n }\n}\n\nexport function exitWithError(error: Error): never {\n if (error instanceof ExitCodeError) {\n process.stderr.write(`\\n${chalk.red(error.message)}\\n\\n`);\n process.exit(error.code);\n } else {\n process.stderr.write(`\\n${chalk.red(`${error}`)}\\n\\n`);\n process.exit(1);\n }\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { relative as relativePath } from 'path';\nimport { spawn } from 'child_process';\nimport { OptionValues } from 'commander';\nimport { findPaths } from '@backstage/cli-common';\nimport { platform } from 'os';\nimport { ExitCodeError } from './errors';\n\n// eslint-disable-next-line no-restricted-syntax\nconst paths = findPaths(__dirname);\n\nexport function createCodemodAction(name: string) {\n return async (dirs: string[], opts: OptionValues) => {\n const transformPath = relativePath(\n process.cwd(),\n paths.resolveOwn('transforms', `${name}.js`),\n );\n\n const args = [\n '--parser=tsx',\n '--extensions=tsx,js,ts,tsx',\n '--transform',\n transformPath,\n '--ignore-pattern=**/node_modules/**',\n ];\n\n if (opts.dry) {\n args.push('--dry');\n }\n\n if (dirs.length) {\n args.push(...dirs);\n } else {\n args.push('.');\n }\n\n console.log(`Running jscodeshift with these arguments: ${args.join(' ')}`);\n\n let command;\n if (platform() === 'win32') {\n command = 'jscodeshift';\n } else {\n // jscodeshift ships a slightly broken bin script with windows\n // line endings so we need to execute it using node rather than\n // letting the `#!/usr/bin/env node` take care of it\n command = process.argv0;\n args.unshift(require.resolve('.bin/jscodeshift'));\n }\n\n const child = spawn(command, args, {\n stdio: 'inherit',\n shell: true,\n env: {\n ...process.env,\n FORCE_COLOR: 'true',\n },\n });\n\n if (typeof child.exitCode === 'number') {\n if (child.exitCode) {\n throw new ExitCodeError(child.exitCode, name);\n }\n return;\n }\n\n await new Promise<void>((resolve, reject) => {\n child.once('error', error => reject(error));\n child.once('exit', code => {\n if (code) {\n reject(new ExitCodeError(code, name));\n } else {\n resolve();\n }\n });\n });\n };\n}\n","/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/**\n * A collection of codemods for Backstage projects\n *\n * @packageDocumentation\n */\n\nimport { program } from 'commander';\nimport chalk from 'chalk';\nimport { codemods } from './codemods';\nimport { exitWithError } from './errors';\nimport { createCodemodAction } from './action';\nimport { version } from '../package.json';\n\nasync function main(argv: string[]) {\n program.name('backstage-codemods').version(version);\n\n const applyCommand = program\n .command('apply <codemod> [target-dirs...]')\n .description(\n 'Apply a codemod to target directories, defaulting to the current directory',\n );\n\n for (const codemod of codemods) {\n applyCommand\n .command(`${codemod.name} [target-dirs...]`)\n .description(codemod.description)\n .option('-d, --dry', 'Dry run, no changes written to files')\n .action(createCodemodAction(codemod.name));\n }\n\n program\n .command('list')\n .description('List available codemods')\n .action(() => {\n const maxNameLength = Math.max(...codemods.map(m => m.name.length));\n for (const codemod of codemods) {\n const paddedName = codemod.name.padEnd(maxNameLength, ' ');\n console.log(`${paddedName} - ${codemod.description}`);\n }\n });\n\n program.on('command:*', () => {\n console.log();\n console.log(chalk.red(`Invalid command: ${program.args.join(' ')}`));\n console.log();\n program.outputHelp();\n process.exit(1);\n });\n\n program.parse(argv);\n}\n\nprocess.on('unhandledRejection', (rejection: unknown) => {\n if (rejection instanceof Error) {\n exitWithError(rejection);\n } else {\n exitWithError(new Error(`Unknown rejection: '${rejection}'`));\n }\n});\n\nmain(process.argv).catch(exitWithError);\n"],"names":["chalk","findPaths","relativePath","platform","spawn","program"],"mappings":";;;;;;;;;;;;;AAAO,MAAM,QAAQ,GAAG;AACxB,EAAE;AACF,IAAI,IAAI,EAAE,cAAc;AACxB,IAAI,WAAW,EAAE,2EAA2E;AAC5F,GAAG;AACH,EAAE;AACF,IAAI,IAAI,EAAE,iBAAiB;AAC3B,IAAI,WAAW,EAAE,oEAAoE;AACrF,GAAG;AACH,CAAC;;ACRM,MAAM,WAAW,SAAS,KAAK,CAAC;AACvC,EAAE,IAAI,IAAI,GAAG;AACb,IAAI,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;AACjC,GAAG;AACH,CAAC;AACM,MAAM,aAAa,SAAS,WAAW,CAAC;AAC/C,EAAE,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE;AAC7B,IAAI,IAAI,OAAO,GAAG,CAAC,GAAG,IAAI,KAAK;AAC/B,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;AACrB,KAAK,CAAC;AACN,IAAI,IAAI,OAAO,EAAE;AACjB,MAAM,OAAO,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,KAAK,MAAM;AACX,MAAM,OAAO,CAAC,CAAC,uBAAuB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;AAChD,KAAK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AAC,GAAG,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;AAC5D,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAEA,iBAAO,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM;AAChC,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAClB,IAAI,OAAO,CAAC,GAAG,CAACL,yBAAK,CAAC,GAAG,CAAC,CAAC,iBAAiB,EAAEK,iBAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACzE,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;AAClB,IAAIA,iBAAO,CAAC,UAAU,EAAE,CAAC;AACzB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,GAAG,CAAC,CAAC;AACL,EAAEA,iBAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACtB,CAAC;AACD,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,SAAS,KAAK;AAChD,EAAE,IAAI,SAAS,YAAY,KAAK,EAAE;AAClC,IAAI,aAAa,CAAC,SAAS,CAAC,CAAC;AAC7B,GAAG,MAAM;AACT,IAAI,aAAa,CAAC,IAAI,KAAK,CAAC,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAClE,GAAG;AACH,CAAC,CAAC,CAAC;AACH,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC;;"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/codemods",
3
3
  "description": "A collection of codemods for Backstage projects",
4
- "version": "0.1.37",
4
+ "version": "0.1.38-next.0",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -42,7 +42,7 @@
42
42
  "devDependencies": {
43
43
  "@types/jscodeshift": "^0.11.0",
44
44
  "@types/node": "^16.11.26",
45
- "commander": "^6.1.0",
45
+ "commander": "^9.1.0",
46
46
  "ts-node": "^10.0.0"
47
47
  },
48
48
  "nodemonConfig": {
@@ -55,5 +55,5 @@
55
55
  "dist",
56
56
  "transforms"
57
57
  ],
58
- "gitHead": "e0e44c433319711c2fb8b175db411a621f7aaec2"
58
+ "gitHead": "88ee375f5ee44b7a7917297785ddf88691fe3381"
59
59
  }