-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support jsonc config files (#206)
- Loading branch information
1 parent
f5239ed
commit 103fda2
Showing
6 changed files
with
163 additions
and
25 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
export { | ||
basename, | ||
dirname, | ||
extname, | ||
fromFileUrl, | ||
join, | ||
normalize, | ||
|
@@ -13,13 +14,15 @@ export { | |
} from "https://deno.land/[email protected]/path/mod.ts"; | ||
export { | ||
bold, | ||
cyan, | ||
green, | ||
magenta, | ||
red, | ||
yellow, | ||
} from "https://deno.land/[email protected]/fmt/colors.ts"; | ||
export { parse } from "https://deno.land/[email protected]/flags/mod.ts"; | ||
export { TextLineStream } from "https://deno.land/[email protected]/streams/text_line_stream.ts"; | ||
export * as JSONC from "https://deno.land/[email protected]/encoding/jsonc.ts"; | ||
|
||
// x/semver | ||
export { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { fromFileUrl } from "../../deps.ts"; | ||
import configFile from "../../src/config_file.ts"; | ||
import { assert, assertEquals } from "../deps.ts"; | ||
|
||
Deno.test("ConfigFile.diff returns array with additions and removals", async () => { | ||
const config = await configFile.read( | ||
fromFileUrl(new URL(import.meta.resolve("./config.json"))), | ||
); | ||
assert(!!config); | ||
|
||
let changes = config.diff({}); | ||
assertEquals(changes, []); | ||
|
||
changes = config.diff({ project: "foo" }); | ||
assertEquals(changes, [{ | ||
key: "project", | ||
addition: "foo", | ||
removal: undefined, | ||
}]); | ||
|
||
// Using file URLs to avoid dealing with path normalization | ||
config.override({ project: "foo", entrypoint: "file://main.ts" }); | ||
|
||
changes = config.diff({ project: "bar", entrypoint: "file://src/main.ts" }); | ||
assertEquals(changes, [ | ||
{ key: "project", removal: "foo", addition: "bar" }, | ||
{ | ||
key: "entrypoint", | ||
removal: "file://main.ts", | ||
addition: "file://src/main.ts", | ||
}, | ||
]); | ||
}); | ||
|
||
Deno.test("ConfigFile.diff reports inculde and exclude changes when one of the entries changed", async () => { | ||
const config = await configFile.read( | ||
fromFileUrl(new URL(import.meta.resolve("./config.json"))), | ||
); | ||
assert(!!config); | ||
|
||
config.override({ include: ["foo", "bar"], exclude: ["fuzz", "bazz"] }); | ||
|
||
const changes = config.diff({ | ||
include: ["fuzz", "bazz"], | ||
exclude: ["foo", "bar"], | ||
}); | ||
assertEquals(changes, [ | ||
{ key: "exclude", addition: ["foo", "bar"], removal: ["fuzz", "bazz"] }, | ||
{ key: "include", removal: ["foo", "bar"], addition: ["fuzz", "bazz"] }, | ||
]); | ||
}); |