Skip to content

Commit

Permalink
fix(cli): fix relative path codemod build from source (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
arybitskiy authored Aug 22, 2024
1 parent dab5b36 commit 388a8a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 4 additions & 5 deletions packages/runner/src/source-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];

Expand All @@ -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`);
Expand Down

0 comments on commit 388a8a2

Please sign in to comment.