asphodelos 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,48 @@
1
+ import { t as __exportAll } from "./rolldown-runtime-wcPFST8Q.mjs";
2
+ import { Context, Data, Effect } from "effect";
3
+ import { format } from "oxfmt";
4
+ //#region src/format/index.ts
5
+ var format_exports = /* @__PURE__ */ __exportAll({
6
+ FormatError: () => FormatError,
7
+ FormatOptions: () => FormatOptions,
8
+ fmt: () => fmt
9
+ });
10
+ /** oxfmt rejected the source it was handed. */
11
+ var FormatError = class extends Data.TaggedError("FormatError") {};
12
+ const defaultConfig = {
13
+ printWidth: 100,
14
+ singleQuote: true,
15
+ semi: false
16
+ };
17
+ /**
18
+ * The oxfmt options generated source is written with.
19
+ *
20
+ * A `Reference` rather than module state: the default is what a program gets without saying
21
+ * anything, and a config file's `format` block overrides it for that program only — two runs in
22
+ * one process cannot leak options into each other.
23
+ */
24
+ const FormatOptions = Context.Reference("asphodelos/FormatOptions", { defaultValue: () => defaultConfig });
25
+ /**
26
+ * oxfmt keeps a blank line wherever the author had one, including between imports. Generated
27
+ * source has no author, so the gaps are an artifact of how the header was assembled.
28
+ */
29
+ function collapseImportGaps(code) {
30
+ return code.replaceAll(/^(import\s[^\n]*?\sfrom\s[^\n]+\n)\n+(?=import\s[^\n]*?\sfrom\s)/gmu, "$1");
31
+ }
32
+ /** Formats generated TypeScript with the options in scope. */
33
+ function fmt(input) {
34
+ return Effect.gen(function* () {
35
+ const config = yield* FormatOptions;
36
+ const { code, errors } = yield* Effect.tryPromise({
37
+ try: () => format("<stdin>.ts", input, {
38
+ ...defaultConfig,
39
+ ...config
40
+ }),
41
+ catch: (cause) => new FormatError({ message: cause instanceof Error ? cause.message : String(cause) })
42
+ });
43
+ if (errors.length > 0) return yield* new FormatError({ message: errors.map((error) => error.message).join("\n") });
44
+ return collapseImportGaps(code);
45
+ });
46
+ }
47
+ //#endregion
48
+ export { fmt as n, format_exports as r, FormatOptions as t };