o134 commited on
Commit
892ad6e
·
verified ·
1 Parent(s): 9a6fd22

Upload api-server\build.mjs with huggingface_hub

Browse files
Files changed (1) hide show
  1. api-server//build.mjs +126 -0
api-server//build.mjs ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createRequire } from "node:module";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { build as esbuild } from "esbuild";
5
+ import esbuildPluginPino from "esbuild-plugin-pino";
6
+ import { rm } from "node:fs/promises";
7
+
8
+ // Plugins (e.g. 'esbuild-plugin-pino') may use `require` to resolve dependencies
9
+ globalThis.require = createRequire(import.meta.url);
10
+
11
+ const artifactDir = path.dirname(fileURLToPath(import.meta.url));
12
+
13
+ async function buildAll() {
14
+ const distDir = path.resolve(artifactDir, "dist");
15
+ await rm(distDir, { recursive: true, force: true });
16
+
17
+ await esbuild({
18
+ entryPoints: [path.resolve(artifactDir, "src/index.ts"), path.resolve(artifactDir, "src/app.ts")],
19
+ platform: "node",
20
+ bundle: true,
21
+ format: "esm",
22
+ outdir: distDir,
23
+ outExtension: { ".js": ".mjs" },
24
+ logLevel: "info",
25
+ // Some packages may not be bundleable, so we externalize them, we can add more here as needed.
26
+ // Some of the packages below may not be imported or installed, but we're adding them in case they are in the future.
27
+ // Examples of unbundleable packages:
28
+ // - uses native modules and loads them dynamically (e.g. sharp)
29
+ // - use path traversal to read files (e.g. @google-cloud/secret-manager loads sibling .proto files)
30
+ external: [
31
+ "*.node",
32
+ "sharp",
33
+ "better-sqlite3",
34
+ "sqlite3",
35
+ "canvas",
36
+ "bcrypt",
37
+ "argon2",
38
+ "fsevents",
39
+ "re2",
40
+ "farmhash",
41
+ "xxhash-addon",
42
+ "bufferutil",
43
+ "utf-8-validate",
44
+ "ssh2",
45
+ "cpu-features",
46
+ "dtrace-provider",
47
+ "isolated-vm",
48
+ "lightningcss",
49
+ "pg-native",
50
+ "oracledb",
51
+ "mongodb-client-encryption",
52
+ "nodemailer",
53
+ "handlebars",
54
+ "knex",
55
+ "typeorm",
56
+ "protobufjs",
57
+ "onnxruntime-node",
58
+ "@tensorflow/*",
59
+ "@prisma/client",
60
+ "@mikro-orm/*",
61
+ "@grpc/*",
62
+ "@swc/*",
63
+ "@aws-sdk/*",
64
+ "@azure/*",
65
+ "@opentelemetry/*",
66
+ "@google-cloud/*",
67
+ "@google/*",
68
+ "googleapis",
69
+ "firebase-admin",
70
+ "@parcel/watcher",
71
+ "@sentry/profiling-node",
72
+ "@tree-sitter/*",
73
+ "aws-sdk",
74
+ "classic-level",
75
+ "dd-trace",
76
+ "ffi-napi",
77
+ "grpc",
78
+ "hiredis",
79
+ "kerberos",
80
+ "leveldown",
81
+ "miniflare",
82
+ "mysql2",
83
+ "newrelic",
84
+ "odbc",
85
+ "piscina",
86
+ "realm",
87
+ "ref-napi",
88
+ "rocksdb",
89
+ "sass-embedded",
90
+ "sequelize",
91
+ "serialport",
92
+ "snappy",
93
+ "tinypool",
94
+ "usb",
95
+ "workerd",
96
+ "wrangler",
97
+ "zeromq",
98
+ "zeromq-prebuilt",
99
+ "playwright",
100
+ "puppeteer",
101
+ "puppeteer-core",
102
+ "electron",
103
+ ],
104
+ sourcemap: "linked",
105
+ plugins: [
106
+ // pino relies on workers to handle logging, instead of externalizing it we use a plugin to handle it
107
+ esbuildPluginPino({ transports: ["pino-pretty"] })
108
+ ],
109
+ // Make sure packages that are cjs only (e.g. express) but are bundled continue to work in our esm output file
110
+ banner: {
111
+ js: `import { createRequire as __bannerCrReq } from 'node:module';
112
+ import __bannerPath from 'node:path';
113
+ import __bannerUrl from 'node:url';
114
+
115
+ globalThis.require = __bannerCrReq(import.meta.url);
116
+ globalThis.__filename = __bannerUrl.fileURLToPath(import.meta.url);
117
+ globalThis.__dirname = __bannerPath.dirname(globalThis.__filename);
118
+ `,
119
+ },
120
+ });
121
+ }
122
+
123
+ buildAll().catch((err) => {
124
+ console.error(err);
125
+ process.exit(1);
126
+ });