@backstage/codemods 0.1.38 → 0.1.39-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 +7 -0
- package/dist/index.cjs.js +8 -3
- package/dist/index.cjs.js.map +1 -1
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -59,7 +59,10 @@ ${chalk__default["default"].red(`${error}`)}
|
|
|
59
59
|
const paths = cliCommon.findPaths(__dirname);
|
|
60
60
|
function createCodemodAction(name) {
|
|
61
61
|
return async (dirs, opts) => {
|
|
62
|
-
const transformPath = path.relative(
|
|
62
|
+
const transformPath = path.relative(
|
|
63
|
+
process.cwd(),
|
|
64
|
+
paths.resolveOwn("transforms", `${name}.js`)
|
|
65
|
+
);
|
|
63
66
|
const args = [
|
|
64
67
|
"--parser=tsx",
|
|
65
68
|
"--extensions=tsx,js,ts,tsx",
|
|
@@ -110,11 +113,13 @@ function createCodemodAction(name) {
|
|
|
110
113
|
};
|
|
111
114
|
}
|
|
112
115
|
|
|
113
|
-
var version = "0.1.
|
|
116
|
+
var version = "0.1.39-next.0";
|
|
114
117
|
|
|
115
118
|
async function main(argv) {
|
|
116
119
|
commander.program.name("backstage-codemods").version(version);
|
|
117
|
-
const applyCommand = commander.program.command("apply <codemod> [target-dirs...]").description(
|
|
120
|
+
const applyCommand = commander.program.command("apply <codemod> [target-dirs...]").description(
|
|
121
|
+
"Apply a codemod to target directories, defaulting to the current directory"
|
|
122
|
+
);
|
|
118
123
|
for (const codemod of codemods) {
|
|
119
124
|
applyCommand.command(`${codemod.name} [target-dirs...]`).description(codemod.description).option("-d, --dry", "Dry run, no changes written to files").action(createCodemodAction(codemod.name));
|
|
120
125
|
}
|
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 }\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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C,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":";;;;;;;;;;;;;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,EAG7C,WAAA,CAAY,MAAc,OAAkB,EAAA;AAAA,IAAA,IAAA,OAAA,GAAA,CAAA,GAAA,IAAA,KAAA;AAAA,MAAA,KAAA,CAAA,GAAA,IAAA,CAAA,CAAA;AAAA,KAAA,CAAA;AAC1C,IAAA,IAAI,OAAS,EAAA;AACX,MAAM,OAAA,CAAA,CAAA,SAAA,EAAY,6BAA6B,IAAM,CAAA,CAAA,CAAA,CAAA;AAAA,KAChD,MAAA;AACL,MAAA,OAAA,CAAM,0BAA0B,IAAM,CAAA,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,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0BAAM,GAAI,CAAA,CAAA,iBAAA,EAAoBK,kBAAQ,IAAK,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA,CAAG,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,SAAA,CAAA,CAAA,CAAY,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,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backstage/codemods",
|
|
3
3
|
"description": "A collection of codemods for Backstage projects",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"private": false,
|
|
4
|
+
"version": "0.1.39-next.0",
|
|
6
5
|
"publishConfig": {
|
|
7
6
|
"access": "public",
|
|
8
7
|
"main": "dist/index.cjs.js"
|
|
@@ -26,20 +25,21 @@
|
|
|
26
25
|
"build": "backstage-cli package build",
|
|
27
26
|
"lint": "backstage-cli package lint",
|
|
28
27
|
"test": "backstage-cli package test",
|
|
29
|
-
"prepack": "backstage-cli prepack",
|
|
30
|
-
"postpack": "backstage-cli postpack",
|
|
28
|
+
"prepack": "backstage-cli package prepack",
|
|
29
|
+
"postpack": "backstage-cli package postpack",
|
|
31
30
|
"clean": "backstage-cli package clean"
|
|
32
31
|
},
|
|
33
32
|
"bin": {
|
|
34
33
|
"backstage-codemods": "bin/backstage-codemods"
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@backstage/cli-common": "^0.1.
|
|
36
|
+
"@backstage/cli-common": "^0.1.10-next.0",
|
|
38
37
|
"chalk": "^4.0.0",
|
|
39
38
|
"jscodeshift": "^0.13.0",
|
|
40
39
|
"jscodeshift-add-imports": "^1.0.10"
|
|
41
40
|
},
|
|
42
41
|
"devDependencies": {
|
|
42
|
+
"@backstage/cli": "^0.19.0-next.3",
|
|
43
43
|
"@types/jscodeshift": "^0.11.0",
|
|
44
44
|
"@types/node": "^16.11.26",
|
|
45
45
|
"commander": "^9.1.0",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"dist",
|
|
56
56
|
"transforms"
|
|
57
57
|
],
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "2f458448f850dc68a711e2f31d14a91f96cf175d"
|
|
59
59
|
}
|