@atlaspack/packager-html 2.14.5-canary.17 → 2.14.5-canary.171

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 CHANGED
@@ -1,5 +1,222 @@
1
1
  # @atlaspack/packager-html
2
2
 
3
+ ## 2.15.9
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
8
+ - @atlaspack/feature-flags@2.23.2
9
+ - @atlaspack/utils@2.18.4
10
+ - @atlaspack/plugin@2.14.27
11
+ - @atlaspack/types@2.15.17
12
+
13
+ ## 2.15.8
14
+
15
+ ### Patch Changes
16
+
17
+ - [#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
18
+
19
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd), [`889c65c`](https://github.com/atlassian-labs/atlaspack/commit/889c65cd25b811045e26a117e7404f694dde77a2)]:
20
+ - @atlaspack/feature-flags@2.23.1
21
+ - @atlaspack/plugin@2.14.26
22
+ - @atlaspack/types@2.15.16
23
+ - @atlaspack/utils@2.18.3
24
+
25
+ ## 2.15.7
26
+
27
+ ### Patch Changes
28
+
29
+ - Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
30
+ - @atlaspack/feature-flags@2.23.0
31
+ - @atlaspack/utils@2.18.2
32
+ - @atlaspack/plugin@2.14.25
33
+ - @atlaspack/types@2.15.15
34
+
35
+ ## 2.15.6
36
+
37
+ ### Patch Changes
38
+
39
+ - Updated dependencies [[`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
40
+ - @atlaspack/feature-flags@2.22.0
41
+ - @atlaspack/utils@2.18.1
42
+ - @atlaspack/plugin@2.14.24
43
+ - @atlaspack/types@2.15.14
44
+
45
+ ## 2.15.5
46
+
47
+ ### Patch Changes
48
+
49
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
50
+ - @atlaspack/feature-flags@2.21.0
51
+ - @atlaspack/utils@2.18.0
52
+ - @atlaspack/types@2.15.13
53
+ - @atlaspack/plugin@2.14.23
54
+
55
+ ## 2.15.4
56
+
57
+ ### Patch Changes
58
+
59
+ - [#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
60
+
61
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94), [`12bee0e`](https://github.com/atlassian-labs/atlaspack/commit/12bee0e23f0464d7f6bd3e24fbe0d19c126d587d)]:
62
+ - @atlaspack/feature-flags@2.20.1
63
+ - @atlaspack/plugin@2.14.22
64
+ - @atlaspack/types@2.15.12
65
+ - @atlaspack/utils@2.17.4
66
+
67
+ ## 2.15.3
68
+
69
+ ### Patch Changes
70
+
71
+ - Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
72
+ - @atlaspack/feature-flags@2.20.0
73
+ - @atlaspack/types@2.15.11
74
+ - @atlaspack/utils@2.17.3
75
+ - @atlaspack/plugin@2.14.21
76
+
77
+ ## 2.15.2
78
+
79
+ ### Patch Changes
80
+
81
+ - [#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
82
+
83
+ - 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)]:
84
+ - @atlaspack/plugin@2.14.20
85
+ - @atlaspack/feature-flags@2.19.2
86
+ - @atlaspack/utils@2.17.2
87
+ - @atlaspack/types@2.15.10
88
+
89
+ ## 2.15.1
90
+
91
+ ### Patch Changes
92
+
93
+ - Updated dependencies [[`13aef17`](https://github.com/atlassian-labs/atlaspack/commit/13aef177eea289a6e40d2113b5ec1ac9be18a33d)]:
94
+ - @atlaspack/feature-flags@2.19.1
95
+ - @atlaspack/utils@2.17.1
96
+ - @atlaspack/types@2.15.9
97
+ - @atlaspack/plugin@2.14.19
98
+
99
+ ## 2.15.0
100
+
101
+ ### Minor Changes
102
+
103
+ - [#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
104
+
105
+ ### Patch Changes
106
+
107
+ - 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)]:
108
+ - @atlaspack/feature-flags@2.19.0
109
+ - @atlaspack/utils@2.17.0
110
+ - @atlaspack/types@2.15.8
111
+ - @atlaspack/plugin@2.14.18
112
+
113
+ ## 2.14.17
114
+
115
+ ### Patch Changes
116
+
117
+ - Updated dependencies []:
118
+ - @atlaspack/utils@2.16.1
119
+ - @atlaspack/types@2.15.7
120
+ - @atlaspack/plugin@2.14.17
121
+
122
+ ## 2.14.16
123
+
124
+ ### Patch Changes
125
+
126
+ - Updated dependencies [[`e8a60ff`](https://github.com/atlassian-labs/atlaspack/commit/e8a60ffbea41caef265786bbf73349771760081c), [`30ee2cf`](https://github.com/atlassian-labs/atlaspack/commit/30ee2cfcd34cf2646ded0eda13fdb80a2a5de529)]:
127
+ - @atlaspack/feature-flags@2.18.4
128
+ - @atlaspack/utils@2.16.0
129
+ - @atlaspack/types@2.15.6
130
+ - @atlaspack/plugin@2.14.16
131
+
132
+ ## 2.14.15
133
+
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [[`5ded263`](https://github.com/atlassian-labs/atlaspack/commit/5ded263c7f11b866e8885b81c73e20dd060b25be)]:
137
+ - @atlaspack/feature-flags@2.18.3
138
+ - @atlaspack/utils@2.15.3
139
+ - @atlaspack/types@2.15.5
140
+ - @atlaspack/plugin@2.14.15
141
+
142
+ ## 2.14.14
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [[`644b157`](https://github.com/atlassian-labs/atlaspack/commit/644b157dee72a871acc2d0facf0b87b8eea51956)]:
147
+ - @atlaspack/feature-flags@2.18.2
148
+ - @atlaspack/utils@2.15.2
149
+ - @atlaspack/types@2.15.4
150
+ - @atlaspack/plugin@2.14.14
151
+
152
+ ## 2.14.13
153
+
154
+ ### Patch Changes
155
+
156
+ - Updated dependencies [[`26aa9c5`](https://github.com/atlassian-labs/atlaspack/commit/26aa9c599d2be45ce1438a74c5fa22f39b9b554b), [`0501255`](https://github.com/atlassian-labs/atlaspack/commit/05012550da35b05ce7d356a8cc29311e7f9afdca)]:
157
+ - @atlaspack/feature-flags@2.18.1
158
+ - @atlaspack/types@2.15.3
159
+ - @atlaspack/utils@2.15.1
160
+ - @atlaspack/plugin@2.14.13
161
+
162
+ ## 2.14.12
163
+
164
+ ### Patch Changes
165
+
166
+ - 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)]:
167
+ - @atlaspack/feature-flags@2.18.0
168
+ - @atlaspack/utils@2.15.0
169
+ - @atlaspack/types@2.15.2
170
+ - @atlaspack/plugin@2.14.12
171
+
172
+ ## 2.14.11
173
+
174
+ ### Patch Changes
175
+
176
+ - [#623](https://github.com/atlassian-labs/atlaspack/pull/623) [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef) Thanks [@JakeLane](https://github.com/JakeLane)! - Load same conditional bundles as conditional manifest in HTML
177
+
178
+ - Updated dependencies [[`73ea3c4`](https://github.com/atlassian-labs/atlaspack/commit/73ea3c4d85d4401fdd15abcbf988237e890e7ad3), [`b1b3693`](https://github.com/atlassian-labs/atlaspack/commit/b1b369317c66f8a431c170df2ebba4fa5b2e38ef)]:
179
+ - @atlaspack/feature-flags@2.17.0
180
+ - @atlaspack/utils@2.14.11
181
+ - @atlaspack/types@2.15.1
182
+ - @atlaspack/plugin@2.14.11
183
+
184
+ ## 2.14.10
185
+
186
+ ### Patch Changes
187
+
188
+ - Updated dependencies [[`51aba5f`](https://github.com/atlassian-labs/atlaspack/commit/51aba5fc0e49235ee06bbc3c376f48c3e7da5c4b), [`1e32d4e`](https://github.com/atlassian-labs/atlaspack/commit/1e32d4eae6b3af3968e8a0ef97d35b4347fd4196)]:
189
+ - @atlaspack/types@2.15.0
190
+ - @atlaspack/plugin@2.14.10
191
+ - @atlaspack/utils@2.14.10
192
+
193
+ ## 2.14.9
194
+
195
+ ### Patch Changes
196
+
197
+ - Updated dependencies []:
198
+ - @atlaspack/utils@2.14.9
199
+ - @atlaspack/types@2.14.9
200
+ - @atlaspack/plugin@2.14.9
201
+
202
+ ## 2.14.8
203
+
204
+ ### Patch Changes
205
+
206
+ - Updated dependencies []:
207
+ - @atlaspack/utils@2.14.8
208
+ - @atlaspack/types@2.14.8
209
+ - @atlaspack/plugin@2.14.8
210
+
211
+ ## 2.14.7
212
+
213
+ ### Patch Changes
214
+
215
+ - Updated dependencies []:
216
+ - @atlaspack/utils@2.14.7
217
+ - @atlaspack/types@2.14.7
218
+ - @atlaspack/plugin@2.14.7
219
+
3
220
  ## 2.14.6
4
221
 
5
222
  ### Patch Changes
@@ -64,8 +64,10 @@ var _default = exports.default = new (_plugin().Packager)({
64
64
  packageKey: '@atlaspack/packager-html'
65
65
  });
66
66
  return {
67
+ // @ts-expect-error TS2339
67
68
  render: posthtmlConfig === null || posthtmlConfig === void 0 || (_posthtmlConfig$conte = posthtmlConfig.contents) === null || _posthtmlConfig$conte === void 0 ? void 0 : _posthtmlConfig$conte.render,
68
- evaluateRootConditionalBundles: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.evaluateRootConditionalBundles)
69
+ evaluateRootConditionalBundles: Boolean( // @ts-expect-error TS2339
70
+ conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.evaluateRootConditionalBundles)
69
71
  };
70
72
  },
71
73
  async package({
@@ -74,6 +76,7 @@ var _default = exports.default = new (_plugin().Packager)({
74
76
  getInlineBundleContents,
75
77
  config
76
78
  }) {
79
+ // @ts-expect-error TS2552
77
80
  let assets = [];
78
81
  bundle.traverseAssets(asset => {
79
82
  assets.push(asset);
@@ -88,11 +91,13 @@ var _default = exports.default = new (_plugin().Packager)({
88
91
  let referencedBundles = [...(0, _utils().setSymmetricDifference)(new Set(referencedBundlesRecursive), new Set(bundleGraph.getReferencedBundles(bundle, {
89
92
  recursive: false
90
93
  })))];
91
- let conditionalBundles = config.evaluateRootConditionalBundles ? (0, _utils().setDifference)(new Set([...referencedBundlesRecursive.flatMap(referencedBundle => bundleGraph.getReferencedConditionalBundles(referencedBundle))]), new Set(referencedBundles)) : new Set();
94
+ let conditionalBundles = config.evaluateRootConditionalBundles ? (0, _utils().setDifference)(getReferencedConditionalScripts(bundleGraph, referencedBundlesRecursive), new Set(referencedBundles)) : new Set();
92
95
  let renderConfig = config === null || config === void 0 ? void 0 : config.render;
93
96
  let {
94
97
  html
95
- } = await (0, _posthtml().default)([tree => insertBundleReferences([...conditionalBundles, ...referencedBundles], tree, conditionalBundles), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
98
+ } = await (0, _posthtml().default)([tree => insertBundleReferences(
99
+ // @ts-expect-error TS2345
100
+ [...conditionalBundles, ...referencedBundles], tree, conditionalBundles), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
96
101
  ...renderConfig,
97
102
  xmlMode: bundle.type === 'xhtml',
98
103
  closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
@@ -142,6 +147,7 @@ async function getAssetContent(bundleGraph, getInlineBundleContents, assetId) {
142
147
  }
143
148
  async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree) {
144
149
  const inlineNodes = [];
150
+ // @ts-expect-error TS7006
145
151
  tree.walk(node => {
146
152
  if (node.attrs && node.attrs['data-parcel-key']) {
147
153
  inlineNodes.push(node);
@@ -206,14 +212,18 @@ function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
206
212
  }
207
213
  addBundlesToTree(bundles, tree);
208
214
  }
215
+
216
+ // @ts-expect-error TS7006
209
217
  function addBundlesToTree(bundles, tree) {
210
218
  const main = find(tree, 'head') || find(tree, 'html');
219
+ // @ts-expect-error TS2339
211
220
  const content = main ? main.content || (main.content = []) : tree;
212
221
  const index = findBundleInsertIndex(content);
213
222
  content.splice(index, 0, ...bundles);
214
223
  }
215
224
  function find(tree, tag) {
216
225
  let res;
226
+ // @ts-expect-error TS7006
217
227
  tree.match({
218
228
  tag
219
229
  }, node => {
@@ -243,4 +253,20 @@ function findBundleInsertIndex(content) {
243
253
  }
244
254
  }
245
255
  return doctypeIndex ? doctypeIndex + 1 : 0;
256
+ }
257
+ function getReferencedConditionalScripts(bundleGraph, referencedBundles) {
258
+ const conditionalBundleMapping = bundleGraph.getConditionalBundleMapping();
259
+ const bundles = [];
260
+ for (const bundle of referencedBundles) {
261
+ const conditions = conditionalBundleMapping.get(bundle.id);
262
+ if (conditions) {
263
+ for (const [, cond] of conditions) {
264
+ // Reverse so dependent bundles are loaded first
265
+ const dependentBundles = [...cond.ifTrueBundles.reverse(), ...cond.ifFalseBundles.reverse()];
266
+ bundles.push(...dependentBundles);
267
+ referencedBundles.push(...dependentBundles);
268
+ }
269
+ }
270
+ }
271
+ return new Set(bundles);
246
272
  }
@@ -0,0 +1,3 @@
1
+ import { Packager } from '@atlaspack/plugin';
2
+ declare const _default: Packager<unknown, unknown>;
3
+ export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaspack/packager-html",
3
- "version": "2.14.5-canary.17+a1773d2a6",
3
+ "version": "2.14.5-canary.171+f0349a6b9",
4
4
  "license": "(MIT OR Apache-2.0)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -9,18 +9,24 @@
9
9
  "type": "git",
10
10
  "url": "https://github.com/atlassian-labs/atlaspack.git"
11
11
  },
12
- "main": "lib/HTMLPackager.js",
13
- "source": "src/HTMLPackager.js",
12
+ "main": "./lib/HTMLPackager.js",
13
+ "source": "./src/HTMLPackager.ts",
14
+ "types": "./lib/types/HTMLPackager.d.ts",
14
15
  "engines": {
15
16
  "node": ">= 16.0.0"
16
17
  },
17
18
  "dependencies": {
18
- "@atlaspack/plugin": "2.14.5-canary.17+a1773d2a6",
19
- "@atlaspack/types": "2.14.5-canary.17+a1773d2a6",
20
- "@atlaspack/utils": "2.14.5-canary.17+a1773d2a6",
19
+ "@atlaspack/feature-flags": "2.14.1-canary.239+f0349a6b9",
20
+ "@atlaspack/plugin": "2.14.5-canary.171+f0349a6b9",
21
+ "@atlaspack/types": "2.14.5-canary.171+f0349a6b9",
22
+ "@atlaspack/utils": "2.14.5-canary.171+f0349a6b9",
21
23
  "nullthrows": "^1.1.1",
22
24
  "posthtml": "^0.16.5"
23
25
  },
24
26
  "type": "commonjs",
25
- "gitHead": "a1773d2a62d0ef7805ac7524621dcabcc1afe929"
27
+ "scripts": {
28
+ "check-ts": "tsc --emitDeclarationOnly --rootDir src",
29
+ "build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
30
+ },
31
+ "gitHead": "f0349a6b9b04755088f121095ca6301a2ada3767"
26
32
  }
@@ -1,4 +1,3 @@
1
- // @flow strict-local
2
1
  import type {Bundle, BundleGraph, NamedBundle} from '@atlaspack/types';
3
2
 
4
3
  import assert from 'assert';
@@ -26,7 +25,7 @@ const metadataContent = new Set([
26
25
  'title',
27
26
  ]);
28
27
 
29
- export default (new Packager({
28
+ export default new Packager({
30
29
  async loadConfig({config, options}) {
31
30
  let posthtmlConfig = await config.getConfig(
32
31
  [
@@ -48,14 +47,17 @@ export default (new Packager({
48
47
  });
49
48
 
50
49
  return {
50
+ // @ts-expect-error TS2339
51
51
  render: posthtmlConfig?.contents?.render,
52
52
  evaluateRootConditionalBundles: Boolean(
53
+ // @ts-expect-error TS2339
53
54
  conf?.contents?.evaluateRootConditionalBundles,
54
55
  ),
55
56
  };
56
57
  },
57
58
  async package({bundle, bundleGraph, getInlineBundleContents, config}) {
58
- let assets = [];
59
+ // @ts-expect-error TS2552
60
+ let assets: Array<Asset> = [];
59
61
  bundle.traverseAssets((asset) => {
60
62
  assets.push(asset);
61
63
  });
@@ -77,25 +79,24 @@ export default (new Packager({
77
79
 
78
80
  let conditionalBundles = config.evaluateRootConditionalBundles
79
81
  ? setDifference(
80
- new Set([
81
- ...referencedBundlesRecursive.flatMap((referencedBundle) =>
82
- bundleGraph.getReferencedConditionalBundles(referencedBundle),
83
- ),
84
- ]),
82
+ getReferencedConditionalScripts(
83
+ bundleGraph,
84
+ referencedBundlesRecursive,
85
+ ),
85
86
  new Set(referencedBundles),
86
87
  )
87
88
  : new Set();
88
-
89
89
  let renderConfig = config?.render;
90
90
 
91
91
  let {html} = await posthtml([
92
- (tree) =>
92
+ (tree: any) =>
93
93
  insertBundleReferences(
94
+ // @ts-expect-error TS2345
94
95
  [...conditionalBundles, ...referencedBundles],
95
96
  tree,
96
97
  conditionalBundles,
97
98
  ),
98
- (tree) =>
99
+ (tree: any) =>
99
100
  replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree),
100
101
  ]).process(code, {
101
102
  ...renderConfig,
@@ -123,14 +124,20 @@ export default (new Packager({
123
124
  map,
124
125
  });
125
126
  },
126
- }): Packager);
127
+ }) as Packager<unknown, unknown>;
127
128
 
128
129
  async function getAssetContent(
129
130
  bundleGraph: BundleGraph<NamedBundle>,
130
- getInlineBundleContents,
131
- assetId,
131
+ getInlineBundleContents: (
132
+ arg1: Bundle,
133
+ arg2: BundleGraph<NamedBundle>,
134
+ // @ts-expect-error TS2304
135
+ ) => Async<{
136
+ contents: Blob;
137
+ }>,
138
+ assetId: any,
132
139
  ) {
133
- let inlineBundle: ?Bundle;
140
+ let inlineBundle: Bundle | null | undefined;
134
141
  bundleGraph.traverseBundles((bundle, context, {stop}) => {
135
142
  let entryAssets = bundle.getEntryAssets();
136
143
  if (entryAssets.some((a) => a.uniqueKey === assetId)) {
@@ -153,10 +160,17 @@ async function getAssetContent(
153
160
 
154
161
  async function replaceInlineAssetContent(
155
162
  bundleGraph: BundleGraph<NamedBundle>,
156
- getInlineBundleContents,
157
- tree,
163
+ getInlineBundleContents: (
164
+ arg1: Bundle,
165
+ arg2: BundleGraph<NamedBundle>,
166
+ // @ts-expect-error TS2304
167
+ ) => Async<{
168
+ contents: Blob;
169
+ }>,
170
+ tree: any,
158
171
  ) {
159
- const inlineNodes = [];
172
+ const inlineNodes: Array<any> = [];
173
+ // @ts-expect-error TS7006
160
174
  tree.walk((node) => {
161
175
  if (node.attrs && node.attrs['data-parcel-key']) {
162
176
  inlineNodes.push(node);
@@ -207,7 +221,11 @@ async function replaceInlineAssetContent(
207
221
  return tree;
208
222
  }
209
223
 
210
- function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
224
+ function insertBundleReferences(
225
+ siblingBundles: Array<NamedBundle>,
226
+ tree: any,
227
+ conditionalBundles: Set<NamedBundle>,
228
+ ) {
211
229
  const bundles = [];
212
230
 
213
231
  for (let bundle of siblingBundles) {
@@ -240,16 +258,19 @@ function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
240
258
  addBundlesToTree(bundles, tree);
241
259
  }
242
260
 
243
- function addBundlesToTree(bundles, tree) {
261
+ // @ts-expect-error TS7006
262
+ function addBundlesToTree(bundles, tree: any) {
244
263
  const main = find(tree, 'head') || find(tree, 'html');
264
+ // @ts-expect-error TS2339
245
265
  const content = main ? main.content || (main.content = []) : tree;
246
266
  const index = findBundleInsertIndex(content);
247
267
 
248
268
  content.splice(index, 0, ...bundles);
249
269
  }
250
270
 
251
- function find(tree, tag) {
271
+ function find(tree: any, tag: string) {
252
272
  let res;
273
+ // @ts-expect-error TS7006
253
274
  tree.match({tag}, (node) => {
254
275
  res = node;
255
276
  return node;
@@ -258,7 +279,7 @@ function find(tree, tag) {
258
279
  return res;
259
280
  }
260
281
 
261
- function findBundleInsertIndex(content) {
282
+ function findBundleInsertIndex(content: any) {
262
283
  // HTML document order (https://html.spec.whatwg.org/multipage/syntax.html#writing)
263
284
  // - Any number of comments and ASCII whitespace.
264
285
  // - A DOCTYPE.
@@ -284,3 +305,28 @@ function findBundleInsertIndex(content) {
284
305
 
285
306
  return doctypeIndex ? doctypeIndex + 1 : 0;
286
307
  }
308
+
309
+ function getReferencedConditionalScripts(
310
+ bundleGraph: BundleGraph<NamedBundle>,
311
+ referencedBundles: NamedBundle[],
312
+ ): Set<NamedBundle> {
313
+ const conditionalBundleMapping = bundleGraph.getConditionalBundleMapping();
314
+
315
+ const bundles: Array<NamedBundle> = [];
316
+ for (const bundle of referencedBundles) {
317
+ const conditions = conditionalBundleMapping.get(bundle.id);
318
+ if (conditions) {
319
+ for (const [, cond] of conditions) {
320
+ // Reverse so dependent bundles are loaded first
321
+ const dependentBundles = [
322
+ ...cond.ifTrueBundles.reverse(),
323
+ ...cond.ifFalseBundles.reverse(),
324
+ ];
325
+ bundles.push(...dependentBundles);
326
+ referencedBundles.push(...dependentBundles);
327
+ }
328
+ }
329
+ }
330
+
331
+ return new Set(bundles);
332
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "extends": "../../../tsconfig.json",
3
+ "include": ["src"]
4
+ }