@atlaspack/runtime-js 2.14.5-canary.18 → 2.14.5-canary.181
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/CHANGELOG.md +252 -0
- package/lib/JSRuntime.js +80 -40
- package/lib/helpers/browser/analytics/analytics.d.js +1 -0
- package/lib/helpers/browser/css-loader.js +4 -3
- package/lib/helpers/browser/html-loader.js +1 -1
- package/lib/helpers/browser/import-polyfill.js +1 -1
- package/lib/helpers/browser/js-loader.js +4 -3
- package/lib/helpers/browser/prefetch-loader.js +1 -1
- package/lib/helpers/browser/preload-loader.js +1 -1
- package/lib/helpers/browser/sync-js-loader.js +33 -0
- package/lib/helpers/browser/wasm-loader.js +1 -1
- package/lib/helpers/cacheLoader.js +1 -1
- package/lib/helpers/conditional-loader-dev.js +10 -3
- package/lib/helpers/conditional-loader.js +15 -2
- package/lib/helpers/get-worker-url.js +1 -1
- package/lib/helpers/node/css-loader.js +1 -1
- package/lib/helpers/node/html-loader.js +1 -1
- package/lib/helpers/node/js-loader.js +1 -1
- package/lib/helpers/node/wasm-loader.js +1 -1
- package/lib/helpers/worker/js-loader.js +1 -1
- package/lib/helpers/worker/wasm-loader.js +1 -1
- package/lib/types/JSRuntime.d.ts +9 -0
- package/package.json +15 -9
- package/src/{JSRuntime.js → JSRuntime.ts} +184 -113
- package/src/helpers/browser/preload-loader.js +1 -2
- package/src/helpers/browser/sync-js-loader.js +39 -0
- package/src/helpers/conditional-loader-dev.js +11 -3
- package/src/helpers/conditional-loader.js +18 -2
- package/test/analytics.test.ts +4 -1
- package/test/{bundle-url.test.js → bundle-url.test.ts} +1 -2
- package/test/esm-js-loader-retry.test.ts +4 -7
- package/tsconfig.json +4 -0
- package/src/helpers/browser/analytics/analytics.js.flow +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,257 @@
|
|
|
1
1
|
# @atlaspack/runtime-js
|
|
2
2
|
|
|
3
|
+
## 2.18.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`830261d`](https://github.com/atlassian-labs/atlaspack/commit/830261dcf4a40293090b61cab52fd75d5683c73f)]:
|
|
8
|
+
- @atlaspack/feature-flags@2.24.1
|
|
9
|
+
- @atlaspack/types-internal@2.19.5
|
|
10
|
+
- @atlaspack/utils@2.19.1
|
|
11
|
+
- @atlaspack/plugin@2.14.29
|
|
12
|
+
|
|
13
|
+
## 2.18.4
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767), [`a5081c3`](https://github.com/atlassian-labs/atlaspack/commit/a5081c3f9207d28716ee4edd3841de1830ea4b80), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`8843980`](https://github.com/atlassian-labs/atlaspack/commit/88439807be20025fd3433380204ff1205079729e)]:
|
|
18
|
+
- @atlaspack/feature-flags@2.24.0
|
|
19
|
+
- @atlaspack/utils@2.19.0
|
|
20
|
+
- @atlaspack/types-internal@2.19.4
|
|
21
|
+
- @atlaspack/plugin@2.14.28
|
|
22
|
+
|
|
23
|
+
## 2.18.3
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
|
|
28
|
+
- @atlaspack/feature-flags@2.23.2
|
|
29
|
+
- @atlaspack/types-internal@2.19.3
|
|
30
|
+
- @atlaspack/utils@2.18.4
|
|
31
|
+
- @atlaspack/plugin@2.14.27
|
|
32
|
+
|
|
33
|
+
## 2.18.2
|
|
34
|
+
|
|
35
|
+
### Patch Changes
|
|
36
|
+
|
|
37
|
+
- [#742](https://github.com/atlassian-labs/atlaspack/pull/742) [`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd) Thanks [@yamadapc](https://github.com/yamadapc)! - Internal changes and bug fixes to environmentDeduplication flag
|
|
38
|
+
|
|
39
|
+
- [#755](https://github.com/atlassian-labs/atlaspack/pull/755) [`b6e72b6`](https://github.com/atlassian-labs/atlaspack/commit/b6e72b6dd2b517cbb0e700fa69e63332d3eacb1e) Thanks [@benjervis](https://github.com/benjervis)! - Allow runtime assets to be marked as requiring execution on load
|
|
40
|
+
|
|
41
|
+
- Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
|
|
42
|
+
- @atlaspack/domain-sharding@2.14.3
|
|
43
|
+
- @atlaspack/types-internal@2.19.2
|
|
44
|
+
- @atlaspack/feature-flags@2.23.1
|
|
45
|
+
- @atlaspack/diagnostic@2.14.3
|
|
46
|
+
- @atlaspack/plugin@2.14.26
|
|
47
|
+
- @atlaspack/utils@2.18.3
|
|
48
|
+
|
|
49
|
+
## 2.18.1
|
|
50
|
+
|
|
51
|
+
### Patch Changes
|
|
52
|
+
|
|
53
|
+
- Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
|
|
54
|
+
- @atlaspack/feature-flags@2.23.0
|
|
55
|
+
- @atlaspack/utils@2.18.2
|
|
56
|
+
- @atlaspack/plugin@2.14.25
|
|
57
|
+
|
|
58
|
+
## 2.18.0
|
|
59
|
+
|
|
60
|
+
### Minor Changes
|
|
61
|
+
|
|
62
|
+
- [#732](https://github.com/atlassian-labs/atlaspack/pull/732) [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45) Thanks [@vykimnguyen](https://github.com/vykimnguyen)! - add tesseract context
|
|
63
|
+
|
|
64
|
+
### Patch Changes
|
|
65
|
+
|
|
66
|
+
- Updated dependencies [[`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
|
|
67
|
+
- @atlaspack/feature-flags@2.22.0
|
|
68
|
+
- @atlaspack/utils@2.18.1
|
|
69
|
+
- @atlaspack/plugin@2.14.24
|
|
70
|
+
|
|
71
|
+
## 2.17.0
|
|
72
|
+
|
|
73
|
+
### Minor Changes
|
|
74
|
+
|
|
75
|
+
- [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
|
|
76
|
+
|
|
77
|
+
### Patch Changes
|
|
78
|
+
|
|
79
|
+
- Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
|
|
80
|
+
- @atlaspack/feature-flags@2.21.0
|
|
81
|
+
- @atlaspack/utils@2.18.0
|
|
82
|
+
- @atlaspack/plugin@2.14.23
|
|
83
|
+
|
|
84
|
+
## 2.16.1
|
|
85
|
+
|
|
86
|
+
### Patch Changes
|
|
87
|
+
|
|
88
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
89
|
+
|
|
90
|
+
- Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`12bee0e`](https://github.com/atlassian-labs/atlaspack/commit/12bee0e23f0464d7f6bd3e24fbe0d19c126d587d)]:
|
|
91
|
+
- @atlaspack/domain-sharding@2.14.2
|
|
92
|
+
- @atlaspack/feature-flags@2.20.1
|
|
93
|
+
- @atlaspack/diagnostic@2.14.2
|
|
94
|
+
- @atlaspack/plugin@2.14.22
|
|
95
|
+
- @atlaspack/utils@2.17.4
|
|
96
|
+
|
|
97
|
+
## 2.16.0
|
|
98
|
+
|
|
99
|
+
### Minor Changes
|
|
100
|
+
|
|
101
|
+
- [#721](https://github.com/atlassian-labs/atlaspack/pull/721) [`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd) Thanks [@benjervis](https://github.com/benjervis)! - Add support for bundle merging based on `webpackChunkName` comments.
|
|
102
|
+
|
|
103
|
+
Adding a `webpackChunkName` comment to an import will allow the bundler to merge multiple imports into a single bundle.
|
|
104
|
+
|
|
105
|
+
e.g.:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import(/* webpackChunkName: "my-chunk" */ './my-module');
|
|
109
|
+
import(/* webpackChunkName: "my-chunk" */ './another-module');
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This can be enabled with the feature flag `supportWebpackChunkName`.
|
|
113
|
+
|
|
114
|
+
### Patch Changes
|
|
115
|
+
|
|
116
|
+
- Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
|
|
117
|
+
- @atlaspack/feature-flags@2.20.0
|
|
118
|
+
- @atlaspack/utils@2.17.3
|
|
119
|
+
- @atlaspack/plugin@2.14.21
|
|
120
|
+
|
|
121
|
+
## 2.15.2
|
|
122
|
+
|
|
123
|
+
### Patch Changes
|
|
124
|
+
|
|
125
|
+
- [#702](https://github.com/atlassian-labs/atlaspack/pull/702) [`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa) Thanks [@alshdavid](https://github.com/alshdavid)! - Fixes to Flow types
|
|
126
|
+
|
|
127
|
+
- Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa), [`1c7865a`](https://github.com/atlassian-labs/atlaspack/commit/1c7865a64451116d94015e248302435839d347c0), [`a0b959f`](https://github.com/atlassian-labs/atlaspack/commit/a0b959fbf61fc3f820ff03c7e8988945fe40a91a)]:
|
|
128
|
+
- @atlaspack/plugin@2.14.20
|
|
129
|
+
- @atlaspack/feature-flags@2.19.2
|
|
130
|
+
- @atlaspack/utils@2.17.2
|
|
131
|
+
|
|
132
|
+
## 2.15.1
|
|
133
|
+
|
|
134
|
+
### Patch Changes
|
|
135
|
+
|
|
136
|
+
- [#692](https://github.com/atlassian-labs/atlaspack/pull/692) [`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d) Thanks [@JakeLane](https://github.com/JakeLane)! - Add fallback behaviour when conditional bundle is missing
|
|
137
|
+
|
|
138
|
+
- Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
|
|
139
|
+
- @atlaspack/feature-flags@2.19.1
|
|
140
|
+
- @atlaspack/utils@2.17.1
|
|
141
|
+
- @atlaspack/plugin@2.14.19
|
|
142
|
+
|
|
143
|
+
## 2.15.0
|
|
144
|
+
|
|
145
|
+
### Minor Changes
|
|
146
|
+
|
|
147
|
+
- [#640](https://github.com/atlassian-labs/atlaspack/pull/640) [`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d) Thanks [@JakeLane](https://github.com/JakeLane)! - Clean up conditional bundling feature flags
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- Updated dependencies [[`dbb4072`](https://github.com/atlassian-labs/atlaspack/commit/dbb40721ebeb45990a14ba04e6b44e7f836fb32d), [`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`c4415a4`](https://github.com/atlassian-labs/atlaspack/commit/c4415a455543d984ca28452c2cb87a794d22497c), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5), [`de23e0c`](https://github.com/atlassian-labs/atlaspack/commit/de23e0ce49d5504fe3947ac26640a3d951087da3), [`18a57cf`](https://github.com/atlassian-labs/atlaspack/commit/18a57cf8a4789b2de5ad8e2676f317a26cc91417), [`a5ed1b4`](https://github.com/atlassian-labs/atlaspack/commit/a5ed1b414498560f393ff491af4da25b6e8dde56)]:
|
|
152
|
+
- @atlaspack/feature-flags@2.19.0
|
|
153
|
+
- @atlaspack/utils@2.17.0
|
|
154
|
+
- @atlaspack/plugin@2.14.18
|
|
155
|
+
|
|
156
|
+
## 2.14.17
|
|
157
|
+
|
|
158
|
+
### Patch Changes
|
|
159
|
+
|
|
160
|
+
- Updated dependencies []:
|
|
161
|
+
- @atlaspack/utils@2.16.1
|
|
162
|
+
- @atlaspack/plugin@2.14.17
|
|
163
|
+
|
|
164
|
+
## 2.14.16
|
|
165
|
+
|
|
166
|
+
### Patch Changes
|
|
167
|
+
|
|
168
|
+
- Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
|
|
169
|
+
- @atlaspack/feature-flags@2.18.4
|
|
170
|
+
- @atlaspack/utils@2.16.0
|
|
171
|
+
- @atlaspack/plugin@2.14.16
|
|
172
|
+
|
|
173
|
+
## 2.14.15
|
|
174
|
+
|
|
175
|
+
### Patch Changes
|
|
176
|
+
|
|
177
|
+
- Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
|
|
178
|
+
- @atlaspack/feature-flags@2.18.3
|
|
179
|
+
- @atlaspack/utils@2.15.3
|
|
180
|
+
- @atlaspack/plugin@2.14.15
|
|
181
|
+
|
|
182
|
+
## 2.14.14
|
|
183
|
+
|
|
184
|
+
### Patch Changes
|
|
185
|
+
|
|
186
|
+
- Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
|
|
187
|
+
- @atlaspack/feature-flags@2.18.2
|
|
188
|
+
- @atlaspack/utils@2.15.2
|
|
189
|
+
- @atlaspack/plugin@2.14.14
|
|
190
|
+
|
|
191
|
+
## 2.14.13
|
|
192
|
+
|
|
193
|
+
### Patch Changes
|
|
194
|
+
|
|
195
|
+
- [#633](https://github.com/atlassian-labs/atlaspack/pull/633) [`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b) Thanks [@sbhuiyan-atlassian](https://github.com/sbhuiyan-atlassian)! - Ported various HMR changes from Parcel
|
|
196
|
+
|
|
197
|
+
- Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
|
|
198
|
+
- @atlaspack/feature-flags@2.18.1
|
|
199
|
+
- @atlaspack/utils@2.15.1
|
|
200
|
+
- @atlaspack/plugin@2.14.13
|
|
201
|
+
|
|
202
|
+
## 2.14.12
|
|
203
|
+
|
|
204
|
+
### Patch Changes
|
|
205
|
+
|
|
206
|
+
- Updated dependencies [[`10fbcfb`](https://github.com/atlassian-labs/atlaspack/commit/10fbcfbfa49c7a83da5d7c40983e36e87f524a75), [`85c52d3`](https://github.com/atlassian-labs/atlaspack/commit/85c52d3f7717b3c84a118d18ab98cfbfd71dcbd2), [`e39c6cf`](https://github.com/atlassian-labs/atlaspack/commit/e39c6cf05f7e95ce5420dbcea66f401b1cbd397c)]:
|
|
207
|
+
- @atlaspack/feature-flags@2.18.0
|
|
208
|
+
- @atlaspack/utils@2.15.0
|
|
209
|
+
- @atlaspack/plugin@2.14.12
|
|
210
|
+
|
|
211
|
+
## 2.14.11
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
|
|
216
|
+
- @atlaspack/feature-flags@2.17.0
|
|
217
|
+
- @atlaspack/utils@2.14.11
|
|
218
|
+
- @atlaspack/plugin@2.14.11
|
|
219
|
+
|
|
220
|
+
## 2.14.10
|
|
221
|
+
|
|
222
|
+
### Patch Changes
|
|
223
|
+
|
|
224
|
+
- Updated dependencies []:
|
|
225
|
+
- @atlaspack/plugin@2.14.10
|
|
226
|
+
- @atlaspack/utils@2.14.10
|
|
227
|
+
|
|
228
|
+
## 2.14.9
|
|
229
|
+
|
|
230
|
+
### Patch Changes
|
|
231
|
+
|
|
232
|
+
- Updated dependencies [[`209692f`](https://github.com/atlassian-labs/atlaspack/commit/209692ffb11eae103a0d65c5e1118a5aa1625818), [`f4da1e1`](https://github.com/atlassian-labs/atlaspack/commit/f4da1e120e73eeb5e8b8927f05e88f04d6148c7b)]:
|
|
233
|
+
- @atlaspack/feature-flags@2.16.0
|
|
234
|
+
- @atlaspack/utils@2.14.9
|
|
235
|
+
- @atlaspack/plugin@2.14.9
|
|
236
|
+
|
|
237
|
+
## 2.14.8
|
|
238
|
+
|
|
239
|
+
### Patch Changes
|
|
240
|
+
|
|
241
|
+
- Updated dependencies [[`30f6017`](https://github.com/atlassian-labs/atlaspack/commit/30f60175ba4d272c5fc193973c63bc298584775b)]:
|
|
242
|
+
- @atlaspack/feature-flags@2.15.1
|
|
243
|
+
- @atlaspack/utils@2.14.8
|
|
244
|
+
- @atlaspack/plugin@2.14.8
|
|
245
|
+
|
|
246
|
+
## 2.14.7
|
|
247
|
+
|
|
248
|
+
### Patch Changes
|
|
249
|
+
|
|
250
|
+
- Updated dependencies [[`a1773d2`](https://github.com/atlassian-labs/atlaspack/commit/a1773d2a62d0ef7805ac7524621dcabcc1afe929)]:
|
|
251
|
+
- @atlaspack/feature-flags@2.15.0
|
|
252
|
+
- @atlaspack/utils@2.14.7
|
|
253
|
+
- @atlaspack/plugin@2.14.7
|
|
254
|
+
|
|
3
255
|
## 2.14.6
|
|
4
256
|
|
|
5
257
|
### Patch Changes
|
package/lib/JSRuntime.js
CHANGED
|
@@ -76,8 +76,10 @@ const LOADERS = {
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
function getLoaders(ctx) {
|
|
79
|
-
|
|
79
|
+
// @ts-expect-error TS2322
|
|
80
|
+
if (ctx.isWorker() || ctx.isTesseract()) return LOADERS.worker;
|
|
80
81
|
if (ctx.isBrowser()) return LOADERS.browser;
|
|
82
|
+
// @ts-expect-error TS2322
|
|
81
83
|
if (ctx.isNode()) return LOADERS.node;
|
|
82
84
|
return null;
|
|
83
85
|
}
|
|
@@ -162,9 +164,11 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
162
164
|
// If this bundle already has the asset this dependency references,
|
|
163
165
|
// return a simple runtime of `Promise.resolve(internalRequire(assetId))`.
|
|
164
166
|
// The linker handles this for scope-hoisting.
|
|
167
|
+
|
|
168
|
+
const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') ? 'parcelRequire' : 'module.bundle.root';
|
|
165
169
|
assets.push({
|
|
166
170
|
filePath: __filename,
|
|
167
|
-
code: `module.exports = Promise.resolve(
|
|
171
|
+
code: `module.exports = Promise.resolve(${requireName}(${JSON.stringify(bundleGraph.getAssetPublicId(resolved.value))}))`,
|
|
168
172
|
dependency,
|
|
169
173
|
env: {
|
|
170
174
|
sourceType: 'module'
|
|
@@ -175,7 +179,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
175
179
|
// Resolve the dependency to a bundle. If inline, export the dependency id,
|
|
176
180
|
// which will be replaced with the contents of that bundle later.
|
|
177
181
|
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
178
|
-
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
182
|
+
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
|
|
179
183
|
assets.push({
|
|
180
184
|
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
181
185
|
code: `module.exports = Promise.resolve(${JSON.stringify(dependency.id)});`,
|
|
@@ -205,10 +209,22 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
205
209
|
// replaced with a reference to this asset to implement the selection.
|
|
206
210
|
const conditions = bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle);
|
|
207
211
|
for (const cond of conditions) {
|
|
208
|
-
const requireName = bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
|
|
209
|
-
|
|
212
|
+
const requireName = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : '__parcel__require__';
|
|
213
|
+
|
|
214
|
+
// @ts-expect-error TS7006
|
|
215
|
+
const fallbackUrls = cond => {
|
|
216
|
+
return `[${[...cond.ifTrueBundles, ...cond.ifFalseBundles].map(target => {
|
|
217
|
+
let relativePathExpr = getRelativePathExpr(bundle, target, options);
|
|
218
|
+
return getAbsoluteUrlExpr(relativePathExpr, bundle, config.domainSharding);
|
|
219
|
+
}).join(',')}]`;
|
|
220
|
+
};
|
|
221
|
+
const shouldUseFallback = options.mode === 'development' ? (0, _featureFlags().getFeatureFlag)('condbDevFallbackDev') : (0, _featureFlags().getFeatureFlag)('condbDevFallbackProd');
|
|
222
|
+
const loaderPath = `./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}`;
|
|
223
|
+
const ifTrue = `function (){return ${requireName}('${cond.ifTrueAssetId}')}`;
|
|
224
|
+
const ifFalse = `function (){return ${requireName}('${cond.ifFalseAssetId}')}`;
|
|
225
|
+
const assetCode = `module.exports = require('${loaderPath}')('${cond.key}', ${ifTrue}, ${ifFalse}${shouldUseFallback ? `, {loader: require('./helpers/browser/sync-js-loader'), urls: ${fallbackUrls(cond)}}` : ''})`;
|
|
210
226
|
assets.push({
|
|
211
|
-
filePath: _path().default.join(__dirname, `/conditions
|
|
227
|
+
filePath: _path().default.join(__dirname, `/conditions-${cond.publicId}.js`),
|
|
212
228
|
code: assetCode,
|
|
213
229
|
// This dependency is important, as it's the last symbol handled in scope hoisting.
|
|
214
230
|
// That means that scope hoisting will use the module id for this asset to replace the symbol
|
|
@@ -224,7 +240,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
224
240
|
// Resolve the dependency to a bundle. If inline, export the dependency id,
|
|
225
241
|
// which will be replaced with the contents of that bundle later.
|
|
226
242
|
let referencedBundle = bundleGraph.getReferencedBundle(dependency, bundle);
|
|
227
|
-
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline') {
|
|
243
|
+
if ((referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inline' || (referencedBundle === null || referencedBundle === void 0 ? void 0 : referencedBundle.bundleBehavior) === 'inlineIsolated') {
|
|
228
244
|
assets.push({
|
|
229
245
|
filePath: _path().default.join(__dirname, `/bundles/${referencedBundle.id}.js`),
|
|
230
246
|
code: `module.exports = ${JSON.stringify(dependency.id)};`,
|
|
@@ -263,7 +279,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
263
279
|
|
|
264
280
|
// Skip URL runtimes for library builds. This is handled in packaging so that
|
|
265
281
|
// the url is inlined and statically analyzable.
|
|
266
|
-
if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated') {
|
|
282
|
+
if (bundle.env.isLibrary && mainBundle.bundleBehavior !== 'isolated' && mainBundle.bundleBehavior !== 'inlineIsolated') {
|
|
267
283
|
continue;
|
|
268
284
|
}
|
|
269
285
|
|
|
@@ -297,7 +313,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
297
313
|
});
|
|
298
314
|
}
|
|
299
315
|
}
|
|
300
|
-
if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline') && isNewContext(bundle, bundleGraph)) {
|
|
316
|
+
if (shouldUseRuntimeManifest(bundle, options) && bundleGraph.getChildBundles(bundle).some(b => b.bundleBehavior !== 'inline' && b.bundleBehavior !== 'inlineIsolated') && isNewContext(bundle, bundleGraph)) {
|
|
301
317
|
assets.push({
|
|
302
318
|
filePath: __filename,
|
|
303
319
|
code: getRegisterCode(bundle, bundleGraph),
|
|
@@ -305,6 +321,7 @@ var _default = exports.default = new (_plugin().Runtime)({
|
|
|
305
321
|
env: {
|
|
306
322
|
sourceType: 'module'
|
|
307
323
|
},
|
|
324
|
+
runtimeAssetRequiringExecutionOnLoad: true,
|
|
308
325
|
priority: getManifestBundlePriority(bundleGraph, bundle, config.splitManifestThreshold)
|
|
309
326
|
});
|
|
310
327
|
}
|
|
@@ -357,10 +374,16 @@ function getLoaderRuntime({
|
|
|
357
374
|
return;
|
|
358
375
|
}
|
|
359
376
|
let externalBundles = bundleGraph.getBundlesInBundleGroup(bundleGroup);
|
|
360
|
-
let
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
}
|
|
377
|
+
let potentialMainBundle;
|
|
378
|
+
if ((0, _featureFlags().getFeatureFlag)('supportWebpackChunkName')) {
|
|
379
|
+
potentialMainBundle = externalBundles.find(bundle => bundle.getEntryAssets().some(asset => asset.id === bundleGroup.entryAssetId));
|
|
380
|
+
} else {
|
|
381
|
+
potentialMainBundle = externalBundles.find(bundle => {
|
|
382
|
+
var _bundle$getMainEntry;
|
|
383
|
+
return ((_bundle$getMainEntry = bundle.getMainEntry()) === null || _bundle$getMainEntry === void 0 ? void 0 : _bundle$getMainEntry.id) === bundleGroup.entryAssetId;
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
let mainBundle = (0, _nullthrows().default)(potentialMainBundle);
|
|
364
387
|
|
|
365
388
|
// CommonJS is a synchronous module system, so there is no need to load bundles in parallel.
|
|
366
389
|
// Importing of the other bundles will be handled by the bundle group entry.
|
|
@@ -385,6 +408,7 @@ function getLoaderRuntime({
|
|
|
385
408
|
let needsEsmLoadPrelude = false;
|
|
386
409
|
let loaderModules = [];
|
|
387
410
|
function getLoaderForBundle(bundle, to, shardingConfig) {
|
|
411
|
+
// @ts-expect-error TS18049
|
|
388
412
|
let loader = loaders[to.type];
|
|
389
413
|
if (!loader) {
|
|
390
414
|
return;
|
|
@@ -400,7 +424,11 @@ function getLoaderRuntime({
|
|
|
400
424
|
if (!needsDynamicImportPolyfill) {
|
|
401
425
|
return `__parcel__import__("./" + ${relativePathExpr})`;
|
|
402
426
|
}
|
|
403
|
-
|
|
427
|
+
|
|
428
|
+
// @ts-expect-error TS2322
|
|
429
|
+
loader = (0, _nullthrows().default)(
|
|
430
|
+
// @ts-expect-error TS18049
|
|
431
|
+
loaders.IMPORT_POLYFILL, `No import() polyfill available for context '${bundle.env.context}'`);
|
|
404
432
|
} else if (to.type === 'js' && to.env.outputFormat === 'commonjs') {
|
|
405
433
|
return `Promise.resolve(__parcel__require__("./" + ${relativePathExpr}))`;
|
|
406
434
|
}
|
|
@@ -434,8 +462,16 @@ function getLoaderRuntime({
|
|
|
434
462
|
const loaders = [];
|
|
435
463
|
for (const cond of conditions) {
|
|
436
464
|
// This bundle has a conditional dependency, we need to load the bundle group
|
|
437
|
-
const ifTrueLoaders = cond.ifTrueBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
|
|
438
|
-
|
|
465
|
+
const ifTrueLoaders = cond.ifTrueBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
|
|
466
|
+
// @ts-expect-error TS2769
|
|
467
|
+
cond.ifTrueBundles.map(targetBundle =>
|
|
468
|
+
// @ts-expect-error TS2554
|
|
469
|
+
getLoaderForBundle(sourceBundle, targetBundle)));
|
|
470
|
+
const ifFalseLoaders = cond.ifFalseBundles.flatMap(targetBundle => getConditionalLoadersForCondition(getDependencies(targetBundle).conditionalDependencies, targetBundle)).concat(
|
|
471
|
+
// @ts-expect-error TS2769
|
|
472
|
+
cond.ifFalseBundles.map(targetBundle =>
|
|
473
|
+
// @ts-expect-error TS2554
|
|
474
|
+
getLoaderForBundle(sourceBundle, targetBundle)));
|
|
439
475
|
if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
|
|
440
476
|
// Load conditional bundles with helper (and a dev mode with additional hints)
|
|
441
477
|
loaders.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
|
|
@@ -444,21 +480,8 @@ function getLoaderRuntime({
|
|
|
444
480
|
return loaders;
|
|
445
481
|
}
|
|
446
482
|
if ((0, _featureFlags().getFeatureFlag)('conditionalBundlingApi')) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
loaderModules.push(...getConditionalLoadersForCondition(conditionalDependencies, bundle));
|
|
450
|
-
} else {
|
|
451
|
-
let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
|
|
452
|
-
for (const cond of bundleGraph.getConditionsForDependencies(conditionalDependencies, bundle)) {
|
|
453
|
-
// This bundle has a conditional dependency, we need to load the bundle group
|
|
454
|
-
const ifTrueLoaders = cond.ifTrueBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
|
|
455
|
-
const ifFalseLoaders = cond.ifFalseBundles.map(targetBundle => getLoaderForBundle(bundle, targetBundle));
|
|
456
|
-
if (ifTrueLoaders.length > 0 || ifFalseLoaders.length > 0) {
|
|
457
|
-
// Load conditional bundles with helper (and a dev mode with additional hints)
|
|
458
|
-
loaderModules.push(`require('./helpers/conditional-loader${options.mode === 'development' ? '-dev' : ''}')('${cond.key}', function (){return Promise.all([${ifTrueLoaders.join(',')}]);}, function (){return Promise.all([${ifFalseLoaders.join(',')}]);})`);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
483
|
+
let conditionalDependencies = externalBundles.flatMap(to => getDependencies(to).conditionalDependencies);
|
|
484
|
+
loaderModules.push(...getConditionalLoadersForCondition(conditionalDependencies, bundle));
|
|
462
485
|
}
|
|
463
486
|
for (let to of externalBundles) {
|
|
464
487
|
let loaderModule = getLoaderForBundle(bundle, to, shardingConfig);
|
|
@@ -488,7 +511,7 @@ function getLoaderRuntime({
|
|
|
488
511
|
loaderCode = `(${loaderCode})`;
|
|
489
512
|
}
|
|
490
513
|
if (mainBundle.type === 'js') {
|
|
491
|
-
let parcelRequire = bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
|
|
514
|
+
let parcelRequire = (0, _featureFlags().getFeatureFlag)('hmrImprovements') || bundle.env.shouldScopeHoist ? 'parcelRequire' : 'module.bundle.root';
|
|
492
515
|
loaderCode += `.then(() => ${parcelRequire}('${bundleGraph.getAssetPublicId(bundleGraph.getAssetById(bundleGroup.entryAssetId))}'))`;
|
|
493
516
|
}
|
|
494
517
|
if (needsEsmLoadPrelude && options.featureFlags.importRetry) {
|
|
@@ -534,14 +557,16 @@ function getHintedBundleGroups(bundleGraph, bundle) {
|
|
|
534
557
|
var _dependency$meta;
|
|
535
558
|
let attributes = (_dependency$meta = dependency.meta) === null || _dependency$meta === void 0 ? void 0 : _dependency$meta.importAttributes;
|
|
536
559
|
if (typeof attributes === 'object' && attributes != null && (
|
|
537
|
-
//
|
|
560
|
+
// @ts-expect-error TS2339
|
|
538
561
|
attributes.preload || attributes.prefetch)) {
|
|
539
562
|
let resolved = bundleGraph.resolveAsyncDependency(dependency, bundle);
|
|
540
563
|
if ((resolved === null || resolved === void 0 ? void 0 : resolved.type) === 'bundle_group') {
|
|
541
564
|
// === true for flow
|
|
565
|
+
// @ts-expect-error TS2339
|
|
542
566
|
if (attributes.preload === true) {
|
|
543
567
|
preload.push(resolved.value);
|
|
544
568
|
}
|
|
569
|
+
// @ts-expect-error TS2339
|
|
545
570
|
if (attributes.prefetch === true) {
|
|
546
571
|
prefetch.push(resolved.value);
|
|
547
572
|
}
|
|
@@ -559,8 +584,11 @@ function getHintLoaders(bundleGraph, from, bundleGroups, loader, options) {
|
|
|
559
584
|
let bundlesToPreload = bundleGraph.getBundlesInBundleGroup(bundleGroupToPreload);
|
|
560
585
|
for (let bundleToPreload of bundlesToPreload) {
|
|
561
586
|
let relativePathExpr = getRelativePathExpr(from, bundleToPreload, options);
|
|
587
|
+
// @ts-expect-error TS7053
|
|
562
588
|
let priority = TYPE_TO_RESOURCE_PRIORITY[bundleToPreload.type];
|
|
563
|
-
hintLoaders.push(
|
|
589
|
+
hintLoaders.push(
|
|
590
|
+
// @ts-expect-error TS2554
|
|
591
|
+
`require(${JSON.stringify(loader)})(${getAbsoluteUrlExpr(relativePathExpr, from)}, ${priority ? JSON.stringify(priority) : 'null'}, ${JSON.stringify(bundleToPreload.target.env.outputFormat === 'esmodule')})`);
|
|
564
592
|
}
|
|
565
593
|
}
|
|
566
594
|
return hintLoaders;
|
|
@@ -571,7 +599,12 @@ function isNewContext(bundle, bundleGraph) {
|
|
|
571
599
|
return isInEntryBundleGroup || parents.length === 0 || parents.some(parent => parent.env.context !== bundle.env.context || parent.type !== 'js');
|
|
572
600
|
}
|
|
573
601
|
function getURLRuntime(dependency, from, to, options, shardingConfig) {
|
|
574
|
-
let relativePathExpr
|
|
602
|
+
let relativePathExpr;
|
|
603
|
+
if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
|
|
604
|
+
relativePathExpr = getRelativePathExpr(from, to, options, true);
|
|
605
|
+
} else {
|
|
606
|
+
relativePathExpr = getRelativePathExpr(from, to, options);
|
|
607
|
+
}
|
|
575
608
|
let code;
|
|
576
609
|
if (dependency.meta.webworker === true && !from.env.isLibrary) {
|
|
577
610
|
code = `let workerURL = require('./helpers/get-worker-url');\n`;
|
|
@@ -599,9 +632,10 @@ function getURLRuntime(dependency, from, to, options, shardingConfig) {
|
|
|
599
632
|
};
|
|
600
633
|
}
|
|
601
634
|
function getRegisterCode(entryBundle, bundleGraph) {
|
|
635
|
+
// @ts-expect-error TS2304
|
|
602
636
|
let mappings = [];
|
|
603
637
|
bundleGraph.traverseBundles((bundle, _, actions) => {
|
|
604
|
-
if (bundle.bundleBehavior === 'inline') {
|
|
638
|
+
if (bundle.bundleBehavior === 'inline' || bundle.bundleBehavior === 'inlineIsolated') {
|
|
605
639
|
return;
|
|
606
640
|
}
|
|
607
641
|
|
|
@@ -625,13 +659,19 @@ function getRegisterCode(entryBundle, bundleGraph) {
|
|
|
625
659
|
: `require('./helpers/bundle-url').getBundleURL('${entryBundle.publicId}')`;
|
|
626
660
|
return `require('./helpers/bundle-manifest').register(${baseUrl},JSON.parse(${JSON.stringify(JSON.stringify(mappings))}));`;
|
|
627
661
|
}
|
|
628
|
-
function getRelativePathExpr(from, to, options) {
|
|
662
|
+
function getRelativePathExpr(from, to, options, isURL = to.type !== 'js') {
|
|
629
663
|
let relativePath = (0, _utils().relativeBundlePath)(from, to, {
|
|
630
664
|
leadingDotSlash: false
|
|
631
665
|
});
|
|
632
666
|
let res = JSON.stringify(relativePath);
|
|
633
|
-
if (
|
|
634
|
-
|
|
667
|
+
if ((0, _featureFlags().getFeatureFlag)('hmrImprovements')) {
|
|
668
|
+
if (isURL && options.hmrOptions) {
|
|
669
|
+
res += ' + "?" + Date.now()';
|
|
670
|
+
}
|
|
671
|
+
} else {
|
|
672
|
+
if (options.hmrOptions) {
|
|
673
|
+
res += ' + "?" + Date.now()';
|
|
674
|
+
}
|
|
635
675
|
}
|
|
636
676
|
return res;
|
|
637
677
|
}
|
|
@@ -648,7 +688,7 @@ function getAbsoluteUrlExpr(relativePathExpr, fromBundle, shardingConfig) {
|
|
|
648
688
|
}
|
|
649
689
|
function shouldUseRuntimeManifest(bundle, options) {
|
|
650
690
|
let env = bundle.env;
|
|
651
|
-
return !env.isLibrary && bundle.bundleBehavior !== 'inline' && env.isBrowser() && options.mode === 'production';
|
|
691
|
+
return !env.isLibrary && bundle.bundleBehavior !== 'inline' && bundle.bundleBehavior !== 'inlineIsolated' && env.isBrowser() && options.mode === 'production';
|
|
652
692
|
}
|
|
653
693
|
function getManifestBundlePriority(bundleGraph, bundle, threshold) {
|
|
654
694
|
let bundleSize = 0;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadCSSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same link element twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingLinks = document.getElementsByTagName('link');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (link) {
|
|
9
9
|
return link.href === bundle && link.rel.indexOf('stylesheet') > -1;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingLinks).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function importModule(bundle) {
|
|
5
5
|
return new Promise((resolve, reject) => {
|
|
6
6
|
// Add a global function to handle when the script loads.
|
|
7
7
|
let globalName = `i${('' + Math.random()).slice(2)}`;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadJSBundle(bundle) {
|
|
5
5
|
return new Promise(function (resolve, reject) {
|
|
6
6
|
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
|
7
7
|
let existingScripts = document.getElementsByTagName('script');
|
|
8
|
-
|
|
8
|
+
let isCurrentBundle = function (script) {
|
|
9
9
|
return script.src === bundle;
|
|
10
|
-
}
|
|
10
|
+
};
|
|
11
|
+
if ([].concat(existingScripts).some(isCurrentBundle)) {
|
|
11
12
|
resolve();
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority) {
|
|
4
|
+
module.exports = cacheLoader(function prefetchJSBundle(bundle, priority) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.rel = 'prefetch';
|
|
7
7
|
link.href = bundle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle, priority, isModule) {
|
|
4
|
+
module.exports = cacheLoader(function preloadJSBundle(bundle, priority, isModule) {
|
|
5
5
|
var link = document.createElement('link');
|
|
6
6
|
link.charset = 'utf-8';
|
|
7
7
|
link.rel = isModule ? 'modulepreload' : 'preload';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const cacheLoader = require('../cacheLoader');
|
|
4
|
+
module.exports = function loadJSBundle(bundle) {
|
|
5
|
+
// Don't insert the same script twice (e.g. if it was already in the HTML)
|
|
6
|
+
let existingScripts = document.getElementsByTagName('script');
|
|
7
|
+
let isCurrentBundle = function (script) {
|
|
8
|
+
return script.src === bundle;
|
|
9
|
+
};
|
|
10
|
+
if ([].concat(existingScripts).some(isCurrentBundle)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Request using XHR because it's synchronous and we can't use promises here
|
|
15
|
+
// This has extremely poor performance because we're idle during this fetch, so we only use this so that the app won't crash
|
|
16
|
+
const xhr = new XMLHttpRequest();
|
|
17
|
+
xhr.open('GET', bundle, false);
|
|
18
|
+
try {
|
|
19
|
+
xhr.send();
|
|
20
|
+
if (xhr.status === 200) {
|
|
21
|
+
const script = document.createElement('script');
|
|
22
|
+
script.type = 'text/javascript';
|
|
23
|
+
script.text = xhr.responseText;
|
|
24
|
+
|
|
25
|
+
// Execute the script synchronously
|
|
26
|
+
document.head.appendChild(script);
|
|
27
|
+
} else {
|
|
28
|
+
throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Status: ${xhr.status}`);
|
|
29
|
+
}
|
|
30
|
+
} catch (e) {
|
|
31
|
+
throw new TypeError(`Failed to fetch dynamically imported module: ${bundle}. Error: ${e.message}`);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
const cacheLoader = require('../cacheLoader');
|
|
4
|
-
module.exports = cacheLoader(function (bundle) {
|
|
4
|
+
module.exports = cacheLoader(function loadWASMBundle(bundle) {
|
|
5
5
|
return fetch(bundle).then(function (res) {
|
|
6
6
|
if (WebAssembly.instantiateStreaming) {
|
|
7
7
|
return WebAssembly.instantiateStreaming(res);
|