From aa204e01e9fca037eedfd10ceb6c26f4ee5a08ba Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 10 Jun 2021 15:16:59 +0200 Subject: [PATCH 1/2] codemods,workflows: fix codemods tests on windows Signed-off-by: Patrik Oldsberg --- .github/workflows/master-win.yml | 4 ++++ packages/codemods/src/tests/core-imports.test.ts | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/master-win.yml b/.github/workflows/master-win.yml index 3850146388..c61ee4798b 100644 --- a/.github/workflows/master-win.yml +++ b/.github/workflows/master-win.yml @@ -53,6 +53,10 @@ jobs: - name: verify type dependencies run: yarn lint:type-deps + # The core packages need to be built for the codemods tests to work + - name: build core packages + run: lerna run --scope @backstage/core-* build + - name: test run: yarn lerna -- run test env: diff --git a/packages/codemods/src/tests/core-imports.test.ts b/packages/codemods/src/tests/core-imports.test.ts index 90bc217d3e..e5924156b6 100644 --- a/packages/codemods/src/tests/core-imports.test.ts +++ b/packages/codemods/src/tests/core-imports.test.ts @@ -25,7 +25,8 @@ function runTransform(source: string) { stats: () => undefined, report: () => undefined, }; - return coreImportTransform({ source, file: 'test.ts' }, api); + const result = coreImportTransform({ source, file: 'test.ts' }, api); + return result?.split('\r\n').join('\n'); } describe('core-imports', () => { From 59752e1037194372db1e69fa8af792f8793d7208 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 10 Jun 2021 15:18:09 +0200 Subject: [PATCH 2/2] codemods: fix execution of jscodeshift on windows Signed-off-by: Patrik Oldsberg --- .changeset/funny-toys-talk.md | 5 +++++ packages/codemods/src/action.ts | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 .changeset/funny-toys-talk.md diff --git a/.changeset/funny-toys-talk.md b/.changeset/funny-toys-talk.md new file mode 100644 index 0000000000..6e6a779ab8 --- /dev/null +++ b/.changeset/funny-toys-talk.md @@ -0,0 +1,5 @@ +--- +'@backstage/codemods': patch +--- + +Fix execution of `jscodeshift` on windows. diff --git a/packages/codemods/src/action.ts b/packages/codemods/src/action.ts index 46e50ead77..c3eba8aecc 100644 --- a/packages/codemods/src/action.ts +++ b/packages/codemods/src/action.ts @@ -18,6 +18,7 @@ import { relative as relativePath } from 'path'; import { spawn } from 'child_process'; import { Command } from 'commander'; import { findPaths } from '@backstage/cli-common'; +import { platform } from 'os'; import { ExitCodeError } from './errors'; // eslint-disable-next-line no-restricted-syntax @@ -50,8 +51,18 @@ export function createCodemodAction(name: string) { console.log(`Running jscodeshift with these arguments: ${args.join(' ')}`); - const jscodeshiftScript = require.resolve('.bin/jscodeshift'); - const child = spawn(process.argv0, [jscodeshiftScript, ...args], { + let command; + if (platform() === 'win32') { + command = 'jscodeshift'; + } else { + // jscodeshift ships a slightly broken bin script with windows + // line endings so we need to execute it using node rather than + // letting the `#!/usr/bin/env node` take care of it + command = process.argv0; + args.unshift(require.resolve('.bin/jscodeshift')); + } + + const child = spawn(command, args, { stdio: 'inherit', shell: true, env: {