rebuildjs 0.34.4 → 0.35.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/browser/index.js CHANGED
@@ -1,5 +1,14 @@
1
1
  import { file_exists__waitfor } from 'ctx-core/fs'
2
- import { be_lock_memosig_triple_, be_memo_pair_, Cancel, nullish__none_, sleep, tup, waitfor } from 'ctx-core/rmemo'
2
+ import {
3
+ be_lock_memosig_triple_,
4
+ be_memo_pair_,
5
+ Cancel,
6
+ memo_,
7
+ nullish__none_,
8
+ sleep,
9
+ tup,
10
+ waitfor
11
+ } from 'ctx-core/rmemo'
3
12
  import { mkdir, readFile, writeFile } from 'node:fs/promises'
4
13
  import { join, relative } from 'path'
5
14
  import { browser__relative_path_, browser_path_, cwd_ } from '../app/index.js'
@@ -11,7 +20,6 @@ export const [
11
20
  ] = be_memo_pair_(ctx=>
12
21
  join(browser_path_(ctx), 'metafile.json'),
13
22
  { ns: 'app', id: 'browser__metafile_path' })
14
- let browser__metafile__waitfor_promise
15
23
  export const [
16
24
  browser__metafile$_,
17
25
  browser__metafile_,
@@ -20,51 +28,54 @@ export const [
20
28
  be_lock_memosig_triple_(
21
29
  ()=>undefined,
22
30
  { ns: 'app', id: 'browser__metafile' }
23
- ).add(async (ctx, browser__metafile$)=>{
24
- browser__metafile__waitfor_promise?.cancel?.()
25
- if (browser__metafile$.lock) return
26
- nullish__none_([browser__metafile_path_(ctx)],
27
- async browser__metafile_path=>{
28
- try {
29
- if (await cmd(
30
- browser__metafile__waitfor_promise =
31
- file_exists__waitfor(
32
- browser__metafile_path,
33
- 1000,
34
- ()=>cmd(sleep(0))))
35
- ) {
36
- browser__metafile$._ = await cmd(
37
- waitfor(async ()=>{
38
- const buf = await cmd(readFile(browser__metafile_path))
39
- const json = buf + ''
40
- try {
41
- return JSON.parse(json)
42
- } catch {
43
- return undefined
44
- }
45
- }, 1000))
31
+ ).add((ctx, browser__metafile$)=>
32
+ memo_(browser__metafile__waitfor_promise$=>{
33
+ browser__metafile__waitfor_promise$.val?.cancel?.()
34
+ if (browser__metafile$.lock) return
35
+ return nullish__none_([browser__metafile_path_(ctx)],
36
+ browser__metafile_path=>{
37
+ const browser__metafile__waitfor_promise =
38
+ file_exists__waitfor(
39
+ browser__metafile_path,
40
+ 1000,
41
+ ()=>cmd(sleep(0)))
42
+ cmd(browser__metafile__waitfor_promise)
43
+ .then(async success=>{
44
+ if (success) {
45
+ browser__metafile$._ = await cmd(
46
+ waitfor(async ()=>{
47
+ const buf = await cmd(readFile(browser__metafile_path))
48
+ const json = buf + ''
49
+ try {
50
+ return JSON.parse(json)
51
+ } catch {
52
+ return undefined
53
+ }
54
+ }, 1000))
55
+ }
56
+ }).catch(err=>{
57
+ if (err instanceof Cancel) return
58
+ throw err
59
+ })
60
+ return browser__metafile__waitfor_promise
61
+ async function cmd(promise) {
62
+ if (cancel_()) throw new Cancel()
63
+ const rv = await promise
64
+ if (cancel_()) {
65
+ promise.cancel?.()
66
+ throw new Cancel()
67
+ }
68
+ return rv
46
69
  }
47
- } catch (err) {
48
- if (err instanceof Cancel) return
49
- throw err
50
- }
51
- async function cmd(promise) {
52
- if (cancel_()) throw new Cancel()
53
- const rv = await promise
54
- if (cancel_()) {
55
- promise.cancel?.()
56
- throw new Cancel()
70
+ function cancel_() {
71
+ return (
72
+ browser__metafile$.lock
73
+ || browser__metafile_path !== browser__metafile_path_(ctx)
74
+ )
57
75
  }
58
- return rv
59
- }
60
- function cancel_() {
61
- return (
62
- browser__metafile$.lock
63
- || browser__metafile_path !== browser__metafile_path_(ctx)
64
- )
65
- }
66
- })
67
- })
76
+ })
77
+ })
78
+ )
68
79
  export function browser__metafile__persist() {
69
80
  return nullish__none_([
70
81
  browser__metafile_path_(app_ctx),
package/build/index.js CHANGED
@@ -56,56 +56,57 @@ export const [
56
56
  ] = be_memo_pair_(
57
57
  ()=>undefined,
58
58
  { id: 'persist__metafile__build_id', ns: 'app' }
59
- ).add((ctx, persist__metafile__build_id$)=>{
60
- const build_id = build_id_(ctx)
61
- const metafile__build_id = metafile__build_id_(ctx)
62
- const server__metafile_path = server__metafile_path_(ctx)
63
- const browser__metafile_path = browser__metafile_path_(ctx)
64
- if (metafile__build_id) {
65
- const cancel__period = cancel__period_(0, cancel_)
66
- run(async ()=>{
67
- try {
68
- await cmd(
69
- file_exists__waitfor(server__metafile_path, 1000, cancel__period))
70
- await cmd(
71
- waitfor(()=>
72
- readFile(server__metafile_path).then(buf=>
73
- JSON.parse('' + buf)?.build_id === build_id),
74
- 1000,
75
- cancel__period))
76
- await cmd(
77
- file_exists__waitfor(browser__metafile_path, 1000, cancel__period))
78
- await cmd(
79
- waitfor(()=>
80
- readFile(browser__metafile_path).then(buf=>
81
- JSON.parse('' + buf)?.build_id === build_id),
82
- 1000,
83
- cancel__period))
84
- persist__metafile__build_id$._ = build_id
85
- } catch (err) {
86
- if (err instanceof Cancel) return
87
- throw err
59
+ ).add((ctx, persist__metafile__build_id$)=>
60
+ memo_(()=>{
61
+ const build_id = build_id_(ctx)
62
+ const metafile__build_id = metafile__build_id_(ctx)
63
+ const server__metafile_path = server__metafile_path_(ctx)
64
+ const browser__metafile_path = browser__metafile_path_(ctx)
65
+ if (metafile__build_id) {
66
+ const cancel__period = cancel__period_(0, cancel_)
67
+ run(async ()=>{
68
+ try {
69
+ await cmd(
70
+ file_exists__waitfor(server__metafile_path, 1000, cancel__period))
71
+ await cmd(
72
+ waitfor(()=>
73
+ readFile(server__metafile_path).then(buf=>
74
+ JSON.parse('' + buf)?.build_id === build_id),
75
+ 1000,
76
+ cancel__period))
77
+ await cmd(
78
+ file_exists__waitfor(browser__metafile_path, 1000, cancel__period))
79
+ await cmd(
80
+ waitfor(()=>
81
+ readFile(browser__metafile_path).then(buf=>
82
+ JSON.parse('' + buf)?.build_id === build_id),
83
+ 1000,
84
+ cancel__period))
85
+ persist__metafile__build_id$._ = build_id
86
+ } catch (err) {
87
+ if (err instanceof Cancel) return
88
+ throw err
89
+ }
90
+ })
91
+ }
92
+ async function cmd(promise) {
93
+ if (cancel_()) throw new Cancel
94
+ const rv = await promise
95
+ if (cancel_()) {
96
+ promise.cancel?.()
97
+ throw new Cancel
88
98
  }
89
- })
90
- }
91
- async function cmd(promise) {
92
- if (cancel_()) throw new Cancel
93
- const rv = await promise
94
- if (cancel_()) {
95
- promise.cancel?.()
96
- throw new Cancel
99
+ return rv
97
100
  }
98
- return rv
99
- }
100
- function cancel_() {
101
- return (
102
- build_id_(ctx) !== build_id
101
+ function cancel_() {
102
+ return (
103
+ build_id_(ctx) !== build_id
103
104
  || metafile__build_id_(ctx) !== metafile__build_id
104
105
  || server__metafile_path_(ctx) !== server__metafile_path
105
106
  || browser__metafile_path_(ctx) !== browser__metafile_path
106
- )
107
- }
108
- })
107
+ )
108
+ }
109
+ }))
109
110
  export const [
110
111
  persist__metafile__ready$_,
111
112
  persist__metafile__ready_,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rebuildjs",
3
- "version": "0.34.4",
3
+ "version": "0.35.1",
4
4
  "description": "Reactive esbuild...simple hackable alternative to vite for Multi Page Apps",
5
5
  "keywords": [
6
6
  "reactive",
@@ -53,8 +53,8 @@
53
53
  "./package.json": "./package.json"
54
54
  },
55
55
  "dependencies": {
56
- "ctx-core": "^5.16.1",
57
- "elysia": "^0.8.8",
56
+ "ctx-core": "^5.17.1",
57
+ "elysia": "^0.8.9",
58
58
  "esbuild": "^0.19.11",
59
59
  "fdir": "^6.1.1",
60
60
  "picomatch": "^3.0.1"
package/server/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  be_memo_pair_,
5
5
  be_sig_triple_,
6
6
  Cancel,
7
+ memo_,
7
8
  nullish__none_,
8
9
  sleep,
9
10
  tup,
@@ -28,50 +29,52 @@ export const [
28
29
  be_lock_memosig_triple_(
29
30
  ()=>undefined,
30
31
  { ns: 'app', id: 'server__metafile' }
31
- ).add(async (ctx, server__metafile$)=>{
32
- server__metafile__waitfor_promise?.cancel?.()
33
- if (server__metafile$.lock) return
34
- nullish__none_([server__metafile_path_(ctx)],
35
- async server__metafile_path=>{
36
- try {
37
- if (await cmd(
38
- server__metafile__waitfor_promise =
39
- file_exists__waitfor(
40
- server__metafile_path,
41
- 1000,
42
- ()=>cmd(sleep(0))))
43
- ) {
44
- server__metafile$._ = await cmd(
45
- waitfor(async ()=>{
46
- const buf = await cmd(readFile(server__metafile_path))
47
- const json = buf + ''
48
- try {
49
- return JSON.parse(json)
50
- } catch {
51
- return undefined
52
- }
53
- }, 1000))
32
+ ).add((ctx, server__metafile$)=>
33
+ memo_(server__metafile__waitfor_promise$=>{
34
+ server__metafile__waitfor_promise$.val?.cancel?.()
35
+ if (server__metafile$.lock) return
36
+ return nullish__none_([server__metafile_path_(ctx)],
37
+ server__metafile_path=>{
38
+ const server__metafile__waitfor_promise =
39
+ file_exists__waitfor(
40
+ server__metafile_path,
41
+ 1000,
42
+ ()=>cmd(sleep(0)))
43
+ cmd(server__metafile__waitfor_promise)
44
+ .then(async success=>{
45
+ if (success) {
46
+ server__metafile$._ = await cmd(
47
+ waitfor(async ()=>{
48
+ const buf = await cmd(readFile(server__metafile_path))
49
+ const json = buf + ''
50
+ try {
51
+ return JSON.parse(json)
52
+ } catch {
53
+ return undefined
54
+ }
55
+ }, 1000))
56
+ }
57
+ }).catch(err=>{
58
+ if (err instanceof Cancel) return
59
+ throw err
60
+ })
61
+ return server__metafile__waitfor_promise
62
+ async function cmd(promise) {
63
+ if (cancel_()) throw new Cancel()
64
+ const rv = await promise
65
+ if (cancel_()) {
66
+ promise.cancel?.()
67
+ throw new Cancel()
68
+ }
69
+ return rv
54
70
  }
55
- } catch (err) {
56
- if (err instanceof Cancel) return
57
- throw err
58
- }
59
- async function cmd(promise) {
60
- if (cancel_()) throw new Cancel()
61
- const rv = await promise
62
- if (cancel_()) {
63
- promise.cancel?.()
64
- throw new Cancel()
71
+ function cancel_() {
72
+ return (
73
+ server__metafile$.lock
74
+ || server__metafile_path !== server__metafile_path_(ctx))
65
75
  }
66
- return rv
67
- }
68
- function cancel_() {
69
- return (
70
- server__metafile$.lock
71
- || server__metafile_path !== server__metafile_path_(ctx))
72
- }
73
- })
74
- })
76
+ })
77
+ }))
75
78
  export function server__metafile__persist() {
76
79
  return nullish__none_([
77
80
  server__metafile_path_(app_ctx),