-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutput.ts
More file actions
executable file
·198 lines (153 loc) · 4.22 KB
/
Copy pathOutput.ts
File metadata and controls
executable file
·198 lines (153 loc) · 4.22 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import type { BuildOptions } from "esbuild";
// RestPlugin is loaded lazily only when Compiler=Rest is set.
// The dynamic import must be inside the conditional body - not a ternary -
// so ESM module evaluation does not resolve the specifier when Compiler != Rest.
let RestPlugin: import("esbuild").Plugin | null = null;
if (process.env["Compiler"]?.toLowerCase() === "rest") {
try {
const { createRestPluginIfEnabled } = await import("./Rest/Plugin.js");
RestPlugin = createRestPluginIfEnabled();
} catch {
console.warn(
"[Output] RestPlugin.js not found - falling back to esbuild TS loader",
);
}
}
export const Clean = process.env["Clean"] === "true";
export const Meta = process.env["Meta"] === "true";
export const On =
process.env["NODE_ENV"] === "development" ||
process.env["TAURI_ENV_DEBUG"] === "true";
/**
* @module ESBuild
*
*/
export default {
color: true,
format: "esm",
logLevel: On ? "debug" : "silent",
metafile: Meta,
minify: !On,
outdir: "Configuration",
outbase: "Source",
platform: "node",
target: "esnext",
tsconfig: "tsconfig.json",
write: true,
legalComments: On ? "inline" : "none",
bundle: false,
assetNames: "Asset/[name]-[hash]",
sourcemap: On,
drop: On ? [] : ["debugger"],
ignoreAnnotations: !On,
keepNames: On,
plugins: (
[
{
name: "Target",
// @ts-ignore
setup({ onStart, initialOptions: { outdir } }) {
switch (true) {
case Clean === true:
onStart(async () => {
try {
outdir
? await (
await import("node:fs/promises")
).rm(outdir, {
recursive: true,
})
: {};
} catch (_Error) {
console.log(_Error);
}
});
break;
default:
break;
}
},
},
// RestPlugin activated only when Compiler=Rest env var is set.
...(RestPlugin ? [RestPlugin] : []),
// PostHog build telemetry - debug only, skipped in production and
// when `Capture=false` (master telemetry kill switch shared with
// Mountain / Cocoon / Sky / Build.sh).
...(process.env["NODE_ENV"] !== "production" &&
process.env["Capture"] !== "false" &&
process.env["Report"] !== "false"
? [
{
name: "PostHogBuildTelemetry",
setup({
onEnd,
}: {
onEnd: (
Callback: (Result: {
errors: unknown[];
warnings: unknown[];
}) => Promise<void>,
) => void;
}) {
const StartTime = performance.now();
onEnd(async (Result) => {
const DurationMs = Math.round(
performance.now() - StartTime,
);
try {
const { request } =
await import("node:https");
const Body = JSON.stringify({
api_key:
process.env["Authorize"] || "",
event: "land:output:build:complete",
properties: {
distinct_id: `land-dev-${process.env["USER"] || "unknown"}`,
$app: "fiddee",
$component: "output",
$tier: "output",
$build_mode: On
? "development"
: "production",
duration_ms: DurationMs,
errors: Result.errors.length,
warnings:
Result.warnings.length,
compiler:
process.env["Compiler"] ||
"esbuild",
},
timestamp: new Date().toISOString(),
});
const Url = new URL(
`${process.env["Beam"] ?? "https://eu.i.posthog.com"}/capture/`,
);
const Req = request({
hostname: Url.hostname,
port: Number(Url.port) || 443,
path: Url.pathname,
method: "POST",
headers: {
"Content-Type":
"application/json",
"Content-Length":
Buffer.byteLength(Body),
},
});
Req.on("error", () => {});
Req.write(Body);
Req.end();
} catch {}
});
},
},
]
: []),
] as import("esbuild").Plugin[]
).filter(Boolean),
loader: {
".json": "copy",
".sh": "copy",
},
} satisfies BuildOptions as BuildOptions;
export const { sep, posix } = await import("node:path");