@backstage/codemods 0.1.48 → 0.1.49
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 +14 -0
- package/dist/index.cjs.js +9 -19
- package/dist/index.cjs.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @backstage/codemods
|
|
2
2
|
|
|
3
|
+
## 0.1.49
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/cli-common@0.1.14
|
|
9
|
+
|
|
10
|
+
## 0.1.49-next.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
- @backstage/cli-common@0.1.14-next.0
|
|
16
|
+
|
|
3
17
|
## 0.1.48
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.cjs.js
CHANGED
|
@@ -7,9 +7,9 @@ var child_process = require('child_process');
|
|
|
7
7
|
var cliCommon = require('@backstage/cli-common');
|
|
8
8
|
var os = require('os');
|
|
9
9
|
|
|
10
|
-
function
|
|
10
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
|
|
11
11
|
|
|
12
|
-
var chalk__default = /*#__PURE__*/
|
|
12
|
+
var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
13
13
|
|
|
14
14
|
const codemods = [
|
|
15
15
|
{
|
|
@@ -22,28 +22,18 @@ const codemods = [
|
|
|
22
22
|
}
|
|
23
23
|
];
|
|
24
24
|
|
|
25
|
-
var __defProp = Object.defineProperty;
|
|
26
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
-
var __publicField = (obj, key, value) => {
|
|
28
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
25
|
class CustomError extends Error {
|
|
32
26
|
get name() {
|
|
33
27
|
return this.constructor.name;
|
|
34
28
|
}
|
|
35
29
|
}
|
|
36
30
|
class ExitCodeError extends CustomError {
|
|
31
|
+
code;
|
|
37
32
|
constructor(code, command) {
|
|
38
|
-
var __super = (...args) => {
|
|
39
|
-
super(...args);
|
|
40
|
-
__publicField(this, "code");
|
|
41
|
-
return this;
|
|
42
|
-
};
|
|
43
33
|
if (command) {
|
|
44
|
-
|
|
34
|
+
super(`Command '${command}' exited with code ${code}`);
|
|
45
35
|
} else {
|
|
46
|
-
|
|
36
|
+
super(`Child exited with code ${code}`);
|
|
47
37
|
}
|
|
48
38
|
this.code = code;
|
|
49
39
|
}
|
|
@@ -51,13 +41,13 @@ class ExitCodeError extends CustomError {
|
|
|
51
41
|
function exitWithError(error) {
|
|
52
42
|
if (error instanceof ExitCodeError) {
|
|
53
43
|
process.stderr.write(`
|
|
54
|
-
${chalk__default
|
|
44
|
+
${chalk__default.default.red(error.message)}
|
|
55
45
|
|
|
56
46
|
`);
|
|
57
47
|
process.exit(error.code);
|
|
58
48
|
} else {
|
|
59
49
|
process.stderr.write(`
|
|
60
|
-
${chalk__default
|
|
50
|
+
${chalk__default.default.red(`${error}`)}
|
|
61
51
|
|
|
62
52
|
`);
|
|
63
53
|
process.exit(1);
|
|
@@ -121,7 +111,7 @@ function createCodemodAction(name) {
|
|
|
121
111
|
};
|
|
122
112
|
}
|
|
123
113
|
|
|
124
|
-
var version = "0.1.
|
|
114
|
+
var version = "0.1.49";
|
|
125
115
|
|
|
126
116
|
async function main(argv) {
|
|
127
117
|
commander.program.name("backstage-codemods").version(version);
|
|
@@ -140,7 +130,7 @@ async function main(argv) {
|
|
|
140
130
|
});
|
|
141
131
|
commander.program.on("command:*", () => {
|
|
142
132
|
console.log();
|
|
143
|
-
console.log(chalk__default
|
|
133
|
+
console.log(chalk__default.default.red(`Invalid command: ${commander.program.args.join(" ")}`));
|
|
144
134
|
console.log();
|
|
145
135
|
commander.program.outputHelp();
|
|
146
136
|
process.exit(1);
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -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 { 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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AA,iBAAA,CAAQ,UAAW,EAAA,CAAA;AACnB,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAAA,GACf,CAAA,CAAA;AAED,EAAAA,iBAAA,CAAQ,MAAM,IAAI,CAAA,CAAA;AACpB,CAAA;AAEA,OAAQ,CAAA,EAAA,CAAG,oBAAsB,EAAA,CAAC,SAAuB,KAAA;AACvD,EAAA,IAAI,qBAAqB,KAAO,EAAA;AAC9B,IAAA,aAAA,CAAc,SAAS,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAA,aAAA,CAAc,IAAI,KAAA,CAAM,CAAuB,oBAAA,EAAA,SAAS,GAAG,CAAC,CAAA,CAAA;AAAA,GAC9D;AACF,CAAC,CAAA,CAAA;AAED,IAAA,CAAK,OAAQ,CAAA,IAAI,CAAE,CAAA,KAAA,CAAM,aAAa,CAAA;;"}
|
|
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":";;;;;;;;;;;;;AAqBO,MAAM,QAAsB,GAAA;AAAA,EACjC;AAAA,IACE,IAAM,EAAA,cAAA;AAAA,IACN,WACE,EAAA,2EAAA;AAAA,GACJ;AAAA,EACA;AAAA,IACE,IAAM,EAAA,iBAAA;AAAA,IACN,WACE,EAAA,oEAAA;AAAA,GACJ;AACF,CAAA;;ACdO,MAAM,oBAAoB,KAAM,CAAA;AAAA,EACrC,IAAI,IAAe,GAAA;AACjB,IAAA,OAAO,KAAK,WAAY,CAAA,IAAA,CAAA;AAAA,GAC1B;AACF,CAAA;AAEO,MAAM,sBAAsB,WAAY,CAAA;AAAA,EACpC,IAAA,CAAA;AAAA,EAET,WAAA,CAAY,MAAc,OAAkB,EAAA;AAC1C,IAAA,IAAI,OAAS,EAAA;AACX,MAAA,KAAA,CAAM,CAAY,SAAA,EAAA,OAAO,CAAsB,mBAAA,EAAA,IAAI,CAAE,CAAA,CAAA,CAAA;AAAA,KAChD,MAAA;AACL,MAAM,KAAA,CAAA,CAAA,uBAAA,EAA0B,IAAI,CAAE,CAAA,CAAA,CAAA;AAAA,KACxC;AACA,IAAA,IAAA,CAAK,IAAO,GAAA,IAAA,CAAA;AAAA,GACd;AACF,CAAA;AAEO,SAA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Q,OAAA,CAAA,GAAA,CAAIL,sBAAM,CAAA,GAAA,CAAI,CAAoB,iBAAA,EAAAK,iBAAA,CAAQ,KAAK,IAAK,CAAA,GAAG,CAAC,CAAA,CAAE,CAAC,CAAA,CAAA;AACnE,IAAA,OAAA,CAAQ,GAAI,EAAA,CAAA;AACZ,IAAAA,iBAAA,CAAQ,UAAW,EAAA,CAAA;AACnB,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAAA,GACf,CAAA,CAAA;AAED,EAAAA,iBAAA,CAAQ,MAAM,IAAI,CAAA,CAAA;AACpB,CAAA;AAEA,OAAQ,CAAA,EAAA,CAAG,oBAAsB,EAAA,CAAC,SAAuB,KAAA;AACvD,EAAA,IAAI,qBAAqB,KAAO,EAAA;AAC9B,IAAA,aAAA,CAAc,SAAS,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAA,aAAA,CAAc,IAAI,KAAA,CAAM,CAAuB,oBAAA,EAAA,SAAS,GAAG,CAAC,CAAA,CAAA;AAAA,GAC9D;AACF,CAAC,CAAA,CAAA;AAED,IAAA,CAAK,OAAQ,CAAA,IAAI,CAAE,CAAA,KAAA,CAAM,aAAa,CAAA;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/codemods",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"description": "A collection of codemods for Backstage projects",
|
|
5
5
|
"backstage": {
|
|
6
6
|
"role": "cli"
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"watch": "./src"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@backstage/cli-common": "^0.1.
|
|
46
|
+
"@backstage/cli-common": "^0.1.14",
|
|
47
47
|
"chalk": "^4.0.0",
|
|
48
48
|
"commander": "^12.0.0",
|
|
49
49
|
"jscodeshift": "^0.15.0",
|
|
50
50
|
"jscodeshift-add-imports": "^1.0.10"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@backstage/cli": "^0.26.
|
|
53
|
+
"@backstage/cli": "^0.26.7",
|
|
54
54
|
"@types/jscodeshift": "^0.11.0",
|
|
55
55
|
"@types/node": "^18.17.8"
|
|
56
56
|
}
|