Skip to content

Commit d8c0f94

Browse files
Jostled around with bundling and failed.
1 parent 9aa1ed9 commit d8c0f94

File tree

10 files changed

+313
-23
lines changed

10 files changed

+313
-23
lines changed

deno/esbuild/mod.js

+52-12
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ var mustBeInteger = (value) => typeof value === "number" && value === (value | 0
208208
var mustBeFunction = (value) => typeof value === "function" ? null : "a function";
209209
var mustBeArray = (value) => Array.isArray(value) ? null : "an array";
210210
var mustBeObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? null : "an object";
211+
var mustBeEntryPoints = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
211212
var mustBeWebAssemblyModule = (value) => value instanceof WebAssembly.Module ? null : "a WebAssembly.Module";
212-
var mustBeArrayOrRecord = (value) => typeof value === "object" && value !== null ? null : "an array or an object";
213213
var mustBeObjectOrNull = (value) => typeof value === "object" && !Array.isArray(value) ? null : "an object or null";
214214
var mustBeStringOrBoolean = (value) => typeof value === "string" || typeof value === "boolean" ? null : "a string or a boolean";
215215
var mustBeStringOrObject = (value) => typeof value === "string" || typeof value === "object" && value !== null && !Array.isArray(value) ? null : "a string or an object";
@@ -423,7 +423,7 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
423423
let inject = getFlag(options, keys, "inject", mustBeArray);
424424
let banner = getFlag(options, keys, "banner", mustBeObject);
425425
let footer = getFlag(options, keys, "footer", mustBeObject);
426-
let entryPoints = getFlag(options, keys, "entryPoints", mustBeArrayOrRecord);
426+
let entryPoints = getFlag(options, keys, "entryPoints", mustBeEntryPoints);
427427
let absWorkingDir = getFlag(options, keys, "absWorkingDir", mustBeString);
428428
let stdin = getFlag(options, keys, "stdin", mustBeObject);
429429
let write = getFlag(options, keys, "write", mustBeBoolean) ?? writeDefault;
@@ -534,8 +534,21 @@ function flagsForBuildOptions(callName, options, isTTY, logLevelDefault, writeDe
534534
}
535535
if (entryPoints) {
536536
if (Array.isArray(entryPoints)) {
537-
for (let entryPoint of entryPoints) {
538-
entries.push(["", validateStringValue(entryPoint, "entry point")]);
537+
for (let i = 0, n = entryPoints.length; i < n; i++) {
538+
let entryPoint = entryPoints[i];
539+
if (typeof entryPoint === "object" && entryPoint !== null) {
540+
let entryPointKeys = /* @__PURE__ */ Object.create(null);
541+
let input = getFlag(entryPoint, entryPointKeys, "in", mustBeString);
542+
let output = getFlag(entryPoint, entryPointKeys, "out", mustBeString);
543+
checkForInvalidFlags(entryPoint, entryPointKeys, "in entry point at index " + i);
544+
if (input === void 0)
545+
throw new Error('Missing property "in" for entry point at index ' + i);
546+
if (output === void 0)
547+
throw new Error('Missing property "out" for entry point at index ' + i);
548+
entries.push([output, input]);
549+
} else {
550+
entries.push(["", validateStringValue(entryPoint, "entry point at index " + i)]);
551+
}
539552
}
540553
} else {
541554
for (let key in entryPoints) {
@@ -698,8 +711,8 @@ function createChannel(streamIn) {
698711
if (isFirstPacket) {
699712
isFirstPacket = false;
700713
let binaryVersion = String.fromCharCode(...bytes);
701-
if (binaryVersion !== "0.17.0") {
702-
throw new Error(`Cannot start service: Host version "${"0.17.0"}" does not match binary version ${quote(binaryVersion)}`);
714+
if (binaryVersion !== "0.17.11") {
715+
throw new Error(`Cannot start service: Host version "${"0.17.11"}" does not match binary version ${quote(binaryVersion)}`);
703716
}
704717
return;
705718
}
@@ -943,7 +956,7 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
943956
if (!result.ok)
944957
return handleError(result.error, result.pluginName);
945958
try {
946-
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks);
959+
buildOrContextContinue(result.requestPlugins, result.runOnEndCallbacks, result.scheduleOnDisposeCallbacks);
947960
} catch (e) {
948961
handleError(e, "");
949962
}
@@ -953,11 +966,12 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
953966
return;
954967
}
955968
try {
956-
buildOrContextContinue(null, (result, done) => done([], []));
969+
buildOrContextContinue(null, (result, done) => done([], []), () => {
970+
});
957971
} catch (e) {
958972
handleError(e, "");
959973
}
960-
function buildOrContextContinue(requestPlugins, runOnEndCallbacks) {
974+
function buildOrContextContinue(requestPlugins, runOnEndCallbacks, scheduleOnDisposeCallbacks) {
961975
const writeDefault = streamIn.hasFS;
962976
const {
963977
entries,
@@ -1034,7 +1048,10 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
10341048
if (error)
10351049
return callback(new Error(error), null);
10361050
if (!isContext) {
1037-
return buildResponseToResult(response, callback);
1051+
return buildResponseToResult(response, (err, res) => {
1052+
scheduleOnDisposeCallbacks();
1053+
return callback(err, res);
1054+
});
10381055
}
10391056
if (response.errors.length > 0) {
10401057
return callback(failureErrorWithLog("Context failed", response.errors, response.warnings), null);
@@ -1122,15 +1139,28 @@ function buildOrContextImpl(callName, buildKey, sendRequest, sendResponse, refs,
11221139
resolve(response2);
11231140
});
11241141
}),
1142+
cancel: () => new Promise((resolve) => {
1143+
if (didDispose)
1144+
return resolve();
1145+
const request2 = {
1146+
command: "cancel",
1147+
key: buildKey
1148+
};
1149+
sendRequest(refs, request2, () => {
1150+
resolve();
1151+
});
1152+
}),
11251153
dispose: () => new Promise((resolve) => {
11261154
if (didDispose)
11271155
return resolve();
1156+
didDispose = true;
11281157
const request2 = {
11291158
command: "dispose",
11301159
key: buildKey
11311160
};
11321161
sendRequest(refs, request2, () => {
11331162
resolve();
1163+
scheduleOnDisposeCallbacks();
11341164
refs.unref();
11351165
});
11361166
})
@@ -1145,6 +1175,7 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
11451175
let onEndCallbacks = [];
11461176
let onResolveCallbacks = {};
11471177
let onLoadCallbacks = {};
1178+
let onDisposeCallbacks = [];
11481179
let nextCallbackID = 0;
11491180
let i = 0;
11501181
let requestPlugins = [];
@@ -1262,6 +1293,9 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
12621293
onLoadCallbacks[id] = { name, callback, note: registeredNote };
12631294
plugin.onLoad.push({ id, filter: filter.source, namespace: namespace || "" });
12641295
},
1296+
onDispose(callback) {
1297+
onDisposeCallbacks.push(callback);
1298+
},
12651299
esbuild: streamIn.esbuild
12661300
});
12671301
if (promise)
@@ -1455,11 +1489,17 @@ var handlePlugins = async (buildKey, sendRequest, sendResponse, refs, streamIn,
14551489
})();
14561490
};
14571491
}
1492+
let scheduleOnDisposeCallbacks = () => {
1493+
for (const cb of onDisposeCallbacks) {
1494+
setTimeout(() => cb(), 0);
1495+
}
1496+
};
14581497
isSetupDone = true;
14591498
return {
14601499
ok: true,
14611500
requestPlugins,
1462-
runOnEndCallbacks
1501+
runOnEndCallbacks,
1502+
scheduleOnDisposeCallbacks
14631503
};
14641504
};
14651505
function createObjectStash() {
@@ -1667,7 +1707,7 @@ function convertOutputFiles({ path, contents }) {
16671707

16681708
// lib/deno/mod.ts
16691709
import * as denoflate from "https://deno.land/x/denoflate@1.2.1/mod.ts";
1670-
var version = "0.17.0";
1710+
var version = "0.17.11";
16711711
var build = (options) => ensureServiceIsRunning().then((service) => service.build(options));
16721712
var context = (options) => ensureServiceIsRunning().then((service) => service.context(options));
16731713
var transform = (input, options) => ensureServiceIsRunning().then((service) => service.transform(input, options));

dist/dofn.mjs

+1-2
Large diffs are not rendered by default.

dist/vercel.mjs

+9-2
Large diffs are not rendered by default.
File renamed without changes.

examples/vercel/package.json

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"name": "mint-flower",
3+
"type": "module",
4+
"version": "0.3.0",
5+
"description": "⛈ Easy-to-configure load balancing, available as serverless functions.",
6+
"keywords": [
7+
"bun js",
8+
"cloud hop",
9+
"cloudflare workers",
10+
"cloudhop",
11+
"deno deploy",
12+
"denoland",
13+
"load balancer",
14+
"reverse proxy",
15+
"serverless functions"
16+
],
17+
"homepage": "https://github.com/ltgcgo/mint",
18+
"bugs": {
19+
"url": "https://github.com/ltgcgo/mint/issues"
20+
},
21+
"license": "LGPL-3.0-only",
22+
"author": "Lumière Élevé (https://github.com/PoneyClairDeLune)",
23+
"funding": [
24+
{
25+
"type": "individual",
26+
"url": "monero:82rPQDB7JVgYfF4TLTz4JJTM9ibYXw9G7BSQ2CE7ixqtYnYjNYPagJoUUhmmXaGfBvjRZ3TWdabP7FngbWXkdSfv23VEo1M"
27+
}
28+
],
29+
"engines": {
30+
"node": ">=18.0.0"
31+
},
32+
"os": [
33+
"linux",
34+
"darwin",
35+
"android",
36+
"windows"
37+
],
38+
"cpu": [
39+
"x64",
40+
"arm64"
41+
],
42+
"files": [
43+
"dist/*",
44+
"shx",
45+
"sh/nodeTest.sh",
46+
"sh/denoTest.sh",
47+
"sh/wranglerTest.sh",
48+
"sh/bunTest.sh"
49+
],
50+
"dependencies": {
51+
"ws": "^8.12.0"
52+
}
53+
}

sh/push.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# Build the project
33
shx build
44
# Some project-specific commands
5-
cp dist/node.js examples/vercel/api/handler.js
5+
cp dist/node.js examples/vercel/api/index.js
6+
cp package.json examples/vercel/
67
# Push the project
78
shx commit
89
exit

src/dofn/prefix.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/vercel/.node

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a Node 18+ project.

0 commit comments

Comments
 (0)