-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathbundle.js
128 lines (126 loc) · 4.23 KB
/
bundle.js
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
import { build } from 'esbuild';
let fastlyPlugin = {
name: 'fastly',
setup(build) {
build.onResolve({ filter: /^fastly:.*/ }, (args) => {
return {
path: args.path.replace('fastly:', ''),
namespace: 'fastly',
};
});
build.onLoad({ filter: /^.*/, namespace: 'fastly' }, async (args) => {
switch (args.path) {
case 'backend': {
return {
contents: `
export const Backend = globalThis.Backend;
export const setDefaultDynamicBackendConfig = Object.getOwnPropertyDescriptor(globalThis.fastly, 'allowDynamicBackends').set;
const allowDynamicBackends = Object.getOwnPropertyDescriptor(globalThis.fastly, 'allowDynamicBackends').set;
export const setDefaultBackend = Object.getOwnPropertyDescriptor(globalThis.fastly, 'defaultBackend').set;
export function enforceExplicitBackends (defaultBackend) {
allowDynamicBackends(false);
if (defaultBackend) setDefaultBackend(defaultBackend);
}
`,
};
}
case 'body': {
return {
contents: `export const FastlyBody = globalThis.FastlyBody;`,
};
}
case 'cache-override': {
return {
contents: `export const CacheOverride = globalThis.CacheOverride;`,
};
}
case 'config-store': {
return {
contents: `export const ConfigStore = globalThis.ConfigStore;`,
};
}
case 'dictionary': {
return {
contents: `export const Dictionary = globalThis.Dictionary;`,
};
}
case 'device': {
return { contents: `export const Device = globalThis.Device;` };
}
case 'edge-rate-limiter': {
return {
contents: `
export const RateCounter = globalThis.RateCounter;
export const PenaltyBox = globalThis.PenaltyBox;
export const EdgeRateLimiter = globalThis.EdgeRateLimiter;
`,
};
}
case 'env': {
return { contents: `export const env = globalThis.fastly.env.get;` };
}
case 'experimental': {
return {
contents: `
export const includeBytes = globalThis.fastly.includeBytes;
export const enableDebugLogging = globalThis.fastly.enableDebugLogging;
export const setBaseURL = Object.getOwnPropertyDescriptor(globalThis.fastly, 'baseURL').set;
export const setDefaultBackend = Object.getOwnPropertyDescriptor(globalThis.fastly, 'defaultBackend').set;
export const allowDynamicBackends = Object.getOwnPropertyDescriptor(globalThis.fastly, 'allowDynamicBackends').set;
export const sdkVersion = globalThis.fastly.sdkVersion;
`,
};
}
case 'fanout': {
return {
contents: `export const createFanoutHandoff = globalThis.fastly.createFanoutHandoff;`,
};
}
case 'geolocation': {
return {
contents: `export const getGeolocationForIpAddress = globalThis.fastly.getGeolocationForIpAddress;`,
};
}
case 'logger': {
return { contents: `export const Logger = globalThis.Logger;` };
}
case 'kv-store': {
return { contents: `export const KVStore = globalThis.KVStore;` };
}
case 'secret-store': {
return {
contents: `export const SecretStore = globalThis.SecretStore;export const SecretStoreEntry = globalThis.SecretStoreEntry;`,
};
}
case 'cache': {
return {
contents: `
export const CacheEntry = globalThis.CacheEntry;
export const CacheState = globalThis.CacheState;
export const CoreCache = globalThis.CoreCache;
export const SimpleCache = globalThis.SimpleCache;
export const SimpleCacheEntry = globalThis.SimpleCacheEntry;
export const TransactionCacheEntry = globalThis.TransactionCacheEntry;
`,
};
}
case 'compute': {
return {
contents: `export const { purgeSurrogateKey, vCpuTime } = globalThis.fastly;`,
};
}
}
});
},
};
export async function bundle(input, moduleMode = false) {
return await build({
conditions: ['fastly'],
entryPoints: [input],
bundle: true,
write: false,
format: moduleMode ? 'esm' : 'iife',
tsconfig: undefined,
plugins: [fastlyPlugin],
});
}