From 1aa630e1bcdfe234f38bec1f750e24ac9ab41d1b Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Mon, 8 May 2023 12:20:48 +0200 Subject: [PATCH] Add support for .fxrc.js --- npm/index.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/npm/index.js b/npm/index.js index e363263..02abd44 100644 --- a/npm/index.js +++ b/npm/index.js @@ -2,6 +2,7 @@ 'use strict' void async function main() { + const os = await import('node:os') const process = await import('node:process') let flagHelp = false let flagRaw = false @@ -16,7 +17,8 @@ void async function main() { } if (flagHelp || (args.length === 0 && process.stdin.isTTY)) return printUsage() - + await importFxrc(process.cwd()) + await importFxrc(os.homedir()) const stdin = await readStdinGenerator() const input = flagRaw ? readLine(stdin) : parseJson(stdin) if (flagSlurp) { @@ -535,6 +537,15 @@ function stringify(value, isPretty = false) { return stringifyValue(value) } +async function importFxrc(path) { + const {join} = await import('node:path') + try { + await import(join(path, '.fxrc.js')) + } catch (err) { + if (err.code !== 'ERR_MODULE_NOT_FOUND') throw err + } +} + function printUsage() { const usage = `Usage fx [flags] [code...]