@donotdev/cli 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dependencies-matrix.json +100 -50
- package/dist/bin/commands/agent-setup.js +245 -12
- package/dist/bin/commands/build.js +3339 -208
- package/dist/bin/commands/bump.js +245 -12
- package/dist/bin/commands/cacheout.js +245 -12
- package/dist/bin/commands/coach.js +361 -60
- package/dist/bin/commands/create-app.js +245 -12
- package/dist/bin/commands/create-project.js +253 -12
- package/dist/bin/commands/db.js +9114 -2327
- package/dist/bin/commands/deploy.js +4074 -694
- package/dist/bin/commands/dev.js +347 -33
- package/dist/bin/commands/doctor.js +408 -107
- package/dist/bin/commands/emu.js +386 -52
- package/dist/bin/commands/format.js +245 -12
- package/dist/bin/commands/get-demo.js +245 -12
- package/dist/bin/commands/make-admin.js +8356 -1516
- package/dist/bin/commands/preview.js +347 -33
- package/dist/bin/commands/seed.js +9114 -2327
- package/dist/bin/commands/setup-cicd.js +452 -132
- package/dist/bin/commands/setup.js +407 -107
- package/dist/bin/commands/staging.js +4074 -694
- package/dist/bin/commands/sync-secrets.js +246 -13
- package/dist/bin/commands/type-check.js +245 -12
- package/dist/bin/commands/wai.js +245 -12
- package/dist/bin/dndev.js +13 -4
- package/dist/bin/donotdev.js +13 -4
- package/dist/index.js +4169 -812
- package/{templates/root-consumer/guides/dndev/advanced/VERSION_CONTROL.md.example → guidelines/VERSION_CONTROL.md} +7 -11
- package/package.json +2 -1
- package/templates/app-demo/src/themes.css.example +21 -0
- package/templates/app-dndev/index.html.example +0 -3
- package/templates/app-dndev/src/themes.css.example +21 -0
- package/templates/app-next/src/app/layout.tsx.example +13 -4
- package/templates/app-next/src/themes.css.example +21 -0
- package/templates/app-vite/csp.example.json +44 -0
- package/templates/app-vite/index.html.example +0 -3
- package/templates/app-vite/src/themes.css.example +21 -0
- package/templates/functions-supabase/supabase/migrations/20250101000000_idempotency.sql +3 -0
- package/templates/functions-supabase/supabase/migrations/20250101000001_rate_limits.sql +3 -0
- package/templates/functions-supabase/supabase/migrations/20250101000003_operation_metrics.sql +3 -0
- package/templates/root-consumer/.claude/hooks/framework-compliance.sh.example +56 -0
- package/templates/root-consumer/.claude/hooks/guard-bash.sh.example +61 -0
- package/templates/root-consumer/.claude/hooks/guard-files.sh.example +46 -0
- package/templates/root-consumer/.claude/hooks/guard-mcp.sh.example +91 -0
- package/templates/root-consumer/.claude/hooks/guard-secrets.sh.example +67 -0
- package/templates/root-consumer/.claude/hooks/guard-write.sh.example +89 -0
- package/templates/root-consumer/.claude/hooks/session-start.sh.example +50 -0
- package/templates/root-consumer/.claude/hooks/track-mcp-lookup.sh.example +20 -0
- package/templates/root-consumer/.claude/hooks/typecheck-stop.sh.example +18 -0
- package/templates/root-consumer/.claude/rules/consumer-ux.md.example +32 -0
- package/templates/root-consumer/.claude/rules/definition-of-done.md.example +32 -0
- package/templates/root-consumer/.claude/rules/framework.md.example +39 -0
- package/templates/root-consumer/.claude/rules/git.md.example +14 -0
- package/templates/root-consumer/.claude/rules/security.md.example +13 -0
- package/templates/root-consumer/.claude/settings.json.example +123 -1
- package/templates/root-consumer/.claude/skills/build/SKILL.md.example +103 -25
- package/templates/root-consumer/.claude/skills/grill/SKILL.md.example +26 -15
- package/templates/root-consumer/.claude/skills/polish/SKILL.md.example +50 -37
- package/templates/root-consumer/AI.md.example +2 -2
- package/templates/root-consumer/CLAUDE.md.example +33 -1
- package/templates/root-consumer/guides/dndev/INDEX.md.example +23 -27
- package/templates/root-consumer/guides/dndev/SETUP_AUTH.md.example +3 -2
- package/templates/root-consumer/guides/dndev/SETUP_OAUTH.md.example +10 -5
- package/templates/root-consumer/guides/dndev/SETUP_SUPABASE.md.example +50 -3
- package/templates/root-consumer/guides/wai-way/blueprints/3_compose.md.example +13 -15
- package/templates/app-demo/public/manifest.json.example +0 -10
- package/templates/app-dndev/public/manifest.json.example +0 -10
- package/templates/root-consumer/.claude/commands/brainstorm.md.example +0 -175
- package/templates/root-consumer/.claude/commands/build.md.example +0 -131
- package/templates/root-consumer/.claude/commands/design.md.example +0 -184
- package/templates/root-consumer/.claude/commands/grill.md.example +0 -135
- package/templates/root-consumer/.claude/commands/polish.md.example +0 -146
- package/templates/root-consumer/.claude/commands/techdebt.md.example +0 -28
- package/templates/root-consumer/guides/dndev/COMPONENTS_ATOMIC.md.example +0 -180
- package/templates/root-consumer/guides/dndev/COMPONENTS_CRUD.md.example +0 -234
- package/templates/root-consumer/guides/dndev/COMPONENTS_UI.md.example +0 -136
- package/templates/root-consumer/guides/dndev/COMPONENT_API.md.example +0 -195
- package/templates/root-consumer/guides/dndev/ENV_SETUP.md.example +0 -219
- package/templates/root-consumer/guides/dndev/GOTCHAS.md.example +0 -197
- package/templates/root-consumer/guides/dndev/SETUP_APP_CONFIG.md.example +0 -132
- package/templates/root-consumer/guides/dndev/SETUP_BLOG.md.example +0 -280
- package/templates/root-consumer/guides/dndev/SETUP_CICD.md.example +0 -115
- package/templates/root-consumer/guides/dndev/SETUP_CRUD.md.example +0 -334
- package/templates/root-consumer/guides/dndev/SETUP_FUNCTIONS.md.example +0 -9
- package/templates/root-consumer/guides/dndev/SETUP_I18N.md.example +0 -233
- package/templates/root-consumer/guides/dndev/SETUP_LAYOUTS.md.example +0 -158
- package/templates/root-consumer/guides/dndev/SETUP_PAGES.md.example +0 -205
- package/templates/root-consumer/guides/dndev/SETUP_PWA.md.example +0 -213
- package/templates/root-consumer/guides/dndev/SETUP_TESTING.md.example +0 -184
- package/templates/root-consumer/guides/dndev/SETUP_THEMES.md.example +0 -111
- package/templates/root-consumer/guides/dndev/SETUP_VERCEL.md.example +0 -260
- package/templates/root-consumer/guides/dndev/USE_ROUTING.md.example +0 -499
- package/templates/root-consumer/guides/dndev/essences_reference.css.example +0 -288
|
@@ -16,6 +16,10 @@ var __esm = (fn, res) => function __init() {
|
|
|
16
16
|
var __commonJS = (cb, mod) => function __require2() {
|
|
17
17
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
18
|
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
19
23
|
var __copyProps = (to, from, except, desc) => {
|
|
20
24
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
25
|
for (let key of __getOwnPropNames(from))
|
|
@@ -2394,14 +2398,15 @@ var require_braces = __commonJS({
|
|
|
2394
2398
|
}
|
|
2395
2399
|
});
|
|
2396
2400
|
|
|
2397
|
-
// node_modules/.bun/picomatch@2.3.
|
|
2401
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/constants.js
|
|
2398
2402
|
var require_constants2 = __commonJS({
|
|
2399
|
-
"node_modules/.bun/picomatch@2.3.
|
|
2403
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/constants.js"(exports, module) {
|
|
2400
2404
|
"use strict";
|
|
2401
2405
|
init_utils();
|
|
2402
2406
|
var path = __require("path");
|
|
2403
2407
|
var WIN_SLASH = "\\\\/";
|
|
2404
2408
|
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
2409
|
+
var DEFAULT_MAX_EXTGLOB_RECURSION = 0;
|
|
2405
2410
|
var DOT_LITERAL = "\\.";
|
|
2406
2411
|
var PLUS_LITERAL = "\\+";
|
|
2407
2412
|
var QMARK_LITERAL = "\\?";
|
|
@@ -2449,6 +2454,7 @@ var require_constants2 = __commonJS({
|
|
|
2449
2454
|
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
|
|
2450
2455
|
};
|
|
2451
2456
|
var POSIX_REGEX_SOURCE = {
|
|
2457
|
+
__proto__: null,
|
|
2452
2458
|
alnum: "a-zA-Z0-9",
|
|
2453
2459
|
alpha: "a-zA-Z",
|
|
2454
2460
|
ascii: "\\x00-\\x7F",
|
|
@@ -2465,6 +2471,7 @@ var require_constants2 = __commonJS({
|
|
|
2465
2471
|
xdigit: "A-Fa-f0-9"
|
|
2466
2472
|
};
|
|
2467
2473
|
module.exports = {
|
|
2474
|
+
DEFAULT_MAX_EXTGLOB_RECURSION,
|
|
2468
2475
|
MAX_LENGTH: 1024 * 64,
|
|
2469
2476
|
POSIX_REGEX_SOURCE,
|
|
2470
2477
|
// regular expressions
|
|
@@ -2476,6 +2483,7 @@ var require_constants2 = __commonJS({
|
|
|
2476
2483
|
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
2477
2484
|
// Replace globs with equivalent patterns to reduce parsing time.
|
|
2478
2485
|
REPLACEMENTS: {
|
|
2486
|
+
__proto__: null,
|
|
2479
2487
|
"***": "*",
|
|
2480
2488
|
"**/**": "**",
|
|
2481
2489
|
"**/**/**": "**"
|
|
@@ -2592,9 +2600,9 @@ var require_constants2 = __commonJS({
|
|
|
2592
2600
|
}
|
|
2593
2601
|
});
|
|
2594
2602
|
|
|
2595
|
-
// node_modules/.bun/picomatch@2.3.
|
|
2603
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/utils.js
|
|
2596
2604
|
var require_utils2 = __commonJS({
|
|
2597
|
-
"node_modules/.bun/picomatch@2.3.
|
|
2605
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/utils.js"(exports) {
|
|
2598
2606
|
"use strict";
|
|
2599
2607
|
init_utils();
|
|
2600
2608
|
var path = __require("path");
|
|
@@ -2654,9 +2662,9 @@ var require_utils2 = __commonJS({
|
|
|
2654
2662
|
}
|
|
2655
2663
|
});
|
|
2656
2664
|
|
|
2657
|
-
// node_modules/.bun/picomatch@2.3.
|
|
2665
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/scan.js
|
|
2658
2666
|
var require_scan = __commonJS({
|
|
2659
|
-
"node_modules/.bun/picomatch@2.3.
|
|
2667
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/scan.js"(exports, module) {
|
|
2660
2668
|
"use strict";
|
|
2661
2669
|
init_utils();
|
|
2662
2670
|
var utils = require_utils2();
|
|
@@ -2985,9 +2993,9 @@ var require_scan = __commonJS({
|
|
|
2985
2993
|
}
|
|
2986
2994
|
});
|
|
2987
2995
|
|
|
2988
|
-
// node_modules/.bun/picomatch@2.3.
|
|
2996
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/parse.js
|
|
2989
2997
|
var require_parse2 = __commonJS({
|
|
2990
|
-
"node_modules/.bun/picomatch@2.3.
|
|
2998
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/parse.js"(exports, module) {
|
|
2991
2999
|
"use strict";
|
|
2992
3000
|
init_utils();
|
|
2993
3001
|
var constants2 = require_constants2();
|
|
@@ -3015,6 +3023,213 @@ var require_parse2 = __commonJS({
|
|
|
3015
3023
|
var syntaxError = (type, char) => {
|
|
3016
3024
|
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
3017
3025
|
};
|
|
3026
|
+
var splitTopLevel = (input) => {
|
|
3027
|
+
const parts = [];
|
|
3028
|
+
let bracket = 0;
|
|
3029
|
+
let paren = 0;
|
|
3030
|
+
let quote = 0;
|
|
3031
|
+
let value = "";
|
|
3032
|
+
let escaped = false;
|
|
3033
|
+
for (const ch of input) {
|
|
3034
|
+
if (escaped === true) {
|
|
3035
|
+
value += ch;
|
|
3036
|
+
escaped = false;
|
|
3037
|
+
continue;
|
|
3038
|
+
}
|
|
3039
|
+
if (ch === "\\") {
|
|
3040
|
+
value += ch;
|
|
3041
|
+
escaped = true;
|
|
3042
|
+
continue;
|
|
3043
|
+
}
|
|
3044
|
+
if (ch === '"') {
|
|
3045
|
+
quote = quote === 1 ? 0 : 1;
|
|
3046
|
+
value += ch;
|
|
3047
|
+
continue;
|
|
3048
|
+
}
|
|
3049
|
+
if (quote === 0) {
|
|
3050
|
+
if (ch === "[") {
|
|
3051
|
+
bracket++;
|
|
3052
|
+
} else if (ch === "]" && bracket > 0) {
|
|
3053
|
+
bracket--;
|
|
3054
|
+
} else if (bracket === 0) {
|
|
3055
|
+
if (ch === "(") {
|
|
3056
|
+
paren++;
|
|
3057
|
+
} else if (ch === ")" && paren > 0) {
|
|
3058
|
+
paren--;
|
|
3059
|
+
} else if (ch === "|" && paren === 0) {
|
|
3060
|
+
parts.push(value);
|
|
3061
|
+
value = "";
|
|
3062
|
+
continue;
|
|
3063
|
+
}
|
|
3064
|
+
}
|
|
3065
|
+
}
|
|
3066
|
+
value += ch;
|
|
3067
|
+
}
|
|
3068
|
+
parts.push(value);
|
|
3069
|
+
return parts;
|
|
3070
|
+
};
|
|
3071
|
+
var isPlainBranch = (branch) => {
|
|
3072
|
+
let escaped = false;
|
|
3073
|
+
for (const ch of branch) {
|
|
3074
|
+
if (escaped === true) {
|
|
3075
|
+
escaped = false;
|
|
3076
|
+
continue;
|
|
3077
|
+
}
|
|
3078
|
+
if (ch === "\\") {
|
|
3079
|
+
escaped = true;
|
|
3080
|
+
continue;
|
|
3081
|
+
}
|
|
3082
|
+
if (/[?*+@!()[\]{}]/.test(ch)) {
|
|
3083
|
+
return false;
|
|
3084
|
+
}
|
|
3085
|
+
}
|
|
3086
|
+
return true;
|
|
3087
|
+
};
|
|
3088
|
+
var normalizeSimpleBranch = (branch) => {
|
|
3089
|
+
let value = branch.trim();
|
|
3090
|
+
let changed = true;
|
|
3091
|
+
while (changed === true) {
|
|
3092
|
+
changed = false;
|
|
3093
|
+
if (/^@\([^\\()[\]{}|]+\)$/.test(value)) {
|
|
3094
|
+
value = value.slice(2, -1);
|
|
3095
|
+
changed = true;
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
if (!isPlainBranch(value)) {
|
|
3099
|
+
return;
|
|
3100
|
+
}
|
|
3101
|
+
return value.replace(/\\(.)/g, "$1");
|
|
3102
|
+
};
|
|
3103
|
+
var hasRepeatedCharPrefixOverlap = (branches) => {
|
|
3104
|
+
const values = branches.map(normalizeSimpleBranch).filter(Boolean);
|
|
3105
|
+
for (let i = 0; i < values.length; i++) {
|
|
3106
|
+
for (let j2 = i + 1; j2 < values.length; j2++) {
|
|
3107
|
+
const a = values[i];
|
|
3108
|
+
const b3 = values[j2];
|
|
3109
|
+
const char = a[0];
|
|
3110
|
+
if (!char || a !== char.repeat(a.length) || b3 !== char.repeat(b3.length)) {
|
|
3111
|
+
continue;
|
|
3112
|
+
}
|
|
3113
|
+
if (a === b3 || a.startsWith(b3) || b3.startsWith(a)) {
|
|
3114
|
+
return true;
|
|
3115
|
+
}
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
return false;
|
|
3119
|
+
};
|
|
3120
|
+
var parseRepeatedExtglob = (pattern, requireEnd = true) => {
|
|
3121
|
+
if (pattern[0] !== "+" && pattern[0] !== "*" || pattern[1] !== "(") {
|
|
3122
|
+
return;
|
|
3123
|
+
}
|
|
3124
|
+
let bracket = 0;
|
|
3125
|
+
let paren = 0;
|
|
3126
|
+
let quote = 0;
|
|
3127
|
+
let escaped = false;
|
|
3128
|
+
for (let i = 1; i < pattern.length; i++) {
|
|
3129
|
+
const ch = pattern[i];
|
|
3130
|
+
if (escaped === true) {
|
|
3131
|
+
escaped = false;
|
|
3132
|
+
continue;
|
|
3133
|
+
}
|
|
3134
|
+
if (ch === "\\") {
|
|
3135
|
+
escaped = true;
|
|
3136
|
+
continue;
|
|
3137
|
+
}
|
|
3138
|
+
if (ch === '"') {
|
|
3139
|
+
quote = quote === 1 ? 0 : 1;
|
|
3140
|
+
continue;
|
|
3141
|
+
}
|
|
3142
|
+
if (quote === 1) {
|
|
3143
|
+
continue;
|
|
3144
|
+
}
|
|
3145
|
+
if (ch === "[") {
|
|
3146
|
+
bracket++;
|
|
3147
|
+
continue;
|
|
3148
|
+
}
|
|
3149
|
+
if (ch === "]" && bracket > 0) {
|
|
3150
|
+
bracket--;
|
|
3151
|
+
continue;
|
|
3152
|
+
}
|
|
3153
|
+
if (bracket > 0) {
|
|
3154
|
+
continue;
|
|
3155
|
+
}
|
|
3156
|
+
if (ch === "(") {
|
|
3157
|
+
paren++;
|
|
3158
|
+
continue;
|
|
3159
|
+
}
|
|
3160
|
+
if (ch === ")") {
|
|
3161
|
+
paren--;
|
|
3162
|
+
if (paren === 0) {
|
|
3163
|
+
if (requireEnd === true && i !== pattern.length - 1) {
|
|
3164
|
+
return;
|
|
3165
|
+
}
|
|
3166
|
+
return {
|
|
3167
|
+
type: pattern[0],
|
|
3168
|
+
body: pattern.slice(2, i),
|
|
3169
|
+
end: i
|
|
3170
|
+
};
|
|
3171
|
+
}
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
};
|
|
3175
|
+
var getStarExtglobSequenceOutput = (pattern) => {
|
|
3176
|
+
let index = 0;
|
|
3177
|
+
const chars = [];
|
|
3178
|
+
while (index < pattern.length) {
|
|
3179
|
+
const match = parseRepeatedExtglob(pattern.slice(index), false);
|
|
3180
|
+
if (!match || match.type !== "*") {
|
|
3181
|
+
return;
|
|
3182
|
+
}
|
|
3183
|
+
const branches = splitTopLevel(match.body).map((branch2) => branch2.trim());
|
|
3184
|
+
if (branches.length !== 1) {
|
|
3185
|
+
return;
|
|
3186
|
+
}
|
|
3187
|
+
const branch = normalizeSimpleBranch(branches[0]);
|
|
3188
|
+
if (!branch || branch.length !== 1) {
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3191
|
+
chars.push(branch);
|
|
3192
|
+
index += match.end + 1;
|
|
3193
|
+
}
|
|
3194
|
+
if (chars.length < 1) {
|
|
3195
|
+
return;
|
|
3196
|
+
}
|
|
3197
|
+
const source = chars.length === 1 ? utils.escapeRegex(chars[0]) : `[${chars.map((ch) => utils.escapeRegex(ch)).join("")}]`;
|
|
3198
|
+
return `${source}*`;
|
|
3199
|
+
};
|
|
3200
|
+
var repeatedExtglobRecursion = (pattern) => {
|
|
3201
|
+
let depth = 0;
|
|
3202
|
+
let value = pattern.trim();
|
|
3203
|
+
let match = parseRepeatedExtglob(value);
|
|
3204
|
+
while (match) {
|
|
3205
|
+
depth++;
|
|
3206
|
+
value = match.body.trim();
|
|
3207
|
+
match = parseRepeatedExtglob(value);
|
|
3208
|
+
}
|
|
3209
|
+
return depth;
|
|
3210
|
+
};
|
|
3211
|
+
var analyzeRepeatedExtglob = (body, options) => {
|
|
3212
|
+
if (options.maxExtglobRecursion === false) {
|
|
3213
|
+
return { risky: false };
|
|
3214
|
+
}
|
|
3215
|
+
const max = typeof options.maxExtglobRecursion === "number" ? options.maxExtglobRecursion : constants2.DEFAULT_MAX_EXTGLOB_RECURSION;
|
|
3216
|
+
const branches = splitTopLevel(body).map((branch) => branch.trim());
|
|
3217
|
+
if (branches.length > 1) {
|
|
3218
|
+
if (branches.some((branch) => branch === "") || branches.some((branch) => /^[*?]+$/.test(branch)) || hasRepeatedCharPrefixOverlap(branches)) {
|
|
3219
|
+
return { risky: true };
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
for (const branch of branches) {
|
|
3223
|
+
const safeOutput = getStarExtglobSequenceOutput(branch);
|
|
3224
|
+
if (safeOutput) {
|
|
3225
|
+
return { risky: true, safeOutput };
|
|
3226
|
+
}
|
|
3227
|
+
if (repeatedExtglobRecursion(branch) > max) {
|
|
3228
|
+
return { risky: true };
|
|
3229
|
+
}
|
|
3230
|
+
}
|
|
3231
|
+
return { risky: false };
|
|
3232
|
+
};
|
|
3018
3233
|
var parse2 = (input, options) => {
|
|
3019
3234
|
if (typeof input !== "string") {
|
|
3020
3235
|
throw new TypeError("Expected a string");
|
|
@@ -3146,6 +3361,8 @@ var require_parse2 = __commonJS({
|
|
|
3146
3361
|
token.prev = prev;
|
|
3147
3362
|
token.parens = state.parens;
|
|
3148
3363
|
token.output = state.output;
|
|
3364
|
+
token.startIndex = state.index;
|
|
3365
|
+
token.tokensIndex = tokens.length;
|
|
3149
3366
|
const output = (opts.capture ? "(" : "") + token.open;
|
|
3150
3367
|
increment("parens");
|
|
3151
3368
|
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
@@ -3153,6 +3370,26 @@ var require_parse2 = __commonJS({
|
|
|
3153
3370
|
extglobs.push(token);
|
|
3154
3371
|
};
|
|
3155
3372
|
const extglobClose = (token) => {
|
|
3373
|
+
const literal = input.slice(token.startIndex, state.index + 1);
|
|
3374
|
+
const body = input.slice(token.startIndex + 2, state.index);
|
|
3375
|
+
const analysis = analyzeRepeatedExtglob(body, opts);
|
|
3376
|
+
if ((token.type === "plus" || token.type === "star") && analysis.risky) {
|
|
3377
|
+
const safeOutput = analysis.safeOutput ? (token.output ? "" : ONE_CHAR) + (opts.capture ? `(${analysis.safeOutput})` : analysis.safeOutput) : void 0;
|
|
3378
|
+
const open = tokens[token.tokensIndex];
|
|
3379
|
+
open.type = "text";
|
|
3380
|
+
open.value = literal;
|
|
3381
|
+
open.output = safeOutput || utils.escapeRegex(literal);
|
|
3382
|
+
for (let i = token.tokensIndex + 1; i < tokens.length; i++) {
|
|
3383
|
+
tokens[i].value = "";
|
|
3384
|
+
tokens[i].output = "";
|
|
3385
|
+
delete tokens[i].suffix;
|
|
3386
|
+
}
|
|
3387
|
+
state.output = token.output + open.output;
|
|
3388
|
+
state.backtrack = true;
|
|
3389
|
+
push({ type: "paren", extglob: true, value, output: "" });
|
|
3390
|
+
decrement("parens");
|
|
3391
|
+
return;
|
|
3392
|
+
}
|
|
3156
3393
|
let output = token.close + (opts.capture ? ")" : "");
|
|
3157
3394
|
let rest;
|
|
3158
3395
|
if (token.type === "negate") {
|
|
@@ -3759,9 +3996,9 @@ var require_parse2 = __commonJS({
|
|
|
3759
3996
|
}
|
|
3760
3997
|
});
|
|
3761
3998
|
|
|
3762
|
-
// node_modules/.bun/picomatch@2.3.
|
|
3999
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/picomatch.js
|
|
3763
4000
|
var require_picomatch = __commonJS({
|
|
3764
|
-
"node_modules/.bun/picomatch@2.3.
|
|
4001
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/lib/picomatch.js"(exports, module) {
|
|
3765
4002
|
"use strict";
|
|
3766
4003
|
init_utils();
|
|
3767
4004
|
var path = __require("path");
|
|
@@ -3901,9 +4138,9 @@ var require_picomatch = __commonJS({
|
|
|
3901
4138
|
}
|
|
3902
4139
|
});
|
|
3903
4140
|
|
|
3904
|
-
// node_modules/.bun/picomatch@2.3.
|
|
4141
|
+
// node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/index.js
|
|
3905
4142
|
var require_picomatch2 = __commonJS({
|
|
3906
|
-
"node_modules/.bun/picomatch@2.3.
|
|
4143
|
+
"node_modules/.bun/picomatch@2.3.2/node_modules/picomatch/index.js"(exports, module) {
|
|
3907
4144
|
"use strict";
|
|
3908
4145
|
init_utils();
|
|
3909
4146
|
module.exports = require_picomatch();
|
|
@@ -4411,8 +4648,8 @@ var require_utils3 = __commonJS({
|
|
|
4411
4648
|
exports.array = array;
|
|
4412
4649
|
var errno = require_errno();
|
|
4413
4650
|
exports.errno = errno;
|
|
4414
|
-
var
|
|
4415
|
-
exports.fs =
|
|
4651
|
+
var fs3 = require_fs();
|
|
4652
|
+
exports.fs = fs3;
|
|
4416
4653
|
var path = require_path();
|
|
4417
4654
|
exports.path = path;
|
|
4418
4655
|
var pattern = require_pattern();
|
|
@@ -4600,12 +4837,12 @@ var require_fs2 = __commonJS({
|
|
|
4600
4837
|
init_utils();
|
|
4601
4838
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4602
4839
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
4603
|
-
var
|
|
4840
|
+
var fs3 = __require("fs");
|
|
4604
4841
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
4605
|
-
lstat:
|
|
4606
|
-
stat:
|
|
4607
|
-
lstatSync:
|
|
4608
|
-
statSync:
|
|
4842
|
+
lstat: fs3.lstat,
|
|
4843
|
+
stat: fs3.stat,
|
|
4844
|
+
lstatSync: fs3.lstatSync,
|
|
4845
|
+
statSync: fs3.statSync
|
|
4609
4846
|
};
|
|
4610
4847
|
function createFileSystemAdapter(fsMethods) {
|
|
4611
4848
|
if (fsMethods === void 0) {
|
|
@@ -4623,12 +4860,12 @@ var require_settings = __commonJS({
|
|
|
4623
4860
|
"use strict";
|
|
4624
4861
|
init_utils();
|
|
4625
4862
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4626
|
-
var
|
|
4863
|
+
var fs3 = require_fs2();
|
|
4627
4864
|
var Settings = class {
|
|
4628
4865
|
constructor(_options = {}) {
|
|
4629
4866
|
this._options = _options;
|
|
4630
4867
|
this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
|
|
4631
|
-
this.fs =
|
|
4868
|
+
this.fs = fs3.createFileSystemAdapter(this._options.fs);
|
|
4632
4869
|
this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
|
|
4633
4870
|
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
|
4634
4871
|
}
|
|
@@ -4789,8 +5026,8 @@ var require_utils4 = __commonJS({
|
|
|
4789
5026
|
init_utils();
|
|
4790
5027
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4791
5028
|
exports.fs = void 0;
|
|
4792
|
-
var
|
|
4793
|
-
exports.fs =
|
|
5029
|
+
var fs3 = require_fs3();
|
|
5030
|
+
exports.fs = fs3;
|
|
4794
5031
|
}
|
|
4795
5032
|
});
|
|
4796
5033
|
|
|
@@ -4989,14 +5226,14 @@ var require_fs4 = __commonJS({
|
|
|
4989
5226
|
init_utils();
|
|
4990
5227
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4991
5228
|
exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
|
|
4992
|
-
var
|
|
5229
|
+
var fs3 = __require("fs");
|
|
4993
5230
|
exports.FILE_SYSTEM_ADAPTER = {
|
|
4994
|
-
lstat:
|
|
4995
|
-
stat:
|
|
4996
|
-
lstatSync:
|
|
4997
|
-
statSync:
|
|
4998
|
-
readdir:
|
|
4999
|
-
readdirSync:
|
|
5231
|
+
lstat: fs3.lstat,
|
|
5232
|
+
stat: fs3.stat,
|
|
5233
|
+
lstatSync: fs3.lstatSync,
|
|
5234
|
+
statSync: fs3.statSync,
|
|
5235
|
+
readdir: fs3.readdir,
|
|
5236
|
+
readdirSync: fs3.readdirSync
|
|
5000
5237
|
};
|
|
5001
5238
|
function createFileSystemAdapter(fsMethods) {
|
|
5002
5239
|
if (fsMethods === void 0) {
|
|
@@ -5016,12 +5253,12 @@ var require_settings2 = __commonJS({
|
|
|
5016
5253
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5017
5254
|
var path = __require("path");
|
|
5018
5255
|
var fsStat = require_out();
|
|
5019
|
-
var
|
|
5256
|
+
var fs3 = require_fs4();
|
|
5020
5257
|
var Settings = class {
|
|
5021
5258
|
constructor(_options = {}) {
|
|
5022
5259
|
this._options = _options;
|
|
5023
5260
|
this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
|
|
5024
|
-
this.fs =
|
|
5261
|
+
this.fs = fs3.createFileSystemAdapter(this._options.fs);
|
|
5025
5262
|
this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path.sep);
|
|
5026
5263
|
this.stats = this._getValue(this._options.stats, false);
|
|
5027
5264
|
this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
|
|
@@ -5341,41 +5578,41 @@ var require_queue = __commonJS({
|
|
|
5341
5578
|
queue.drained = drained;
|
|
5342
5579
|
return queue;
|
|
5343
5580
|
function push(value) {
|
|
5344
|
-
var p2 = new Promise(function(
|
|
5581
|
+
var p2 = new Promise(function(resolve5, reject) {
|
|
5345
5582
|
pushCb(value, function(err, result) {
|
|
5346
5583
|
if (err) {
|
|
5347
5584
|
reject(err);
|
|
5348
5585
|
return;
|
|
5349
5586
|
}
|
|
5350
|
-
|
|
5587
|
+
resolve5(result);
|
|
5351
5588
|
});
|
|
5352
5589
|
});
|
|
5353
5590
|
p2.catch(noop);
|
|
5354
5591
|
return p2;
|
|
5355
5592
|
}
|
|
5356
5593
|
function unshift(value) {
|
|
5357
|
-
var p2 = new Promise(function(
|
|
5594
|
+
var p2 = new Promise(function(resolve5, reject) {
|
|
5358
5595
|
unshiftCb(value, function(err, result) {
|
|
5359
5596
|
if (err) {
|
|
5360
5597
|
reject(err);
|
|
5361
5598
|
return;
|
|
5362
5599
|
}
|
|
5363
|
-
|
|
5600
|
+
resolve5(result);
|
|
5364
5601
|
});
|
|
5365
5602
|
});
|
|
5366
5603
|
p2.catch(noop);
|
|
5367
5604
|
return p2;
|
|
5368
5605
|
}
|
|
5369
5606
|
function drained() {
|
|
5370
|
-
var p2 = new Promise(function(
|
|
5607
|
+
var p2 = new Promise(function(resolve5) {
|
|
5371
5608
|
process.nextTick(function() {
|
|
5372
5609
|
if (queue.idle()) {
|
|
5373
|
-
|
|
5610
|
+
resolve5();
|
|
5374
5611
|
} else {
|
|
5375
5612
|
var previousDrain = queue.drain;
|
|
5376
5613
|
queue.drain = function() {
|
|
5377
5614
|
if (typeof previousDrain === "function") previousDrain();
|
|
5378
|
-
|
|
5615
|
+
resolve5();
|
|
5379
5616
|
queue.drain = previousDrain;
|
|
5380
5617
|
};
|
|
5381
5618
|
}
|
|
@@ -5872,9 +6109,9 @@ var require_stream3 = __commonJS({
|
|
|
5872
6109
|
});
|
|
5873
6110
|
}
|
|
5874
6111
|
_getStat(filepath) {
|
|
5875
|
-
return new Promise((
|
|
6112
|
+
return new Promise((resolve5, reject) => {
|
|
5876
6113
|
this._stat(filepath, this._fsStatSettings, (error2, stats) => {
|
|
5877
|
-
return error2 === null ?
|
|
6114
|
+
return error2 === null ? resolve5(stats) : reject(error2);
|
|
5878
6115
|
});
|
|
5879
6116
|
});
|
|
5880
6117
|
}
|
|
@@ -5899,10 +6136,10 @@ var require_async5 = __commonJS({
|
|
|
5899
6136
|
this._readerStream = new stream_1.default(this._settings);
|
|
5900
6137
|
}
|
|
5901
6138
|
dynamic(root, options) {
|
|
5902
|
-
return new Promise((
|
|
6139
|
+
return new Promise((resolve5, reject) => {
|
|
5903
6140
|
this._walkAsync(root, options, (error2, entries) => {
|
|
5904
6141
|
if (error2 === null) {
|
|
5905
|
-
|
|
6142
|
+
resolve5(entries);
|
|
5906
6143
|
} else {
|
|
5907
6144
|
reject(error2);
|
|
5908
6145
|
}
|
|
@@ -5912,10 +6149,10 @@ var require_async5 = __commonJS({
|
|
|
5912
6149
|
async static(patterns, options) {
|
|
5913
6150
|
const entries = [];
|
|
5914
6151
|
const stream = this._readerStream.static(patterns, options);
|
|
5915
|
-
return new Promise((
|
|
6152
|
+
return new Promise((resolve5, reject) => {
|
|
5916
6153
|
stream.once("error", reject);
|
|
5917
6154
|
stream.on("data", (entry) => entries.push(entry));
|
|
5918
|
-
stream.once("end", () =>
|
|
6155
|
+
stream.once("end", () => resolve5(entries));
|
|
5919
6156
|
});
|
|
5920
6157
|
}
|
|
5921
6158
|
};
|
|
@@ -6429,16 +6666,16 @@ var require_settings4 = __commonJS({
|
|
|
6429
6666
|
init_utils();
|
|
6430
6667
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6431
6668
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
6432
|
-
var
|
|
6669
|
+
var fs3 = __require("fs");
|
|
6433
6670
|
var os = __require("os");
|
|
6434
6671
|
var CPU_COUNT = Math.max(os.cpus().length, 1);
|
|
6435
6672
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
|
|
6436
|
-
lstat:
|
|
6437
|
-
lstatSync:
|
|
6438
|
-
stat:
|
|
6439
|
-
statSync:
|
|
6440
|
-
readdir:
|
|
6441
|
-
readdirSync:
|
|
6673
|
+
lstat: fs3.lstat,
|
|
6674
|
+
lstatSync: fs3.lstatSync,
|
|
6675
|
+
stat: fs3.stat,
|
|
6676
|
+
statSync: fs3.statSync,
|
|
6677
|
+
readdir: fs3.readdir,
|
|
6678
|
+
readdirSync: fs3.readdirSync
|
|
6442
6679
|
};
|
|
6443
6680
|
var Settings = class {
|
|
6444
6681
|
constructor(_options = {}) {
|
|
@@ -7768,7 +8005,7 @@ import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
|
7768
8005
|
function readdirSync2(dirPath, options) {
|
|
7769
8006
|
return pathResolverInstance.readdirSync(dirPath, options);
|
|
7770
8007
|
}
|
|
7771
|
-
var pathResolverInstance, getRepoRoot, normalizePath, pathExists, readSync, statSync2, joinPath;
|
|
8008
|
+
var pathResolverInstance, getRepoRoot, resolvePackage, normalizePath, pathExists, readSync, statSync2, joinPath;
|
|
7772
8009
|
var init_pathResolver = __esm({
|
|
7773
8010
|
"packages/tooling/src/utils/pathResolver.ts"() {
|
|
7774
8011
|
"use strict";
|
|
@@ -7776,6 +8013,7 @@ var init_pathResolver = __esm({
|
|
|
7776
8013
|
init_PathResolver();
|
|
7777
8014
|
pathResolverInstance = PathResolver.getInstance({ debug: false });
|
|
7778
8015
|
getRepoRoot = () => pathResolverInstance.getRepoRoot();
|
|
8016
|
+
resolvePackage = (spec, from) => pathResolverInstance.resolvePackage(spec, from || null);
|
|
7779
8017
|
normalizePath = (...pathSegments) => {
|
|
7780
8018
|
return pathResolverInstance.normalizePath(join2(...pathSegments));
|
|
7781
8019
|
};
|
|
@@ -7862,6 +8100,18 @@ var init_utils = __esm({
|
|
|
7862
8100
|
});
|
|
7863
8101
|
|
|
7864
8102
|
// packages/tooling/src/utils/app-detection.ts
|
|
8103
|
+
function getFunctionsPath(app) {
|
|
8104
|
+
switch (app.functions) {
|
|
8105
|
+
case "firebase":
|
|
8106
|
+
return joinPath(app.path, "functions");
|
|
8107
|
+
case "supabase":
|
|
8108
|
+
return joinPath(app.path, "supabase", "functions");
|
|
8109
|
+
case "vercel":
|
|
8110
|
+
return joinPath(app.path, "api");
|
|
8111
|
+
default:
|
|
8112
|
+
return null;
|
|
8113
|
+
}
|
|
8114
|
+
}
|
|
7865
8115
|
function detectApps(projectRoot) {
|
|
7866
8116
|
const apps = [];
|
|
7867
8117
|
const appsDir = joinPath(projectRoot, "apps");
|
|
@@ -7917,37 +8167,118 @@ function analyzeApp(appPath, appName) {
|
|
|
7917
8167
|
} else if (pathExists(joinPath(appPath, "vite.config.ts")) || pathExists(joinPath(appPath, "vite.config.js")) || pathExists(joinPath(appPath, "vite.config.mjs")) || packageJson.dependencies?.vite || packageJson.devDependencies?.vite) {
|
|
7918
8168
|
framework = "vite";
|
|
7919
8169
|
}
|
|
7920
|
-
const
|
|
7921
|
-
const
|
|
7922
|
-
const
|
|
7923
|
-
|
|
7924
|
-
const
|
|
7925
|
-
|
|
7926
|
-
if (
|
|
7927
|
-
|
|
8170
|
+
const firebaseJsonPath = joinPath(appPath, "firebase.json");
|
|
8171
|
+
const hasFirebase = pathExists(firebaseJsonPath);
|
|
8172
|
+
const supabaseDir = joinPath(appPath, "supabase");
|
|
8173
|
+
const supabaseConfigPath = joinPath(supabaseDir, "config.toml");
|
|
8174
|
+
const hasSupabaseDep = !!(packageJson.dependencies?.["@donotdev/supabase"] || packageJson.dependencies?.["@supabase/supabase-js"]);
|
|
8175
|
+
let hasSupabase = pathExists(supabaseDir) || pathExists(supabaseConfigPath) || hasSupabaseDep;
|
|
8176
|
+
if (!hasSupabase) {
|
|
8177
|
+
try {
|
|
8178
|
+
const envPath = joinPath(appPath, ".env");
|
|
8179
|
+
if (pathExists(envPath)) {
|
|
8180
|
+
const envContent = readSync(envPath);
|
|
8181
|
+
if (envContent.match(/VITE_SUPABASE_URL=.+/)) {
|
|
8182
|
+
hasSupabase = true;
|
|
8183
|
+
}
|
|
8184
|
+
}
|
|
8185
|
+
} catch {
|
|
8186
|
+
}
|
|
8187
|
+
}
|
|
8188
|
+
let provider = "unknown";
|
|
8189
|
+
if (hasFirebase && hasSupabase) {
|
|
8190
|
+
provider = "both";
|
|
8191
|
+
} else if (hasFirebase) {
|
|
8192
|
+
provider = "firebase";
|
|
8193
|
+
} else if (hasSupabase) {
|
|
8194
|
+
provider = "supabase";
|
|
7928
8195
|
}
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
|
|
8196
|
+
let firebaseConfig;
|
|
8197
|
+
if (hasFirebase) {
|
|
8198
|
+
try {
|
|
8199
|
+
const config = readSync(firebaseJsonPath, { format: "json" });
|
|
8200
|
+
if (config && typeof config === "object") {
|
|
8201
|
+
const fb = config;
|
|
8202
|
+
firebaseConfig = {
|
|
8203
|
+
projectId: fb.projectId,
|
|
8204
|
+
hasHosting: !!fb.hosting,
|
|
8205
|
+
hasFunctions: !!fb.functions,
|
|
8206
|
+
hasFirestoreRules: !!fb.firestore?.rules,
|
|
8207
|
+
hasStorageRules: !!fb.storage?.rules
|
|
8208
|
+
};
|
|
8209
|
+
}
|
|
8210
|
+
} catch {
|
|
8211
|
+
firebaseConfig = {
|
|
8212
|
+
hasHosting: false,
|
|
8213
|
+
hasFunctions: false,
|
|
8214
|
+
hasFirestoreRules: false,
|
|
8215
|
+
hasStorageRules: false
|
|
8216
|
+
};
|
|
8217
|
+
}
|
|
8218
|
+
}
|
|
8219
|
+
const supabaseFunctionsDir = joinPath(supabaseDir, "functions");
|
|
8220
|
+
const supabaseMigrationsDir = joinPath(supabaseDir, "migrations");
|
|
8221
|
+
let supabaseConfig;
|
|
8222
|
+
if (hasSupabase) {
|
|
8223
|
+
let url;
|
|
8224
|
+
try {
|
|
8225
|
+
const envPath = joinPath(appPath, ".env");
|
|
8226
|
+
if (pathExists(envPath)) {
|
|
8227
|
+
const envContent = readSync(envPath);
|
|
8228
|
+
const urlMatch = envContent.match(/VITE_SUPABASE_URL=(.+)/);
|
|
8229
|
+
if (urlMatch && urlMatch[1]) {
|
|
8230
|
+
url = urlMatch[1].trim();
|
|
8231
|
+
}
|
|
8232
|
+
}
|
|
8233
|
+
} catch {
|
|
8234
|
+
}
|
|
8235
|
+
supabaseConfig = {
|
|
8236
|
+
url,
|
|
8237
|
+
hasFunctions: pathExists(supabaseFunctionsDir),
|
|
8238
|
+
hasMigrations: pathExists(supabaseMigrationsDir)
|
|
8239
|
+
};
|
|
8240
|
+
}
|
|
8241
|
+
let functions;
|
|
8242
|
+
if (hasFirebase && firebaseConfig?.hasFunctions) {
|
|
8243
|
+
const firebaseFunctionsDir = joinPath(appPath, "functions");
|
|
8244
|
+
const firebaseFunctionsStat = statSync2(firebaseFunctionsDir);
|
|
8245
|
+
if (pathExists(firebaseFunctionsDir) && (firebaseFunctionsStat?.isDirectory() ?? false)) {
|
|
8246
|
+
functions = "firebase";
|
|
8247
|
+
}
|
|
8248
|
+
}
|
|
8249
|
+
if (!functions && hasSupabase) {
|
|
8250
|
+
const sbFunctionsStat = statSync2(supabaseFunctionsDir);
|
|
8251
|
+
if (pathExists(supabaseFunctionsDir) && (sbFunctionsStat?.isDirectory() ?? false)) {
|
|
8252
|
+
functions = "supabase";
|
|
7934
8253
|
}
|
|
7935
8254
|
}
|
|
7936
|
-
if (!
|
|
8255
|
+
if (!functions) {
|
|
7937
8256
|
const vercelJsonPath = joinPath(appPath, "vercel.json");
|
|
7938
|
-
|
|
7939
|
-
|
|
8257
|
+
const apiDir = joinPath(appPath, "api");
|
|
8258
|
+
const apiDirStat = statSync2(apiDir);
|
|
8259
|
+
if (pathExists(vercelJsonPath) && pathExists(apiDir) && (apiDirStat?.isDirectory() ?? false)) {
|
|
8260
|
+
functions = "vercel";
|
|
8261
|
+
}
|
|
8262
|
+
}
|
|
8263
|
+
let hosting;
|
|
8264
|
+
if (hasFirebase && firebaseConfig?.hasHosting) {
|
|
8265
|
+
hosting = "firebase";
|
|
8266
|
+
}
|
|
8267
|
+
if (!hosting) {
|
|
8268
|
+
if (pathExists(joinPath(appPath, "vercel.json")) || pathExists(joinPath(appPath, ".vercel"))) {
|
|
8269
|
+
hosting = "vercel";
|
|
7940
8270
|
}
|
|
7941
8271
|
}
|
|
7942
8272
|
return {
|
|
7943
8273
|
name: appName,
|
|
7944
8274
|
packageName: packageJson.name || appName,
|
|
7945
8275
|
path: appPath,
|
|
7946
|
-
packageJsonPath,
|
|
7947
8276
|
framework,
|
|
7948
|
-
|
|
7949
|
-
|
|
7950
|
-
|
|
8277
|
+
provider,
|
|
8278
|
+
functions,
|
|
8279
|
+
hosting,
|
|
8280
|
+
firebaseConfig,
|
|
8281
|
+
supabaseConfig
|
|
7951
8282
|
};
|
|
7952
8283
|
}
|
|
7953
8284
|
var init_app_detection = __esm({
|
|
@@ -7985,7 +8316,7 @@ async function selectApp(projectRoot, appName) {
|
|
|
7985
8316
|
message: "Select app:",
|
|
7986
8317
|
options: apps.map((app) => ({
|
|
7987
8318
|
value: app.name,
|
|
7988
|
-
label: `${app.name} (${app.framework === "nextjs" ? "Next.js" : "Vite"}${app.
|
|
8319
|
+
label: `${app.name} (${app.framework === "nextjs" ? "Next.js" : "Vite"}${app.functions ? ` + ${app.functions} functions` : ""})`
|
|
7989
8320
|
}))
|
|
7990
8321
|
});
|
|
7991
8322
|
if (typeof selected !== "string") {
|
|
@@ -8029,120 +8360,2909 @@ var init_cli_input = __esm({
|
|
|
8029
8360
|
}
|
|
8030
8361
|
});
|
|
8031
8362
|
|
|
8032
|
-
//
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
|
|
8036
|
-
init_utils();
|
|
8037
|
-
|
|
8038
|
-
|
|
8039
|
-
|
|
8040
|
-
|
|
8041
|
-
|
|
8042
|
-
|
|
8043
|
-
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8049
|
-
|
|
8050
|
-
|
|
8051
|
-
|
|
8052
|
-
|
|
8053
|
-
|
|
8054
|
-
|
|
8055
|
-
|
|
8056
|
-
|
|
8057
|
-
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8062
|
-
|
|
8063
|
-
|
|
8363
|
+
// node_modules/.bun/esbuild@0.27.4/node_modules/esbuild/lib/main.js
|
|
8364
|
+
var require_main = __commonJS({
|
|
8365
|
+
"node_modules/.bun/esbuild@0.27.4/node_modules/esbuild/lib/main.js"(exports, module) {
|
|
8366
|
+
"use strict";
|
|
8367
|
+
init_utils();
|
|
8368
|
+
var __defProp2 = Object.defineProperty;
|
|
8369
|
+
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
8370
|
+
var __getOwnPropNames2 = Object.getOwnPropertyNames;
|
|
8371
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
8372
|
+
var __export2 = (target, all) => {
|
|
8373
|
+
for (var name in all)
|
|
8374
|
+
__defProp2(target, name, { get: all[name], enumerable: true });
|
|
8375
|
+
};
|
|
8376
|
+
var __copyProps2 = (to, from, except, desc) => {
|
|
8377
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8378
|
+
for (let key of __getOwnPropNames2(from))
|
|
8379
|
+
if (!__hasOwnProp2.call(to, key) && key !== except)
|
|
8380
|
+
__defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
|
|
8381
|
+
}
|
|
8382
|
+
return to;
|
|
8383
|
+
};
|
|
8384
|
+
var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
|
|
8385
|
+
var node_exports = {};
|
|
8386
|
+
__export2(node_exports, {
|
|
8387
|
+
analyzeMetafile: () => analyzeMetafile,
|
|
8388
|
+
analyzeMetafileSync: () => analyzeMetafileSync,
|
|
8389
|
+
build: () => build2,
|
|
8390
|
+
buildSync: () => buildSync,
|
|
8391
|
+
context: () => context,
|
|
8392
|
+
default: () => node_default,
|
|
8393
|
+
formatMessages: () => formatMessages,
|
|
8394
|
+
formatMessagesSync: () => formatMessagesSync,
|
|
8395
|
+
initialize: () => initialize,
|
|
8396
|
+
stop: () => stop,
|
|
8397
|
+
transform: () => transform,
|
|
8398
|
+
transformSync: () => transformSync,
|
|
8399
|
+
version: () => version
|
|
8400
|
+
});
|
|
8401
|
+
module.exports = __toCommonJS(node_exports);
|
|
8402
|
+
function encodePacket(packet) {
|
|
8403
|
+
let visit = (value) => {
|
|
8404
|
+
if (value === null) {
|
|
8405
|
+
bb.write8(0);
|
|
8406
|
+
} else if (typeof value === "boolean") {
|
|
8407
|
+
bb.write8(1);
|
|
8408
|
+
bb.write8(+value);
|
|
8409
|
+
} else if (typeof value === "number") {
|
|
8410
|
+
bb.write8(2);
|
|
8411
|
+
bb.write32(value | 0);
|
|
8412
|
+
} else if (typeof value === "string") {
|
|
8413
|
+
bb.write8(3);
|
|
8414
|
+
bb.write(encodeUTF8(value));
|
|
8415
|
+
} else if (value instanceof Uint8Array) {
|
|
8416
|
+
bb.write8(4);
|
|
8417
|
+
bb.write(value);
|
|
8418
|
+
} else if (value instanceof Array) {
|
|
8419
|
+
bb.write8(5);
|
|
8420
|
+
bb.write32(value.length);
|
|
8421
|
+
for (let item of value) {
|
|
8422
|
+
visit(item);
|
|
8423
|
+
}
|
|
8424
|
+
} else {
|
|
8425
|
+
let keys = Object.keys(value);
|
|
8426
|
+
bb.write8(6);
|
|
8427
|
+
bb.write32(keys.length);
|
|
8428
|
+
for (let key of keys) {
|
|
8429
|
+
bb.write(encodeUTF8(key));
|
|
8430
|
+
visit(value[key]);
|
|
8431
|
+
}
|
|
8432
|
+
}
|
|
8433
|
+
};
|
|
8434
|
+
let bb = new ByteBuffer();
|
|
8435
|
+
bb.write32(0);
|
|
8436
|
+
bb.write32(packet.id << 1 | +!packet.isRequest);
|
|
8437
|
+
visit(packet.value);
|
|
8438
|
+
writeUInt32LE(bb.buf, bb.len - 4, 0);
|
|
8439
|
+
return bb.buf.subarray(0, bb.len);
|
|
8440
|
+
}
|
|
8441
|
+
function decodePacket(bytes) {
|
|
8442
|
+
let visit = () => {
|
|
8443
|
+
switch (bb.read8()) {
|
|
8444
|
+
case 0:
|
|
8445
|
+
return null;
|
|
8446
|
+
case 1:
|
|
8447
|
+
return !!bb.read8();
|
|
8448
|
+
case 2:
|
|
8449
|
+
return bb.read32();
|
|
8450
|
+
case 3:
|
|
8451
|
+
return decodeUTF8(bb.read());
|
|
8452
|
+
case 4:
|
|
8453
|
+
return bb.read();
|
|
8454
|
+
case 5: {
|
|
8455
|
+
let count = bb.read32();
|
|
8456
|
+
let value2 = [];
|
|
8457
|
+
for (let i = 0; i < count; i++) {
|
|
8458
|
+
value2.push(visit());
|
|
8459
|
+
}
|
|
8460
|
+
return value2;
|
|
8461
|
+
}
|
|
8462
|
+
case 6: {
|
|
8463
|
+
let count = bb.read32();
|
|
8464
|
+
let value2 = {};
|
|
8465
|
+
for (let i = 0; i < count; i++) {
|
|
8466
|
+
value2[decodeUTF8(bb.read())] = visit();
|
|
8467
|
+
}
|
|
8468
|
+
return value2;
|
|
8469
|
+
}
|
|
8470
|
+
default:
|
|
8471
|
+
throw new Error("Invalid packet");
|
|
8472
|
+
}
|
|
8473
|
+
};
|
|
8474
|
+
let bb = new ByteBuffer(bytes);
|
|
8475
|
+
let id = bb.read32();
|
|
8476
|
+
let isRequest = (id & 1) === 0;
|
|
8477
|
+
id >>>= 1;
|
|
8478
|
+
let value = visit();
|
|
8479
|
+
if (bb.ptr !== bytes.length) {
|
|
8480
|
+
throw new Error("Invalid packet");
|
|
8481
|
+
}
|
|
8482
|
+
return { id, isRequest, value };
|
|
8064
8483
|
}
|
|
8065
|
-
|
|
8066
|
-
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8077
|
-
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8082
|
-
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8484
|
+
var ByteBuffer = class {
|
|
8485
|
+
constructor(buf = new Uint8Array(1024)) {
|
|
8486
|
+
this.buf = buf;
|
|
8487
|
+
this.len = 0;
|
|
8488
|
+
this.ptr = 0;
|
|
8489
|
+
}
|
|
8490
|
+
_write(delta) {
|
|
8491
|
+
if (this.len + delta > this.buf.length) {
|
|
8492
|
+
let clone = new Uint8Array((this.len + delta) * 2);
|
|
8493
|
+
clone.set(this.buf);
|
|
8494
|
+
this.buf = clone;
|
|
8495
|
+
}
|
|
8496
|
+
this.len += delta;
|
|
8497
|
+
return this.len - delta;
|
|
8498
|
+
}
|
|
8499
|
+
write8(value) {
|
|
8500
|
+
let offset = this._write(1);
|
|
8501
|
+
this.buf[offset] = value;
|
|
8502
|
+
}
|
|
8503
|
+
write32(value) {
|
|
8504
|
+
let offset = this._write(4);
|
|
8505
|
+
writeUInt32LE(this.buf, value, offset);
|
|
8506
|
+
}
|
|
8507
|
+
write(bytes) {
|
|
8508
|
+
let offset = this._write(4 + bytes.length);
|
|
8509
|
+
writeUInt32LE(this.buf, bytes.length, offset);
|
|
8510
|
+
this.buf.set(bytes, offset + 4);
|
|
8511
|
+
}
|
|
8512
|
+
_read(delta) {
|
|
8513
|
+
if (this.ptr + delta > this.buf.length) {
|
|
8514
|
+
throw new Error("Invalid packet");
|
|
8515
|
+
}
|
|
8516
|
+
this.ptr += delta;
|
|
8517
|
+
return this.ptr - delta;
|
|
8518
|
+
}
|
|
8519
|
+
read8() {
|
|
8520
|
+
return this.buf[this._read(1)];
|
|
8521
|
+
}
|
|
8522
|
+
read32() {
|
|
8523
|
+
return readUInt32LE(this.buf, this._read(4));
|
|
8524
|
+
}
|
|
8525
|
+
read() {
|
|
8526
|
+
let length = this.read32();
|
|
8527
|
+
let bytes = new Uint8Array(length);
|
|
8528
|
+
let ptr = this._read(bytes.length);
|
|
8529
|
+
bytes.set(this.buf.subarray(ptr, ptr + length));
|
|
8530
|
+
return bytes;
|
|
8531
|
+
}
|
|
8532
|
+
};
|
|
8533
|
+
var encodeUTF8;
|
|
8534
|
+
var decodeUTF8;
|
|
8535
|
+
var encodeInvariant;
|
|
8536
|
+
if (typeof TextEncoder !== "undefined" && typeof TextDecoder !== "undefined") {
|
|
8537
|
+
let encoder = new TextEncoder();
|
|
8538
|
+
let decoder = new TextDecoder();
|
|
8539
|
+
encodeUTF8 = (text) => encoder.encode(text);
|
|
8540
|
+
decodeUTF8 = (bytes) => decoder.decode(bytes);
|
|
8541
|
+
encodeInvariant = 'new TextEncoder().encode("")';
|
|
8542
|
+
} else if (typeof Buffer !== "undefined") {
|
|
8543
|
+
encodeUTF8 = (text) => Buffer.from(text);
|
|
8544
|
+
decodeUTF8 = (bytes) => {
|
|
8545
|
+
let { buffer, byteOffset, byteLength } = bytes;
|
|
8546
|
+
return Buffer.from(buffer, byteOffset, byteLength).toString();
|
|
8091
8547
|
};
|
|
8548
|
+
encodeInvariant = 'Buffer.from("")';
|
|
8549
|
+
} else {
|
|
8550
|
+
throw new Error("No UTF-8 codec found");
|
|
8092
8551
|
}
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8097
|
-
|
|
8098
|
-
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8104
|
-
|
|
8105
|
-
|
|
8106
|
-
|
|
8107
|
-
|
|
8108
|
-
|
|
8109
|
-
|
|
8110
|
-
|
|
8111
|
-
|
|
8112
|
-
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8117
|
-
|
|
8118
|
-
|
|
8119
|
-
|
|
8120
|
-
|
|
8121
|
-
} else if (typePart === "func" || typePart === "functions") {
|
|
8122
|
-
result.buildType = "functions";
|
|
8123
|
-
} else if (typePart === "both") {
|
|
8124
|
-
result.buildType = "both";
|
|
8552
|
+
if (!(encodeUTF8("") instanceof Uint8Array))
|
|
8553
|
+
throw new Error(`Invariant violation: "${encodeInvariant} instanceof Uint8Array" is incorrectly false
|
|
8554
|
+
|
|
8555
|
+
This indicates that your JavaScript environment is broken. You cannot use
|
|
8556
|
+
esbuild in this environment because esbuild relies on this invariant. This
|
|
8557
|
+
is not a problem with esbuild. You need to fix your environment instead.
|
|
8558
|
+
`);
|
|
8559
|
+
function readUInt32LE(buffer, offset) {
|
|
8560
|
+
return (buffer[offset++] | buffer[offset++] << 8 | buffer[offset++] << 16 | buffer[offset++] << 24) >>> 0;
|
|
8561
|
+
}
|
|
8562
|
+
function writeUInt32LE(buffer, value, offset) {
|
|
8563
|
+
buffer[offset++] = value;
|
|
8564
|
+
buffer[offset++] = value >> 8;
|
|
8565
|
+
buffer[offset++] = value >> 16;
|
|
8566
|
+
buffer[offset++] = value >> 24;
|
|
8567
|
+
}
|
|
8568
|
+
var fromCharCode = String.fromCharCode;
|
|
8569
|
+
function throwSyntaxError(bytes, index, message) {
|
|
8570
|
+
const c = bytes[index];
|
|
8571
|
+
let line = 1;
|
|
8572
|
+
let column = 0;
|
|
8573
|
+
for (let i = 0; i < index; i++) {
|
|
8574
|
+
if (bytes[i] === 10) {
|
|
8575
|
+
line++;
|
|
8576
|
+
column = 0;
|
|
8577
|
+
} else {
|
|
8578
|
+
column++;
|
|
8579
|
+
}
|
|
8125
8580
|
}
|
|
8126
|
-
|
|
8127
|
-
|
|
8581
|
+
throw new SyntaxError(
|
|
8582
|
+
message ? message : index === bytes.length ? "Unexpected end of input while parsing JSON" : c >= 32 && c <= 126 ? `Unexpected character ${fromCharCode(c)} in JSON at position ${index} (line ${line}, column ${column})` : `Unexpected byte 0x${c.toString(16)} in JSON at position ${index} (line ${line}, column ${column})`
|
|
8583
|
+
);
|
|
8128
8584
|
}
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
|
|
8140
|
-
|
|
8141
|
-
|
|
8142
|
-
|
|
8143
|
-
|
|
8144
|
-
|
|
8145
|
-
|
|
8585
|
+
function JSON_parse(bytes) {
|
|
8586
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
8587
|
+
throw new Error(`JSON input must be a Uint8Array`);
|
|
8588
|
+
}
|
|
8589
|
+
const propertyStack = [];
|
|
8590
|
+
const objectStack = [];
|
|
8591
|
+
const stateStack = [];
|
|
8592
|
+
const length = bytes.length;
|
|
8593
|
+
let property = null;
|
|
8594
|
+
let state = 0;
|
|
8595
|
+
let object;
|
|
8596
|
+
let i = 0;
|
|
8597
|
+
while (i < length) {
|
|
8598
|
+
let c = bytes[i++];
|
|
8599
|
+
if (c <= 32) {
|
|
8600
|
+
continue;
|
|
8601
|
+
}
|
|
8602
|
+
let value;
|
|
8603
|
+
if (state === 2 && property === null && c !== 34 && c !== 125) {
|
|
8604
|
+
throwSyntaxError(bytes, --i);
|
|
8605
|
+
}
|
|
8606
|
+
switch (c) {
|
|
8607
|
+
// True
|
|
8608
|
+
case 116: {
|
|
8609
|
+
if (bytes[i++] !== 114 || bytes[i++] !== 117 || bytes[i++] !== 101) {
|
|
8610
|
+
throwSyntaxError(bytes, --i);
|
|
8611
|
+
}
|
|
8612
|
+
value = true;
|
|
8613
|
+
break;
|
|
8614
|
+
}
|
|
8615
|
+
// False
|
|
8616
|
+
case 102: {
|
|
8617
|
+
if (bytes[i++] !== 97 || bytes[i++] !== 108 || bytes[i++] !== 115 || bytes[i++] !== 101) {
|
|
8618
|
+
throwSyntaxError(bytes, --i);
|
|
8619
|
+
}
|
|
8620
|
+
value = false;
|
|
8621
|
+
break;
|
|
8622
|
+
}
|
|
8623
|
+
// Null
|
|
8624
|
+
case 110: {
|
|
8625
|
+
if (bytes[i++] !== 117 || bytes[i++] !== 108 || bytes[i++] !== 108) {
|
|
8626
|
+
throwSyntaxError(bytes, --i);
|
|
8627
|
+
}
|
|
8628
|
+
value = null;
|
|
8629
|
+
break;
|
|
8630
|
+
}
|
|
8631
|
+
// Number begin
|
|
8632
|
+
case 45:
|
|
8633
|
+
case 46:
|
|
8634
|
+
case 48:
|
|
8635
|
+
case 49:
|
|
8636
|
+
case 50:
|
|
8637
|
+
case 51:
|
|
8638
|
+
case 52:
|
|
8639
|
+
case 53:
|
|
8640
|
+
case 54:
|
|
8641
|
+
case 55:
|
|
8642
|
+
case 56:
|
|
8643
|
+
case 57: {
|
|
8644
|
+
let index = i;
|
|
8645
|
+
value = fromCharCode(c);
|
|
8646
|
+
c = bytes[i];
|
|
8647
|
+
while (true) {
|
|
8648
|
+
switch (c) {
|
|
8649
|
+
case 43:
|
|
8650
|
+
case 45:
|
|
8651
|
+
case 46:
|
|
8652
|
+
case 48:
|
|
8653
|
+
case 49:
|
|
8654
|
+
case 50:
|
|
8655
|
+
case 51:
|
|
8656
|
+
case 52:
|
|
8657
|
+
case 53:
|
|
8658
|
+
case 54:
|
|
8659
|
+
case 55:
|
|
8660
|
+
case 56:
|
|
8661
|
+
case 57:
|
|
8662
|
+
case 101:
|
|
8663
|
+
case 69: {
|
|
8664
|
+
value += fromCharCode(c);
|
|
8665
|
+
c = bytes[++i];
|
|
8666
|
+
continue;
|
|
8667
|
+
}
|
|
8668
|
+
}
|
|
8669
|
+
break;
|
|
8670
|
+
}
|
|
8671
|
+
value = +value;
|
|
8672
|
+
if (isNaN(value)) {
|
|
8673
|
+
throwSyntaxError(bytes, --index, "Invalid number");
|
|
8674
|
+
}
|
|
8675
|
+
break;
|
|
8676
|
+
}
|
|
8677
|
+
// String begin
|
|
8678
|
+
case 34: {
|
|
8679
|
+
value = "";
|
|
8680
|
+
while (true) {
|
|
8681
|
+
if (i >= length) {
|
|
8682
|
+
throwSyntaxError(bytes, length);
|
|
8683
|
+
}
|
|
8684
|
+
c = bytes[i++];
|
|
8685
|
+
if (c === 34) {
|
|
8686
|
+
break;
|
|
8687
|
+
} else if (c === 92) {
|
|
8688
|
+
switch (bytes[i++]) {
|
|
8689
|
+
// Normal escape sequence
|
|
8690
|
+
case 34:
|
|
8691
|
+
value += '"';
|
|
8692
|
+
break;
|
|
8693
|
+
case 47:
|
|
8694
|
+
value += "/";
|
|
8695
|
+
break;
|
|
8696
|
+
case 92:
|
|
8697
|
+
value += "\\";
|
|
8698
|
+
break;
|
|
8699
|
+
case 98:
|
|
8700
|
+
value += "\b";
|
|
8701
|
+
break;
|
|
8702
|
+
case 102:
|
|
8703
|
+
value += "\f";
|
|
8704
|
+
break;
|
|
8705
|
+
case 110:
|
|
8706
|
+
value += "\n";
|
|
8707
|
+
break;
|
|
8708
|
+
case 114:
|
|
8709
|
+
value += "\r";
|
|
8710
|
+
break;
|
|
8711
|
+
case 116:
|
|
8712
|
+
value += " ";
|
|
8713
|
+
break;
|
|
8714
|
+
// Unicode escape sequence
|
|
8715
|
+
case 117: {
|
|
8716
|
+
let code = 0;
|
|
8717
|
+
for (let j2 = 0; j2 < 4; j2++) {
|
|
8718
|
+
c = bytes[i++];
|
|
8719
|
+
code <<= 4;
|
|
8720
|
+
if (c >= 48 && c <= 57) code |= c - 48;
|
|
8721
|
+
else if (c >= 97 && c <= 102) code |= c + (10 - 97);
|
|
8722
|
+
else if (c >= 65 && c <= 70) code |= c + (10 - 65);
|
|
8723
|
+
else throwSyntaxError(bytes, --i);
|
|
8724
|
+
}
|
|
8725
|
+
value += fromCharCode(code);
|
|
8726
|
+
break;
|
|
8727
|
+
}
|
|
8728
|
+
// Invalid escape sequence
|
|
8729
|
+
default:
|
|
8730
|
+
throwSyntaxError(bytes, --i);
|
|
8731
|
+
break;
|
|
8732
|
+
}
|
|
8733
|
+
} else if (c <= 127) {
|
|
8734
|
+
value += fromCharCode(c);
|
|
8735
|
+
} else if ((c & 224) === 192) {
|
|
8736
|
+
value += fromCharCode((c & 31) << 6 | bytes[i++] & 63);
|
|
8737
|
+
} else if ((c & 240) === 224) {
|
|
8738
|
+
value += fromCharCode((c & 15) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63);
|
|
8739
|
+
} else if ((c & 248) == 240) {
|
|
8740
|
+
let codePoint = (c & 7) << 18 | (bytes[i++] & 63) << 12 | (bytes[i++] & 63) << 6 | bytes[i++] & 63;
|
|
8741
|
+
if (codePoint > 65535) {
|
|
8742
|
+
codePoint -= 65536;
|
|
8743
|
+
value += fromCharCode(codePoint >> 10 & 1023 | 55296);
|
|
8744
|
+
codePoint = 56320 | codePoint & 1023;
|
|
8745
|
+
}
|
|
8746
|
+
value += fromCharCode(codePoint);
|
|
8747
|
+
}
|
|
8748
|
+
}
|
|
8749
|
+
value[0];
|
|
8750
|
+
break;
|
|
8751
|
+
}
|
|
8752
|
+
// Array begin
|
|
8753
|
+
case 91: {
|
|
8754
|
+
value = [];
|
|
8755
|
+
propertyStack.push(property);
|
|
8756
|
+
objectStack.push(object);
|
|
8757
|
+
stateStack.push(state);
|
|
8758
|
+
property = null;
|
|
8759
|
+
object = value;
|
|
8760
|
+
state = 1;
|
|
8761
|
+
continue;
|
|
8762
|
+
}
|
|
8763
|
+
// Object begin
|
|
8764
|
+
case 123: {
|
|
8765
|
+
value = {};
|
|
8766
|
+
propertyStack.push(property);
|
|
8767
|
+
objectStack.push(object);
|
|
8768
|
+
stateStack.push(state);
|
|
8769
|
+
property = null;
|
|
8770
|
+
object = value;
|
|
8771
|
+
state = 2;
|
|
8772
|
+
continue;
|
|
8773
|
+
}
|
|
8774
|
+
// Array end
|
|
8775
|
+
case 93: {
|
|
8776
|
+
if (state !== 1) {
|
|
8777
|
+
throwSyntaxError(bytes, --i);
|
|
8778
|
+
}
|
|
8779
|
+
value = object;
|
|
8780
|
+
property = propertyStack.pop();
|
|
8781
|
+
object = objectStack.pop();
|
|
8782
|
+
state = stateStack.pop();
|
|
8783
|
+
break;
|
|
8784
|
+
}
|
|
8785
|
+
// Object end
|
|
8786
|
+
case 125: {
|
|
8787
|
+
if (state !== 2) {
|
|
8788
|
+
throwSyntaxError(bytes, --i);
|
|
8789
|
+
}
|
|
8790
|
+
value = object;
|
|
8791
|
+
property = propertyStack.pop();
|
|
8792
|
+
object = objectStack.pop();
|
|
8793
|
+
state = stateStack.pop();
|
|
8794
|
+
break;
|
|
8795
|
+
}
|
|
8796
|
+
default: {
|
|
8797
|
+
throwSyntaxError(bytes, --i);
|
|
8798
|
+
}
|
|
8799
|
+
}
|
|
8800
|
+
c = bytes[i];
|
|
8801
|
+
while (c <= 32) {
|
|
8802
|
+
c = bytes[++i];
|
|
8803
|
+
}
|
|
8804
|
+
switch (state) {
|
|
8805
|
+
case 0: {
|
|
8806
|
+
if (i === length) {
|
|
8807
|
+
return value;
|
|
8808
|
+
}
|
|
8809
|
+
break;
|
|
8810
|
+
}
|
|
8811
|
+
case 1: {
|
|
8812
|
+
object.push(value);
|
|
8813
|
+
if (c === 44) {
|
|
8814
|
+
i++;
|
|
8815
|
+
continue;
|
|
8816
|
+
}
|
|
8817
|
+
if (c === 93) {
|
|
8818
|
+
continue;
|
|
8819
|
+
}
|
|
8820
|
+
break;
|
|
8821
|
+
}
|
|
8822
|
+
case 2: {
|
|
8823
|
+
if (property === null) {
|
|
8824
|
+
property = value;
|
|
8825
|
+
if (c === 58) {
|
|
8826
|
+
i++;
|
|
8827
|
+
continue;
|
|
8828
|
+
}
|
|
8829
|
+
} else {
|
|
8830
|
+
object[property] = value;
|
|
8831
|
+
property = null;
|
|
8832
|
+
if (c === 44) {
|
|
8833
|
+
i++;
|
|
8834
|
+
continue;
|
|
8835
|
+
}
|
|
8836
|
+
if (c === 125) {
|
|
8837
|
+
continue;
|
|
8838
|
+
}
|
|
8839
|
+
}
|
|
8840
|
+
break;
|
|
8841
|
+
}
|
|
8842
|
+
}
|
|
8843
|
+
break;
|
|
8844
|
+
}
|
|
8845
|
+
throwSyntaxError(bytes, i);
|
|
8846
|
+
}
|
|
8847
|
+
var quote = JSON.stringify;
|
|
8848
|
+
var buildLogLevelDefault = "warning";
|
|
8849
|
+
var transformLogLevelDefault = "silent";
|
|
8850
|
+
function validateAndJoinStringArray(values, what) {
|
|
8851
|
+
const toJoin = [];
|
|
8852
|
+
for (const value of values) {
|
|
8853
|
+
validateStringValue(value, what);
|
|
8854
|
+
if (value.indexOf(",") >= 0) throw new Error(`Invalid ${what}: ${value}`);
|
|
8855
|
+
toJoin.push(value);
|
|
8856
|
+
}
|
|
8857
|
+
return toJoin.join(",");
|
|
8858
|
+
}
|
|
8859
|
+
var canBeAnything = () => null;
|
|
8860
|
+
var mustBeBoolean = (value) => typeof value === "boolean" ? null : "a boolean";
|
|
8861
|
+
var mustBeString = (value) => typeof value === "string" ? null : "a string";
|
|
8862
|
+
var mustBeRegExp = (value) => value instanceof RegExp ? null : "a RegExp object";
|
|
8863
|
+
var mustBeInteger = (value) => typeof value === "number" && value === (value | 0) ? null : "an integer";
|
|
8864
|
+
var mustBeValidPortNumber = (value) => typeof value === "number" && value === (value | 0) && value >= 0 && value <= 65535 ? null : "a valid port number";
|
|
8865
|
+
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
|
|
8866
|
+
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
|
|
8867
|
+
var mustBeArrayOfStrings = (value) => Array.isArray(value) && value.every((x2) => typeof x2 === "string") ? null : "an array of strings";
|
|
8868
|
+
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
|
|
8869
|
+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
|
|
8870
|
+
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
|
|
8871
|
+
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
|
|
8872
|
+
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
|
|
8873
|
+
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
|
|
8874
|
+
var mustBeStringOrArrayOfStrings = (value) => typeof value === "string" || Array.isArray(value) && value.every((x2) => typeof x2 === "string") ? null : "a string or an array of strings";
|
|
8875
|
+
var mustBeStringOrUint8Array = (value) => typeof value === "string" || value instanceof Uint8Array ? null : "a string or a Uint8Array";
|
|
8876
|
+
var mustBeStringOrURL = (value) => typeof value === "string" || value instanceof URL ? null : "a string or a URL";
|
|
8877
|
+
function getFlag(object, keys, key, mustBeFn) {
|
|
8878
|
+
let value = object[key];
|
|
8879
|
+
keys[key + ""] = true;
|
|
8880
|
+
if (value === void 0) return void 0;
|
|
8881
|
+
let mustBe = mustBeFn(value);
|
|
8882
|
+
if (mustBe !== null) throw new Error(`${quote(key)} must be ${mustBe}`);
|
|
8883
|
+
return value;
|
|
8884
|
+
}
|
|
8885
|
+
function checkForInvalidFlags(object, keys, where) {
|
|
8886
|
+
for (let key in object) {
|
|
8887
|
+
if (!(key in keys)) {
|
|
8888
|
+
throw new Error(`Invalid option ${where}: ${quote(key)}`);
|
|
8889
|
+
}
|
|
8890
|
+
}
|
|
8891
|
+
}
|
|
8892
|
+
function validateInitializeOptions(options) {
|
|
8893
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
8894
|
+
let wasmURL = getFlag(options, keys, "wasmURL", mustBeStringOrURL);
|
|
8895
|
+
let wasmModule = getFlag(options, keys, "wasmModule", mustBeWebAssemblyModule);
|
|
8896
|
+
let worker = getFlag(options, keys, "worker", mustBeBoolean);
|
|
8897
|
+
checkForInvalidFlags(options, keys, "in initialize() call");
|
|
8898
|
+
return {
|
|
8899
|
+
wasmURL,
|
|
8900
|
+
wasmModule,
|
|
8901
|
+
worker
|
|
8902
|
+
};
|
|
8903
|
+
}
|
|
8904
|
+
function validateMangleCache(mangleCache) {
|
|
8905
|
+
let validated;
|
|
8906
|
+
if (mangleCache !== void 0) {
|
|
8907
|
+
validated = /* @__PURE__ */ Object.create(null);
|
|
8908
|
+
for (let key in mangleCache) {
|
|
8909
|
+
let value = mangleCache[key];
|
|
8910
|
+
if (typeof value === "string" || value === false) {
|
|
8911
|
+
validated[key] = value;
|
|
8912
|
+
} else {
|
|
8913
|
+
throw new Error(`Expected ${quote(key)} in mangle cache to map to either a string or false`);
|
|
8914
|
+
}
|
|
8915
|
+
}
|
|
8916
|
+
}
|
|
8917
|
+
return validated;
|
|
8918
|
+
}
|
|
8919
|
+
function pushLogFlags(flags, options, keys, isTTY2, logLevelDefault) {
|
|
8920
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
8921
|
+
let logLevel = getFlag(options, keys, "logLevel", mustBeString);
|
|
8922
|
+
let logLimit = getFlag(options, keys, "logLimit", mustBeInteger);
|
|
8923
|
+
if (color !== void 0) flags.push(`--color=${color}`);
|
|
8924
|
+
else if (isTTY2) flags.push(`--color=true`);
|
|
8925
|
+
flags.push(`--log-level=${logLevel || logLevelDefault}`);
|
|
8926
|
+
flags.push(`--log-limit=${logLimit || 0}`);
|
|
8927
|
+
}
|
|
8928
|
+
function validateStringValue(value, what, key) {
|
|
8929
|
+
if (typeof value !== "string") {
|
|
8930
|
+
throw new Error(`Expected value for ${what}${key !== void 0 ? " " + quote(key) : ""} to be a string, got ${typeof value} instead`);
|
|
8931
|
+
}
|
|
8932
|
+
return value;
|
|
8933
|
+
}
|
|
8934
|
+
function pushCommonFlags(flags, options, keys) {
|
|
8935
|
+
let legalComments = getFlag(options, keys, "legalComments", mustBeString);
|
|
8936
|
+
let sourceRoot = getFlag(options, keys, "sourceRoot", mustBeString);
|
|
8937
|
+
let sourcesContent = getFlag(options, keys, "sourcesContent", mustBeBoolean);
|
|
8938
|
+
let target = getFlag(options, keys, "target", mustBeStringOrArrayOfStrings);
|
|
8939
|
+
let format = getFlag(options, keys, "format", mustBeString);
|
|
8940
|
+
let globalName = getFlag(options, keys, "globalName", mustBeString);
|
|
8941
|
+
let mangleProps = getFlag(options, keys, "mangleProps", mustBeRegExp);
|
|
8942
|
+
let reserveProps = getFlag(options, keys, "reserveProps", mustBeRegExp);
|
|
8943
|
+
let mangleQuoted = getFlag(options, keys, "mangleQuoted", mustBeBoolean);
|
|
8944
|
+
let minify = getFlag(options, keys, "minify", mustBeBoolean);
|
|
8945
|
+
let minifySyntax = getFlag(options, keys, "minifySyntax", mustBeBoolean);
|
|
8946
|
+
let minifyWhitespace = getFlag(options, keys, "minifyWhitespace", mustBeBoolean);
|
|
8947
|
+
let minifyIdentifiers = getFlag(options, keys, "minifyIdentifiers", mustBeBoolean);
|
|
8948
|
+
let lineLimit = getFlag(options, keys, "lineLimit", mustBeInteger);
|
|
8949
|
+
let drop = getFlag(options, keys, "drop", mustBeArrayOfStrings);
|
|
8950
|
+
let dropLabels = getFlag(options, keys, "dropLabels", mustBeArrayOfStrings);
|
|
8951
|
+
let charset = getFlag(options, keys, "charset", mustBeString);
|
|
8952
|
+
let treeShaking = getFlag(options, keys, "treeShaking", mustBeBoolean);
|
|
8953
|
+
let ignoreAnnotations = getFlag(options, keys, "ignoreAnnotations", mustBeBoolean);
|
|
8954
|
+
let jsx = getFlag(options, keys, "jsx", mustBeString);
|
|
8955
|
+
let jsxFactory = getFlag(options, keys, "jsxFactory", mustBeString);
|
|
8956
|
+
let jsxFragment = getFlag(options, keys, "jsxFragment", mustBeString);
|
|
8957
|
+
let jsxImportSource = getFlag(options, keys, "jsxImportSource", mustBeString);
|
|
8958
|
+
let jsxDev = getFlag(options, keys, "jsxDev", mustBeBoolean);
|
|
8959
|
+
let jsxSideEffects = getFlag(options, keys, "jsxSideEffects", mustBeBoolean);
|
|
8960
|
+
let define = getFlag(options, keys, "define", mustBeObject);
|
|
8961
|
+
let logOverride = getFlag(options, keys, "logOverride", mustBeObject);
|
|
8962
|
+
let supported = getFlag(options, keys, "supported", mustBeObject);
|
|
8963
|
+
let pure = getFlag(options, keys, "pure", mustBeArrayOfStrings);
|
|
8964
|
+
let keepNames = getFlag(options, keys, "keepNames", mustBeBoolean);
|
|
8965
|
+
let platform = getFlag(options, keys, "platform", mustBeString);
|
|
8966
|
+
let tsconfigRaw = getFlag(options, keys, "tsconfigRaw", mustBeStringOrObject);
|
|
8967
|
+
let absPaths = getFlag(options, keys, "absPaths", mustBeArrayOfStrings);
|
|
8968
|
+
if (legalComments) flags.push(`--legal-comments=${legalComments}`);
|
|
8969
|
+
if (sourceRoot !== void 0) flags.push(`--source-root=${sourceRoot}`);
|
|
8970
|
+
if (sourcesContent !== void 0) flags.push(`--sources-content=${sourcesContent}`);
|
|
8971
|
+
if (target) flags.push(`--target=${validateAndJoinStringArray(Array.isArray(target) ? target : [target], "target")}`);
|
|
8972
|
+
if (format) flags.push(`--format=${format}`);
|
|
8973
|
+
if (globalName) flags.push(`--global-name=${globalName}`);
|
|
8974
|
+
if (platform) flags.push(`--platform=${platform}`);
|
|
8975
|
+
if (tsconfigRaw) flags.push(`--tsconfig-raw=${typeof tsconfigRaw === "string" ? tsconfigRaw : JSON.stringify(tsconfigRaw)}`);
|
|
8976
|
+
if (minify) flags.push("--minify");
|
|
8977
|
+
if (minifySyntax) flags.push("--minify-syntax");
|
|
8978
|
+
if (minifyWhitespace) flags.push("--minify-whitespace");
|
|
8979
|
+
if (minifyIdentifiers) flags.push("--minify-identifiers");
|
|
8980
|
+
if (lineLimit) flags.push(`--line-limit=${lineLimit}`);
|
|
8981
|
+
if (charset) flags.push(`--charset=${charset}`);
|
|
8982
|
+
if (treeShaking !== void 0) flags.push(`--tree-shaking=${treeShaking}`);
|
|
8983
|
+
if (ignoreAnnotations) flags.push(`--ignore-annotations`);
|
|
8984
|
+
if (drop) for (let what of drop) flags.push(`--drop:${validateStringValue(what, "drop")}`);
|
|
8985
|
+
if (dropLabels) flags.push(`--drop-labels=${validateAndJoinStringArray(dropLabels, "drop label")}`);
|
|
8986
|
+
if (absPaths) flags.push(`--abs-paths=${validateAndJoinStringArray(absPaths, "abs paths")}`);
|
|
8987
|
+
if (mangleProps) flags.push(`--mangle-props=${jsRegExpToGoRegExp(mangleProps)}`);
|
|
8988
|
+
if (reserveProps) flags.push(`--reserve-props=${jsRegExpToGoRegExp(reserveProps)}`);
|
|
8989
|
+
if (mangleQuoted !== void 0) flags.push(`--mangle-quoted=${mangleQuoted}`);
|
|
8990
|
+
if (jsx) flags.push(`--jsx=${jsx}`);
|
|
8991
|
+
if (jsxFactory) flags.push(`--jsx-factory=${jsxFactory}`);
|
|
8992
|
+
if (jsxFragment) flags.push(`--jsx-fragment=${jsxFragment}`);
|
|
8993
|
+
if (jsxImportSource) flags.push(`--jsx-import-source=${jsxImportSource}`);
|
|
8994
|
+
if (jsxDev) flags.push(`--jsx-dev`);
|
|
8995
|
+
if (jsxSideEffects) flags.push(`--jsx-side-effects`);
|
|
8996
|
+
if (define) {
|
|
8997
|
+
for (let key in define) {
|
|
8998
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid define: ${key}`);
|
|
8999
|
+
flags.push(`--define:${key}=${validateStringValue(define[key], "define", key)}`);
|
|
9000
|
+
}
|
|
9001
|
+
}
|
|
9002
|
+
if (logOverride) {
|
|
9003
|
+
for (let key in logOverride) {
|
|
9004
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid log override: ${key}`);
|
|
9005
|
+
flags.push(`--log-override:${key}=${validateStringValue(logOverride[key], "log override", key)}`);
|
|
9006
|
+
}
|
|
9007
|
+
}
|
|
9008
|
+
if (supported) {
|
|
9009
|
+
for (let key in supported) {
|
|
9010
|
+
if (key.indexOf("=") >= 0) throw new Error(`Invalid supported: ${key}`);
|
|
9011
|
+
const value = supported[key];
|
|
9012
|
+
if (typeof value !== "boolean") throw new Error(`Expected value for supported ${quote(key)} to be a boolean, got ${typeof value} instead`);
|
|
9013
|
+
flags.push(`--supported:${key}=${value}`);
|
|
9014
|
+
}
|
|
9015
|
+
}
|
|
9016
|
+
if (pure) for (let fn of pure) flags.push(`--pure:${validateStringValue(fn, "pure")}`);
|
|
9017
|
+
if (keepNames) flags.push(`--keep-names`);
|
|
9018
|
+
}
|
|
9019
|
+
function flagsForBuildOptions(callName, options, isTTY2, logLevelDefault, writeDefault) {
|
|
9020
|
+
var _a2;
|
|
9021
|
+
let flags = [];
|
|
9022
|
+
let entries = [];
|
|
9023
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
9024
|
+
let stdinContents = null;
|
|
9025
|
+
let stdinResolveDir = null;
|
|
9026
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
9027
|
+
pushCommonFlags(flags, options, keys);
|
|
9028
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
9029
|
+
let bundle = getFlag(options, keys, "bundle", mustBeBoolean);
|
|
9030
|
+
let splitting = getFlag(options, keys, "splitting", mustBeBoolean);
|
|
9031
|
+
let preserveSymlinks = getFlag(options, keys, "preserveSymlinks", mustBeBoolean);
|
|
9032
|
+
let metafile = getFlag(options, keys, "metafile", mustBeBoolean);
|
|
9033
|
+
let outfile = getFlag(options, keys, "outfile", mustBeString);
|
|
9034
|
+
let outdir = getFlag(options, keys, "outdir", mustBeString);
|
|
9035
|
+
let outbase = getFlag(options, keys, "outbase", mustBeString);
|
|
9036
|
+
let tsconfig = getFlag(options, keys, "tsconfig", mustBeString);
|
|
9037
|
+
let resolveExtensions = getFlag(options, keys, "resolveExtensions", mustBeArrayOfStrings);
|
|
9038
|
+
let nodePathsInput = getFlag(options, keys, "nodePaths", mustBeArrayOfStrings);
|
|
9039
|
+
let mainFields = getFlag(options, keys, "mainFields", mustBeArrayOfStrings);
|
|
9040
|
+
let conditions = getFlag(options, keys, "conditions", mustBeArrayOfStrings);
|
|
9041
|
+
let external = getFlag(options, keys, "external", mustBeArrayOfStrings);
|
|
9042
|
+
let packages = getFlag(options, keys, "packages", mustBeString);
|
|
9043
|
+
let alias = getFlag(options, keys, "alias", mustBeObject);
|
|
9044
|
+
let loader = getFlag(options, keys, "loader", mustBeObject);
|
|
9045
|
+
let outExtension = getFlag(options, keys, "outExtension", mustBeObject);
|
|
9046
|
+
let publicPath = getFlag(options, keys, "publicPath", mustBeString);
|
|
9047
|
+
let entryNames = getFlag(options, keys, "entryNames", mustBeString);
|
|
9048
|
+
let chunkNames = getFlag(options, keys, "chunkNames", mustBeString);
|
|
9049
|
+
let assetNames = getFlag(options, keys, "assetNames", mustBeString);
|
|
9050
|
+
let inject = getFlag(options, keys, "inject", mustBeArrayOfStrings);
|
|
9051
|
+
let banner = getFlag(options, keys, "banner", mustBeObject);
|
|
9052
|
+
let footer = getFlag(options, keys, "footer", mustBeObject);
|
|
9053
|
+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
|
|
9054
|
+
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
|
|
9055
|
+
let stdin = getFlag(options, keys, "stdin", mustBeObject);
|
|
9056
|
+
let write = (_a2 = getFlag(options, keys, "write", mustBeBoolean)) != null ? _a2 : writeDefault;
|
|
9057
|
+
let allowOverwrite = getFlag(options, keys, "allowOverwrite", mustBeBoolean);
|
|
9058
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
9059
|
+
keys.plugins = true;
|
|
9060
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
9061
|
+
if (sourcemap) flags.push(`--sourcemap${sourcemap === true ? "" : `=${sourcemap}`}`);
|
|
9062
|
+
if (bundle) flags.push("--bundle");
|
|
9063
|
+
if (allowOverwrite) flags.push("--allow-overwrite");
|
|
9064
|
+
if (splitting) flags.push("--splitting");
|
|
9065
|
+
if (preserveSymlinks) flags.push("--preserve-symlinks");
|
|
9066
|
+
if (metafile) flags.push(`--metafile`);
|
|
9067
|
+
if (outfile) flags.push(`--outfile=${outfile}`);
|
|
9068
|
+
if (outdir) flags.push(`--outdir=${outdir}`);
|
|
9069
|
+
if (outbase) flags.push(`--outbase=${outbase}`);
|
|
9070
|
+
if (tsconfig) flags.push(`--tsconfig=${tsconfig}`);
|
|
9071
|
+
if (packages) flags.push(`--packages=${packages}`);
|
|
9072
|
+
if (resolveExtensions) flags.push(`--resolve-extensions=${validateAndJoinStringArray(resolveExtensions, "resolve extension")}`);
|
|
9073
|
+
if (publicPath) flags.push(`--public-path=${publicPath}`);
|
|
9074
|
+
if (entryNames) flags.push(`--entry-names=${entryNames}`);
|
|
9075
|
+
if (chunkNames) flags.push(`--chunk-names=${chunkNames}`);
|
|
9076
|
+
if (assetNames) flags.push(`--asset-names=${assetNames}`);
|
|
9077
|
+
if (mainFields) flags.push(`--main-fields=${validateAndJoinStringArray(mainFields, "main field")}`);
|
|
9078
|
+
if (conditions) flags.push(`--conditions=${validateAndJoinStringArray(conditions, "condition")}`);
|
|
9079
|
+
if (external) for (let name of external) flags.push(`--external:${validateStringValue(name, "external")}`);
|
|
9080
|
+
if (alias) {
|
|
9081
|
+
for (let old in alias) {
|
|
9082
|
+
if (old.indexOf("=") >= 0) throw new Error(`Invalid package name in alias: ${old}`);
|
|
9083
|
+
flags.push(`--alias:${old}=${validateStringValue(alias[old], "alias", old)}`);
|
|
9084
|
+
}
|
|
9085
|
+
}
|
|
9086
|
+
if (banner) {
|
|
9087
|
+
for (let type in banner) {
|
|
9088
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid banner file type: ${type}`);
|
|
9089
|
+
flags.push(`--banner:${type}=${validateStringValue(banner[type], "banner", type)}`);
|
|
9090
|
+
}
|
|
9091
|
+
}
|
|
9092
|
+
if (footer) {
|
|
9093
|
+
for (let type in footer) {
|
|
9094
|
+
if (type.indexOf("=") >= 0) throw new Error(`Invalid footer file type: ${type}`);
|
|
9095
|
+
flags.push(`--footer:${type}=${validateStringValue(footer[type], "footer", type)}`);
|
|
9096
|
+
}
|
|
9097
|
+
}
|
|
9098
|
+
if (inject) for (let path3 of inject) flags.push(`--inject:${validateStringValue(path3, "inject")}`);
|
|
9099
|
+
if (loader) {
|
|
9100
|
+
for (let ext in loader) {
|
|
9101
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid loader extension: ${ext}`);
|
|
9102
|
+
flags.push(`--loader:${ext}=${validateStringValue(loader[ext], "loader", ext)}`);
|
|
9103
|
+
}
|
|
9104
|
+
}
|
|
9105
|
+
if (outExtension) {
|
|
9106
|
+
for (let ext in outExtension) {
|
|
9107
|
+
if (ext.indexOf("=") >= 0) throw new Error(`Invalid out extension: ${ext}`);
|
|
9108
|
+
flags.push(`--out-extension:${ext}=${validateStringValue(outExtension[ext], "out extension", ext)}`);
|
|
9109
|
+
}
|
|
9110
|
+
}
|
|
9111
|
+
if (entryPoints) {
|
|
9112
|
+
if (Array.isArray(entryPoints)) {
|
|
9113
|
+
for (let i = 0, n = entryPoints.length; i < n; i++) {
|
|
9114
|
+
let entryPoint = entryPoints[i];
|
|
9115
|
+
if (typeof entryPoint === "object" && entryPoint !== null) {
|
|
9116
|
+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
|
|
9117
|
+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
|
|
9118
|
+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
|
|
9119
|
+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
|
|
9120
|
+
if (input === void 0) throw new Error('Missing property "in" for entry point at index ' + i);
|
|
9121
|
+
if (output === void 0) throw new Error('Missing property "out" for entry point at index ' + i);
|
|
9122
|
+
entries.push([output, input]);
|
|
9123
|
+
} else {
|
|
9124
|
+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
|
|
9125
|
+
}
|
|
9126
|
+
}
|
|
9127
|
+
} else {
|
|
9128
|
+
for (let key in entryPoints) {
|
|
9129
|
+
entries.push([key, validateStringValue(entryPoints[key], "entry point", key)]);
|
|
9130
|
+
}
|
|
9131
|
+
}
|
|
9132
|
+
}
|
|
9133
|
+
if (stdin) {
|
|
9134
|
+
let stdinKeys = /* @__PURE__ */ Object.create(null);
|
|
9135
|
+
let contents = getFlag(stdin, stdinKeys, "contents", mustBeStringOrUint8Array);
|
|
9136
|
+
let resolveDir = getFlag(stdin, stdinKeys, "resolveDir", mustBeString);
|
|
9137
|
+
let sourcefile = getFlag(stdin, stdinKeys, "sourcefile", mustBeString);
|
|
9138
|
+
let loader2 = getFlag(stdin, stdinKeys, "loader", mustBeString);
|
|
9139
|
+
checkForInvalidFlags(stdin, stdinKeys, 'in "stdin" object');
|
|
9140
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
9141
|
+
if (loader2) flags.push(`--loader=${loader2}`);
|
|
9142
|
+
if (resolveDir) stdinResolveDir = resolveDir;
|
|
9143
|
+
if (typeof contents === "string") stdinContents = encodeUTF8(contents);
|
|
9144
|
+
else if (contents instanceof Uint8Array) stdinContents = contents;
|
|
9145
|
+
}
|
|
9146
|
+
let nodePaths = [];
|
|
9147
|
+
if (nodePathsInput) {
|
|
9148
|
+
for (let value of nodePathsInput) {
|
|
9149
|
+
value += "";
|
|
9150
|
+
nodePaths.push(value);
|
|
9151
|
+
}
|
|
9152
|
+
}
|
|
9153
|
+
return {
|
|
9154
|
+
entries,
|
|
9155
|
+
flags,
|
|
9156
|
+
write,
|
|
9157
|
+
stdinContents,
|
|
9158
|
+
stdinResolveDir,
|
|
9159
|
+
absWorkingDir,
|
|
9160
|
+
nodePaths,
|
|
9161
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
9162
|
+
};
|
|
9163
|
+
}
|
|
9164
|
+
function flagsForTransformOptions(callName, options, isTTY2, logLevelDefault) {
|
|
9165
|
+
let flags = [];
|
|
9166
|
+
let keys = /* @__PURE__ */ Object.create(null);
|
|
9167
|
+
pushLogFlags(flags, options, keys, isTTY2, logLevelDefault);
|
|
9168
|
+
pushCommonFlags(flags, options, keys);
|
|
9169
|
+
let sourcemap = getFlag(options, keys, "sourcemap", mustBeStringOrBoolean);
|
|
9170
|
+
let sourcefile = getFlag(options, keys, "sourcefile", mustBeString);
|
|
9171
|
+
let loader = getFlag(options, keys, "loader", mustBeString);
|
|
9172
|
+
let banner = getFlag(options, keys, "banner", mustBeString);
|
|
9173
|
+
let footer = getFlag(options, keys, "footer", mustBeString);
|
|
9174
|
+
let mangleCache = getFlag(options, keys, "mangleCache", mustBeObject);
|
|
9175
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
9176
|
+
if (sourcemap) flags.push(`--sourcemap=${sourcemap === true ? "external" : sourcemap}`);
|
|
9177
|
+
if (sourcefile) flags.push(`--sourcefile=${sourcefile}`);
|
|
9178
|
+
if (loader) flags.push(`--loader=${loader}`);
|
|
9179
|
+
if (banner) flags.push(`--banner=${banner}`);
|
|
9180
|
+
if (footer) flags.push(`--footer=${footer}`);
|
|
9181
|
+
return {
|
|
9182
|
+
flags,
|
|
9183
|
+
mangleCache: validateMangleCache(mangleCache)
|
|
9184
|
+
};
|
|
9185
|
+
}
|
|
9186
|
+
function createChannel(streamIn) {
|
|
9187
|
+
const requestCallbacksByKey = {};
|
|
9188
|
+
const closeData = { didClose: false, reason: "" };
|
|
9189
|
+
let responseCallbacks = {};
|
|
9190
|
+
let nextRequestID = 0;
|
|
9191
|
+
let nextBuildKey = 0;
|
|
9192
|
+
let stdout = new Uint8Array(16 * 1024);
|
|
9193
|
+
let stdoutUsed = 0;
|
|
9194
|
+
let readFromStdout = (chunk) => {
|
|
9195
|
+
let limit = stdoutUsed + chunk.length;
|
|
9196
|
+
if (limit > stdout.length) {
|
|
9197
|
+
let swap = new Uint8Array(limit * 2);
|
|
9198
|
+
swap.set(stdout);
|
|
9199
|
+
stdout = swap;
|
|
9200
|
+
}
|
|
9201
|
+
stdout.set(chunk, stdoutUsed);
|
|
9202
|
+
stdoutUsed += chunk.length;
|
|
9203
|
+
let offset = 0;
|
|
9204
|
+
while (offset + 4 <= stdoutUsed) {
|
|
9205
|
+
let length = readUInt32LE(stdout, offset);
|
|
9206
|
+
if (offset + 4 + length > stdoutUsed) {
|
|
9207
|
+
break;
|
|
9208
|
+
}
|
|
9209
|
+
offset += 4;
|
|
9210
|
+
handleIncomingPacket(stdout.subarray(offset, offset + length));
|
|
9211
|
+
offset += length;
|
|
9212
|
+
}
|
|
9213
|
+
if (offset > 0) {
|
|
9214
|
+
stdout.copyWithin(0, offset, stdoutUsed);
|
|
9215
|
+
stdoutUsed -= offset;
|
|
9216
|
+
}
|
|
9217
|
+
};
|
|
9218
|
+
let afterClose = (error2) => {
|
|
9219
|
+
closeData.didClose = true;
|
|
9220
|
+
if (error2) closeData.reason = ": " + (error2.message || error2);
|
|
9221
|
+
const text = "The service was stopped" + closeData.reason;
|
|
9222
|
+
for (let id in responseCallbacks) {
|
|
9223
|
+
responseCallbacks[id](text, null);
|
|
9224
|
+
}
|
|
9225
|
+
responseCallbacks = {};
|
|
9226
|
+
};
|
|
9227
|
+
let sendRequest = (refs, value, callback) => {
|
|
9228
|
+
if (closeData.didClose) return callback("The service is no longer running" + closeData.reason, null);
|
|
9229
|
+
let id = nextRequestID++;
|
|
9230
|
+
responseCallbacks[id] = (error2, response) => {
|
|
9231
|
+
try {
|
|
9232
|
+
callback(error2, response);
|
|
9233
|
+
} finally {
|
|
9234
|
+
if (refs) refs.unref();
|
|
9235
|
+
}
|
|
9236
|
+
};
|
|
9237
|
+
if (refs) refs.ref();
|
|
9238
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: true, value }));
|
|
9239
|
+
};
|
|
9240
|
+
let sendResponse = (id, value) => {
|
|
9241
|
+
if (closeData.didClose) throw new Error("The service is no longer running" + closeData.reason);
|
|
9242
|
+
streamIn.writeToStdin(encodePacket({ id, isRequest: false, value }));
|
|
9243
|
+
};
|
|
9244
|
+
let handleRequest = async (id, request) => {
|
|
9245
|
+
try {
|
|
9246
|
+
if (request.command === "ping") {
|
|
9247
|
+
sendResponse(id, {});
|
|
9248
|
+
return;
|
|
9249
|
+
}
|
|
9250
|
+
if (typeof request.key === "number") {
|
|
9251
|
+
const requestCallbacks = requestCallbacksByKey[request.key];
|
|
9252
|
+
if (!requestCallbacks) {
|
|
9253
|
+
return;
|
|
9254
|
+
}
|
|
9255
|
+
const callback = requestCallbacks[request.command];
|
|
9256
|
+
if (callback) {
|
|
9257
|
+
await callback(id, request);
|
|
9258
|
+
return;
|
|
9259
|
+
}
|
|
9260
|
+
}
|
|
9261
|
+
throw new Error(`Invalid command: ` + request.command);
|
|
9262
|
+
} catch (e2) {
|
|
9263
|
+
const errors = [extractErrorMessageV8(e2, streamIn, null, void 0, "")];
|
|
9264
|
+
try {
|
|
9265
|
+
sendResponse(id, { errors });
|
|
9266
|
+
} catch {
|
|
9267
|
+
}
|
|
9268
|
+
}
|
|
9269
|
+
};
|
|
9270
|
+
let isFirstPacket = true;
|
|
9271
|
+
let handleIncomingPacket = (bytes) => {
|
|
9272
|
+
if (isFirstPacket) {
|
|
9273
|
+
isFirstPacket = false;
|
|
9274
|
+
let binaryVersion = String.fromCharCode(...bytes);
|
|
9275
|
+
if (binaryVersion !== "0.27.4") {
|
|
9276
|
+
throw new Error(`Cannot start service: Host version "${"0.27.4"}" does not match binary version ${quote(binaryVersion)}`);
|
|
9277
|
+
}
|
|
9278
|
+
return;
|
|
9279
|
+
}
|
|
9280
|
+
let packet = decodePacket(bytes);
|
|
9281
|
+
if (packet.isRequest) {
|
|
9282
|
+
handleRequest(packet.id, packet.value);
|
|
9283
|
+
} else {
|
|
9284
|
+
let callback = responseCallbacks[packet.id];
|
|
9285
|
+
delete responseCallbacks[packet.id];
|
|
9286
|
+
if (packet.value.error) callback(packet.value.error, {});
|
|
9287
|
+
else callback(null, packet.value);
|
|
9288
|
+
}
|
|
9289
|
+
};
|
|
9290
|
+
let buildOrContext = ({ callName, refs, options, isTTY: isTTY2, defaultWD: defaultWD2, callback }) => {
|
|
9291
|
+
let refCount = 0;
|
|
9292
|
+
const buildKey = nextBuildKey++;
|
|
9293
|
+
const requestCallbacks = {};
|
|
9294
|
+
const buildRefs = {
|
|
9295
|
+
ref() {
|
|
9296
|
+
if (++refCount === 1) {
|
|
9297
|
+
if (refs) refs.ref();
|
|
9298
|
+
}
|
|
9299
|
+
},
|
|
9300
|
+
unref() {
|
|
9301
|
+
if (--refCount === 0) {
|
|
9302
|
+
delete requestCallbacksByKey[buildKey];
|
|
9303
|
+
if (refs) refs.unref();
|
|
9304
|
+
}
|
|
9305
|
+
}
|
|
9306
|
+
};
|
|
9307
|
+
requestCallbacksByKey[buildKey] = requestCallbacks;
|
|
9308
|
+
buildRefs.ref();
|
|
9309
|
+
buildOrContextImpl(
|
|
9310
|
+
callName,
|
|
9311
|
+
buildKey,
|
|
9312
|
+
sendRequest,
|
|
9313
|
+
sendResponse,
|
|
9314
|
+
buildRefs,
|
|
9315
|
+
streamIn,
|
|
9316
|
+
requestCallbacks,
|
|
9317
|
+
options,
|
|
9318
|
+
isTTY2,
|
|
9319
|
+
defaultWD2,
|
|
9320
|
+
(err, res) => {
|
|
9321
|
+
try {
|
|
9322
|
+
callback(err, res);
|
|
9323
|
+
} finally {
|
|
9324
|
+
buildRefs.unref();
|
|
9325
|
+
}
|
|
9326
|
+
}
|
|
9327
|
+
);
|
|
9328
|
+
};
|
|
9329
|
+
let transform2 = ({ callName, refs, input, options, isTTY: isTTY2, fs: fs32, callback }) => {
|
|
9330
|
+
const details = createObjectStash();
|
|
9331
|
+
let start = (inputPath) => {
|
|
9332
|
+
try {
|
|
9333
|
+
if (typeof input !== "string" && !(input instanceof Uint8Array))
|
|
9334
|
+
throw new Error('The input to "transform" must be a string or a Uint8Array');
|
|
9335
|
+
let {
|
|
9336
|
+
flags,
|
|
9337
|
+
mangleCache
|
|
9338
|
+
} = flagsForTransformOptions(callName, options, isTTY2, transformLogLevelDefault);
|
|
9339
|
+
let request = {
|
|
9340
|
+
command: "transform",
|
|
9341
|
+
flags,
|
|
9342
|
+
inputFS: inputPath !== null,
|
|
9343
|
+
input: inputPath !== null ? encodeUTF8(inputPath) : typeof input === "string" ? encodeUTF8(input) : input
|
|
9344
|
+
};
|
|
9345
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
9346
|
+
sendRequest(refs, request, (error2, response) => {
|
|
9347
|
+
if (error2) return callback(new Error(error2), null);
|
|
9348
|
+
let errors = replaceDetailsInMessages(response.errors, details);
|
|
9349
|
+
let warnings = replaceDetailsInMessages(response.warnings, details);
|
|
9350
|
+
let outstanding = 1;
|
|
9351
|
+
let next = () => {
|
|
9352
|
+
if (--outstanding === 0) {
|
|
9353
|
+
let result = {
|
|
9354
|
+
warnings,
|
|
9355
|
+
code: response.code,
|
|
9356
|
+
map: response.map,
|
|
9357
|
+
mangleCache: void 0,
|
|
9358
|
+
legalComments: void 0
|
|
9359
|
+
};
|
|
9360
|
+
if ("legalComments" in response) result.legalComments = response == null ? void 0 : response.legalComments;
|
|
9361
|
+
if (response.mangleCache) result.mangleCache = response == null ? void 0 : response.mangleCache;
|
|
9362
|
+
callback(null, result);
|
|
9363
|
+
}
|
|
9364
|
+
};
|
|
9365
|
+
if (errors.length > 0) return callback(failureErrorWithLog("Transform failed", errors, warnings), null);
|
|
9366
|
+
if (response.codeFS) {
|
|
9367
|
+
outstanding++;
|
|
9368
|
+
fs32.readFile(response.code, (err, contents) => {
|
|
9369
|
+
if (err !== null) {
|
|
9370
|
+
callback(err, null);
|
|
9371
|
+
} else {
|
|
9372
|
+
response.code = contents;
|
|
9373
|
+
next();
|
|
9374
|
+
}
|
|
9375
|
+
});
|
|
9376
|
+
}
|
|
9377
|
+
if (response.mapFS) {
|
|
9378
|
+
outstanding++;
|
|
9379
|
+
fs32.readFile(response.map, (err, contents) => {
|
|
9380
|
+
if (err !== null) {
|
|
9381
|
+
callback(err, null);
|
|
9382
|
+
} else {
|
|
9383
|
+
response.map = contents;
|
|
9384
|
+
next();
|
|
9385
|
+
}
|
|
9386
|
+
});
|
|
9387
|
+
}
|
|
9388
|
+
next();
|
|
9389
|
+
});
|
|
9390
|
+
} catch (e2) {
|
|
9391
|
+
let flags = [];
|
|
9392
|
+
try {
|
|
9393
|
+
pushLogFlags(flags, options, {}, isTTY2, transformLogLevelDefault);
|
|
9394
|
+
} catch {
|
|
9395
|
+
}
|
|
9396
|
+
const error2 = extractErrorMessageV8(e2, streamIn, details, void 0, "");
|
|
9397
|
+
sendRequest(refs, { command: "error", flags, error: error2 }, () => {
|
|
9398
|
+
error2.detail = details.load(error2.detail);
|
|
9399
|
+
callback(failureErrorWithLog("Transform failed", [error2], []), null);
|
|
9400
|
+
});
|
|
9401
|
+
}
|
|
9402
|
+
};
|
|
9403
|
+
if ((typeof input === "string" || input instanceof Uint8Array) && input.length > 1024 * 1024) {
|
|
9404
|
+
let next = start;
|
|
9405
|
+
start = () => fs32.writeFile(input, next);
|
|
9406
|
+
}
|
|
9407
|
+
start(null);
|
|
9408
|
+
};
|
|
9409
|
+
let formatMessages2 = ({ callName, refs, messages, options, callback }) => {
|
|
9410
|
+
if (!options) throw new Error(`Missing second argument in ${callName}() call`);
|
|
9411
|
+
let keys = {};
|
|
9412
|
+
let kind = getFlag(options, keys, "kind", mustBeString);
|
|
9413
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
9414
|
+
let terminalWidth = getFlag(options, keys, "terminalWidth", mustBeInteger);
|
|
9415
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
9416
|
+
if (kind === void 0) throw new Error(`Missing "kind" in ${callName}() call`);
|
|
9417
|
+
if (kind !== "error" && kind !== "warning") throw new Error(`Expected "kind" to be "error" or "warning" in ${callName}() call`);
|
|
9418
|
+
let request = {
|
|
9419
|
+
command: "format-msgs",
|
|
9420
|
+
messages: sanitizeMessages(messages, "messages", null, "", terminalWidth),
|
|
9421
|
+
isWarning: kind === "warning"
|
|
9422
|
+
};
|
|
9423
|
+
if (color !== void 0) request.color = color;
|
|
9424
|
+
if (terminalWidth !== void 0) request.terminalWidth = terminalWidth;
|
|
9425
|
+
sendRequest(refs, request, (error2, response) => {
|
|
9426
|
+
if (error2) return callback(new Error(error2), null);
|
|
9427
|
+
callback(null, response.messages);
|
|
9428
|
+
});
|
|
9429
|
+
};
|
|
9430
|
+
let analyzeMetafile2 = ({ callName, refs, metafile, options, callback }) => {
|
|
9431
|
+
if (options === void 0) options = {};
|
|
9432
|
+
let keys = {};
|
|
9433
|
+
let color = getFlag(options, keys, "color", mustBeBoolean);
|
|
9434
|
+
let verbose = getFlag(options, keys, "verbose", mustBeBoolean);
|
|
9435
|
+
checkForInvalidFlags(options, keys, `in ${callName}() call`);
|
|
9436
|
+
let request = {
|
|
9437
|
+
command: "analyze-metafile",
|
|
9438
|
+
metafile
|
|
9439
|
+
};
|
|
9440
|
+
if (color !== void 0) request.color = color;
|
|
9441
|
+
if (verbose !== void 0) request.verbose = verbose;
|
|
9442
|
+
sendRequest(refs, request, (error2, response) => {
|
|
9443
|
+
if (error2) return callback(new Error(error2), null);
|
|
9444
|
+
callback(null, response.result);
|
|
9445
|
+
});
|
|
9446
|
+
};
|
|
9447
|
+
return {
|
|
9448
|
+
readFromStdout,
|
|
9449
|
+
afterClose,
|
|
9450
|
+
service: {
|
|
9451
|
+
buildOrContext,
|
|
9452
|
+
transform: transform2,
|
|
9453
|
+
formatMessages: formatMessages2,
|
|
9454
|
+
analyzeMetafile: analyzeMetafile2
|
|
9455
|
+
}
|
|
9456
|
+
};
|
|
9457
|
+
}
|
|
9458
|
+
function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, options, isTTY2, defaultWD2, callback) {
|
|
9459
|
+
const details = createObjectStash();
|
|
9460
|
+
const isContext = callName === "context";
|
|
9461
|
+
const handleError = (e2, pluginName) => {
|
|
9462
|
+
const flags = [];
|
|
9463
|
+
try {
|
|
9464
|
+
pushLogFlags(flags, options, {}, isTTY2, buildLogLevelDefault);
|
|
9465
|
+
} catch {
|
|
9466
|
+
}
|
|
9467
|
+
const message = extractErrorMessageV8(e2, streamIn, details, void 0, pluginName);
|
|
9468
|
+
sendRequest(refs, { command: "error", flags, error: message }, () => {
|
|
9469
|
+
message.detail = details.load(message.detail);
|
|
9470
|
+
callback(failureErrorWithLog(isContext ? "Context failed" : "Build failed", [message], []), null);
|
|
9471
|
+
});
|
|
9472
|
+
};
|
|
9473
|
+
let plugins;
|
|
9474
|
+
if (typeof options === "object") {
|
|
9475
|
+
const value = options.plugins;
|
|
9476
|
+
if (value !== void 0) {
|
|
9477
|
+
if (!Array.isArray(value)) return handleError(new Error(`"plugins" must be an array`), "");
|
|
9478
|
+
plugins = value;
|
|
9479
|
+
}
|
|
9480
|
+
}
|
|
9481
|
+
if (plugins && plugins.length > 0) {
|
|
9482
|
+
if (streamIn.isSync) return handleError(new Error("Cannot use plugins in synchronous API calls"), "");
|
|
9483
|
+
handlePlugins(
|
|
9484
|
+
buildKey,
|
|
9485
|
+
sendRequest,
|
|
9486
|
+
sendResponse,
|
|
9487
|
+
refs,
|
|
9488
|
+
streamIn,
|
|
9489
|
+
requestCallbacks,
|
|
9490
|
+
options,
|
|
9491
|
+
plugins,
|
|
9492
|
+
details
|
|
9493
|
+
).then(
|
|
9494
|
+
(result) => {
|
|
9495
|
+
if (!result.ok) return handleError(result.error, result.pluginName);
|
|
9496
|
+
try {
|
|
9497
|
+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
|
|
9498
|
+
} catch (e2) {
|
|
9499
|
+
handleError(e2, "");
|
|
9500
|
+
}
|
|
9501
|
+
},
|
|
9502
|
+
(e2) => handleError(e2, "")
|
|
9503
|
+
);
|
|
9504
|
+
return;
|
|
9505
|
+
}
|
|
9506
|
+
try {
|
|
9507
|
+
buildOrContextContinue(null, (result, done) => done([], []), () => {
|
|
9508
|
+
});
|
|
9509
|
+
} catch (e2) {
|
|
9510
|
+
handleError(e2, "");
|
|
9511
|
+
}
|
|
9512
|
+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
|
|
9513
|
+
const writeDefault = streamIn.hasFS;
|
|
9514
|
+
const {
|
|
9515
|
+
entries,
|
|
9516
|
+
flags,
|
|
9517
|
+
write,
|
|
9518
|
+
stdinContents,
|
|
9519
|
+
stdinResolveDir,
|
|
9520
|
+
absWorkingDir,
|
|
9521
|
+
nodePaths,
|
|
9522
|
+
mangleCache
|
|
9523
|
+
} = flagsForBuildOptions(callName, options, isTTY2, buildLogLevelDefault, writeDefault);
|
|
9524
|
+
if (write && !streamIn.hasFS) throw new Error(`The "write" option is unavailable in this environment`);
|
|
9525
|
+
const request = {
|
|
9526
|
+
command: "build",
|
|
9527
|
+
key: buildKey,
|
|
9528
|
+
entries,
|
|
9529
|
+
flags,
|
|
9530
|
+
write,
|
|
9531
|
+
stdinContents,
|
|
9532
|
+
stdinResolveDir,
|
|
9533
|
+
absWorkingDir: absWorkingDir || defaultWD2,
|
|
9534
|
+
nodePaths,
|
|
9535
|
+
context: isContext
|
|
9536
|
+
};
|
|
9537
|
+
if (requestPlugins) request.plugins = requestPlugins;
|
|
9538
|
+
if (mangleCache) request.mangleCache = mangleCache;
|
|
9539
|
+
const buildResponseToResult = (response, callback2) => {
|
|
9540
|
+
const result = {
|
|
9541
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
9542
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
9543
|
+
outputFiles: void 0,
|
|
9544
|
+
metafile: void 0,
|
|
9545
|
+
mangleCache: void 0
|
|
9546
|
+
};
|
|
9547
|
+
const originalErrors = result.errors.slice();
|
|
9548
|
+
const originalWarnings = result.warnings.slice();
|
|
9549
|
+
if (response.outputFiles) result.outputFiles = response.outputFiles.map(convertOutputFiles);
|
|
9550
|
+
if (response.metafile) result.metafile = parseJSON(response.metafile);
|
|
9551
|
+
if (response.mangleCache) result.mangleCache = response.mangleCache;
|
|
9552
|
+
if (response.writeToStdout !== void 0) ;
|
|
9553
|
+
runOnEndCallbacks(result, (onEndErrors, onEndWarnings) => {
|
|
9554
|
+
if (originalErrors.length > 0 || onEndErrors.length > 0) {
|
|
9555
|
+
const error2 = failureErrorWithLog("Build failed", originalErrors.concat(onEndErrors), originalWarnings.concat(onEndWarnings));
|
|
9556
|
+
return callback2(error2, null, onEndErrors, onEndWarnings);
|
|
9557
|
+
}
|
|
9558
|
+
callback2(null, result, onEndErrors, onEndWarnings);
|
|
9559
|
+
});
|
|
9560
|
+
};
|
|
9561
|
+
let latestResultPromise;
|
|
9562
|
+
let provideLatestResult;
|
|
9563
|
+
if (isContext)
|
|
9564
|
+
requestCallbacks["on-end"] = (id, request2) => new Promise((resolve5) => {
|
|
9565
|
+
buildResponseToResult(request2, (err, result, onEndErrors, onEndWarnings) => {
|
|
9566
|
+
const response = {
|
|
9567
|
+
errors: onEndErrors,
|
|
9568
|
+
warnings: onEndWarnings
|
|
9569
|
+
};
|
|
9570
|
+
if (provideLatestResult) provideLatestResult(err, result);
|
|
9571
|
+
latestResultPromise = void 0;
|
|
9572
|
+
provideLatestResult = void 0;
|
|
9573
|
+
sendResponse(id, response);
|
|
9574
|
+
resolve5();
|
|
9575
|
+
});
|
|
9576
|
+
});
|
|
9577
|
+
sendRequest(refs, request, (error2, response) => {
|
|
9578
|
+
if (error2) return callback(new Error(error2), null);
|
|
9579
|
+
if (!isContext) {
|
|
9580
|
+
return buildResponseToResult(response, (err, res) => {
|
|
9581
|
+
scheduleOnDisposeCallbacks();
|
|
9582
|
+
return callback(err, res);
|
|
9583
|
+
});
|
|
9584
|
+
}
|
|
9585
|
+
if (response.errors.length > 0) {
|
|
9586
|
+
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
|
|
9587
|
+
}
|
|
9588
|
+
let didDispose = false;
|
|
9589
|
+
const result = {
|
|
9590
|
+
rebuild: () => {
|
|
9591
|
+
if (!latestResultPromise) latestResultPromise = new Promise((resolve5, reject) => {
|
|
9592
|
+
let settlePromise;
|
|
9593
|
+
provideLatestResult = (err, result2) => {
|
|
9594
|
+
if (!settlePromise) settlePromise = () => err ? reject(err) : resolve5(result2);
|
|
9595
|
+
};
|
|
9596
|
+
const triggerAnotherBuild = () => {
|
|
9597
|
+
const request2 = {
|
|
9598
|
+
command: "rebuild",
|
|
9599
|
+
key: buildKey
|
|
9600
|
+
};
|
|
9601
|
+
sendRequest(refs, request2, (error22, response2) => {
|
|
9602
|
+
if (error22) {
|
|
9603
|
+
reject(new Error(error22));
|
|
9604
|
+
} else if (settlePromise) {
|
|
9605
|
+
settlePromise();
|
|
9606
|
+
} else {
|
|
9607
|
+
triggerAnotherBuild();
|
|
9608
|
+
}
|
|
9609
|
+
});
|
|
9610
|
+
};
|
|
9611
|
+
triggerAnotherBuild();
|
|
9612
|
+
});
|
|
9613
|
+
return latestResultPromise;
|
|
9614
|
+
},
|
|
9615
|
+
watch: (options2 = {}) => new Promise((resolve5, reject) => {
|
|
9616
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "watch" API in this environment`);
|
|
9617
|
+
const keys = {};
|
|
9618
|
+
const delay = getFlag(options2, keys, "delay", mustBeInteger);
|
|
9619
|
+
checkForInvalidFlags(options2, keys, `in watch() call`);
|
|
9620
|
+
const request2 = {
|
|
9621
|
+
command: "watch",
|
|
9622
|
+
key: buildKey
|
|
9623
|
+
};
|
|
9624
|
+
if (delay) request2.delay = delay;
|
|
9625
|
+
sendRequest(refs, request2, (error22) => {
|
|
9626
|
+
if (error22) reject(new Error(error22));
|
|
9627
|
+
else resolve5(void 0);
|
|
9628
|
+
});
|
|
9629
|
+
}),
|
|
9630
|
+
serve: (options2 = {}) => new Promise((resolve5, reject) => {
|
|
9631
|
+
if (!streamIn.hasFS) throw new Error(`Cannot use the "serve" API in this environment`);
|
|
9632
|
+
const keys = {};
|
|
9633
|
+
const port = getFlag(options2, keys, "port", mustBeValidPortNumber);
|
|
9634
|
+
const host = getFlag(options2, keys, "host", mustBeString);
|
|
9635
|
+
const servedir = getFlag(options2, keys, "servedir", mustBeString);
|
|
9636
|
+
const keyfile = getFlag(options2, keys, "keyfile", mustBeString);
|
|
9637
|
+
const certfile = getFlag(options2, keys, "certfile", mustBeString);
|
|
9638
|
+
const fallback = getFlag(options2, keys, "fallback", mustBeString);
|
|
9639
|
+
const cors = getFlag(options2, keys, "cors", mustBeObject);
|
|
9640
|
+
const onRequest = getFlag(options2, keys, "onRequest", mustBeFunction);
|
|
9641
|
+
checkForInvalidFlags(options2, keys, `in serve() call`);
|
|
9642
|
+
const request2 = {
|
|
9643
|
+
command: "serve",
|
|
9644
|
+
key: buildKey,
|
|
9645
|
+
onRequest: !!onRequest
|
|
9646
|
+
};
|
|
9647
|
+
if (port !== void 0) request2.port = port;
|
|
9648
|
+
if (host !== void 0) request2.host = host;
|
|
9649
|
+
if (servedir !== void 0) request2.servedir = servedir;
|
|
9650
|
+
if (keyfile !== void 0) request2.keyfile = keyfile;
|
|
9651
|
+
if (certfile !== void 0) request2.certfile = certfile;
|
|
9652
|
+
if (fallback !== void 0) request2.fallback = fallback;
|
|
9653
|
+
if (cors) {
|
|
9654
|
+
const corsKeys = {};
|
|
9655
|
+
const origin = getFlag(cors, corsKeys, "origin", mustBeStringOrArrayOfStrings);
|
|
9656
|
+
checkForInvalidFlags(cors, corsKeys, `on "cors" object`);
|
|
9657
|
+
if (Array.isArray(origin)) request2.corsOrigin = origin;
|
|
9658
|
+
else if (origin !== void 0) request2.corsOrigin = [origin];
|
|
9659
|
+
}
|
|
9660
|
+
sendRequest(refs, request2, (error22, response2) => {
|
|
9661
|
+
if (error22) return reject(new Error(error22));
|
|
9662
|
+
if (onRequest) {
|
|
9663
|
+
requestCallbacks["serve-request"] = (id, request3) => {
|
|
9664
|
+
onRequest(request3.args);
|
|
9665
|
+
sendResponse(id, {});
|
|
9666
|
+
};
|
|
9667
|
+
}
|
|
9668
|
+
resolve5(response2);
|
|
9669
|
+
});
|
|
9670
|
+
}),
|
|
9671
|
+
cancel: () => new Promise((resolve5) => {
|
|
9672
|
+
if (didDispose) return resolve5();
|
|
9673
|
+
const request2 = {
|
|
9674
|
+
command: "cancel",
|
|
9675
|
+
key: buildKey
|
|
9676
|
+
};
|
|
9677
|
+
sendRequest(refs, request2, () => {
|
|
9678
|
+
resolve5();
|
|
9679
|
+
});
|
|
9680
|
+
}),
|
|
9681
|
+
dispose: () => new Promise((resolve5) => {
|
|
9682
|
+
if (didDispose) return resolve5();
|
|
9683
|
+
didDispose = true;
|
|
9684
|
+
const request2 = {
|
|
9685
|
+
command: "dispose",
|
|
9686
|
+
key: buildKey
|
|
9687
|
+
};
|
|
9688
|
+
sendRequest(refs, request2, () => {
|
|
9689
|
+
resolve5();
|
|
9690
|
+
scheduleOnDisposeCallbacks();
|
|
9691
|
+
refs.unref();
|
|
9692
|
+
});
|
|
9693
|
+
})
|
|
9694
|
+
};
|
|
9695
|
+
refs.ref();
|
|
9696
|
+
callback(null, result);
|
|
9697
|
+
});
|
|
9698
|
+
}
|
|
9699
|
+
}
|
|
9700
|
+
var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn, requestCallbacks, initialOptions, plugins, details) => {
|
|
9701
|
+
let onStartCallbacks = [];
|
|
9702
|
+
let onEndCallbacks = [];
|
|
9703
|
+
let onResolveCallbacks = {};
|
|
9704
|
+
let onLoadCallbacks = {};
|
|
9705
|
+
let onDisposeCallbacks = [];
|
|
9706
|
+
let nextCallbackID = 0;
|
|
9707
|
+
let i = 0;
|
|
9708
|
+
let requestPlugins = [];
|
|
9709
|
+
let isSetupDone = false;
|
|
9710
|
+
plugins = [...plugins];
|
|
9711
|
+
for (let item of plugins) {
|
|
9712
|
+
let keys = {};
|
|
9713
|
+
if (typeof item !== "object") throw new Error(`Plugin at index ${i} must be an object`);
|
|
9714
|
+
const name = getFlag(item, keys, "name", mustBeString);
|
|
9715
|
+
if (typeof name !== "string" || name === "") throw new Error(`Plugin at index ${i} is missing a name`);
|
|
9716
|
+
try {
|
|
9717
|
+
let setup = getFlag(item, keys, "setup", mustBeFunction);
|
|
9718
|
+
if (typeof setup !== "function") throw new Error(`Plugin is missing a setup function`);
|
|
9719
|
+
checkForInvalidFlags(item, keys, `on plugin ${quote(name)}`);
|
|
9720
|
+
let plugin = {
|
|
9721
|
+
name,
|
|
9722
|
+
onStart: false,
|
|
9723
|
+
onEnd: false,
|
|
9724
|
+
onResolve: [],
|
|
9725
|
+
onLoad: []
|
|
9726
|
+
};
|
|
9727
|
+
i++;
|
|
9728
|
+
let resolve5 = (path3, options = {}) => {
|
|
9729
|
+
if (!isSetupDone) throw new Error('Cannot call "resolve" before plugin setup has completed');
|
|
9730
|
+
if (typeof path3 !== "string") throw new Error(`The path to resolve must be a string`);
|
|
9731
|
+
let keys2 = /* @__PURE__ */ Object.create(null);
|
|
9732
|
+
let pluginName = getFlag(options, keys2, "pluginName", mustBeString);
|
|
9733
|
+
let importer = getFlag(options, keys2, "importer", mustBeString);
|
|
9734
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
9735
|
+
let resolveDir = getFlag(options, keys2, "resolveDir", mustBeString);
|
|
9736
|
+
let kind = getFlag(options, keys2, "kind", mustBeString);
|
|
9737
|
+
let pluginData = getFlag(options, keys2, "pluginData", canBeAnything);
|
|
9738
|
+
let importAttributes = getFlag(options, keys2, "with", mustBeObject);
|
|
9739
|
+
checkForInvalidFlags(options, keys2, "in resolve() call");
|
|
9740
|
+
return new Promise((resolve22, reject) => {
|
|
9741
|
+
const request = {
|
|
9742
|
+
command: "resolve",
|
|
9743
|
+
path: path3,
|
|
9744
|
+
key: buildKey,
|
|
9745
|
+
pluginName: name
|
|
9746
|
+
};
|
|
9747
|
+
if (pluginName != null) request.pluginName = pluginName;
|
|
9748
|
+
if (importer != null) request.importer = importer;
|
|
9749
|
+
if (namespace != null) request.namespace = namespace;
|
|
9750
|
+
if (resolveDir != null) request.resolveDir = resolveDir;
|
|
9751
|
+
if (kind != null) request.kind = kind;
|
|
9752
|
+
else throw new Error(`Must specify "kind" when calling "resolve"`);
|
|
9753
|
+
if (pluginData != null) request.pluginData = details.store(pluginData);
|
|
9754
|
+
if (importAttributes != null) request.with = sanitizeStringMap(importAttributes, "with");
|
|
9755
|
+
sendRequest(refs, request, (error2, response) => {
|
|
9756
|
+
if (error2 !== null) reject(new Error(error2));
|
|
9757
|
+
else resolve22({
|
|
9758
|
+
errors: replaceDetailsInMessages(response.errors, details),
|
|
9759
|
+
warnings: replaceDetailsInMessages(response.warnings, details),
|
|
9760
|
+
path: response.path,
|
|
9761
|
+
external: response.external,
|
|
9762
|
+
sideEffects: response.sideEffects,
|
|
9763
|
+
namespace: response.namespace,
|
|
9764
|
+
suffix: response.suffix,
|
|
9765
|
+
pluginData: details.load(response.pluginData)
|
|
9766
|
+
});
|
|
9767
|
+
});
|
|
9768
|
+
});
|
|
9769
|
+
};
|
|
9770
|
+
let promise = setup({
|
|
9771
|
+
initialOptions,
|
|
9772
|
+
resolve: resolve5,
|
|
9773
|
+
onStart(callback) {
|
|
9774
|
+
let registeredText = `This error came from the "onStart" callback registered here:`;
|
|
9775
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onStart");
|
|
9776
|
+
onStartCallbacks.push({ name, callback, note: registeredNote });
|
|
9777
|
+
plugin.onStart = true;
|
|
9778
|
+
},
|
|
9779
|
+
onEnd(callback) {
|
|
9780
|
+
let registeredText = `This error came from the "onEnd" callback registered here:`;
|
|
9781
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onEnd");
|
|
9782
|
+
onEndCallbacks.push({ name, callback, note: registeredNote });
|
|
9783
|
+
plugin.onEnd = true;
|
|
9784
|
+
},
|
|
9785
|
+
onResolve(options, callback) {
|
|
9786
|
+
let registeredText = `This error came from the "onResolve" callback registered here:`;
|
|
9787
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onResolve");
|
|
9788
|
+
let keys2 = {};
|
|
9789
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
9790
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
9791
|
+
checkForInvalidFlags(options, keys2, `in onResolve() call for plugin ${quote(name)}`);
|
|
9792
|
+
if (filter == null) throw new Error(`onResolve() call is missing a filter`);
|
|
9793
|
+
let id = nextCallbackID++;
|
|
9794
|
+
onResolveCallbacks[id] = { name, callback, note: registeredNote };
|
|
9795
|
+
plugin.onResolve.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
9796
|
+
},
|
|
9797
|
+
onLoad(options, callback) {
|
|
9798
|
+
let registeredText = `This error came from the "onLoad" callback registered here:`;
|
|
9799
|
+
let registeredNote = extractCallerV8(new Error(registeredText), streamIn, "onLoad");
|
|
9800
|
+
let keys2 = {};
|
|
9801
|
+
let filter = getFlag(options, keys2, "filter", mustBeRegExp);
|
|
9802
|
+
let namespace = getFlag(options, keys2, "namespace", mustBeString);
|
|
9803
|
+
checkForInvalidFlags(options, keys2, `in onLoad() call for plugin ${quote(name)}`);
|
|
9804
|
+
if (filter == null) throw new Error(`onLoad() call is missing a filter`);
|
|
9805
|
+
let id = nextCallbackID++;
|
|
9806
|
+
onLoadCallbacks[id] = { name, callback, note: registeredNote };
|
|
9807
|
+
plugin.onLoad.push({ id, filter: jsRegExpToGoRegExp(filter), namespace: namespace || "" });
|
|
9808
|
+
},
|
|
9809
|
+
onDispose(callback) {
|
|
9810
|
+
onDisposeCallbacks.push(callback);
|
|
9811
|
+
},
|
|
9812
|
+
esbuild: streamIn.esbuild
|
|
9813
|
+
});
|
|
9814
|
+
if (promise) await promise;
|
|
9815
|
+
requestPlugins.push(plugin);
|
|
9816
|
+
} catch (e2) {
|
|
9817
|
+
return { ok: false, error: e2, pluginName: name };
|
|
9818
|
+
}
|
|
9819
|
+
}
|
|
9820
|
+
requestCallbacks["on-start"] = async (id, request) => {
|
|
9821
|
+
details.clear();
|
|
9822
|
+
let response = { errors: [], warnings: [] };
|
|
9823
|
+
await Promise.all(onStartCallbacks.map(async ({ name, callback, note }) => {
|
|
9824
|
+
try {
|
|
9825
|
+
let result = await callback();
|
|
9826
|
+
if (result != null) {
|
|
9827
|
+
if (typeof result !== "object") throw new Error(`Expected onStart() callback in plugin ${quote(name)} to return an object`);
|
|
9828
|
+
let keys = {};
|
|
9829
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
9830
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
9831
|
+
checkForInvalidFlags(result, keys, `from onStart() callback in plugin ${quote(name)}`);
|
|
9832
|
+
if (errors != null) response.errors.push(...sanitizeMessages(errors, "errors", details, name, void 0));
|
|
9833
|
+
if (warnings != null) response.warnings.push(...sanitizeMessages(warnings, "warnings", details, name, void 0));
|
|
9834
|
+
}
|
|
9835
|
+
} catch (e2) {
|
|
9836
|
+
response.errors.push(extractErrorMessageV8(e2, streamIn, details, note && note(), name));
|
|
9837
|
+
}
|
|
9838
|
+
}));
|
|
9839
|
+
sendResponse(id, response);
|
|
9840
|
+
};
|
|
9841
|
+
requestCallbacks["on-resolve"] = async (id, request) => {
|
|
9842
|
+
let response = {}, name = "", callback, note;
|
|
9843
|
+
for (let id2 of request.ids) {
|
|
9844
|
+
try {
|
|
9845
|
+
({ name, callback, note } = onResolveCallbacks[id2]);
|
|
9846
|
+
let result = await callback({
|
|
9847
|
+
path: request.path,
|
|
9848
|
+
importer: request.importer,
|
|
9849
|
+
namespace: request.namespace,
|
|
9850
|
+
resolveDir: request.resolveDir,
|
|
9851
|
+
kind: request.kind,
|
|
9852
|
+
pluginData: details.load(request.pluginData),
|
|
9853
|
+
with: request.with
|
|
9854
|
+
});
|
|
9855
|
+
if (result != null) {
|
|
9856
|
+
if (typeof result !== "object") throw new Error(`Expected onResolve() callback in plugin ${quote(name)} to return an object`);
|
|
9857
|
+
let keys = {};
|
|
9858
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
9859
|
+
let path3 = getFlag(result, keys, "path", mustBeString);
|
|
9860
|
+
let namespace = getFlag(result, keys, "namespace", mustBeString);
|
|
9861
|
+
let suffix = getFlag(result, keys, "suffix", mustBeString);
|
|
9862
|
+
let external = getFlag(result, keys, "external", mustBeBoolean);
|
|
9863
|
+
let sideEffects = getFlag(result, keys, "sideEffects", mustBeBoolean);
|
|
9864
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
9865
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
9866
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
9867
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
9868
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
9869
|
+
checkForInvalidFlags(result, keys, `from onResolve() callback in plugin ${quote(name)}`);
|
|
9870
|
+
response.id = id2;
|
|
9871
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
9872
|
+
if (path3 != null) response.path = path3;
|
|
9873
|
+
if (namespace != null) response.namespace = namespace;
|
|
9874
|
+
if (suffix != null) response.suffix = suffix;
|
|
9875
|
+
if (external != null) response.external = external;
|
|
9876
|
+
if (sideEffects != null) response.sideEffects = sideEffects;
|
|
9877
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
9878
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
9879
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
9880
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
9881
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
9882
|
+
break;
|
|
9883
|
+
}
|
|
9884
|
+
} catch (e2) {
|
|
9885
|
+
response = { id: id2, errors: [extractErrorMessageV8(e2, streamIn, details, note && note(), name)] };
|
|
9886
|
+
break;
|
|
9887
|
+
}
|
|
9888
|
+
}
|
|
9889
|
+
sendResponse(id, response);
|
|
9890
|
+
};
|
|
9891
|
+
requestCallbacks["on-load"] = async (id, request) => {
|
|
9892
|
+
let response = {}, name = "", callback, note;
|
|
9893
|
+
for (let id2 of request.ids) {
|
|
9894
|
+
try {
|
|
9895
|
+
({ name, callback, note } = onLoadCallbacks[id2]);
|
|
9896
|
+
let result = await callback({
|
|
9897
|
+
path: request.path,
|
|
9898
|
+
namespace: request.namespace,
|
|
9899
|
+
suffix: request.suffix,
|
|
9900
|
+
pluginData: details.load(request.pluginData),
|
|
9901
|
+
with: request.with
|
|
9902
|
+
});
|
|
9903
|
+
if (result != null) {
|
|
9904
|
+
if (typeof result !== "object") throw new Error(`Expected onLoad() callback in plugin ${quote(name)} to return an object`);
|
|
9905
|
+
let keys = {};
|
|
9906
|
+
let pluginName = getFlag(result, keys, "pluginName", mustBeString);
|
|
9907
|
+
let contents = getFlag(result, keys, "contents", mustBeStringOrUint8Array);
|
|
9908
|
+
let resolveDir = getFlag(result, keys, "resolveDir", mustBeString);
|
|
9909
|
+
let pluginData = getFlag(result, keys, "pluginData", canBeAnything);
|
|
9910
|
+
let loader = getFlag(result, keys, "loader", mustBeString);
|
|
9911
|
+
let errors = getFlag(result, keys, "errors", mustBeArray);
|
|
9912
|
+
let warnings = getFlag(result, keys, "warnings", mustBeArray);
|
|
9913
|
+
let watchFiles = getFlag(result, keys, "watchFiles", mustBeArrayOfStrings);
|
|
9914
|
+
let watchDirs = getFlag(result, keys, "watchDirs", mustBeArrayOfStrings);
|
|
9915
|
+
checkForInvalidFlags(result, keys, `from onLoad() callback in plugin ${quote(name)}`);
|
|
9916
|
+
response.id = id2;
|
|
9917
|
+
if (pluginName != null) response.pluginName = pluginName;
|
|
9918
|
+
if (contents instanceof Uint8Array) response.contents = contents;
|
|
9919
|
+
else if (contents != null) response.contents = encodeUTF8(contents);
|
|
9920
|
+
if (resolveDir != null) response.resolveDir = resolveDir;
|
|
9921
|
+
if (pluginData != null) response.pluginData = details.store(pluginData);
|
|
9922
|
+
if (loader != null) response.loader = loader;
|
|
9923
|
+
if (errors != null) response.errors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
9924
|
+
if (warnings != null) response.warnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
9925
|
+
if (watchFiles != null) response.watchFiles = sanitizeStringArray(watchFiles, "watchFiles");
|
|
9926
|
+
if (watchDirs != null) response.watchDirs = sanitizeStringArray(watchDirs, "watchDirs");
|
|
9927
|
+
break;
|
|
9928
|
+
}
|
|
9929
|
+
} catch (e2) {
|
|
9930
|
+
response = { id: id2, errors: [extractErrorMessageV8(e2, streamIn, details, note && note(), name)] };
|
|
9931
|
+
break;
|
|
9932
|
+
}
|
|
9933
|
+
}
|
|
9934
|
+
sendResponse(id, response);
|
|
9935
|
+
};
|
|
9936
|
+
let runOnEndCallbacks = (result, done) => done([], []);
|
|
9937
|
+
if (onEndCallbacks.length > 0) {
|
|
9938
|
+
runOnEndCallbacks = (result, done) => {
|
|
9939
|
+
(async () => {
|
|
9940
|
+
const onEndErrors = [];
|
|
9941
|
+
const onEndWarnings = [];
|
|
9942
|
+
for (const { name, callback, note } of onEndCallbacks) {
|
|
9943
|
+
let newErrors;
|
|
9944
|
+
let newWarnings;
|
|
9945
|
+
try {
|
|
9946
|
+
const value = await callback(result);
|
|
9947
|
+
if (value != null) {
|
|
9948
|
+
if (typeof value !== "object") throw new Error(`Expected onEnd() callback in plugin ${quote(name)} to return an object`);
|
|
9949
|
+
let keys = {};
|
|
9950
|
+
let errors = getFlag(value, keys, "errors", mustBeArray);
|
|
9951
|
+
let warnings = getFlag(value, keys, "warnings", mustBeArray);
|
|
9952
|
+
checkForInvalidFlags(value, keys, `from onEnd() callback in plugin ${quote(name)}`);
|
|
9953
|
+
if (errors != null) newErrors = sanitizeMessages(errors, "errors", details, name, void 0);
|
|
9954
|
+
if (warnings != null) newWarnings = sanitizeMessages(warnings, "warnings", details, name, void 0);
|
|
9955
|
+
}
|
|
9956
|
+
} catch (e2) {
|
|
9957
|
+
newErrors = [extractErrorMessageV8(e2, streamIn, details, note && note(), name)];
|
|
9958
|
+
}
|
|
9959
|
+
if (newErrors) {
|
|
9960
|
+
onEndErrors.push(...newErrors);
|
|
9961
|
+
try {
|
|
9962
|
+
result.errors.push(...newErrors);
|
|
9963
|
+
} catch {
|
|
9964
|
+
}
|
|
9965
|
+
}
|
|
9966
|
+
if (newWarnings) {
|
|
9967
|
+
onEndWarnings.push(...newWarnings);
|
|
9968
|
+
try {
|
|
9969
|
+
result.warnings.push(...newWarnings);
|
|
9970
|
+
} catch {
|
|
9971
|
+
}
|
|
9972
|
+
}
|
|
9973
|
+
}
|
|
9974
|
+
done(onEndErrors, onEndWarnings);
|
|
9975
|
+
})();
|
|
9976
|
+
};
|
|
9977
|
+
}
|
|
9978
|
+
let scheduleOnDisposeCallbacks = () => {
|
|
9979
|
+
for (const cb of onDisposeCallbacks) {
|
|
9980
|
+
setTimeout(() => cb(), 0);
|
|
9981
|
+
}
|
|
9982
|
+
};
|
|
9983
|
+
isSetupDone = true;
|
|
9984
|
+
return {
|
|
9985
|
+
ok: true,
|
|
9986
|
+
requestPlugins,
|
|
9987
|
+
runOnEndCallbacks,
|
|
9988
|
+
scheduleOnDisposeCallbacks
|
|
9989
|
+
};
|
|
9990
|
+
};
|
|
9991
|
+
function createObjectStash() {
|
|
9992
|
+
const map = /* @__PURE__ */ new Map();
|
|
9993
|
+
let nextID = 0;
|
|
9994
|
+
return {
|
|
9995
|
+
clear() {
|
|
9996
|
+
map.clear();
|
|
9997
|
+
},
|
|
9998
|
+
load(id) {
|
|
9999
|
+
return map.get(id);
|
|
10000
|
+
},
|
|
10001
|
+
store(value) {
|
|
10002
|
+
if (value === void 0) return -1;
|
|
10003
|
+
const id = nextID++;
|
|
10004
|
+
map.set(id, value);
|
|
10005
|
+
return id;
|
|
10006
|
+
}
|
|
10007
|
+
};
|
|
10008
|
+
}
|
|
10009
|
+
function extractCallerV8(e2, streamIn, ident) {
|
|
10010
|
+
let note;
|
|
10011
|
+
let tried = false;
|
|
10012
|
+
return () => {
|
|
10013
|
+
if (tried) return note;
|
|
10014
|
+
tried = true;
|
|
10015
|
+
try {
|
|
10016
|
+
let lines = (e2.stack + "").split("\n");
|
|
10017
|
+
lines.splice(1, 1);
|
|
10018
|
+
let location = parseStackLinesV8(streamIn, lines, ident);
|
|
10019
|
+
if (location) {
|
|
10020
|
+
note = { text: e2.message, location };
|
|
10021
|
+
return note;
|
|
10022
|
+
}
|
|
10023
|
+
} catch {
|
|
10024
|
+
}
|
|
10025
|
+
};
|
|
10026
|
+
}
|
|
10027
|
+
function extractErrorMessageV8(e2, streamIn, stash, note, pluginName) {
|
|
10028
|
+
let text = "Internal error";
|
|
10029
|
+
let location = null;
|
|
10030
|
+
try {
|
|
10031
|
+
text = (e2 && e2.message || e2) + "";
|
|
10032
|
+
} catch {
|
|
10033
|
+
}
|
|
10034
|
+
try {
|
|
10035
|
+
location = parseStackLinesV8(streamIn, (e2.stack + "").split("\n"), "");
|
|
10036
|
+
} catch {
|
|
10037
|
+
}
|
|
10038
|
+
return { id: "", pluginName, text, location, notes: note ? [note] : [], detail: stash ? stash.store(e2) : -1 };
|
|
10039
|
+
}
|
|
10040
|
+
function parseStackLinesV8(streamIn, lines, ident) {
|
|
10041
|
+
let at = " at ";
|
|
10042
|
+
if (streamIn.readFileSync && !lines[0].startsWith(at) && lines[1].startsWith(at)) {
|
|
10043
|
+
for (let i = 1; i < lines.length; i++) {
|
|
10044
|
+
let line = lines[i];
|
|
10045
|
+
if (!line.startsWith(at)) continue;
|
|
10046
|
+
line = line.slice(at.length);
|
|
10047
|
+
while (true) {
|
|
10048
|
+
let match = /^(?:new |async )?\S+ \((.*)\)$/.exec(line);
|
|
10049
|
+
if (match) {
|
|
10050
|
+
line = match[1];
|
|
10051
|
+
continue;
|
|
10052
|
+
}
|
|
10053
|
+
match = /^eval at \S+ \((.*)\)(?:, \S+:\d+:\d+)?$/.exec(line);
|
|
10054
|
+
if (match) {
|
|
10055
|
+
line = match[1];
|
|
10056
|
+
continue;
|
|
10057
|
+
}
|
|
10058
|
+
match = /^(\S+):(\d+):(\d+)$/.exec(line);
|
|
10059
|
+
if (match) {
|
|
10060
|
+
let contents;
|
|
10061
|
+
try {
|
|
10062
|
+
contents = streamIn.readFileSync(match[1], "utf8");
|
|
10063
|
+
} catch {
|
|
10064
|
+
break;
|
|
10065
|
+
}
|
|
10066
|
+
let lineText = contents.split(/\r\n|\r|\n|\u2028|\u2029/)[+match[2] - 1] || "";
|
|
10067
|
+
let column = +match[3] - 1;
|
|
10068
|
+
let length = lineText.slice(column, column + ident.length) === ident ? ident.length : 0;
|
|
10069
|
+
return {
|
|
10070
|
+
file: match[1],
|
|
10071
|
+
namespace: "file",
|
|
10072
|
+
line: +match[2],
|
|
10073
|
+
column: encodeUTF8(lineText.slice(0, column)).length,
|
|
10074
|
+
length: encodeUTF8(lineText.slice(column, column + length)).length,
|
|
10075
|
+
lineText: lineText + "\n" + lines.slice(1).join("\n"),
|
|
10076
|
+
suggestion: ""
|
|
10077
|
+
};
|
|
10078
|
+
}
|
|
10079
|
+
break;
|
|
10080
|
+
}
|
|
10081
|
+
}
|
|
10082
|
+
}
|
|
10083
|
+
return null;
|
|
10084
|
+
}
|
|
10085
|
+
function failureErrorWithLog(text, errors, warnings) {
|
|
10086
|
+
let limit = 5;
|
|
10087
|
+
text += errors.length < 1 ? "" : ` with ${errors.length} error${errors.length < 2 ? "" : "s"}:` + errors.slice(0, limit + 1).map((e2, i) => {
|
|
10088
|
+
if (i === limit) return "\n...";
|
|
10089
|
+
if (!e2.location) return `
|
|
10090
|
+
error: ${e2.text}`;
|
|
10091
|
+
let { file, line, column } = e2.location;
|
|
10092
|
+
let pluginText = e2.pluginName ? `[plugin: ${e2.pluginName}] ` : "";
|
|
10093
|
+
return `
|
|
10094
|
+
${file}:${line}:${column}: ERROR: ${pluginText}${e2.text}`;
|
|
10095
|
+
}).join("");
|
|
10096
|
+
let error2 = new Error(text);
|
|
10097
|
+
for (const [key, value] of [["errors", errors], ["warnings", warnings]]) {
|
|
10098
|
+
Object.defineProperty(error2, key, {
|
|
10099
|
+
configurable: true,
|
|
10100
|
+
enumerable: true,
|
|
10101
|
+
get: () => value,
|
|
10102
|
+
set: (value2) => Object.defineProperty(error2, key, {
|
|
10103
|
+
configurable: true,
|
|
10104
|
+
enumerable: true,
|
|
10105
|
+
value: value2
|
|
10106
|
+
})
|
|
10107
|
+
});
|
|
10108
|
+
}
|
|
10109
|
+
return error2;
|
|
10110
|
+
}
|
|
10111
|
+
function replaceDetailsInMessages(messages, stash) {
|
|
10112
|
+
for (const message of messages) {
|
|
10113
|
+
message.detail = stash.load(message.detail);
|
|
10114
|
+
}
|
|
10115
|
+
return messages;
|
|
10116
|
+
}
|
|
10117
|
+
function sanitizeLocation(location, where, terminalWidth) {
|
|
10118
|
+
if (location == null) return null;
|
|
10119
|
+
let keys = {};
|
|
10120
|
+
let file = getFlag(location, keys, "file", mustBeString);
|
|
10121
|
+
let namespace = getFlag(location, keys, "namespace", mustBeString);
|
|
10122
|
+
let line = getFlag(location, keys, "line", mustBeInteger);
|
|
10123
|
+
let column = getFlag(location, keys, "column", mustBeInteger);
|
|
10124
|
+
let length = getFlag(location, keys, "length", mustBeInteger);
|
|
10125
|
+
let lineText = getFlag(location, keys, "lineText", mustBeString);
|
|
10126
|
+
let suggestion = getFlag(location, keys, "suggestion", mustBeString);
|
|
10127
|
+
checkForInvalidFlags(location, keys, where);
|
|
10128
|
+
if (lineText) {
|
|
10129
|
+
const relevantASCII = lineText.slice(
|
|
10130
|
+
0,
|
|
10131
|
+
(column && column > 0 ? column : 0) + (length && length > 0 ? length : 0) + (terminalWidth && terminalWidth > 0 ? terminalWidth : 80)
|
|
10132
|
+
);
|
|
10133
|
+
if (!/[\x7F-\uFFFF]/.test(relevantASCII) && !/\n/.test(lineText)) {
|
|
10134
|
+
lineText = relevantASCII;
|
|
10135
|
+
}
|
|
10136
|
+
}
|
|
10137
|
+
return {
|
|
10138
|
+
file: file || "",
|
|
10139
|
+
namespace: namespace || "",
|
|
10140
|
+
line: line || 0,
|
|
10141
|
+
column: column || 0,
|
|
10142
|
+
length: length || 0,
|
|
10143
|
+
lineText: lineText || "",
|
|
10144
|
+
suggestion: suggestion || ""
|
|
10145
|
+
};
|
|
10146
|
+
}
|
|
10147
|
+
function sanitizeMessages(messages, property, stash, fallbackPluginName, terminalWidth) {
|
|
10148
|
+
let messagesClone = [];
|
|
10149
|
+
let index = 0;
|
|
10150
|
+
for (const message of messages) {
|
|
10151
|
+
let keys = {};
|
|
10152
|
+
let id = getFlag(message, keys, "id", mustBeString);
|
|
10153
|
+
let pluginName = getFlag(message, keys, "pluginName", mustBeString);
|
|
10154
|
+
let text = getFlag(message, keys, "text", mustBeString);
|
|
10155
|
+
let location = getFlag(message, keys, "location", mustBeObjectOrNull);
|
|
10156
|
+
let notes = getFlag(message, keys, "notes", mustBeArray);
|
|
10157
|
+
let detail = getFlag(message, keys, "detail", canBeAnything);
|
|
10158
|
+
let where = `in element ${index} of "${property}"`;
|
|
10159
|
+
checkForInvalidFlags(message, keys, where);
|
|
10160
|
+
let notesClone = [];
|
|
10161
|
+
if (notes) {
|
|
10162
|
+
for (const note of notes) {
|
|
10163
|
+
let noteKeys = {};
|
|
10164
|
+
let noteText = getFlag(note, noteKeys, "text", mustBeString);
|
|
10165
|
+
let noteLocation = getFlag(note, noteKeys, "location", mustBeObjectOrNull);
|
|
10166
|
+
checkForInvalidFlags(note, noteKeys, where);
|
|
10167
|
+
notesClone.push({
|
|
10168
|
+
text: noteText || "",
|
|
10169
|
+
location: sanitizeLocation(noteLocation, where, terminalWidth)
|
|
10170
|
+
});
|
|
10171
|
+
}
|
|
10172
|
+
}
|
|
10173
|
+
messagesClone.push({
|
|
10174
|
+
id: id || "",
|
|
10175
|
+
pluginName: pluginName || fallbackPluginName,
|
|
10176
|
+
text: text || "",
|
|
10177
|
+
location: sanitizeLocation(location, where, terminalWidth),
|
|
10178
|
+
notes: notesClone,
|
|
10179
|
+
detail: stash ? stash.store(detail) : -1
|
|
10180
|
+
});
|
|
10181
|
+
index++;
|
|
10182
|
+
}
|
|
10183
|
+
return messagesClone;
|
|
10184
|
+
}
|
|
10185
|
+
function sanitizeStringArray(values, property) {
|
|
10186
|
+
const result = [];
|
|
10187
|
+
for (const value of values) {
|
|
10188
|
+
if (typeof value !== "string") throw new Error(`${quote(property)} must be an array of strings`);
|
|
10189
|
+
result.push(value);
|
|
10190
|
+
}
|
|
10191
|
+
return result;
|
|
10192
|
+
}
|
|
10193
|
+
function sanitizeStringMap(map, property) {
|
|
10194
|
+
const result = /* @__PURE__ */ Object.create(null);
|
|
10195
|
+
for (const key in map) {
|
|
10196
|
+
const value = map[key];
|
|
10197
|
+
if (typeof value !== "string") throw new Error(`key ${quote(key)} in object ${quote(property)} must be a string`);
|
|
10198
|
+
result[key] = value;
|
|
10199
|
+
}
|
|
10200
|
+
return result;
|
|
10201
|
+
}
|
|
10202
|
+
function convertOutputFiles({ path: path3, contents, hash }) {
|
|
10203
|
+
let text = null;
|
|
10204
|
+
return {
|
|
10205
|
+
path: path3,
|
|
10206
|
+
contents,
|
|
10207
|
+
hash,
|
|
10208
|
+
get text() {
|
|
10209
|
+
const binary = this.contents;
|
|
10210
|
+
if (text === null || binary !== contents) {
|
|
10211
|
+
contents = binary;
|
|
10212
|
+
text = decodeUTF8(binary);
|
|
10213
|
+
}
|
|
10214
|
+
return text;
|
|
10215
|
+
}
|
|
10216
|
+
};
|
|
10217
|
+
}
|
|
10218
|
+
function jsRegExpToGoRegExp(regexp) {
|
|
10219
|
+
let result = regexp.source;
|
|
10220
|
+
if (regexp.flags) result = `(?${regexp.flags})${result}`;
|
|
10221
|
+
return result;
|
|
10222
|
+
}
|
|
10223
|
+
function parseJSON(bytes) {
|
|
10224
|
+
let text;
|
|
10225
|
+
try {
|
|
10226
|
+
text = decodeUTF8(bytes);
|
|
10227
|
+
} catch {
|
|
10228
|
+
return JSON_parse(bytes);
|
|
10229
|
+
}
|
|
10230
|
+
return JSON.parse(text);
|
|
10231
|
+
}
|
|
10232
|
+
var fs3 = __require("fs");
|
|
10233
|
+
var os = __require("os");
|
|
10234
|
+
var path = __require("path");
|
|
10235
|
+
var ESBUILD_BINARY_PATH = process.env.ESBUILD_BINARY_PATH || ESBUILD_BINARY_PATH;
|
|
10236
|
+
var isValidBinaryPath = (x2) => !!x2 && x2 !== "/usr/bin/esbuild";
|
|
10237
|
+
var packageDarwin_arm64 = "@esbuild/darwin-arm64";
|
|
10238
|
+
var packageDarwin_x64 = "@esbuild/darwin-x64";
|
|
10239
|
+
var knownWindowsPackages = {
|
|
10240
|
+
"win32 arm64 LE": "@esbuild/win32-arm64",
|
|
10241
|
+
"win32 ia32 LE": "@esbuild/win32-ia32",
|
|
10242
|
+
"win32 x64 LE": "@esbuild/win32-x64"
|
|
10243
|
+
};
|
|
10244
|
+
var knownUnixlikePackages = {
|
|
10245
|
+
"aix ppc64 BE": "@esbuild/aix-ppc64",
|
|
10246
|
+
"android arm64 LE": "@esbuild/android-arm64",
|
|
10247
|
+
"darwin arm64 LE": "@esbuild/darwin-arm64",
|
|
10248
|
+
"darwin x64 LE": "@esbuild/darwin-x64",
|
|
10249
|
+
"freebsd arm64 LE": "@esbuild/freebsd-arm64",
|
|
10250
|
+
"freebsd x64 LE": "@esbuild/freebsd-x64",
|
|
10251
|
+
"linux arm LE": "@esbuild/linux-arm",
|
|
10252
|
+
"linux arm64 LE": "@esbuild/linux-arm64",
|
|
10253
|
+
"linux ia32 LE": "@esbuild/linux-ia32",
|
|
10254
|
+
"linux mips64el LE": "@esbuild/linux-mips64el",
|
|
10255
|
+
"linux ppc64 LE": "@esbuild/linux-ppc64",
|
|
10256
|
+
"linux riscv64 LE": "@esbuild/linux-riscv64",
|
|
10257
|
+
"linux s390x BE": "@esbuild/linux-s390x",
|
|
10258
|
+
"linux x64 LE": "@esbuild/linux-x64",
|
|
10259
|
+
"linux loong64 LE": "@esbuild/linux-loong64",
|
|
10260
|
+
"netbsd arm64 LE": "@esbuild/netbsd-arm64",
|
|
10261
|
+
"netbsd x64 LE": "@esbuild/netbsd-x64",
|
|
10262
|
+
"openbsd arm64 LE": "@esbuild/openbsd-arm64",
|
|
10263
|
+
"openbsd x64 LE": "@esbuild/openbsd-x64",
|
|
10264
|
+
"sunos x64 LE": "@esbuild/sunos-x64"
|
|
10265
|
+
};
|
|
10266
|
+
var knownWebAssemblyFallbackPackages = {
|
|
10267
|
+
"android arm LE": "@esbuild/android-arm",
|
|
10268
|
+
"android x64 LE": "@esbuild/android-x64",
|
|
10269
|
+
"openharmony arm64 LE": "@esbuild/openharmony-arm64"
|
|
10270
|
+
};
|
|
10271
|
+
function pkgAndSubpathForCurrentPlatform() {
|
|
10272
|
+
let pkg;
|
|
10273
|
+
let subpath;
|
|
10274
|
+
let isWASM = false;
|
|
10275
|
+
let platformKey = `${process.platform} ${os.arch()} ${os.endianness()}`;
|
|
10276
|
+
if (platformKey in knownWindowsPackages) {
|
|
10277
|
+
pkg = knownWindowsPackages[platformKey];
|
|
10278
|
+
subpath = "esbuild.exe";
|
|
10279
|
+
} else if (platformKey in knownUnixlikePackages) {
|
|
10280
|
+
pkg = knownUnixlikePackages[platformKey];
|
|
10281
|
+
subpath = "bin/esbuild";
|
|
10282
|
+
} else if (platformKey in knownWebAssemblyFallbackPackages) {
|
|
10283
|
+
pkg = knownWebAssemblyFallbackPackages[platformKey];
|
|
10284
|
+
subpath = "bin/esbuild";
|
|
10285
|
+
isWASM = true;
|
|
10286
|
+
} else {
|
|
10287
|
+
throw new Error(`Unsupported platform: ${platformKey}`);
|
|
10288
|
+
}
|
|
10289
|
+
return { pkg, subpath, isWASM };
|
|
10290
|
+
}
|
|
10291
|
+
function pkgForSomeOtherPlatform() {
|
|
10292
|
+
const libMainJS = __require.resolve("esbuild");
|
|
10293
|
+
const nodeModulesDirectory = path.dirname(path.dirname(path.dirname(libMainJS)));
|
|
10294
|
+
if (path.basename(nodeModulesDirectory) === "node_modules") {
|
|
10295
|
+
for (const unixKey in knownUnixlikePackages) {
|
|
10296
|
+
try {
|
|
10297
|
+
const pkg = knownUnixlikePackages[unixKey];
|
|
10298
|
+
if (fs3.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
10299
|
+
} catch {
|
|
10300
|
+
}
|
|
10301
|
+
}
|
|
10302
|
+
for (const windowsKey in knownWindowsPackages) {
|
|
10303
|
+
try {
|
|
10304
|
+
const pkg = knownWindowsPackages[windowsKey];
|
|
10305
|
+
if (fs3.existsSync(path.join(nodeModulesDirectory, pkg))) return pkg;
|
|
10306
|
+
} catch {
|
|
10307
|
+
}
|
|
10308
|
+
}
|
|
10309
|
+
}
|
|
10310
|
+
return null;
|
|
10311
|
+
}
|
|
10312
|
+
function downloadedBinPath(pkg, subpath) {
|
|
10313
|
+
const esbuildLibDir = path.dirname(__require.resolve("esbuild"));
|
|
10314
|
+
return path.join(esbuildLibDir, `downloaded-${pkg.replace("/", "-")}-${path.basename(subpath)}`);
|
|
10315
|
+
}
|
|
10316
|
+
function generateBinPath() {
|
|
10317
|
+
if (isValidBinaryPath(ESBUILD_BINARY_PATH)) {
|
|
10318
|
+
if (!fs3.existsSync(ESBUILD_BINARY_PATH)) {
|
|
10319
|
+
} else {
|
|
10320
|
+
return { binPath: ESBUILD_BINARY_PATH, isWASM: false };
|
|
10321
|
+
}
|
|
10322
|
+
}
|
|
10323
|
+
const { pkg, subpath, isWASM } = pkgAndSubpathForCurrentPlatform();
|
|
10324
|
+
let binPath;
|
|
10325
|
+
try {
|
|
10326
|
+
binPath = __require.resolve(`${pkg}/${subpath}`);
|
|
10327
|
+
} catch (e2) {
|
|
10328
|
+
binPath = downloadedBinPath(pkg, subpath);
|
|
10329
|
+
if (!fs3.existsSync(binPath)) {
|
|
10330
|
+
try {
|
|
10331
|
+
__require.resolve(pkg);
|
|
10332
|
+
} catch {
|
|
10333
|
+
const otherPkg = pkgForSomeOtherPlatform();
|
|
10334
|
+
if (otherPkg) {
|
|
10335
|
+
let suggestions = `
|
|
10336
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
10337
|
+
needs the "${pkg}" package instead. People often get into this
|
|
10338
|
+
situation by installing esbuild on Windows or macOS and copying "node_modules"
|
|
10339
|
+
into a Docker image that runs Linux, or by copying "node_modules" between
|
|
10340
|
+
Windows and WSL environments.
|
|
10341
|
+
|
|
10342
|
+
If you are installing with npm, you can try not copying the "node_modules"
|
|
10343
|
+
directory when you copy the files over, and running "npm ci" or "npm install"
|
|
10344
|
+
on the destination platform after the copy. Or you could consider using yarn
|
|
10345
|
+
instead of npm which has built-in support for installing a package on multiple
|
|
10346
|
+
platforms simultaneously.
|
|
10347
|
+
|
|
10348
|
+
If you are installing with yarn, you can try listing both this platform and the
|
|
10349
|
+
other platform in your ".yarnrc.yml" file using the "supportedArchitectures"
|
|
10350
|
+
feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
10351
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
10352
|
+
`;
|
|
10353
|
+
if (pkg === packageDarwin_x64 && otherPkg === packageDarwin_arm64 || pkg === packageDarwin_arm64 && otherPkg === packageDarwin_x64) {
|
|
10354
|
+
suggestions = `
|
|
10355
|
+
Specifically the "${otherPkg}" package is present but this platform
|
|
10356
|
+
needs the "${pkg}" package instead. People often get into this
|
|
10357
|
+
situation by installing esbuild with npm running inside of Rosetta 2 and then
|
|
10358
|
+
trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta
|
|
10359
|
+
2 is Apple's on-the-fly x86_64-to-arm64 translation service).
|
|
10360
|
+
|
|
10361
|
+
If you are installing with npm, you can try ensuring that both npm and node are
|
|
10362
|
+
not running under Rosetta 2 and then reinstalling esbuild. This likely involves
|
|
10363
|
+
changing how you installed npm and/or node. For example, installing node with
|
|
10364
|
+
the universal installer here should work: https://nodejs.org/en/download/. Or
|
|
10365
|
+
you could consider using yarn instead of npm which has built-in support for
|
|
10366
|
+
installing a package on multiple platforms simultaneously.
|
|
10367
|
+
|
|
10368
|
+
If you are installing with yarn, you can try listing both "arm64" and "x64"
|
|
10369
|
+
in your ".yarnrc.yml" file using the "supportedArchitectures" feature:
|
|
10370
|
+
https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures
|
|
10371
|
+
Keep in mind that this means multiple copies of esbuild will be present.
|
|
10372
|
+
`;
|
|
10373
|
+
}
|
|
10374
|
+
throw new Error(`
|
|
10375
|
+
You installed esbuild for another platform than the one you're currently using.
|
|
10376
|
+
This won't work because esbuild is written with native code and needs to
|
|
10377
|
+
install a platform-specific binary executable.
|
|
10378
|
+
${suggestions}
|
|
10379
|
+
Another alternative is to use the "esbuild-wasm" package instead, which works
|
|
10380
|
+
the same way on all platforms. But it comes with a heavy performance cost and
|
|
10381
|
+
can sometimes be 10x slower than the "esbuild" package, so you may also not
|
|
10382
|
+
want to do that.
|
|
10383
|
+
`);
|
|
10384
|
+
}
|
|
10385
|
+
throw new Error(`The package "${pkg}" could not be found, and is needed by esbuild.
|
|
10386
|
+
|
|
10387
|
+
If you are installing esbuild with npm, make sure that you don't specify the
|
|
10388
|
+
"--no-optional" or "--omit=optional" flags. The "optionalDependencies" feature
|
|
10389
|
+
of "package.json" is used by esbuild to install the correct binary executable
|
|
10390
|
+
for your current platform.`);
|
|
10391
|
+
}
|
|
10392
|
+
throw e2;
|
|
10393
|
+
}
|
|
10394
|
+
}
|
|
10395
|
+
if (/\.zip\//.test(binPath)) {
|
|
10396
|
+
let pnpapi;
|
|
10397
|
+
try {
|
|
10398
|
+
pnpapi = __require("pnpapi");
|
|
10399
|
+
} catch (e2) {
|
|
10400
|
+
}
|
|
10401
|
+
if (pnpapi) {
|
|
10402
|
+
const root = pnpapi.getPackageInformation(pnpapi.topLevel).packageLocation;
|
|
10403
|
+
const binTargetPath = path.join(
|
|
10404
|
+
root,
|
|
10405
|
+
"node_modules",
|
|
10406
|
+
".cache",
|
|
10407
|
+
"esbuild",
|
|
10408
|
+
`pnpapi-${pkg.replace("/", "-")}-${"0.27.4"}-${path.basename(subpath)}`
|
|
10409
|
+
);
|
|
10410
|
+
if (!fs3.existsSync(binTargetPath)) {
|
|
10411
|
+
fs3.mkdirSync(path.dirname(binTargetPath), { recursive: true });
|
|
10412
|
+
fs3.copyFileSync(binPath, binTargetPath);
|
|
10413
|
+
fs3.chmodSync(binTargetPath, 493);
|
|
10414
|
+
}
|
|
10415
|
+
return { binPath: binTargetPath, isWASM };
|
|
10416
|
+
}
|
|
10417
|
+
}
|
|
10418
|
+
return { binPath, isWASM };
|
|
10419
|
+
}
|
|
10420
|
+
var child_process = __require("child_process");
|
|
10421
|
+
var crypto = __require("crypto");
|
|
10422
|
+
var path2 = __require("path");
|
|
10423
|
+
var fs22 = __require("fs");
|
|
10424
|
+
var os2 = __require("os");
|
|
10425
|
+
var tty = __require("tty");
|
|
10426
|
+
var worker_threads;
|
|
10427
|
+
if (process.env.ESBUILD_WORKER_THREADS !== "0") {
|
|
10428
|
+
try {
|
|
10429
|
+
worker_threads = __require("worker_threads");
|
|
10430
|
+
} catch {
|
|
10431
|
+
}
|
|
10432
|
+
let [major, minor] = process.versions.node.split(".");
|
|
10433
|
+
if (
|
|
10434
|
+
// <v12.17.0 does not work
|
|
10435
|
+
+major < 12 || +major === 12 && +minor < 17 || +major === 13 && +minor < 13
|
|
10436
|
+
) {
|
|
10437
|
+
worker_threads = void 0;
|
|
10438
|
+
}
|
|
10439
|
+
}
|
|
10440
|
+
var _a;
|
|
10441
|
+
var isInternalWorkerThread = ((_a = worker_threads == null ? void 0 : worker_threads.workerData) == null ? void 0 : _a.esbuildVersion) === "0.27.4";
|
|
10442
|
+
var esbuildCommandAndArgs = () => {
|
|
10443
|
+
if ((!ESBUILD_BINARY_PATH || false) && (path2.basename(__filename) !== "main.js" || path2.basename(__dirname) !== "lib")) {
|
|
10444
|
+
throw new Error(
|
|
10445
|
+
`The esbuild JavaScript API cannot be bundled. Please mark the "esbuild" package as external so it's not included in the bundle.
|
|
10446
|
+
|
|
10447
|
+
More information: The file containing the code for esbuild's JavaScript API (${__filename}) does not appear to be inside the esbuild package on the file system, which usually means that the esbuild package was bundled into another file. This is problematic because the API needs to run a binary executable inside the esbuild package which is located using a relative path from the API code to the executable. If the esbuild package is bundled, the relative path will be incorrect and the executable won't be found.`
|
|
10448
|
+
);
|
|
10449
|
+
}
|
|
10450
|
+
if (false) {
|
|
10451
|
+
return ["node", [path2.join(__dirname, "..", "bin", "esbuild")]];
|
|
10452
|
+
} else {
|
|
10453
|
+
const { binPath, isWASM } = generateBinPath();
|
|
10454
|
+
if (isWASM) {
|
|
10455
|
+
return ["node", [binPath]];
|
|
10456
|
+
} else {
|
|
10457
|
+
return [binPath, []];
|
|
10458
|
+
}
|
|
10459
|
+
}
|
|
10460
|
+
};
|
|
10461
|
+
var isTTY = () => tty.isatty(2);
|
|
10462
|
+
var fsSync = {
|
|
10463
|
+
readFile(tempFile, callback) {
|
|
10464
|
+
try {
|
|
10465
|
+
let contents = fs22.readFileSync(tempFile, "utf8");
|
|
10466
|
+
try {
|
|
10467
|
+
fs22.unlinkSync(tempFile);
|
|
10468
|
+
} catch {
|
|
10469
|
+
}
|
|
10470
|
+
callback(null, contents);
|
|
10471
|
+
} catch (err) {
|
|
10472
|
+
callback(err, null);
|
|
10473
|
+
}
|
|
10474
|
+
},
|
|
10475
|
+
writeFile(contents, callback) {
|
|
10476
|
+
try {
|
|
10477
|
+
let tempFile = randomFileName();
|
|
10478
|
+
fs22.writeFileSync(tempFile, contents);
|
|
10479
|
+
callback(tempFile);
|
|
10480
|
+
} catch {
|
|
10481
|
+
callback(null);
|
|
10482
|
+
}
|
|
10483
|
+
}
|
|
10484
|
+
};
|
|
10485
|
+
var fsAsync = {
|
|
10486
|
+
readFile(tempFile, callback) {
|
|
10487
|
+
try {
|
|
10488
|
+
fs22.readFile(tempFile, "utf8", (err, contents) => {
|
|
10489
|
+
try {
|
|
10490
|
+
fs22.unlink(tempFile, () => callback(err, contents));
|
|
10491
|
+
} catch {
|
|
10492
|
+
callback(err, contents);
|
|
10493
|
+
}
|
|
10494
|
+
});
|
|
10495
|
+
} catch (err) {
|
|
10496
|
+
callback(err, null);
|
|
10497
|
+
}
|
|
10498
|
+
},
|
|
10499
|
+
writeFile(contents, callback) {
|
|
10500
|
+
try {
|
|
10501
|
+
let tempFile = randomFileName();
|
|
10502
|
+
fs22.writeFile(tempFile, contents, (err) => err !== null ? callback(null) : callback(tempFile));
|
|
10503
|
+
} catch {
|
|
10504
|
+
callback(null);
|
|
10505
|
+
}
|
|
10506
|
+
}
|
|
10507
|
+
};
|
|
10508
|
+
var version = "0.27.4";
|
|
10509
|
+
var build2 = (options) => ensureServiceIsRunning().build(options);
|
|
10510
|
+
var context = (buildOptions) => ensureServiceIsRunning().context(buildOptions);
|
|
10511
|
+
var transform = (input, options) => ensureServiceIsRunning().transform(input, options);
|
|
10512
|
+
var formatMessages = (messages, options) => ensureServiceIsRunning().formatMessages(messages, options);
|
|
10513
|
+
var analyzeMetafile = (messages, options) => ensureServiceIsRunning().analyzeMetafile(messages, options);
|
|
10514
|
+
var buildSync = (options) => {
|
|
10515
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
10516
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
10517
|
+
return workerThreadService.buildSync(options);
|
|
10518
|
+
}
|
|
10519
|
+
let result;
|
|
10520
|
+
runServiceSync((service) => service.buildOrContext({
|
|
10521
|
+
callName: "buildSync",
|
|
10522
|
+
refs: null,
|
|
10523
|
+
options,
|
|
10524
|
+
isTTY: isTTY(),
|
|
10525
|
+
defaultWD,
|
|
10526
|
+
callback: (err, res) => {
|
|
10527
|
+
if (err) throw err;
|
|
10528
|
+
result = res;
|
|
10529
|
+
}
|
|
10530
|
+
}));
|
|
10531
|
+
return result;
|
|
10532
|
+
};
|
|
10533
|
+
var transformSync = (input, options) => {
|
|
10534
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
10535
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
10536
|
+
return workerThreadService.transformSync(input, options);
|
|
10537
|
+
}
|
|
10538
|
+
let result;
|
|
10539
|
+
runServiceSync((service) => service.transform({
|
|
10540
|
+
callName: "transformSync",
|
|
10541
|
+
refs: null,
|
|
10542
|
+
input,
|
|
10543
|
+
options: options || {},
|
|
10544
|
+
isTTY: isTTY(),
|
|
10545
|
+
fs: fsSync,
|
|
10546
|
+
callback: (err, res) => {
|
|
10547
|
+
if (err) throw err;
|
|
10548
|
+
result = res;
|
|
10549
|
+
}
|
|
10550
|
+
}));
|
|
10551
|
+
return result;
|
|
10552
|
+
};
|
|
10553
|
+
var formatMessagesSync = (messages, options) => {
|
|
10554
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
10555
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
10556
|
+
return workerThreadService.formatMessagesSync(messages, options);
|
|
10557
|
+
}
|
|
10558
|
+
let result;
|
|
10559
|
+
runServiceSync((service) => service.formatMessages({
|
|
10560
|
+
callName: "formatMessagesSync",
|
|
10561
|
+
refs: null,
|
|
10562
|
+
messages,
|
|
10563
|
+
options,
|
|
10564
|
+
callback: (err, res) => {
|
|
10565
|
+
if (err) throw err;
|
|
10566
|
+
result = res;
|
|
10567
|
+
}
|
|
10568
|
+
}));
|
|
10569
|
+
return result;
|
|
10570
|
+
};
|
|
10571
|
+
var analyzeMetafileSync = (metafile, options) => {
|
|
10572
|
+
if (worker_threads && !isInternalWorkerThread) {
|
|
10573
|
+
if (!workerThreadService) workerThreadService = startWorkerThreadService(worker_threads);
|
|
10574
|
+
return workerThreadService.analyzeMetafileSync(metafile, options);
|
|
10575
|
+
}
|
|
10576
|
+
let result;
|
|
10577
|
+
runServiceSync((service) => service.analyzeMetafile({
|
|
10578
|
+
callName: "analyzeMetafileSync",
|
|
10579
|
+
refs: null,
|
|
10580
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
10581
|
+
options,
|
|
10582
|
+
callback: (err, res) => {
|
|
10583
|
+
if (err) throw err;
|
|
10584
|
+
result = res;
|
|
10585
|
+
}
|
|
10586
|
+
}));
|
|
10587
|
+
return result;
|
|
10588
|
+
};
|
|
10589
|
+
var stop = () => {
|
|
10590
|
+
if (stopService) stopService();
|
|
10591
|
+
if (workerThreadService) workerThreadService.stop();
|
|
10592
|
+
return Promise.resolve();
|
|
10593
|
+
};
|
|
10594
|
+
var initializeWasCalled = false;
|
|
10595
|
+
var initialize = (options) => {
|
|
10596
|
+
options = validateInitializeOptions(options || {});
|
|
10597
|
+
if (options.wasmURL) throw new Error(`The "wasmURL" option only works in the browser`);
|
|
10598
|
+
if (options.wasmModule) throw new Error(`The "wasmModule" option only works in the browser`);
|
|
10599
|
+
if (options.worker) throw new Error(`The "worker" option only works in the browser`);
|
|
10600
|
+
if (initializeWasCalled) throw new Error('Cannot call "initialize" more than once');
|
|
10601
|
+
ensureServiceIsRunning();
|
|
10602
|
+
initializeWasCalled = true;
|
|
10603
|
+
return Promise.resolve();
|
|
10604
|
+
};
|
|
10605
|
+
var defaultWD = process.cwd();
|
|
10606
|
+
var longLivedService;
|
|
10607
|
+
var stopService;
|
|
10608
|
+
var ensureServiceIsRunning = () => {
|
|
10609
|
+
if (longLivedService) return longLivedService;
|
|
10610
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
10611
|
+
let child = child_process.spawn(command, args.concat(`--service=${"0.27.4"}`, "--ping"), {
|
|
10612
|
+
windowsHide: true,
|
|
10613
|
+
stdio: ["pipe", "pipe", "inherit"],
|
|
10614
|
+
cwd: defaultWD
|
|
10615
|
+
});
|
|
10616
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
10617
|
+
writeToStdin(bytes) {
|
|
10618
|
+
child.stdin.write(bytes, (err) => {
|
|
10619
|
+
if (err) afterClose(err);
|
|
10620
|
+
});
|
|
10621
|
+
},
|
|
10622
|
+
readFileSync: fs22.readFileSync,
|
|
10623
|
+
isSync: false,
|
|
10624
|
+
hasFS: true,
|
|
10625
|
+
esbuild: node_exports
|
|
10626
|
+
});
|
|
10627
|
+
child.stdin.on("error", afterClose);
|
|
10628
|
+
child.on("error", afterClose);
|
|
10629
|
+
const stdin = child.stdin;
|
|
10630
|
+
const stdout = child.stdout;
|
|
10631
|
+
stdout.on("data", readFromStdout);
|
|
10632
|
+
stdout.on("end", afterClose);
|
|
10633
|
+
stopService = () => {
|
|
10634
|
+
stdin.destroy();
|
|
10635
|
+
stdout.destroy();
|
|
10636
|
+
child.kill();
|
|
10637
|
+
initializeWasCalled = false;
|
|
10638
|
+
longLivedService = void 0;
|
|
10639
|
+
stopService = void 0;
|
|
10640
|
+
};
|
|
10641
|
+
let refCount = 0;
|
|
10642
|
+
child.unref();
|
|
10643
|
+
if (stdin.unref) {
|
|
10644
|
+
stdin.unref();
|
|
10645
|
+
}
|
|
10646
|
+
if (stdout.unref) {
|
|
10647
|
+
stdout.unref();
|
|
10648
|
+
}
|
|
10649
|
+
const refs = {
|
|
10650
|
+
ref() {
|
|
10651
|
+
if (++refCount === 1) child.ref();
|
|
10652
|
+
},
|
|
10653
|
+
unref() {
|
|
10654
|
+
if (--refCount === 0) child.unref();
|
|
10655
|
+
}
|
|
10656
|
+
};
|
|
10657
|
+
longLivedService = {
|
|
10658
|
+
build: (options) => new Promise((resolve5, reject) => {
|
|
10659
|
+
service.buildOrContext({
|
|
10660
|
+
callName: "build",
|
|
10661
|
+
refs,
|
|
10662
|
+
options,
|
|
10663
|
+
isTTY: isTTY(),
|
|
10664
|
+
defaultWD,
|
|
10665
|
+
callback: (err, res) => err ? reject(err) : resolve5(res)
|
|
10666
|
+
});
|
|
10667
|
+
}),
|
|
10668
|
+
context: (options) => new Promise((resolve5, reject) => service.buildOrContext({
|
|
10669
|
+
callName: "context",
|
|
10670
|
+
refs,
|
|
10671
|
+
options,
|
|
10672
|
+
isTTY: isTTY(),
|
|
10673
|
+
defaultWD,
|
|
10674
|
+
callback: (err, res) => err ? reject(err) : resolve5(res)
|
|
10675
|
+
})),
|
|
10676
|
+
transform: (input, options) => new Promise((resolve5, reject) => service.transform({
|
|
10677
|
+
callName: "transform",
|
|
10678
|
+
refs,
|
|
10679
|
+
input,
|
|
10680
|
+
options: options || {},
|
|
10681
|
+
isTTY: isTTY(),
|
|
10682
|
+
fs: fsAsync,
|
|
10683
|
+
callback: (err, res) => err ? reject(err) : resolve5(res)
|
|
10684
|
+
})),
|
|
10685
|
+
formatMessages: (messages, options) => new Promise((resolve5, reject) => service.formatMessages({
|
|
10686
|
+
callName: "formatMessages",
|
|
10687
|
+
refs,
|
|
10688
|
+
messages,
|
|
10689
|
+
options,
|
|
10690
|
+
callback: (err, res) => err ? reject(err) : resolve5(res)
|
|
10691
|
+
})),
|
|
10692
|
+
analyzeMetafile: (metafile, options) => new Promise((resolve5, reject) => service.analyzeMetafile({
|
|
10693
|
+
callName: "analyzeMetafile",
|
|
10694
|
+
refs,
|
|
10695
|
+
metafile: typeof metafile === "string" ? metafile : JSON.stringify(metafile),
|
|
10696
|
+
options,
|
|
10697
|
+
callback: (err, res) => err ? reject(err) : resolve5(res)
|
|
10698
|
+
}))
|
|
10699
|
+
};
|
|
10700
|
+
return longLivedService;
|
|
10701
|
+
};
|
|
10702
|
+
var runServiceSync = (callback) => {
|
|
10703
|
+
let [command, args] = esbuildCommandAndArgs();
|
|
10704
|
+
let stdin = new Uint8Array();
|
|
10705
|
+
let { readFromStdout, afterClose, service } = createChannel({
|
|
10706
|
+
writeToStdin(bytes) {
|
|
10707
|
+
if (stdin.length !== 0) throw new Error("Must run at most one command");
|
|
10708
|
+
stdin = bytes;
|
|
10709
|
+
},
|
|
10710
|
+
isSync: true,
|
|
10711
|
+
hasFS: true,
|
|
10712
|
+
esbuild: node_exports
|
|
10713
|
+
});
|
|
10714
|
+
callback(service);
|
|
10715
|
+
let stdout = child_process.execFileSync(command, args.concat(`--service=${"0.27.4"}`), {
|
|
10716
|
+
cwd: defaultWD,
|
|
10717
|
+
windowsHide: true,
|
|
10718
|
+
input: stdin,
|
|
10719
|
+
// We don't know how large the output could be. If it's too large, the
|
|
10720
|
+
// command will fail with ENOBUFS. Reserve 16mb for now since that feels
|
|
10721
|
+
// like it should be enough. Also allow overriding this with an environment
|
|
10722
|
+
// variable.
|
|
10723
|
+
maxBuffer: +process.env.ESBUILD_MAX_BUFFER || 16 * 1024 * 1024
|
|
10724
|
+
});
|
|
10725
|
+
readFromStdout(stdout);
|
|
10726
|
+
afterClose(null);
|
|
10727
|
+
};
|
|
10728
|
+
var randomFileName = () => {
|
|
10729
|
+
return path2.join(os2.tmpdir(), `esbuild-${crypto.randomBytes(32).toString("hex")}`);
|
|
10730
|
+
};
|
|
10731
|
+
var workerThreadService = null;
|
|
10732
|
+
var startWorkerThreadService = (worker_threads2) => {
|
|
10733
|
+
let { port1: mainPort, port2: workerPort } = new worker_threads2.MessageChannel();
|
|
10734
|
+
let worker = new worker_threads2.Worker(__filename, {
|
|
10735
|
+
workerData: { workerPort, defaultWD, esbuildVersion: "0.27.4" },
|
|
10736
|
+
transferList: [workerPort],
|
|
10737
|
+
// From node's documentation: https://nodejs.org/api/worker_threads.html
|
|
10738
|
+
//
|
|
10739
|
+
// Take care when launching worker threads from preload scripts (scripts loaded
|
|
10740
|
+
// and run using the `-r` command line flag). Unless the `execArgv` option is
|
|
10741
|
+
// explicitly set, new Worker threads automatically inherit the command line flags
|
|
10742
|
+
// from the running process and will preload the same preload scripts as the main
|
|
10743
|
+
// thread. If the preload script unconditionally launches a worker thread, every
|
|
10744
|
+
// thread spawned will spawn another until the application crashes.
|
|
10745
|
+
//
|
|
10746
|
+
execArgv: []
|
|
10747
|
+
});
|
|
10748
|
+
let nextID = 0;
|
|
10749
|
+
let fakeBuildError = (text) => {
|
|
10750
|
+
let error2 = new Error(`Build failed with 1 error:
|
|
10751
|
+
error: ${text}`);
|
|
10752
|
+
let errors = [{ id: "", pluginName: "", text, location: null, notes: [], detail: void 0 }];
|
|
10753
|
+
error2.errors = errors;
|
|
10754
|
+
error2.warnings = [];
|
|
10755
|
+
return error2;
|
|
10756
|
+
};
|
|
10757
|
+
let validateBuildSyncOptions = (options) => {
|
|
10758
|
+
if (!options) return;
|
|
10759
|
+
let plugins = options.plugins;
|
|
10760
|
+
if (plugins && plugins.length > 0) throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
|
|
10761
|
+
};
|
|
10762
|
+
let applyProperties = (object, properties) => {
|
|
10763
|
+
for (let key in properties) {
|
|
10764
|
+
object[key] = properties[key];
|
|
10765
|
+
}
|
|
10766
|
+
};
|
|
10767
|
+
let runCallSync = (command, args) => {
|
|
10768
|
+
let id = nextID++;
|
|
10769
|
+
let sharedBuffer = new SharedArrayBuffer(8);
|
|
10770
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
10771
|
+
let msg = { sharedBuffer, id, command, args };
|
|
10772
|
+
worker.postMessage(msg);
|
|
10773
|
+
let status = Atomics.wait(sharedBufferView, 0, 0);
|
|
10774
|
+
if (status !== "ok" && status !== "not-equal") throw new Error("Internal error: Atomics.wait() failed: " + status);
|
|
10775
|
+
let { message: { id: id2, resolve: resolve5, reject, properties } } = worker_threads2.receiveMessageOnPort(mainPort);
|
|
10776
|
+
if (id !== id2) throw new Error(`Internal error: Expected id ${id} but got id ${id2}`);
|
|
10777
|
+
if (reject) {
|
|
10778
|
+
applyProperties(reject, properties);
|
|
10779
|
+
throw reject;
|
|
10780
|
+
}
|
|
10781
|
+
return resolve5;
|
|
10782
|
+
};
|
|
10783
|
+
worker.unref();
|
|
10784
|
+
return {
|
|
10785
|
+
buildSync(options) {
|
|
10786
|
+
validateBuildSyncOptions(options);
|
|
10787
|
+
return runCallSync("build", [options]);
|
|
10788
|
+
},
|
|
10789
|
+
transformSync(input, options) {
|
|
10790
|
+
return runCallSync("transform", [input, options]);
|
|
10791
|
+
},
|
|
10792
|
+
formatMessagesSync(messages, options) {
|
|
10793
|
+
return runCallSync("formatMessages", [messages, options]);
|
|
10794
|
+
},
|
|
10795
|
+
analyzeMetafileSync(metafile, options) {
|
|
10796
|
+
return runCallSync("analyzeMetafile", [metafile, options]);
|
|
10797
|
+
},
|
|
10798
|
+
stop() {
|
|
10799
|
+
worker.terminate();
|
|
10800
|
+
workerThreadService = null;
|
|
10801
|
+
}
|
|
10802
|
+
};
|
|
10803
|
+
};
|
|
10804
|
+
var startSyncServiceWorker = () => {
|
|
10805
|
+
let workerPort = worker_threads.workerData.workerPort;
|
|
10806
|
+
let parentPort = worker_threads.parentPort;
|
|
10807
|
+
let extractProperties = (object) => {
|
|
10808
|
+
let properties = {};
|
|
10809
|
+
if (object && typeof object === "object") {
|
|
10810
|
+
for (let key in object) {
|
|
10811
|
+
properties[key] = object[key];
|
|
10812
|
+
}
|
|
10813
|
+
}
|
|
10814
|
+
return properties;
|
|
10815
|
+
};
|
|
10816
|
+
try {
|
|
10817
|
+
let service = ensureServiceIsRunning();
|
|
10818
|
+
defaultWD = worker_threads.workerData.defaultWD;
|
|
10819
|
+
parentPort.on("message", (msg) => {
|
|
10820
|
+
(async () => {
|
|
10821
|
+
let { sharedBuffer, id, command, args } = msg;
|
|
10822
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
10823
|
+
try {
|
|
10824
|
+
switch (command) {
|
|
10825
|
+
case "build":
|
|
10826
|
+
workerPort.postMessage({ id, resolve: await service.build(args[0]) });
|
|
10827
|
+
break;
|
|
10828
|
+
case "transform":
|
|
10829
|
+
workerPort.postMessage({ id, resolve: await service.transform(args[0], args[1]) });
|
|
10830
|
+
break;
|
|
10831
|
+
case "formatMessages":
|
|
10832
|
+
workerPort.postMessage({ id, resolve: await service.formatMessages(args[0], args[1]) });
|
|
10833
|
+
break;
|
|
10834
|
+
case "analyzeMetafile":
|
|
10835
|
+
workerPort.postMessage({ id, resolve: await service.analyzeMetafile(args[0], args[1]) });
|
|
10836
|
+
break;
|
|
10837
|
+
default:
|
|
10838
|
+
throw new Error(`Invalid command: ${command}`);
|
|
10839
|
+
}
|
|
10840
|
+
} catch (reject) {
|
|
10841
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
10842
|
+
}
|
|
10843
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
10844
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
10845
|
+
})();
|
|
10846
|
+
});
|
|
10847
|
+
} catch (reject) {
|
|
10848
|
+
parentPort.on("message", (msg) => {
|
|
10849
|
+
let { sharedBuffer, id } = msg;
|
|
10850
|
+
let sharedBufferView = new Int32Array(sharedBuffer);
|
|
10851
|
+
workerPort.postMessage({ id, reject, properties: extractProperties(reject) });
|
|
10852
|
+
Atomics.add(sharedBufferView, 0, 1);
|
|
10853
|
+
Atomics.notify(sharedBufferView, 0, Infinity);
|
|
10854
|
+
});
|
|
10855
|
+
}
|
|
10856
|
+
};
|
|
10857
|
+
if (isInternalWorkerThread) {
|
|
10858
|
+
startSyncServiceWorker();
|
|
10859
|
+
}
|
|
10860
|
+
var node_default = node_exports;
|
|
10861
|
+
}
|
|
10862
|
+
});
|
|
10863
|
+
|
|
10864
|
+
// packages/tooling/src/utils/bundle-edge-function.ts
|
|
10865
|
+
var bundle_edge_function_exports = {};
|
|
10866
|
+
__export(bundle_edge_function_exports, {
|
|
10867
|
+
buildSupabaseEdgeFunctions: () => buildSupabaseEdgeFunctions,
|
|
10868
|
+
bundleEdgeFunction: () => bundleEdgeFunction
|
|
10869
|
+
});
|
|
10870
|
+
import { resolve as resolve4, dirname as dirname4, join as join3 } from "node:path";
|
|
10871
|
+
import fs2 from "node:fs";
|
|
10872
|
+
function detectWorkspace() {
|
|
10873
|
+
let currentDir = process.cwd();
|
|
10874
|
+
const maxDepth = 10;
|
|
10875
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
10876
|
+
const packageJsonPath = join3(currentDir, "package.json");
|
|
10877
|
+
if (fs2.existsSync(packageJsonPath)) {
|
|
10878
|
+
try {
|
|
10879
|
+
const packageJson = JSON.parse(fs2.readFileSync(packageJsonPath, "utf8"));
|
|
10880
|
+
const hasWorkspaces = Array.isArray(packageJson.workspaces);
|
|
10881
|
+
const hasDndevPackages = hasWorkspaces && packageJson.workspaces.some(
|
|
10882
|
+
(w2) => w2 === "packages/**" || w2.startsWith("packages/")
|
|
10883
|
+
);
|
|
10884
|
+
const isDndevRepo = hasDndevPackages && (fs2.existsSync(join3(currentDir, "packages", "core")) || fs2.existsSync(join3(currentDir, "packages", "functions")));
|
|
10885
|
+
if (isDndevRepo) {
|
|
10886
|
+
return { type: "dndev", root: currentDir };
|
|
10887
|
+
}
|
|
10888
|
+
if (hasWorkspaces) {
|
|
10889
|
+
const dndevPattern = packageJson.workspaces.find(
|
|
10890
|
+
(w2) => w2.includes("dndev/packages")
|
|
10891
|
+
);
|
|
10892
|
+
if (dndevPattern) {
|
|
10893
|
+
const dndevRelPath = dndevPattern.replace(/\/packages.*$/, "");
|
|
10894
|
+
const dndevRoot = resolve4(currentDir, dndevRelPath);
|
|
10895
|
+
if (fs2.existsSync(join3(dndevRoot, "packages", "core"))) {
|
|
10896
|
+
return { type: "dndev", root: dndevRoot };
|
|
10897
|
+
}
|
|
10898
|
+
}
|
|
10899
|
+
}
|
|
10900
|
+
} catch {
|
|
10901
|
+
}
|
|
10902
|
+
}
|
|
10903
|
+
const parentDir = dirname4(currentDir);
|
|
10904
|
+
if (parentDir === currentDir) break;
|
|
10905
|
+
currentDir = parentDir;
|
|
10906
|
+
}
|
|
10907
|
+
return { type: "npm", root: process.cwd() };
|
|
10908
|
+
}
|
|
10909
|
+
function readDenoImports(functionsDir) {
|
|
10910
|
+
const denoJsonPath = join3(functionsDir, "deno.json");
|
|
10911
|
+
if (!fs2.existsSync(denoJsonPath)) {
|
|
10912
|
+
throw new Error(
|
|
10913
|
+
`deno.json not found in ${functionsDir}. Required for edge function bundling.`
|
|
10914
|
+
);
|
|
10915
|
+
}
|
|
10916
|
+
const content = JSON.parse(fs2.readFileSync(denoJsonPath, "utf8"));
|
|
10917
|
+
return content.imports ?? {};
|
|
10918
|
+
}
|
|
10919
|
+
function findMatchingSpecifier(importPath, imports) {
|
|
10920
|
+
if (imports[importPath]) return importPath;
|
|
10921
|
+
for (const key of Object.keys(imports)) {
|
|
10922
|
+
if (key.endsWith("/") && importPath.startsWith(key)) return key;
|
|
10923
|
+
}
|
|
10924
|
+
return null;
|
|
10925
|
+
}
|
|
10926
|
+
function resolvePackageExport(packageName, subpath, fromDir) {
|
|
10927
|
+
const pkgDir = resolvePackage(packageName, fromDir);
|
|
10928
|
+
if (!pkgDir) return null;
|
|
10929
|
+
try {
|
|
10930
|
+
const pkgJson = JSON.parse(fs2.readFileSync(join3(pkgDir, "package.json"), "utf8"));
|
|
10931
|
+
const exports = pkgJson.exports;
|
|
10932
|
+
if (!exports) return null;
|
|
10933
|
+
const entry = exports[subpath];
|
|
10934
|
+
if (!entry) return null;
|
|
10935
|
+
const target = typeof entry === "string" ? entry : entry.import ?? entry.default ?? null;
|
|
10936
|
+
if (!target) return null;
|
|
10937
|
+
const resolved = resolve4(pkgDir, target);
|
|
10938
|
+
if (fs2.existsSync(resolved)) return resolved;
|
|
10939
|
+
} catch {
|
|
10940
|
+
}
|
|
10941
|
+
return null;
|
|
10942
|
+
}
|
|
10943
|
+
function createDenoEdgePlugin(workspace, denoImports, functionsDir) {
|
|
10944
|
+
return {
|
|
10945
|
+
name: "deno-edge-externals",
|
|
10946
|
+
setup(build2) {
|
|
10947
|
+
build2.onResolve({ filter: /^@donotdev\/functions\/.+/ }, (args) => {
|
|
10948
|
+
const subpath = args.path.replace("@donotdev/functions/", "");
|
|
10949
|
+
if (workspace.type === "dndev") {
|
|
10950
|
+
return {
|
|
10951
|
+
path: resolve4(workspace.root, "packages", "functions", "src", subpath, "index.ts")
|
|
10952
|
+
};
|
|
10953
|
+
}
|
|
10954
|
+
const resolved = resolvePackageExport("@donotdev/functions", `./${subpath}`, functionsDir);
|
|
10955
|
+
if (resolved) return { path: resolved };
|
|
10956
|
+
return null;
|
|
10957
|
+
});
|
|
10958
|
+
build2.onResolve({ filter: /^@donotdev\/core$/ }, (args) => {
|
|
10959
|
+
if (workspace.type === "dndev") {
|
|
10960
|
+
return {
|
|
10961
|
+
path: resolve4(workspace.root, "packages", "core", "server.ts")
|
|
10962
|
+
};
|
|
10963
|
+
}
|
|
10964
|
+
return build2.resolve("@donotdev/core/server", {
|
|
10965
|
+
kind: args.kind,
|
|
10966
|
+
resolveDir: args.resolveDir
|
|
10967
|
+
});
|
|
10968
|
+
});
|
|
10969
|
+
build2.onResolve({ filter: /^@donotdev\/core\/.+/ }, (args) => {
|
|
10970
|
+
const subpath = args.path.replace("@donotdev/core/", "");
|
|
10971
|
+
if (workspace.type === "dndev") {
|
|
10972
|
+
return {
|
|
10973
|
+
path: resolve4(workspace.root, "packages", "core", `${subpath}.ts`)
|
|
10974
|
+
};
|
|
10975
|
+
}
|
|
10976
|
+
const resolved = resolvePackageExport("@donotdev/core", `./${subpath}`, functionsDir);
|
|
10977
|
+
if (resolved) return { path: resolved };
|
|
10978
|
+
return null;
|
|
10979
|
+
});
|
|
10980
|
+
build2.onResolve({ filter: /^@donotdev\/utils$/ }, (args) => {
|
|
10981
|
+
if (workspace.type === "dndev") {
|
|
10982
|
+
return {
|
|
10983
|
+
path: resolve4(workspace.root, "packages", "core", "utils", "src", "server", "index.ts")
|
|
10984
|
+
};
|
|
10985
|
+
}
|
|
10986
|
+
const resolved = resolvePackageExport("@donotdev/core", "./server", functionsDir);
|
|
10987
|
+
if (resolved) return { path: resolved };
|
|
10988
|
+
return build2.resolve("@donotdev/core/server", {
|
|
10989
|
+
kind: args.kind,
|
|
10990
|
+
resolveDir: args.resolveDir
|
|
10991
|
+
});
|
|
10992
|
+
});
|
|
10993
|
+
build2.onResolve({ filter: /^@donotdev\/utils\/.+/ }, (args) => {
|
|
10994
|
+
const subpath = args.path.replace("@donotdev/utils/", "");
|
|
10995
|
+
if (workspace.type === "dndev") {
|
|
10996
|
+
return {
|
|
10997
|
+
path: resolve4(workspace.root, "packages", "core", "utils", "src", subpath, "index.ts")
|
|
10998
|
+
};
|
|
10999
|
+
}
|
|
11000
|
+
const resolved = resolvePackageExport("@donotdev/core", `./${subpath}`, functionsDir);
|
|
11001
|
+
if (resolved) return { path: resolved };
|
|
11002
|
+
return null;
|
|
11003
|
+
});
|
|
11004
|
+
build2.onResolve({ filter: /^@donotdev\/supabase$/ }, (args) => {
|
|
11005
|
+
if (workspace.type === "dndev") {
|
|
11006
|
+
return {
|
|
11007
|
+
path: resolve4(workspace.root, "packages", "providers", "supabase", "src", "server", "index.ts")
|
|
11008
|
+
};
|
|
11009
|
+
}
|
|
11010
|
+
const resolved = resolvePackageExport("@donotdev/supabase", "./server", functionsDir);
|
|
11011
|
+
if (resolved) return { path: resolved };
|
|
11012
|
+
return build2.resolve("@donotdev/supabase/server", {
|
|
11013
|
+
kind: args.kind,
|
|
11014
|
+
resolveDir: args.resolveDir
|
|
11015
|
+
});
|
|
11016
|
+
});
|
|
11017
|
+
for (const [specifier, target] of Object.entries(denoImports)) {
|
|
11018
|
+
if (target.startsWith("npm:")) continue;
|
|
11019
|
+
if (specifier.endsWith("/")) {
|
|
11020
|
+
const prefix = specifier;
|
|
11021
|
+
const basePath = resolve4(functionsDir, target);
|
|
11022
|
+
const escapedPrefix = prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11023
|
+
build2.onResolve({ filter: new RegExp(`^${escapedPrefix}`) }, (args) => {
|
|
11024
|
+
const subpath = args.path.slice(prefix.length);
|
|
11025
|
+
return { path: resolve4(basePath, subpath) };
|
|
11026
|
+
});
|
|
11027
|
+
}
|
|
11028
|
+
}
|
|
11029
|
+
build2.onResolve({ filter: /.*/ }, (args) => {
|
|
11030
|
+
if (args.kind === "entry-point") return null;
|
|
11031
|
+
if (args.path.startsWith(".") || args.path.startsWith("/")) return null;
|
|
11032
|
+
if (args.path.startsWith("@donotdev/")) return null;
|
|
11033
|
+
const packageRoot = args.path.startsWith("@") ? args.path.split("/").slice(0, 2).join("/") : args.path.split("/")[0];
|
|
11034
|
+
if (packageRoot && ALWAYS_BUNDLE.has(packageRoot)) return null;
|
|
11035
|
+
const specifier = findMatchingSpecifier(args.path, denoImports);
|
|
11036
|
+
if (specifier) {
|
|
11037
|
+
const target = denoImports[specifier];
|
|
11038
|
+
if (!target.startsWith("npm:")) return null;
|
|
11039
|
+
return { path: target, external: true };
|
|
11040
|
+
}
|
|
11041
|
+
return { path: `npm:${args.path}`, external: true };
|
|
11042
|
+
});
|
|
11043
|
+
}
|
|
11044
|
+
};
|
|
11045
|
+
}
|
|
11046
|
+
async function bundleEdgeFunction(options) {
|
|
11047
|
+
const { entryPointPath, functionsDir } = options;
|
|
11048
|
+
const workspace = detectWorkspace();
|
|
11049
|
+
const denoImports = readDenoImports(functionsDir);
|
|
11050
|
+
const alias = {};
|
|
11051
|
+
if (workspace.type === "dndev") {
|
|
11052
|
+
alias["@donotdev/types"] = join3(workspace.root, "packages", "core", "types", "src");
|
|
11053
|
+
alias["@donotdev/functions"] = join3(workspace.root, "packages", "functions", "src");
|
|
11054
|
+
alias["@donotdev/utils"] = join3(workspace.root, "packages", "core", "utils", "src");
|
|
11055
|
+
alias["@donotdev/schemas"] = join3(workspace.root, "packages", "core", "schemas", "src");
|
|
11056
|
+
alias["@donotdev/core"] = join3(workspace.root, "packages", "core");
|
|
11057
|
+
}
|
|
11058
|
+
const config = {
|
|
11059
|
+
entryPoints: [entryPointPath],
|
|
11060
|
+
bundle: true,
|
|
11061
|
+
write: false,
|
|
11062
|
+
// in-memory output
|
|
11063
|
+
format: "esm",
|
|
11064
|
+
platform: "browser",
|
|
11065
|
+
// Deno is closer to browser than node (no node builtins)
|
|
11066
|
+
target: "esnext",
|
|
11067
|
+
// Deno supports latest ES
|
|
11068
|
+
treeShaking: true,
|
|
11069
|
+
minify: false,
|
|
11070
|
+
// keep readable for debugging deployed functions
|
|
11071
|
+
sourcemap: false,
|
|
11072
|
+
// Supabase doesn't use sourcemaps
|
|
11073
|
+
keepNames: true,
|
|
11074
|
+
loader: { ".ts": "ts", ".tsx": "tsx" },
|
|
11075
|
+
alias,
|
|
11076
|
+
plugins: [createDenoEdgePlugin(workspace, denoImports, functionsDir)],
|
|
11077
|
+
mainFields: ["module", "main"],
|
|
11078
|
+
conditions: ["import", "module"],
|
|
11079
|
+
logLevel: "warning"
|
|
11080
|
+
};
|
|
11081
|
+
const result = await (0, import_esbuild.build)(config);
|
|
11082
|
+
if (result.errors.length > 0) {
|
|
11083
|
+
const errorMessages = result.errors.map((e2) => e2.text).join("\n");
|
|
11084
|
+
throw new Error(`Edge function bundling failed:
|
|
11085
|
+
${errorMessages}`);
|
|
11086
|
+
}
|
|
11087
|
+
if (result.warnings.length > 0) {
|
|
11088
|
+
for (const warning of result.warnings) {
|
|
11089
|
+
log.debug(`[bundle-edge] Warning: ${warning.text}`);
|
|
11090
|
+
}
|
|
11091
|
+
}
|
|
11092
|
+
if (!result.outputFiles?.[0]) {
|
|
11093
|
+
throw new Error("esbuild produced no output");
|
|
11094
|
+
}
|
|
11095
|
+
return result.outputFiles[0].text;
|
|
11096
|
+
}
|
|
11097
|
+
async function buildSupabaseEdgeFunctions(functionsDir) {
|
|
11098
|
+
const buildDir = join3(functionsDir, ".build");
|
|
11099
|
+
fs2.mkdirSync(buildDir, { recursive: true });
|
|
11100
|
+
const entries = fs2.readdirSync(functionsDir).filter((item) => {
|
|
11101
|
+
const itemPath = join3(functionsDir, item);
|
|
11102
|
+
if (!fs2.statSync(itemPath).isDirectory()) return false;
|
|
11103
|
+
if (item === ".build") return false;
|
|
11104
|
+
return fs2.existsSync(join3(itemPath, "index.ts"));
|
|
11105
|
+
});
|
|
11106
|
+
if (entries.length === 0) {
|
|
11107
|
+
log.warn("No edge functions found (no index.ts in any subdirectory)");
|
|
11108
|
+
return { success: true, functions: [], errors: [] };
|
|
11109
|
+
}
|
|
11110
|
+
log.info(`Bundling ${entries.length} edge function(s)...`);
|
|
11111
|
+
const results = [];
|
|
11112
|
+
const errors = [];
|
|
11113
|
+
for (const functionName of entries) {
|
|
11114
|
+
const entryPointPath = join3(functionsDir, functionName, "index.ts");
|
|
11115
|
+
try {
|
|
11116
|
+
const bundled = await bundleEdgeFunction({ entryPointPath, functionsDir });
|
|
11117
|
+
const outputPath = join3(buildDir, `${functionName}.js`);
|
|
11118
|
+
fs2.writeFileSync(outputPath, bundled, "utf8");
|
|
11119
|
+
const size = Buffer.byteLength(bundled, "utf8");
|
|
11120
|
+
results.push({ name: functionName, outputPath, size });
|
|
11121
|
+
log.info(` ${functionName} \u2192 ${(size / 1024).toFixed(1)} KB`);
|
|
11122
|
+
} catch (error2) {
|
|
11123
|
+
const msg = error2 instanceof Error ? error2.message : String(error2);
|
|
11124
|
+
errors.push(`${functionName}: ${msg}`);
|
|
11125
|
+
log.error(` ${functionName} \u2014 FAILED: ${msg}`);
|
|
11126
|
+
}
|
|
11127
|
+
}
|
|
11128
|
+
if (errors.length > 0) {
|
|
11129
|
+
log.error(`
|
|
11130
|
+
${errors.length} function(s) failed to bundle`);
|
|
11131
|
+
return { success: false, functions: results, errors };
|
|
11132
|
+
}
|
|
11133
|
+
log.info(`
|
|
11134
|
+
All ${results.length} function(s) built to ${buildDir}`);
|
|
11135
|
+
return { success: true, functions: results, errors: [] };
|
|
11136
|
+
}
|
|
11137
|
+
var import_esbuild, ALWAYS_BUNDLE;
|
|
11138
|
+
var init_bundle_edge_function = __esm({
|
|
11139
|
+
"packages/tooling/src/utils/bundle-edge-function.ts"() {
|
|
11140
|
+
"use strict";
|
|
11141
|
+
init_utils();
|
|
11142
|
+
import_esbuild = __toESM(require_main(), 1);
|
|
11143
|
+
init_cli_output();
|
|
11144
|
+
init_pathResolver();
|
|
11145
|
+
ALWAYS_BUNDLE = /* @__PURE__ */ new Set([
|
|
11146
|
+
"valibot"
|
|
11147
|
+
]);
|
|
11148
|
+
}
|
|
11149
|
+
});
|
|
11150
|
+
|
|
11151
|
+
// packages/cli/src/bin/commands/build.ts
|
|
11152
|
+
init_utils();
|
|
11153
|
+
|
|
11154
|
+
// packages/tooling/src/index.ts
|
|
11155
|
+
init_utils();
|
|
11156
|
+
|
|
11157
|
+
// packages/tooling/src/cli/index.ts
|
|
11158
|
+
init_utils();
|
|
11159
|
+
|
|
11160
|
+
// packages/tooling/src/apps/build.ts
|
|
11161
|
+
init_utils();
|
|
11162
|
+
init_app_detection();
|
|
11163
|
+
init_app_selector();
|
|
11164
|
+
init_cli_input();
|
|
11165
|
+
init_cli_output();
|
|
11166
|
+
init_errors();
|
|
11167
|
+
init_pathResolver();
|
|
11168
|
+
init_typed_file_operations();
|
|
11169
|
+
import { execSync, spawnSync as spawnSync2 } from "node:child_process";
|
|
11170
|
+
|
|
11171
|
+
// packages/tooling/src/apps/deploy-utils.ts
|
|
11172
|
+
init_utils();
|
|
11173
|
+
import { spawnSync } from "node:child_process";
|
|
11174
|
+
init_pathResolver();
|
|
11175
|
+
function checkConfigPlaceholders(appDir) {
|
|
11176
|
+
const CONFIG_FILES = ["vercel.json", "firebase.json", ".firebaserc"];
|
|
11177
|
+
const bad = [];
|
|
11178
|
+
for (const file of CONFIG_FILES) {
|
|
11179
|
+
const filePath = joinPath(appDir, file);
|
|
11180
|
+
if (!pathExists(filePath)) continue;
|
|
11181
|
+
const content = readSync(filePath, { format: "text" });
|
|
11182
|
+
if (typeof content === "string" && (content.includes("{{") || content.includes("}}"))) {
|
|
11183
|
+
bad.push(file);
|
|
11184
|
+
}
|
|
11185
|
+
}
|
|
11186
|
+
if (bad.length > 0) {
|
|
11187
|
+
log.warn(`Unreplaced template placeholders found in: ${bad.join(", ")}`);
|
|
11188
|
+
log.warn(` Fix manually or re-run "dndev init" to regenerate.
|
|
11189
|
+
`);
|
|
11190
|
+
}
|
|
11191
|
+
return bad.length > 0;
|
|
11192
|
+
}
|
|
11193
|
+
|
|
11194
|
+
// packages/tooling/src/apps/build.ts
|
|
11195
|
+
function validateFirebaseJson(appDir) {
|
|
11196
|
+
const firebaseJsonPath = joinPath(appDir, "firebase.json");
|
|
11197
|
+
if (!pathExists(firebaseJsonPath)) {
|
|
11198
|
+
return {
|
|
11199
|
+
valid: false,
|
|
11200
|
+
hasHosting: false,
|
|
11201
|
+
hasFunctions: false
|
|
11202
|
+
};
|
|
11203
|
+
}
|
|
11204
|
+
try {
|
|
11205
|
+
const config = readFirebaseJson(firebaseJsonPath);
|
|
11206
|
+
if (!config.projectId) {
|
|
11207
|
+
return {
|
|
11208
|
+
valid: false,
|
|
11209
|
+
hasHosting: false,
|
|
11210
|
+
hasFunctions: false
|
|
11211
|
+
};
|
|
11212
|
+
}
|
|
11213
|
+
return {
|
|
11214
|
+
valid: true,
|
|
11215
|
+
hasHosting: !!config.hosting,
|
|
11216
|
+
hasFunctions: !!config.functions && Array.isArray(config.functions)
|
|
11217
|
+
};
|
|
11218
|
+
} catch {
|
|
11219
|
+
return {
|
|
11220
|
+
valid: false,
|
|
11221
|
+
hasHosting: false,
|
|
11222
|
+
hasFunctions: false
|
|
11223
|
+
};
|
|
11224
|
+
}
|
|
11225
|
+
}
|
|
11226
|
+
function parseBuildArgs(args) {
|
|
11227
|
+
const result = {};
|
|
11228
|
+
for (const arg of args) {
|
|
11229
|
+
if (arg === ":front" || arg === ":frontend" || arg === "front" || arg === "frontend") {
|
|
11230
|
+
result.buildType = "frontend";
|
|
11231
|
+
} else if (arg === ":func" || arg === ":functions" || arg === "func" || arg === "functions") {
|
|
11232
|
+
result.buildType = "functions";
|
|
11233
|
+
} else if (arg === ":both" || arg === "both") {
|
|
11234
|
+
result.buildType = "both";
|
|
11235
|
+
} else if (arg.includes(":")) {
|
|
11236
|
+
const parts = arg.split(":");
|
|
11237
|
+
result.appName = parts[0];
|
|
11238
|
+
const typePart = parts[1];
|
|
11239
|
+
if (typePart === "front" || typePart === "frontend") {
|
|
11240
|
+
result.buildType = "frontend";
|
|
11241
|
+
} else if (typePart === "func" || typePart === "functions") {
|
|
11242
|
+
result.buildType = "functions";
|
|
11243
|
+
} else if (typePart === "both") {
|
|
11244
|
+
result.buildType = "both";
|
|
11245
|
+
}
|
|
11246
|
+
} else if (!arg.startsWith(":") && arg !== "build") {
|
|
11247
|
+
result.appName = arg;
|
|
11248
|
+
}
|
|
11249
|
+
}
|
|
11250
|
+
return result;
|
|
11251
|
+
}
|
|
11252
|
+
async function main() {
|
|
11253
|
+
const args = process.argv.slice(2);
|
|
11254
|
+
const { appName: parsedAppName, buildType: parsedBuildType } = parseBuildArgs(args);
|
|
11255
|
+
const debugMode = process.env.DEBUG === "true" || process.env.DEBUG === "1" || args.includes("--debug") || args.includes("-d");
|
|
11256
|
+
if (debugMode) {
|
|
11257
|
+
log.debug(` Args: ${args.join(" ")}`);
|
|
11258
|
+
log.debug(
|
|
11259
|
+
` Parsed app: ${parsedAppName || "none"}, build type: ${parsedBuildType || "none"}
|
|
11260
|
+
`
|
|
11261
|
+
);
|
|
11262
|
+
}
|
|
11263
|
+
const projectRoot = getRepoRoot();
|
|
11264
|
+
if (!projectRoot) {
|
|
11265
|
+
throw new DoNotDevError(
|
|
8146
11266
|
"Could not determine repository root",
|
|
8147
11267
|
"path-resolution-error"
|
|
8148
11268
|
);
|
|
@@ -8154,7 +11274,7 @@ async function main() {
|
|
|
8154
11274
|
const appDir = app.path;
|
|
8155
11275
|
checkConfigPlaceholders(appDir);
|
|
8156
11276
|
const firebaseConfig = validateFirebaseJson(appDir);
|
|
8157
|
-
const
|
|
11277
|
+
const hasFunc = !!app.functions || firebaseConfig.hasFunctions;
|
|
8158
11278
|
const hasFrontend = app.framework !== "unknown";
|
|
8159
11279
|
let buildType = parsedBuildType;
|
|
8160
11280
|
if (!buildType) {
|
|
@@ -8166,14 +11286,14 @@ async function main() {
|
|
|
8166
11286
|
hint: "Build app bundle"
|
|
8167
11287
|
});
|
|
8168
11288
|
}
|
|
8169
|
-
if (
|
|
11289
|
+
if (hasFunc) {
|
|
8170
11290
|
choices.push({
|
|
8171
11291
|
title: "Functions only",
|
|
8172
11292
|
value: "functions",
|
|
8173
|
-
hint: "Build cloud functions"
|
|
11293
|
+
hint: app.functions === "supabase" ? "Bundle edge functions for Deno" : "Build cloud functions"
|
|
8174
11294
|
});
|
|
8175
11295
|
}
|
|
8176
|
-
if (hasFrontend &&
|
|
11296
|
+
if (hasFrontend && hasFunc) {
|
|
8177
11297
|
choices.push({
|
|
8178
11298
|
title: "Both frontend and functions",
|
|
8179
11299
|
value: "both",
|
|
@@ -8221,7 +11341,7 @@ async function main() {
|
|
|
8221
11341
|
}
|
|
8222
11342
|
}
|
|
8223
11343
|
if (buildType === "functions" || buildType === "both") {
|
|
8224
|
-
if (!
|
|
11344
|
+
if (!hasFunc) {
|
|
8225
11345
|
log.error(
|
|
8226
11346
|
"Functions build requested but app has no functions directory."
|
|
8227
11347
|
);
|
|
@@ -8230,31 +11350,42 @@ async function main() {
|
|
|
8230
11350
|
"validation-error"
|
|
8231
11351
|
);
|
|
8232
11352
|
}
|
|
8233
|
-
const
|
|
8234
|
-
if (!pathExists(
|
|
8235
|
-
log.error(`Functions directory not found: ${
|
|
11353
|
+
const funcPath = getFunctionsPath(app);
|
|
11354
|
+
if (!funcPath || !pathExists(funcPath)) {
|
|
11355
|
+
log.error(`Functions directory not found: ${funcPath}`);
|
|
8236
11356
|
throw new DoNotDevError(
|
|
8237
|
-
`Functions directory not found: ${
|
|
11357
|
+
`Functions directory not found: ${funcPath}`,
|
|
8238
11358
|
"file-not-found"
|
|
8239
11359
|
);
|
|
8240
11360
|
}
|
|
8241
|
-
log.info(`Building ${app.name} functions...
|
|
11361
|
+
log.info(`Building ${app.name} functions (${app.functions})...
|
|
8242
11362
|
`);
|
|
8243
|
-
|
|
8244
|
-
|
|
8245
|
-
|
|
8246
|
-
|
|
8247
|
-
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8252
|
-
|
|
8253
|
-
|
|
8254
|
-
|
|
8255
|
-
|
|
8256
|
-
"
|
|
8257
|
-
|
|
11363
|
+
if (app.functions === "supabase") {
|
|
11364
|
+
const { buildSupabaseEdgeFunctions: buildSupabaseEdgeFunctions2 } = await Promise.resolve().then(() => (init_bundle_edge_function(), bundle_edge_function_exports));
|
|
11365
|
+
const result = await buildSupabaseEdgeFunctions2(funcPath);
|
|
11366
|
+
if (!result.success) {
|
|
11367
|
+
throw new DoNotDevError(
|
|
11368
|
+
"Supabase edge functions build failed",
|
|
11369
|
+
"cli-execution-error"
|
|
11370
|
+
);
|
|
11371
|
+
}
|
|
11372
|
+
} else {
|
|
11373
|
+
const s = Y2();
|
|
11374
|
+
s.start("Building functions...");
|
|
11375
|
+
try {
|
|
11376
|
+
execSync("bun run build", {
|
|
11377
|
+
cwd: funcPath,
|
|
11378
|
+
stdio: "inherit"
|
|
11379
|
+
});
|
|
11380
|
+
s.stop("Functions built");
|
|
11381
|
+
} catch (error2) {
|
|
11382
|
+
s.stop("Functions build failed");
|
|
11383
|
+
throw DoNotDevError.from(
|
|
11384
|
+
error2,
|
|
11385
|
+
"Functions build failed",
|
|
11386
|
+
"cli-execution-error"
|
|
11387
|
+
);
|
|
11388
|
+
}
|
|
8258
11389
|
}
|
|
8259
11390
|
}
|
|
8260
11391
|
log.success(`Build complete for ${app.name}`);
|