@atlaspack/packager-html 2.14.5-canary.171 → 2.14.5-canary.173
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/lib/HTMLPackager.js +2 -10
- package/package.json +6 -6
- package/src/HTMLPackager.ts +25 -16
package/lib/HTMLPackager.js
CHANGED
|
@@ -64,10 +64,8 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
64
64
|
packageKey: '@atlaspack/packager-html'
|
|
65
65
|
});
|
|
66
66
|
return {
|
|
67
|
-
// @ts-expect-error TS2339
|
|
68
67
|
render: posthtmlConfig === null || posthtmlConfig === void 0 || (_posthtmlConfig$conte = posthtmlConfig.contents) === null || _posthtmlConfig$conte === void 0 ? void 0 : _posthtmlConfig$conte.render,
|
|
69
|
-
evaluateRootConditionalBundles: Boolean(
|
|
70
|
-
conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.evaluateRootConditionalBundles)
|
|
68
|
+
evaluateRootConditionalBundles: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.evaluateRootConditionalBundles)
|
|
71
69
|
};
|
|
72
70
|
},
|
|
73
71
|
async package({
|
|
@@ -76,7 +74,6 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
76
74
|
getInlineBundleContents,
|
|
77
75
|
config
|
|
78
76
|
}) {
|
|
79
|
-
// @ts-expect-error TS2552
|
|
80
77
|
let assets = [];
|
|
81
78
|
bundle.traverseAssets(asset => {
|
|
82
79
|
assets.push(asset);
|
|
@@ -95,9 +92,7 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
95
92
|
let renderConfig = config === null || config === void 0 ? void 0 : config.render;
|
|
96
93
|
let {
|
|
97
94
|
html
|
|
98
|
-
} = await (0, _posthtml().default)([tree => insertBundleReferences(
|
|
99
|
-
// @ts-expect-error TS2345
|
|
100
|
-
[...conditionalBundles, ...referencedBundles], tree, conditionalBundles), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
|
|
95
|
+
} = await (0, _posthtml().default)([tree => insertBundleReferences([...conditionalBundles, ...referencedBundles], tree, conditionalBundles), tree => replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree)]).process(code, {
|
|
101
96
|
...renderConfig,
|
|
102
97
|
xmlMode: bundle.type === 'xhtml',
|
|
103
98
|
closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
|
|
@@ -147,7 +142,6 @@ async function getAssetContent(bundleGraph, getInlineBundleContents, assetId) {
|
|
|
147
142
|
}
|
|
148
143
|
async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree) {
|
|
149
144
|
const inlineNodes = [];
|
|
150
|
-
// @ts-expect-error TS7006
|
|
151
145
|
tree.walk(node => {
|
|
152
146
|
if (node.attrs && node.attrs['data-parcel-key']) {
|
|
153
147
|
inlineNodes.push(node);
|
|
@@ -212,8 +206,6 @@ function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
|
|
|
212
206
|
}
|
|
213
207
|
addBundlesToTree(bundles, tree);
|
|
214
208
|
}
|
|
215
|
-
|
|
216
|
-
// @ts-expect-error TS7006
|
|
217
209
|
function addBundlesToTree(bundles, tree) {
|
|
218
210
|
const main = find(tree, 'head') || find(tree, 'html');
|
|
219
211
|
// @ts-expect-error TS2339
|
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.173+f93000336",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/feature-flags": "2.14.1-canary.
|
|
20
|
-
"@atlaspack/plugin": "2.14.5-canary.
|
|
21
|
-
"@atlaspack/types": "2.14.5-canary.
|
|
22
|
-
"@atlaspack/utils": "2.14.5-canary.
|
|
19
|
+
"@atlaspack/feature-flags": "2.14.1-canary.241+f93000336",
|
|
20
|
+
"@atlaspack/plugin": "2.14.5-canary.173+f93000336",
|
|
21
|
+
"@atlaspack/types": "2.14.5-canary.173+f93000336",
|
|
22
|
+
"@atlaspack/utils": "2.14.5-canary.173+f93000336",
|
|
23
23
|
"nullthrows": "^1.1.1",
|
|
24
24
|
"posthtml": "^0.16.5"
|
|
25
25
|
},
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
|
29
29
|
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "f930003364fdc31e5487520ebe256f1a9389f579"
|
|
32
32
|
}
|
package/src/HTMLPackager.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Asset,
|
|
3
|
+
Async,
|
|
4
|
+
Blob,
|
|
5
|
+
Bundle,
|
|
6
|
+
BundleGraph,
|
|
7
|
+
NamedBundle,
|
|
8
|
+
} from '@atlaspack/types';
|
|
2
9
|
|
|
3
10
|
import assert from 'assert';
|
|
4
11
|
import {Readable} from 'stream';
|
|
@@ -25,9 +32,15 @@ const metadataContent = new Set([
|
|
|
25
32
|
'title',
|
|
26
33
|
]);
|
|
27
34
|
|
|
35
|
+
type HTMLPackagerConfig = {
|
|
36
|
+
evaluateRootConditionalBundles: boolean;
|
|
37
|
+
};
|
|
38
|
+
|
|
28
39
|
export default new Packager({
|
|
29
40
|
async loadConfig({config, options}) {
|
|
30
|
-
let posthtmlConfig = await config.getConfig
|
|
41
|
+
let posthtmlConfig = await config.getConfig<{
|
|
42
|
+
render: any;
|
|
43
|
+
}>(
|
|
31
44
|
[
|
|
32
45
|
'.posthtmlrc',
|
|
33
46
|
'.posthtmlrc.js',
|
|
@@ -42,21 +55,22 @@ export default new Packager({
|
|
|
42
55
|
},
|
|
43
56
|
);
|
|
44
57
|
|
|
45
|
-
let conf = await config.getConfigFrom(
|
|
46
|
-
|
|
47
|
-
|
|
58
|
+
let conf = await config.getConfigFrom<HTMLPackagerConfig>(
|
|
59
|
+
options.projectRoot + '/index',
|
|
60
|
+
[],
|
|
61
|
+
{
|
|
62
|
+
packageKey: '@atlaspack/packager-html',
|
|
63
|
+
},
|
|
64
|
+
);
|
|
48
65
|
|
|
49
66
|
return {
|
|
50
|
-
// @ts-expect-error TS2339
|
|
51
67
|
render: posthtmlConfig?.contents?.render,
|
|
52
68
|
evaluateRootConditionalBundles: Boolean(
|
|
53
|
-
// @ts-expect-error TS2339
|
|
54
69
|
conf?.contents?.evaluateRootConditionalBundles,
|
|
55
70
|
),
|
|
56
71
|
};
|
|
57
72
|
},
|
|
58
73
|
async package({bundle, bundleGraph, getInlineBundleContents, config}) {
|
|
59
|
-
// @ts-expect-error TS2552
|
|
60
74
|
let assets: Array<Asset> = [];
|
|
61
75
|
bundle.traverseAssets((asset) => {
|
|
62
76
|
assets.push(asset);
|
|
@@ -85,13 +99,12 @@ export default new Packager({
|
|
|
85
99
|
),
|
|
86
100
|
new Set(referencedBundles),
|
|
87
101
|
)
|
|
88
|
-
: new Set();
|
|
102
|
+
: new Set<NamedBundle>();
|
|
89
103
|
let renderConfig = config?.render;
|
|
90
104
|
|
|
91
105
|
let {html} = await posthtml([
|
|
92
106
|
(tree: any) =>
|
|
93
107
|
insertBundleReferences(
|
|
94
|
-
// @ts-expect-error TS2345
|
|
95
108
|
[...conditionalBundles, ...referencedBundles],
|
|
96
109
|
tree,
|
|
97
110
|
conditionalBundles,
|
|
@@ -131,7 +144,6 @@ async function getAssetContent(
|
|
|
131
144
|
getInlineBundleContents: (
|
|
132
145
|
arg1: Bundle,
|
|
133
146
|
arg2: BundleGraph<NamedBundle>,
|
|
134
|
-
// @ts-expect-error TS2304
|
|
135
147
|
) => Async<{
|
|
136
148
|
contents: Blob;
|
|
137
149
|
}>,
|
|
@@ -163,15 +175,13 @@ async function replaceInlineAssetContent(
|
|
|
163
175
|
getInlineBundleContents: (
|
|
164
176
|
arg1: Bundle,
|
|
165
177
|
arg2: BundleGraph<NamedBundle>,
|
|
166
|
-
// @ts-expect-error TS2304
|
|
167
178
|
) => Async<{
|
|
168
179
|
contents: Blob;
|
|
169
180
|
}>,
|
|
170
181
|
tree: any,
|
|
171
182
|
) {
|
|
172
183
|
const inlineNodes: Array<any> = [];
|
|
173
|
-
|
|
174
|
-
tree.walk((node) => {
|
|
184
|
+
tree.walk((node: any) => {
|
|
175
185
|
if (node.attrs && node.attrs['data-parcel-key']) {
|
|
176
186
|
inlineNodes.push(node);
|
|
177
187
|
}
|
|
@@ -258,8 +268,7 @@ function insertBundleReferences(
|
|
|
258
268
|
addBundlesToTree(bundles, tree);
|
|
259
269
|
}
|
|
260
270
|
|
|
261
|
-
|
|
262
|
-
function addBundlesToTree(bundles, tree: any) {
|
|
271
|
+
function addBundlesToTree(bundles: any[], tree: any) {
|
|
263
272
|
const main = find(tree, 'head') || find(tree, 'html');
|
|
264
273
|
// @ts-expect-error TS2339
|
|
265
274
|
const content = main ? main.content || (main.content = []) : tree;
|