Merge pull request #5992 from backstage/rugvip/mods

codemods: fixes for test and execution on Windows
This commit is contained in:
Patrik Oldsberg
2021-06-11 11:23:07 +02:00
committed by GitHub
4 changed files with 24 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/codemods': patch
---
Fix execution of `jscodeshift` on windows.
+4
View File
@@ -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:
+13 -2
View File
@@ -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: {
@@ -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', () => {