@parcel/packager-svg 2.8.4-nightly.2921 → 2.8.4-nightly.2937
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/SVGPackager.js +6 -36
- package/package.json +6 -6
package/lib/SVGPackager.js
CHANGED
|
@@ -4,49 +4,35 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _assert() {
|
|
9
8
|
const data = _interopRequireDefault(require("assert"));
|
|
10
|
-
|
|
11
9
|
_assert = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _plugin() {
|
|
19
15
|
const data = require("@parcel/plugin");
|
|
20
|
-
|
|
21
16
|
_plugin = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _posthtml() {
|
|
29
22
|
const data = _interopRequireDefault(require("posthtml"));
|
|
30
|
-
|
|
31
23
|
_posthtml = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _utils() {
|
|
39
29
|
const data = require("@parcel/utils");
|
|
40
|
-
|
|
41
30
|
_utils = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
49
|
-
|
|
50
36
|
var _default = new (_plugin().Packager)({
|
|
51
37
|
async package({
|
|
52
38
|
bundle,
|
|
@@ -57,11 +43,10 @@ var _default = new (_plugin().Packager)({
|
|
|
57
43
|
bundle.traverseAssets(asset => {
|
|
58
44
|
assets.push(asset);
|
|
59
45
|
});
|
|
46
|
+
_assert().default.strictEqual(assets.length, 1, 'SVG bundles must only contain one asset');
|
|
60
47
|
|
|
61
|
-
|
|
48
|
+
// Add bundles in the same bundle group that are not inline. For example, if two inline
|
|
62
49
|
// bundles refer to the same library that is extracted into a shared bundle.
|
|
63
|
-
|
|
64
|
-
|
|
65
50
|
let referencedBundles = [...(0, _utils().setDifference)(new Set(bundleGraph.getReferencedBundles(bundle)), new Set(bundleGraph.getReferencedBundles(bundle, {
|
|
66
51
|
recursive: false
|
|
67
52
|
})))];
|
|
@@ -99,72 +84,59 @@ var _default = new (_plugin().Packager)({
|
|
|
99
84
|
map
|
|
100
85
|
});
|
|
101
86
|
}
|
|
102
|
-
|
|
103
87
|
});
|
|
104
|
-
|
|
105
88
|
exports.default = _default;
|
|
106
|
-
|
|
107
89
|
async function replaceInlineAssetContent(bundleGraph, getInlineBundleContents, tree) {
|
|
108
90
|
const inlineNodes = [];
|
|
109
91
|
tree.walk(node => {
|
|
110
92
|
if (node.attrs && node.attrs['data-parcel-key']) {
|
|
111
93
|
inlineNodes.push(node);
|
|
112
94
|
}
|
|
113
|
-
|
|
114
95
|
return node;
|
|
115
96
|
});
|
|
116
|
-
|
|
117
97
|
for (const node of inlineNodes) {
|
|
118
98
|
const newContent = await getAssetContent(bundleGraph, getInlineBundleContents, node.attrs['data-parcel-key']);
|
|
119
|
-
|
|
120
99
|
if (newContent === null) {
|
|
121
100
|
continue;
|
|
122
101
|
}
|
|
102
|
+
node.content = await (0, _utils().blobToString)(newContent.contents);
|
|
123
103
|
|
|
124
|
-
|
|
125
|
-
|
|
104
|
+
// Wrap scripts and styles with CDATA if needed to ensure characters are not interpreted as XML
|
|
126
105
|
if (node.tag === 'script' || node.tag === 'style') {
|
|
127
106
|
if (node.content.includes('<') || node.content.includes('&')) {
|
|
128
107
|
node.content = node.content.replace(/]]>/g, ']\\]>');
|
|
129
108
|
node.content = `<![CDATA[\n${node.content}\n]]>`;
|
|
130
109
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
110
|
+
}
|
|
133
111
|
|
|
112
|
+
// remove attr from output
|
|
134
113
|
delete node.attrs['data-parcel-key'];
|
|
135
114
|
}
|
|
136
|
-
|
|
137
115
|
return tree;
|
|
138
116
|
}
|
|
139
|
-
|
|
140
117
|
async function getAssetContent(bundleGraph, getInlineBundleContents, assetId) {
|
|
141
118
|
let inlineBundle;
|
|
142
119
|
bundleGraph.traverseBundles((bundle, context, {
|
|
143
120
|
stop
|
|
144
121
|
}) => {
|
|
145
122
|
const entryAssets = bundle.getEntryAssets();
|
|
146
|
-
|
|
147
123
|
if (entryAssets.some(a => a.uniqueKey === assetId)) {
|
|
148
124
|
inlineBundle = bundle;
|
|
149
125
|
stop();
|
|
150
126
|
}
|
|
151
127
|
});
|
|
152
|
-
|
|
153
128
|
if (!inlineBundle) {
|
|
154
129
|
return null;
|
|
155
130
|
}
|
|
156
|
-
|
|
157
131
|
const bundleResult = await getInlineBundleContents(inlineBundle, bundleGraph);
|
|
158
132
|
return {
|
|
159
133
|
bundle: inlineBundle,
|
|
160
134
|
contents: bundleResult.contents
|
|
161
135
|
};
|
|
162
136
|
}
|
|
163
|
-
|
|
164
137
|
function insertBundleReferences(siblingBundles, tree) {
|
|
165
138
|
let scripts = [];
|
|
166
139
|
let stylesheets = [];
|
|
167
|
-
|
|
168
140
|
for (let bundle of siblingBundles) {
|
|
169
141
|
if (bundle.type === 'css') {
|
|
170
142
|
stylesheets.push(`<?xml-stylesheet href=${JSON.stringify((0, _utils().urlJoin)(bundle.target.publicUrl, bundle.name))}?>`);
|
|
@@ -177,9 +149,7 @@ function insertBundleReferences(siblingBundles, tree) {
|
|
|
177
149
|
});
|
|
178
150
|
}
|
|
179
151
|
}
|
|
180
|
-
|
|
181
152
|
tree.unshift(...stylesheets);
|
|
182
|
-
|
|
183
153
|
if (scripts.length > 0) {
|
|
184
154
|
tree.match({
|
|
185
155
|
tag: 'svg'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/packager-svg",
|
|
3
|
-
"version": "2.8.4-nightly.
|
|
3
|
+
"version": "2.8.4-nightly.2937+3ad435157",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"source": "src/SVGPackager.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "2.0.0-nightly.
|
|
20
|
+
"parcel": "2.0.0-nightly.1312+3ad435157"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "2.0.0-nightly.
|
|
24
|
-
"@parcel/types": "2.0.0-nightly.
|
|
25
|
-
"@parcel/utils": "2.0.0-nightly.
|
|
23
|
+
"@parcel/plugin": "2.0.0-nightly.1314+3ad435157",
|
|
24
|
+
"@parcel/types": "2.0.0-nightly.1314+3ad435157",
|
|
25
|
+
"@parcel/utils": "2.0.0-nightly.1314+3ad435157",
|
|
26
26
|
"posthtml": "^0.16.4"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "3ad435157d443da806c215d68ccf292b4e95ae0c"
|
|
29
29
|
}
|