@atlaspack/transformer-html 2.14.5-canary.30 → 2.14.5-canary.301

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,274 @@
1
1
  # @atlaspack/transformer-html
2
2
 
3
+ ## 2.15.16
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`7dd5bd8`](https://github.com/atlassian-labs/atlaspack/commit/7dd5bd89ff60c7b324347d772729eb4c3314f01e), [`c8a0e51`](https://github.com/atlassian-labs/atlaspack/commit/c8a0e51b1096d038a64644ad02fe68383f58682a), [`8eb84ee`](https://github.com/atlassian-labs/atlaspack/commit/8eb84ee61a42bfe87c58079b610802b07a6a13e4), [`71900f3`](https://github.com/atlassian-labs/atlaspack/commit/71900f3508d53c3882ca8ea71501ba3069687d4e), [`73168c2`](https://github.com/atlassian-labs/atlaspack/commit/73168c275a5d9abff9907bcf536b340bca1ed5f0), [`2c4953e`](https://github.com/atlassian-labs/atlaspack/commit/2c4953e20dc1a6b012792081667aefeb9340505e), [`3fe7d4e`](https://github.com/atlassian-labs/atlaspack/commit/3fe7d4e821bee162fcbbaf9278b107a5eead944f)]:
8
+ - @atlaspack/rust@3.11.0
9
+ - @atlaspack/feature-flags@2.27.0
10
+ - @atlaspack/plugin@2.14.39
11
+
12
+ ## 2.15.15
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies [[`ec3abe4`](https://github.com/atlassian-labs/atlaspack/commit/ec3abe4dffc98560a850fd2f71fb566577e6c99c), [`c7fe3f7`](https://github.com/atlassian-labs/atlaspack/commit/c7fe3f76f247e9e20299e205e2df0a16c418eaf2), [`cfb4707`](https://github.com/atlassian-labs/atlaspack/commit/cfb4707087498e4fa4dcf10753fe984a248d196b), [`1468695`](https://github.com/atlassian-labs/atlaspack/commit/1468695fc0c9d06f060a6da9e9b0e154f11dff34), [`f31b041`](https://github.com/atlassian-labs/atlaspack/commit/f31b04107e9077c9946aadb99f6f91bb69703bb7), [`8180981`](https://github.com/atlassian-labs/atlaspack/commit/8180981be14c00f9570adb70d3f350bd91d6ec0a), [`ae77e74`](https://github.com/atlassian-labs/atlaspack/commit/ae77e7452a466b43b3fa5bed24d4ba26345ed765), [`f0a496f`](https://github.com/atlassian-labs/atlaspack/commit/f0a496f70fc8652e090cf1b3f6260e8cfbb796e2), [`540f253`](https://github.com/atlassian-labs/atlaspack/commit/540f253dfdcd1a5caebbdc0b197319d439404aae)]:
17
+ - @atlaspack/feature-flags@2.26.2
18
+ - @atlaspack/rust@3.10.0
19
+ - @atlaspack/plugin@2.14.38
20
+
21
+ ## 2.15.14
22
+
23
+ ### Patch Changes
24
+
25
+ - Updated dependencies [[`339b600`](https://github.com/atlassian-labs/atlaspack/commit/339b60095d755742cea50f811d08ccc44a4ae521), [`373ee2d`](https://github.com/atlassian-labs/atlaspack/commit/373ee2d3b5cc315df1e90e647619f915892e2b87)]:
26
+ - @atlaspack/rust@3.9.1
27
+ - @atlaspack/feature-flags@2.26.1
28
+ - @atlaspack/plugin@2.14.37
29
+
30
+ ## 2.15.13
31
+
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [[`02f6aa1`](https://github.com/atlassian-labs/atlaspack/commit/02f6aa1906953fc184d2b49c905c2ef815cb878d), [`58527ee`](https://github.com/atlassian-labs/atlaspack/commit/58527eec15c1aebaaadbeb63586f3082c16beae3), [`525898e`](https://github.com/atlassian-labs/atlaspack/commit/525898e33cc229a4bc938ae853732be36d20c01a), [`cfb39a0`](https://github.com/atlassian-labs/atlaspack/commit/cfb39a0d729eb620cf2ca1611750a2bf7a080d08), [`d0c7bea`](https://github.com/atlassian-labs/atlaspack/commit/d0c7bea04458255b4c5d4299600e734b5f919fe1), [`1086c6a`](https://github.com/atlassian-labs/atlaspack/commit/1086c6a2c59271b63b3fb78e6acdb9d3a0dbf354), [`9cd9521`](https://github.com/atlassian-labs/atlaspack/commit/9cd9521978f783046e2ae4ce78f2de7aeb07d073), [`5776be2`](https://github.com/atlassian-labs/atlaspack/commit/5776be21f70a3f2b9471ba33da3ba1a883f21f1a)]:
35
+ - @atlaspack/rust@3.9.0
36
+ - @atlaspack/feature-flags@2.26.0
37
+ - @atlaspack/plugin@2.14.36
38
+
39
+ ## 2.15.12
40
+
41
+ ### Patch Changes
42
+
43
+ - Updated dependencies [[`79a7e22`](https://github.com/atlassian-labs/atlaspack/commit/79a7e22ef119891a2f4180a9d3cc66b38dd52092), [`3da8e69`](https://github.com/atlassian-labs/atlaspack/commit/3da8e690605472d81c531366b65fa9844f8ca337), [`17dfea9`](https://github.com/atlassian-labs/atlaspack/commit/17dfea9e9f3169807808520df9c09ebf70dc8b10), [`f1070ec`](https://github.com/atlassian-labs/atlaspack/commit/f1070ec48e99b4ec111a03179c5ab5b74163fab1), [`27fd73f`](https://github.com/atlassian-labs/atlaspack/commit/27fd73fa07d358653f1be6f2d15d72dc5d8fc2fd), [`3091fa3`](https://github.com/atlassian-labs/atlaspack/commit/3091fa36425ecffe3938e55247a035b08cda37a2)]:
44
+ - @atlaspack/feature-flags@2.25.5
45
+ - @atlaspack/rust@3.8.3
46
+ - @atlaspack/plugin@2.14.35
47
+
48
+ ## 2.15.11
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [[`662d3c6`](https://github.com/atlassian-labs/atlaspack/commit/662d3c627888b16bf27df15cfac5a9094509e93d)]:
53
+ - @atlaspack/feature-flags@2.25.4
54
+ - @atlaspack/plugin@2.14.34
55
+
56
+ ## 2.15.10
57
+
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [[`f07351a`](https://github.com/atlassian-labs/atlaspack/commit/f07351a2398b6a8e5155a2daad77e69b7dcb2b4b)]:
61
+ - @atlaspack/feature-flags@2.25.3
62
+ - @atlaspack/plugin@2.14.33
63
+
64
+ ## 2.15.9
65
+
66
+ ### Patch Changes
67
+
68
+ - Updated dependencies [[`0207171`](https://github.com/atlassian-labs/atlaspack/commit/0207171e59e985c51e105aec2e0a99de174374bd), [`10ee3fa`](https://github.com/atlassian-labs/atlaspack/commit/10ee3fa5b75a92acde8973673d9b3c5b6f3958e5), [`bbe4e28`](https://github.com/atlassian-labs/atlaspack/commit/bbe4e28c89e5e9284bd730075d4d6f2a3cb37b21), [`1180103`](https://github.com/atlassian-labs/atlaspack/commit/118010351ed444f8178988afb3f77807154dd933), [`2bc93b1`](https://github.com/atlassian-labs/atlaspack/commit/2bc93b17cea07fd7cbb68acec84d8471345a22b4)]:
69
+ - @atlaspack/feature-flags@2.25.2
70
+ - @atlaspack/rust@3.8.2
71
+ - @atlaspack/plugin@2.14.32
72
+
73
+ ## 2.15.8
74
+
75
+ ### Patch Changes
76
+
77
+ - [#785](https://github.com/atlassian-labs/atlaspack/pull/785) [`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922) Thanks [@matt-koko](https://github.com/matt-koko)! - We need to re-publish every package in Atlaspack with the corrected types field.
78
+
79
+ - Updated dependencies [[`0e7dd5e`](https://github.com/atlassian-labs/atlaspack/commit/0e7dd5ec6fbe05aa9e0bb5775a9d0975f206a922), [`686a398`](https://github.com/atlassian-labs/atlaspack/commit/686a398faa1f9e19cbf9274add2c46e246bafba8)]:
80
+ - @atlaspack/diagnostic@2.14.4
81
+ - @atlaspack/feature-flags@2.25.1
82
+ - @atlaspack/plugin@2.14.31
83
+ - @atlaspack/rust@3.8.1
84
+
85
+ ## 2.15.7
86
+
87
+ ### Patch Changes
88
+
89
+ - Updated dependencies [[`7a52bab`](https://github.com/atlassian-labs/atlaspack/commit/7a52bab6281e8edbfa66af248eb6f872c6b4b7bd), [`eedcbc4`](https://github.com/atlassian-labs/atlaspack/commit/eedcbc408fc1e86a2a8e25f1a41c57146d8529e1), [`5a0363f`](https://github.com/atlassian-labs/atlaspack/commit/5a0363f1086e81068959b87e92064bed5a11a9b4), [`038e87a`](https://github.com/atlassian-labs/atlaspack/commit/038e87a7858d39556d59d3a2d17db534d45f62c6), [`f6532d7`](https://github.com/atlassian-labs/atlaspack/commit/f6532d7a4f7f007bd4e5e36af04dd466f0b9f572), [`0684997`](https://github.com/atlassian-labs/atlaspack/commit/0684997c127a6204af1376b36e556fddd1ba5557), [`602f8ed`](https://github.com/atlassian-labs/atlaspack/commit/602f8ed9d8381301df8b2cc82c1d5cf6f2f94fec)]:
90
+ - @atlaspack/feature-flags@2.25.0
91
+ - @atlaspack/rust@3.8.0
92
+ - @atlaspack/plugin@2.14.30
93
+
94
+ ## 2.15.6
95
+
96
+ ### Patch Changes
97
+
98
+ - Updated dependencies [[`830261d`](https://github.com/atlassian-labs/atlaspack/commit/830261dcf4a40293090b61cab52fd75d5683c73f), [`53dd47b`](https://github.com/atlassian-labs/atlaspack/commit/53dd47bd6d23cd47f87297347f03a609ab38a03d)]:
99
+ - @atlaspack/feature-flags@2.24.1
100
+ - @atlaspack/rust@3.7.0
101
+ - @atlaspack/plugin@2.14.29
102
+
103
+ ## 2.15.5
104
+
105
+ ### Patch Changes
106
+
107
+ - Updated dependencies [[`f0349a6`](https://github.com/atlassian-labs/atlaspack/commit/f0349a6b9b04755088f121095ca6301a2ada3767), [`a5081c3`](https://github.com/atlassian-labs/atlaspack/commit/a5081c3f9207d28716ee4edd3841de1830ea4b80), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`f930003`](https://github.com/atlassian-labs/atlaspack/commit/f930003364fdc31e5487520ebe256f1a9389f579), [`8843980`](https://github.com/atlassian-labs/atlaspack/commit/88439807be20025fd3433380204ff1205079729e)]:
108
+ - @atlaspack/feature-flags@2.24.0
109
+ - @atlaspack/plugin@2.14.28
110
+
111
+ ## 2.15.4
112
+
113
+ ### Patch Changes
114
+
115
+ - [#757](https://github.com/atlassian-labs/atlaspack/pull/757) [`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3) Thanks [@marcins](https://github.com/marcins)! - Clean up the `inlineIsolatedScripts` feature flag
116
+
117
+ - Updated dependencies [[`3cfb7cf`](https://github.com/atlassian-labs/atlaspack/commit/3cfb7cfd90b78a5c48ce717e779ff789769825a3)]:
118
+ - @atlaspack/feature-flags@2.23.2
119
+ - @atlaspack/rust@3.6.2
120
+ - @atlaspack/plugin@2.14.27
121
+
122
+ ## 2.15.3
123
+
124
+ ### Patch Changes
125
+
126
+ - [#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
127
+
128
+ - Updated dependencies [[`ee040bb`](https://github.com/atlassian-labs/atlaspack/commit/ee040bb6428f29b57d892ddd8107e29077d08ffd)]:
129
+ - @atlaspack/feature-flags@2.23.1
130
+ - @atlaspack/diagnostic@2.14.3
131
+ - @atlaspack/plugin@2.14.26
132
+ - @atlaspack/rust@3.6.1
133
+
134
+ ## 2.15.2
135
+
136
+ ### Patch Changes
137
+
138
+ - Updated dependencies [[`f6b3f22`](https://github.com/atlassian-labs/atlaspack/commit/f6b3f2276c7e417580b49c4879563aab51f156b1)]:
139
+ - @atlaspack/feature-flags@2.23.0
140
+ - @atlaspack/plugin@2.14.25
141
+
142
+ ## 2.15.1
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [[`ad26146`](https://github.com/atlassian-labs/atlaspack/commit/ad26146f13b4c1cc65d4a0f9c67060b90ef14ff3), [`f1b48e7`](https://github.com/atlassian-labs/atlaspack/commit/f1b48e7a04e005cef0f36a3e692087a9ecdb6f7a), [`7f5841c`](https://github.com/atlassian-labs/atlaspack/commit/7f5841c39df049f9546cccbeea2a7337e0337b45), [`73dd7ba`](https://github.com/atlassian-labs/atlaspack/commit/73dd7baab69456ef2f6e4a0cc7dbb04f407eb148)]:
147
+ - @atlaspack/rust@3.6.0
148
+ - @atlaspack/feature-flags@2.22.0
149
+ - @atlaspack/plugin@2.14.24
150
+
151
+ ## 2.15.0
152
+
153
+ ### Minor Changes
154
+
155
+ - [#731](https://github.com/atlassian-labs/atlaspack/pull/731) [`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2) Thanks [@marcins](https://github.com/marcins)! - Implement "inline isolated" scripts
156
+
157
+ ### Patch Changes
158
+
159
+ - Updated dependencies [[`23d561e`](https://github.com/atlassian-labs/atlaspack/commit/23d561e51e68b0c38fd1ff4e4fb173e5e7b01cf2)]:
160
+ - @atlaspack/feature-flags@2.21.0
161
+ - @atlaspack/rust@3.5.0
162
+ - @atlaspack/plugin@2.14.23
163
+
164
+ ## 2.14.22
165
+
166
+ ### Patch Changes
167
+
168
+ - [#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
169
+
170
+ - Updated dependencies [[`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94)]:
171
+ - @atlaspack/diagnostic@2.14.2
172
+ - @atlaspack/plugin@2.14.22
173
+ - @atlaspack/rust@3.4.2
174
+
175
+ ## 2.14.21
176
+
177
+ ### Patch Changes
178
+
179
+ - Updated dependencies []:
180
+ - @atlaspack/plugin@2.14.21
181
+
182
+ ## 2.14.20
183
+
184
+ ### Patch Changes
185
+
186
+ - [#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
187
+
188
+ - Updated dependencies [[`daaa768`](https://github.com/atlassian-labs/atlaspack/commit/daaa7688786772d7e3713b71c5bba6b89ec704aa)]:
189
+ - @atlaspack/plugin@2.14.20
190
+
191
+ ## 2.14.19
192
+
193
+ ### Patch Changes
194
+
195
+ - Updated dependencies []:
196
+ - @atlaspack/plugin@2.14.19
197
+
198
+ ## 2.14.18
199
+
200
+ ### Patch Changes
201
+
202
+ - Updated dependencies [[`becf977`](https://github.com/atlassian-labs/atlaspack/commit/becf977f625d5ee46dae3d4c679f173bf5f40cc0), [`f0f7c71`](https://github.com/atlassian-labs/atlaspack/commit/f0f7c7168a1d3d18c6f30d2daed611275692b7c5)]:
203
+ - @atlaspack/rust@3.4.1
204
+ - @atlaspack/plugin@2.14.18
205
+
206
+ ## 2.14.17
207
+
208
+ ### Patch Changes
209
+
210
+ - Updated dependencies [[`c75bf55`](https://github.com/atlassian-labs/atlaspack/commit/c75bf553fff4decc285b5fd499a275853b18f8f2)]:
211
+ - @atlaspack/rust@3.4.0
212
+ - @atlaspack/plugin@2.14.17
213
+
214
+ ## 2.14.16
215
+
216
+ ### Patch Changes
217
+
218
+ - Updated dependencies []:
219
+ - @atlaspack/plugin@2.14.16
220
+
221
+ ## 2.14.15
222
+
223
+ ### Patch Changes
224
+
225
+ - Updated dependencies []:
226
+ - @atlaspack/plugin@2.14.15
227
+
228
+ ## 2.14.14
229
+
230
+ ### Patch Changes
231
+
232
+ - Updated dependencies []:
233
+ - @atlaspack/plugin@2.14.14
234
+
235
+ ## 2.14.13
236
+
237
+ ### Patch Changes
238
+
239
+ - Updated dependencies []:
240
+ - @atlaspack/plugin@2.14.13
241
+
242
+ ## 2.14.12
243
+
244
+ ### Patch Changes
245
+
246
+ - Updated dependencies []:
247
+ - @atlaspack/plugin@2.14.12
248
+
249
+ ## 2.14.11
250
+
251
+ ### Patch Changes
252
+
253
+ - Updated dependencies []:
254
+ - @atlaspack/plugin@2.14.11
255
+
256
+ ## 2.14.10
257
+
258
+ ### Patch Changes
259
+
260
+ - Updated dependencies [[`35fdd4b`](https://github.com/atlassian-labs/atlaspack/commit/35fdd4b52da0af20f74667f7b8adfb2f90279b7c), [`6dd4ccb`](https://github.com/atlassian-labs/atlaspack/commit/6dd4ccb753541de32322d881f973d571dd57e4ca)]:
261
+ - @atlaspack/rust@3.3.5
262
+ - @atlaspack/plugin@2.14.10
263
+
264
+ ## 2.14.9
265
+
266
+ ### Patch Changes
267
+
268
+ - Updated dependencies [[`124b7ff`](https://github.com/atlassian-labs/atlaspack/commit/124b7fff44f71aac9fbad289a9a9509b3dfc9aaa), [`e052521`](https://github.com/atlassian-labs/atlaspack/commit/e0525210850ed1606146eb86991049cf567c5dec), [`15c6d70`](https://github.com/atlassian-labs/atlaspack/commit/15c6d7000bd89da876bc590aa75b17a619a41896), [`e4d966c`](https://github.com/atlassian-labs/atlaspack/commit/e4d966c3c9c4292c5013372ae65b10d19d4bacc6), [`42a775d`](https://github.com/atlassian-labs/atlaspack/commit/42a775de8eec638ad188f3271964170d8c04d84b), [`29c2f10`](https://github.com/atlassian-labs/atlaspack/commit/29c2f106de9679adfb5afa04e1910471dc65a427), [`1ef91fc`](https://github.com/atlassian-labs/atlaspack/commit/1ef91fcc863fdd2831511937083dbbc1263b3d9d)]:
269
+ - @atlaspack/rust@3.3.4
270
+ - @atlaspack/plugin@2.14.9
271
+
3
272
  ## 2.14.8
4
273
 
5
274
  ### Patch Changes
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.transformerOpts = void 0;
7
+ exports.parseHTML = parseHTML;
8
+ const plugin_1 = require("@atlaspack/plugin");
9
+ const posthtml_parser_1 = require("posthtml-parser");
10
+ const nullthrows_1 = __importDefault(require("nullthrows"));
11
+ const posthtml_1 = __importDefault(require("posthtml"));
12
+ const posthtml_render_1 = require("posthtml-render");
13
+ const semver_1 = __importDefault(require("semver"));
14
+ const dependencies_1 = __importDefault(require("./dependencies"));
15
+ const inline_1 = __importDefault(require("./inline"));
16
+ const diagnostic_1 = __importDefault(require("@atlaspack/diagnostic"));
17
+ function parseHTML(code, xmlMode) {
18
+ return {
19
+ type: 'posthtml',
20
+ version: '0.4.1',
21
+ program: (0, posthtml_parser_1.parser)(code, {
22
+ lowerCaseTags: true,
23
+ lowerCaseAttributeNames: true,
24
+ sourceLocations: true,
25
+ xmlMode,
26
+ }),
27
+ };
28
+ }
29
+ exports.transformerOpts = {
30
+ canReuseAST({ ast }) {
31
+ return ast.type === 'posthtml' && semver_1.default.satisfies(ast.version, '^0.4.0');
32
+ },
33
+ async parse({ asset }) {
34
+ const code = await asset.getCode();
35
+ const xmlMode = asset.type === 'xhtml';
36
+ return parseHTML(code, xmlMode);
37
+ },
38
+ async transform({ asset, options }) {
39
+ if (asset.type === 'htm') {
40
+ asset.type = 'html';
41
+ }
42
+ asset.bundleBehavior = 'isolated';
43
+ let ast = (0, nullthrows_1.default)(await asset.getAST());
44
+ let hasModuleScripts;
45
+ try {
46
+ hasModuleScripts = (0, dependencies_1.default)(asset, ast);
47
+ }
48
+ catch (errors) {
49
+ if (Array.isArray(errors)) {
50
+ throw new diagnostic_1.default({
51
+ diagnostic: errors.map((error) => ({
52
+ message: error.message,
53
+ origin: '@atlaspack/transformer-html',
54
+ codeFrames: [
55
+ {
56
+ filePath: error.filePath,
57
+ language: 'html',
58
+ codeHighlights: [error.loc],
59
+ },
60
+ ],
61
+ })),
62
+ });
63
+ }
64
+ throw errors;
65
+ }
66
+ const { assets: inlineAssets, hasModuleScripts: hasInlineModuleScripts } = (0, inline_1.default)(asset, ast);
67
+ const result = [asset, ...inlineAssets];
68
+ // empty <script></script> is added to make sure HMR is working even if user
69
+ // didn't add any.
70
+ if (options.hmrOptions && !(hasModuleScripts || hasInlineModuleScripts)) {
71
+ const script = {
72
+ tag: 'script',
73
+ attrs: {
74
+ src: asset.addURLDependency('hmr.js', {
75
+ priority: 'parallel',
76
+ }),
77
+ },
78
+ content: [],
79
+ };
80
+ const found = findFirstMatch(ast, [{ tag: 'body' }, { tag: 'html' }]);
81
+ if (found) {
82
+ found.content = found.content || [];
83
+ found.content.push(script);
84
+ }
85
+ else {
86
+ // Insert at the very end.
87
+ ast.program.push(script);
88
+ }
89
+ asset.setAST(ast);
90
+ result.push({
91
+ type: 'js',
92
+ content: '',
93
+ uniqueKey: 'hmr.js',
94
+ });
95
+ }
96
+ return result;
97
+ },
98
+ generate({ ast, asset }) {
99
+ return {
100
+ content: (0, posthtml_render_1.render)(ast.program, {
101
+ // @ts-expect-error TS2322
102
+ closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
103
+ }),
104
+ };
105
+ },
106
+ };
107
+ exports.default = new plugin_1.Transformer(exports.transformerOpts);
108
+ function findFirstMatch(ast, expressions) {
109
+ let found;
110
+ for (const expression of expressions) {
111
+ // @ts-expect-error TS2339
112
+ (0, posthtml_1.default)().match.call(ast.program, expression, (node) => {
113
+ found = node;
114
+ return node;
115
+ });
116
+ if (found) {
117
+ return found;
118
+ }
119
+ }
120
+ }
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.default = collectDependencies;
7
+ const posthtml_1 = __importDefault(require("posthtml"));
8
+ const srcset_1 = require("srcset");
9
+ // A list of all attributes that may produce a dependency
10
+ // Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
11
+ const ATTRS = {
12
+ src: [
13
+ 'script',
14
+ 'img',
15
+ 'audio',
16
+ 'video',
17
+ 'source',
18
+ 'track',
19
+ 'iframe',
20
+ 'embed',
21
+ 'amp-img',
22
+ ],
23
+ // Using href with <script> is described here: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/script
24
+ href: ['link', 'a', 'use', 'script', 'image'],
25
+ srcset: ['img', 'source'],
26
+ imagesrcset: ['link'],
27
+ poster: ['video'],
28
+ 'xlink:href': ['use', 'image', 'script'],
29
+ content: ['meta'],
30
+ data: ['object'],
31
+ };
32
+ // A list of metadata that should produce a dependency
33
+ // Based on:
34
+ // - http://schema.org/
35
+ // - http://ogp.me
36
+ // - https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/markup
37
+ // - https://msdn.microsoft.com/en-us/library/dn255024.aspx
38
+ // - https://vk.com/dev/publications
39
+ const META = {
40
+ property: [
41
+ 'og:image',
42
+ 'og:image:url',
43
+ 'og:image:secure_url',
44
+ 'og:audio',
45
+ 'og:audio:secure_url',
46
+ 'og:video',
47
+ 'og:video:secure_url',
48
+ 'vk:image',
49
+ ],
50
+ name: [
51
+ 'twitter:image',
52
+ 'msapplication-square150x150logo',
53
+ 'msapplication-square310x310logo',
54
+ 'msapplication-square70x70logo',
55
+ 'msapplication-wide310x150logo',
56
+ 'msapplication-TileImage',
57
+ 'msapplication-config',
58
+ ],
59
+ itemprop: [
60
+ 'image',
61
+ 'logo',
62
+ 'screenshot',
63
+ 'thumbnailUrl',
64
+ 'contentUrl',
65
+ 'downloadUrl',
66
+ ],
67
+ };
68
+ const FEED_TYPES = new Set(['application/rss+xml', 'application/atom+xml']);
69
+ // Options to be passed to `addDependency` for certain tags + attributes
70
+ const OPTIONS = {
71
+ a: {
72
+ href: { needsStableName: true },
73
+ },
74
+ iframe: {
75
+ src: { needsStableName: true },
76
+ },
77
+ link(attrs) {
78
+ if (attrs.rel === 'stylesheet') {
79
+ return {
80
+ // Keep in the same bundle group as the HTML.
81
+ priority: 'parallel',
82
+ };
83
+ }
84
+ },
85
+ };
86
+ function collectSrcSetDependencies(asset, srcset, opts) {
87
+ let parsed = (0, srcset_1.parse)(srcset).map(({ url, ...v }) => ({
88
+ url: asset.addURLDependency(url, opts),
89
+ ...v,
90
+ }));
91
+ return (0, srcset_1.stringify)(parsed);
92
+ }
93
+ function getAttrDepHandler(attr) {
94
+ if (attr === 'srcset' || attr === 'imagesrcset') {
95
+ return collectSrcSetDependencies;
96
+ }
97
+ return (asset, src, opts) => asset.addURLDependency(src, opts);
98
+ }
99
+ function collectDependencies(asset, ast) {
100
+ let isDirty = false;
101
+ let hasModuleScripts = false;
102
+ let seen = new Set();
103
+ let errors = [];
104
+ // @ts-expect-error TS2339
105
+ (0, posthtml_1.default)().walk.call(ast.program, (node) => {
106
+ let { tag, attrs } = node;
107
+ if (!attrs || seen.has(node)) {
108
+ return node;
109
+ }
110
+ seen.add(node);
111
+ if (tag === 'meta') {
112
+ const isMetaDependency = Object.keys(attrs).some((attr) => {
113
+ // @ts-expect-error TS7053
114
+ let values = META[attr];
115
+ return (values &&
116
+ values.includes(attrs[attr]) &&
117
+ attrs.content !== '' &&
118
+ !(attrs.name === 'msapplication-config' && attrs.content === 'none'));
119
+ });
120
+ if (isMetaDependency) {
121
+ const metaAssetUrl = attrs.content;
122
+ if (metaAssetUrl) {
123
+ attrs.content = asset.addURLDependency(attrs.content, {
124
+ needsStableName: !(attrs.name && attrs.name.includes('msapplication')),
125
+ });
126
+ isDirty = true;
127
+ asset.setAST(ast);
128
+ }
129
+ }
130
+ return node;
131
+ }
132
+ if (tag === 'link' &&
133
+ (attrs.rel === 'canonical' ||
134
+ attrs.rel === 'manifest' ||
135
+ (attrs.rel === 'alternate' && FEED_TYPES.has(attrs.type))) &&
136
+ attrs.href) {
137
+ let href = attrs.href;
138
+ if (attrs.rel === 'manifest') {
139
+ // A hack to allow manifest.json rather than manifest.webmanifest.
140
+ // If a custom pipeline is used, it is responsible for running @atlaspack/transformer-webmanifest.
141
+ if (!href.includes(':')) {
142
+ href = 'webmanifest:' + href;
143
+ }
144
+ }
145
+ attrs.href = asset.addURLDependency(href, {
146
+ needsStableName: true,
147
+ });
148
+ isDirty = true;
149
+ asset.setAST(ast);
150
+ return node;
151
+ }
152
+ if (tag === 'script' && attrs.src) {
153
+ let sourceType = attrs.type === 'module' ? 'module' : 'script';
154
+ let loc = node.location
155
+ ? {
156
+ filePath: asset.filePath,
157
+ start: node.location.start,
158
+ end: {
159
+ line: node.location.end.line,
160
+ // PostHTML's location is inclusive
161
+ column: node.location.end.column + 1,
162
+ },
163
+ }
164
+ : undefined;
165
+ let outputFormat = 'global';
166
+ if (attrs.type === 'module' && asset.env.shouldScopeHoist) {
167
+ outputFormat = 'esmodule';
168
+ }
169
+ else {
170
+ if (attrs.type === 'module') {
171
+ attrs.defer = '';
172
+ }
173
+ delete attrs.type;
174
+ }
175
+ // If this is a <script type="module">, and not all of the browser targets support ESM natively,
176
+ // add a copy of the script tag with a nomodule attribute.
177
+ let copy;
178
+ if (outputFormat === 'esmodule' &&
179
+ !asset.env.supports('esmodules', true)) {
180
+ let attrs = Object.assign({}, node.attrs);
181
+ copy = { ...node, attrs };
182
+ delete attrs.type;
183
+ attrs.nomodule = '';
184
+ attrs.defer = '';
185
+ attrs.src = asset.addURLDependency(attrs.src, {
186
+ // Keep in the same bundle group as the HTML.
187
+ priority: 'parallel',
188
+ bundleBehavior: sourceType === 'script' || attrs.async != null
189
+ ? 'isolated'
190
+ : undefined,
191
+ env: {
192
+ // @ts-expect-error TS2322
193
+ sourceType,
194
+ outputFormat: 'global',
195
+ loc,
196
+ },
197
+ });
198
+ seen.add(copy);
199
+ }
200
+ attrs.src = asset.addURLDependency(attrs.src, {
201
+ // Keep in the same bundle group as the HTML.
202
+ priority: 'parallel',
203
+ // If the script is async it can be executed in any order, so it cannot depend
204
+ // on any sibling scripts for dependencies. Keep all dependencies together.
205
+ // Also, don't share dependencies between classic scripts and nomodule scripts
206
+ // because nomodule scripts won't run when modules are supported.
207
+ bundleBehavior: sourceType === 'script' || attrs.async != null
208
+ ? 'isolated'
209
+ : undefined,
210
+ env: {
211
+ // @ts-expect-error TS2322
212
+ sourceType,
213
+ // @ts-expect-error TS2322
214
+ outputFormat,
215
+ loc,
216
+ },
217
+ });
218
+ asset.setAST(ast);
219
+ if (sourceType === 'module')
220
+ hasModuleScripts = true;
221
+ return copy ? [node, copy] : node;
222
+ }
223
+ for (let attr in attrs) {
224
+ // Check for virtual paths
225
+ if (tag === 'a' && attrs[attr].split('#')[0].lastIndexOf('.') < 1) {
226
+ continue;
227
+ }
228
+ // Check for id references
229
+ if (attrs[attr][0] === '#') {
230
+ continue;
231
+ }
232
+ // @ts-expect-error TS7053
233
+ let elements = ATTRS[attr];
234
+ if (elements && elements.includes(node.tag)) {
235
+ // Check for empty string
236
+ if (attrs[attr].length === 0) {
237
+ errors.push({
238
+ message: `'${attr}' should not be empty string`,
239
+ filePath: asset.filePath,
240
+ loc: node.location,
241
+ });
242
+ }
243
+ let depHandler = getAttrDepHandler(attr);
244
+ // @ts-expect-error TS7053
245
+ let depOptionsHandler = OPTIONS[node.tag];
246
+ let depOptions = typeof depOptionsHandler === 'function'
247
+ ? depOptionsHandler(attrs, asset.env)
248
+ : depOptionsHandler && depOptionsHandler[attr];
249
+ attrs[attr] = depHandler(asset, attrs[attr], depOptions);
250
+ isDirty = true;
251
+ }
252
+ }
253
+ if (isDirty) {
254
+ asset.setAST(ast);
255
+ }
256
+ return node;
257
+ });
258
+ if (errors.length > 0) {
259
+ throw errors;
260
+ }
261
+ return hasModuleScripts;
262
+ }