From 1498c47bc0dda17103367ed2ba0f4a127fb8ea0e Mon Sep 17 00:00:00 2001 From: void_malex Date: Thu, 18 Jul 2024 13:02:46 +0100 Subject: [PATCH] duplicate execute function to avoid an export from audit system --- packages/compat/src/audit/build.ts | 2 +- packages/compat/src/template-tag-codemod.ts | 51 ++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/packages/compat/src/audit/build.ts b/packages/compat/src/audit/build.ts index 8029be193..6db022770 100644 --- a/packages/compat/src/audit/build.ts +++ b/packages/compat/src/audit/build.ts @@ -28,7 +28,7 @@ export function isBuildError(err: any): err is BuildError { return err?.isBuildError; } -export async function execute( +async function execute( shellCommand: string, opts?: { env?: Record; pwd?: string } ): Promise<{ diff --git a/packages/compat/src/template-tag-codemod.ts b/packages/compat/src/template-tag-codemod.ts index d2a57315a..c930a1792 100644 --- a/packages/compat/src/template-tag-codemod.ts +++ b/packages/compat/src/template-tag-codemod.ts @@ -10,7 +10,7 @@ import { transformSync } from '@babel/core'; import { hbsToJS, ResolverLoader } from '@embroider/core'; import { ImportUtil } from 'babel-import-util'; import ResolverTransform from './resolver-transform'; -import { execute } from './audit/build'; +import { spawn } from 'child_process'; import { locateEmbroiderWorkingDir } from '@embroider/core'; export interface TemplateTagCodemodOptions { @@ -148,7 +148,6 @@ class TemplateTagCodemodPlugin extends Plugin { const backing_class_filename = 'filename' in backing_class_resolution ? backing_class_resolution.filename : ''; const backing_class_src = readFileSync(backing_class_filename).toString(); - // console.log(backing_class_src); const magic_string = '__MAGIC_STRING_FOR_TEMPLATE_TAG_REPLACE__'; const is_template_only = backing_class_src.indexOf("import templateOnlyComponent from '@ember/component/template-only';") !== -1; @@ -243,3 +242,51 @@ class TemplateTagCodemodPlugin extends Plugin { } } } + +async function execute( + shellCommand: string, + opts?: { env?: Record; pwd?: string } +): Promise<{ + exitCode: number; + stderr: string; + stdout: string; + output: string; +}> { + let env: Record | undefined; + if (opts?.env) { + env = { ...process.env, ...opts.env }; + } + let child = spawn(shellCommand, { + stdio: ['inherit', 'pipe', 'pipe'], + cwd: opts?.pwd, + shell: true, + env, + }); + let stderrBuffer: string[] = []; + let stdoutBuffer: string[] = []; + let combinedBuffer: string[] = []; + child.stderr.on('data', data => { + stderrBuffer.push(data); + combinedBuffer.push(data); + }); + child.stdout.on('data', data => { + stdoutBuffer.push(data); + combinedBuffer.push(data); + }); + return new Promise(resolve => { + child.on('close', (exitCode: number) => { + resolve({ + exitCode, + get stdout() { + return stdoutBuffer.join(''); + }, + get stderr() { + return stderrBuffer.join(''); + }, + get output() { + return combinedBuffer.join(''); + }, + }); + }); + }); +}