-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathsubpackages.js
76 lines (72 loc) · 2 KB
/
subpackages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import path from 'path'
import test from 'ava'
import MinaEntryPlugin from '@tinajs/mina-entry-webpack-plugin'
import compiler from './helpers/compiler'
const resolveRelative = path.resolve.bind(null, __dirname)
test('subpackages', async t => {
const { compile, mfs } = compiler({
context: resolveRelative('fixtures/subpackages/src'),
entry: 'app.mina',
output: {
filename: 'app.js',
},
plugins: [new MinaEntryPlugin()],
})
await compile()
// app
t.deepEqual(JSON.parse(mfs.readFileSync('/app.json', 'utf-8')), {
pages: ['pages/home'],
subPackages: [
{
root: 'sub1',
pages: ['page1', 'page2'],
},
{
root: 'sub2',
pages: ['page1'],
independent: true, // support independent
},
],
})
// sub1
t.deepEqual(JSON.parse(mfs.readFileSync('/sub1/page1.json', 'utf-8')), {
usingComponents: {
a: './_/components/a', // a is moved to sub1
b: './../components/b', // b is shared from sub1, sub2, so it's not moved
},
})
// sub2
t.deepEqual(JSON.parse(mfs.readFileSync('/sub2/page1.json', 'utf-8')), {
usingComponents: {
b: './../components/b', // b is shared from sub1, sub2, so it's not moved
},
})
// a is only used by sub1, it is moved
t.deepEqual(
JSON.parse(mfs.readFileSync('/sub1/_/components/a.json', 'utf-8')),
{
usingComponents: {
c: './c', // c is also moved
d: './../../../components/d', // d is not moved
},
}
)
// b is shared by sub1 and sub2, it is not moved
t.deepEqual(JSON.parse(mfs.readFileSync('/components/b.json', 'utf-8')), {
usingComponents: {
d: './d', // d is not moved
},
})
// c is only used by a, it is moved
t.deepEqual(
JSON.parse(mfs.readFileSync('/sub1/_/components/c.json', 'utf-8')),
{
component: true,
}
)
// d is shared by a and b, it's not moved
t.deepEqual(JSON.parse(mfs.readFileSync('/components/d.json', 'utf-8')), {
component: true,
})
t.pass()
})