forked from floydspace/serverless-esbuild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.ts
151 lines (123 loc) · 3.57 KB
/
types.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import type { WatchOptions } from 'chokidar';
import type { BuildOptions, BuildResult, Plugin } from 'esbuild';
import type Serverless from 'serverless';
export type ConfigFn = (sls: Serverless) => Configuration;
export type Plugins = Plugin[];
export type ReturnPluginsFn = (sls: Serverless) => Plugins;
export interface WatchConfiguration {
pattern?: string[] | string;
ignore?: string[] | string;
chokidar?: WatchOptions;
}
export interface PackagerOptions {
scripts?: string[] | string;
noInstall?: boolean;
}
interface NodeExternalsOptions {
allowList?: string[];
}
export type EsbuildOptions = Omit<BuildOptions, 'watch' | 'plugins'>;
export interface Configuration extends EsbuildOptions {
concurrency?: number;
packager: PackagerId;
packagerOptions: PackagerOptions;
packagePath: string;
exclude: '*' | string[];
nativeZip: boolean;
watch: WatchConfiguration;
installExtraArgs: string[];
plugins?: string | Plugin[];
keepOutputDirectory?: boolean;
disableIncremental?: boolean;
outputWorkFolder?: string;
outputBuildFolder?: string;
outputFileExtension: '.js' | '.cjs' | '.mjs';
nodeExternals?: NodeExternalsOptions;
}
export interface EsbuildFunctionDefinitionHandler extends Serverless.FunctionDefinitionHandler {
skipEsbuild: boolean;
}
export interface FunctionEntry {
entry: string;
func: Serverless.FunctionDefinitionHandler | null;
functionAlias?: string;
}
export interface FunctionBuildResult {
bundlePath: string;
func: Serverless.FunctionDefinitionHandler;
functionAlias: string;
}
interface BuildInvalidate {
(): Promise<BuildIncremental>;
dispose(): void;
}
interface BuildIncremental extends BuildResult {
rebuild: BuildInvalidate;
}
interface OldAPIResult extends BuildResult {
rebuild?: BuildInvalidate;
stop?: () => void;
}
export interface FileBuildResult {
bundlePath: string;
entry: string;
result: OldAPIResult;
context?: BuildContext | null;
}
interface ServeOptions {
port?: number;
host?: string;
servedir?: string;
keyfile?: string;
certfile?: string;
onRequest?: (args: ServeOnRequestArgs) => void;
}
interface ServeOnRequestArgs {
remoteAddress: string;
method: string;
path: string;
status: number;
/** The time to generate the response, not to send it */
timeInMS: number;
}
export interface BuildContext {
/** Documentation: https://esbuild.github.io/api/#rebuild */
rebuild(): Promise<BuildResult>;
/** Documentation: https://esbuild.github.io/api/#watch */
watch(options?: {}): Promise<void>;
/** Documentation: https://esbuild.github.io/api/#serve */
serve(options?: ServeOptions): Promise<ServeResult>;
cancel(): Promise<void>;
dispose(): Promise<void>;
}
/** Documentation: https://esbuild.github.io/api/#serve-return-values */
interface ServeResult {
port: number;
host: string;
}
export type JSONObject = any;
export interface DependenciesResult {
stdout?: string;
dependencies?: DependencyMap;
}
export type DependencyMap = Record<string, DependencyTree>;
export interface DependencyTree {
version: string;
dependencies?: DependencyMap;
/** Indicates the dependency is available from the root node_modules folder/root of this tree */
isRootDep?: boolean;
}
export interface IFile {
readonly localPath: string;
readonly rootPath: string;
}
export type IFiles = readonly IFile[];
export type PackagerId = 'npm' | 'pnpm' | 'yarn';
export type PackageJSON = {
name: string;
version: string;
dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
peerDependencies?: Record<string, string>;
[key: string]: unknown;
};