Skip to content

Commit

Permalink
fix(js): output file name
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed Jun 16, 2023
1 parent e74c18b commit cb63166
Showing 1 changed file with 3 additions and 39 deletions.
42 changes: 3 additions & 39 deletions packages/js/src/executors/node/node.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,10 @@ export async function* nodeExecutor(
// Re-map buildable workspace projects to their output directory.
const mappings = calculateResolveMappings(context, options);

const outputFileNameWithoutExtension =
buildOptions.outputFileName ?? path.parse(buildOptions.main).name;

const fileToRun = getOutputFilePath(
context.root,
buildOptions.outputPath,
outputFileNameWithoutExtension
);
const outputFileName =
buildOptions.outputFileName ?? `${path.parse(buildOptions.main).name}.js`;

const fileToRun = join(context.root, buildOptions.outputPath, outputFileName);
const tasks: ActiveTask[] = [];
let currentTask: ActiveTask = null;

Expand Down Expand Up @@ -311,35 +306,4 @@ function runWaitUntilTargets(
);
}

function getOutputFilePath(
root: string,
outputPath: string,
outputFileNameWithoutExtension: string
): string {
const possibleExtensions = ['.js', '.cjs', '.mjs'];
let fullPath: string | undefined = undefined;

for (const extension of possibleExtensions) {
const filePath = join(
root,
outputPath,
`${outputFileNameWithoutExtension}${extension}`
);

if (fileExists(filePath)) {
fullPath = filePath;
break;
}
}

if (!fullPath) {
throw new Error(
`Could not find any output files for ${outputFileNameWithoutExtension} in ${outputPath},
please try building the project first, or make sure your build ran correctly.`
);
}

return fullPath;
}

export default nodeExecutor;

0 comments on commit cb63166

Please sign in to comment.