@duraxis/cli 0.1.0 → 0.3.0

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.
@@ -1,43 +0,0 @@
1
- import ts from "typescript";
2
- import { readFile } from "node:fs/promises";
3
- export async function resolve(specifier, context, nextResolve) {
4
- try {
5
- return await nextResolve(specifier, context);
6
- } catch (error) {
7
- if (
8
- error.code == "ERR_MODULE_NOT_FOUND" &&
9
- /^(\.|\/)/.test(specifier) &&
10
- specifier.endsWith(".js")
11
- )
12
- return nextResolve(specifier.slice(0, -3) + ".ts", context);
13
- throw error;
14
- }
15
- }
16
- export async function load(url, context, nextLoad) {
17
- if (!url.endsWith(".ts") || url.endsWith(".d.ts")) return nextLoad(url, context);
18
- const source = await readFile(new URL(url), "utf8");
19
- const result = ts.transpileModule(source, {
20
- fileName: new URL(url).pathname,
21
- reportDiagnostics: true,
22
- compilerOptions: {
23
- target: ts.ScriptTarget.ES2022,
24
- module: ts.ModuleKind.ESNext,
25
- experimentalDecorators: true,
26
- emitDecoratorMetadata: true,
27
- useDefineForClassFields: false,
28
- sourceMap: false,
29
- },
30
- });
31
- const errors = (result.diagnostics ?? []).filter(
32
- (item) => item.category == ts.DiagnosticCategory.Error,
33
- );
34
- if (errors.length)
35
- throw new Error(
36
- ts.formatDiagnosticsWithColorAndContext(errors, {
37
- getCurrentDirectory: () => process.cwd(),
38
- getCanonicalFileName: (file) => file,
39
- getNewLine: () => "\n",
40
- }),
41
- );
42
- return { format: "module", source: result.outputText, shortCircuit: true };
43
- }