-
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathbuild.mjs
151 lines (150 loc) · 4.49 KB
/
build.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
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 { writeFileSync } from 'node:fs'
import { exit } from 'node:process'
import * as esbuild from 'esbuild'
esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
platform: 'node',
target: 'node20',
outfile: 'dist/index.js', // Change this to output a single file
sourcemap: process.env.NODE_ENV === 'development',
metafile: true,
minify: true, // Minify the output
treeShaking: true, // Enable tree shaking to remove unused code
banner: {
js: '#!/usr/bin/env node',
},
define: {
'process.env.SUPA_DB': '"production"',
},
loader: {
'.ts': 'ts',
},
plugins: [
// TOSO: remove this when fixed
{
name: 'ignore-punycode',
setup(build) {
build.onResolve({ filter: /^punycode$/ }, args => ({
path: args.path,
namespace: 'ignore',
}))
build.onLoad({ filter: /.*/, namespace: 'ignore' }, () => ({
contents: 'export default {}',
}))
},
},
// Generic noop for fetch-related files
{
name: 'noop-supabase-node-fetch',
setup(build) {
build.onResolve({ filter: /@supabase\/node-fetch/ }, args => ({
path: args.path,
namespace: 'noop',
}))
build.onLoad({ filter: /.*/, namespace: 'noop' }, () => ({
contents: 'export default {}',
}))
},
},
// Noop xml2js as we only use capacitor-cli to read capacitor file nothing native
{
name: 'noop-xml2js',
setup(build) {
build.onResolve({ filter: /^xml2js$/ }, args => ({
path: args.path,
namespace: 'noop',
}))
build.onLoad({ filter: /.*/, namespace: 'noop' }, () => ({
contents: 'export default {}',
}))
},
},
// Noop @ionic/utils-subprocess
{
name: 'noop-ionic-utils-subprocess',
setup(build) {
build.onResolve({ filter: /@ionic\/utils-subprocess/ }, args => ({
path: args.path,
namespace: 'noop',
}))
build.onLoad({ filter: /.*/, namespace: 'noop' }, () => ({
contents: 'export default {}',
}))
},
},
// Smarter noop for @ionic/cli-framework-output
{
name: 'smart-noop-ionic-cli-framework-output',
setup(build) {
build.onResolve({ filter: /@ionic\/cli-framework-output/ }, args => ({
path: args.path,
namespace: 'smart-noop-ionic-cli-framework-output',
}))
build.onLoad({ filter: /.*/, namespace: 'smart-noop-ionic-cli-framework-output' }, () => ({
contents: `
export const TTY_WIDTH = 80;
export const indent = (str) => str;
export const sliceAnsi = (str) => str;
export const stringWidth = (str) => str.length;
export const stripAnsi = (str) => str;
export const wordWrap = (str) => str;
export const createDefaultLogger = () => ({
info: console.log,
warn: console.warn,
error: console.error,
debug: console.debug,
});
export const NO_COLORS = {};
export class StreamOutputStrategy {
constructor() {
this.colors = NO_COLORS;
this.stream = process.stdout;
}
}
export class TTYOutputStrategy extends StreamOutputStrategy {
constructor(options) {
super();
this.options = options;
}
}
export class Logger {
constructor() {}
info() {}
warn() {}
error() {}
debug() {}
}
export const LOGGER_LEVELS = {
DEBUG: 'DEBUG',
INFO: 'INFO',
WARN: 'WARN',
ERROR: 'ERROR'
};
`,
}))
},
},
// Noop @supabase/realtime-js
{
name: 'noop-supabase-realtime-js',
setup(build) {
build.onResolve({ filter: /@supabase\/realtime-js/ }, args => ({
path: args.path,
namespace: 'noop-supabase-realtime-js',
}))
build.onLoad({ filter: /.*/, namespace: 'noop-supabase-realtime-js' }, () => ({
contents: `
export class RealtimeClient {
constructor() {}
connect() {}
disconnect() {}
}
`,
}))
},
},
],
}).catch(() => exit(1)).then((result) => {
writeFileSync('meta.json', JSON.stringify(result.metafile))
})