Skip to content

Commit

Permalink
remove find-up (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
forgetso authored Sep 12, 2024
1 parent 7a24598 commit 130c70e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 99 deletions.
92 changes: 1 addition & 91 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions packages/dotenv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@
},
"types": "./dist/index.d.ts",
"dependencies": {
"dotenv": "^16.0.1",
"find-up": "^7.0.0",
"unicorn-magic": "^0.1.0"
"dotenv": "^16.0.1"
},
"devDependencies": {
"tslib": "2.6.2",
Expand Down
38 changes: 33 additions & 5 deletions packages/dotenv/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { LogLevel, getLogger } from "@prosopo/common";
import dotenv from "dotenv";
import { findUpSync } from "find-up";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
Expand Down Expand Up @@ -59,8 +59,36 @@ export function getEnvFile(
const env = getEnv();
const fileNameFull = `${filename}.${env}`;

return (
findUpSync(fileNameFull, { type: "file" }) ||
path.join(rootDir || filepath, fileNameFull)
);
let searchPath = path.resolve(rootDir || ".");

logger.info(`Searching for ${fileNameFull} in ${searchPath}`);

let levelCount = 0;

while (!fs.existsSync(path.join(searchPath, fileNameFull))) {
if (fs.existsSync(path.join(searchPath, "package.json"))) {
const pkgJson = JSON.parse(
fs.readFileSync(path.join(searchPath, "package.json"), "utf8"),
);
if (pkgJson.name === "@prosopo/captcha-private") {
logger.info(
`Reached the workspace root package.json, stopping search for ${fileNameFull}.`,
);
break;
}
}
searchPath = path.resolve(searchPath, "..");
levelCount += 1;
if (levelCount > 10) {
logger.error(
`Checked ${levelCount} directories above, stopping search for ${fileNameFull}.`,
);
break;
}
}

const foundPath = path.join(searchPath, fileNameFull);
return fs.existsSync(foundPath)
? foundPath
: path.join(rootDir || filepath, fileNameFull);
}

0 comments on commit 130c70e

Please sign in to comment.