rebuildjs 0.27.0 → 0.27.2
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 +46 -14
- package/browser/index.test.ts +9 -7
- package/build/index.js +63 -22
- package/build/index.test.ts +66 -5
- package/package.json +2 -2
- package/server/index.js +48 -18
- package/server/index.test.ts +18 -9
package/browser/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { nullish__none_, waitfor } from 'ctx-core/function'
|
|
1
|
+
import { file_exists__waitfor } from 'ctx-core/fs'
|
|
2
|
+
import { Cancel, nullish__none_, sleep, waitfor } from 'ctx-core/function'
|
|
3
3
|
import { be_lock_memosig_triple_, be_memo_pair_ } from 'ctx-core/rmemo'
|
|
4
4
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
5
5
|
import { join, relative } from 'path'
|
|
@@ -18,20 +18,52 @@ 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_(
|
|
21
|
+
be_lock_memosig_triple_(
|
|
22
|
+
()=>undefined,
|
|
22
23
|
async (ctx, browser__metafile$)=>{
|
|
23
24
|
browser__metafile__waitfor_promise?.cancel?.()
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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))
|
|
46
|
+
}
|
|
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()
|
|
57
|
+
}
|
|
58
|
+
return rv
|
|
59
|
+
}
|
|
60
|
+
function cancel_() {
|
|
61
|
+
return (
|
|
62
|
+
browser__metafile$.lock
|
|
63
|
+
|| browser__metafile_path !== browser__metafile_path_(ctx)
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
})
|
|
35
67
|
}, { ns: 'app', id: 'browser__metafile' })
|
|
36
68
|
export function browser__metafile__persist() {
|
|
37
69
|
return nullish__none_([
|
package/browser/index.test.ts
CHANGED
|
@@ -48,7 +48,7 @@ test('browser__metafile_path', ()=>{
|
|
|
48
48
|
throws(()=>browser__metafile_path_(ctx_()))
|
|
49
49
|
})
|
|
50
50
|
test('browser__metafile', async ()=>{
|
|
51
|
-
let
|
|
51
|
+
let file_exists__waitfor__path:string|undefined = undefined
|
|
52
52
|
let readFile_path:string|undefined = undefined
|
|
53
53
|
let _browser__metafile$_:typeof browser__metafile$_
|
|
54
54
|
let _browser__metafile_:typeof browser__metafile_
|
|
@@ -62,14 +62,15 @@ test('browser__metafile', async ()=>{
|
|
|
62
62
|
browser__metafile__set: _browser__metafile__set,
|
|
63
63
|
} = await esmock.p('./index.js', import.meta.url, {}, {
|
|
64
64
|
'ctx-core/rmemo': rmemo,
|
|
65
|
+
// TODO: remove with https://github.com/iambumblehead/esmock/issues/281
|
|
65
66
|
'ctx-core/fs': {
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
file_exists__waitfor: async (path:string)=>{
|
|
68
|
+
file_exists__waitfor__path = path
|
|
68
69
|
return true
|
|
69
70
|
}
|
|
70
71
|
},
|
|
71
72
|
'node:fs/promises': {
|
|
72
|
-
// TODO:
|
|
73
|
+
// TODO: https://github.com/iambumblehead/esmock/issues/281
|
|
73
74
|
// access: async ()=>{},
|
|
74
75
|
readFile: async (path:string)=>{
|
|
75
76
|
readFile_path = path
|
|
@@ -79,6 +80,7 @@ test('browser__metafile', async ()=>{
|
|
|
79
80
|
case '/cwd/dist1/browser/metafile.json':
|
|
80
81
|
return Buffer.from(JSON.stringify(browser__metafile1), 'utf-8')
|
|
81
82
|
}
|
|
83
|
+
return undefined
|
|
82
84
|
}
|
|
83
85
|
},
|
|
84
86
|
}))
|
|
@@ -91,7 +93,7 @@ test('browser__metafile', async ()=>{
|
|
|
91
93
|
100)
|
|
92
94
|
equal(_browser__metafile$_(app_ctx)._, browser__metafile0)
|
|
93
95
|
equal(_browser__metafile_(app_ctx), browser__metafile0)
|
|
94
|
-
equal(
|
|
96
|
+
equal(file_exists__waitfor__path, '/cwd/dist0/browser/metafile.json')
|
|
95
97
|
equal(readFile_path, '/cwd/dist0/browser/metafile.json')
|
|
96
98
|
equal(_browser__metafile$_(app_ctx)._, browser__metafile0)
|
|
97
99
|
equal(_browser__metafile_(app_ctx), browser__metafile0)
|
|
@@ -102,7 +104,7 @@ test('browser__metafile', async ()=>{
|
|
|
102
104
|
100)
|
|
103
105
|
equal(_browser__metafile$_(app_ctx)._, browser__metafile1)
|
|
104
106
|
equal(_browser__metafile_(app_ctx), browser__metafile1)
|
|
105
|
-
equal(
|
|
107
|
+
equal(file_exists__waitfor__path, '/cwd/dist1/browser/metafile.json')
|
|
106
108
|
equal(readFile_path, '/cwd/dist1/browser/metafile.json')
|
|
107
109
|
dist_path__set(app_ctx, '/cwd/dist0')
|
|
108
110
|
await rmemo__wait(
|
|
@@ -111,7 +113,7 @@ test('browser__metafile', async ()=>{
|
|
|
111
113
|
100)
|
|
112
114
|
equal(_browser__metafile$_(app_ctx)._, browser__metafile0)
|
|
113
115
|
equal(_browser__metafile_(app_ctx), browser__metafile0)
|
|
114
|
-
equal(
|
|
116
|
+
equal(file_exists__waitfor__path, '/cwd/dist0/browser/metafile.json')
|
|
115
117
|
equal(readFile_path, '/cwd/dist0/browser/metafile.json')
|
|
116
118
|
_browser__metafile__set(app_ctx, browser__metafile2)
|
|
117
119
|
equal(_browser__metafile$_(app_ctx)._, browser__metafile2)
|
package/build/index.js
CHANGED
|
@@ -6,8 +6,8 @@ import { be, be_memo_pair_, be_sig_triple_, memo_, off, rmemo__wait } from 'ctx-
|
|
|
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, readFile, rm } from 'node:fs/promises'
|
|
10
|
-
import { join, relative, resolve } from 'path'
|
|
9
|
+
import { cp, link, mkdir, readFile, rm } from 'node:fs/promises'
|
|
10
|
+
import { basename, dirname, extname, 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_,
|
|
@@ -268,25 +268,26 @@ export function rebuildjs_plugin_() {
|
|
|
268
268
|
})
|
|
269
269
|
}
|
|
270
270
|
// Prevent GC
|
|
271
|
-
setup.
|
|
271
|
+
setup.rebuildjs_plugin__postprocess$ = rebuildjs_plugin__postprocess$_()
|
|
272
272
|
return setup
|
|
273
273
|
/**
|
|
274
274
|
*
|
|
275
275
|
* @returns {memo_T<void>}
|
|
276
276
|
* @private
|
|
277
277
|
*/
|
|
278
|
-
function
|
|
278
|
+
function rebuildjs_plugin__postprocess$_() {
|
|
279
279
|
return (
|
|
280
280
|
be(app_ctx, ctx=>
|
|
281
|
-
run(memo_(
|
|
281
|
+
run(memo_(rebuildjs__assets__link$=>{
|
|
282
282
|
r()
|
|
283
|
-
return
|
|
283
|
+
return rebuildjs__assets__link$
|
|
284
284
|
function r() {
|
|
285
285
|
if (!persist__metafile__ready_(ctx)) return
|
|
286
286
|
nullish__none_([
|
|
287
287
|
build_id_(ctx),
|
|
288
288
|
metafile__build_id_(ctx),
|
|
289
289
|
server__metafile_(ctx),
|
|
290
|
+
browser__metafile_(ctx),
|
|
290
291
|
cwd_(ctx),
|
|
291
292
|
browser_path_(ctx),
|
|
292
293
|
server__relative_path_(ctx),
|
|
@@ -294,6 +295,7 @@ export function rebuildjs_plugin_() {
|
|
|
294
295
|
build_id,
|
|
295
296
|
metafile__build_id,
|
|
296
297
|
server__metafile,
|
|
298
|
+
browser__metafile,
|
|
297
299
|
cwd,
|
|
298
300
|
browser_path,
|
|
299
301
|
server__relative_path,
|
|
@@ -301,20 +303,8 @@ export function rebuildjs_plugin_() {
|
|
|
301
303
|
if (build_id === metafile__build_id) {
|
|
302
304
|
run(async ()=>{
|
|
303
305
|
try {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if (/(\.js|\.mjs)(\.map)?$/.test(output__relative_path)) continue
|
|
307
|
-
const server_asset_path = join(cwd, output__relative_path)
|
|
308
|
-
const browser_asset_path = join(
|
|
309
|
-
browser_path,
|
|
310
|
-
relative(server__relative_path, output__relative_path))
|
|
311
|
-
await cmd(
|
|
312
|
-
rm(browser_asset_path, { force: true }))
|
|
313
|
-
await cmd(
|
|
314
|
-
file_exists__waitfor(server_asset_path))
|
|
315
|
-
await cmd(
|
|
316
|
-
link(server_asset_path, browser_asset_path))
|
|
317
|
-
}
|
|
306
|
+
await esbuild_cssBundle__cp()
|
|
307
|
+
await rebuildjs__assets__link()
|
|
318
308
|
} catch (err) {
|
|
319
309
|
if (err instanceof Cancel) return
|
|
320
310
|
throw err
|
|
@@ -322,6 +312,51 @@ export function rebuildjs_plugin_() {
|
|
|
322
312
|
rebuildjs__build_id__set(ctx, build_id)
|
|
323
313
|
})
|
|
324
314
|
}
|
|
315
|
+
async function esbuild_cssBundle__cp() {
|
|
316
|
+
for (const metafile of [server__metafile, browser__metafile]) {
|
|
317
|
+
for (let output__relative_path in metafile.outputs) {
|
|
318
|
+
let cssBundle, esbuild_cssBundle
|
|
319
|
+
switch (extname(output__relative_path)) {
|
|
320
|
+
case '.js':
|
|
321
|
+
case '.mjs':
|
|
322
|
+
({ cssBundle, esbuild_cssBundle } = metafile.outputs[output__relative_path])
|
|
323
|
+
if (cssBundle && esbuild_cssBundle) {
|
|
324
|
+
const cssBundle_path = join(cwd_(ctx), cssBundle)
|
|
325
|
+
const esbuild_cssBundle_path = join(cwd_(ctx), esbuild_cssBundle)
|
|
326
|
+
await cmd(
|
|
327
|
+
file_exists__waitfor(cssBundle_path))
|
|
328
|
+
await cmd(
|
|
329
|
+
cp(cssBundle_path, esbuild_cssBundle_path))
|
|
330
|
+
await cmd(
|
|
331
|
+
file_exists__waitfor(cssBundle_path + '.map'))
|
|
332
|
+
await cmd(
|
|
333
|
+
cp(cssBundle_path + '.map', esbuild_cssBundle_path + '.map'))
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
async function rebuildjs__assets__link() {
|
|
340
|
+
const outputs= server__metafile.outputs ?? {}
|
|
341
|
+
for (let output__relative_path in outputs) {
|
|
342
|
+
switch (extname(output__relative_path)) {
|
|
343
|
+
case '.js':
|
|
344
|
+
case '.mjs':
|
|
345
|
+
case '.map':
|
|
346
|
+
continue
|
|
347
|
+
}
|
|
348
|
+
const server_asset_path = join(cwd, output__relative_path)
|
|
349
|
+
const browser_asset_path = join(
|
|
350
|
+
browser_path,
|
|
351
|
+
relative(server__relative_path, output__relative_path))
|
|
352
|
+
await cmd(
|
|
353
|
+
rm(browser_asset_path, { force: true }))
|
|
354
|
+
await cmd(
|
|
355
|
+
file_exists__waitfor(server_asset_path))
|
|
356
|
+
await cmd(
|
|
357
|
+
link(server_asset_path, browser_asset_path))
|
|
358
|
+
}
|
|
359
|
+
}
|
|
325
360
|
async function cmd(promise) {
|
|
326
361
|
if (cancel_()) throw new Cancel()
|
|
327
362
|
promise.rebuildjs_cancel$ = run(memo_(rebuildjs_cancel$=>{
|
|
@@ -340,6 +375,7 @@ export function rebuildjs_plugin_() {
|
|
|
340
375
|
build_id_(ctx) !== build_id
|
|
341
376
|
|| metafile__build_id_(ctx) !== metafile__build_id
|
|
342
377
|
|| server__metafile_(ctx) !== server__metafile
|
|
378
|
+
|| browser__metafile_(ctx) !== browser__metafile
|
|
343
379
|
|| cwd_(ctx) !== cwd
|
|
344
380
|
|| browser_path_(ctx) !== browser_path
|
|
345
381
|
|| server__relative_path_(ctx) !== server__relative_path
|
|
@@ -368,7 +404,7 @@ async function server__metafile__update(server__metafile, build_id) {
|
|
|
368
404
|
const output = server__metafile.outputs[server__output__relative_path]
|
|
369
405
|
const { cssBundle } = output
|
|
370
406
|
if (cssBundle) {
|
|
371
|
-
output.esbuild_cssBundle = cssBundle
|
|
407
|
+
output.esbuild_cssBundle = esbuild_cssBundle_(cssBundle)
|
|
372
408
|
output.cssBundle_content = [
|
|
373
409
|
server__output__relative_path,
|
|
374
410
|
...(
|
|
@@ -394,10 +430,15 @@ async function browser__metafile__update(browser__metafile, build_id) {
|
|
|
394
430
|
const output = browser__metafile.outputs[browser__output__relative_path]
|
|
395
431
|
const { cssBundle } = output
|
|
396
432
|
if (cssBundle) {
|
|
397
|
-
output.esbuild_cssBundle = cssBundle
|
|
433
|
+
output.esbuild_cssBundle = esbuild_cssBundle_(cssBundle)
|
|
398
434
|
output.cssBundle_content = [browser__output__relative_path]
|
|
399
435
|
}
|
|
400
436
|
}
|
|
401
437
|
}
|
|
402
438
|
await browser__metafile__persist()
|
|
403
439
|
}
|
|
440
|
+
function esbuild_cssBundle_(cssBundle) {
|
|
441
|
+
return join(
|
|
442
|
+
dirname(cssBundle),
|
|
443
|
+
basename(cssBundle, '.css') + '_esbuild.css')
|
|
444
|
+
}
|
package/build/index.test.ts
CHANGED
|
@@ -2,12 +2,13 @@ import { ctx_ } from 'ctx-core/be'
|
|
|
2
2
|
import { file_exists_ } from 'ctx-core/fs'
|
|
3
3
|
import { sleep } from 'ctx-core/function'
|
|
4
4
|
import { BuildContext } from 'esbuild'
|
|
5
|
+
import { readFile } from 'fs/promises'
|
|
5
6
|
import { rm } from 'node:fs/promises'
|
|
6
|
-
import { dirname, join } from 'path'
|
|
7
|
+
import { basename, dirname, join } from 'path'
|
|
7
8
|
import { test } from 'uvu'
|
|
8
9
|
import { equal, throws } from 'uvu/assert'
|
|
9
10
|
import { browser__metafile0, browser__metafile1, server__metafile0, server__metafile1 } from '../_fixtures/metafiles.js'
|
|
10
|
-
import { cwd__set } from '../app/index.js'
|
|
11
|
+
import { cwd_, cwd__set } from '../app/index.js'
|
|
11
12
|
import { browser__metafile_, browser__metafile__set } from '../browser/index.js'
|
|
12
13
|
import { app_ctx } from '../ctx/index.js'
|
|
13
14
|
import { server__metafile_, server__metafile__set } from '../server/index.js'
|
|
@@ -130,6 +131,7 @@ test('browser__build|server__build|rebuildjs_plugin_|metafile', async ()=>{
|
|
|
130
131
|
equal(await file_exists_(join(cwd, 'dist')), true)
|
|
131
132
|
equal(await file_exists_(join(cwd, 'dist', 'browser--dev')), true)
|
|
132
133
|
equal(await file_exists_(join(cwd, 'dist', 'server--dev')), true)
|
|
134
|
+
await rebuildjs__ready__wait()
|
|
133
135
|
const server__metafile = server__metafile_(app_ctx)!
|
|
134
136
|
equal(server__metafile.rebuildjs_target, 'server')
|
|
135
137
|
const browser__metafile = browser__metafile_(app_ctx)!
|
|
@@ -145,7 +147,10 @@ test('browser__build|server__build|rebuildjs_plugin_|metafile', async ()=>{
|
|
|
145
147
|
server__metafile.outputs[server__output__relative_path]
|
|
146
148
|
equal(server__entryPoint__output != null, true)
|
|
147
149
|
equal(server__entryPoint__output.cssBundle != null, true)
|
|
148
|
-
equal(server__entryPoint__output.esbuild_cssBundle,
|
|
150
|
+
equal(server__entryPoint__output.esbuild_cssBundle,
|
|
151
|
+
join(
|
|
152
|
+
dirname(server__entryPoint__output.cssBundle!),
|
|
153
|
+
basename(server__entryPoint__output.cssBundle!, '.css') + '_esbuild.css'))
|
|
149
154
|
const browser__output__relative_path =
|
|
150
155
|
Object.keys(browser__metafile.outputs)
|
|
151
156
|
.find(browser__output__relative_path=>
|
|
@@ -155,7 +160,10 @@ test('browser__build|server__build|rebuildjs_plugin_|metafile', async ()=>{
|
|
|
155
160
|
browser__metafile.outputs[browser__output__relative_path]
|
|
156
161
|
equal(browser__entryPoint__output != null, true)
|
|
157
162
|
equal(browser__entryPoint__output.cssBundle != null, true)
|
|
158
|
-
equal(browser__entryPoint__output.esbuild_cssBundle,
|
|
163
|
+
equal(browser__entryPoint__output.esbuild_cssBundle,
|
|
164
|
+
join(
|
|
165
|
+
dirname(browser__entryPoint__output.cssBundle!),
|
|
166
|
+
basename(browser__entryPoint__output.cssBundle!, '.css') + '_esbuild.css'))
|
|
159
167
|
equal(server__entryPoint__output.cssBundle_content, [
|
|
160
168
|
server__output__relative_path,
|
|
161
169
|
browser__output__relative_path
|
|
@@ -164,7 +172,60 @@ test('browser__build|server__build|rebuildjs_plugin_|metafile', async ()=>{
|
|
|
164
172
|
browser__output__relative_path
|
|
165
173
|
])
|
|
166
174
|
} finally {
|
|
167
|
-
await
|
|
175
|
+
await rebuildjs__ready__wait()
|
|
176
|
+
server__build_context?.dispose?.()
|
|
177
|
+
browser__build_context?.dispose?.()
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
test('browser__build|server__build|rebuildjs_plugin_|css', async ()=>{
|
|
181
|
+
const test_dir = dirname(new URL(import.meta.url).pathname)
|
|
182
|
+
const cwd = join(test_dir, '../_fixtures')
|
|
183
|
+
cwd__set(app_ctx, cwd)
|
|
184
|
+
await rm(join(cwd, 'dist'), { recursive: true, force: true })
|
|
185
|
+
let server__build_context:BuildContext|undefined = undefined
|
|
186
|
+
let browser__build_context:BuildContext|undefined = undefined
|
|
187
|
+
try {
|
|
188
|
+
server__build_context = await server__build()
|
|
189
|
+
browser__build_context = await browser__build()
|
|
190
|
+
await rebuildjs__ready__wait()
|
|
191
|
+
const server__metafile = server__metafile_(app_ctx)!
|
|
192
|
+
const server__output__relative_path =
|
|
193
|
+
Object.keys(server__metafile.outputs)
|
|
194
|
+
.find(server__output__relative_path=>
|
|
195
|
+
server__metafile.outputs[server__output__relative_path].entryPoint)!
|
|
196
|
+
const server__entryPoint__output =
|
|
197
|
+
server__metafile.outputs[server__output__relative_path]
|
|
198
|
+
const browser__metafile = browser__metafile_(app_ctx)!
|
|
199
|
+
const browser__output__relative_path =
|
|
200
|
+
Object.keys(browser__metafile.outputs)
|
|
201
|
+
.find(browser__output__relative_path=>
|
|
202
|
+
browser__metafile.outputs[browser__output__relative_path].entryPoint)!
|
|
203
|
+
const browser__entryPoint__output =
|
|
204
|
+
browser__metafile.outputs[browser__output__relative_path]
|
|
205
|
+
equal(typeof server__entryPoint__output.cssBundle, 'string')
|
|
206
|
+
equal(typeof browser__entryPoint__output.cssBundle, 'string')
|
|
207
|
+
equal(typeof server__entryPoint__output.esbuild_cssBundle, 'string')
|
|
208
|
+
equal(typeof browser__entryPoint__output.esbuild_cssBundle, 'string')
|
|
209
|
+
equal(server__entryPoint__output.cssBundle !== server__entryPoint__output.esbuild_cssBundle, true)
|
|
210
|
+
equal(browser__entryPoint__output.cssBundle !== browser__entryPoint__output.esbuild_cssBundle, true)
|
|
211
|
+
equal(
|
|
212
|
+
await readFile(join(cwd_(app_ctx), server__entryPoint__output.cssBundle + '.map')).then(buf=>buf + '')
|
|
213
|
+
=== await readFile(join(cwd_(app_ctx), server__entryPoint__output.esbuild_cssBundle + '.map')).then(buf=>buf + ''),
|
|
214
|
+
true)
|
|
215
|
+
equal(
|
|
216
|
+
await readFile(join(cwd_(app_ctx), browser__entryPoint__output.cssBundle + '.map')).then(buf=>buf + '')
|
|
217
|
+
=== await readFile(join(cwd_(app_ctx), browser__entryPoint__output.esbuild_cssBundle + '.map')).then(buf=>buf + ''),
|
|
218
|
+
true)
|
|
219
|
+
equal(
|
|
220
|
+
await readFile(join(cwd_(app_ctx), server__entryPoint__output.cssBundle + '.map')).then(buf=>buf + '')
|
|
221
|
+
=== await readFile(join(cwd_(app_ctx), server__entryPoint__output.esbuild_cssBundle + '.map')).then(buf=>buf + ''),
|
|
222
|
+
true)
|
|
223
|
+
equal(
|
|
224
|
+
await readFile(join(cwd_(app_ctx), browser__entryPoint__output.cssBundle + '.map')).then(buf=>buf + '')
|
|
225
|
+
=== await readFile(join(cwd_(app_ctx), browser__entryPoint__output.esbuild_cssBundle + '.map')).then(buf=>buf + ''),
|
|
226
|
+
true)
|
|
227
|
+
} finally {
|
|
228
|
+
await rebuildjs__ready__wait()
|
|
168
229
|
server__build_context?.dispose?.()
|
|
169
230
|
browser__build_context?.dispose?.()
|
|
170
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rebuildjs",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.2",
|
|
4
4
|
"description": "Reactive esbuild...simple hackable alternative to vite for Multi Page Apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"reactive",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"ctx-core": "^5.9.0",
|
|
57
|
-
"elysia": "^0.8.
|
|
57
|
+
"elysia": "^0.8.8",
|
|
58
58
|
"esbuild": "^0.19.11",
|
|
59
59
|
"fdir": "^6.1.1",
|
|
60
60
|
"picomatch": "^3.0.1"
|
package/server/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { nullish__none_, tup, waitfor } from 'ctx-core/function'
|
|
1
|
+
import { file_exists__waitfor } from 'ctx-core/fs'
|
|
2
|
+
import { Cancel, nullish__none_, sleep, tup, waitfor } from 'ctx-core/function'
|
|
3
3
|
import { be_lock_memosig_triple_, be_memo_pair_, be_sig_triple_ } from 'ctx-core/rmemo'
|
|
4
4
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
5
5
|
import { join, relative } from 'path'
|
|
@@ -17,22 +17,52 @@ export const [
|
|
|
17
17
|
server__metafile_,
|
|
18
18
|
server__metafile__set
|
|
19
19
|
] = /** @type {be_lock_memosig_triple_T<rebuildjs_metafile_T>} */
|
|
20
|
-
be_lock_memosig_triple_(
|
|
21
|
-
undefined,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
20
|
+
be_lock_memosig_triple_(
|
|
21
|
+
()=>undefined,
|
|
22
|
+
async (ctx, server__metafile$)=>{
|
|
23
|
+
server__metafile__waitfor_promise?.cancel?.()
|
|
24
|
+
if (server__metafile$.lock) return
|
|
25
|
+
nullish__none_([server__metafile_path_(ctx)],
|
|
26
|
+
async server__metafile_path=>{
|
|
27
|
+
try {
|
|
28
|
+
if (await cmd(
|
|
29
|
+
server__metafile__waitfor_promise =
|
|
30
|
+
file_exists__waitfor(
|
|
31
|
+
server__metafile_path,
|
|
32
|
+
1000,
|
|
33
|
+
()=>cmd(sleep(0))))
|
|
34
|
+
) {
|
|
35
|
+
server__metafile$._ = await cmd(
|
|
36
|
+
waitfor(async ()=>{
|
|
37
|
+
const buf = await cmd(readFile(server__metafile_path))
|
|
38
|
+
const json = buf + ''
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(json)
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
}, 1000))
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (err instanceof Cancel) return
|
|
48
|
+
throw err
|
|
49
|
+
}
|
|
50
|
+
async function cmd(promise) {
|
|
51
|
+
if (cancel_()) throw new Cancel()
|
|
52
|
+
const rv = await promise
|
|
53
|
+
if (cancel_()) {
|
|
54
|
+
promise.cancel?.()
|
|
55
|
+
throw new Cancel()
|
|
56
|
+
}
|
|
57
|
+
return rv
|
|
58
|
+
}
|
|
59
|
+
function cancel_() {
|
|
60
|
+
return (
|
|
61
|
+
server__metafile$.lock
|
|
62
|
+
|| server__metafile_path !== server__metafile_path_(ctx))
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
}, { ns: 'app', id: 'server__metafile' })
|
|
36
66
|
export function server__metafile__persist() {
|
|
37
67
|
return nullish__none_([
|
|
38
68
|
server__metafile_path_(app_ctx),
|
package/server/index.test.ts
CHANGED
|
@@ -51,13 +51,11 @@ test('server__metafile_path', ()=>{
|
|
|
51
51
|
throws(()=>server__metafile_path_(ctx_()))
|
|
52
52
|
})
|
|
53
53
|
test('server__metafile', async ()=>{
|
|
54
|
-
let
|
|
54
|
+
let file_exists__waitfor__path:string|undefined = undefined
|
|
55
55
|
let readFile_path:string|undefined = undefined
|
|
56
56
|
let _server__metafile$_:typeof server__metafile$_
|
|
57
57
|
let _server__metafile_:typeof server__metafile_
|
|
58
58
|
let _server__metafile__set:typeof server__metafile__set
|
|
59
|
-
is_prod__set(app_ctx, true)
|
|
60
|
-
dist_path__set(app_ctx, '/cwd/dist0')
|
|
61
59
|
{
|
|
62
60
|
({
|
|
63
61
|
server__metafile$_: _server__metafile$_,
|
|
@@ -65,13 +63,16 @@ test('server__metafile', async ()=>{
|
|
|
65
63
|
server__metafile__set: _server__metafile__set,
|
|
66
64
|
} = await esmock('./index.js', {}, {
|
|
67
65
|
'ctx-core/rmemo': rmemo,
|
|
66
|
+
// TODO: remove with https://github.com/iambumblehead/esmock/issues/281
|
|
68
67
|
'ctx-core/fs': {
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
file_exists__waitfor: async (path:string)=>{
|
|
69
|
+
file_exists__waitfor__path = path
|
|
71
70
|
return true
|
|
72
71
|
}
|
|
73
72
|
},
|
|
74
73
|
'node:fs/promises': {
|
|
74
|
+
// TODO: https://github.com/iambumblehead/esmock/issues/281
|
|
75
|
+
// access: async ()=>{},
|
|
75
76
|
readFile: async (path:string)=>{
|
|
76
77
|
readFile_path = path
|
|
77
78
|
switch (path) {
|
|
@@ -80,16 +81,24 @@ test('server__metafile', async ()=>{
|
|
|
80
81
|
case '/cwd/dist1/server/metafile.json':
|
|
81
82
|
return Buffer.from(JSON.stringify(server__metafile1), 'utf-8')
|
|
82
83
|
}
|
|
84
|
+
return undefined
|
|
83
85
|
}
|
|
84
86
|
}
|
|
85
87
|
}))
|
|
86
88
|
}
|
|
87
89
|
equal(_server__metafile$_(app_ctx)._, undefined)
|
|
88
90
|
equal(_server__metafile_(app_ctx), undefined)
|
|
89
|
-
|
|
91
|
+
is_prod__set(app_ctx, true)
|
|
92
|
+
dist_path__set(app_ctx, '/cwd/dist0')
|
|
93
|
+
equal(_server__metafile$_(app_ctx)._, undefined)
|
|
94
|
+
equal(_server__metafile_(app_ctx), undefined)
|
|
95
|
+
await rmemo__wait(
|
|
96
|
+
_server__metafile$_(app_ctx),
|
|
97
|
+
m=>m,
|
|
98
|
+
100)
|
|
90
99
|
equal(_server__metafile$_(app_ctx)._, server__metafile0)
|
|
91
100
|
equal(_server__metafile_(app_ctx), server__metafile0)
|
|
92
|
-
equal(
|
|
101
|
+
equal(file_exists__waitfor__path, '/cwd/dist0/server/metafile.json')
|
|
93
102
|
equal(readFile_path, '/cwd/dist0/server/metafile.json')
|
|
94
103
|
equal(_server__metafile$_(app_ctx)._, server__metafile0)
|
|
95
104
|
equal(_server__metafile_(app_ctx), server__metafile0)
|
|
@@ -97,13 +106,13 @@ test('server__metafile', async ()=>{
|
|
|
97
106
|
await rmemo__wait(_server__metafile$_(app_ctx), m=>deep_equal(m, server__metafile1), 100)
|
|
98
107
|
equal(_server__metafile$_(app_ctx)._, server__metafile1)
|
|
99
108
|
equal(_server__metafile_(app_ctx), server__metafile1)
|
|
100
|
-
equal(
|
|
109
|
+
equal(file_exists__waitfor__path, '/cwd/dist1/server/metafile.json')
|
|
101
110
|
equal(readFile_path, '/cwd/dist1/server/metafile.json')
|
|
102
111
|
dist_path__set(app_ctx, '/cwd/dist0')
|
|
103
112
|
await rmemo__wait(_server__metafile$_(app_ctx), m=>deep_equal(m, server__metafile0), 100)
|
|
104
113
|
equal(_server__metafile$_(app_ctx)._, server__metafile0)
|
|
105
114
|
equal(_server__metafile_(app_ctx), server__metafile0)
|
|
106
|
-
equal(
|
|
115
|
+
equal(file_exists__waitfor__path, '/cwd/dist0/server/metafile.json')
|
|
107
116
|
equal(readFile_path, '/cwd/dist0/server/metafile.json')
|
|
108
117
|
_server__metafile__set(app_ctx, server__metafile2)
|
|
109
118
|
equal(_server__metafile$_(app_ctx)._, server__metafile2)
|