Skip to content

Commit

Permalink
feat: add support for config files with ".cjs" extension (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay authored Mar 16, 2023
1 parent 30fcc0c commit 3682f12
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 87 deletions.
5 changes: 1 addition & 4 deletions packages/mysql-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"dependencies": {
"cosmiconfig": "^5.0.7",
"cosmiconfig": "^8.1.0",
"funtypes": "^4.1.0"
},
"devDependencies": {
"@types/cosmiconfig": "^5.0.3"
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/atdatabases/tree/master/packages/mysql-config",
"bugs": "https://github.com/ForbesLindesay/atdatabases/issues",
Expand Down
14 changes: 8 additions & 6 deletions packages/mysql-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import cosmiconfig = require('cosmiconfig');
import {cosmiconfig, cosmiconfigSync} from 'cosmiconfig';
import MySqlConfig, {MySqlConfigSchema} from './MySqlConfig';

const explorer = cosmiconfig('mysql');
const asyncExplorer = cosmiconfig('mysql');
const syncExplorer = cosmiconfigSync('mysql');

export async function getMySqlConfig(
searchFrom?: string,
): Promise<MySqlConfig> {
return parseResult(await explorer.search(searchFrom));
return parseResult(await asyncExplorer.search(searchFrom));
}
export function getMySqlConfigSync(searchFrom?: string): MySqlConfig {
return parseResult(explorer.searchSync(searchFrom));
return parseResult(syncExplorer.search(searchFrom));
}

export function readMySqlConfigSync(filename: string): MySqlConfig {
return parseResult(explorer.loadSync(filename));
return parseResult(syncExplorer.load(filename));
}

function parseResult(result: cosmiconfig.CosmiconfigResult): MySqlConfig {
function parseResult(result: null | {config: unknown}): MySqlConfig {
return MySqlConfigSchema.parse(result ? result.config : {});
}

Expand Down
5 changes: 1 addition & 4 deletions packages/pg-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"dependencies": {
"cosmiconfig": "^5.0.7",
"cosmiconfig": "^8.1.0",
"funtypes": "^4.1.0"
},
"devDependencies": {
"@types/cosmiconfig": "^5.0.3"
},
"scripts": {},
"repository": "https://github.com/ForbesLindesay/atdatabases/tree/master/packages/pg-config",
"bugs": "https://github.com/ForbesLindesay/atdatabases/issues",
Expand Down
13 changes: 7 additions & 6 deletions packages/pg-config/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import cosmiconfig = require('cosmiconfig');
import {cosmiconfig, cosmiconfigSync} from 'cosmiconfig';
import PgConfig, {PgConfigSchema} from './PgConfig';

const explorer = cosmiconfig('pg');
const asyncExplorer = cosmiconfig('pg');
const syncExplorer = cosmiconfigSync('pg');
export async function getPgConfig(searchFrom?: string): Promise<PgConfig> {
return parseResult(await explorer.search(searchFrom));
return parseResult(await asyncExplorer.search(searchFrom));
}
export function getPgConfigSync(searchFrom?: string): PgConfig {
return parseResult(explorer.searchSync(searchFrom));
return parseResult(syncExplorer.search(searchFrom));
}

export function readPgConfigSync(filename: string): PgConfig {
return parseResult(explorer.loadSync(filename));
return parseResult(syncExplorer.load(filename));
}

function parseResult(result: cosmiconfig.CosmiconfigResult): PgConfig {
function parseResult(result: null | {config: unknown}): PgConfig {
return PgConfigSchema.parse(result ? result.config : {});
}

Expand Down
1 change: 1 addition & 0 deletions scripts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{"path": "../packages/bigquery"},
{"path": "../packages/cache"},
{"path": "../packages/connection-pool"},
{"path": "../packages/dataloader"},
{"path": "../packages/escape-identifier"},
{"path": "../packages/expo"},
{"path": "../packages/lock"},
Expand Down
89 changes: 22 additions & 67 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1709,13 +1709,6 @@
dependencies:
camelcase "*"

"@types/cosmiconfig@^5.0.3":
version "5.0.3"
resolved "https://registry.yarnpkg.com/@types/cosmiconfig/-/cosmiconfig-5.0.3.tgz#880644bb155d4038d3b752159684b777b0a159dd"
integrity sha512-HgTGG7X5y9pLl3pixeo2XtDEFD8rq2EuH+S4mK6teCnAwWMucQl6v1D43hI4Uw1VJh6nu59lxLkqXHRl4uwThA==
dependencies:
"@types/node" "*"

"@types/cross-spawn@^6.0.0":
version "6.0.2"
resolved "https://registry.yarnpkg.com/@types/cross-spawn/-/cross-spawn-6.0.2.tgz#168309de311cd30a2b8ae720de6475c2fbf33ac7"
Expand Down Expand Up @@ -2152,6 +2145,11 @@ argparse@^1.0.7:
dependencies:
sprintf-js "~1.0.2"

argparse@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

argsarray@^0.0.1:
version "0.0.1"
resolved "https://registry.yarnpkg.com/argsarray/-/argsarray-0.0.1.tgz#6e7207b4ecdb39b0af88303fa5ae22bda8df61cb"
Expand Down Expand Up @@ -2765,25 +2763,6 @@ call-bind@^1.0.0, call-bind@^1.0.2:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"

caller-callsite@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/caller-callsite/-/caller-callsite-2.0.0.tgz#847e0fce0a223750a9a027c54b33731ad3154134"
integrity sha512-JuG3qI4QOftFsZyOn1qq87fq5grLIyk1JYd5lJmdA+fG7aQ9pA/i3JIJGcO3q0MrRcHlOt1U+ZeHW8Dq9axALQ==
dependencies:
callsites "^2.0.0"

caller-path@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/caller-path/-/caller-path-2.0.0.tgz#468f83044e369ab2010fac5f06ceee15bb2cb1f4"
integrity sha512-MCL3sf6nCSXOwCTzvPKhN18TU7AHTvdtam8DAogxcrJ8Rjfbbg7Lgng64H9Iy+vUV6VGFClN/TyxBkAebLRR4A==
dependencies:
caller-callsite "^2.0.0"

callsites@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50"
integrity sha512-ksWePWBloaWPxJYQ8TL0JHvtci6G5QTKwQ95RcWAa/lzoAKuAOflGdAK92hpHXjkwb8zLxoLNUoNYZgVsaJzvQ==

callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
Expand Down Expand Up @@ -3209,16 +3188,6 @@ core-util-is@~1.0.0:
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.3.tgz#a6042d3634c2b27e9328f837b965fac83808db85"
integrity sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==

cosmiconfig@^5.0.7:
version "5.2.1"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-5.2.1.tgz#040f726809c591e77a17c0a3626ca45b4f168b1a"
integrity sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==
dependencies:
import-fresh "^2.0.0"
is-directory "^0.3.1"
js-yaml "^3.13.1"
parse-json "^4.0.0"

cosmiconfig@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-6.0.0.tgz#da4fee853c52f6b1e6935f41c1a2fc50bd4a9982"
Expand All @@ -3241,6 +3210,16 @@ cosmiconfig@^7.0.0, cosmiconfig@^7.0.1:
path-type "^4.0.0"
yaml "^1.10.0"

cosmiconfig@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/cosmiconfig/-/cosmiconfig-8.1.0.tgz#947e174c796483ccf0a48476c24e4fefb7e1aea8"
integrity sha512-0tLZ9URlPGU7JsKq0DQOQ3FoRsYX8xDZ7xMiATQfaiGMz7EHowNkbU9u1coAOmnh9p/1ySpm0RB3JNWRXM5GCg==
dependencies:
import-fresh "^3.2.1"
js-yaml "^4.1.0"
parse-json "^5.0.0"
path-type "^4.0.0"

crc-32@~1.2.0, crc-32@~1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/crc-32/-/crc-32-1.2.2.tgz#3cad35a934b8bf71f25ca524b6da51fb7eace2ff"
Expand Down Expand Up @@ -4731,14 +4710,6 @@ immediate@^3.2.2:
resolved "https://registry.yarnpkg.com/immediate/-/immediate-3.3.0.tgz#1aef225517836bcdf7f2a2de2600c79ff0269266"
integrity sha512-HR7EVodfFUdQCTIeySw+WDRFJlPcLOJbXfwwZ7Oom6tjsvZ3bOkCDJHehQC3nxJrv7+f9XecwazynjU8e4Vw3Q==

import-fresh@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-2.0.0.tgz#d81355c15612d386c61f9ddd3922d4304822a546"
integrity sha512-eZ5H8rcgYazHbKC3PG4ClHNykCSxtAhxSSEM+2mb+7evD2CKF5V7c0dNum7AdpDh0ZdICwZY9sRSn8f+KH96sg==
dependencies:
caller-path "^2.0.0"
resolve-from "^3.0.0"

import-fresh@^3.1.0, import-fresh@^3.2.1:
version "3.3.0"
resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.3.0.tgz#37162c25fcb9ebaa2e6e53d5b4d88ce17d9e0c2b"
Expand Down Expand Up @@ -4996,11 +4967,6 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2:
is-data-descriptor "^1.0.0"
kind-of "^6.0.2"

is-directory@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/is-directory/-/is-directory-0.3.1.tgz#61339b6f2475fc772fd9c9d83f5c8575dc154ae1"
integrity sha512-yVChGzahRFvbkscn2MlwGismPO12i9+znNruC5gVEntG3qu0xQMzsGg/JFbrsqDOHtHFPci+V5aP5T9I+yeKqw==

is-docker@^2.0.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.2.1.tgz#33eeabe23cfe86f14bde4408a02c0cfb853acdaa"
Expand Down Expand Up @@ -5723,6 +5689,13 @@ js-yaml@^3.13.1:
argparse "^1.0.7"
esprima "^4.0.0"

js-yaml@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
dependencies:
argparse "^2.0.1"

jsbn@~0.1.0:
version "0.1.1"
resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513"
Expand Down Expand Up @@ -5778,11 +5751,6 @@ json-bigint@^1.0.0:
dependencies:
bignumber.js "^9.0.0"

json-parse-better-errors@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz#bb867cfb3450e69107c131d1c514bab3dc8bcaa9"
integrity sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==

json-parse-even-better-errors@^2.3.0:
version "2.3.1"
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
Expand Down Expand Up @@ -7044,14 +7012,6 @@ parse-entities@^2.0.0:
is-decimal "^1.0.0"
is-hexadecimal "^1.0.0"

parse-json@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-4.0.0.tgz#be35f5425be1f7f6c747184f98a788cb99477ee0"
integrity sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==
dependencies:
error-ex "^1.3.1"
json-parse-better-errors "^1.0.1"

parse-json@^5.0.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-5.2.0.tgz#c76fc66dee54231c962b22bcc8a72cf2f99753cd"
Expand Down Expand Up @@ -7840,11 +7800,6 @@ resolve-cwd@^3.0.0:
dependencies:
resolve-from "^5.0.0"

resolve-from@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748"
integrity sha512-GnlH6vxLymXJNMBo7XP1fJIzBFbdYt49CuTwmB/6N53t+kMPRMFKz783LlQ4tv28XoQfMWinAJX6WCGf2IlaIw==

resolve-from@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
Expand Down

0 comments on commit 3682f12

Please sign in to comment.