This repository has been archived by the owner on Jul 28, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
hooks.ts
79 lines (72 loc) · 2.29 KB
/
hooks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import loadCache, { Opts as CacheLoaderOptions } from "./cacheLoader/mod.ts";
import loadFiles, { Opts as FileLoaderOptions } from "./fileLoader/mod.ts";
import importer from "./importResolver/mod.ts";
import tsCompile from "./typescriptCompile/mod.ts";
import tsTransform from "./typescriptTransform/mod.ts";
const useLoadAndTransform = ({
fileLoaderOptions,
compilerOptions,
}: {
compilerOptions?: Deno.CompilerOptions;
fileLoaderOptions?: FileLoaderOptions;
}) => [loadFiles(fileLoaderOptions), tsTransform(compilerOptions)];
export const useAlwaysFetch = (
opts: {
compilerOptions?: Deno.CompilerOptions;
fileLoaderOptions?: FileLoaderOptions;
} = {},
) => [importer(), ...useLoadAndTransform(opts)];
export const useCache = (
opts: {
cacheLoaderOptions?: CacheLoaderOptions;
compilerOptions?: Deno.CompilerOptions;
fileLoaderOptions?: FileLoaderOptions;
} = {},
) => [
importer(),
loadCache(opts.cacheLoaderOptions),
...useLoadAndTransform({
compilerOptions: opts.compilerOptions,
fileLoaderOptions: opts.fileLoaderOptions,
}),
];
export const useCacheLazy = (
opts: {
fileLoaderOptions?: FileLoaderOptions;
cacheLoaderOptions?: CacheLoaderOptions;
compilerOptions?: Deno.CompilerOptions;
} = {},
) =>
useCache({
cacheLoaderOptions: { ...opts.cacheLoaderOptions, lazy: true },
compilerOptions: opts.compilerOptions,
fileLoaderOptions: opts.fileLoaderOptions,
});
export const useCacheOnly = (
opts: {
fileLoaderOptions?: FileLoaderOptions;
cacheLoaderOptions?: CacheLoaderOptions;
compilerOptions?: Deno.CompilerOptions;
} = {},
) =>
useCache({
fileLoaderOptions: opts.fileLoaderOptions,
cacheLoaderOptions: { ...opts.cacheLoaderOptions, cacheOnly: true },
compilerOptions: opts.compilerOptions,
});
export const useCompile = (
opts: {
cacheLoaderOptions?: CacheLoaderOptions;
compilerOptions?: Deno.CompilerOptions;
fileLoaderOptions?: FileLoaderOptions;
} = {},
) => [
tsCompile({ useAsLoader: false, compilerOptions: opts.compilerOptions }),
loadCache(opts.cacheLoaderOptions),
loadFiles(opts.fileLoaderOptions),
];
export const useCompileAsLoader = (
opts: {
compilerOptions?: Deno.CompilerOptions;
} = {},
) => [tsCompile({ useAsLoader: true, compilerOptions: opts.compilerOptions })];