@atlaspack/packager-html 2.14.5-canary.137 → 2.14.5-canary.139
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 +10 -0
- package/lib/HTMLPackager.d.ts +3 -0
- package/lib/HTMLPackager.js +12 -5
- package/package.json +13 -9
- package/src/{HTMLPackager.js → HTMLPackager.ts} +40 -19
- package/tsconfig.json +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaspack/packager-html
|
|
2
2
|
|
|
3
|
+
## 2.15.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`069de47`](https://github.com/atlassian-labs/atlaspack/commit/069de478e64fb5889f6f2ce023eb510782767fbd)]:
|
|
8
|
+
- @atlaspack/feature-flags@2.20.0
|
|
9
|
+
- @atlaspack/types@2.15.11
|
|
10
|
+
- @atlaspack/utils@2.17.3
|
|
11
|
+
- @atlaspack/plugin@2.14.21
|
|
12
|
+
|
|
3
13
|
## 2.15.2
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/lib/HTMLPackager.js
CHANGED
|
@@ -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(
|
|
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,14 +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
|
-
|
|
92
|
-
// $FlowFixMe
|
|
93
94
|
let conditionalBundles = config.evaluateRootConditionalBundles ? (0, _utils().setDifference)(getReferencedConditionalScripts(bundleGraph, referencedBundlesRecursive), new Set(referencedBundles)) : new Set();
|
|
94
|
-
// $FlowFixMe
|
|
95
95
|
let renderConfig = config === null || config === void 0 ? void 0 : config.render;
|
|
96
96
|
let {
|
|
97
97
|
html
|
|
98
|
-
} = await (0, _posthtml().default)([tree => insertBundleReferences(
|
|
98
|
+
} = await (0, _posthtml().default)([tree => insertBundleReferences(
|
|
99
|
+
// @ts-expect-error TS2345
|
|
100
|
+
[...conditionalBundles, ...referencedBundles], tree, conditionalBundles), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
|
|
99
101
|
...renderConfig,
|
|
100
102
|
xmlMode: bundle.type === 'xhtml',
|
|
101
103
|
closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
|
|
@@ -145,6 +147,7 @@ async function getAssetContent(bundleGraph, getInlineBundleContents, assetId) {
|
|
|
145
147
|
}
|
|
146
148
|
async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree) {
|
|
147
149
|
const inlineNodes = [];
|
|
150
|
+
// @ts-expect-error TS7006
|
|
148
151
|
tree.walk(node => {
|
|
149
152
|
if (node.attrs && node.attrs['data-parcel-key']) {
|
|
150
153
|
inlineNodes.push(node);
|
|
@@ -209,14 +212,18 @@ function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
|
|
|
209
212
|
}
|
|
210
213
|
addBundlesToTree(bundles, tree);
|
|
211
214
|
}
|
|
215
|
+
|
|
216
|
+
// @ts-expect-error TS7006
|
|
212
217
|
function addBundlesToTree(bundles, tree) {
|
|
213
218
|
const main = find(tree, 'head') || find(tree, 'html');
|
|
219
|
+
// @ts-expect-error TS2339
|
|
214
220
|
const content = main ? main.content || (main.content = []) : tree;
|
|
215
221
|
const index = findBundleInsertIndex(content);
|
|
216
222
|
content.splice(index, 0, ...bundles);
|
|
217
223
|
}
|
|
218
224
|
function find(tree, tag) {
|
|
219
225
|
let res;
|
|
226
|
+
// @ts-expect-error TS7006
|
|
220
227
|
tree.match({
|
|
221
228
|
tag
|
|
222
229
|
}, node => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-html",
|
|
3
|
-
"version": "2.14.5-canary.
|
|
3
|
+
"version": "2.14.5-canary.139+d2fd84977",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -9,19 +9,23 @@
|
|
|
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.
|
|
12
|
+
"main": "./lib/HTMLPackager.js",
|
|
13
|
+
"source": "./src/HTMLPackager.ts",
|
|
14
|
+
"types": "./lib/HTMLPackager.d.ts",
|
|
14
15
|
"engines": {
|
|
15
16
|
"node": ">= 16.0.0"
|
|
16
17
|
},
|
|
17
18
|
"dependencies": {
|
|
18
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
19
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
20
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
21
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-canary.207+d2fd84977",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.139+d2fd84977",
|
|
21
|
+
"@atlaspack/types": "2.14.5-canary.139+d2fd84977",
|
|
22
|
+
"@atlaspack/utils": "2.14.5-canary.139+d2fd84977",
|
|
22
23
|
"nullthrows": "^1.1.1",
|
|
23
24
|
"posthtml": "^0.16.5"
|
|
24
25
|
},
|
|
25
26
|
"type": "commonjs",
|
|
26
|
-
"
|
|
27
|
-
|
|
27
|
+
"scripts": {
|
|
28
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "d2fd849770fe6305e9c694bd97b1bd905abd9d94"
|
|
31
|
+
}
|
|
@@ -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
|
|
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
|
-
|
|
59
|
+
// @ts-expect-error TS2552
|
|
60
|
+
let assets: Array<Asset> = [];
|
|
59
61
|
bundle.traverseAssets((asset) => {
|
|
60
62
|
assets.push(asset);
|
|
61
63
|
});
|
|
@@ -75,7 +77,6 @@ export default (new Packager({
|
|
|
75
77
|
),
|
|
76
78
|
];
|
|
77
79
|
|
|
78
|
-
// $FlowFixMe
|
|
79
80
|
let conditionalBundles = config.evaluateRootConditionalBundles
|
|
80
81
|
? setDifference(
|
|
81
82
|
getReferencedConditionalScripts(
|
|
@@ -85,17 +86,17 @@ export default (new Packager({
|
|
|
85
86
|
new Set(referencedBundles),
|
|
86
87
|
)
|
|
87
88
|
: new Set();
|
|
88
|
-
// $FlowFixMe
|
|
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
|
-
})
|
|
127
|
+
}) as Packager<unknown, unknown>;
|
|
127
128
|
|
|
128
129
|
async function getAssetContent(
|
|
129
130
|
bundleGraph: BundleGraph<NamedBundle>,
|
|
130
|
-
getInlineBundleContents
|
|
131
|
-
|
|
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:
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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.
|
|
@@ -291,7 +312,7 @@ function getReferencedConditionalScripts(
|
|
|
291
312
|
): Set<NamedBundle> {
|
|
292
313
|
const conditionalBundleMapping = bundleGraph.getConditionalBundleMapping();
|
|
293
314
|
|
|
294
|
-
const bundles = [];
|
|
315
|
+
const bundles: Array<NamedBundle> = [];
|
|
295
316
|
for (const bundle of referencedBundles) {
|
|
296
317
|
const conditions = conditionalBundleMapping.get(bundle.id);
|
|
297
318
|
if (conditions) {
|
package/tsconfig.json
ADDED