-
-
Notifications
You must be signed in to change notification settings - Fork 84
/
esbuild.config.mjs
100 lines (84 loc) · 2.26 KB
/
esbuild.config.mjs
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
import { sentryEsbuildPlugin } from '@sentry/esbuild-plugin';
import { config } from 'dotenv';
import { execSync } from 'child_process';
import * as esbuild from 'esbuild';
import fs from 'fs';
config();
const gitCommit = execSync('git rev-parse --short HEAD').toString().trim();
const gitUrl = execSync('git remote get-url origin').toString().trim();
const gitBranch = execSync('git rev-parse --abbrev-ref HEAD')
.toString()
.trim()
.replace(/[\\\/]/g, '-');
let workerName = 'fixtweet';
// Get worker name from wrangler.toml
try {
workerName = fs
.readFileSync('wrangler.toml')
.toString()
.match(/name ?= ?"(.+?)"/)[1];
} catch (e) {
console.error(`Error reading wrangler.toml to find worker name, using 'fixtweet' instead.`);
}
const releaseName = `${workerName}-${gitBranch}-${gitCommit}-${new Date()
.toISOString()
.substring(0, 19)}`;
let envVariables = [
'BRANDING_NAME',
'BRANDING_NAME_BSKY',
'STANDARD_DOMAIN_LIST',
'STANDARD_BSKY_DOMAIN_LIST',
'DIRECT_MEDIA_DOMAINS',
'TEXT_ONLY_DOMAINS',
'INSTANT_VIEW_DOMAINS',
'INSTANT_VIEW_THREADS_DOMAINS',
'GALLERY_DOMAINS',
'NATIVE_MULTI_IMAGE_DOMAINS',
'HOST_URL',
'REDIRECT_URL',
'REDIRECT_URL_BSKY',
'EMBED_URL',
'MOSAIC_DOMAIN_LIST',
'MOSAIC_BSKY_DOMAIN_LIST',
'API_HOST_LIST',
'SENTRY_DSN',
'GIF_TRANSCODE_DOMAIN_LIST'
];
// Create defines for all environment variables
let defines = {};
for (let envVar of envVariables) {
defines[envVar] = `"${process.env[envVar]}"`;
}
defines['RELEASE_NAME'] = `"${releaseName}"`;
const plugins = [];
if (process.env.SENTRY_DSN) {
plugins.push(
sentryEsbuildPlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
telemetry: false,
release: {
name: releaseName,
create: true,
vcsRemote: gitUrl,
setCommits: {
auto: true,
ignoreMissing: true
}
},
// Auth tokens can be obtained from
// https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/
authToken: process.env.SENTRY_AUTH_TOKEN
})
);
}
await esbuild.build({
entryPoints: ['src/worker.ts'],
sourcemap: 'external',
outdir: 'dist',
minify: true,
bundle: true,
format: 'esm',
plugins: plugins,
define: defines
});