@barefootjs/hono 0.30.5 → 0.31.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/dist/adapter/hono-adapter.d.ts +43 -6
- package/dist/adapter/hono-adapter.d.ts.map +1 -1
- package/dist/adapter/index.js +44 -8
- package/dist/app.d.ts +11 -55
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +1 -13
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -8
- package/dist/preload.d.ts +10 -1
- package/dist/preload.d.ts.map +1 -1
- package/dist/render.d.ts +1 -1
- package/dist/scripts.d.ts +76 -0
- package/dist/scripts.d.ts.map +1 -1
- package/dist/scripts.js +81 -17
- package/dist/vite.d.ts +37 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2749 -0
- package/package.json +19 -11
- package/src/__tests__/scaffold.test.ts +9 -2
- package/src/__tests__/script-assets.test.ts +228 -0
- package/src/__tests__/vite.test.ts +144 -0
- package/src/adapter/hono-adapter.ts +134 -15
- package/src/app.ts +12 -73
- package/src/index.ts +1 -1
- package/src/preload.tsx +15 -2
- package/src/render.ts +1 -1
- package/src/scripts.tsx +136 -0
- package/src/vite.ts +210 -0
- package/dist/build.d.ts +0 -65
- package/dist/build.d.ts.map +0 -1
- package/dist/build.js +0 -188137
- package/dist/dev.d.ts +0 -36
- package/dist/dev.d.ts.map +0 -1
- package/dist/dev.js +0 -508
- package/src/__tests__/build.test.ts +0 -299
- package/src/__tests__/dev.test.tsx +0 -123
- package/src/__tests__/import-map.test.ts +0 -98
- package/src/build.ts +0 -230
- package/src/dev.tsx +0 -154
package/dist/dev.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BarefootJS Dev Reloader (Hono, Node-side)
|
|
3
|
-
*
|
|
4
|
-
* `createDevReloader` turns `bf build --watch`'s sentinel file
|
|
5
|
-
* (`<distDir>/.dev/build-id`) into an SSE stream:
|
|
6
|
-
*
|
|
7
|
-
* [bf build --watch] → writes `<distDir>/.dev/build-id` after each successful build
|
|
8
|
-
* [createDevReloader] → watches that file, streams SSE `event: reload`
|
|
9
|
-
*
|
|
10
|
-
* Mount it on a Hono route in the generated app; the matching browser-
|
|
11
|
-
* side subscriber (`<DevReload />`) lives in the project itself (see
|
|
12
|
-
* the hono-node scaffold's `dev-reload.tsx`) so its endpoint URL and
|
|
13
|
-
* reconnect behavior are an in-tree edit.
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* // factory.ts
|
|
17
|
-
* import { createDevReloader } from '@barefootjs/hono/dev'
|
|
18
|
-
* app.get('/_bf/reload', createDevReloader({ distDir: './dist' }))
|
|
19
|
-
* ```
|
|
20
|
-
*
|
|
21
|
-
* Disabled (404) when `NODE_ENV === 'production'` unless `enabled: true`
|
|
22
|
-
* is passed explicitly.
|
|
23
|
-
*/
|
|
24
|
-
import type { Context } from 'hono';
|
|
25
|
-
export interface CreateDevReloaderOptions {
|
|
26
|
-
/** Directory that `bf build` writes output into (contains `.dev/build-id`). */
|
|
27
|
-
distDir: string;
|
|
28
|
-
/** Override the dev gate. Defaults to `process.env.NODE_ENV !== 'production'`. */
|
|
29
|
-
enabled?: boolean;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Hono route handler that streams Server-Sent Events and emits `reload` every
|
|
33
|
-
* time `<distDir>/.dev/build-id` is written. Disabled (404) in production.
|
|
34
|
-
*/
|
|
35
|
-
export declare function createDevReloader(options: CreateDevReloaderOptions): (c: Context) => Response | Promise<Response>;
|
|
36
|
-
//# sourceMappingURL=dev.d.ts.map
|
package/dist/dev.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAInC,MAAM,WAAW,wBAAwB;IACvC,+EAA+E;IAC/E,OAAO,EAAE,MAAM,CAAA;IACf,kFAAkF;IAClF,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAmBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,GAChC,CAAC,CAAC,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CA8F9C"}
|
package/dist/dev.js
DELETED
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
function __accessProp(key) {
|
|
8
|
-
return this[key];
|
|
9
|
-
}
|
|
10
|
-
var __toESMCache_node;
|
|
11
|
-
var __toESMCache_esm;
|
|
12
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
for (let key of __getOwnPropNames(mod))
|
|
23
|
-
if (!__hasOwnProp.call(to, key))
|
|
24
|
-
__defProp(to, key, {
|
|
25
|
-
get: __accessProp.bind(mod, key),
|
|
26
|
-
enumerable: true
|
|
27
|
-
});
|
|
28
|
-
if (canCache)
|
|
29
|
-
cache.set(mod, to);
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __toCommonJS = (from) => {
|
|
33
|
-
var entry = (__moduleCache ??= new WeakMap).get(from), desc;
|
|
34
|
-
if (entry)
|
|
35
|
-
return entry;
|
|
36
|
-
entry = __defProp({}, "__esModule", { value: true });
|
|
37
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
38
|
-
for (var key of __getOwnPropNames(from))
|
|
39
|
-
if (!__hasOwnProp.call(entry, key))
|
|
40
|
-
__defProp(entry, key, {
|
|
41
|
-
get: __accessProp.bind(from, key),
|
|
42
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
__moduleCache.set(from, entry);
|
|
46
|
-
return entry;
|
|
47
|
-
};
|
|
48
|
-
var __moduleCache;
|
|
49
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
50
|
-
var __returnValue = (v) => v;
|
|
51
|
-
function __exportSetter(name, newValue) {
|
|
52
|
-
this[name] = __returnValue.bind(null, newValue);
|
|
53
|
-
}
|
|
54
|
-
var __export = (target, all) => {
|
|
55
|
-
for (var name in all)
|
|
56
|
-
__defProp(target, name, {
|
|
57
|
-
get: all[name],
|
|
58
|
-
enumerable: true,
|
|
59
|
-
configurable: true,
|
|
60
|
-
set: __exportSetter.bind(all, name)
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
64
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
65
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
66
|
-
}) : x)(function(x) {
|
|
67
|
-
if (typeof require !== "undefined")
|
|
68
|
-
return require.apply(this, arguments);
|
|
69
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// node:path
|
|
73
|
-
var exports_path = {};
|
|
74
|
-
__export(exports_path, {
|
|
75
|
-
sep: () => sep,
|
|
76
|
-
resolve: () => resolve,
|
|
77
|
-
relative: () => relative,
|
|
78
|
-
posix: () => posix,
|
|
79
|
-
parse: () => parse,
|
|
80
|
-
normalize: () => normalize,
|
|
81
|
-
join: () => join,
|
|
82
|
-
isAbsolute: () => isAbsolute,
|
|
83
|
-
format: () => format,
|
|
84
|
-
extname: () => extname,
|
|
85
|
-
dirname: () => dirname,
|
|
86
|
-
delimiter: () => delimiter,
|
|
87
|
-
default: () => path_default,
|
|
88
|
-
basename: () => basename,
|
|
89
|
-
_makeLong: () => _makeLong
|
|
90
|
-
});
|
|
91
|
-
function assertPath(path) {
|
|
92
|
-
if (typeof path !== "string")
|
|
93
|
-
throw TypeError("Path must be a string. Received " + JSON.stringify(path));
|
|
94
|
-
}
|
|
95
|
-
function normalizeStringPosix(path, allowAboveRoot) {
|
|
96
|
-
var res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, code;
|
|
97
|
-
for (var i = 0;i <= path.length; ++i) {
|
|
98
|
-
if (i < path.length)
|
|
99
|
-
code = path.charCodeAt(i);
|
|
100
|
-
else if (code === 47)
|
|
101
|
-
break;
|
|
102
|
-
else
|
|
103
|
-
code = 47;
|
|
104
|
-
if (code === 47) {
|
|
105
|
-
if (lastSlash === i - 1 || dots === 1)
|
|
106
|
-
;
|
|
107
|
-
else if (lastSlash !== i - 1 && dots === 2) {
|
|
108
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 || res.charCodeAt(res.length - 2) !== 46) {
|
|
109
|
-
if (res.length > 2) {
|
|
110
|
-
var lastSlashIndex = res.lastIndexOf("/");
|
|
111
|
-
if (lastSlashIndex !== res.length - 1) {
|
|
112
|
-
if (lastSlashIndex === -1)
|
|
113
|
-
res = "", lastSegmentLength = 0;
|
|
114
|
-
else
|
|
115
|
-
res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
116
|
-
lastSlash = i, dots = 0;
|
|
117
|
-
continue;
|
|
118
|
-
}
|
|
119
|
-
} else if (res.length === 2 || res.length === 1) {
|
|
120
|
-
res = "", lastSegmentLength = 0, lastSlash = i, dots = 0;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (allowAboveRoot) {
|
|
125
|
-
if (res.length > 0)
|
|
126
|
-
res += "/..";
|
|
127
|
-
else
|
|
128
|
-
res = "..";
|
|
129
|
-
lastSegmentLength = 2;
|
|
130
|
-
}
|
|
131
|
-
} else {
|
|
132
|
-
if (res.length > 0)
|
|
133
|
-
res += "/" + path.slice(lastSlash + 1, i);
|
|
134
|
-
else
|
|
135
|
-
res = path.slice(lastSlash + 1, i);
|
|
136
|
-
lastSegmentLength = i - lastSlash - 1;
|
|
137
|
-
}
|
|
138
|
-
lastSlash = i, dots = 0;
|
|
139
|
-
} else if (code === 46 && dots !== -1)
|
|
140
|
-
++dots;
|
|
141
|
-
else
|
|
142
|
-
dots = -1;
|
|
143
|
-
}
|
|
144
|
-
return res;
|
|
145
|
-
}
|
|
146
|
-
function _format(sep, pathObject) {
|
|
147
|
-
var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
148
|
-
if (!dir)
|
|
149
|
-
return base;
|
|
150
|
-
if (dir === pathObject.root)
|
|
151
|
-
return dir + base;
|
|
152
|
-
return dir + sep + base;
|
|
153
|
-
}
|
|
154
|
-
function resolve() {
|
|
155
|
-
var resolvedPath = "", resolvedAbsolute = false, cwd;
|
|
156
|
-
for (var i = arguments.length - 1;i >= -1 && !resolvedAbsolute; i--) {
|
|
157
|
-
var path;
|
|
158
|
-
if (i >= 0)
|
|
159
|
-
path = arguments[i];
|
|
160
|
-
else {
|
|
161
|
-
if (cwd === undefined)
|
|
162
|
-
cwd = process.cwd();
|
|
163
|
-
path = cwd;
|
|
164
|
-
}
|
|
165
|
-
if (assertPath(path), path.length === 0)
|
|
166
|
-
continue;
|
|
167
|
-
resolvedPath = path + "/" + resolvedPath, resolvedAbsolute = path.charCodeAt(0) === 47;
|
|
168
|
-
}
|
|
169
|
-
if (resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute)
|
|
170
|
-
if (resolvedPath.length > 0)
|
|
171
|
-
return "/" + resolvedPath;
|
|
172
|
-
else
|
|
173
|
-
return "/";
|
|
174
|
-
else if (resolvedPath.length > 0)
|
|
175
|
-
return resolvedPath;
|
|
176
|
-
else
|
|
177
|
-
return ".";
|
|
178
|
-
}
|
|
179
|
-
function normalize(path) {
|
|
180
|
-
if (assertPath(path), path.length === 0)
|
|
181
|
-
return ".";
|
|
182
|
-
var isAbsolute = path.charCodeAt(0) === 47, trailingSeparator = path.charCodeAt(path.length - 1) === 47;
|
|
183
|
-
if (path = normalizeStringPosix(path, !isAbsolute), path.length === 0 && !isAbsolute)
|
|
184
|
-
path = ".";
|
|
185
|
-
if (path.length > 0 && trailingSeparator)
|
|
186
|
-
path += "/";
|
|
187
|
-
if (isAbsolute)
|
|
188
|
-
return "/" + path;
|
|
189
|
-
return path;
|
|
190
|
-
}
|
|
191
|
-
function isAbsolute(path) {
|
|
192
|
-
return assertPath(path), path.length > 0 && path.charCodeAt(0) === 47;
|
|
193
|
-
}
|
|
194
|
-
function join() {
|
|
195
|
-
if (arguments.length === 0)
|
|
196
|
-
return ".";
|
|
197
|
-
var joined;
|
|
198
|
-
for (var i = 0;i < arguments.length; ++i) {
|
|
199
|
-
var arg = arguments[i];
|
|
200
|
-
if (assertPath(arg), arg.length > 0)
|
|
201
|
-
if (joined === undefined)
|
|
202
|
-
joined = arg;
|
|
203
|
-
else
|
|
204
|
-
joined += "/" + arg;
|
|
205
|
-
}
|
|
206
|
-
if (joined === undefined)
|
|
207
|
-
return ".";
|
|
208
|
-
return normalize(joined);
|
|
209
|
-
}
|
|
210
|
-
function relative(from, to) {
|
|
211
|
-
if (assertPath(from), assertPath(to), from === to)
|
|
212
|
-
return "";
|
|
213
|
-
if (from = resolve(from), to = resolve(to), from === to)
|
|
214
|
-
return "";
|
|
215
|
-
var fromStart = 1;
|
|
216
|
-
for (;fromStart < from.length; ++fromStart)
|
|
217
|
-
if (from.charCodeAt(fromStart) !== 47)
|
|
218
|
-
break;
|
|
219
|
-
var fromEnd = from.length, fromLen = fromEnd - fromStart, toStart = 1;
|
|
220
|
-
for (;toStart < to.length; ++toStart)
|
|
221
|
-
if (to.charCodeAt(toStart) !== 47)
|
|
222
|
-
break;
|
|
223
|
-
var toEnd = to.length, toLen = toEnd - toStart, length = fromLen < toLen ? fromLen : toLen, lastCommonSep = -1, i = 0;
|
|
224
|
-
for (;i <= length; ++i) {
|
|
225
|
-
if (i === length) {
|
|
226
|
-
if (toLen > length) {
|
|
227
|
-
if (to.charCodeAt(toStart + i) === 47)
|
|
228
|
-
return to.slice(toStart + i + 1);
|
|
229
|
-
else if (i === 0)
|
|
230
|
-
return to.slice(toStart + i);
|
|
231
|
-
} else if (fromLen > length) {
|
|
232
|
-
if (from.charCodeAt(fromStart + i) === 47)
|
|
233
|
-
lastCommonSep = i;
|
|
234
|
-
else if (i === 0)
|
|
235
|
-
lastCommonSep = 0;
|
|
236
|
-
}
|
|
237
|
-
break;
|
|
238
|
-
}
|
|
239
|
-
var fromCode = from.charCodeAt(fromStart + i), toCode = to.charCodeAt(toStart + i);
|
|
240
|
-
if (fromCode !== toCode)
|
|
241
|
-
break;
|
|
242
|
-
else if (fromCode === 47)
|
|
243
|
-
lastCommonSep = i;
|
|
244
|
-
}
|
|
245
|
-
var out = "";
|
|
246
|
-
for (i = fromStart + lastCommonSep + 1;i <= fromEnd; ++i)
|
|
247
|
-
if (i === fromEnd || from.charCodeAt(i) === 47)
|
|
248
|
-
if (out.length === 0)
|
|
249
|
-
out += "..";
|
|
250
|
-
else
|
|
251
|
-
out += "/..";
|
|
252
|
-
if (out.length > 0)
|
|
253
|
-
return out + to.slice(toStart + lastCommonSep);
|
|
254
|
-
else {
|
|
255
|
-
if (toStart += lastCommonSep, to.charCodeAt(toStart) === 47)
|
|
256
|
-
++toStart;
|
|
257
|
-
return to.slice(toStart);
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
function _makeLong(path) {
|
|
261
|
-
return path;
|
|
262
|
-
}
|
|
263
|
-
function dirname(path) {
|
|
264
|
-
if (assertPath(path), path.length === 0)
|
|
265
|
-
return ".";
|
|
266
|
-
var code = path.charCodeAt(0), hasRoot = code === 47, end = -1, matchedSlash = true;
|
|
267
|
-
for (var i = path.length - 1;i >= 1; --i)
|
|
268
|
-
if (code = path.charCodeAt(i), code === 47) {
|
|
269
|
-
if (!matchedSlash) {
|
|
270
|
-
end = i;
|
|
271
|
-
break;
|
|
272
|
-
}
|
|
273
|
-
} else
|
|
274
|
-
matchedSlash = false;
|
|
275
|
-
if (end === -1)
|
|
276
|
-
return hasRoot ? "/" : ".";
|
|
277
|
-
if (hasRoot && end === 1)
|
|
278
|
-
return "//";
|
|
279
|
-
return path.slice(0, end);
|
|
280
|
-
}
|
|
281
|
-
function basename(path, ext) {
|
|
282
|
-
if (ext !== undefined && typeof ext !== "string")
|
|
283
|
-
throw TypeError('"ext" argument must be a string');
|
|
284
|
-
assertPath(path);
|
|
285
|
-
var start = 0, end = -1, matchedSlash = true, i;
|
|
286
|
-
if (ext !== undefined && ext.length > 0 && ext.length <= path.length) {
|
|
287
|
-
if (ext.length === path.length && ext === path)
|
|
288
|
-
return "";
|
|
289
|
-
var extIdx = ext.length - 1, firstNonSlashEnd = -1;
|
|
290
|
-
for (i = path.length - 1;i >= 0; --i) {
|
|
291
|
-
var code = path.charCodeAt(i);
|
|
292
|
-
if (code === 47) {
|
|
293
|
-
if (!matchedSlash) {
|
|
294
|
-
start = i + 1;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
} else {
|
|
298
|
-
if (firstNonSlashEnd === -1)
|
|
299
|
-
matchedSlash = false, firstNonSlashEnd = i + 1;
|
|
300
|
-
if (extIdx >= 0)
|
|
301
|
-
if (code === ext.charCodeAt(extIdx)) {
|
|
302
|
-
if (--extIdx === -1)
|
|
303
|
-
end = i;
|
|
304
|
-
} else
|
|
305
|
-
extIdx = -1, end = firstNonSlashEnd;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (start === end)
|
|
309
|
-
end = firstNonSlashEnd;
|
|
310
|
-
else if (end === -1)
|
|
311
|
-
end = path.length;
|
|
312
|
-
return path.slice(start, end);
|
|
313
|
-
} else {
|
|
314
|
-
for (i = path.length - 1;i >= 0; --i)
|
|
315
|
-
if (path.charCodeAt(i) === 47) {
|
|
316
|
-
if (!matchedSlash) {
|
|
317
|
-
start = i + 1;
|
|
318
|
-
break;
|
|
319
|
-
}
|
|
320
|
-
} else if (end === -1)
|
|
321
|
-
matchedSlash = false, end = i + 1;
|
|
322
|
-
if (end === -1)
|
|
323
|
-
return "";
|
|
324
|
-
return path.slice(start, end);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
function extname(path) {
|
|
328
|
-
assertPath(path);
|
|
329
|
-
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, preDotState = 0;
|
|
330
|
-
for (var i = path.length - 1;i >= 0; --i) {
|
|
331
|
-
var code = path.charCodeAt(i);
|
|
332
|
-
if (code === 47) {
|
|
333
|
-
if (!matchedSlash) {
|
|
334
|
-
startPart = i + 1;
|
|
335
|
-
break;
|
|
336
|
-
}
|
|
337
|
-
continue;
|
|
338
|
-
}
|
|
339
|
-
if (end === -1)
|
|
340
|
-
matchedSlash = false, end = i + 1;
|
|
341
|
-
if (code === 46) {
|
|
342
|
-
if (startDot === -1)
|
|
343
|
-
startDot = i;
|
|
344
|
-
else if (preDotState !== 1)
|
|
345
|
-
preDotState = 1;
|
|
346
|
-
} else if (startDot !== -1)
|
|
347
|
-
preDotState = -1;
|
|
348
|
-
}
|
|
349
|
-
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1)
|
|
350
|
-
return "";
|
|
351
|
-
return path.slice(startDot, end);
|
|
352
|
-
}
|
|
353
|
-
function format(pathObject) {
|
|
354
|
-
if (pathObject === null || typeof pathObject !== "object")
|
|
355
|
-
throw TypeError('The "pathObject" argument must be of type Object. Received type ' + typeof pathObject);
|
|
356
|
-
return _format("/", pathObject);
|
|
357
|
-
}
|
|
358
|
-
function parse(path) {
|
|
359
|
-
assertPath(path);
|
|
360
|
-
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
361
|
-
if (path.length === 0)
|
|
362
|
-
return ret;
|
|
363
|
-
var code = path.charCodeAt(0), isAbsolute2 = code === 47, start;
|
|
364
|
-
if (isAbsolute2)
|
|
365
|
-
ret.root = "/", start = 1;
|
|
366
|
-
else
|
|
367
|
-
start = 0;
|
|
368
|
-
var startDot = -1, startPart = 0, end = -1, matchedSlash = true, i = path.length - 1, preDotState = 0;
|
|
369
|
-
for (;i >= start; --i) {
|
|
370
|
-
if (code = path.charCodeAt(i), code === 47) {
|
|
371
|
-
if (!matchedSlash) {
|
|
372
|
-
startPart = i + 1;
|
|
373
|
-
break;
|
|
374
|
-
}
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
if (end === -1)
|
|
378
|
-
matchedSlash = false, end = i + 1;
|
|
379
|
-
if (code === 46) {
|
|
380
|
-
if (startDot === -1)
|
|
381
|
-
startDot = i;
|
|
382
|
-
else if (preDotState !== 1)
|
|
383
|
-
preDotState = 1;
|
|
384
|
-
} else if (startDot !== -1)
|
|
385
|
-
preDotState = -1;
|
|
386
|
-
}
|
|
387
|
-
if (startDot === -1 || end === -1 || preDotState === 0 || preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) {
|
|
388
|
-
if (end !== -1)
|
|
389
|
-
if (startPart === 0 && isAbsolute2)
|
|
390
|
-
ret.base = ret.name = path.slice(1, end);
|
|
391
|
-
else
|
|
392
|
-
ret.base = ret.name = path.slice(startPart, end);
|
|
393
|
-
} else {
|
|
394
|
-
if (startPart === 0 && isAbsolute2)
|
|
395
|
-
ret.name = path.slice(1, startDot), ret.base = path.slice(1, end);
|
|
396
|
-
else
|
|
397
|
-
ret.name = path.slice(startPart, startDot), ret.base = path.slice(startPart, end);
|
|
398
|
-
ret.ext = path.slice(startDot, end);
|
|
399
|
-
}
|
|
400
|
-
if (startPart > 0)
|
|
401
|
-
ret.dir = path.slice(0, startPart - 1);
|
|
402
|
-
else if (isAbsolute2)
|
|
403
|
-
ret.dir = "/";
|
|
404
|
-
return ret;
|
|
405
|
-
}
|
|
406
|
-
var sep = "/", delimiter = ":", posix, path_default;
|
|
407
|
-
var init_path = __esm(() => {
|
|
408
|
-
posix = ((p) => (p.posix = p, p))({ resolve, normalize, isAbsolute, join, relative, _makeLong, dirname, basename, extname, format, parse, sep, delimiter, win32: null, posix: null });
|
|
409
|
-
path_default = posix;
|
|
410
|
-
});
|
|
411
|
-
|
|
412
|
-
// src/dev.tsx
|
|
413
|
-
init_path();
|
|
414
|
-
var {mkdir, readFile, watch} = (() => ({}));
|
|
415
|
-
var DEV_SUBDIR = ".dev";
|
|
416
|
-
var BUILD_ID_FILE = "build-id";
|
|
417
|
-
var HEARTBEAT_MS = 5000;
|
|
418
|
-
function isDevDefault() {
|
|
419
|
-
return true;
|
|
420
|
-
}
|
|
421
|
-
function createDevReloader(options) {
|
|
422
|
-
const { distDir, enabled = isDevDefault() } = options;
|
|
423
|
-
return async (c) => {
|
|
424
|
-
if (!enabled)
|
|
425
|
-
return c.notFound();
|
|
426
|
-
const devDir = resolve(distDir, DEV_SUBDIR);
|
|
427
|
-
await mkdir(devDir, { recursive: true });
|
|
428
|
-
const buildIdPath = resolve(devDir, BUILD_ID_FILE);
|
|
429
|
-
const signal = c.req.raw.signal;
|
|
430
|
-
const lastEventId = (c.req.header("Last-Event-ID") ?? "").trim();
|
|
431
|
-
const readBuildId = async () => {
|
|
432
|
-
try {
|
|
433
|
-
return new TextDecoder().decode(await readFile(buildIdPath)).trim();
|
|
434
|
-
} catch {
|
|
435
|
-
return "";
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
const stream = new ReadableStream({
|
|
439
|
-
async start(controller) {
|
|
440
|
-
const encoder = new TextEncoder;
|
|
441
|
-
const send = (chunk) => {
|
|
442
|
-
try {
|
|
443
|
-
controller.enqueue(encoder.encode(chunk));
|
|
444
|
-
} catch {}
|
|
445
|
-
};
|
|
446
|
-
send(`retry: 1000
|
|
447
|
-
|
|
448
|
-
`);
|
|
449
|
-
let lastSentId = "";
|
|
450
|
-
const initialId = await readBuildId();
|
|
451
|
-
if (initialId) {
|
|
452
|
-
lastSentId = initialId;
|
|
453
|
-
const event = lastEventId && lastEventId !== initialId ? "reload" : "hello";
|
|
454
|
-
send(`event: ${event}
|
|
455
|
-
id: ${initialId}
|
|
456
|
-
data: ${initialId}
|
|
457
|
-
|
|
458
|
-
`);
|
|
459
|
-
}
|
|
460
|
-
const heartbeat = setInterval(() => send(`: hb
|
|
461
|
-
|
|
462
|
-
`), HEARTBEAT_MS);
|
|
463
|
-
try {
|
|
464
|
-
const iter = watch(devDir, { signal });
|
|
465
|
-
for await (const event of iter) {
|
|
466
|
-
if (event.filename !== BUILD_ID_FILE)
|
|
467
|
-
continue;
|
|
468
|
-
const id = await readBuildId();
|
|
469
|
-
if (!id || id === lastSentId)
|
|
470
|
-
continue;
|
|
471
|
-
lastSentId = id;
|
|
472
|
-
send(`event: reload
|
|
473
|
-
id: ${id}
|
|
474
|
-
data: ${id}
|
|
475
|
-
|
|
476
|
-
`);
|
|
477
|
-
}
|
|
478
|
-
} catch (err) {
|
|
479
|
-
const name = err?.name;
|
|
480
|
-
if (name !== "AbortError") {
|
|
481
|
-
const message = err.message ?? "watch error";
|
|
482
|
-
send(`event: error
|
|
483
|
-
data: ${JSON.stringify(message)}
|
|
484
|
-
|
|
485
|
-
`);
|
|
486
|
-
}
|
|
487
|
-
} finally {
|
|
488
|
-
clearInterval(heartbeat);
|
|
489
|
-
try {
|
|
490
|
-
controller.close();
|
|
491
|
-
} catch {}
|
|
492
|
-
}
|
|
493
|
-
},
|
|
494
|
-
cancel() {}
|
|
495
|
-
});
|
|
496
|
-
return new Response(stream, {
|
|
497
|
-
headers: {
|
|
498
|
-
"Content-Type": "text/event-stream",
|
|
499
|
-
"Cache-Control": "no-cache, no-transform",
|
|
500
|
-
Connection: "keep-alive",
|
|
501
|
-
"X-Accel-Buffering": "no"
|
|
502
|
-
}
|
|
503
|
-
});
|
|
504
|
-
};
|
|
505
|
-
}
|
|
506
|
-
export {
|
|
507
|
-
createDevReloader
|
|
508
|
-
};
|