Skip to content

Commit

Permalink
fix: add shouldCheckForExisting for getCodemodExecutable function at …
Browse files Browse the repository at this point in the history
…pacakges/runner/source-code.ts
  • Loading branch information
amirabbas-gh committed Dec 19, 2024
1 parent edd88bd commit c1df708
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/cli/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const handlePublishCliCommand = async (options: {
source,
esm,
codemodRc.engine,
false,
).catch(() => null);

if (builtExecutable === null) {
Expand Down
16 changes: 16 additions & 0 deletions packages/runner/src/source-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { getEntryPath, isJavaScriptName } from "@codemod-com/utilities";
import esbuild from "esbuild";
import { glob } from "glob";
import * as v from "valibot";

export type TransformFunction = (
Expand Down Expand Up @@ -183,7 +184,22 @@ export const getCodemodExecutable = async (
source: string,
esm?: boolean,
engine?: string,
shouldCheckForExisting = true,
) => {
if (shouldCheckForExisting) {
const existing = await glob(BUILT_SOURCE_GLOB, {
cwd: source,
absolute: true,
});

if (existing.length > 0) {
// biome-ignore lint: it exists
return await readFile(existing[0]!, { encoding: "utf8" }).catch(() => {
throw new Error(`Could not read ${existing[0]}`);
});
}
}

const { path: entryPoint } = await getEntryPath({
source,
throwOnNotFound: true,
Expand Down

0 comments on commit c1df708

Please sign in to comment.