rebuildjs 0.26.1 → 0.27.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/browser/index.js +14 -15
- package/build/index.d.ts +6 -3
- package/build/index.js +75 -15
- package/build/index.test.ts +22 -18
- package/package.json +2 -2
package/browser/index.js
CHANGED
|
@@ -18,22 +18,21 @@ export const [
|
|
|
18
18
|
browser__metafile_,
|
|
19
19
|
browser__metafile__set
|
|
20
20
|
] = /** @type {be_lock_memosig_triple_T<rebuildjs_metafile_T>} */
|
|
21
|
-
be_lock_memosig_triple_(()=>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
be_lock_memosig_triple_(()=>undefined,
|
|
22
|
+
async (ctx, browser__metafile$)=>{
|
|
23
|
+
browser__metafile__waitfor_promise?.cancel?.()
|
|
24
|
+
let metafile_path
|
|
25
|
+
if (!browser__metafile$.lock) {
|
|
26
|
+
metafile_path = browser__metafile_path_(ctx)
|
|
27
|
+
browser__metafile__waitfor_promise = waitfor(
|
|
28
|
+
()=>file_exists_(metafile_path),
|
|
29
|
+
200
|
|
30
|
+
).catch(()=>false)
|
|
31
|
+
if (await browser__metafile__waitfor_promise && metafile_path === browser__metafile_path_(ctx)) {
|
|
32
|
+
browser__metafile$._ = await readFile(metafile_path).then(buf=>JSON.parse(buf + ''))
|
|
33
|
+
}
|
|
34
34
|
}
|
|
35
|
-
}
|
|
36
|
-
}, { ns: 'app', id: 'browser__metafile' })
|
|
35
|
+
}, { ns: 'app', id: 'browser__metafile' })
|
|
37
36
|
export function browser__metafile__persist() {
|
|
38
37
|
return nullish__none_([
|
|
39
38
|
browser__metafile_path_(app_ctx),
|
package/build/index.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import type { ctx__be_T, ctx__get_T, ctx__set_T, sig_T } from 'ctx-core/rmemo'
|
|
1
|
+
import type { ctx__be_T, ctx__get_T, ctx__set_T, rmemo__wait_ret_T, sig_T } from 'ctx-core/rmemo'
|
|
2
2
|
import type { BuildContext, BuildOptions, Plugin } from 'esbuild'
|
|
3
3
|
import type { has_app_T } from '../ctx/index.js'
|
|
4
4
|
export declare const build_id$_:ctx__be_T<has_app_T, sig_T<string|undefined>, 'app'>
|
|
5
5
|
export declare const build_id_:ctx__get_T<has_app_T, string|undefined>
|
|
6
6
|
export declare const build_id__set:ctx__set_T<has_app_T, string|undefined>
|
|
7
|
+
export declare const persist__metafile__build_id$_:ctx__be_T<has_app_T, sig_T<string|undefined>, 'app'>
|
|
8
|
+
export declare const persist__metafile__build_id_:ctx__get_T<has_app_T, string|undefined>
|
|
9
|
+
export declare const persist__metafile__ready$_:ctx__be_T<has_app_T, sig_T<boolean>, 'app'>
|
|
10
|
+
export declare const persist__metafile__ready_:ctx__get_T<has_app_T, boolean>
|
|
7
11
|
export declare function build_id__refresh():string
|
|
8
12
|
export declare const rebuildjs__build_id$_:ctx__be_T<has_app_T, sig_T<string>, 'app'>
|
|
9
13
|
export declare const rebuildjs__build_id_:ctx__get_T<has_app_T, string>
|
|
10
14
|
export declare const rebuildjs__build_id__set:ctx__set_T<has_app_T, string>
|
|
11
15
|
export declare const rebuildjs__ready$_:ctx__be_T<has_app_T, sig_T<boolean>, 'app'>
|
|
12
16
|
export declare const rebuildjs__ready_:ctx__get_T<has_app_T, boolean>
|
|
13
|
-
export declare function rebuildjs__ready__wait(timeout?:number):
|
|
17
|
+
export declare function rebuildjs__ready__wait(timeout?:number):rmemo__wait_ret_T<unknown>
|
|
14
18
|
export declare function browser__build(config?:rebuildjs_build_config_T):Promise<BuildContext>
|
|
15
19
|
export declare function server__build(config?:rebuildjs_build_config_T):Promise<BuildContext>
|
|
16
20
|
export declare function server__external_(config?:Partial<BuildOptions>):Promise<string[]>
|
|
17
21
|
export declare function rebuildjs_plugin_():Plugin
|
|
18
|
-
export declare class RebuildjsInterrupt extends Error {}
|
|
19
22
|
export type rebuildjs_build_config_T =
|
|
20
23
|
Partial<BuildOptions>&{ rebuildjs?:rebuildjs_plugin_config_T }
|
|
21
24
|
export type rebuildjs_plugin_config_T = {
|
package/build/index.js
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
/// <reference types="../metafile_l0/index.d.ts" />
|
|
2
2
|
/// <reference types="./index.d.ts" />
|
|
3
3
|
import { file_exists__waitfor } from 'ctx-core/fs'
|
|
4
|
-
import { nullish__none_, run } from 'ctx-core/function'
|
|
4
|
+
import { Cancel, cancel__period_, nullish__none_, run, waitfor } from 'ctx-core/function'
|
|
5
5
|
import { be, be_memo_pair_, be_sig_triple_, memo_, off, rmemo__wait } from 'ctx-core/rmemo'
|
|
6
6
|
import { short_uuid_ } from 'ctx-core/uuid'
|
|
7
7
|
import { context } from 'esbuild'
|
|
8
8
|
import { fdir } from 'fdir'
|
|
9
|
-
import { link, mkdir, rm } from 'node:fs/promises'
|
|
9
|
+
import { link, mkdir, readFile, rm } from 'node:fs/promises'
|
|
10
10
|
import { join, relative, resolve } from 'path'
|
|
11
11
|
import { app_path_, browser_path_, cwd_, is_prod_, server__relative_path_, server_path_ } from '../app/index.js'
|
|
12
12
|
import {
|
|
13
13
|
browser__metafile_,
|
|
14
14
|
browser__metafile__persist,
|
|
15
15
|
browser__metafile__set,
|
|
16
|
+
browser__metafile_path_,
|
|
16
17
|
browser__output__relative_path_
|
|
17
18
|
} from '../browser/index.js'
|
|
18
19
|
import { app_ctx } from '../ctx/index.js'
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
server__metafile_,
|
|
22
23
|
server__metafile__persist,
|
|
23
24
|
server__metafile__set,
|
|
25
|
+
server__metafile_path_,
|
|
24
26
|
server__output__relative_path_M_middleware_ctx_
|
|
25
27
|
} from '../server/index.js'
|
|
26
28
|
export const [
|
|
@@ -35,6 +37,69 @@ export function build_id__refresh() {
|
|
|
35
37
|
build_id__set(app_ctx, build_id)
|
|
36
38
|
return build_id
|
|
37
39
|
}
|
|
40
|
+
export const [
|
|
41
|
+
persist__metafile__build_id$_,
|
|
42
|
+
persist__metafile__build_id_,
|
|
43
|
+
] = be_memo_pair_(()=>undefined,
|
|
44
|
+
(ctx, persist__metafile__build_id$)=>{
|
|
45
|
+
const build_id = build_id_(ctx)
|
|
46
|
+
const metafile__build_id = metafile__build_id_(ctx)
|
|
47
|
+
const server__metafile_path = server__metafile_path_(ctx)
|
|
48
|
+
const browser__metafile_path = browser__metafile_path_(ctx)
|
|
49
|
+
if (metafile__build_id) {
|
|
50
|
+
const cancel__period = cancel__period_(0, cancel_)
|
|
51
|
+
run(async ()=>{
|
|
52
|
+
try {
|
|
53
|
+
await cmd(
|
|
54
|
+
file_exists__waitfor(server__metafile_path, 1000, cancel__period))
|
|
55
|
+
await cmd(
|
|
56
|
+
waitfor(()=>
|
|
57
|
+
readFile(server__metafile_path).then(buf=>
|
|
58
|
+
JSON.parse('' + buf)?.build_id === build_id),
|
|
59
|
+
1000,
|
|
60
|
+
cancel__period))
|
|
61
|
+
await cmd(
|
|
62
|
+
file_exists__waitfor(browser__metafile_path, 1000, cancel__period))
|
|
63
|
+
await cmd(
|
|
64
|
+
waitfor(()=>
|
|
65
|
+
readFile(browser__metafile_path).then(buf=>
|
|
66
|
+
JSON.parse('' + buf)?.build_id === build_id),
|
|
67
|
+
1000,
|
|
68
|
+
cancel__period))
|
|
69
|
+
persist__metafile__build_id$._ = build_id
|
|
70
|
+
} catch (err) {
|
|
71
|
+
if (err instanceof Cancel) return
|
|
72
|
+
throw err
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
async function cmd(promise) {
|
|
77
|
+
if (cancel_()) throw new Cancel
|
|
78
|
+
const rv = await promise
|
|
79
|
+
if (cancel_()) {
|
|
80
|
+
promise.cancel?.()
|
|
81
|
+
throw new Cancel
|
|
82
|
+
}
|
|
83
|
+
return rv
|
|
84
|
+
}
|
|
85
|
+
function cancel_() {
|
|
86
|
+
return (
|
|
87
|
+
build_id_(ctx) !== build_id
|
|
88
|
+
|| metafile__build_id_(ctx) !== metafile__build_id
|
|
89
|
+
|| server__metafile_path_(ctx) !== server__metafile_path
|
|
90
|
+
|| browser__metafile_path_(ctx) !== browser__metafile_path
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{ id: 'persist__metafile__build_id', ns: 'app' })
|
|
95
|
+
export const [
|
|
96
|
+
persist__metafile__ready$_,
|
|
97
|
+
persist__metafile__ready_,
|
|
98
|
+
] = be_memo_pair_(ctx=>
|
|
99
|
+
nullish__none_([build_id_(ctx), persist__metafile__build_id_(ctx)],
|
|
100
|
+
(build_id, persist__metafile__build_id)=>
|
|
101
|
+
!!(build_id && build_id === persist__metafile__build_id)),
|
|
102
|
+
{ id: 'persist__metafile__ready', ns: 'app' })
|
|
38
103
|
export const [
|
|
39
104
|
rebuildjs__build_id$_,
|
|
40
105
|
rebuildjs__build_id_,
|
|
@@ -217,6 +282,7 @@ export function rebuildjs_plugin_() {
|
|
|
217
282
|
r()
|
|
218
283
|
return assets__link$
|
|
219
284
|
function r() {
|
|
285
|
+
if (!persist__metafile__ready_(ctx)) return
|
|
220
286
|
nullish__none_([
|
|
221
287
|
build_id_(ctx),
|
|
222
288
|
metafile__build_id_(ctx),
|
|
@@ -242,23 +308,22 @@ export function rebuildjs_plugin_() {
|
|
|
242
308
|
const browser_asset_path = join(
|
|
243
309
|
browser_path,
|
|
244
310
|
relative(server__relative_path, output__relative_path))
|
|
245
|
-
await cmd(
|
|
311
|
+
await cmd(
|
|
246
312
|
rm(browser_asset_path, { force: true }))
|
|
247
|
-
await cmd(
|
|
313
|
+
await cmd(
|
|
248
314
|
file_exists__waitfor(server_asset_path))
|
|
249
|
-
await cmd(
|
|
315
|
+
await cmd(
|
|
250
316
|
link(server_asset_path, browser_asset_path))
|
|
251
317
|
}
|
|
252
318
|
} catch (err) {
|
|
253
|
-
if (err instanceof
|
|
319
|
+
if (err instanceof Cancel) return
|
|
254
320
|
throw err
|
|
255
321
|
}
|
|
256
322
|
rebuildjs__build_id__set(ctx, build_id)
|
|
257
323
|
})
|
|
258
324
|
}
|
|
259
|
-
async function cmd(
|
|
260
|
-
if (cancel_()) throw new
|
|
261
|
-
const promise = fn()
|
|
325
|
+
async function cmd(promise) {
|
|
326
|
+
if (cancel_()) throw new Cancel()
|
|
262
327
|
promise.rebuildjs_cancel$ = run(memo_(rebuildjs_cancel$=>{
|
|
263
328
|
if (cancel_()) {
|
|
264
329
|
promise.cancel?.()
|
|
@@ -267,7 +332,7 @@ export function rebuildjs_plugin_() {
|
|
|
267
332
|
return rebuildjs_cancel$
|
|
268
333
|
}))
|
|
269
334
|
const ret = await promise
|
|
270
|
-
if (cancel_()) throw new
|
|
335
|
+
if (cancel_()) throw new Cancel()
|
|
271
336
|
return ret
|
|
272
337
|
}
|
|
273
338
|
function cancel_() {
|
|
@@ -336,8 +401,3 @@ async function browser__metafile__update(browser__metafile, build_id) {
|
|
|
336
401
|
}
|
|
337
402
|
await browser__metafile__persist()
|
|
338
403
|
}
|
|
339
|
-
export class RebuildjsInterrupt extends Error {
|
|
340
|
-
constructor() {
|
|
341
|
-
super('RebuildjsInterrupt')
|
|
342
|
-
}
|
|
343
|
-
}
|
package/build/index.test.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { rm } from 'node:fs/promises'
|
|
|
6
6
|
import { dirname, join } from 'path'
|
|
7
7
|
import { test } from 'uvu'
|
|
8
8
|
import { equal, throws } from 'uvu/assert'
|
|
9
|
-
import { browser__metafile0, server__metafile0 } from '../_fixtures/metafiles.js'
|
|
9
|
+
import { browser__metafile0, browser__metafile1, server__metafile0, server__metafile1 } from '../_fixtures/metafiles.js'
|
|
10
10
|
import { cwd__set } from '../app/index.js'
|
|
11
11
|
import { browser__metafile_, browser__metafile__set } from '../browser/index.js'
|
|
12
12
|
import { app_ctx } from '../ctx/index.js'
|
|
@@ -63,7 +63,7 @@ test('rebuildjs__build_id', ()=>{
|
|
|
63
63
|
// @ts-expect-error TS2345
|
|
64
64
|
throws(()=>rebuildjs__build_id_(ctx_()))
|
|
65
65
|
})
|
|
66
|
-
test('rebuildjs__ready', ()=>{
|
|
66
|
+
test('rebuildjs__ready', async ()=>{
|
|
67
67
|
equal(rebuildjs__ready$_(app_ctx)(), false)
|
|
68
68
|
equal(rebuildjs__ready_(app_ctx), false)
|
|
69
69
|
const build_id = server__metafile0.build_id!
|
|
@@ -86,22 +86,26 @@ test('rebuildjs__ready', ()=>{
|
|
|
86
86
|
})
|
|
87
87
|
test('rebuildjs__ready__wait', async ()=>{
|
|
88
88
|
let done = false
|
|
89
|
-
rebuildjs__ready__wait()
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
const promise = rebuildjs__ready__wait()
|
|
90
|
+
promise.then(()=>done = true)
|
|
91
|
+
try {
|
|
92
|
+
equal(done, false)
|
|
93
|
+
const build_id = server__metafile1.build_id!
|
|
94
|
+
build_id__set(app_ctx, build_id)
|
|
95
|
+
await sleep(0)
|
|
96
|
+
equal(done, false)
|
|
97
|
+
server__metafile__set(app_ctx, server__metafile1)
|
|
98
|
+
await sleep(0)
|
|
99
|
+
equal(done, false)
|
|
100
|
+
browser__metafile__set(app_ctx, browser__metafile1)
|
|
101
|
+
await sleep(0)
|
|
102
|
+
equal(done, false)
|
|
103
|
+
rebuildjs__build_id__set(app_ctx, build_id)
|
|
104
|
+
await sleep(0)
|
|
105
|
+
equal(done, true)
|
|
106
|
+
} finally {
|
|
107
|
+
await promise.cancel()
|
|
108
|
+
}
|
|
105
109
|
})
|
|
106
110
|
test('rebuildjs__ready__wait|timeout', async ()=>{
|
|
107
111
|
let err:Error|undefined = undefined
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rebuildjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "Reactive esbuild...simple hackable alternative to vite for Multi Page Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"reactive",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"./package.json": "./package.json"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"ctx-core": "^5.
|
|
56
|
+
"ctx-core": "^5.9.0",
|
|
57
57
|
"elysia": "^0.8.6",
|
|
58
58
|
"esbuild": "^0.19.11",
|
|
59
59
|
"fdir": "^6.1.1",
|