effect-start 0.25.0 → 0.26.0
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/package.json +18 -86
- package/dist/ChildProcess.js +0 -42
- package/dist/Commander.js +0 -410
- package/dist/ContentNegotiation.js +0 -465
- package/dist/Cookies.js +0 -371
- package/dist/Development.js +0 -94
- package/dist/Effectify.js +0 -27
- package/dist/Entity.js +0 -289
- package/dist/Fetch.js +0 -192
- package/dist/FilePathPattern.js +0 -97
- package/dist/FileRouter.js +0 -204
- package/dist/FileRouterCodegen.js +0 -298
- package/dist/FileSystem.js +0 -132
- package/dist/Http.js +0 -107
- package/dist/PathPattern.js +0 -451
- package/dist/PlatformError.js +0 -40
- package/dist/PlatformRuntime.js +0 -71
- package/dist/Route.js +0 -143
- package/dist/RouteBody.js +0 -92
- package/dist/RouteError.js +0 -76
- package/dist/RouteHook.js +0 -64
- package/dist/RouteHttp.js +0 -367
- package/dist/RouteHttpTracer.js +0 -90
- package/dist/RouteMount.js +0 -86
- package/dist/RouteSchema.js +0 -271
- package/dist/RouteSse.js +0 -94
- package/dist/RouteTree.js +0 -119
- package/dist/RouteTrie.js +0 -179
- package/dist/SchemaExtra.js +0 -99
- package/dist/Socket.js +0 -40
- package/dist/SqlIntrospect.js +0 -515
- package/dist/Start.js +0 -79
- package/dist/StartApp.js +0 -3
- package/dist/StreamExtra.js +0 -135
- package/dist/System.js +0 -38
- package/dist/TuplePathPattern.js +0 -74
- package/dist/Unique.js +0 -226
- package/dist/Values.js +0 -52
- package/dist/bun/BunBundle.js +0 -186
- package/dist/bun/BunChildProcessSpawner.js +0 -142
- package/dist/bun/BunImportTrackerPlugin.js +0 -91
- package/dist/bun/BunRoute.js +0 -157
- package/dist/bun/BunRuntime.js +0 -41
- package/dist/bun/BunServer.js +0 -285
- package/dist/bun/BunVirtualFilesPlugin.js +0 -54
- package/dist/bun/_BunEnhancedResolve.js +0 -127
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.js +0 -92
- package/dist/bundler/BundleFiles.js +0 -154
- package/dist/bundler/BundleRoute.js +0 -62
- package/dist/client/Overlay.js +0 -33
- package/dist/client/ScrollState.js +0 -106
- package/dist/client/index.js +0 -97
- package/dist/console/Console.js +0 -42
- package/dist/console/ConsoleErrors.js +0 -211
- package/dist/console/ConsoleLogger.js +0 -56
- package/dist/console/ConsoleMetrics.js +0 -72
- package/dist/console/ConsoleProcess.js +0 -59
- package/dist/console/ConsoleStore.js +0 -72
- package/dist/console/ConsoleTracer.js +0 -107
- package/dist/console/Simulation.js +0 -784
- package/dist/console/index.js +0 -3
- package/dist/console/routes/tree.js +0 -30
- package/dist/datastar/actions/fetch.js +0 -536
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.js +0 -19
- package/dist/datastar/actions/toggleAll.js +0 -19
- package/dist/datastar/attributes/attr.js +0 -49
- package/dist/datastar/attributes/bind.js +0 -194
- package/dist/datastar/attributes/class.js +0 -54
- package/dist/datastar/attributes/computed.js +0 -25
- package/dist/datastar/attributes/effect.js +0 -10
- package/dist/datastar/attributes/indicator.js +0 -33
- package/dist/datastar/attributes/init.js +0 -27
- package/dist/datastar/attributes/jsonSignals.js +0 -33
- package/dist/datastar/attributes/on.js +0 -81
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.js +0 -31
- package/dist/datastar/attributes/onSignalPatch.js +0 -51
- package/dist/datastar/attributes/ref.js +0 -11
- package/dist/datastar/attributes/show.js +0 -32
- package/dist/datastar/attributes/signals.js +0 -18
- package/dist/datastar/attributes/style.js +0 -57
- package/dist/datastar/attributes/text.js +0 -29
- package/dist/datastar/engine.js +0 -1145
- package/dist/datastar/index.js +0 -25
- package/dist/datastar/utils.js +0 -250
- package/dist/datastar/watchers/patchElements.js +0 -486
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.js +0 -328
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.js +0 -28
- package/dist/hyper/HyperHtml.js +0 -165
- package/dist/hyper/HyperNode.js +0 -13
- package/dist/hyper/HyperRoute.js +0 -45
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.js +0 -14
- package/dist/index.js +0 -8
- package/dist/node/NodeFileSystem.js +0 -675
- package/dist/node/NodeUtils.js +0 -23
- package/dist/sql/Sql.js +0 -8
- package/dist/sql/bun/index.js +0 -142
- package/dist/sql/index.js +0 -1
- package/dist/sql/libsql/index.js +0 -156
- package/dist/sql/mssql/docker.js +0 -110
- package/dist/sql/mssql/index.js +0 -194
- package/dist/testing/TestLogger.js +0 -42
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.js +0 -61
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -63
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.js +0 -94
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.js +0 -294
- package/dist/x/tailwind/compile.js +0 -210
- package/dist/x/tailwind/plugin.js +0 -17
package/dist/bun/BunServer.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import * as Socket from "../Socket.js"
|
|
2
|
-
import * as Bun from "bun"
|
|
3
|
-
import * as Config from "effect/Config"
|
|
4
|
-
import * as Context from "effect/Context"
|
|
5
|
-
import * as Deferred from "effect/Deferred"
|
|
6
|
-
import * as Effect from "effect/Effect"
|
|
7
|
-
import * as Exit from "effect/Exit"
|
|
8
|
-
import * as Layer from "effect/Layer"
|
|
9
|
-
import * as Option from "effect/Option"
|
|
10
|
-
import * as Runtime from "effect/Runtime"
|
|
11
|
-
import * as NOs from "node:os"
|
|
12
|
-
import * as NPath from "node:path"
|
|
13
|
-
import * as PathPattern from "../PathPattern.js"
|
|
14
|
-
import * as PlataformRuntime from "../PlatformRuntime.js"
|
|
15
|
-
import * as Route from "../Route.js"
|
|
16
|
-
import * as RouteHttp from "../RouteHttp.js"
|
|
17
|
-
import * as StartApp from "../StartApp.js"
|
|
18
|
-
import * as RouteTree from "../RouteTree.js"
|
|
19
|
-
import * as BunRoute from "./BunRoute.js"
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Basically `Omit<Bun.Serve.Options, "fetch" | "error" | "websocket">`
|
|
23
|
-
* TypeScript 5.9 cannot verify discriminated union types used in
|
|
24
|
-
* {@link Bun.serve} so we need to define them explicitly.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
export const BunServer = Context.GenericTag("effect-start/BunServer")
|
|
28
|
-
|
|
29
|
-
export const make = (
|
|
30
|
-
options,
|
|
31
|
-
tree,
|
|
32
|
-
) =>
|
|
33
|
-
Effect.gen(function* () {
|
|
34
|
-
const port = yield* Config.number("PORT").pipe(
|
|
35
|
-
Effect.catchTag("ConfigError", () => {
|
|
36
|
-
return PlataformRuntime.isAgentHarness()
|
|
37
|
-
? Effect.succeed(0) // random port
|
|
38
|
-
: Effect.succeed(3000)
|
|
39
|
-
}),
|
|
40
|
-
)
|
|
41
|
-
const hostFlag = process.argv.includes("--host")
|
|
42
|
-
const hostname = yield* Config.string("HOST").pipe(
|
|
43
|
-
Effect.catchTag("ConfigError", () => Effect.succeed(hostFlag ? "0.0.0.0" : undefined)),
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
const handlerStack = [
|
|
47
|
-
function (_request, _server) {
|
|
48
|
-
return new Response("not found", { status: 404 })
|
|
49
|
-
},
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
const service = BunServer.of({
|
|
53
|
-
// During the construction we need to create a service imlpementation
|
|
54
|
-
// first so we can provide it in the runtime that will be used in web
|
|
55
|
-
// handlers. After we create the runtime, we set it below so it's always
|
|
56
|
-
// available at runtime.
|
|
57
|
-
// An alternative approach would be to use Bun.Server.reload but I prefer
|
|
58
|
-
// to avoid it since it's badly documented and has bunch of bugs.
|
|
59
|
-
server: undefined,
|
|
60
|
-
pushHandler(fetch) {
|
|
61
|
-
handlerStack.push(fetch)
|
|
62
|
-
reload()
|
|
63
|
-
},
|
|
64
|
-
popHandler() {
|
|
65
|
-
handlerStack.pop()
|
|
66
|
-
reload()
|
|
67
|
-
},
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const runtime = yield* Effect.runtime().pipe(
|
|
71
|
-
Effect.andThen(Runtime.provideService(BunServer, service)),
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
let currentRoutes = tree ? yield* walkBunRoutes(runtime, tree) : {}
|
|
75
|
-
|
|
76
|
-
const websocket = {
|
|
77
|
-
open(ws) {
|
|
78
|
-
Deferred.unsafeDone(ws.data.deferred, Exit.succeed(ws))
|
|
79
|
-
},
|
|
80
|
-
message(ws, message) {
|
|
81
|
-
ws.data.run(message)
|
|
82
|
-
},
|
|
83
|
-
close(ws, code, closeReason) {
|
|
84
|
-
Deferred.unsafeDone(
|
|
85
|
-
ws.data.closeDeferred,
|
|
86
|
-
Socket.defaultCloseCodeIsError(code)
|
|
87
|
-
? Exit.fail(
|
|
88
|
-
new Socket.SocketCloseError({
|
|
89
|
-
reason: "Close",
|
|
90
|
-
code,
|
|
91
|
-
closeReason,
|
|
92
|
-
}),
|
|
93
|
-
)
|
|
94
|
-
: Exit.void,
|
|
95
|
-
)
|
|
96
|
-
},
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const server = Bun.serve({
|
|
100
|
-
port,
|
|
101
|
-
hostname,
|
|
102
|
-
...options,
|
|
103
|
-
routes: currentRoutes,
|
|
104
|
-
fetch: handlerStack[0],
|
|
105
|
-
websocket,
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
// @ts-expect-error
|
|
109
|
-
service.server = server
|
|
110
|
-
|
|
111
|
-
yield* Effect.addFinalizer(() =>
|
|
112
|
-
Effect.sync(() => {
|
|
113
|
-
server.stop()
|
|
114
|
-
}),
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
const reload = () => {
|
|
118
|
-
server.reload({
|
|
119
|
-
fetch: handlerStack[handlerStack.length - 1],
|
|
120
|
-
routes: currentRoutes,
|
|
121
|
-
websocket,
|
|
122
|
-
})
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const bunServer = BunServer.of({
|
|
126
|
-
server,
|
|
127
|
-
pushHandler(fetch) {
|
|
128
|
-
handlerStack.push(fetch)
|
|
129
|
-
reload()
|
|
130
|
-
},
|
|
131
|
-
popHandler() {
|
|
132
|
-
handlerStack.pop()
|
|
133
|
-
reload()
|
|
134
|
-
},
|
|
135
|
-
})
|
|
136
|
-
|
|
137
|
-
return bunServer
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Provides HttpServer using BunServer under the hood.
|
|
142
|
-
*/
|
|
143
|
-
export const layer = (options) =>
|
|
144
|
-
Layer.scoped(BunServer, make(options ?? {}))
|
|
145
|
-
|
|
146
|
-
export const layerRoutes = (
|
|
147
|
-
options,
|
|
148
|
-
) =>
|
|
149
|
-
Layer.scoped(
|
|
150
|
-
BunServer,
|
|
151
|
-
Effect.gen(function* () {
|
|
152
|
-
const routes = yield* Route.Routes
|
|
153
|
-
return yield* make(options ?? {}, routes)
|
|
154
|
-
}),
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Resolves the Bun server in one place for Start.serve so routes are available:
|
|
159
|
-
* 1) Reuse a user-provided BunServer when one already exists in context.
|
|
160
|
-
* 2) Otherwise create the server from Route.Routes when routes are available.
|
|
161
|
-
* 3) Otherwise create a fallback server with the default 404 handler.
|
|
162
|
-
*/
|
|
163
|
-
export const layerStart = (
|
|
164
|
-
options,
|
|
165
|
-
) =>
|
|
166
|
-
Layer.scoped(
|
|
167
|
-
BunServer,
|
|
168
|
-
Effect.gen(function* () {
|
|
169
|
-
const app = yield* StartApp.StartApp
|
|
170
|
-
const existing = yield* Effect.serviceOption(BunServer)
|
|
171
|
-
if (Option.isSome(existing)) {
|
|
172
|
-
yield* Deferred.succeed(app.server, existing.value)
|
|
173
|
-
return existing.value
|
|
174
|
-
}
|
|
175
|
-
const routes = yield* Effect.serviceOption(Route.Routes)
|
|
176
|
-
if (Option.isSome(routes)) {
|
|
177
|
-
const server = yield* make(options ?? {}, routes.value)
|
|
178
|
-
yield* Deferred.succeed(app.server, server)
|
|
179
|
-
return server
|
|
180
|
-
}
|
|
181
|
-
const server = yield* make(options ?? {})
|
|
182
|
-
yield* Deferred.succeed(app.server, server)
|
|
183
|
-
return server
|
|
184
|
-
}),
|
|
185
|
-
)
|
|
186
|
-
|
|
187
|
-
export const withLogAddress = (layer) =>
|
|
188
|
-
Layer.effectDiscard(
|
|
189
|
-
Effect.gen(function* () {
|
|
190
|
-
const { server } = yield* BunServer
|
|
191
|
-
const { hostname, port } = server
|
|
192
|
-
const addr = hostname === "0.0.0.0" ? getLocalIp() : "localhost"
|
|
193
|
-
|
|
194
|
-
yield* Effect.log(`Listening on http://${addr}:${port}`)
|
|
195
|
-
}),
|
|
196
|
-
).pipe(Layer.provideMerge(layer))
|
|
197
|
-
|
|
198
|
-
function walkBunRoutes(runtime, tree) {
|
|
199
|
-
return Effect.gen(function* () {
|
|
200
|
-
const bunRoutes = {}
|
|
201
|
-
const pathGroups = new Map()
|
|
202
|
-
const toWebHandler = RouteHttp.toWebHandlerRuntime(runtime)
|
|
203
|
-
|
|
204
|
-
for (const route of RouteTree.walk(tree)) {
|
|
205
|
-
const bunDescriptors = BunRoute.descriptors(route)
|
|
206
|
-
if (bunDescriptors) {
|
|
207
|
-
const htmlBundle = yield* Effect.promise(bunDescriptors.bunLoad)
|
|
208
|
-
if (htmlBundle.files) {
|
|
209
|
-
registerPrebuiltBundle(bunDescriptors.bunPrefix, htmlBundle, bunRoutes)
|
|
210
|
-
} else {
|
|
211
|
-
bunRoutes[`${bunDescriptors.bunPrefix}/*`] = htmlBundle
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const path = Route.descriptor(route).path
|
|
216
|
-
const group = pathGroups.get(path) ?? []
|
|
217
|
-
group.push(route)
|
|
218
|
-
pathGroups.set(path, group)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
for (const [path, routes] of pathGroups) {
|
|
222
|
-
const handler = toWebHandler(routes)
|
|
223
|
-
for (const bunPath of PathPattern.toBun(path)) {
|
|
224
|
-
bunRoutes[bunPath] = handler
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return bunRoutes
|
|
229
|
-
})
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function registerPrebuiltBundle(prefix, bundle, bunRoutes) {
|
|
233
|
-
const mainDir = NPath.dirname(Bun.main)
|
|
234
|
-
const indexPath = NPath.resolve(mainDir, bundle.index)
|
|
235
|
-
|
|
236
|
-
const htmlPromise = rewriteRelativeAssetPaths(Bun.file(indexPath).text())
|
|
237
|
-
|
|
238
|
-
bunRoutes[`${prefix}/*`] = async () =>
|
|
239
|
-
new Response(await htmlPromise, { headers: { "content-type": "text/html;charset=utf-8" } })
|
|
240
|
-
|
|
241
|
-
for (const file of bundle.files ?? []) {
|
|
242
|
-
if (file.loader === "html") continue
|
|
243
|
-
const absPath = NPath.resolve(mainDir, file.path)
|
|
244
|
-
const basename = NPath.basename(file.path)
|
|
245
|
-
bunRoutes[`/${basename}`] = () =>
|
|
246
|
-
new Response(Bun.file(absPath), { headers: file.headers ?? {} })
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function rewriteRelativeAssetPaths(html) {
|
|
251
|
-
const rewriter = new HTMLRewriter()
|
|
252
|
-
.on("link[href]", {
|
|
253
|
-
element(el) {
|
|
254
|
-
const href = el.getAttribute("href")
|
|
255
|
-
if (href && isRelativePath(href)) {
|
|
256
|
-
el.setAttribute("href", "/" + assetBasename(href))
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
})
|
|
260
|
-
.on("script[src]", {
|
|
261
|
-
element(el) {
|
|
262
|
-
const src = el.getAttribute("src")
|
|
263
|
-
if (src && isRelativePath(src)) {
|
|
264
|
-
el.setAttribute("src", "/" + assetBasename(src))
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
return Promise.resolve(html).then((h) => rewriter.transform(new Response(h)).text())
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function isRelativePath(path) {
|
|
273
|
-
return path.startsWith("./") || path.startsWith("../")
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
function assetBasename(path) {
|
|
277
|
-
const i = path.lastIndexOf("/")
|
|
278
|
-
return i === -1 ? path : path.slice(i + 1)
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
function getLocalIp() {
|
|
282
|
-
return Object.values(NOs.networkInterfaces())
|
|
283
|
-
.flatMap((addresses) => addresses ?? [])
|
|
284
|
-
.find((addr) => addr.family === "IPv4" && !addr.internal)?.address
|
|
285
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function loaderFromPath(path) {
|
|
4
|
-
return path.slice(path.lastIndexOf(".") + 1)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function make(files) {
|
|
8
|
-
return {
|
|
9
|
-
name: "virtual-fs",
|
|
10
|
-
setup(build) {
|
|
11
|
-
build.onResolve(
|
|
12
|
-
{
|
|
13
|
-
// change the filter so it only works for file namespace
|
|
14
|
-
filter: /.*/,
|
|
15
|
-
},
|
|
16
|
-
(args) => {
|
|
17
|
-
const resolved = resolvePath(args.path, args.resolveDir)
|
|
18
|
-
const resolvedFile = files[resolved]
|
|
19
|
-
|
|
20
|
-
if (resolvedFile) {
|
|
21
|
-
return {
|
|
22
|
-
path: resolved,
|
|
23
|
-
namespace: "virtual-fs",
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return
|
|
27
|
-
},
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
build.onLoad(
|
|
31
|
-
{
|
|
32
|
-
filter: /.*/,
|
|
33
|
-
namespace: "virtual-fs",
|
|
34
|
-
},
|
|
35
|
-
(args) => {
|
|
36
|
-
const contents = files[args.path]
|
|
37
|
-
|
|
38
|
-
if (!contents) {
|
|
39
|
-
return undefined
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
contents,
|
|
44
|
-
loader: loaderFromPath(args.path),
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
)
|
|
48
|
-
},
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function resolvePath(path, base = process.cwd()) {
|
|
53
|
-
return Bun.resolveSync(path, base)
|
|
54
|
-
}
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Bun adapter for enhanced-resolve
|
|
3
|
-
*
|
|
4
|
-
* This module provides a drop-in replacement for `enhanced-resolve` that uses
|
|
5
|
-
* Bun's built-in resolver. It implements the subset of the enhanced-resolve API
|
|
6
|
-
* used for Tailwind CSS.
|
|
7
|
-
*/
|
|
8
|
-
import fs from "node:fs"
|
|
9
|
-
import path from "node:path"
|
|
10
|
-
|
|
11
|
-
export class CachedInputFileSystem {
|
|
12
|
-
constructor(_fileSystem, _duration) {}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export const ResolverFactory = {
|
|
16
|
-
createResolver(options) {
|
|
17
|
-
const extensions = options.extensions ?? []
|
|
18
|
-
const mainFields = (options.mainFields ?? []).flatMap((f) => (Array.isArray(f) ? f : [f]))
|
|
19
|
-
const conditionNames = options.conditionNames ?? []
|
|
20
|
-
|
|
21
|
-
return {
|
|
22
|
-
resolve(
|
|
23
|
-
_context,
|
|
24
|
-
basePath,
|
|
25
|
-
id,
|
|
26
|
-
_resolveContext,
|
|
27
|
-
callback,
|
|
28
|
-
) {
|
|
29
|
-
try {
|
|
30
|
-
const result = resolveSync(id, basePath, {
|
|
31
|
-
extensions,
|
|
32
|
-
mainFields,
|
|
33
|
-
conditionNames,
|
|
34
|
-
})
|
|
35
|
-
callback(null, result)
|
|
36
|
-
} catch (err) {
|
|
37
|
-
callback(err instanceof Error ? err : new Error(String(err)))
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function resolveSync(
|
|
45
|
-
id,
|
|
46
|
-
base,
|
|
47
|
-
options,
|
|
48
|
-
) {
|
|
49
|
-
if (id.startsWith(".") || id.startsWith("/")) {
|
|
50
|
-
for (const ext of ["", ...options.extensions]) {
|
|
51
|
-
const fullPath = path.resolve(base, id + ext)
|
|
52
|
-
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile()) {
|
|
53
|
-
return fullPath
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return undefined
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const packagePath = resolvePackagePath(id, base)
|
|
60
|
-
if (!packagePath) return undefined
|
|
61
|
-
|
|
62
|
-
const packageJsonPath = path.join(packagePath, "package.json")
|
|
63
|
-
if (!fs.existsSync(packageJsonPath)) return undefined
|
|
64
|
-
|
|
65
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"))
|
|
66
|
-
|
|
67
|
-
for (const field of options.mainFields) {
|
|
68
|
-
if (typeof packageJson[field] === "string") {
|
|
69
|
-
const resolved = path.resolve(packagePath, packageJson[field])
|
|
70
|
-
if (fs.existsSync(resolved)) return resolved
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (packageJson.exports) {
|
|
75
|
-
const resolved = resolveExports(packageJson.exports, packagePath, options.conditionNames)
|
|
76
|
-
if (resolved && fs.existsSync(resolved)) return resolved
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
return Bun.resolveSync(id, base)
|
|
81
|
-
} catch {
|
|
82
|
-
return undefined
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function resolvePackagePath(id, base) {
|
|
87
|
-
const parts = id.split("/")
|
|
88
|
-
const packageName = id.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]
|
|
89
|
-
|
|
90
|
-
let dir = base
|
|
91
|
-
while (dir !== path.dirname(dir)) {
|
|
92
|
-
const candidate = path.join(dir, "node_modules", packageName)
|
|
93
|
-
if (fs.existsSync(candidate)) return candidate
|
|
94
|
-
dir = path.dirname(dir)
|
|
95
|
-
}
|
|
96
|
-
return undefined
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function resolveExports(
|
|
100
|
-
exports,
|
|
101
|
-
packagePath,
|
|
102
|
-
conditionNames,
|
|
103
|
-
) {
|
|
104
|
-
if (typeof exports === "string") {
|
|
105
|
-
return path.resolve(packagePath, exports)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (exports && typeof exports === "object" && !Array.isArray(exports)) {
|
|
109
|
-
const exportsObj = exports
|
|
110
|
-
|
|
111
|
-
if ("." in exportsObj) {
|
|
112
|
-
return resolveExports(exportsObj["."], packagePath, conditionNames)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
for (const condition of conditionNames) {
|
|
116
|
-
if (condition in exportsObj) {
|
|
117
|
-
return resolveExports(exportsObj[condition], packagePath, conditionNames)
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if ("default" in exportsObj) {
|
|
122
|
-
return resolveExports(exportsObj["default"], packagePath, conditionNames)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return undefined
|
|
127
|
-
}
|
package/dist/bun/index.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
export * as BunChildProcessSpawner from "./BunChildProcessSpawner.js"
|
|
2
|
-
export * as BunBundle from "./BunBundle.js"
|
|
3
|
-
export * as BunImportTrackerPlugin from "./BunImportTrackerPlugin.js"
|
|
4
|
-
export * as BunRoute from "./BunRoute.js"
|
|
5
|
-
export * as BunServer from "./BunServer.js"
|
package/dist/bundler/Bundle.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Context, Data, Effect, pipe } from "effect"
|
|
2
|
-
import * as Schema from "effect/Schema"
|
|
3
|
-
|
|
4
|
-
export const BundleEntrypointMetaKey = Symbol.for(
|
|
5
|
-
"effect-start/BundleEntrypointMetaKey",
|
|
6
|
-
)
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Generic shape describing a bundle across multiple bundlers
|
|
10
|
-
* (like bun, esbuild & vite)
|
|
11
|
-
*/
|
|
12
|
-
export const BundleManifestSchema = Schema.Struct({
|
|
13
|
-
entrypoints: Schema.Record({
|
|
14
|
-
key: Schema.String,
|
|
15
|
-
value: Schema.String,
|
|
16
|
-
}),
|
|
17
|
-
artifacts: Schema.Array(
|
|
18
|
-
Schema.Struct({
|
|
19
|
-
path: Schema.String,
|
|
20
|
-
type: Schema.String,
|
|
21
|
-
size: Schema.Number,
|
|
22
|
-
hash: pipe(Schema.String, Schema.optional),
|
|
23
|
-
imports: pipe(
|
|
24
|
-
Schema.Array(
|
|
25
|
-
Schema.Struct({
|
|
26
|
-
path: Schema.String,
|
|
27
|
-
kind: Schema.Literal(
|
|
28
|
-
"import-statement",
|
|
29
|
-
"require-call",
|
|
30
|
-
"require-resolve",
|
|
31
|
-
"dynamic-import",
|
|
32
|
-
"import-rule",
|
|
33
|
-
"url-token",
|
|
34
|
-
"internal",
|
|
35
|
-
"entry-point-run",
|
|
36
|
-
"entry-point-build",
|
|
37
|
-
),
|
|
38
|
-
}),
|
|
39
|
-
),
|
|
40
|
-
Schema.optional,
|
|
41
|
-
),
|
|
42
|
-
}),
|
|
43
|
-
),
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
const BundleEventChange = Schema.TaggedStruct("Change", {
|
|
47
|
-
path: Schema.String,
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
const BundleEventBuildError = Schema.TaggedStruct("BuildError", {
|
|
51
|
-
error: Schema.String,
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
export const BundleEvent = Schema.Union(BundleEventChange, BundleEventBuildError)
|
|
55
|
-
|
|
56
|
-
const IdPrefix = "effect-start/tags/"
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Passed to bundle effects and within bundle runtime.
|
|
60
|
-
* Used to expose artifacts via HTTP server and properly resolve
|
|
61
|
-
* imports within the bundle.
|
|
62
|
-
*/
|
|
63
|
-
|
|
64
|
-
export class BundleError extends Data.TaggedError("BundleError") {}
|
|
65
|
-
|
|
66
|
-
export const emptyBundleContext = {
|
|
67
|
-
entrypoints: {},
|
|
68
|
-
artifacts: [],
|
|
69
|
-
resolve: () => null,
|
|
70
|
-
getArtifact: () => null,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export const handleBundleErrorSilently = (
|
|
74
|
-
effect,
|
|
75
|
-
) =>
|
|
76
|
-
pipe(
|
|
77
|
-
effect,
|
|
78
|
-
Effect.catchTag("BundleError", (error) =>
|
|
79
|
-
Effect.gen(function* () {
|
|
80
|
-
yield* Effect.logError("Bundle build failed", error)
|
|
81
|
-
return emptyBundleContext
|
|
82
|
-
}),
|
|
83
|
-
),
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
export const Tag =
|
|
87
|
-
(name) =>
|
|
88
|
-
() =>
|
|
89
|
-
Context.Tag(`${IdPrefix}${name}`)()
|
|
90
|
-
|
|
91
|
-
export class ClientBundle extends Tag("ClientBundle")() {}
|
|
92
|
-
export class ServerBundle extends Tag("ServerBundle")() {}
|