From 388a8a29833e80214987ce03b021e4a905bce205 Mon Sep 17 00:00:00 2001 From: Aleksy Date: Thu, 22 Aug 2024 23:44:01 +0100 Subject: [PATCH] fix(cli): fix relative path codemod build from source (#1274) --- apps/cli/package.json | 2 +- packages/runner/src/source-code.ts | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/apps/cli/package.json b/apps/cli/package.json index de6c257ba..ad0ffcd51 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -4,7 +4,7 @@ "imports": { "#*": "./src/*" }, - "version": "0.13.9", + "version": "0.13.10", "description": "A codemod engine for Node.js libraries (jscodeshift, ts-morph, etc.)", "type": "module", "exports": null, diff --git a/packages/runner/src/source-code.ts b/packages/runner/src/source-code.ts index 215346674..17593bd92 100644 --- a/packages/runner/src/source-code.ts +++ b/packages/runner/src/source-code.ts @@ -47,10 +47,7 @@ export const getTransformer = (source: string) => { export const BUILT_SOURCE_PATH = "cdmd_dist/index.cjs"; -export const bundleJS = async (options: { - entry: string; - output?: string; -}) => { +export const bundleJS = async (options: { entry: string; output?: string }) => { const { entry, output = join(dirname(entry), BUILT_SOURCE_PATH) } = options; const EXTERNAL_DEPENDENCIES = ["jscodeshift", "ts-morph", "@ast-grep/napi"]; @@ -71,7 +68,9 @@ export const bundleJS = async (options: { const { outputFiles } = await esbuild.build(buildOptions); const sourceCode = - outputFiles?.find((file) => file.path.endsWith(output))?.text ?? null; + outputFiles?.find((file) => + file.path.endsWith(output.replace(/\.\.\//g, "").replace(/\.\//g, "")), + )?.text ?? null; if (sourceCode === null) { throw new Error(`Could not find ${output} in output files`);