rebuildjs 0.17.0 → 0.18.3
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/app/index.d.ts +37 -62
- package/app/index.js +25 -22
- package/app/index.test.ts +316 -4
- package/asset/index.d.ts +11 -2
- package/asset/index.js +17 -1
- package/asset/index.test.ts +51 -8
- package/browser/index.d.ts +11 -18
- package/browser/index.js +8 -11
- package/browser/index.test.ts +164 -5
- package/build/index.test.ts +4 -0
- package/css/index.test.ts +30 -3
- package/ctx/index.d.ts +9 -10
- package/ctx/index.js +5 -30
- package/ctx/index.test.ts +22 -4
- package/metafile/index.d.ts +1 -1
- package/metafile/index.js +11 -17
- package/metafile/index.test.ts +33 -3
- package/middleware/index.test.ts +14 -3
- package/package.json +7 -5
- package/server/index.d.ts +18 -27
- package/server/index.js +16 -11
- package/server/index.test.ts +261 -4
package/app/index.d.ts
CHANGED
|
@@ -1,62 +1,37 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export const
|
|
37
|
-
|
|
38
|
-
app_path_,
|
|
39
|
-
app_path__set,
|
|
40
|
-
]:be_lock_memosig_triple_T<string>
|
|
41
|
-
export const [
|
|
42
|
-
app__relative_path$_,
|
|
43
|
-
app__relative_path_,
|
|
44
|
-
]:be_memo_pair_T<string>
|
|
45
|
-
export const [
|
|
46
|
-
browser__relative_path$_,
|
|
47
|
-
browser__relative_path_,
|
|
48
|
-
]:be_memo_pair_T<string>
|
|
49
|
-
export const [
|
|
50
|
-
browser_path$_,
|
|
51
|
-
browser_path_,
|
|
52
|
-
browser_path__set,
|
|
53
|
-
]:be_lock_memosig_triple_T<string>
|
|
54
|
-
export const [
|
|
55
|
-
server__relative_path$_,
|
|
56
|
-
server__relative_path_,
|
|
57
|
-
]:be_memo_pair_T<string>
|
|
58
|
-
export const [
|
|
59
|
-
server_path$_,
|
|
60
|
-
server_path_,
|
|
61
|
-
server_path__set,
|
|
62
|
-
]:be_lock_memosig_triple_T<string>
|
|
1
|
+
import type { ctx__be_T, ctx__get_T, ctx__set_T, lock_memosig_T, memo_T, sig_T } from 'ctx-core/rmemo'
|
|
2
|
+
import { has_app_T } from '../ctx/index.js'
|
|
3
|
+
export declare const port$_:ctx__be_T<has_app_T, sig_T<number>, 'app'>
|
|
4
|
+
export declare const port_:ctx__get_T<has_app_T, number>
|
|
5
|
+
export declare const port__set:ctx__set_T<has_app_T, number>
|
|
6
|
+
export declare const cwd$_:ctx__be_T<has_app_T, sig_T<string>, 'app'>
|
|
7
|
+
export declare const cwd_:ctx__get_T<has_app_T, string>
|
|
8
|
+
export declare const cwd__set:ctx__set_T<has_app_T, string>
|
|
9
|
+
export declare const is_prod$_:ctx__be_T<has_app_T, lock_memosig_T<boolean>, 'app'>
|
|
10
|
+
export declare const is_prod_:ctx__get_T<has_app_T, boolean>
|
|
11
|
+
export declare const is_prod__set:ctx__set_T<has_app_T, boolean>
|
|
12
|
+
export declare const public_path$_:ctx__be_T<has_app_T, lock_memosig_T<string>, 'app'>
|
|
13
|
+
export declare const public_path_:ctx__get_T<has_app_T, string>
|
|
14
|
+
export declare const public_path__set:ctx__set_T<has_app_T, string>
|
|
15
|
+
export declare const dist_path$_:ctx__be_T<has_app_T, lock_memosig_T<string>, 'app'>
|
|
16
|
+
export declare const dist_path_:ctx__get_T<has_app_T, string>
|
|
17
|
+
export declare const dist_path__set:ctx__set_T<has_app_T, string>
|
|
18
|
+
export declare const dist__relative_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
19
|
+
export declare const dist__relative_path_:ctx__get_T<has_app_T, string>
|
|
20
|
+
export declare const src_path$_:ctx__be_T<has_app_T, lock_memosig_T<string>, 'app'>
|
|
21
|
+
export declare const src_path_:ctx__get_T<has_app_T, string>
|
|
22
|
+
export declare const src_path__set:ctx__set_T<has_app_T, string>
|
|
23
|
+
export declare const src__relative_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
24
|
+
export declare const src__relative_path_:ctx__get_T<has_app_T, string>
|
|
25
|
+
export declare const app_path$_:ctx__be_T<has_app_T, lock_memosig_T<string>, 'app'>
|
|
26
|
+
export declare const app_path_:ctx__get_T<has_app_T, string>
|
|
27
|
+
export declare const app_path__set:ctx__set_T<has_app_T, string>
|
|
28
|
+
export declare const app__relative_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
29
|
+
export declare const app__relative_path_:ctx__get_T<has_app_T, string>
|
|
30
|
+
export declare const browser__relative_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
31
|
+
export declare const browser__relative_path_:ctx__get_T<has_app_T, string>
|
|
32
|
+
export declare const browser_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
33
|
+
export declare const browser_path_:ctx__get_T<has_app_T, string>
|
|
34
|
+
export declare const server__relative_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
35
|
+
export declare const server__relative_path_:ctx__get_T<has_app_T, string>
|
|
36
|
+
export declare const server_path$_:ctx__be_T<has_app_T, memo_T<string>, 'app'>
|
|
37
|
+
export declare const server_path_:ctx__get_T<has_app_T, string>
|
package/app/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { be_lock_memosig_triple_, be_memo_pair_,
|
|
1
|
+
import { be_lock_memosig_triple_, be_memo_pair_, be_sig_triple_ } from 'ctx-core/rmemo'
|
|
2
2
|
import { join, relative, resolve } from 'path'
|
|
3
|
-
import { app_ctx__be_config } from '../ctx/index.js'
|
|
4
3
|
export const [
|
|
5
4
|
port$_,
|
|
6
5
|
port_,
|
|
@@ -9,84 +8,88 @@ export const [
|
|
|
9
8
|
process.env.PORT
|
|
10
9
|
? parseInt(process.env.PORT)
|
|
11
10
|
: 3000,
|
|
12
|
-
{
|
|
11
|
+
{ ns: 'app', id: 'port' })
|
|
13
12
|
export const [
|
|
14
13
|
cwd$_,
|
|
15
14
|
cwd_,
|
|
16
15
|
cwd__set,
|
|
17
16
|
] = be_sig_triple_(()=>
|
|
18
17
|
resolve('.'),
|
|
19
|
-
{
|
|
18
|
+
{ ns: 'app', id: 'cwd' })
|
|
20
19
|
export const [
|
|
21
20
|
is_prod$_,
|
|
22
21
|
is_prod_,
|
|
23
22
|
is_prod__set,
|
|
24
23
|
] = be_lock_memosig_triple_(()=>
|
|
25
24
|
process.env.NODE_ENV === 'production',
|
|
26
|
-
{
|
|
25
|
+
{ ns: 'app', id: 'is_prod' })
|
|
27
26
|
export const [
|
|
28
27
|
public_path$_,
|
|
29
28
|
public_path_,
|
|
30
29
|
public_path__set,
|
|
31
30
|
] = be_lock_memosig_triple_(ctx=>
|
|
32
31
|
join(cwd_(ctx), 'public'),
|
|
33
|
-
{
|
|
32
|
+
{ ns: 'app', id: 'public_path' })
|
|
34
33
|
export const [
|
|
35
34
|
dist_path$_,
|
|
36
35
|
dist_path_,
|
|
37
36
|
dist_path__set,
|
|
38
|
-
] =
|
|
37
|
+
] = be_lock_memosig_triple_(ctx=>
|
|
39
38
|
join(cwd_(ctx), 'dist'),
|
|
40
|
-
{
|
|
39
|
+
{ ns: 'app', id: 'dist_path' })
|
|
40
|
+
export const [
|
|
41
|
+
dist__relative_path$_,
|
|
42
|
+
dist__relative_path_,
|
|
43
|
+
] = be_memo_pair_(ctx=>
|
|
44
|
+
relative(cwd_(ctx), dist_path_(ctx)),
|
|
45
|
+
{ ns: 'app', id: 'dist__relative_path' })
|
|
41
46
|
export const [
|
|
42
47
|
src_path$_,
|
|
43
48
|
src_path_,
|
|
44
49
|
src_path__set,
|
|
45
50
|
] = be_lock_memosig_triple_(ctx=>
|
|
46
51
|
join(cwd_(ctx), 'src'),
|
|
47
|
-
{
|
|
52
|
+
{ ns: 'app', id: 'src_path' })
|
|
48
53
|
export const [
|
|
49
54
|
src__relative_path$_,
|
|
50
55
|
src__relative_path_,
|
|
51
56
|
] = be_memo_pair_(ctx=>
|
|
52
57
|
relative(cwd_(ctx), src_path_(ctx)),
|
|
53
|
-
{
|
|
58
|
+
{ ns: 'app', id: 'src__relative_path' })
|
|
54
59
|
export const [
|
|
55
60
|
app_path$_,
|
|
56
61
|
app_path_,
|
|
57
62
|
app_path__set,
|
|
58
63
|
] = be_lock_memosig_triple_(ctx=>
|
|
59
64
|
join(src_path_(ctx), 'app'),
|
|
60
|
-
{
|
|
65
|
+
{ ns: 'app', id: 'app_path' })
|
|
61
66
|
export const [
|
|
62
67
|
app__relative_path$_,
|
|
63
68
|
app__relative_path_,
|
|
64
69
|
] = be_memo_pair_(ctx=>
|
|
65
70
|
relative(cwd_(ctx), app_path_(ctx)),
|
|
66
|
-
{
|
|
71
|
+
{ ns: 'app', id: 'app__relative_path' })
|
|
67
72
|
export const [
|
|
68
73
|
browser__relative_path$_,
|
|
69
74
|
browser__relative_path_,
|
|
70
75
|
] = be_memo_pair_(ctx=>
|
|
71
|
-
join(
|
|
72
|
-
{
|
|
76
|
+
join(dist__relative_path_(ctx), is_prod_(ctx) ? 'browser' : 'browser--dev'),
|
|
77
|
+
{ ns: 'app', is: 'browser_relative_path' })
|
|
73
78
|
export const [
|
|
74
79
|
browser_path$_,
|
|
75
80
|
browser_path_,
|
|
76
|
-
|
|
77
|
-
] = be_lock_memosig_triple_(ctx=>
|
|
81
|
+
] = be_memo_pair_(ctx=>
|
|
78
82
|
join(cwd_(ctx), browser__relative_path_(ctx)),
|
|
79
|
-
{
|
|
83
|
+
{ ns: 'app', id: 'browser_path' })
|
|
80
84
|
export const [
|
|
81
85
|
server__relative_path$_,
|
|
82
86
|
server__relative_path_,
|
|
83
87
|
] = be_memo_pair_(ctx=>
|
|
84
|
-
join(
|
|
85
|
-
{
|
|
88
|
+
join(dist__relative_path_(ctx), is_prod_(ctx) ? 'server' : 'server--dev'),
|
|
89
|
+
{ ns: 'app', id: 'server__relative_path' })
|
|
86
90
|
export const [
|
|
87
91
|
server_path$_,
|
|
88
92
|
server_path_,
|
|
89
|
-
|
|
90
|
-
] = be_lock_memosig_triple_(ctx=>
|
|
93
|
+
] = be_memo_pair_(ctx=>
|
|
91
94
|
join(cwd_(ctx), server__relative_path_(ctx)),
|
|
92
|
-
{
|
|
95
|
+
{ ns: 'app', id: 'server_path' })
|
package/app/index.test.ts
CHANGED
|
@@ -1,7 +1,319 @@
|
|
|
1
|
+
import { type Ctx, ctx_ } from 'ctx-core/be'
|
|
2
|
+
import type { Equal, Expect } from 'ctx-core/test'
|
|
3
|
+
import { resolve } from 'path'
|
|
1
4
|
import { test } from 'uvu'
|
|
2
|
-
import { equal } from 'uvu/assert'
|
|
3
|
-
import '
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import { equal, not, throws } from 'uvu/assert'
|
|
6
|
+
import { app_ctx } from '../ctx/index.js'
|
|
7
|
+
import {
|
|
8
|
+
app__relative_path$_,
|
|
9
|
+
app__relative_path_,
|
|
10
|
+
app_path$_,
|
|
11
|
+
app_path_,
|
|
12
|
+
app_path__set,
|
|
13
|
+
browser__relative_path$_,
|
|
14
|
+
browser__relative_path_,
|
|
15
|
+
browser_path$_,
|
|
16
|
+
browser_path_,
|
|
17
|
+
cwd$_,
|
|
18
|
+
cwd_,
|
|
19
|
+
cwd__set,
|
|
20
|
+
dist__relative_path$_,
|
|
21
|
+
dist__relative_path_,
|
|
22
|
+
dist_path$_,
|
|
23
|
+
dist_path_,
|
|
24
|
+
dist_path__set,
|
|
25
|
+
is_prod$_,
|
|
26
|
+
is_prod_,
|
|
27
|
+
is_prod__set,
|
|
28
|
+
port$_,
|
|
29
|
+
port_,
|
|
30
|
+
port__set,
|
|
31
|
+
public_path$_,
|
|
32
|
+
public_path_,
|
|
33
|
+
public_path__set,
|
|
34
|
+
server__relative_path$_,
|
|
35
|
+
server__relative_path_,
|
|
36
|
+
server_path$_,
|
|
37
|
+
server_path_,
|
|
38
|
+
src__relative_path$_,
|
|
39
|
+
src__relative_path_,
|
|
40
|
+
src_path$_,
|
|
41
|
+
src_path_,
|
|
42
|
+
src_path__set
|
|
43
|
+
} from './index.js'
|
|
44
|
+
test.after.each(()=>{
|
|
45
|
+
app_ctx.s.app.clear()
|
|
46
|
+
})
|
|
47
|
+
test('app_ctx', ()=>{
|
|
48
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
49
|
+
type test_app_ctx = Expect<Equal<typeof app_ctx, Ctx<'app'>>>
|
|
50
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
51
|
+
})
|
|
52
|
+
test('port', ()=>{
|
|
53
|
+
equal(process.env.PORT, undefined)
|
|
54
|
+
equal(port$_(app_ctx)._, 3000)
|
|
55
|
+
equal(port_(app_ctx), 3000)
|
|
56
|
+
port__set(app_ctx, 4000)
|
|
57
|
+
equal(port_(app_ctx), 4000)
|
|
58
|
+
// @ts-expect-error TS2345
|
|
59
|
+
throws(()=>port$_(ctx_()))
|
|
60
|
+
// @ts-expect-error TS2345
|
|
61
|
+
throws(()=>port_(ctx_()))
|
|
62
|
+
// @ts-expect-error TS2345
|
|
63
|
+
throws(()=>port__set(ctx_(), 5000))
|
|
64
|
+
})
|
|
65
|
+
test('cwd', ()=>{
|
|
66
|
+
equal(cwd$_(app_ctx)._, resolve('.'))
|
|
67
|
+
equal(cwd_(app_ctx), resolve('.'))
|
|
68
|
+
cwd__set(app_ctx, '/test/path')
|
|
69
|
+
equal(cwd$_(app_ctx)._, resolve('/test/path'))
|
|
70
|
+
equal(cwd_(app_ctx), resolve('/test/path'))
|
|
71
|
+
// @ts-expect-error TS2345
|
|
72
|
+
throws(()=>cwd$_(ctx_()))
|
|
73
|
+
// @ts-expect-error TS2345
|
|
74
|
+
throws(()=>cwd_(ctx_()))
|
|
75
|
+
// @ts-expect-error TS2345
|
|
76
|
+
throws(()=>cwd__set(ctx_(), '/another/path'))
|
|
77
|
+
})
|
|
78
|
+
test('is_prod', ()=>{
|
|
79
|
+
not.equal(process.env.NODE_ENV, 'production')
|
|
80
|
+
equal(is_prod$_(app_ctx)._, false)
|
|
81
|
+
equal(is_prod_(app_ctx), false)
|
|
82
|
+
is_prod__set(app_ctx, true)
|
|
83
|
+
equal(is_prod$_(app_ctx)._, true)
|
|
84
|
+
equal(is_prod_(app_ctx), true)
|
|
85
|
+
// @ts-expect-error TS2345
|
|
86
|
+
throws(()=>is_prod$_(ctx_()))
|
|
87
|
+
// @ts-expect-error TS2345
|
|
88
|
+
throws(()=>is_prod_(ctx_()))
|
|
89
|
+
// @ts-expect-error TS2345
|
|
90
|
+
throws(()=>is_prod__set(ctx_(), false))
|
|
91
|
+
})
|
|
92
|
+
test('public_path', ()=>{
|
|
93
|
+
equal(public_path$_(app_ctx)._, resolve('./public'))
|
|
94
|
+
equal(public_path_(app_ctx), resolve('./public'))
|
|
95
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
96
|
+
equal(public_path$_(app_ctx)._, '/test/cwd/public')
|
|
97
|
+
equal(public_path_(app_ctx), '/test/cwd/public')
|
|
98
|
+
public_path__set(app_ctx, '/test/cwd/public2')
|
|
99
|
+
equal(public_path$_(app_ctx)._, '/test/cwd/public2')
|
|
100
|
+
equal(public_path_(app_ctx), '/test/cwd/public2')
|
|
101
|
+
cwd__set(app_ctx, '/test/cwd2')
|
|
102
|
+
equal(public_path$_(app_ctx)._, '/test/cwd/public2')
|
|
103
|
+
equal(public_path_(app_ctx), '/test/cwd/public2')
|
|
104
|
+
// @ts-expect-error TS2345
|
|
105
|
+
throws(()=>public_path$_(ctx_()))
|
|
106
|
+
// @ts-expect-error TS2345
|
|
107
|
+
throws(()=>public_path_(ctx_()))
|
|
108
|
+
// @ts-expect-error TS2345
|
|
109
|
+
throws(()=>public_path__set(ctx_(), '/another/path/public'))
|
|
110
|
+
})
|
|
111
|
+
test('dist_path', ()=>{
|
|
112
|
+
equal(dist_path$_(app_ctx)._, resolve('./dist'))
|
|
113
|
+
equal(dist_path_(app_ctx), resolve('./dist'))
|
|
114
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
115
|
+
equal(dist_path$_(app_ctx)._, '/test/cwd/dist')
|
|
116
|
+
equal(dist_path_(app_ctx), '/test/cwd/dist')
|
|
117
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
118
|
+
equal(dist_path$_(app_ctx)._, '/test/cwd/dist2')
|
|
119
|
+
equal(dist_path_(app_ctx), '/test/cwd/dist2')
|
|
120
|
+
cwd__set(app_ctx, '/test/cwd2')
|
|
121
|
+
equal(dist_path$_(app_ctx)._, '/test/cwd/dist2')
|
|
122
|
+
equal(dist_path_(app_ctx), '/test/cwd/dist2')
|
|
123
|
+
// @ts-expect-error TS2345
|
|
124
|
+
throws(()=>dist_path$_(ctx_()))
|
|
125
|
+
// @ts-expect-error TS2345
|
|
126
|
+
throws(()=>dist_path_(ctx_()))
|
|
127
|
+
// @ts-expect-error TS2345
|
|
128
|
+
throws(()=>dist_path__set(ctx_(), '/another/path/dist'))
|
|
129
|
+
})
|
|
130
|
+
test('dist__relative_path', ()=>{
|
|
131
|
+
equal(dist__relative_path$_(app_ctx)._, 'dist')
|
|
132
|
+
equal(dist__relative_path_(app_ctx), 'dist')
|
|
133
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
134
|
+
equal(dist__relative_path$_(app_ctx)._, 'dist')
|
|
135
|
+
equal(dist__relative_path_(app_ctx), 'dist')
|
|
136
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
137
|
+
equal(dist__relative_path$_(app_ctx)._, 'dist2')
|
|
138
|
+
equal(dist__relative_path_(app_ctx), 'dist2')
|
|
139
|
+
// @ts-expect-error TS2345
|
|
140
|
+
throws(()=>dist__relative_path$_(ctx_()))
|
|
141
|
+
// @ts-expect-error TS2345
|
|
142
|
+
throws(()=>dist__relative_path_(ctx_()))
|
|
143
|
+
})
|
|
144
|
+
test('src_path', ()=>{
|
|
145
|
+
equal(src_path$_(app_ctx)._, resolve('./src'))
|
|
146
|
+
equal(src_path_(app_ctx), resolve('./src'))
|
|
147
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
148
|
+
equal(src_path$_(app_ctx)._, '/test/cwd/src')
|
|
149
|
+
equal(src_path_(app_ctx), '/test/cwd/src')
|
|
150
|
+
src_path__set(app_ctx, '/test/cwd/src2')
|
|
151
|
+
equal(src_path$_(app_ctx)._, '/test/cwd/src2')
|
|
152
|
+
equal(src_path_(app_ctx), '/test/cwd/src2')
|
|
153
|
+
cwd__set(app_ctx, '/test/cwd2')
|
|
154
|
+
equal(src_path$_(app_ctx)._, '/test/cwd/src2')
|
|
155
|
+
equal(src_path_(app_ctx), '/test/cwd/src2')
|
|
156
|
+
// @ts-expect-error TS2345
|
|
157
|
+
throws(()=>src_path$_(ctx_()))
|
|
158
|
+
// @ts-expect-error TS2345
|
|
159
|
+
throws(()=>src_path_(ctx_()))
|
|
160
|
+
// @ts-expect-error TS2345
|
|
161
|
+
throws(()=>src_path__set(ctx_(), '/another/path/src'))
|
|
162
|
+
})
|
|
163
|
+
test('src__relative_path', ()=>{
|
|
164
|
+
equal(src__relative_path$_(app_ctx)._, 'src')
|
|
165
|
+
equal(src__relative_path_(app_ctx), 'src')
|
|
166
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
167
|
+
equal(src__relative_path$_(app_ctx)._, 'src')
|
|
168
|
+
equal(src__relative_path_(app_ctx), 'src')
|
|
169
|
+
src_path__set(app_ctx, '/test/cwd/src2')
|
|
170
|
+
equal(src__relative_path$_(app_ctx)._, 'src2')
|
|
171
|
+
equal(src__relative_path_(app_ctx), 'src2')
|
|
172
|
+
// @ts-expect-error TS2345
|
|
173
|
+
throws(()=>src__relative_path$_(ctx_()))
|
|
174
|
+
// @ts-expect-error TS2345
|
|
175
|
+
throws(()=>src__relative_path_(ctx_()))
|
|
176
|
+
})
|
|
177
|
+
test('app_path', ()=>{
|
|
178
|
+
equal(app_path$_(app_ctx)._, resolve('./src/app'))
|
|
179
|
+
equal(app_path_(app_ctx), resolve('./src/app'))
|
|
180
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
181
|
+
equal(app_path$_(app_ctx)._, '/test/cwd/src/app')
|
|
182
|
+
equal(app_path_(app_ctx), '/test/cwd/src/app')
|
|
183
|
+
src_path__set(app_ctx, '/test/cwd/src2')
|
|
184
|
+
app_path__set(app_ctx, '/test/cwd/src2/app2')
|
|
185
|
+
equal(app_path$_(app_ctx)._, '/test/cwd/src2/app2')
|
|
186
|
+
equal(app_path_(app_ctx), '/test/cwd/src2/app2')
|
|
187
|
+
cwd__set(app_ctx, '/test/cwd2')
|
|
188
|
+
equal(app_path$_(app_ctx)._, '/test/cwd/src2/app2')
|
|
189
|
+
equal(app_path_(app_ctx), '/test/cwd/src2/app2')
|
|
190
|
+
src_path__set(app_ctx, '/test/cwd/src3')
|
|
191
|
+
equal(app_path$_(app_ctx)._, '/test/cwd/src2/app2')
|
|
192
|
+
equal(app_path_(app_ctx), '/test/cwd/src2/app2')
|
|
193
|
+
// @ts-expect-error TS2345
|
|
194
|
+
throws(()=>app_path$_(ctx_()))
|
|
195
|
+
// @ts-expect-error TS2345
|
|
196
|
+
throws(()=>app_path_(ctx_()))
|
|
197
|
+
// @ts-expect-error TS2345
|
|
198
|
+
throws(()=>app_path__set(ctx_(), '/another/path/src/app'))
|
|
199
|
+
})
|
|
200
|
+
test('app__relative_path', ()=>{
|
|
201
|
+
equal(app__relative_path$_(app_ctx)._, 'src/app')
|
|
202
|
+
equal(app__relative_path_(app_ctx), 'src/app')
|
|
203
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
204
|
+
equal(app__relative_path$_(app_ctx)._, 'src/app')
|
|
205
|
+
equal(app__relative_path_(app_ctx), 'src/app')
|
|
206
|
+
src_path__set(app_ctx, '/test/cwd/src2')
|
|
207
|
+
equal(app__relative_path$_(app_ctx)._, 'src2/app')
|
|
208
|
+
equal(app__relative_path_(app_ctx), 'src2/app')
|
|
209
|
+
app_path__set(app_ctx, '/test/cwd/src2/app2')
|
|
210
|
+
equal(app__relative_path$_(app_ctx)._, 'src2/app2')
|
|
211
|
+
equal(app__relative_path_(app_ctx), 'src2/app2')
|
|
212
|
+
cwd__set(app_ctx, '/test/cwd2')
|
|
213
|
+
equal(app__relative_path$_(app_ctx)._, '../cwd/src2/app2')
|
|
214
|
+
equal(app__relative_path_(app_ctx), '../cwd/src2/app2')
|
|
215
|
+
src_path__set(app_ctx, '/test/cwd2/src2')
|
|
216
|
+
equal(app__relative_path$_(app_ctx)._, '../cwd/src2/app2')
|
|
217
|
+
equal(app__relative_path_(app_ctx), '../cwd/src2/app2')
|
|
218
|
+
// @ts-expect-error TS2345
|
|
219
|
+
throws(()=>app__relative_path$_(ctx_()))
|
|
220
|
+
// @ts-expect-error TS2345
|
|
221
|
+
throws(()=>app__relative_path_(ctx_()))
|
|
222
|
+
})
|
|
223
|
+
test('browser__relative_path', ()=>{
|
|
224
|
+
is_prod__set(app_ctx, false)
|
|
225
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist/browser--dev')
|
|
226
|
+
equal(browser__relative_path_(app_ctx), 'dist/browser--dev')
|
|
227
|
+
is_prod__set(app_ctx, true)
|
|
228
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist/browser')
|
|
229
|
+
equal(browser__relative_path_(app_ctx), 'dist/browser')
|
|
230
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
231
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist/browser')
|
|
232
|
+
equal(browser__relative_path_(app_ctx), 'dist/browser')
|
|
233
|
+
is_prod__set(app_ctx, false)
|
|
234
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist/browser--dev')
|
|
235
|
+
equal(browser__relative_path_(app_ctx), 'dist/browser--dev')
|
|
236
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
237
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist2/browser--dev')
|
|
238
|
+
equal(browser__relative_path_(app_ctx), 'dist2/browser--dev')
|
|
239
|
+
is_prod__set(app_ctx, true)
|
|
240
|
+
equal(browser__relative_path$_(app_ctx)._, 'dist2/browser')
|
|
241
|
+
equal(browser__relative_path_(app_ctx), 'dist2/browser')
|
|
242
|
+
// @ts-expect-error TS2345
|
|
243
|
+
throws(()=>browser__relative_path$_(ctx_()))
|
|
244
|
+
// @ts-expect-error TS2345
|
|
245
|
+
throws(()=>browser__relative_path_(ctx_()))
|
|
246
|
+
})
|
|
247
|
+
test('browser_path', ()=>{
|
|
248
|
+
is_prod__set(app_ctx, false)
|
|
249
|
+
equal(browser_path$_(app_ctx)._, resolve('./dist/browser--dev'))
|
|
250
|
+
equal(browser_path_(app_ctx), resolve('./dist/browser--dev'))
|
|
251
|
+
is_prod__set(app_ctx, true)
|
|
252
|
+
equal(browser_path$_(app_ctx)._, resolve('./dist/browser'))
|
|
253
|
+
equal(browser_path_(app_ctx), resolve('./dist/browser'))
|
|
254
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
255
|
+
equal(browser_path$_(app_ctx)._, '/test/cwd/dist/browser')
|
|
256
|
+
equal(browser_path_(app_ctx), '/test/cwd/dist/browser')
|
|
257
|
+
is_prod__set(app_ctx, false)
|
|
258
|
+
equal(browser_path$_(app_ctx)._, '/test/cwd/dist/browser--dev')
|
|
259
|
+
equal(browser_path_(app_ctx), '/test/cwd/dist/browser--dev')
|
|
260
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
261
|
+
equal(browser_path$_(app_ctx)._, '/test/cwd/dist2/browser--dev')
|
|
262
|
+
equal(browser_path_(app_ctx), '/test/cwd/dist2/browser--dev')
|
|
263
|
+
is_prod__set(app_ctx, true)
|
|
264
|
+
equal(browser_path$_(app_ctx)._, '/test/cwd/dist2/browser')
|
|
265
|
+
equal(browser_path_(app_ctx), '/test/cwd/dist2/browser')
|
|
266
|
+
// @ts-expect-error TS2345
|
|
267
|
+
throws(()=>browser_path$_(ctx_()))
|
|
268
|
+
// @ts-expect-error TS2345
|
|
269
|
+
throws(()=>browser_path_(ctx_()))
|
|
270
|
+
})
|
|
271
|
+
test('server__relative_path', ()=>{
|
|
272
|
+
is_prod__set(app_ctx, false)
|
|
273
|
+
equal(server__relative_path$_(app_ctx)._, 'dist/server--dev')
|
|
274
|
+
equal(server__relative_path_(app_ctx), 'dist/server--dev')
|
|
275
|
+
is_prod__set(app_ctx, true)
|
|
276
|
+
equal(server__relative_path$_(app_ctx)._, 'dist/server')
|
|
277
|
+
equal(server__relative_path_(app_ctx), 'dist/server')
|
|
278
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
279
|
+
equal(server__relative_path$_(app_ctx)._, 'dist/server')
|
|
280
|
+
equal(server__relative_path_(app_ctx), 'dist/server')
|
|
281
|
+
is_prod__set(app_ctx, false)
|
|
282
|
+
equal(server__relative_path$_(app_ctx)._, 'dist/server--dev')
|
|
283
|
+
equal(server__relative_path_(app_ctx), 'dist/server--dev')
|
|
284
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
285
|
+
equal(server__relative_path$_(app_ctx)._, 'dist2/server--dev')
|
|
286
|
+
equal(server__relative_path_(app_ctx), 'dist2/server--dev')
|
|
287
|
+
is_prod__set(app_ctx, true)
|
|
288
|
+
equal(server__relative_path$_(app_ctx)._, 'dist2/server')
|
|
289
|
+
equal(server__relative_path_(app_ctx), 'dist2/server')
|
|
290
|
+
// @ts-expect-error TS2345
|
|
291
|
+
throws(()=>server__relative_path$_(ctx_()))
|
|
292
|
+
// @ts-expect-error TS2345
|
|
293
|
+
throws(()=>server__relative_path_(ctx_()))
|
|
294
|
+
})
|
|
295
|
+
test('server_path', ()=>{
|
|
296
|
+
is_prod__set(app_ctx, false)
|
|
297
|
+
equal(server_path$_(app_ctx)._, resolve('./dist/server--dev'))
|
|
298
|
+
equal(server_path_(app_ctx), resolve('./dist/server--dev'))
|
|
299
|
+
is_prod__set(app_ctx, true)
|
|
300
|
+
equal(server_path$_(app_ctx)._, resolve('./dist/server'))
|
|
301
|
+
equal(server_path_(app_ctx), resolve('./dist/server'))
|
|
302
|
+
cwd__set(app_ctx, '/test/cwd')
|
|
303
|
+
equal(server_path$_(app_ctx)._, '/test/cwd/dist/server')
|
|
304
|
+
equal(server_path_(app_ctx), '/test/cwd/dist/server')
|
|
305
|
+
is_prod__set(app_ctx, false)
|
|
306
|
+
equal(server_path$_(app_ctx)._, '/test/cwd/dist/server--dev')
|
|
307
|
+
equal(server_path_(app_ctx), '/test/cwd/dist/server--dev')
|
|
308
|
+
dist_path__set(app_ctx, '/test/cwd/dist2')
|
|
309
|
+
equal(server_path$_(app_ctx)._, '/test/cwd/dist2/server--dev')
|
|
310
|
+
equal(server_path_(app_ctx), '/test/cwd/dist2/server--dev')
|
|
311
|
+
is_prod__set(app_ctx, true)
|
|
312
|
+
equal(server_path$_(app_ctx)._, '/test/cwd/dist2/server')
|
|
313
|
+
equal(server_path_(app_ctx), '/test/cwd/dist2/server')
|
|
314
|
+
// @ts-expect-error TS2345
|
|
315
|
+
throws(()=>server_path$_(ctx_()))
|
|
316
|
+
// @ts-expect-error TS2345
|
|
317
|
+
throws(()=>server_path_(ctx_()))
|
|
6
318
|
})
|
|
7
319
|
test.run()
|
package/asset/index.d.ts
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
|
+
import type { ctx__be_T, ctx__get_T, ctx__set_T, Ctx_wide_T } from 'ctx-core/be'
|
|
2
|
+
import type { lock_memosig_T } from 'ctx-core/rmemo'
|
|
1
3
|
export declare function asset_path_(mod_promise:Promise<{ default:string }>):Promise<string>
|
|
2
4
|
export declare function asset_path_a_<
|
|
3
5
|
Tuple extends [...Promise<{ default:string }>[]]
|
|
4
6
|
>(...mod_promise_a:Tuple):Promise<{
|
|
5
|
-
[Index in keyof Tuple]:
|
|
7
|
+
[Index in keyof Tuple]:string
|
|
6
8
|
}>
|
|
7
|
-
export declare
|
|
9
|
+
export declare const assets$_:ctx__be_T<has_route_T, lock_memosig_T<assets_T>, 'route'>
|
|
10
|
+
export declare const assets_:ctx__get_T<has_route_T, assets_T>
|
|
11
|
+
export declare const assets__set:ctx__set_T<has_route_T, assets_T>
|
|
12
|
+
export declare function assets__assign<ctx_T extends has_route_T>(
|
|
13
|
+
ctx:ctx_T,
|
|
14
|
+
..._assets_a:assets_T[]):assets_T
|
|
15
|
+
export declare function assets__new(..._assets_a:assets_T[]):assets_T
|
|
8
16
|
export type assets_T = {
|
|
9
17
|
css_a?:string[]
|
|
10
18
|
script_a?:string[]
|
|
11
19
|
}
|
|
20
|
+
type has_route_T = Ctx_wide_T<'route'>
|
package/asset/index.js
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
1
|
/// <reference types="./index.d.ts" />
|
|
2
|
+
import { be_lock_memosig_triple_ } from 'ctx-core/rmemo'
|
|
3
|
+
import { browser__script_ } from '../browser/index.js'
|
|
4
|
+
import { server__css_ } from '../server/index.js'
|
|
2
5
|
export async function asset_path_(mod_promise) {
|
|
3
6
|
return (await mod_promise.then(mod=>mod.default)).replace(/^\.\//, '/')
|
|
4
7
|
}
|
|
5
8
|
export async function asset_path_a_(...mod_promise_a) {
|
|
6
9
|
return Promise.all(mod_promise_a.map(asset_path_))
|
|
7
10
|
}
|
|
11
|
+
export const [
|
|
12
|
+
assets$_,
|
|
13
|
+
assets_,
|
|
14
|
+
assets__set,
|
|
15
|
+
] = be_lock_memosig_triple_(ctx=>
|
|
16
|
+
assets__new({
|
|
17
|
+
css_a: [server__css_(ctx)],
|
|
18
|
+
script_a: [browser__script_(ctx)]
|
|
19
|
+
}),
|
|
20
|
+
{ ns: 'route', id: 'assets' })
|
|
21
|
+
export function assets__assign(route_ctx, ..._assets_a) {
|
|
22
|
+
assets__set(route_ctx, assets__new(assets_(route_ctx, ..._assets_a)))
|
|
23
|
+
}
|
|
8
24
|
/**
|
|
9
25
|
* @param {assets_T[]}_assets_a
|
|
10
26
|
* @returns {{script_a: *[], css_a: *[]}}
|
|
11
27
|
* @private
|
|
12
28
|
*/
|
|
13
|
-
export function
|
|
29
|
+
export function assets__new(..._assets_a) {
|
|
14
30
|
/** @type {assets_T} */
|
|
15
31
|
const assets = { css_a: [], script_a: [] }
|
|
16
32
|
for (const _assets of _assets_a) {
|
package/asset/index.test.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
import { type Ctx, ctx_, ns_ctx_ } from 'ctx-core/be'
|
|
2
|
+
import type { Equal, Expect } from 'ctx-core/test'
|
|
1
3
|
import { test } from 'uvu'
|
|
2
|
-
import { equal } from 'uvu/assert'
|
|
3
|
-
import {
|
|
4
|
+
import { equal, throws } from 'uvu/assert'
|
|
5
|
+
import { app_ctx, middleware_ctx_, route_ctx_ } from '../ctx/index.js'
|
|
6
|
+
import { asset_path_, asset_path_a_, assets$_, assets_, assets__assign, assets__new, assets__set } from './index.js'
|
|
7
|
+
test.after.each(()=>{
|
|
8
|
+
app_ctx.s.app.clear()
|
|
9
|
+
})
|
|
4
10
|
test('asset_path_', async ()=>{
|
|
5
11
|
equal(await asset_path_(mod_('./path.png')), '/path.png')
|
|
6
12
|
})
|
|
@@ -17,12 +23,49 @@ test('asset_path_a_', async ()=>{
|
|
|
17
23
|
'/path3.png',
|
|
18
24
|
])
|
|
19
25
|
})
|
|
20
|
-
test('
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
test('assets', ()=>{
|
|
27
|
+
const route_ctx = route_ctx_(middleware_ctx_())
|
|
28
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
29
|
+
type test_ctx = Expect<Equal<typeof route_ctx, Ctx<'app'|'middleware'|'route'>>>
|
|
30
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
31
|
+
const assets = assets__new({ css_a: ['/foo.css'], script_a: ['/foo.js'] })
|
|
32
|
+
assets__set(route_ctx, assets)
|
|
33
|
+
equal(assets_(route_ctx), assets)
|
|
34
|
+
equal(assets$_(route_ctx)(), assets)
|
|
35
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
36
|
+
// @ts-expect-error TS2345
|
|
37
|
+
type test_assets$_ = Expect<Equal<typeof assets$_, number>>
|
|
38
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
39
|
+
// @ts-expect-error TS2345
|
|
40
|
+
throws(()=>assets$_(ctx_()))
|
|
41
|
+
// @ts-expect-error TS2345
|
|
42
|
+
throws(()=>assets$_(middleware_ctx_()))
|
|
43
|
+
// @ts-expect-error TS2345
|
|
44
|
+
throws(()=>assets_(ctx_()))
|
|
45
|
+
// @ts-expect-error TS2345
|
|
46
|
+
throws(()=>assets_(middleware_ctx_()))
|
|
47
|
+
// @ts-expect-error TS2345
|
|
48
|
+
throws(()=>assets__set(ctx_(), assets))
|
|
49
|
+
// @ts-expect-error TS2345
|
|
50
|
+
throws(()=>assets__set(middleware_ctx_(), assets))
|
|
51
|
+
})
|
|
52
|
+
test('assets__assign', async ()=>{
|
|
53
|
+
assets__assign(route_ctx_(middleware_ctx_()), assets__new())
|
|
54
|
+
// @ts-expect-error TS2345
|
|
55
|
+
throws(()=>assets__assign(ctx_()))
|
|
56
|
+
// @ts-expect-error TS2345
|
|
57
|
+
throws(()=>assets__assign(ns_ctx_(ctx_())))
|
|
58
|
+
// @ts-expect-error TS2345
|
|
59
|
+
throws(()=>assets__assign(middleware_ctx_()))
|
|
60
|
+
// @ts-expect-error TS2345
|
|
61
|
+
throws(()=>assets__assign(app_ctx, assets__new()))
|
|
62
|
+
})
|
|
63
|
+
test('assets__new', async ()=>{
|
|
64
|
+
equal(assets__new(
|
|
65
|
+
{ script_a: ['/foo.js'] },
|
|
23
66
|
{ css_a: ['/foo.css'] },
|
|
24
67
|
{ script_a: ['/bar.js'], css_a: ['/bar.css'] },
|
|
25
|
-
{
|
|
68
|
+
{},
|
|
26
69
|
{ script_a: [], css_a: [] },
|
|
27
70
|
{ script_a: undefined, css_a: undefined }),
|
|
28
71
|
{
|
|
@@ -31,6 +74,6 @@ test('assets_', async ()=>{
|
|
|
31
74
|
})
|
|
32
75
|
})
|
|
33
76
|
test.run()
|
|
34
|
-
async function mod_
|
|
35
|
-
return { default:out_path }
|
|
77
|
+
async function mod_(out_path:string) {
|
|
78
|
+
return { default: out_path }
|
|
36
79
|
}
|