@atlaspack/packager-html 2.12.1-dev.3520 → 2.12.1-dev.3566
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 +14 -6
- package/package.json +7 -7
- package/src/HTMLPackager.js +32 -6
package/lib/HTMLPackager.js
CHANGED
|
@@ -53,14 +53,19 @@ const metadataContent = new Set(['base', 'link', 'meta', 'noscript',
|
|
|
53
53
|
'style', 'template', 'title']);
|
|
54
54
|
var _default = exports.default = new (_plugin().Packager)({
|
|
55
55
|
async loadConfig({
|
|
56
|
-
config
|
|
56
|
+
config,
|
|
57
|
+
options
|
|
57
58
|
}) {
|
|
58
|
-
var _posthtmlConfig$conte;
|
|
59
|
+
var _posthtmlConfig$conte, _conf$contents;
|
|
59
60
|
let posthtmlConfig = await config.getConfig(['.posthtmlrc', '.posthtmlrc.js', '.posthtmlrc.cjs', '.posthtmlrc.mjs', 'posthtml.config.js', 'posthtml.config.cjs', 'posthtml.config.mjs'], {
|
|
60
61
|
packageKey: 'posthtml'
|
|
61
62
|
});
|
|
63
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
64
|
+
packageKey: '@atlaspack/packager-html'
|
|
65
|
+
});
|
|
62
66
|
return {
|
|
63
|
-
render: posthtmlConfig === null || posthtmlConfig === void 0 || (_posthtmlConfig$conte = posthtmlConfig.contents) === null || _posthtmlConfig$conte === void 0 ? void 0 : _posthtmlConfig$conte.render
|
|
67
|
+
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)
|
|
64
69
|
};
|
|
65
70
|
},
|
|
66
71
|
async package({
|
|
@@ -79,13 +84,15 @@ var _default = exports.default = new (_plugin().Packager)({
|
|
|
79
84
|
|
|
80
85
|
// Add bundles in the same bundle group that are not inline. For example, if two inline
|
|
81
86
|
// bundles refer to the same library that is extracted into a shared bundle.
|
|
82
|
-
let
|
|
87
|
+
let referencedBundlesRecursive = bundleGraph.getReferencedBundles(bundle);
|
|
88
|
+
let referencedBundles = [...(0, _utils().setSymmetricDifference)(new Set(referencedBundlesRecursive), new Set(bundleGraph.getReferencedBundles(bundle, {
|
|
83
89
|
recursive: false
|
|
84
90
|
})))];
|
|
91
|
+
let conditionalBundles = config.evaluateRootConditionalBundles ? (0, _utils().setDifference)(new Set([...referencedBundlesRecursive.flatMap(referencedBundle => bundleGraph.getReferencedConditionalBundles(referencedBundle))]), new Set(referencedBundles)) : new Set();
|
|
85
92
|
let renderConfig = config === null || config === void 0 ? void 0 : config.render;
|
|
86
93
|
let {
|
|
87
94
|
html
|
|
88
|
-
} = await (0, _posthtml().default)([tree => insertBundleReferences(referencedBundles, tree), 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, {
|
|
89
96
|
...renderConfig,
|
|
90
97
|
xmlMode: bundle.type === 'xhtml',
|
|
91
98
|
closingSingleTag: bundle.type === 'xhtml' ? 'slash' : undefined
|
|
@@ -172,7 +179,7 @@ async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, t
|
|
|
172
179
|
}
|
|
173
180
|
return tree;
|
|
174
181
|
}
|
|
175
|
-
function insertBundleReferences(siblingBundles, tree) {
|
|
182
|
+
function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
|
|
176
183
|
const bundles = [];
|
|
177
184
|
for (let bundle of siblingBundles) {
|
|
178
185
|
if (bundle.type === 'css') {
|
|
@@ -191,6 +198,7 @@ function insertBundleReferences(siblingBundles, tree) {
|
|
|
191
198
|
type: bundle.env.outputFormat === 'esmodule' ? 'module' : undefined,
|
|
192
199
|
nomodule: nomodule ? '' : undefined,
|
|
193
200
|
defer: nomodule ? '' : undefined,
|
|
201
|
+
'data-conditional': conditionalBundles.has(bundle) ? true : undefined,
|
|
194
202
|
src: (0, _utils().urlJoin)(bundle.target.publicUrl, bundle.name)
|
|
195
203
|
}
|
|
196
204
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-html",
|
|
3
|
-
"version": "2.12.1-dev.
|
|
3
|
+
"version": "2.12.1-dev.3566+facdfb05f",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,15 +12,15 @@
|
|
|
12
12
|
"main": "lib/HTMLPackager.js",
|
|
13
13
|
"source": "src/HTMLPackager.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"
|
|
16
|
-
"
|
|
15
|
+
"atlaspack": "^2.12.1-dev.3566+facdfb05f",
|
|
16
|
+
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/plugin": "2.12.1-dev.
|
|
20
|
-
"@atlaspack/types": "2.12.1-dev.
|
|
21
|
-
"@atlaspack/utils": "2.12.1-dev.
|
|
19
|
+
"@atlaspack/plugin": "2.12.1-dev.3566+facdfb05f",
|
|
20
|
+
"@atlaspack/types": "2.12.1-dev.3566+facdfb05f",
|
|
21
|
+
"@atlaspack/utils": "2.12.1-dev.3566+facdfb05f",
|
|
22
22
|
"nullthrows": "^1.1.1",
|
|
23
23
|
"posthtml": "^0.16.5"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "facdfb05f693e50037a82a4afa101adf093fd8c9"
|
|
26
26
|
}
|
package/src/HTMLPackager.js
CHANGED
|
@@ -4,7 +4,7 @@ import type {Bundle, BundleGraph, NamedBundle} from '@atlaspack/types';
|
|
|
4
4
|
import assert from 'assert';
|
|
5
5
|
import {Readable} from 'stream';
|
|
6
6
|
import {Packager} from '@atlaspack/plugin';
|
|
7
|
-
import {setDifference} from '@atlaspack/utils';
|
|
7
|
+
import {setSymmetricDifference, setDifference} from '@atlaspack/utils';
|
|
8
8
|
import posthtml from 'posthtml';
|
|
9
9
|
import {
|
|
10
10
|
bufferStream,
|
|
@@ -27,7 +27,7 @@ const metadataContent = new Set([
|
|
|
27
27
|
]);
|
|
28
28
|
|
|
29
29
|
export default (new Packager({
|
|
30
|
-
async loadConfig({config}) {
|
|
30
|
+
async loadConfig({config, options}) {
|
|
31
31
|
let posthtmlConfig = await config.getConfig(
|
|
32
32
|
[
|
|
33
33
|
'.posthtmlrc',
|
|
@@ -42,8 +42,16 @@ export default (new Packager({
|
|
|
42
42
|
packageKey: 'posthtml',
|
|
43
43
|
},
|
|
44
44
|
);
|
|
45
|
+
|
|
46
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
47
|
+
packageKey: '@atlaspack/packager-html',
|
|
48
|
+
});
|
|
49
|
+
|
|
45
50
|
return {
|
|
46
51
|
render: posthtmlConfig?.contents?.render,
|
|
52
|
+
evaluateRootConditionalBundles: Boolean(
|
|
53
|
+
conf?.contents?.evaluateRootConditionalBundles,
|
|
54
|
+
),
|
|
47
55
|
};
|
|
48
56
|
},
|
|
49
57
|
async package({bundle, bundleGraph, getInlineBundleContents, config}) {
|
|
@@ -59,17 +67,34 @@ export default (new Packager({
|
|
|
59
67
|
|
|
60
68
|
// Add bundles in the same bundle group that are not inline. For example, if two inline
|
|
61
69
|
// bundles refer to the same library that is extracted into a shared bundle.
|
|
70
|
+
let referencedBundlesRecursive = bundleGraph.getReferencedBundles(bundle);
|
|
62
71
|
let referencedBundles = [
|
|
63
|
-
...
|
|
64
|
-
new Set(
|
|
72
|
+
...setSymmetricDifference(
|
|
73
|
+
new Set(referencedBundlesRecursive),
|
|
65
74
|
new Set(bundleGraph.getReferencedBundles(bundle, {recursive: false})),
|
|
66
75
|
),
|
|
67
76
|
];
|
|
68
77
|
|
|
78
|
+
let conditionalBundles = config.evaluateRootConditionalBundles
|
|
79
|
+
? setDifference(
|
|
80
|
+
new Set([
|
|
81
|
+
...referencedBundlesRecursive.flatMap((referencedBundle) =>
|
|
82
|
+
bundleGraph.getReferencedConditionalBundles(referencedBundle),
|
|
83
|
+
),
|
|
84
|
+
]),
|
|
85
|
+
new Set(referencedBundles),
|
|
86
|
+
)
|
|
87
|
+
: new Set();
|
|
88
|
+
|
|
69
89
|
let renderConfig = config?.render;
|
|
70
90
|
|
|
71
91
|
let {html} = await posthtml([
|
|
72
|
-
(tree) =>
|
|
92
|
+
(tree) =>
|
|
93
|
+
insertBundleReferences(
|
|
94
|
+
[...conditionalBundles, ...referencedBundles],
|
|
95
|
+
tree,
|
|
96
|
+
conditionalBundles,
|
|
97
|
+
),
|
|
73
98
|
(tree) =>
|
|
74
99
|
replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree),
|
|
75
100
|
]).process(code, {
|
|
@@ -182,7 +207,7 @@ async function replaceInlineAssetContent(
|
|
|
182
207
|
return tree;
|
|
183
208
|
}
|
|
184
209
|
|
|
185
|
-
function insertBundleReferences(siblingBundles, tree) {
|
|
210
|
+
function insertBundleReferences(siblingBundles, tree, conditionalBundles) {
|
|
186
211
|
const bundles = [];
|
|
187
212
|
|
|
188
213
|
for (let bundle of siblingBundles) {
|
|
@@ -205,6 +230,7 @@ function insertBundleReferences(siblingBundles, tree) {
|
|
|
205
230
|
type: bundle.env.outputFormat === 'esmodule' ? 'module' : undefined,
|
|
206
231
|
nomodule: nomodule ? '' : undefined,
|
|
207
232
|
defer: nomodule ? '' : undefined,
|
|
233
|
+
'data-conditional': conditionalBundles.has(bundle) ? true : undefined,
|
|
208
234
|
src: urlJoin(bundle.target.publicUrl, bundle.name),
|
|
209
235
|
},
|
|
210
236
|
});
|