@parcel/transformer-posthtml 2.0.0-beta.3.1 → 2.0.0-nightly.1002
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/PostHTMLTransformer.js +22 -21
- package/package.json +9 -9
- package/src/PostHTMLTransformer.js +17 -9
|
@@ -36,7 +36,7 @@ function _posthtml() {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
function _posthtmlParser() {
|
|
39
|
-
const data =
|
|
39
|
+
const data = require("posthtml-parser");
|
|
40
40
|
|
|
41
41
|
_posthtmlParser = function () {
|
|
42
42
|
return data;
|
|
@@ -46,7 +46,7 @@ function _posthtmlParser() {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function _posthtmlRender() {
|
|
49
|
-
const data =
|
|
49
|
+
const data = require("posthtml-render");
|
|
50
50
|
|
|
51
51
|
_posthtmlRender = function () {
|
|
52
52
|
return data;
|
|
@@ -85,15 +85,7 @@ function _utils() {
|
|
|
85
85
|
return data;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
const data = _interopRequireDefault(require("./loadPlugins"));
|
|
90
|
-
|
|
91
|
-
_loadPlugins = function () {
|
|
92
|
-
return data;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
return data;
|
|
96
|
-
}
|
|
88
|
+
var _loadPlugins = _interopRequireDefault(require("./loadPlugins"));
|
|
97
89
|
|
|
98
90
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
99
91
|
|
|
@@ -103,6 +95,10 @@ var _default = new (_plugin().Transformer)({
|
|
|
103
95
|
options,
|
|
104
96
|
logger
|
|
105
97
|
}) {
|
|
98
|
+
if (!config.isSource) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
106
102
|
let configFile = await config.getConfig(['.posthtmlrc', '.posthtmlrc.js', 'posthtml.config.js'], {
|
|
107
103
|
packageKey: 'posthtml'
|
|
108
104
|
});
|
|
@@ -116,23 +112,23 @@ var _default = new (_plugin().Transformer)({
|
|
|
116
112
|
logger.warn({
|
|
117
113
|
message: 'WARNING: Using a JavaScript PostHTML config file means losing out on caching features of Parcel. Use a .posthtmlrc (JSON) file whenever possible.'
|
|
118
114
|
});
|
|
119
|
-
config.
|
|
115
|
+
config.invalidateOnStartup(); // Also add the config as a dev dependency so we attempt to reload in watch mode.
|
|
120
116
|
|
|
121
117
|
config.addDevDependency({
|
|
122
|
-
|
|
118
|
+
specifier: (0, _utils().relativePath)(_path().default.dirname(config.searchPath), configFile.filePath),
|
|
123
119
|
resolveFrom: config.searchPath
|
|
124
120
|
});
|
|
125
121
|
} // Load plugins. This must be done before adding dev dependencies so we auto install.
|
|
126
122
|
|
|
127
123
|
|
|
128
|
-
let plugins = await (0, _loadPlugins
|
|
124
|
+
let plugins = await (0, _loadPlugins.default)(configFile.contents.plugins, config.searchPath, options); // Now add dev dependencies so we invalidate when they change.
|
|
129
125
|
|
|
130
126
|
let pluginArray = Array.isArray(configFile.contents.plugins) ? configFile.contents.plugins : Object.keys(configFile.contents.plugins);
|
|
131
127
|
|
|
132
128
|
for (let p of pluginArray) {
|
|
133
129
|
if (typeof p === 'string') {
|
|
134
130
|
config.addDevDependency({
|
|
135
|
-
|
|
131
|
+
specifier: p,
|
|
136
132
|
resolveFrom: configFile.filePath
|
|
137
133
|
});
|
|
138
134
|
}
|
|
@@ -142,7 +138,7 @@ var _default = new (_plugin().Transformer)({
|
|
|
142
138
|
|
|
143
139
|
configFile.contents.skipParse = true;
|
|
144
140
|
delete configFile.contents.render;
|
|
145
|
-
|
|
141
|
+
return configFile.contents;
|
|
146
142
|
}
|
|
147
143
|
},
|
|
148
144
|
|
|
@@ -164,8 +160,10 @@ var _default = new (_plugin().Transformer)({
|
|
|
164
160
|
return {
|
|
165
161
|
type: 'posthtml',
|
|
166
162
|
version: '0.4.1',
|
|
167
|
-
program: (0, _posthtmlParser().
|
|
168
|
-
lowerCaseAttributeNames: true
|
|
163
|
+
program: (0, _posthtmlParser().parser)(await asset.getCode(), {
|
|
164
|
+
lowerCaseAttributeNames: true,
|
|
165
|
+
sourceLocations: true,
|
|
166
|
+
xmlMode: asset.type === 'xhtml'
|
|
169
167
|
})
|
|
170
168
|
};
|
|
171
169
|
},
|
|
@@ -189,7 +187,7 @@ var _default = new (_plugin().Transformer)({
|
|
|
189
187
|
file: filePath
|
|
190
188
|
}) => {
|
|
191
189
|
if (type === 'dependency') {
|
|
192
|
-
return asset.
|
|
190
|
+
return asset.invalidateOnFileChange(filePath);
|
|
193
191
|
}
|
|
194
192
|
|
|
195
193
|
return Promise.resolve();
|
|
@@ -206,10 +204,13 @@ var _default = new (_plugin().Transformer)({
|
|
|
206
204
|
},
|
|
207
205
|
|
|
208
206
|
generate({
|
|
209
|
-
ast
|
|
207
|
+
ast,
|
|
208
|
+
asset
|
|
210
209
|
}) {
|
|
211
210
|
return {
|
|
212
|
-
content: (0, _posthtmlRender().
|
|
211
|
+
content: (0, _posthtmlRender().render)(ast.program, {
|
|
212
|
+
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined
|
|
213
|
+
})
|
|
213
214
|
};
|
|
214
215
|
}
|
|
215
216
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-posthtml",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-nightly.1002+5530a6ef",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/PostHTMLTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "
|
|
20
|
+
"parcel": "2.0.0-nightly.1000+5530a6ef"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "2.0.0-
|
|
24
|
-
"@parcel/utils": "2.0.0-
|
|
23
|
+
"@parcel/plugin": "2.0.0-nightly.1002+5530a6ef",
|
|
24
|
+
"@parcel/utils": "2.0.0-nightly.1002+5530a6ef",
|
|
25
25
|
"nullthrows": "^1.1.1",
|
|
26
|
-
"posthtml": "^0.
|
|
27
|
-
"posthtml-parser": "^0.
|
|
28
|
-
"posthtml-render": "^
|
|
29
|
-
"semver": "^5.
|
|
26
|
+
"posthtml": "^0.16.5",
|
|
27
|
+
"posthtml-parser": "^0.10.1",
|
|
28
|
+
"posthtml-render": "^3.0.0",
|
|
29
|
+
"semver": "^5.7.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "5530a6eff8b619873353baeb0457ae4ec591e9fa"
|
|
32
32
|
}
|
|
@@ -4,8 +4,8 @@ import {Transformer} from '@parcel/plugin';
|
|
|
4
4
|
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import posthtml from 'posthtml';
|
|
7
|
-
import parse from 'posthtml-parser';
|
|
8
|
-
import render from 'posthtml-render';
|
|
7
|
+
import {parser as parse} from 'posthtml-parser';
|
|
8
|
+
import {render} from 'posthtml-render';
|
|
9
9
|
import nullthrows from 'nullthrows';
|
|
10
10
|
import semver from 'semver';
|
|
11
11
|
import {relativePath} from '@parcel/utils';
|
|
@@ -13,6 +13,10 @@ import loadPlugins from './loadPlugins';
|
|
|
13
13
|
|
|
14
14
|
export default (new Transformer({
|
|
15
15
|
async loadConfig({config, options, logger}) {
|
|
16
|
+
if (!config.isSource) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
let configFile = await config.getConfig(
|
|
17
21
|
['.posthtmlrc', '.posthtmlrc.js', 'posthtml.config.js'],
|
|
18
22
|
{
|
|
@@ -30,11 +34,11 @@ export default (new Transformer({
|
|
|
30
34
|
'WARNING: Using a JavaScript PostHTML config file means losing out on caching features of Parcel. Use a .posthtmlrc (JSON) file whenever possible.',
|
|
31
35
|
});
|
|
32
36
|
|
|
33
|
-
config.
|
|
37
|
+
config.invalidateOnStartup();
|
|
34
38
|
|
|
35
39
|
// Also add the config as a dev dependency so we attempt to reload in watch mode.
|
|
36
40
|
config.addDevDependency({
|
|
37
|
-
|
|
41
|
+
specifier: relativePath(
|
|
38
42
|
path.dirname(config.searchPath),
|
|
39
43
|
configFile.filePath,
|
|
40
44
|
),
|
|
@@ -56,7 +60,7 @@ export default (new Transformer({
|
|
|
56
60
|
for (let p of pluginArray) {
|
|
57
61
|
if (typeof p === 'string') {
|
|
58
62
|
config.addDevDependency({
|
|
59
|
-
|
|
63
|
+
specifier: p,
|
|
60
64
|
resolveFrom: configFile.filePath,
|
|
61
65
|
});
|
|
62
66
|
}
|
|
@@ -68,7 +72,7 @@ export default (new Transformer({
|
|
|
68
72
|
configFile.contents.skipParse = true;
|
|
69
73
|
delete configFile.contents.render;
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
return configFile.contents;
|
|
72
76
|
}
|
|
73
77
|
},
|
|
74
78
|
|
|
@@ -87,6 +91,8 @@ export default (new Transformer({
|
|
|
87
91
|
version: '0.4.1',
|
|
88
92
|
program: parse(await asset.getCode(), {
|
|
89
93
|
lowerCaseAttributeNames: true,
|
|
94
|
+
sourceLocations: true,
|
|
95
|
+
xmlMode: asset.type === 'xhtml',
|
|
90
96
|
}),
|
|
91
97
|
};
|
|
92
98
|
},
|
|
@@ -106,7 +112,7 @@ export default (new Transformer({
|
|
|
106
112
|
await Promise.all(
|
|
107
113
|
res.messages.map(({type, file: filePath}) => {
|
|
108
114
|
if (type === 'dependency') {
|
|
109
|
-
return asset.
|
|
115
|
+
return asset.invalidateOnFileChange(filePath);
|
|
110
116
|
}
|
|
111
117
|
return Promise.resolve();
|
|
112
118
|
}),
|
|
@@ -122,9 +128,11 @@ export default (new Transformer({
|
|
|
122
128
|
return [asset];
|
|
123
129
|
},
|
|
124
130
|
|
|
125
|
-
generate({ast}) {
|
|
131
|
+
generate({ast, asset}) {
|
|
126
132
|
return {
|
|
127
|
-
content: render(ast.program
|
|
133
|
+
content: render(ast.program, {
|
|
134
|
+
closingSingleTag: asset.type === 'xhtml' ? 'slash' : undefined,
|
|
135
|
+
}),
|
|
128
136
|
};
|
|
129
137
|
},
|
|
130
138
|
}): Transformer);
|