@backstage/codemods 0.1.50 → 0.1.51

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,13 @@
1
1
  # @backstage/codemods
2
2
 
3
+ ## 0.1.51
4
+
5
+ ### Patch Changes
6
+
7
+ - c06b7f1: Updated dependency `@types/jscodeshift` to `^0.12.0`.
8
+ - Updated dependencies
9
+ - @backstage/cli-common@0.1.14
10
+
3
11
  ## 0.1.50
4
12
 
5
13
  ### Patch Changes
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ var path = require('path');
4
+ var child_process = require('child_process');
5
+ var cliCommon = require('@backstage/cli-common');
6
+ var os = require('os');
7
+ var errors = require('./errors.cjs.js');
8
+
9
+ const paths = cliCommon.findPaths(__dirname);
10
+ function createCodemodAction(name) {
11
+ return async (dirs, opts) => {
12
+ const transformPath = path.relative(
13
+ process.cwd(),
14
+ paths.resolveOwn("transforms", `${name}.js`)
15
+ );
16
+ const args = [
17
+ "--parser=tsx",
18
+ "--extensions=tsx,js,ts,tsx",
19
+ "--transform",
20
+ transformPath,
21
+ "--ignore-pattern=**/node_modules/**"
22
+ ];
23
+ if (opts.dry) {
24
+ args.push("--dry");
25
+ }
26
+ if (dirs.length) {
27
+ args.push(...dirs);
28
+ } else {
29
+ args.push(".");
30
+ }
31
+ console.log(`Running jscodeshift with these arguments: ${args.join(" ")}`);
32
+ let command;
33
+ if (os.platform() === "win32") {
34
+ command = "jscodeshift";
35
+ } else {
36
+ command = process.argv0;
37
+ args.unshift(require.resolve(".bin/jscodeshift"));
38
+ }
39
+ const child = child_process.spawn(command, args, {
40
+ stdio: "inherit",
41
+ shell: true,
42
+ env: {
43
+ ...process.env,
44
+ FORCE_COLOR: "true"
45
+ }
46
+ });
47
+ if (typeof child.exitCode === "number") {
48
+ if (child.exitCode) {
49
+ throw new errors.ExitCodeError(child.exitCode, name);
50
+ }
51
+ return;
52
+ }
53
+ await new Promise((resolve, reject) => {
54
+ child.once("error", (error) => reject(error));
55
+ child.once("exit", (code) => {
56
+ if (code) {
57
+ reject(new errors.ExitCodeError(code, name));
58
+ } else {
59
+ resolve();
60
+ }
61
+ });
62
+ });
63
+ };
64
+ }
65
+
66
+ exports.createCodemodAction = createCodemodAction;
67
+ //# sourceMappingURL=action.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.cjs.js","sources":["../src/action.ts"],"sourcesContent":["/*\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"],"names":["findPaths","relativePath","platform","spawn","ExitCodeError"],"mappings":";;;;;;;;AAwBA,MAAM,KAAA,GAAQA,oBAAU,SAAS,CAAA,CAAA;AAE1B,SAAS,oBAAoB,IAAc,EAAA;AAChD,EAAO,OAAA,OAAO,MAAgB,IAAuB,KAAA;AACnD,IAAA,MAAM,aAAgB,GAAAC,aAAA;AAAA,MACpB,QAAQ,GAAI,EAAA;AAAA,MACZ,KAAM,CAAA,UAAA,CAAW,YAAc,EAAA,CAAA,EAAG,IAAI,CAAK,GAAA,CAAA,CAAA;AAAA,KAC7C,CAAA;AAEA,IAAA,MAAM,IAAO,GAAA;AAAA,MACX,cAAA;AAAA,MACA,4BAAA;AAAA,MACA,aAAA;AAAA,MACA,aAAA;AAAA,MACA,qCAAA;AAAA,KACF,CAAA;AAEA,IAAA,IAAI,KAAK,GAAK,EAAA;AACZ,MAAA,IAAA,CAAK,KAAK,OAAO,CAAA,CAAA;AAAA,KACnB;AAEA,IAAA,IAAI,KAAK,MAAQ,EAAA;AACf,MAAK,IAAA,CAAA,IAAA,CAAK,GAAG,IAAI,CAAA,CAAA;AAAA,KACZ,MAAA;AACL,MAAA,IAAA,CAAK,KAAK,GAAG,CAAA,CAAA;AAAA,KACf;AAEA,IAAA,OAAA,CAAQ,IAAI,CAA6C,0CAAA,EAAA,IAAA,CAAK,IAAK,CAAA,GAAG,CAAC,CAAE,CAAA,CAAA,CAAA;AAEzE,IAAI,IAAA,OAAA,CAAA;AACJ,IAA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
4
+ {
5
+ name: "core-imports",
6
+ description: "Updates @backstage/core imports to use @backstage/core-* imports instead."
7
+ },
8
+ {
9
+ name: "extension-names",
10
+ description: 'Adds a "name" property to all core extensions provided by plugins.'
11
+ }
12
+ ];
13
+
14
+ exports.codemods = codemods;
15
+ //# sourceMappingURL=codemods.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"codemods.cjs.js","sources":["../src/codemods.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"],"names":[],"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;;;;"}
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ var chalk = require('chalk');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
6
+
7
+ var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
8
+
9
+ class CustomError extends Error {
10
+ get name() {
11
+ return this.constructor.name;
12
+ }
13
+ }
14
+ class ExitCodeError extends CustomError {
15
+ code;
16
+ constructor(code, command) {
17
+ if (command) {
18
+ super(`Command '${command}' exited with code ${code}`);
19
+ } else {
20
+ super(`Child exited with code ${code}`);
21
+ }
22
+ this.code = code;
23
+ }
24
+ }
25
+ function exitWithError(error) {
26
+ if (error instanceof ExitCodeError) {
27
+ process.stderr.write(`
28
+ ${chalk__default.default.red(error.message)}
29
+
30
+ `);
31
+ process.exit(error.code);
32
+ } else {
33
+ process.stderr.write(`
34
+ ${chalk__default.default.red(`${error}`)}
35
+
36
+ `);
37
+ process.exit(1);
38
+ }
39
+ }
40
+
41
+ exports.CustomError = CustomError;
42
+ exports.ExitCodeError = ExitCodeError;
43
+ exports.exitWithError = exitWithError;
44
+ //# sourceMappingURL=errors.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs.js","sources":["../src/errors.ts"],"sourcesContent":["/*\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"],"names":["chalk"],"mappings":";;;;;;;;AAkBO,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,SAAS,cAAc,KAAqB,EAAA;AACjD,EAAA,IAAI,iBAAiB,aAAe,EAAA;AAClC,IAAA,OAAA,CAAQ,OAAO,KAAM,CAAA,CAAA;AAAA,EAAKA,sBAAM,CAAA,GAAA,CAAI,KAAM,CAAA,OAAO,CAAC,CAAA;AAAA;AAAA,CAAM,CAAA,CAAA;AACxD,IAAQ,OAAA,CAAA,IAAA,CAAK,MAAM,IAAI,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAA,OAAA,CAAQ,OAAO,KAAM,CAAA,CAAA;AAAA,EAAKA,sBAAM,CAAA,GAAA,CAAI,CAAG,EAAA,KAAK,EAAE,CAAC,CAAA;AAAA;AAAA,CAAM,CAAA,CAAA;AACrD,IAAA,OAAA,CAAQ,KAAK,CAAC,CAAA,CAAA;AAAA,GAChB;AACF;;;;;;"}
package/dist/index.cjs.js CHANGED
@@ -2,128 +2,26 @@
2
2
 
