@atlaspack/transformer-html 2.14.21-typescript-e99c742e9.0 → 2.14.21
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 +7 -0
- package/lib/HTMLTransformer.js +0 -4
- package/lib/dependencies.js +0 -10
- package/lib/inline.js +2 -8
- package/package.json +10 -13
- package/src/{HTMLTransformer.ts → HTMLTransformer.js} +7 -8
- package/src/{dependencies.ts → dependencies.js} +15 -26
- package/src/{inline.ts → inline.js} +5 -7
- package/test/{HTMLTransformer.test.ts → HTMLTransformer.test.js} +27 -20
- package/LICENSE +0 -201
- package/lib/HTMLTransformer.d.ts +0 -6
- package/lib/dependencies.d.ts +0 -2
- package/lib/inline.d.ts +0 -7
- package/tsconfig.json +0 -4
package/CHANGELOG.md
CHANGED
package/lib/HTMLTransformer.js
CHANGED
@@ -58,8 +58,6 @@ function _diagnostic() {
|
|
58
58
|
return data;
|
59
59
|
}
|
60
60
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
61
|
-
// @ts-expect-error TS2305
|
62
|
-
|
63
61
|
function parseHTML(code, xmlMode) {
|
64
62
|
return {
|
65
63
|
type: 'posthtml',
|
@@ -158,7 +156,6 @@ const transformerOpts = exports.transformerOpts = {
|
|
158
156
|
}) {
|
159
157
|
return {
|
160
158
|
content: (0, _posthtmlRender().render)(ast.program, {
|
161
|
-
// @ts-expect-error TS2322
|
162
159
|
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined
|
163
160
|
})
|
164
161
|
};
|
@@ -168,7 +165,6 @@ var _default = exports.default = new (_plugin().Transformer)(transformerOpts);
|
|
168
165
|
function findFirstMatch(ast, expressions) {
|
169
166
|
let found;
|
170
167
|
for (const expression of expressions) {
|
171
|
-
// @ts-expect-error TS2339
|
172
168
|
(0, _posthtml().default)().match.call(ast.program, expression, node => {
|
173
169
|
found = node;
|
174
170
|
return node;
|
package/lib/dependencies.js
CHANGED
@@ -19,8 +19,6 @@ function _srcset() {
|
|
19
19
|
return data;
|
20
20
|
}
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22
|
-
// @ts-expect-error TS2724
|
23
|
-
|
24
22
|
// A list of all attributes that may produce a dependency
|
25
23
|
// Based on https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
|
26
24
|
const ATTRS = {
|
@@ -91,7 +89,6 @@ function collectDependencies(asset, ast) {
|
|
91
89
|
let hasModuleScripts = false;
|
92
90
|
let seen = new Set();
|
93
91
|
let errors = [];
|
94
|
-
// @ts-expect-error TS2339
|
95
92
|
(0, _posthtml().default)().walk.call(ast.program, node => {
|
96
93
|
let {
|
97
94
|
tag,
|
@@ -103,7 +100,6 @@ function collectDependencies(asset, ast) {
|
|
103
100
|
seen.add(node);
|
104
101
|
if (tag === 'meta') {
|
105
102
|
const isMetaDependency = Object.keys(attrs).some(attr => {
|
106
|
-
// @ts-expect-error TS7053
|
107
103
|
let values = META[attr];
|
108
104
|
return values && values.includes(attrs[attr]) && attrs.content !== '' && !(attrs.name === 'msapplication-config' && attrs.content === 'none');
|
109
105
|
});
|
@@ -173,7 +169,6 @@ function collectDependencies(asset, ast) {
|
|
173
169
|
priority: 'parallel',
|
174
170
|
bundleBehavior: sourceType === 'script' || attrs.async != null ? 'isolated' : undefined,
|
175
171
|
env: {
|
176
|
-
// @ts-expect-error TS2322
|
177
172
|
sourceType,
|
178
173
|
outputFormat: 'global',
|
179
174
|
loc
|
@@ -190,9 +185,7 @@ function collectDependencies(asset, ast) {
|
|
190
185
|
// because nomodule scripts won't run when modules are supported.
|
191
186
|
bundleBehavior: sourceType === 'script' || attrs.async != null ? 'isolated' : undefined,
|
192
187
|
env: {
|
193
|
-
// @ts-expect-error TS2322
|
194
188
|
sourceType,
|
195
|
-
// @ts-expect-error TS2322
|
196
189
|
outputFormat,
|
197
190
|
loc
|
198
191
|
}
|
@@ -211,8 +204,6 @@ function collectDependencies(asset, ast) {
|
|
211
204
|
if (attrs[attr][0] === '#') {
|
212
205
|
continue;
|
213
206
|
}
|
214
|
-
|
215
|
-
// @ts-expect-error TS7053
|
216
207
|
let elements = ATTRS[attr];
|
217
208
|
if (elements && elements.includes(node.tag)) {
|
218
209
|
// Check for empty string
|
@@ -224,7 +215,6 @@ function collectDependencies(asset, ast) {
|
|
224
215
|
});
|
225
216
|
}
|
226
217
|
let depHandler = getAttrDepHandler(attr);
|
227
|
-
// @ts-expect-error TS7053
|
228
218
|
let depOptionsHandler = OPTIONS[node.tag];
|
229
219
|
let depOptions = typeof depOptionsHandler === 'function' ? depOptionsHandler(attrs, asset.env) : depOptionsHandler && depOptionsHandler[attr];
|
230
220
|
attrs[attr] = depHandler(asset, attrs[attr], depOptions);
|
package/lib/inline.js
CHANGED
@@ -19,8 +19,6 @@ function _posthtml() {
|
|
19
19
|
return data;
|
20
20
|
}
|
21
21
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
22
|
-
// @ts-expect-error TS2724
|
23
|
-
|
24
22
|
const SCRIPT_TYPES = {
|
25
23
|
'application/javascript': 'js',
|
26
24
|
'text/javascript': 'js',
|
@@ -36,7 +34,6 @@ function extractInlineAssets(asset, ast) {
|
|
36
34
|
// Extract inline <script> and <style> tags for processing.
|
37
35
|
let parts = [];
|
38
36
|
let hasModuleScripts = false;
|
39
|
-
// @ts-expect-error TS2339
|
40
37
|
(0, _posthtml().default)().walk.call(program, node => {
|
41
38
|
let parcelKey = (0, _rust().hashString)(`${asset.id}:${key++}`);
|
42
39
|
if (node.tag === 'script' || node.tag === 'style') {
|
@@ -52,14 +49,10 @@ function extractInlineAssets(asset, ast) {
|
|
52
49
|
}
|
53
50
|
} else if (node.attrs && node.attrs.type != null) {
|
54
51
|
// Skip JSON
|
55
|
-
// @ts-expect-error TS7053
|
56
52
|
if (SCRIPT_TYPES[node.attrs.type] === false) {
|
57
53
|
return node;
|
58
54
|
}
|
59
|
-
|
60
|
-
// @ts-expect-error TS7053
|
61
55
|
if (SCRIPT_TYPES[node.attrs.type]) {
|
62
|
-
// @ts-expect-error TS7053
|
63
56
|
type = SCRIPT_TYPES[node.attrs.type];
|
64
57
|
} else {
|
65
58
|
type = node.attrs.type.split('/')[1];
|
@@ -127,10 +120,10 @@ function extractInlineAssets(asset, ast) {
|
|
127
120
|
content: value,
|
128
121
|
uniqueKey: parcelKey,
|
129
122
|
bundleBehavior: 'inline',
|
130
|
-
// @ts-expect-error TS2322
|
131
123
|
env,
|
132
124
|
meta: {
|
133
125
|
type: 'tag',
|
126
|
+
// $FlowFixMe
|
134
127
|
node,
|
135
128
|
startLine: (_node$location = node.location) === null || _node$location === void 0 ? void 0 : _node$location.start.line
|
136
129
|
}
|
@@ -158,6 +151,7 @@ function extractInlineAssets(asset, ast) {
|
|
158
151
|
bundleBehavior: 'inline',
|
159
152
|
meta: {
|
160
153
|
type: 'attr',
|
154
|
+
// $FlowFixMe
|
161
155
|
node
|
162
156
|
}
|
163
157
|
});
|
package/package.json
CHANGED
@@ -1,28 +1,26 @@
|
|
1
1
|
{
|
2
2
|
"name": "@atlaspack/transformer-html",
|
3
|
-
"version": "2.14.21
|
3
|
+
"version": "2.14.21",
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
5
5
|
"publishConfig": {
|
6
6
|
"access": "public"
|
7
7
|
},
|
8
8
|
"scripts": {
|
9
|
-
"test": "mocha"
|
10
|
-
"check-ts": "tsc --emitDeclarationOnly --rootDir src"
|
9
|
+
"test": "mocha"
|
11
10
|
},
|
12
11
|
"repository": {
|
13
12
|
"type": "git",
|
14
13
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
15
14
|
},
|
16
|
-
"main": "
|
17
|
-
"source": "
|
18
|
-
"types": "./lib/HTMLTransformer.d.ts",
|
15
|
+
"main": "lib/HTMLTransformer.js",
|
16
|
+
"source": "src/HTMLTransformer.js",
|
19
17
|
"engines": {
|
20
18
|
"node": ">= 16.0.0"
|
21
19
|
},
|
22
20
|
"dependencies": {
|
23
|
-
"@atlaspack/diagnostic": "2.14.
|
24
|
-
"@atlaspack/plugin": "2.14.21
|
25
|
-
"@atlaspack/rust": "3.4.
|
21
|
+
"@atlaspack/diagnostic": "2.14.1",
|
22
|
+
"@atlaspack/plugin": "2.14.21",
|
23
|
+
"@atlaspack/rust": "3.4.1",
|
26
24
|
"nullthrows": "^1.1.1",
|
27
25
|
"posthtml": "^0.16.5",
|
28
26
|
"posthtml-parser": "^0.10.1",
|
@@ -31,8 +29,7 @@
|
|
31
29
|
"srcset": "4"
|
32
30
|
},
|
33
31
|
"devDependencies": {
|
34
|
-
"@atlaspack/core": "2.
|
32
|
+
"@atlaspack/core": "2.20.0"
|
35
33
|
},
|
36
|
-
"type": "commonjs"
|
37
|
-
|
38
|
-
}
|
34
|
+
"type": "commonjs"
|
35
|
+
}
|
@@ -1,8 +1,9 @@
|
|
1
|
+
// @flow
|
2
|
+
|
1
3
|
import {Transformer} from '@atlaspack/plugin';
|
2
4
|
import type {AST, Transformer as TransformerOpts} from '@atlaspack/types';
|
3
5
|
import {parser as parse} from 'posthtml-parser';
|
4
6
|
import nullthrows from 'nullthrows';
|
5
|
-
// @ts-expect-error TS2305
|
6
7
|
import type {PostHTMLExpression, PostHTMLNode} from 'posthtml';
|
7
8
|
import PostHTML from 'posthtml';
|
8
9
|
import {render} from 'posthtml-render';
|
@@ -24,7 +25,7 @@ export function parseHTML(code: string, xmlMode: boolean): AST {
|
|
24
25
|
};
|
25
26
|
}
|
26
27
|
|
27
|
-
export const transformerOpts: TransformerOpts<
|
28
|
+
export const transformerOpts: TransformerOpts<void> = {
|
28
29
|
canReuseAST({ast}) {
|
29
30
|
return ast.type === 'posthtml' && semver.satisfies(ast.version, '^0.4.0');
|
30
31
|
},
|
@@ -45,7 +46,7 @@ export const transformerOpts: TransformerOpts<undefined> = {
|
|
45
46
|
let hasModuleScripts;
|
46
47
|
try {
|
47
48
|
hasModuleScripts = collectDependencies(asset, ast);
|
48
|
-
} catch (errors
|
49
|
+
} catch (errors) {
|
49
50
|
if (Array.isArray(errors)) {
|
50
51
|
throw new ThrowableDiagnostic({
|
51
52
|
diagnostic: errors.map((error) => ({
|
@@ -80,7 +81,7 @@ export const transformerOpts: TransformerOpts<undefined> = {
|
|
80
81
|
}),
|
81
82
|
},
|
82
83
|
content: [],
|
83
|
-
}
|
84
|
+
};
|
84
85
|
|
85
86
|
const found = findFirstMatch(ast, [{tag: 'body'}, {tag: 'html'}]);
|
86
87
|
|
@@ -107,23 +108,21 @@ export const transformerOpts: TransformerOpts<undefined> = {
|
|
107
108
|
generate({ast, asset}) {
|
108
109
|
return {
|
109
110
|
content: render(ast.program, {
|
110
|
-
// @ts-expect-error TS2322
|
111
111
|
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
|
112
112
|
}),
|
113
113
|
};
|
114
114
|
},
|
115
115
|
};
|
116
116
|
|
117
|
-
export default new Transformer(transformerOpts)
|
117
|
+
export default (new Transformer(transformerOpts): Transformer<void>);
|
118
118
|
|
119
119
|
function findFirstMatch(
|
120
120
|
ast: AST,
|
121
121
|
expressions: PostHTMLExpression[],
|
122
|
-
): PostHTMLNode
|
122
|
+
): ?PostHTMLNode {
|
123
123
|
let found;
|
124
124
|
|
125
125
|
for (const expression of expressions) {
|
126
|
-
// @ts-expect-error TS2339
|
127
126
|
PostHTML().match.call(ast.program, expression, (node) => {
|
128
127
|
found = node;
|
129
128
|
return node;
|
@@ -1,5 +1,6 @@
|
|
1
|
+
// @flow
|
2
|
+
|
1
3
|
import type {AST, MutableAsset, FilePath} from '@atlaspack/types';
|
2
|
-
// @ts-expect-error TS2724
|
3
4
|
import type {PostHTMLNode} from 'posthtml';
|
4
5
|
import PostHTML from 'posthtml';
|
5
6
|
import {parse, stringify} from 'srcset';
|
@@ -25,7 +26,7 @@ const ATTRS = {
|
|
25
26
|
'xlink:href': ['use', 'image', 'script'],
|
26
27
|
content: ['meta'],
|
27
28
|
data: ['object'],
|
28
|
-
}
|
29
|
+
};
|
29
30
|
|
30
31
|
// A list of metadata that should produce a dependency
|
31
32
|
// Based on:
|
@@ -62,7 +63,7 @@ const META = {
|
|
62
63
|
'contentUrl',
|
63
64
|
'downloadUrl',
|
64
65
|
],
|
65
|
-
}
|
66
|
+
};
|
66
67
|
|
67
68
|
const FEED_TYPES = new Set(['application/rss+xml', 'application/atom+xml']);
|
68
69
|
|
@@ -74,7 +75,7 @@ const OPTIONS = {
|
|
74
75
|
iframe: {
|
75
76
|
src: {needsStableName: true},
|
76
77
|
},
|
77
|
-
link(attrs
|
78
|
+
link(attrs) {
|
78
79
|
if (attrs.rel === 'stylesheet') {
|
79
80
|
return {
|
80
81
|
// Keep in the same bundle group as the HTML.
|
@@ -82,13 +83,9 @@ const OPTIONS = {
|
|
82
83
|
};
|
83
84
|
}
|
84
85
|
},
|
85
|
-
}
|
86
|
+
};
|
86
87
|
|
87
|
-
function collectSrcSetDependencies(
|
88
|
-
asset: MutableAsset,
|
89
|
-
srcset: string,
|
90
|
-
opts: any,
|
91
|
-
) {
|
88
|
+
function collectSrcSetDependencies(asset, srcset, opts) {
|
92
89
|
let parsed = parse(srcset).map(({url, ...v}) => ({
|
93
90
|
url: asset.addURLDependency(url, opts),
|
94
91
|
...v,
|
@@ -96,13 +93,12 @@ function collectSrcSetDependencies(
|
|
96
93
|
return stringify(parsed);
|
97
94
|
}
|
98
95
|
|
99
|
-
function getAttrDepHandler(attr
|
96
|
+
function getAttrDepHandler(attr) {
|
100
97
|
if (attr === 'srcset' || attr === 'imagesrcset') {
|
101
98
|
return collectSrcSetDependencies;
|
102
99
|
}
|
103
100
|
|
104
|
-
return (asset
|
105
|
-
asset.addURLDependency(src, opts);
|
101
|
+
return (asset, src, opts) => asset.addURLDependency(src, opts);
|
106
102
|
}
|
107
103
|
|
108
104
|
export default function collectDependencies(
|
@@ -112,12 +108,11 @@ export default function collectDependencies(
|
|
112
108
|
let isDirty = false;
|
113
109
|
let hasModuleScripts = false;
|
114
110
|
let seen = new Set();
|
115
|
-
let errors: Array<{
|
116
|
-
message: string
|
117
|
-
filePath: FilePath
|
118
|
-
loc: PostHTMLNode['location']
|
119
|
-
}> = [];
|
120
|
-
// @ts-expect-error TS2339
|
111
|
+
let errors: Array<{|
|
112
|
+
message: string,
|
113
|
+
filePath: FilePath,
|
114
|
+
loc: PostHTMLNode['location'],
|
115
|
+
|}> = [];
|
121
116
|
PostHTML().walk.call(ast.program, (node) => {
|
122
117
|
let {tag, attrs} = node;
|
123
118
|
if (!attrs || seen.has(node)) {
|
@@ -128,7 +123,6 @@ export default function collectDependencies(
|
|
128
123
|
|
129
124
|
if (tag === 'meta') {
|
130
125
|
const isMetaDependency = Object.keys(attrs).some((attr) => {
|
131
|
-
// @ts-expect-error TS7053
|
132
126
|
let values = META[attr];
|
133
127
|
return (
|
134
128
|
values &&
|
@@ -203,7 +197,7 @@ export default function collectDependencies(
|
|
203
197
|
|
204
198
|
// If this is a <script type="module">, and not all of the browser targets support ESM natively,
|
205
199
|
// add a copy of the script tag with a nomodule attribute.
|
206
|
-
let copy: PostHTMLNode
|
200
|
+
let copy: ?PostHTMLNode;
|
207
201
|
if (
|
208
202
|
outputFormat === 'esmodule' &&
|
209
203
|
!asset.env.supports('esmodules', true)
|
@@ -221,7 +215,6 @@ export default function collectDependencies(
|
|
221
215
|
? 'isolated'
|
222
216
|
: undefined,
|
223
217
|
env: {
|
224
|
-
// @ts-expect-error TS2322
|
225
218
|
sourceType,
|
226
219
|
outputFormat: 'global',
|
227
220
|
loc,
|
@@ -243,9 +236,7 @@ export default function collectDependencies(
|
|
243
236
|
? 'isolated'
|
244
237
|
: undefined,
|
245
238
|
env: {
|
246
|
-
// @ts-expect-error TS2322
|
247
239
|
sourceType,
|
248
|
-
// @ts-expect-error TS2322
|
249
240
|
outputFormat,
|
250
241
|
loc,
|
251
242
|
},
|
@@ -267,7 +258,6 @@ export default function collectDependencies(
|
|
267
258
|
continue;
|
268
259
|
}
|
269
260
|
|
270
|
-
// @ts-expect-error TS7053
|
271
261
|
let elements = ATTRS[attr];
|
272
262
|
if (elements && elements.includes(node.tag)) {
|
273
263
|
// Check for empty string
|
@@ -280,7 +270,6 @@ export default function collectDependencies(
|
|
280
270
|
}
|
281
271
|
|
282
272
|
let depHandler = getAttrDepHandler(attr);
|
283
|
-
// @ts-expect-error TS7053
|
284
273
|
let depOptionsHandler = OPTIONS[node.tag];
|
285
274
|
let depOptions =
|
286
275
|
typeof depOptionsHandler === 'function'
|
@@ -1,6 +1,7 @@
|
|
1
|
+
// @flow strict-local
|
2
|
+
|
1
3
|
import type {AST, MutableAsset, TransformerResult} from '@atlaspack/types';
|
2
4
|
import {hashString} from '@atlaspack/rust';
|
3
|
-
// @ts-expect-error TS2724
|
4
5
|
import type {PostHTMLNode} from 'posthtml';
|
5
6
|
|
6
7
|
import PostHTML from 'posthtml';
|
@@ -12,7 +13,7 @@ const SCRIPT_TYPES = {
|
|
12
13
|
'application/ld+json': 'jsonld',
|
13
14
|
'text/html': false,
|
14
15
|
module: 'js',
|
15
|
-
}
|
16
|
+
};
|
16
17
|
|
17
18
|
interface ExtractInlineAssetsResult {
|
18
19
|
hasModuleScripts: boolean;
|
@@ -29,7 +30,6 @@ export default function extractInlineAssets(
|
|
29
30
|
// Extract inline <script> and <style> tags for processing.
|
30
31
|
let parts: Array<TransformerResult> = [];
|
31
32
|
let hasModuleScripts = false;
|
32
|
-
// @ts-expect-error TS2339
|
33
33
|
PostHTML().walk.call(program, (node: PostHTMLNode) => {
|
34
34
|
let parcelKey = hashString(`${asset.id}:${key++}`);
|
35
35
|
if (node.tag === 'script' || node.tag === 'style') {
|
@@ -45,14 +45,11 @@ export default function extractInlineAssets(
|
|
45
45
|
}
|
46
46
|
} else if (node.attrs && node.attrs.type != null) {
|
47
47
|
// Skip JSON
|
48
|
-
// @ts-expect-error TS7053
|
49
48
|
if (SCRIPT_TYPES[node.attrs.type] === false) {
|
50
49
|
return node;
|
51
50
|
}
|
52
51
|
|
53
|
-
// @ts-expect-error TS7053
|
54
52
|
if (SCRIPT_TYPES[node.attrs.type]) {
|
55
|
-
// @ts-expect-error TS7053
|
56
53
|
type = SCRIPT_TYPES[node.attrs.type];
|
57
54
|
} else {
|
58
55
|
type = node.attrs.type.split('/')[1];
|
@@ -134,10 +131,10 @@ export default function extractInlineAssets(
|
|
134
131
|
content: value,
|
135
132
|
uniqueKey: parcelKey,
|
136
133
|
bundleBehavior: 'inline',
|
137
|
-
// @ts-expect-error TS2322
|
138
134
|
env,
|
139
135
|
meta: {
|
140
136
|
type: 'tag',
|
137
|
+
// $FlowFixMe
|
141
138
|
node,
|
142
139
|
startLine: node.location?.start.line,
|
143
140
|
},
|
@@ -166,6 +163,7 @@ export default function extractInlineAssets(
|
|
166
163
|
bundleBehavior: 'inline',
|
167
164
|
meta: {
|
168
165
|
type: 'attr',
|
166
|
+
// $FlowFixMe
|
169
167
|
node,
|
170
168
|
},
|
171
169
|
});
|
@@ -1,19 +1,22 @@
|
|
1
|
-
|
1
|
+
// @flow strict-local
|
2
|
+
|
3
|
+
import {type PostHTMLNode, render} from 'posthtml-render';
|
2
4
|
import {parseHTML, transformerOpts} from '../src/HTMLTransformer';
|
3
5
|
import assert from 'assert';
|
4
6
|
import type {PluginOptions} from '../../../core/types-internal/src';
|
5
7
|
|
6
8
|
function normalizeHTML(code: string): string {
|
7
9
|
const ast = parseHTML(code, true);
|
10
|
+
// $FlowFixMe
|
8
11
|
const result = renderHTML(ast);
|
9
12
|
const lines = result
|
10
13
|
.split('\n')
|
11
|
-
.map((line
|
12
|
-
.filter((line
|
14
|
+
.map((line) => line.trim())
|
15
|
+
.filter((line) => line);
|
13
16
|
return lines.join('');
|
14
17
|
}
|
15
18
|
|
16
|
-
function renderHTML(newAST: {program: PostHTMLNode}): string {
|
19
|
+
function renderHTML(newAST: {|program: PostHTMLNode|}): string {
|
17
20
|
return render(newAST.program, {
|
18
21
|
closingSingleTag: 'slash',
|
19
22
|
});
|
@@ -21,24 +24,24 @@ function renderHTML(newAST: {program: PostHTMLNode}): string {
|
|
21
24
|
|
22
25
|
async function runTestTransform(
|
23
26
|
code: string,
|
24
|
-
options: {
|
25
|
-
shouldScopeHoist: boolean
|
26
|
-
supportsEsmodules: boolean
|
27
|
-
hmrOptions: PluginOptions['hmrOptions']
|
28
|
-
} = {
|
27
|
+
options: {|
|
28
|
+
shouldScopeHoist: boolean,
|
29
|
+
supportsEsmodules: boolean,
|
30
|
+
hmrOptions: PluginOptions['hmrOptions'],
|
31
|
+
|} = {
|
29
32
|
shouldScopeHoist: true,
|
30
33
|
supportsEsmodules: true,
|
31
34
|
hmrOptions: null,
|
32
35
|
},
|
33
36
|
) {
|
34
|
-
const dependencies
|
37
|
+
const dependencies = [];
|
35
38
|
let newAST = null;
|
36
39
|
const asset = {
|
37
40
|
getAST: () => parseHTML(code, true),
|
38
|
-
setAST: (n
|
41
|
+
setAST: (n) => {
|
39
42
|
newAST = n;
|
40
43
|
},
|
41
|
-
addURLDependency(url
|
44
|
+
addURLDependency(url, opts) {
|
42
45
|
dependencies.push({url, opts});
|
43
46
|
return `dependency-id::${url}`;
|
44
47
|
},
|
@@ -50,31 +53,34 @@ async function runTestTransform(
|
|
50
53
|
return options.supportsEsmodules;
|
51
54
|
},
|
52
55
|
},
|
53
|
-
addDependency(specifier
|
56
|
+
addDependency(specifier, specifierType) {
|
54
57
|
dependencies.push({specifier, specifierType});
|
55
58
|
return 'dependency-id';
|
56
59
|
},
|
57
|
-
}
|
60
|
+
};
|
58
61
|
|
59
62
|
const transformInput = {
|
60
63
|
asset,
|
61
64
|
options: {
|
62
65
|
hmrOptions: options.hmrOptions,
|
63
66
|
},
|
64
|
-
}
|
67
|
+
};
|
68
|
+
// $FlowFixMe
|
65
69
|
const transformResult = await transformerOpts.transform(transformInput);
|
66
70
|
|
71
|
+
// $FlowFixMe
|
67
72
|
const outputCode = renderHTML(newAST);
|
68
73
|
|
69
74
|
return {dependencies, newAST, outputCode, transformResult, inputAsset: asset};
|
70
75
|
}
|
71
76
|
|
72
|
-
function normalizeDependencies(dependencies
|
73
|
-
return dependencies.map((dependency
|
77
|
+
function normalizeDependencies(dependencies) {
|
78
|
+
return dependencies.map((dependency) => ({
|
74
79
|
...dependency,
|
75
80
|
opts: {
|
76
81
|
...dependency.opts,
|
77
82
|
env: {
|
83
|
+
// $FlowFixMe
|
78
84
|
...dependency.opts.env,
|
79
85
|
loc: null,
|
80
86
|
},
|
@@ -82,8 +88,9 @@ function normalizeDependencies(dependencies: any) {
|
|
82
88
|
}));
|
83
89
|
}
|
84
90
|
|
85
|
-
function normalizeAssets(assets
|
86
|
-
return assets.map((asset
|
91
|
+
function normalizeAssets(assets) {
|
92
|
+
return assets.map((asset) => {
|
93
|
+
// $FlowFixMe
|
87
94
|
return {
|
88
95
|
...asset,
|
89
96
|
env: null,
|
@@ -182,7 +189,7 @@ describe('HTMLTransformer', () => {
|
|
182
189
|
sourceType: 'script',
|
183
190
|
},
|
184
191
|
priority: 'parallel',
|
185
|
-
}
|
192
|
+
};
|
186
193
|
assert.deepEqual(normalizeDependencies(dependencies), [
|
187
194
|
{
|
188
195
|
url: 'input1.js',
|
package/LICENSE
DELETED
@@ -1,201 +0,0 @@
|
|
1
|
-
Apache License
|
2
|
-
Version 2.0, January 2004
|
3
|
-
http://www.apache.org/licenses/
|
4
|
-
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
-
|
7
|
-
1. Definitions.
|
8
|
-
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
-
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
-
the copyright owner that is granting the License.
|
14
|
-
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
-
other entities that control, are controlled by, or are under common
|
17
|
-
control with that entity. For the purposes of this definition,
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
19
|
-
direction or management of such entity, whether by contract or
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
-
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
-
exercising permissions granted by this License.
|
25
|
-
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
27
|
-
including but not limited to software source code, documentation
|
28
|
-
source, and configuration files.
|
29
|
-
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
31
|
-
transformation or translation of a Source form, including but
|
32
|
-
not limited to compiled object code, generated documentation,
|
33
|
-
and conversions to other media types.
|
34
|
-
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
36
|
-
Object form, made available under the License, as indicated by a
|
37
|
-
copyright notice that is included in or attached to the work
|
38
|
-
(an example is provided in the Appendix below).
|
39
|
-
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
-
the Work and Derivative Works thereof.
|
47
|
-
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
49
|
-
the original version of the Work and any modifications or additions
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
-
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
64
|
-
subsequently incorporated within the Work.
|
65
|
-
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
72
|
-
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
-
where such license applies only to those patent claims licensable
|
79
|
-
by such Contributor that are necessarily infringed by their
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
82
|
-
institute patent litigation against any entity (including a
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
85
|
-
or contributory patent infringement, then any patent licenses
|
86
|
-
granted to You under this License for that Work shall terminate
|
87
|
-
as of the date such litigation is filed.
|
88
|
-
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
91
|
-
modifications, and in Source or Object form, provided that You
|
92
|
-
meet the following conditions:
|
93
|
-
|
94
|
-
(a) You must give any other recipients of the Work or
|
95
|
-
Derivative Works a copy of this License; and
|
96
|
-
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
98
|
-
stating that You changed the files; and
|
99
|
-
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
102
|
-
attribution notices from the Source form of the Work,
|
103
|
-
excluding those notices that do not pertain to any part of
|
104
|
-
the Derivative Works; and
|
105
|
-
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
108
|
-
include a readable copy of the attribution notices contained
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
111
|
-
of the following places: within a NOTICE text file distributed
|
112
|
-
as part of the Derivative Works; within the Source form or
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
114
|
-
within a display generated by the Derivative Works, if and
|
115
|
-
wherever such third-party notices normally appear. The contents
|
116
|
-
of the NOTICE file are for informational purposes only and
|
117
|
-
do not modify the License. You may add Your own attribution
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
120
|
-
that such additional attribution notices cannot be construed
|
121
|
-
as modifying the License.
|
122
|
-
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
124
|
-
may provide additional or different license terms and conditions
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
128
|
-
the conditions stated in this License.
|
129
|
-
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
133
|
-
this License, without any additional terms or conditions.
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
-
the terms of any separate license agreement you may have executed
|
136
|
-
with Licensor regarding such Contributions.
|
137
|
-
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
140
|
-
except as required for reasonable and customary use in describing the
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
-
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
152
|
-
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
158
|
-
incidental, or consequential damages of any character arising as a
|
159
|
-
result of this License or out of the use or inability to use the
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
162
|
-
other commercial damages or losses), even if such Contributor
|
163
|
-
has been advised of the possibility of such damages.
|
164
|
-
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
-
or other liability obligations and/or rights consistent with this
|
169
|
-
License. However, in accepting such obligations, You may act only
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
174
|
-
of your accepting any such warranty or additional liability.
|
175
|
-
|
176
|
-
END OF TERMS AND CONDITIONS
|
177
|
-
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
179
|
-
|
180
|
-
To apply the Apache License to your work, attach the following
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
-
replaced with your own identifying information. (Don't include
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
184
|
-
comment syntax for the file format. We also recommend that a
|
185
|
-
file or class name and description of purpose be included on the
|
186
|
-
same "printed page" as the copyright notice for easier
|
187
|
-
identification within third-party archives.
|
188
|
-
|
189
|
-
Copyright (c) 2024 Atlassian US., Inc.
|
190
|
-
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
-
you may not use this file except in compliance with the License.
|
193
|
-
You may obtain a copy of the License at
|
194
|
-
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
-
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
-
See the License for the specific language governing permissions and
|
201
|
-
limitations under the License.
|
package/lib/HTMLTransformer.d.ts
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
import { Transformer } from '@atlaspack/plugin';
|
2
|
-
import type { AST, Transformer as TransformerOpts } from '@atlaspack/types';
|
3
|
-
export declare function parseHTML(code: string, xmlMode: boolean): AST;
|
4
|
-
export declare const transformerOpts: TransformerOpts<undefined>;
|
5
|
-
declare const _default: Transformer<undefined>;
|
6
|
-
export default _default;
|
package/lib/dependencies.d.ts
DELETED
package/lib/inline.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import type { AST, MutableAsset, TransformerResult } from '@atlaspack/types';
|
2
|
-
interface ExtractInlineAssetsResult {
|
3
|
-
hasModuleScripts: boolean;
|
4
|
-
assets: Array<TransformerResult>;
|
5
|
-
}
|
6
|
-
export default function extractInlineAssets(asset: MutableAsset, ast: AST): ExtractInlineAssetsResult;
|
7
|
-
export {};
|
package/tsconfig.json
DELETED