-
Notifications
You must be signed in to change notification settings - Fork 46
🐈🐈🐈 #657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "\u{1F408}.json"
🐈🐈🐈 #657
Changes from 4 commits
876d932
9ef1a4b
2fda1f7
9c68c69
7517e14
02df0ea
4665c87
6a980b2
efb2e06
330cb36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,10 @@ | |
| "extension": [ | ||
| ".civet", | ||
| ".coffee", | ||
| ".hera", | ||
| ".js", | ||
| ".mjs", | ||
| ".mts", | ||
| ".ts" | ||
| ], | ||
| "include": [ | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import path from "path"; | ||
|
||
| import fs from "fs/promises"; | ||
| import { compile } from "./main.coffee"; | ||
|
|
||
| const findInDir = async function (dirPath: string): Promise<string | undefined> { | ||
| const dir = await fs.opendir(dirPath); | ||
| for await (const entry of dir) { | ||
| if ( | ||
| entry.isDirectory() && | ||
| entry.name === ".config" | ||
| ) { | ||
| // scan for ./civet.json as well as ./.config/civet.json | ||
| const found = await findInDir( | ||
| path.join(dirPath, entry.name) | ||
| ); | ||
| if (found) { | ||
| return found; | ||
| } | ||
| } | ||
| if (entry.isFile()) { | ||
| const name = entry.name.replace(/^\./, ""); // allow both .civetconfig.civet and civetconfig.civet | ||
| if ([ | ||
| "🐈.json", | ||
| "🐈.civet", | ||
| "civetconfig.json", | ||
| "civetconfig.civet", | ||
| ].includes(name)) { | ||
|
||
| return path.join(dirPath, entry.name); | ||
| } | ||
| } | ||
| } | ||
| return | ||
| }; | ||
|
|
||
| export var findConfig = async function (startDir: string) { | ||
| let curr = startDir, | ||
| parent = path.dirname(curr); | ||
|
|
||
| while (curr !== parent) { | ||
| // root directory (/, C:, etc.) | ||
| const configPath = await findInDir(curr); | ||
| if (configPath) { | ||
| return configPath; | ||
| } | ||
| curr = parent; | ||
| parent = path.dirname(curr); | ||
| } | ||
| return; | ||
| }; | ||
|
|
||
| export var loadConfig = async function (path: string) { | ||
| const config = await fs.readFile(path, "utf8"); | ||
| if (path.endsWith(".json")) { | ||
| return JSON.parse(config); | ||
| } else { | ||
| const js = compile(config, { js: true }); | ||
| let exports; | ||
|
|
||
| try { | ||
| exports = await import(`data:text/javascript,${js}`); | ||
| } catch (e) { | ||
| console.error("Error loading config file", path, e); | ||
| } | ||
|
|
||
| if (typeof exports.default !== "object" || exports.default === null) { | ||
| throw new Error( | ||
| "civet config file must export an object" | ||
| ); | ||
| } | ||
| return exports.default; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| assert from assert | ||
| { findConfig, loadConfig } from ../../source/config.mts | ||
|
|
||
| describe "loading config", -> | ||
| it "should load from civetconfig.json", -> | ||
| path := await findConfig("test/infra/config/") | ||
| config := await loadConfig(path) | ||
|
|
||
| assert config.coffeeCompat | ||
|
|
||
| it "should load specified custom files", -> | ||
| customConfig := await loadConfig("test/infra/config/customconfig.civet") | ||
| assert.equal customConfig.someConfig, "heyy" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "coffeeCompat": true | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export default { | ||
| someConfig: "heyy" | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's nice to keep this registration in case others want to use this as a CoffeeScript ESM handler. So I lean toward keeping it, but it's also OK to remove it and leave this for a CoffeeScript issue (actually jashkenas/coffeescript#5447).