Skip to content

Commit

Permalink
chore: upgrade flat to v6 and inline
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Apr 9, 2024
1 parent 701f71a commit 38cebbb
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
18 changes: 18 additions & 0 deletions LICENSE
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions build.config.ts
@@ -0,0 +1,9 @@
import { defineBuildConfig } from "unbuild";

export default defineBuildConfig({
declaration: true,
rollup: {
emitCJS: true,
inlineDependencies: true,
},
});
5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -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",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

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

10 changes: 4 additions & 6 deletions src/index.ts
Expand Up @@ -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*$/;
Expand Down Expand Up @@ -62,9 +62,7 @@ export function parse<T extends RC = RC>(
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<T extends RC = RC>(
Expand All @@ -89,7 +87,7 @@ export function readUser<T extends RC = RC>(options?: RCOptions | string): T {
}

export function serialize<T extends RC = RC>(config: T): string {
return Object.entries(flat.flatten<RC, RC>(config))
return Object.entries(flatten<RC, RC>(config))
.map(([key, value]) => `${key}=${JSON.stringify(value)}`)
.join("\n");
}
Expand Down Expand Up @@ -119,7 +117,7 @@ export function update<T extends RC = RC>(
): 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);
Expand Down

0 comments on commit 38cebbb

Please sign in to comment.