/
bundler.js
217 lines (208 loc) Β· 5.75 KB
/
bundler.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import path from 'path';
import assert from 'assert';
import {bundle, assertBundles, findAsset} from '@parcel/test-utils';
describe('bundler', function () {
it('should remove reused bundle (over shared bundles based on size) if the bundlegroup hit the parallel request limit', async function () {
if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) {
let b = await bundle(
path.join(
__dirname,
'integration/shared-bundle-reused-bundle-remove-reuse/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'css-loader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['bar.js', 'foo.js', 'a.js', 'b.js'],
},
{
assets: ['buzz.js'],
},
{
assets: ['c.js'],
},
{
assets: ['a.js', 'b.js', 'foo.js'],
},
{
assets: ['styles.css'],
},
{
assets: ['local.html'],
},
]);
}
});
//This test case is the sdame as previous except we remove the shared bundle since it is smaller
it('should remove shared bundle (over reused bundles based on size) if the bundlegroup hit the parallel request limit', async function () {
let b = await bundle(
path.join(
__dirname,
'integration/shared-bundle-reused-bundle-remove-shared/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'css-loader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['bar.js', 'c.js'],
},
{
// A consequence of our shared bundle 'c' being removed for the bundleGroup bar
// is that it must also be removed for buzz, even though the buzz bundleGroup does not
// hit the parallel request limit. This is because the shared bundle is no longer sharing
// it is only attached to one bundle and thus should be removed.
assets: ['buzz.js', 'c.js'],
},
{
assets: ['a.js', 'b.js', 'foo.js'],
},
{
assets: ['styles.css'],
},
{
assets: ['local.html'],
},
]);
});
it('should not remove shared bundle from graph if one bundlegroup hits the parallel request limit, and at least 2 other bundleGroups that need it do not', async function () {
//The shared bundle should only be 'put back' for the bundlegroups which hit the parallel request limit
// But if there are at least two other bundlegroups using this shared bundle that do not hit the max limit
// the shared bundle should not be removed from the graph
let b = await bundle(
path.join(
__dirname,
'integration/shared-bundle-remove-from-one-group-only/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'css-loader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['bar.js', 'c.js'], // shared bundle merged back
},
{
assets: ['buzz.js'],
},
{
assets: ['c.js'], // shared bundle
},
{
assets: ['foo.js'],
},
{
assets: ['styles.css'],
},
{
assets: ['local.html'],
},
]);
});
it('should not remove shared bundle from graph if its parent (a reused bundle) is removed by parallel request limit', async function () {
//The shared bundle should only be 'put back' for the bundlegroups which hit the parallel request limit
// But if there are at least two other bundlegroups using this shared bundle that do not hit the max limit
// the shared bundle should not be removed from the graph
if (process.env.PARCEL_TEST_EXPERIMENTAL_BUNDLER) {
let b = await bundle(
path.join(
__dirname,
'integration/shared-bundle-between-reused-bundle-removal/index.js',
),
{
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: false,
},
},
);
assertBundles(b, [
{
name: 'index.js',
assets: [
'index.js',
'bundle-url.js',
'cacheLoader.js',
'css-loader.js',
'esmodule-helpers.js',
'js-loader.js',
'bundle-manifest.js',
],
},
{
assets: ['bar.js', 'foo.js', 'a.js', 'b.js'], // shared bundle merged back
},
{
assets: ['buzz.js'],
},
{
assets: ['c.js'], // shared bundle
},
{
assets: ['foo.js', 'a.js', 'b.js'],
},
{
assets: ['styles.css'],
},
{
assets: ['local.html'],
},
]);
assert(
b
.getReferencedBundles(
b.getBundlesWithAsset(findAsset(b, 'bar.js'))[0],
)
.includes(b.getBundlesWithAsset(findAsset(b, 'c.js'))[0]),
);
}
});
});