@atlaspack/transformer-html 2.12.1-canary.3425 → 2.12.1-canary.3427
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/package.json +7 -7
- package/test/HTMLTransformer.test.js +80 -9
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/transformer-html",
|
3
|
-
"version": "2.12.1-canary.
|
3
|
+
"version": "2.12.1-canary.3427+a86b8559a",
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
@@ -16,12 +16,12 @@
|
|
16
16
|
"source": "src/HTMLTransformer.js",
|
17
17
|
"engines": {
|
18
18
|
"node": ">= 16.0.0",
|
19
|
-
"parcel": "2.12.1-canary.
|
19
|
+
"parcel": "2.12.1-canary.3427+a86b8559a"
|
20
20
|
},
|
21
21
|
"dependencies": {
|
22
|
-
"@atlaspack/diagnostic": "2.12.1-canary.
|
23
|
-
"@atlaspack/plugin": "2.12.1-canary.
|
24
|
-
"@atlaspack/rust": "2.12.1-canary.
|
22
|
+
"@atlaspack/diagnostic": "2.12.1-canary.3427+a86b8559a",
|
23
|
+
"@atlaspack/plugin": "2.12.1-canary.3427+a86b8559a",
|
24
|
+
"@atlaspack/rust": "2.12.1-canary.3427+a86b8559a",
|
25
25
|
"nullthrows": "^1.1.1",
|
26
26
|
"posthtml": "^0.16.5",
|
27
27
|
"posthtml-parser": "^0.10.1",
|
@@ -30,7 +30,7 @@
|
|
30
30
|
"srcset": "4"
|
31
31
|
},
|
32
32
|
"devDependencies": {
|
33
|
-
"@atlaspack/core": "2.12.1-canary.
|
33
|
+
"@atlaspack/core": "2.12.1-canary.3427+a86b8559a"
|
34
34
|
},
|
35
|
-
"gitHead": "
|
35
|
+
"gitHead": "a86b8559a2aefd7033eb14e71320308f7ece0122"
|
36
36
|
}
|
@@ -3,6 +3,7 @@
|
|
3
3
|
import {type PostHTMLNode, render} from 'posthtml-render';
|
4
4
|
import {parseHTML, transformerOpts} from '../src/HTMLTransformer';
|
5
5
|
import assert from 'assert';
|
6
|
+
import type {PluginOptions} from '../../../core/types-internal/src';
|
6
7
|
|
7
8
|
function normalizeHTML(code: string): string {
|
8
9
|
const ast = parseHTML(code, true);
|
@@ -23,9 +24,14 @@ function renderHTML(newAST: {|program: PostHTMLNode|}): string {
|
|
23
24
|
|
24
25
|
async function runTestTransform(
|
25
26
|
code: string,
|
26
|
-
options: {|
|
27
|
+
options: {|
|
28
|
+
shouldScopeHoist: boolean,
|
29
|
+
supportsEsmodules: boolean,
|
30
|
+
hmrOptions: PluginOptions['hmrOptions'],
|
31
|
+
|} = {
|
27
32
|
shouldScopeHoist: true,
|
28
33
|
supportsEsmodules: true,
|
34
|
+
hmrOptions: null,
|
29
35
|
},
|
30
36
|
) {
|
31
37
|
const dependencies = [];
|
@@ -37,7 +43,7 @@ async function runTestTransform(
|
|
37
43
|
},
|
38
44
|
addURLDependency(url, opts) {
|
39
45
|
dependencies.push({url, opts});
|
40
|
-
return
|
46
|
+
return `dependency-id::${url}`;
|
41
47
|
},
|
42
48
|
env: {
|
43
49
|
shouldScopeHoist: options.shouldScopeHoist,
|
@@ -55,7 +61,9 @@ async function runTestTransform(
|
|
55
61
|
|
56
62
|
const transformInput = {
|
57
63
|
asset,
|
58
|
-
options: {
|
64
|
+
options: {
|
65
|
+
hmrOptions: options.hmrOptions,
|
66
|
+
},
|
59
67
|
};
|
60
68
|
// $FlowFixMe
|
61
69
|
const transformResult = await transformerOpts.transform(transformInput);
|
@@ -107,7 +115,7 @@ describe('HTMLTransformer', () => {
|
|
107
115
|
`
|
108
116
|
<html>
|
109
117
|
<body>
|
110
|
-
<script src="dependency-id"></script>
|
118
|
+
<script src="dependency-id::input.js"></script>
|
111
119
|
</body>
|
112
120
|
</html>
|
113
121
|
`,
|
@@ -167,8 +175,8 @@ describe('HTMLTransformer', () => {
|
|
167
175
|
`
|
168
176
|
<html>
|
169
177
|
<body>
|
170
|
-
<script src="dependency-id"></script>
|
171
|
-
<script src="dependency-id"></script>
|
178
|
+
<script src="dependency-id::input1.js"></script>
|
179
|
+
<script src="dependency-id::input2.js"></script>
|
172
180
|
</body>
|
173
181
|
</html>
|
174
182
|
`,
|
@@ -211,7 +219,7 @@ describe('HTMLTransformer', () => {
|
|
211
219
|
`
|
212
220
|
<html>
|
213
221
|
<body>
|
214
|
-
<script src="dependency-id" type="module"></script>
|
222
|
+
<script src="dependency-id::input.js" type="module"></script>
|
215
223
|
</body>
|
216
224
|
</html>
|
217
225
|
`,
|
@@ -246,14 +254,15 @@ describe('HTMLTransformer', () => {
|
|
246
254
|
await runTestTransform(code, {
|
247
255
|
shouldScopeHoist: true,
|
248
256
|
supportsEsmodules: false,
|
257
|
+
hmrOptions: null,
|
249
258
|
});
|
250
259
|
assert.equal(
|
251
260
|
normalizeHTML(outputCode),
|
252
261
|
normalizeHTML(`
|
253
262
|
<html>
|
254
263
|
<body>
|
255
|
-
<script src="dependency-id" type="module"></script>
|
256
|
-
<script src="dependency-id" nomodule="" defer=""></script>
|
264
|
+
<script src="dependency-id::input.js" type="module"></script>
|
265
|
+
<script src="dependency-id::input.js" nomodule="" defer=""></script>
|
257
266
|
</body>
|
258
267
|
</html>
|
259
268
|
`),
|
@@ -287,4 +296,66 @@ describe('HTMLTransformer', () => {
|
|
287
296
|
|
288
297
|
assert.deepEqual(transformResult, [inputAsset]);
|
289
298
|
});
|
299
|
+
|
300
|
+
it('adds an HMR tag if there are HMR options set', async () => {
|
301
|
+
const code = `
|
302
|
+
<html>
|
303
|
+
<body>
|
304
|
+
<script src="input.js"></script>
|
305
|
+
</body>
|
306
|
+
</html>
|
307
|
+
`;
|
308
|
+
const {dependencies, outputCode, transformResult, inputAsset} =
|
309
|
+
await runTestTransform(code, {
|
310
|
+
shouldScopeHoist: true,
|
311
|
+
supportsEsmodules: true,
|
312
|
+
hmrOptions: {
|
313
|
+
port: 1234,
|
314
|
+
host: 'localhost',
|
315
|
+
},
|
316
|
+
});
|
317
|
+
assert.equal(
|
318
|
+
normalizeHTML(outputCode),
|
319
|
+
normalizeHTML(`
|
320
|
+
<html>
|
321
|
+
<body>
|
322
|
+
<script src="dependency-id::input.js"></script>
|
323
|
+
<script src="dependency-id::hmr.js"></script>
|
324
|
+
</body>
|
325
|
+
</html>
|
326
|
+
`),
|
327
|
+
);
|
328
|
+
assert.deepEqual(normalizeDependencies(dependencies), [
|
329
|
+
{
|
330
|
+
url: 'input.js',
|
331
|
+
opts: {
|
332
|
+
bundleBehavior: 'isolated',
|
333
|
+
env: {
|
334
|
+
loc: null,
|
335
|
+
outputFormat: 'global',
|
336
|
+
sourceType: 'script',
|
337
|
+
},
|
338
|
+
priority: 'parallel',
|
339
|
+
},
|
340
|
+
},
|
341
|
+
{
|
342
|
+
url: 'hmr.js',
|
343
|
+
opts: {
|
344
|
+
env: {
|
345
|
+
loc: null,
|
346
|
+
},
|
347
|
+
priority: 'parallel',
|
348
|
+
},
|
349
|
+
},
|
350
|
+
]);
|
351
|
+
|
352
|
+
assert.deepEqual(transformResult, [
|
353
|
+
inputAsset,
|
354
|
+
{
|
355
|
+
content: '',
|
356
|
+
type: 'js',
|
357
|
+
uniqueKey: 'hmr.js',
|
358
|
+
},
|
359
|
+
]);
|
360
|
+
});
|
290
361
|
});
|