3
3
  var commander = require('commander');
4
4
  var chalk = require('chalk');
5
- var path = require('path');
6
- var child_process = require('child_process');
7
- var cliCommon = require('@backstage/cli-common');
8
- var os = require('os');
5
+ var codemods = require('./codemods.cjs.js');
6
+ var errors = require('./errors.cjs.js');
7
+ var action = require('./action.cjs.js');
8
+ var _package = require('./package.json.cjs.js');
9
9
 
10
10
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
11
 
12
12
  var chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
13
13
 
14
- const codemods = [
15
- {
16
- name: "core-imports",
17
- description: "Updates @backstage/core imports to use @backstage/core-* imports instead."
18
- },
19
- {
20
- name: "extension-names",
21
- description: 'Adds a "name" property to all core extensions provided by plugins.'
22
- }
23
- ];
24
-
25
- class CustomError extends Error {
26
- get name() {
27
- return this.constructor.name;
28
- }
29
- }
30
- class ExitCodeError extends CustomError {
31
- code;
32
- constructor(code, command) {
33
- if (command) {
34
- super(`Command '${command}' exited with code ${code}`);
35
- } else {
36
- super(`Child exited with code ${code}`);
37
- }
38
- this.code = code;
39
- }
40
- }
41
- function exitWithError(error) {
42
- if (error instanceof ExitCodeError) {
43
- process.stderr.write(`
44
- ${chalk__default.default.red(error.message)}
45
-
46
- `);
47
- process.exit(error.code);
48
- } else {
49
- process.stderr.write(`
50
- ${chalk__default.default.red(`${error}`)}
51
-
52
- `);
53
- process.exit(1);
54
- }
55
- }
56
-
57
- const paths = cliCommon.findPaths(__dirname);
58
- function createCodemodAction(name) {
59
- return async (dirs, opts) => {
60
- const transformPath = path.relative(
61
- process.cwd(),
62
- paths.resolveOwn("transforms", `${name}.js`)
63
- );
64
- const args = [
65
- "--parser=tsx",
66
- "--extensions=tsx,js,ts,tsx",
67
- "--transform",
68
- transformPath,
69
- "--ignore-pattern=**/node_modules/**"
70
- ];
71
- if (opts.dry) {
72
- args.push("--dry");
73
- }
74
- if (dirs.length) {
75
- args.push(...dirs);
76
- } else {
77
- args.push(".");
78
- }
79
- console.log(`Running jscodeshift with these arguments: ${args.join(" ")}`);
80
- let command;
81
- if (os.platform() === "win32") {
82
- command = "jscodeshift";
83
- } else {
84
- command = process.argv0;
85
- args.unshift(require.resolve(".bin/jscodeshift"));
86
- }
87
- const child = child_process.spawn(command, args, {
88
- stdio: "inherit",
89
- shell: true,
90
- env: {
91
- ...process.env,
92
- FORCE_COLOR: "true"
93
- }
94
- });
95
- if (typeof child.exitCode === "number") {
96
- if (child.exitCode) {
97
- throw new ExitCodeError(child.exitCode, name);
98
- }
99
- return;
100
- }
101
- await new Promise((resolve, reject) => {
102
- child.once("error", (error) => reject(error));
103
- child.once("exit", (code) => {
104
- if (code) {
105
- reject(new ExitCodeError(code, name));
106
- } else {
107
- resolve();
108
- }
109
- });
110
- });
111
- };
112
- }
113
-
114
- var version = "0.1.50";
115
-
116
14
  async function main(argv) {
117
- commander.program.name("backstage-codemods").version(version);
15
+ commander.program.name("backstage-codemods").version(_package.version);
118
16
  const applyCommand = commander.program.command("apply <codemod> [target-dirs...]").description(
119
17
  "Apply a codemod to target directories, defaulting to the current directory"
120
18
  );
121
- for (const codemod of codemods) {
122
- applyCommand.command(`${codemod.name} [target-dirs...]`).description(codemod.description).option("-d, --dry", "Dry run, no changes written to files").action(createCodemodAction(codemod.name));
19
+ for (const codemod of codemods.codemods) {
20
+ applyCommand.command(`${codemod.name} [target-dirs...]`).description(codemod.description).option("-d, --dry", "Dry run, no changes written to files").action(action.createCodemodAction(codemod.name));
123
21
  }
124
22
  commander.program.command("list").description("List available codemods").action(() => {
125
- const maxNameLength = Math.max(...codemods.map((m) => m.name.length));
126
- for (const codemod of codemods) {
23
+ const maxNameLength = Math.max(...codemods.codemods.map((m) => m.name.length));
24
+ for (const codemod of codemods.codemods) {
127
25
  const paddedName = codemod.name.padEnd(maxNameLength, " ");
128
26
  console.log(`${paddedName} - ${codemod.description}`);
129
27
  }
@@ -139,10 +37,10 @@ async function main(argv) {
139
37
  }
140
38
  process.on("unhandledRejection", (rejection) => {
141
39
  if (rejection instanceof Error) {
142
- exitWithError(rejection);
40
+ errors.exitWithError(rejection);
143
41
  } else {
144
- exitWithError(new Error(`Unknown rejection: '${rejection}'`));
42
+ errors.exitWithError(new Error(`Unknown rejection: '${rejection}'`));
145
43
  }
146
44
  });
147
- main(process.argv).catch(exitWithError);
45
+ main(process.argv).catch(errors.exitWithError);
148
46
  //# sourceMappingURL=index.cjs.js.map
@@ -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 }\n});\n\n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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/index.ts"],"sourcesContent":["/*\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":["program","version","codemods","createCodemodAction","chalk","exitWithError"],"mappings":";;;;;;;;;;;;;AA6BA,eAAe,KAAK,IAAgB,EAAA;AAClC,EAAAA,iBAAA,CAAQ,IAAK,CAAA,oBAAoB,CAAE,CAAA,OAAA,CAAQC,gBAAO,CAAA,CAAA;AAElD,EAAA,MAAM,YAAe,GAAAD,iBAAA,CAClB,OAAQ,CAAA,kCAAkC,CAC1C,CAAA,WAAA;AAAA,IACC,4EAAA;AAAA,GACF,CAAA;AAEF,EAAA,KAAA,MAAW,WAAWE,iBAAU,EAAA;AAC9B,IAAA,YAAA,CACG,QAAQ,CAAG,EAAA,OAAA,CAAQ,IAAI,CAAmB,iBAAA,CAAA,CAAA,CAC1C,YAAY,OAAQ,CAAA,WAAW,CAC/B,CAAA,MAAA,CAAO,aAAa,sCAAsC,CAAA,CAC1D,OAAOC,0BAAoB,CAAA,OAAA,CAAQ,IAAI,CAAC,CAAA,CAAA;AAAA,GAC7C;AAEA,EAAAH,iBAAA,CACG,QAAQ,MAAM,CAAA,CACd,YAAY,yBAAyB,CAAA,CACrC,OAAO,MAAM;AACZ,IAAM,MAAA,aAAA,GAAgB,IAAK,CAAA,GAAA,CAAI,GAAGE,iBAAA,CAAS,IAAI,CAAK,CAAA,KAAA,CAAA,CAAE,IAAK,CAAA,MAAM,CAAC,CAAA,CAAA;AAClE,IAAA,KAAA,MAAW,WAAWA,iBAAU,EAAA;AAC9B,MAAA,MAAM,UAAa,GAAA,OAAA,CAAQ,IAAK,CAAA,MAAA,CAAO,eAAe,GAAG,CAAA,CAAA;AACzD,MAAA,OAAA,CAAQ,IAAI,CAAG,EAAA,UAAU,CAAM,GAAA,EAAA,OAAA,CAAQ,WAAW,CAAE,CAAA,CAAA,CAAA;AAAA,KACtD;AAAA,GACD,CAAA,CAAA;AAEH,EAAQF,iBAAA,CAAA,EAAA,CAAG,aAAa,MAAM;AAC5B,IAAA,OAAA,CAAQ,GAAI,EAAA,CAAA;AACZ,IAAQ,OAAA,CAAA,GAAA,CAAII,sBAAM,CAAA,GAAA,CAAI,CAAoB,iBAAA,EAAAJ,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,IAAAK,oBAAA,CAAc,SAAS,CAAA,CAAA;AAAA,GAClB,MAAA;AACL,IAAAA,oBAAA,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,CAAMA,oBAAa,CAAA;;"}
@@ -0,0 +1,6 @@
1
+ 'use strict';
2
+
3
+ var version = "0.1.51";
4
+
5
+ exports.version = version;
6
+ //# sourceMappingURL=package.json.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.json.cjs.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/codemods",
3
- "version": "0.1.50",
3
+ "version": "0.1.51",
4
4
  "description": "A collection of codemods for Backstage projects",
5
5
  "backstage": {
6
6
  "role": "cli"
@@ -50,8 +50,8 @@
50
50
  "jscodeshift-add-imports": "^1.0.10"
51
51
  },
52
52
  "devDependencies": {
53
- "@backstage/cli": "^0.27.1",
54
- "@types/jscodeshift": "^0.11.0",
53
+ "@backstage/cli": "^0.28.0",
54
+ "@types/jscodeshift": "^0.12.0",
55
55
  "@types/node": "^18.17.8"
56
56
  }
57
57
  }