From 38cebbb9ec94f1daf580e6407005db5ed4ed1d7a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 9 Apr 2024 18:56:25 +0200 Subject: [PATCH] chore: upgrade `flat` to v6 and inline --- LICENSE | 18 ++++++++++++++++++ build.config.ts | 9 +++++++++ package.json | 5 ++--- pnpm-lock.yaml | 18 +++++++++--------- src/index.ts | 10 ++++------ 5 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 build.config.ts diff --git a/LICENSE b/LICENSE index e739abc..4caf8c2 100644 --- a/LICENSE +++ b/LICENSE @@ -19,3 +19,21 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +----- + +Bundled with https://github.com/hughsk/flat + +Copyright (c) 2014, Hugh Kennedy +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/build.config.ts b/build.config.ts new file mode 100644 index 0000000..2927b93 --- /dev/null +++ b/build.config.ts @@ -0,0 +1,9 @@ +import { defineBuildConfig } from "unbuild"; + +export default defineBuildConfig({ + declaration: true, + rollup: { + emitCJS: true, + inlineDependencies: true, + }, +}); diff --git a/package.json b/package.json index be0eff4..957a689 100644 --- a/package.json +++ b/package.json @@ -27,17 +27,16 @@ }, "dependencies": { "defu": "^6.1.4", - "destr": "^2.0.3", - "flat": "^5.0.2" + "destr": "^2.0.3" }, "devDependencies": { - "@types/flat": "^5.0.5", "@types/node": "^20.12.6", "@vitest/coverage-v8": "^1.4.0", "automd": "^0.3.7", "changelogen": "^0.5.5", "eslint": "^9.0.0", "eslint-config-unjs": "^0.3.0-rc.4", + "flat": "^6.0.1", "prettier": "^3.2.5", "typescript": "^5.4.4", "unbuild": "^2.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d8a184..9543947 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,13 +12,10 @@ dependencies: specifier: ^2.0.3 version: 2.0.3 flat: - specifier: ^5.0.2 - version: 5.0.2 + specifier: ^6.0.1 + version: 6.0.1 devDependencies: - '@types/flat': - specifier: ^5.0.5 - version: 5.0.5 '@types/node': specifier: ^20.12.6 version: 20.12.6 @@ -1185,10 +1182,6 @@ packages: resolution: {integrity: sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==} dev: true - /@types/flat@5.0.5: - resolution: {integrity: sha512-nPLljZQKSnac53KDUDzuzdRfGI0TDb5qPrb+SrQyN3MtdQrOnGsKniHN1iYZsJEBIVQve94Y6gNz22sgISZq+Q==} - dev: true - /@types/istanbul-lib-coverage@2.0.6: resolution: {integrity: sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==} dev: true @@ -2440,6 +2433,13 @@ packages: /flat@5.0.2: resolution: {integrity: sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==} hasBin: true + dev: true + + /flat@6.0.1: + resolution: {integrity: sha512-/3FfIa8mbrg3xE7+wAhWeV+bd7L2Mof+xtZb5dRDKZ+wDvYJK4WDYeIOuOhre5Yv5aQObZrlbRmk3RTSiuQBtw==} + engines: {node: '>=18'} + hasBin: true + dev: false /flatted@3.3.1: resolution: {integrity: sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==} diff --git a/src/index.ts b/src/index.ts index 5c99472..d82b741 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs"; import { resolve } from "node:path"; import { homedir } from "node:os"; import destr from "destr"; -import flat from "flat"; +import { flatten, unflatten } from "flat"; import { defu } from "defu"; const RE_KEY_VAL = /^\s*([^\s=]+)\s*=\s*(.*)?\s*$/; @@ -62,9 +62,7 @@ export function parse( config[key] = value; } - return options.flat - ? (config as T) - : flat.unflatten(config, { overwrite: true }); + return options.flat ? (config as T) : unflatten(config, { overwrite: true }); } export function parseFile( @@ -89,7 +87,7 @@ export function readUser(options?: RCOptions | string): T { } export function serialize(config: T): string { - return Object.entries(flat.flatten(config)) + return Object.entries(flatten(config)) .map(([key, value]) => `${key}=${JSON.stringify(value)}`) .join("\n"); } @@ -119,7 +117,7 @@ export function update( ): T { options = withDefaults(options); if (!options.flat) { - config = flat.unflatten(config, { overwrite: true }); + config = unflatten(config, { overwrite: true }); } const newConfig = defu(config, read(options)); write(newConfig, options);