Skip to content

Commit

Permalink
fix(forastro): get the current working directory instead of the modul…
Browse files Browse the repository at this point in the history
…e directory
  • Loading branch information
louiss0 committed Jan 23, 2025
1 parent 0002778 commit dc477fa
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions plugins/replaceValuesInExportsPlugin.cts
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,41 @@ module.exports = (

build.onEnd(() => {

const outFolder = build.initialOptions.outfile
.match(/^([\w/]+\/)/)?.[0];

const { outdir, outfile } = build.initialOptions


const outputDirectoryFromRoot = outdir ?? outfile.match(/^([a-z/]+\/).+/)[1]


if (!outputDirectoryFromRoot) {


throw Error(
"There is no output Directory make sure that esbuild has a outfile or a outdir property",
{ cause: "No Directory Path" }
)
}

let packageJsonPath;

if (__dirname === outFolder) {
const currentWorkingDirectory = process.cwd()

packageJsonPath = path.resolve(__dirname, "package.json");
if (currentWorkingDirectory === outputDirectoryFromRoot) {

packageJsonPath = path.resolve(currentWorkingDirectory, "package.json");

} else {

packageJsonPath =
path.resolve(__dirname, outFolder, 'package.json');
path.resolve(currentWorkingDirectory, outputDirectoryFromRoot, 'package.json');
}



if (!fs.existsSync(packageJsonPath)) {

throw Error(
`This file isn't in here ${outFolder}`,
`This file isn't in here ${outputDirectoryFromRoot}`,
{
cause: "Invalid Path"
}
Expand Down

0 comments on commit dc477fa

Please sign in to comment.